diff --git a/.changeset/old-apricots-hunt.md b/.changeset/old-apricots-hunt.md new file mode 100644 index 000000000000..28f6e062633a --- /dev/null +++ b/.changeset/old-apricots-hunt.md @@ -0,0 +1,6 @@ +--- +"@rspack/binding": patch +"@rspack/core": patch +--- + +feat: stats for chunkRelations and chunkModules diff --git a/crates/node_binding/binding.d.ts b/crates/node_binding/binding.d.ts index 31891f9c0670..62f9c3ca4fe0 100644 --- a/crates/node_binding/binding.d.ts +++ b/crates/node_binding/binding.d.ts @@ -3,6 +3,16 @@ /* auto-generated by NAPI-RS */ +export interface ThreadsafeNodeFS { + writeFile: (...args: any[]) => any + mkdir: (...args: any[]) => any + mkdirp: (...args: any[]) => any +} +export interface NodeFS { + writeFile: (...args: any[]) => any + mkdir: (...args: any[]) => any + mkdirp: (...args: any[]) => any +} export interface RawPattern { from: string to?: string @@ -330,6 +340,7 @@ export interface RawCacheGroupOptions { } export interface RawStatsOptions { colors: boolean + reasons: boolean } export interface RawOptions { entry: Record @@ -351,16 +362,6 @@ export interface RawOptions { experiments: RawExperiments node: RawNodeOption } -export interface ThreadsafeNodeFS { - writeFile: (...args: any[]) => any - mkdir: (...args: any[]) => any - mkdirp: (...args: any[]) => any -} -export interface NodeFS { - writeFile: (...args: any[]) => any - mkdir: (...args: any[]) => any - mkdirp: (...args: any[]) => any -} export interface JsAssetInfoRelated { sourceMap?: string } @@ -479,6 +480,10 @@ export interface JsStatsChunk { initial: boolean names: Array size: number + modules?: Array + parents?: Array + children?: Array + siblings?: Array } export interface JsStatsChunkGroupAsset { name: string @@ -531,8 +536,8 @@ export class JsCompilation { } export class JsStats { getAssets(): JsStatsGetAssets - getModules(showReasons: boolean): Array - getChunks(): Array + getModules(): Array + getChunks(chunkModules: boolean, chunksRelations: boolean): Array getEntrypoints(): Array getNamedChunkGroups(): Array getErrors(): Array diff --git a/crates/node_binding/src/js_values/stats.rs b/crates/node_binding/src/js_values/stats.rs index 291c9314e85c..1391ff4f5890 100644 --- a/crates/node_binding/src/js_values/stats.rs +++ b/crates/node_binding/src/js_values/stats.rs @@ -154,6 +154,10 @@ pub struct JsStatsChunk { pub initial: bool, pub names: Vec, pub size: f64, + pub modules: Option>, + pub parents: Option>, + pub children: Option>, + pub siblings: Option>, } impl From for JsStatsChunk { @@ -166,6 +170,12 @@ impl From for JsStatsChunk { initial: stats.initial, names: stats.names, size: stats.size, + modules: stats + .modules + .map(|i| i.into_iter().map(Into::into).collect()), + parents: stats.parents, + children: stats.children, + siblings: stats.siblings, } } } @@ -250,10 +260,10 @@ impl JsStats { } #[napi] - pub fn get_modules(&self, show_reasons: bool) -> Vec { + pub fn get_modules(&self) -> Vec { self .inner - .get_modules(show_reasons) + .get_modules() .expect("Failed to get modules") .into_iter() .map(Into::into) @@ -261,10 +271,11 @@ impl JsStats { } #[napi] - pub fn get_chunks(&self) -> Vec { + pub fn get_chunks(&self, chunk_modules: bool, chunks_relations: bool) -> Vec { self .inner - .get_chunks() + .get_chunks(chunk_modules, chunks_relations) + .expect("Failed to get chunks") .into_iter() .map(Into::into) .collect() diff --git a/crates/rspack_binding_options/src/options/raw_stats.rs b/crates/rspack_binding_options/src/options/raw_stats.rs index 732c13c7a3f4..81cf09e56441 100644 --- a/crates/rspack_binding_options/src/options/raw_stats.rs +++ b/crates/rspack_binding_options/src/options/raw_stats.rs @@ -7,12 +7,14 @@ use serde::Deserialize; #[napi(object)] pub struct RawStatsOptions { pub colors: bool, + pub reasons: bool, } impl From for StatsOptions { fn from(value: RawStatsOptions) -> Self { Self { colors: value.colors, + reasons: value.reasons, } } } diff --git a/crates/rspack_core/src/chunk_graph.rs b/crates/rspack_core/src/chunk_graph.rs index 63ae04d59b45..7c5404769c30 100644 --- a/crates/rspack_core/src/chunk_graph.rs +++ b/crates/rspack_core/src/chunk_graph.rs @@ -2,8 +2,8 @@ use rspack_identifier::{IdentifierLinkedMap, IdentifierMap, IdentifierSet}; use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet}; use crate::{ - find_graph_roots, Chunk, ChunkByUkey, ChunkGroup, ChunkGroupByUkey, ChunkGroupUkey, ChunkUkey, - Module, ModuleGraph, ModuleGraphModule, ModuleIdentifier, RuntimeSpec, RuntimeSpecMap, + find_graph_roots, BoxModule, Chunk, ChunkByUkey, ChunkGroup, ChunkGroupByUkey, ChunkGroupUkey, + ChunkUkey, Module, ModuleGraph, ModuleGraphModule, ModuleIdentifier, RuntimeSpec, RuntimeSpecMap, RuntimeSpecSet, SourceType, }; @@ -168,12 +168,12 @@ impl ChunkGraph { &self, chunk: &ChunkUkey, module_graph: &'module ModuleGraph, - ) -> Vec<&'module ModuleGraphModule> { + ) -> Vec<&'module BoxModule> { let chunk_graph_chunk = self.get_chunk_graph_chunk(chunk); chunk_graph_chunk .modules .iter() - .filter_map(|uri| module_graph.module_graph_module_by_identifier(uri)) + .filter_map(|uri| module_graph.module_by_identifier(uri)) .collect() } @@ -186,10 +186,10 @@ impl ChunkGraph { &self, chunk: &ChunkUkey, module_graph: &'module ModuleGraph, - ) -> Vec<&'module ModuleGraphModule> { + ) -> Vec<&'module BoxModule> { let mut modules = self.get_chunk_modules(chunk, module_graph); // SAFETY: module identifier is unique - modules.sort_unstable_by_key(|m| m.module_identifier.as_str()); + modules.sort_unstable_by_key(|m| m.identifier().as_str()); modules } @@ -234,14 +234,7 @@ impl ChunkGraph { .get_chunk_modules(chunk, module_graph) .iter() .fold(0.0, |acc, m| { - let module = module_graph - .module_by_identifier(&m.module_identifier) - .unwrap_or_else(|| panic!("Module({}) does not exist", m.module_identifier)); - acc - + module - .source_types() - .iter() - .fold(0.0, |acc, t| acc + module.size(t)) + acc + m.source_types().iter().fold(0.0, |acc, t| acc + m.size(t)) }) } diff --git a/crates/rspack_core/src/compiler/compilation.rs b/crates/rspack_core/src/compiler/compilation.rs index 3a20512d69b3..190c0f9dd376 100644 --- a/crates/rspack_core/src/compiler/compilation.rs +++ b/crates/rspack_core/src/compiler/compilation.rs @@ -1074,7 +1074,7 @@ impl Compilation { { if let Some(runtime_requirements) = self .chunk_graph - .get_module_runtime_requirements(module.module_identifier, &chunk.runtime) + .get_module_runtime_requirements(module.identifier(), &chunk.runtime) { set.extend(runtime_requirements); } @@ -1153,7 +1153,7 @@ impl Compilation { .chunk_graph .get_ordered_chunk_modules(&chunk.ukey, &self.module_graph) .into_iter() - .filter_map(|mgm| self.module_graph.get_module_hash(&mgm.module_identifier)) + .filter_map(|m| self.module_graph.get_module_hash(&m.identifier())) .inspect(|hash| hash.hash(&mut chunk.hash)) }) .collect::>() diff --git a/crates/rspack_core/src/options/stats.rs b/crates/rspack_core/src/options/stats.rs index 50bc2eac6653..51b454026c94 100644 --- a/crates/rspack_core/src/options/stats.rs +++ b/crates/rspack_core/src/options/stats.rs @@ -1,4 +1,5 @@ #[derive(Debug, Default)] pub struct StatsOptions { pub colors: bool, + pub reasons: bool, } diff --git a/crates/rspack_core/src/stats.rs b/crates/rspack_core/src/stats.rs index 7f76922ff49e..370ff1ab9db6 100644 --- a/crates/rspack_core/src/stats.rs +++ b/crates/rspack_core/src/stats.rs @@ -4,7 +4,7 @@ use rspack_error::{ }, Result, }; -use rustc_hash::FxHashMap as HashMap; +use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet}; use crate::{ BoxModule, Chunk, ChunkGroupUkey, Compilation, ModuleIdentifier, ModuleType, SourceType, @@ -109,116 +109,48 @@ impl Stats<'_> { (assets, assets_by_chunk_name) } - pub fn get_modules(&self, show_reasons: bool) -> Result> { + pub fn get_modules(&self) -> Result> { let mut modules: Vec = self .compilation .module_graph .modules() - .map(|module| { - let identifier = module.identifier(); - let mgm = self - .compilation - .module_graph - .module_graph_module_by_identifier(&identifier) - .unwrap_or_else(|| { - panic!("Could not find ModuleGraphModule by identifier: {identifier:?}") - }); - - let issuer = self.compilation.module_graph.get_issuer(module); - let (issuer_name, issuer_id) = issuer - .map(|i| get_stats_module_name_and_id(i, self.compilation)) - .unzip(); - let mut issuer_path = Vec::new(); - let mut current_issuer = issuer; - while let Some(i) = current_issuer { - let (name, id) = get_stats_module_name_and_id(i, self.compilation); - issuer_path.push(StatsModuleIssuer { - identifier: i.identifier().to_string(), - name, - id, - }); - current_issuer = self.compilation.module_graph.get_issuer(i); - } - issuer_path.reverse(); - - let reasons = show_reasons - .then(|| -> Result<_> { - let mut reasons: Vec = mgm - .incoming_connections_unordered(&self.compilation.module_graph)? - .map(|connection| { - let (module_name, module_id) = connection - .original_module_identifier - .and_then(|i| self.compilation.module_graph.module_by_identifier(&i)) - .map(|m| get_stats_module_name_and_id(m, self.compilation)) - .unzip(); - StatsModuleReason { - module_identifier: connection.original_module_identifier.map(|i| i.to_string()), - module_name, - module_id, - } - }) - .collect(); - reasons.sort_unstable_by(|a, b| a.module_identifier.cmp(&b.module_identifier)); - Ok(reasons) - }) - .transpose()?; - - let mut chunks: Vec = self - .compilation - .chunk_graph - .get_chunk_graph_module(mgm.module_identifier) - .chunks - .iter() - .map(|k| { - self - .compilation - .chunk_by_ukey - .get(k) - .unwrap_or_else(|| panic!("Could not find chunk by ukey: {k:?}")) - .expect_id() - .to_string() - }) - .collect(); - chunks.sort_unstable(); - - Ok(StatsModule { - r#type: "module", - module_type: *module.module_type(), - identifier, - name: module - .readable_identifier(&self.compilation.options.context) - .into(), - id: mgm.id(&self.compilation.chunk_graph).to_string(), - chunks, - size: module.size(&SourceType::JavaScript), - issuer: issuer.map(|i| i.identifier().to_string()), - issuer_name, - issuer_id, - issuer_path, - reasons, - }) - }) + .map(|module| self.get_module(module, self.compilation.options.stats.reasons)) .collect::>()?; - modules.sort_unstable_by(|a, b| { - if a.name.len() != b.name.len() { - a.name.len().cmp(&b.name.len()) - } else { - a.name.cmp(&b.name) - } - }); // TODO: sort by module.depth + Self::sort_modules(&mut modules); Ok(modules) } - pub fn get_chunks(&self) -> Vec { + pub fn get_chunks(&self, chunk_modules: bool, chunk_relations: bool) -> Result> { let mut chunks: Vec = self .compilation .chunk_by_ukey .values() .into_iter() - .map(|c| { + .map(|c| -> Result<_> { let mut files = Vec::from_iter(c.files.iter().cloned()); files.sort_unstable(); - StatsChunk { + let chunk_modules = if chunk_modules { + let chunk_modules = self + .compilation + .chunk_graph + .get_chunk_modules(&c.ukey, &self.compilation.module_graph); + let mut chunk_modules = chunk_modules + .into_iter() + .map(|m| self.get_module(m, self.compilation.options.stats.reasons)) + .collect::>>()?; + Self::sort_modules(&mut chunk_modules); + Some(chunk_modules) + } else { + None + }; + let (parents, children, siblings) = if let Some((parents, children, siblings)) = + chunk_relations.then(|| self.get_chunk_relations(c)) + { + (Some(parents), Some(children), Some(siblings)) + } else { + (None, None, None) + }; + Ok(StatsChunk { r#type: "chunk", files, id: c.expect_id().to_string(), @@ -229,11 +161,15 @@ impl Stats<'_> { .compilation .chunk_graph .get_chunk_modules_size(&c.ukey, &self.compilation.module_graph), - } + modules: chunk_modules, + parents, + children, + siblings, + }) }) - .collect(); + .collect::>()?; chunks.sort_by_cached_key(|v| v.id.to_string()); - chunks + Ok(chunks) } fn get_chunk_group(&self, name: &str, ukey: &ChunkGroupUkey) -> StatsChunkGroup { @@ -333,6 +269,144 @@ impl Stats<'_> { pub fn get_hash(&self) -> String { self.compilation.hash.to_owned() } + + fn sort_modules(modules: &mut [StatsModule]) { + // TODO: sort by module.depth + modules.sort_unstable_by(|a, b| { + if a.name.len() != b.name.len() { + a.name.len().cmp(&b.name.len()) + } else { + a.name.cmp(&b.name) + } + }); + } + + fn get_module(&self, module: &BoxModule, show_reasons: bool) -> Result { + let identifier = module.identifier(); + let mgm = self + .compilation + .module_graph + .module_graph_module_by_identifier(&identifier) + .unwrap_or_else(|| panic!("Could not find ModuleGraphModule by identifier: {identifier:?}")); + + let issuer = self.compilation.module_graph.get_issuer(module); + let (issuer_name, issuer_id) = issuer + .map(|i| get_stats_module_name_and_id(i, self.compilation)) + .unzip(); + let mut issuer_path = Vec::new(); + let mut current_issuer = issuer; + while let Some(i) = current_issuer { + let (name, id) = get_stats_module_name_and_id(i, self.compilation); + issuer_path.push(StatsModuleIssuer { + identifier: i.identifier().to_string(), + name, + id, + }); + current_issuer = self.compilation.module_graph.get_issuer(i); + } + issuer_path.reverse(); + + let reasons = show_reasons + .then(|| -> Result<_> { + let mut reasons: Vec = mgm + .incoming_connections_unordered(&self.compilation.module_graph)? + .map(|connection| { + let (module_name, module_id) = connection + .original_module_identifier + .and_then(|i| self.compilation.module_graph.module_by_identifier(&i)) + .map(|m| get_stats_module_name_and_id(m, self.compilation)) + .unzip(); + StatsModuleReason { + module_identifier: connection.original_module_identifier.map(|i| i.to_string()), + module_name, + module_id, + } + }) + .collect(); + reasons.sort_unstable_by(|a, b| a.module_identifier.cmp(&b.module_identifier)); + Ok(reasons) + }) + .transpose()?; + + let mut chunks: Vec = self + .compilation + .chunk_graph + .get_chunk_graph_module(mgm.module_identifier) + .chunks + .iter() + .map(|k| { + self + .compilation + .chunk_by_ukey + .get(k) + .unwrap_or_else(|| panic!("Could not find chunk by ukey: {k:?}")) + .expect_id() + .to_string() + }) + .collect(); + chunks.sort_unstable(); + + Ok(StatsModule { + r#type: "module", + module_type: *module.module_type(), + identifier, + name: module + .readable_identifier(&self.compilation.options.context) + .into(), + id: mgm.id(&self.compilation.chunk_graph).to_string(), + chunks, + size: module.size(&SourceType::JavaScript), + issuer: issuer.map(|i| i.identifier().to_string()), + issuer_name, + issuer_id, + issuer_path, + reasons, + }) + } + + fn get_chunk_relations(&self, chunk: &Chunk) -> (Vec, Vec, Vec) { + let mut parents = HashSet::default(); + let mut children = HashSet::default(); + let mut siblings = HashSet::default(); + for cg in &chunk.groups { + if let Some(cg) = self.compilation.chunk_group_by_ukey.get(cg) { + for p in &cg.parents { + if let Some(pg) = self.compilation.chunk_group_by_ukey.get(p) { + for c in &pg.chunks { + if let Some(c) = self.compilation.chunk_by_ukey.get(c) && let Some(id) = &c.id { + parents.insert(id.to_string()); + } + } + } + } + } + if let Some(cg) = self.compilation.chunk_group_by_ukey.get(cg) { + for p in &cg.children { + if let Some(pg) = self.compilation.chunk_group_by_ukey.get(p) { + for c in &pg.chunks { + if let Some(c) = self.compilation.chunk_by_ukey.get(c) && let Some(id) = &c.id { + children.insert(id.to_string()); + } + } + } + } + } + if let Some(cg) = self.compilation.chunk_group_by_ukey.get(cg) { + for c in &cg.chunks { + if let Some(c) = self.compilation.chunk_by_ukey.get(c) && c.id != chunk.id && let Some(id) = &c.id { + siblings.insert(id.to_string()); + } + } + } + } + let mut parents = Vec::from_iter(parents.into_iter()); + let mut children = Vec::from_iter(children.into_iter()); + let mut siblings = Vec::from_iter(siblings.into_iter()); + parents.sort(); + children.sort(); + siblings.sort(); + (parents, children, siblings) + } } fn get_stats_module_name_and_id(module: &BoxModule, compilation: &Compilation) -> (String, String) { @@ -408,6 +482,10 @@ pub struct StatsChunk { pub initial: bool, pub names: Vec, pub size: f64, + pub modules: Option>, + pub parents: Option>, + pub children: Option>, + pub siblings: Option>, } #[derive(Debug)] diff --git a/crates/rspack_plugin_asset/src/lib.rs b/crates/rspack_plugin_asset/src/lib.rs index bd248e5cbc61..38267cf17049 100644 --- a/crates/rspack_plugin_asset/src/lib.rs +++ b/crates/rspack_plugin_asset/src/lib.rs @@ -459,23 +459,23 @@ impl Plugin for AssetPlugin { let assets = ordered_modules .par_iter() - .filter(|mgm| { + .filter(|m| { let module = compilation .module_graph - .module_by_identifier(&mgm.module_identifier) + .module_by_identifier(&m.identifier()) .ok_or_else(|| internal_error!("Failed to get module".to_owned())) // FIXME: use result .expect("Failed to get module"); module.source_types().contains(&SourceType::Asset) }) - .map(|mgm| { + .map(|m| { let code_gen_result = compilation .code_generation_results - .get(&mgm.module_identifier, Some(&chunk.runtime))?; + .get(&m.identifier(), Some(&chunk.runtime))?; let module = compilation .module_graph - .module_by_identifier(&mgm.module_identifier) + .module_by_identifier(&m.identifier()) .ok_or_else(|| internal_error!("Failed to get module".to_owned())) .expect("Failed to get module") .as_normal_module() @@ -488,7 +488,7 @@ impl Plugin for AssetPlugin { .map(|source| { let asset_filename = self .module_id_to_filename_without_ext - .get(&mgm.module_identifier) + .get(&m.identifier()) .map(|s| s.clone()); let contenthash = Some(get_contenthash(&source).to_string()); let chunkhash = None; diff --git a/crates/rspack_plugin_split_chunks/src/split_chunks_plugin.rs b/crates/rspack_plugin_split_chunks/src/split_chunks_plugin.rs index dd006bdb9084..9ec80821e718 100644 --- a/crates/rspack_plugin_split_chunks/src/split_chunks_plugin.rs +++ b/crates/rspack_plugin_split_chunks/src/split_chunks_plugin.rs @@ -769,7 +769,7 @@ impl Plugin for SplitChunksPlugin { { let module = compilation .module_graph - .module_by_identifier(&module.module_identifier) + .module_by_identifier(&module.identifier()) .expect("Module should exist"); if !item.modules.contains(&module.identifier()) { for ty in module.source_types() { diff --git a/packages/rspack/src/compilation.ts b/packages/rspack/src/compilation.ts index e341a5237a47..62c081c01b77 100644 --- a/packages/rspack/src/compilation.ts +++ b/packages/rspack/src/compilation.ts @@ -176,6 +176,14 @@ export class Compilation { options.chunks, !context.forToString ); + options.chunkModules = optionOrLocalFallback( + options.chunkModules, + !context.forToString + ); + options.chunkRelations = optionOrLocalFallback( + options.chunkRelations, + !context.forToString + ); options.modules = optionOrLocalFallback(options.modules, true); options.reasons = optionOrLocalFallback( options.reasons, diff --git a/packages/rspack/src/config/adapter.ts b/packages/rspack/src/config/adapter.ts index 9b9eaf3e7853..3bfe6aa081f1 100644 --- a/packages/rspack/src/config/adapter.ts +++ b/packages/rspack/src/config/adapter.ts @@ -24,6 +24,7 @@ import { RuleSetLogicalConditions, RuleSetRule, SnapshotOptions, + StatsValue, Target } from "./types"; import { @@ -58,7 +59,7 @@ export const getRawOptions = ( options.externalsType === undefined ? "" : options.externalsType, devtool, optimization: getRawOptimization(options.optimization), - stats: { colors: normalizeStatsPreset(options.stats).colors ?? false }, + stats: getRawStats(options.stats), devServer: { hot: options.devServer?.hot ?? false }, @@ -390,3 +391,11 @@ function getRawNode(node: Node): RawOptions["node"] { global: String(node.global) }; } + +function getRawStats(stats: StatsValue): RawOptions["stats"] { + const statsOptions = normalizeStatsPreset(stats); + return { + colors: statsOptions.colors ?? false, + reasons: statsOptions.reasons ?? false + }; +} diff --git a/packages/rspack/src/config/types.ts b/packages/rspack/src/config/types.ts index df207078e931..80f24fcaed87 100644 --- a/packages/rspack/src/config/types.ts +++ b/packages/rspack/src/config/types.ts @@ -414,6 +414,8 @@ export interface StatsOptions { hash?: boolean; reasons?: boolean; publicPath?: boolean; + chunkModules?: boolean; + chunkRelations?: boolean; } ///// Optimization ///// diff --git a/packages/rspack/src/stats.ts b/packages/rspack/src/stats.ts index 10accda7156a..b66c915a9829 100644 --- a/packages/rspack/src/stats.ts +++ b/packages/rspack/src/stats.ts @@ -66,10 +66,13 @@ export class Stats { }, {}); } if (options.chunks) { - obj.chunks = this.#inner.getChunks(); + obj.chunks = this.#inner.getChunks( + options.chunkModules!, + options.chunkRelations! + ); } if (options.modules) { - obj.modules = this.#inner.getModules(options.reasons ?? false); + obj.modules = this.#inner.getModules(); } if (options.entrypoints) { obj.entrypoints = this.#inner diff --git a/packages/rspack/tests/Stats.test.ts b/packages/rspack/tests/Stats.test.ts index 6bce7c25c03e..22522bd63985 100644 --- a/packages/rspack/tests/Stats.test.ts +++ b/packages/rspack/tests/Stats.test.ts @@ -45,15 +45,32 @@ describe("Stats", () => { }, "chunks": [ { + "children": [], "entry": true, "files": [ "main.js", ], "id": "main", "initial": true, + "modules": [ + { + "chunks": [ + "main", + ], + "id": "777", + "identifier": "javascript/auto|/tests/fixtures/a.js", + "issuerPath": [], + "moduleType": "javascript/auto", + "name": "./fixtures/a.js", + "size": 55, + "type": "module", + }, + ], "names": [ "main", ], + "parents": [], + "siblings": [], "size": 55, "type": "chunk", }, @@ -86,9 +103,6 @@ describe("Stats", () => { "issuerPath": [], "moduleType": "javascript/auto", "name": "./fixtures/a.js", - "reasons": [ - {}, - ], "size": 55, "type": "module", }, @@ -120,8 +134,8 @@ describe("Stats", () => { main.js 215 bytes main [emitted] main Entrypoint main = main.js chunk {main} main.js (main) 55 bytes [entry] - [777] ./fixtures/a.js 55 bytes {main} - " + [777] ./fixtures/a.js 55 bytes {main} + [777] ./fixtures/a.js 55 bytes {main}" `); }); diff --git a/packages/rspack/tests/__snapshots__/StatsTestCases.test.ts.snap b/packages/rspack/tests/__snapshots__/StatsTestCases.test.ts.snap index 52c465d3944e..9c45a5ce8164 100644 --- a/packages/rspack/tests/__snapshots__/StatsTestCases.test.ts.snap +++ b/packages/rspack/tests/__snapshots__/StatsTestCases.test.ts.snap @@ -41,26 +41,73 @@ exports[`StatsTestCases should print correct stats for filename 1`] = ` }, "chunks": [ { + "children": [], "entry": false, "files": [ "dynamic_js.xxxx.js", ], "id": "dynamic_js", "initial": false, + "modules": [ + { + "chunks": [ + "dynamic_js", + ], + "id": "471", + "identifier": "javascript/auto|/tests/statsCases/filename/dynamic.js", + "issuer": "javascript/auto|/tests/statsCases/filename/index.js", + "issuerId": "2", + "issuerName": "./index.js", + "issuerPath": [ + { + "id": "2", + "identifier": "javascript/auto|/tests/statsCases/filename/index.js", + "name": "./index.js", + }, + ], + "moduleType": "javascript/auto", + "name": "./dynamic.js", + "size": 32, + "type": "module", + }, + ], "names": [], + "parents": [ + "main", + ], + "siblings": [], "size": 32, "type": "chunk", }, { + "children": [ + "dynamic_js", + ], "entry": true, "files": [ "main.xxxx.js", ], "id": "main", "initial": true, + "modules": [ + { + "chunks": [ + "main", + ], + "id": "2", + "identifier": "javascript/auto|/tests/statsCases/filename/index.js", + "issuerPath": [], + "moduleType": "javascript/auto", + "name": "./index.js", + "size": 38, + "type": "module", + }, + ], "names": [ "main", ], + "parents": [], + "siblings": [], "size": 38, "type": "chunk", }, @@ -93,9 +140,6 @@ exports[`StatsTestCases should print correct stats for filename 1`] = ` "issuerPath": [], "moduleType": "javascript/auto", "name": "./index.js", - "reasons": [ - {}, - ], "size": 38, "type": "module", }, @@ -117,13 +161,6 @@ exports[`StatsTestCases should print correct stats for filename 1`] = ` ], "moduleType": "javascript/auto", "name": "./dynamic.js", - "reasons": [ - { - "moduleId": "2", - "moduleIdentifier": "javascript/auto|/tests/statsCases/filename/index.js", - "moduleName": "./index.js", - }, - ], "size": 32, "type": "module", }, @@ -156,11 +193,11 @@ exports[`StatsTestCases should print correct stats for filename 2`] = ` dynamic_js.xxxx.js 218 bytes dynamic_js [emitted] Entrypoint main = main.xxxx.js chunk {dynamic_js} dynamic_js.xxxx.js 32 bytes + [471] ./dynamic.js 32 bytes {dynamic_js} chunk {main} main.xxxx.js (main) 38 bytes [entry] + [2] ./index.js 38 bytes {main} [2] ./index.js 38 bytes {main} - -[471] ./dynamic.js 32 bytes {dynamic_js} - [2]" +[471] ./dynamic.js 32 bytes {dynamic_js}" `; exports[`StatsTestCases should print correct stats for hot+production 1`] = ` @@ -190,15 +227,32 @@ exports[`StatsTestCases should print correct stats for hot+production 1`] = ` }, "chunks": [ { + "children": [], "entry": true, "files": [ "bundle.js", ], "id": "main", "initial": true, + "modules": [ + { + "chunks": [ + "main", + ], + "id": "2", + "identifier": "javascript/auto|/tests/statsCases/hot+production/index.js", + "issuerPath": [], + "moduleType": "javascript/auto", + "name": "./index.js", + "size": 25, + "type": "module", + }, + ], "names": [ "main", ], + "parents": [], + "siblings": [], "size": 25, "type": "chunk", }, @@ -231,9 +285,6 @@ exports[`StatsTestCases should print correct stats for hot+production 1`] = ` "issuerPath": [], "moduleType": "javascript/auto", "name": "./index.js", - "reasons": [ - {}, - ], "size": 25, "type": "module", }, @@ -265,8 +316,8 @@ exports[`StatsTestCases should print correct stats for hot+production 2`] = ` bundle.js 8.81 KiB main [emitted] main Entrypoint main = bundle.js chunk {main} bundle.js (main) 25 bytes [entry] -[2] ./index.js 25 bytes {main} - " + [2] ./index.js 25 bytes {main} +[2] ./index.js 25 bytes {main}" `; exports[`StatsTestCases should print correct stats for identifier-let-strict-mode 1`] = ` @@ -1022,15 +1073,53 @@ exports[`StatsTestCases should print correct stats for resolve-overflow 1`] = ` }, "chunks": [ { + "children": [], "entry": true, "files": [ "bundle.js", ], "id": "main", "initial": true, + "modules": [ + { + "chunks": [ + "main", + ], + "id": "2", + "identifier": "javascript/auto|/tests/statsCases/resolve-overflow/index.js", + "issuerPath": [], + "moduleType": "javascript/auto", + "name": "./index.js", + "size": 51, + "type": "module", + }, + { + "chunks": [ + "main", + ], + "id": "259", + "identifier": "missing|/tests/statsCases/resolve-overflowcycle-alias/acycle-alias/a", + "issuer": "javascript/auto|/tests/statsCases/resolve-overflow/index.js", + "issuerId": "2", + "issuerName": "./index.js", + "issuerPath": [ + { + "id": "2", + "identifier": "javascript/auto|/tests/statsCases/resolve-overflow/index.js", + "name": "./index.js", + }, + ], + "moduleType": "javascript/auto", + "name": "/tests/statsCases/resolve-overflowcycle-alias/a (missing)", + "size": 160, + "type": "module", + }, + ], "names": [ "main", ], + "parents": [], + "siblings": [], "size": 211, "type": "chunk", }, @@ -1074,9 +1163,6 @@ exports[`StatsTestCases should print correct stats for resolve-overflow 1`] = ` "issuerPath": [], "moduleType": "javascript/auto", "name": "./index.js", - "reasons": [ - {}, - ], "size": 51, "type": "module", }, @@ -1098,13 +1184,6 @@ exports[`StatsTestCases should print correct stats for resolve-overflow 1`] = ` ], "moduleType": "javascript/auto", "name": "/tests/statsCases/resolve-overflowcycle-alias/a (missing)", - "reasons": [ - { - "moduleId": "2", - "moduleIdentifier": "javascript/auto|/tests/statsCases/resolve-overflow/index.js", - "moduleName": "./index.js", - }, - ], "size": 160, "type": "module", }, @@ -1137,10 +1216,10 @@ PublicPath: auto bundle.js 363 bytes main [emitted] main Entrypoint main = bundle.js chunk {main} bundle.js (main) 211 bytes [entry] + [2] ./index.js 51 bytes {main} + [259] /tests/statsCases/resolve-overflowcycle-alias/a (missing) 160 bytes {main} [2] ./index.js 51 bytes {main} - [259] /tests/statsCases/resolve-overflowcycle-alias/a (missing) 160 bytes {main} - [2] error[internal]: Resolve error ┌─ tests/statsCases/resolve-overflow/index.js:1:1 @@ -1178,15 +1257,53 @@ exports[`StatsTestCases should print correct stats for resolve-unexpected-export }, "chunks": [ { + "children": [], "entry": true, "files": [ "bundle.js", ], "id": "main", "initial": true, + "modules": [ + { + "chunks": [ + "main", + ], + "id": "2", + "identifier": "javascript/auto|/tests/statsCases/resolve-unexpected-exports-in-pkg/index.js", + "issuerPath": [], + "moduleType": "javascript/auto", + "name": "./index.js", + "size": 39, + "type": "module", + }, + { + "chunks": [ + "main", + ], + "id": "805", + "identifier": "missing|/tests/statsCases/resolve-unexpected-exports-in-pkgpkg-apkg-a", + "issuer": "javascript/auto|/tests/statsCases/resolve-unexpected-exports-in-pkg/index.js", + "issuerId": "2", + "issuerName": "./index.js", + "issuerPath": [ + { + "id": "2", + "identifier": "javascript/auto|/tests/statsCases/resolve-unexpected-exports-in-pkg/index.js", + "name": "./index.js", + }, + ], + "moduleType": "javascript/auto", + "name": "/tests/statsCases/resolve-unexpected-exports-in-pkgpkg-a (missing)", + "size": 160, + "type": "module", + }, + ], "names": [ "main", ], + "parents": [], + "siblings": [], "size": 199, "type": "chunk", }, @@ -1225,9 +1342,6 @@ exports[`StatsTestCases should print correct stats for resolve-unexpected-export "issuerPath": [], "moduleType": "javascript/auto", "name": "./index.js", - "reasons": [ - {}, - ], "size": 39, "type": "module", }, @@ -1249,13 +1363,6 @@ exports[`StatsTestCases should print correct stats for resolve-unexpected-export ], "moduleType": "javascript/auto", "name": "/tests/statsCases/resolve-unexpected-exports-in-pkgpkg-a (missing)", - "reasons": [ - { - "moduleId": "2", - "moduleIdentifier": "javascript/auto|/tests/statsCases/resolve-unexpected-exports-in-pkg/index.js", - "moduleName": "./index.js", - }, - ], "size": 160, "type": "module", }, @@ -1287,10 +1394,10 @@ exports[`StatsTestCases should print correct stats for resolve-unexpected-export bundle.js 972 bytes main [emitted] main Entrypoint main = bundle.js chunk {main} bundle.js (main) 199 bytes [entry] + [2] ./index.js 39 bytes {main} + [805] /tests/statsCases/resolve-unexpected-exports-in-pkgpkg-a (missing) 160 bytes {main} [2] ./index.js 39 bytes {main} - [805] /tests/statsCases/resolve-unexpected-exports-in-pkgpkg-a (missing) 160 bytes {main} - [2] Export should be relative path and start with "./", but got ../../index.js " @@ -1323,15 +1430,32 @@ exports[`StatsTestCases should print correct stats for simple 1`] = ` }, "chunks": [ { + "children": [], "entry": true, "files": [ "bundle.js", ], "id": "main", "initial": true, + "modules": [ + { + "chunks": [ + "main", + ], + "id": "2", + "identifier": "javascript/auto|/tests/statsCases/simple/index.js", + "issuerPath": [], + "moduleType": "javascript/auto", + "name": "./index.js", + "size": 26, + "type": "module", + }, + ], "names": [ "main", ], + "parents": [], + "siblings": [], "size": 26, "type": "chunk", }, @@ -1364,9 +1488,6 @@ exports[`StatsTestCases should print correct stats for simple 1`] = ` "issuerPath": [], "moduleType": "javascript/auto", "name": "./index.js", - "reasons": [ - {}, - ], "size": 26, "type": "module", }, @@ -1398,6 +1519,6 @@ exports[`StatsTestCases should print correct stats for simple 2`] = ` bundle.js 317 bytes main [emitted] main Entrypoint main = bundle.js chunk {main} bundle.js (main) 26 bytes [entry] -[2] ./index.js 26 bytes {main} - " + [2] ./index.js 26 bytes {main} +[2] ./index.js 26 bytes {main}" `;