rspack_core/stats/
struct.rs

1use std::{borrow::Cow, fmt::Debug};
2
3use rspack_paths::Utf8Path;
4use rspack_sources::BoxSource;
5use rspack_util::atom::Atom;
6use rustc_hash::FxHashMap as HashMap;
7
8use crate::{ChunkGroupOrderKey, ModuleId, ModuleIdentifier, ModuleType, RuntimeSpec, SourceType};
9
10pub enum EntrypointsStatsOption {
11  Bool(bool),
12  String(String),
13}
14
15pub struct ExtendedStatsOptions {
16  pub assets: bool,
17  pub cached_modules: bool,
18  pub chunks: bool,
19  pub chunk_group_auxiliary: bool,
20  pub chunk_group_children: bool,
21  pub chunk_groups: bool,
22  pub chunk_modules: bool,
23  pub chunk_relations: bool,
24  pub depth: bool,
25  pub entrypoints: EntrypointsStatsOption,
26  pub errors: bool,
27  pub hash: bool,
28  pub ids: bool,
29  pub modules: bool,
30  pub module_assets: bool,
31  pub nested_modules: bool,
32  pub optimization_bailout: bool,
33  pub provided_exports: bool,
34  pub reasons: bool,
35  pub source: bool,
36  pub used_exports: bool,
37  pub warnings: bool,
38}
39
40impl Default for ExtendedStatsOptions {
41  fn default() -> Self {
42    Self {
43      chunks: true,
44      chunk_modules: true,
45      errors: true,
46      warnings: true,
47      assets: true,
48      hash: true,
49
50      cached_modules: false,
51      chunk_group_auxiliary: false,
52      chunk_group_children: false,
53      chunk_groups: false,
54      chunk_relations: false,
55      depth: false,
56      entrypoints: EntrypointsStatsOption::Bool(false),
57      ids: false,
58      modules: false,
59      module_assets: false,
60      nested_modules: false,
61      optimization_bailout: false,
62      provided_exports: false,
63      reasons: false,
64      source: false,
65      used_exports: false,
66    }
67  }
68}
69
70#[derive(Debug)]
71pub struct StatsError<'a> {
72  pub name: Option<String>,
73  pub message: String,
74  pub code: Option<String>,
75  pub module_identifier: Option<ModuleIdentifier>,
76  pub module_name: Option<Cow<'a, str>>,
77  pub module_id: Option<ModuleId>,
78  pub loc: Option<String>,
79  pub file: Option<&'a Utf8Path>,
80
81  pub chunk_name: Option<&'a str>,
82  pub chunk_entry: Option<bool>,
83  pub chunk_initial: Option<bool>,
84  pub chunk_id: Option<&'a str>,
85  pub details: Option<String>,
86  pub stack: Option<String>,
87  pub module_trace: Vec<StatsModuleTrace<'a>>,
88}
89
90#[derive(Debug)]
91pub struct StatsModuleTrace<'a> {
92  pub origin: StatsErrorModuleTraceModule<'a>,
93  pub module: StatsErrorModuleTraceModule<'a>,
94  pub dependencies: Vec<StatsErrorModuleTraceDependency>,
95}
96
97#[derive(Debug)]
98pub struct StatsErrorModuleTraceModule<'a> {
99  pub identifier: ModuleIdentifier,
100  pub name: Cow<'a, str>,
101  pub id: Option<ModuleId>,
102}
103
104#[derive(Debug)]
105pub struct StatsErrorModuleTraceDependency {
106  pub loc: String,
107}
108
109#[derive(Debug)]
110pub struct StatsAsset<'a> {
111  pub r#type: &'static str,
112  pub name: &'a str,
113  pub size: f64,
114  pub chunks: Vec<Option<&'a str>>,
115  pub chunk_names: Vec<&'a str>,
116  pub chunk_id_hints: Vec<&'a str>,
117  pub info: StatsAssetInfo<'a>,
118  pub emitted: bool,
119  pub auxiliary_chunk_names: Vec<&'a str>,
120  pub auxiliary_chunk_id_hints: Vec<&'a str>,
121  pub auxiliary_chunks: Vec<Option<&'a str>>,
122}
123
124#[derive(Debug)]
125pub struct StatsAssetsByChunkName<'a> {
126  pub name: &'a str,
127  pub files: Vec<&'a str>,
128}
129
130#[derive(Debug)]
131pub struct StatsAssetInfo<'a> {
132  pub minimized: Option<bool>,
133  pub development: Option<bool>,
134  pub hot_module_replacement: Option<bool>,
135  pub source_filename: Option<&'a str>,
136  pub copied: Option<bool>,
137  pub immutable: Option<bool>,
138  pub javascript_module: Option<bool>,
139  pub chunk_hash: Vec<&'a str>,
140  pub content_hash: Vec<&'a str>,
141  pub full_hash: Vec<&'a str>,
142  pub related: Vec<StatsAssetInfoRelated<'a>>,
143  pub is_over_size_limit: Option<bool>,
144}
145
146#[derive(Debug)]
147pub struct StatsAssetInfoRelated<'a> {
148  pub name: &'a str,
149  pub value: Vec<&'a str>,
150}
151
152#[derive(Debug)]
153pub struct StatsModule<'a> {
154  pub r#type: &'static str,
155  pub module_type: ModuleType,
156  pub layer: Option<Cow<'a, str>>,
157  pub identifier: Option<ModuleIdentifier>,
158  pub name: Option<Cow<'a, str>>,
159  pub name_for_condition: Option<String>,
160  pub id: Option<ModuleId>,
161  pub chunks: Option<Vec<&'a str>>, // has id after the call of chunkIds hook
162  pub size: f64,
163  pub sizes: Vec<StatsSourceTypeSize>,
164  pub dependent: Option<bool>,
165  pub issuer: Option<ModuleIdentifier>,
166  pub issuer_name: Option<Cow<'a, str>>,
167  pub issuer_id: Option<ModuleId>,
168  pub issuer_path: Option<Vec<StatsModuleIssuer<'a>>>,
169  pub reasons: Option<Vec<StatsModuleReason<'a>>>,
170  pub assets: Option<Vec<&'a str>>,
171  pub modules: Option<Vec<StatsModule<'a>>>,
172  pub source: Option<&'a BoxSource>,
173  pub profile: Option<StatsModuleProfile>,
174  pub orphan: Option<bool>,
175  pub provided_exports: Option<Vec<Atom>>,
176  pub used_exports: Option<StatsUsedExports>,
177  pub optimization_bailout: Option<&'a [String]>,
178  pub depth: Option<usize>,
179  pub pre_order_index: Option<u32>,
180  pub post_order_index: Option<u32>,
181  pub built: bool,
182  pub code_generated: bool,
183  pub build_time_executed: bool,
184  pub cached: bool,
185  pub cacheable: Option<bool>,
186  pub optional: Option<bool>,
187  pub failed: Option<bool>,
188  pub errors: Option<u32>,
189  pub warnings: Option<u32>,
190}
191
192#[derive(Debug)]
193pub enum StatsUsedExports {
194  Vec(Vec<Atom>),
195  Bool(bool),
196  Null,
197}
198
199#[derive(Debug)]
200pub struct StatsModuleProfile {
201  pub factory: u64,
202  pub building: u64,
203}
204
205#[derive(Debug)]
206pub struct StatsOriginRecord<'a> {
207  pub module: Option<ModuleIdentifier>,
208  pub module_id: Option<ModuleId>,
209  pub module_identifier: Option<ModuleIdentifier>,
210  pub module_name: Cow<'a, str>,
211  pub loc: String,
212  pub request: &'a str,
213}
214
215#[derive(Debug)]
216pub struct StatsChunk<'a> {
217  pub r#type: &'static str,
218  pub files: Vec<&'a str>,
219  pub auxiliary_files: Vec<&'a str>,
220  pub id: Option<&'a str>,
221  pub entry: bool,
222  pub initial: bool,
223  pub names: Vec<&'a str>,
224  pub size: f64,
225  pub modules: Option<Vec<StatsModule<'a>>>,
226  pub parents: Option<Vec<&'a str>>,
227  pub children: Option<Vec<&'a str>>,
228  pub siblings: Option<Vec<&'a str>>,
229  pub children_by_order: HashMap<ChunkGroupOrderKey, Vec<String>>,
230  pub runtime: &'a RuntimeSpec,
231  pub sizes: HashMap<SourceType, f64>,
232  pub reason: Option<&'a str>,
233  pub rendered: bool,
234  pub origins: Vec<StatsOriginRecord<'a>>,
235  pub id_hints: Vec<&'a str>,
236  pub hash: Option<&'a str>,
237}
238
239#[derive(Debug)]
240pub struct StatsChunkGroupAsset<'a> {
241  pub name: &'a str,
242  pub size: usize,
243}
244
245#[derive(Debug)]
246pub struct StatsChunkGroup<'a> {
247  pub name: &'a str,
248  pub chunks: Vec<&'a str>,
249  pub assets: Vec<StatsChunkGroupAsset<'a>>,
250  pub assets_size: usize,
251  pub auxiliary_assets: Option<Vec<StatsChunkGroupAsset<'a>>>,
252  pub auxiliary_assets_size: Option<usize>,
253  pub children: Option<StatsChunkGroupChildren<'a>>,
254  pub is_over_size_limit: Option<bool>,
255  pub child_assets: Option<StatschunkGroupChildAssets<'a>>,
256}
257
258#[derive(Debug)]
259pub struct StatsChunkGroupChildren<'a> {
260  pub preload: Vec<StatsChunkGroup<'a>>,
261  pub prefetch: Vec<StatsChunkGroup<'a>>,
262}
263
264#[derive(Debug)]
265pub struct StatschunkGroupChildAssets<'a> {
266  pub preload: Vec<&'a str>,
267  pub prefetch: Vec<&'a str>,
268}
269
270#[derive(Debug)]
271pub struct StatsModuleIssuer<'s> {
272  pub identifier: ModuleIdentifier,
273  pub name: Cow<'s, str>,
274  pub id: Option<ModuleId>,
275}
276
277#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
278pub struct StatsModuleReason<'s> {
279  pub module_identifier: Option<ModuleIdentifier>,
280  pub module_name: Option<Cow<'s, str>>,
281  pub module_id: Option<ModuleId>,
282  pub module_chunks: Option<u32>,
283  pub resolved_module_identifier: Option<ModuleIdentifier>,
284  pub resolved_module_name: Option<Cow<'s, str>>,
285  pub resolved_module_id: Option<ModuleId>,
286
287  pub r#type: Option<&'static str>,
288  pub user_request: Option<&'s str>,
289  pub explanation: Option<&'static str>,
290  pub active: bool,
291  pub loc: Option<String>,
292}
293
294#[derive(Debug)]
295pub struct StatsSourceTypeSize {
296  pub source_type: SourceType,
297  pub size: f64,
298}