webpack_stats/common/
module.rs1use crate::common::chunk::ChunkId;
18use crate::import::{ImportType, ResolvedModule};
19use meshed::prelude::*;
20use serde::{Deserialize, Serialize};
21use std::borrow::Cow;
22use std::collections::HashSet;
23use std::fmt::{Display, Formatter};
24
25use crate::rc::RefCount;
26
27pub struct IncludedModuleNames(pub HashSet<String>);
28pub type ModuleChunks = HashSet<ChunkId>;
29
30impl IncludedModuleNames {
31 pub fn included_name_suffix(&self, pattern: impl AsRef<str>) -> Option<&String> {
32 self.0.iter().find(|name| name.ends_with(pattern.as_ref()))
33 }
34
35 pub fn included_names_contains(&self, pattern: impl AsRef<str>) -> Option<&String> {
36 self.0.iter().find(|name| name.contains(pattern.as_ref()))
37 }
38}
39
40#[derive(Deserialize, Debug, Hash, Eq, PartialEq, Ord, PartialOrd, Serialize)]
43#[serde(transparent)]
44pub struct ModuleIdentifier(pub RefCount<str>);
45
46impl Clone for ModuleIdentifier {
47 fn clone(&self) -> Self {
48 Self(RefCount::clone(&self.0))
49 }
50}
51
52impl Display for ModuleIdentifier {
53 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
54 Display::fmt(&self.0, f)
55 }
56}
57
58impl Identity for ModuleIdentifier {}
59
60#[derive(Deserialize, Serialize, Debug)]
61#[serde(transparent)]
62pub struct ModuleName(pub RefCount<str>);
63
64impl Default for ModuleName {
65 fn default() -> Self {
66 Self("".into())
67 }
68}
69
70impl Display for ModuleName {
71 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
72 <str as Display>::fmt(&self.0, f)
73 }
74}
75
76impl Clone for ModuleName {
77 fn clone(&self) -> Self {
78 Self(RefCount::clone(&self.0))
79 }
80}
81
82#[derive(Deserialize, Debug, Default)]
83#[serde(transparent)]
84pub struct ModuleId(u32);
85
86#[derive(Deserialize, Debug, Default)]
87#[serde(transparent)]
88pub struct RelativeModulePath<'a>(#[serde(borrow)] Cow<'a, str>);
89
90pub trait Modules<T>: Query<ModuleIdentifier, T>
91where
92 T: Module,
93{
94}
95pub trait Module:
96 Identifiable<ModuleIdentifier>
97 + Edges<ModuleIdentifier, (ImportType, ResolvedModule)>
98 + ExtractData<IncludedModuleNames>
99 + ExtractData<ModuleChunks>
100 + Label<Label = ModuleName>
101{
102}