From 9127603120229be3b3ded5a602d30f4a5e50615a Mon Sep 17 00:00:00 2001 From: jserfeng <1114550440@qq.com> Date: Sun, 5 Jan 2025 04:40:04 +0800 Subject: [PATCH] chore: update --- .../build_chunk_graph/new_code_splitter.rs | 49 ++++++++++++++----- .../StatsTestCases.basictest.js.snap | 4 +- .../webpack-test/statsCases/prefetch/inner.js | 1 + .../statsCases/prefetch/test.config.js | 1 - 4 files changed, 40 insertions(+), 15 deletions(-) diff --git a/crates/rspack_core/src/build_chunk_graph/new_code_splitter.rs b/crates/rspack_core/src/build_chunk_graph/new_code_splitter.rs index f8209927de0e..e90ef05712f6 100644 --- a/crates/rspack_core/src/build_chunk_graph/new_code_splitter.rs +++ b/crates/rspack_core/src/build_chunk_graph/new_code_splitter.rs @@ -786,7 +786,6 @@ impl CodeSplitter { .expect("should have module") .pre_order_index = Some(idx); } - for (m, idx) in post_order_indices { module_graph .module_graph_module_by_identifier_mut(&m) @@ -1516,23 +1515,13 @@ fn merge_chunk(chunk: ChunkDesc, existing_chunk: &mut ChunkDesc) -> Result<()> { (Some(_), None) => {} (Some(existing), Some(other)) => *existing = merge_runtime(existing, &other), } - - // for (module, idx) in &mut existing_chunk.pre_order_indices { - // if let Some(other_idx) = chunk.pre_order_indices.get(module) { - // *idx = std::cmp::min(*idx, *other_idx); - // } - // } - // for (module, idx) in &mut existing_chunk.post_order_indices { - // if let Some(other_idx) = chunk.post_order_indices.get(module) { - // *idx = std::cmp::min(*idx, *other_idx); - // } - // } } (ChunkDesc::Chunk(existing_chunk), ChunkDesc::Chunk(chunk)) => { existing_chunk.modules_ordinal |= chunk.modules_ordinal; existing_chunk.chunk_modules.extend(chunk.chunk_modules); existing_chunk.incoming_blocks.extend(chunk.incoming_blocks); existing_chunk.outgoing_blocks.extend(chunk.outgoing_blocks); + match (&mut existing_chunk.runtime, chunk.runtime) { (None, None) => {} (None, Some(other)) => existing_chunk.runtime = Some(other), @@ -1540,6 +1529,42 @@ fn merge_chunk(chunk: ChunkDesc, existing_chunk: &mut ChunkDesc) -> Result<()> { (Some(existing), Some(other)) => *existing = merge_runtime(existing, &other), } + match (&mut existing_chunk.options, chunk.options) { + (None, None) => {} + (Some(_), None) => {} + (None, Some(options)) => { + existing_chunk.options = Some(options); + } + (Some(existing), Some(other)) => { + match (&mut existing.prefetch_order, other.prefetch_order) { + (None, None) => {} + (Some(_), None) => {} + (None, Some(other)) => existing.prefetch_order = Some(other), + (Some(existing), Some(other)) => { + *existing = std::cmp::max(*existing, other); + } + } + + match (&mut existing.preload_order, other.preload_order) { + (None, None) => {} + (Some(_), None) => {} + (None, Some(other)) => existing.preload_order = Some(other), + (Some(existing), Some(other)) => { + *existing = std::cmp::max(*existing, other); + } + } + + match (&mut existing.fetch_priority, other.fetch_priority) { + (None, None) => {} + (Some(_), None) => {} + (None, Some(other)) => existing.fetch_priority = Some(other), + (Some(existing), Some(other)) => { + *existing = std::cmp::max(*existing, other); + } + } + } + } + // for (module, idx) in &mut existing_chunk.pre_order_indices { // if let Some(other_idx) = chunk.pre_order_indices.get(module) { // *idx = std::cmp::min(*idx, *other_idx); diff --git a/tests/webpack-test/__snapshots__/StatsTestCases.basictest.js.snap b/tests/webpack-test/__snapshots__/StatsTestCases.basictest.js.snap index 63e73a37982f..9befdd56cfe9 100644 --- a/tests/webpack-test/__snapshots__/StatsTestCases.basictest.js.snap +++ b/tests/webpack-test/__snapshots__/StatsTestCases.basictest.js.snap @@ -1205,7 +1205,7 @@ exports[`StatsTestCases should print correct stats for prefetch 1`] = ` "asset main.js 13.9 KiB {909} [emitted] (name: main) asset prefetched.js 554 bytes {674} [emitted] (name: prefetched) asset inner2.js 130 bytes {857} [emitted] (name: inner2) -asset inner.js 102 bytes {481} [emitted] (name: inner) +asset inner.js 103 bytes {481} [emitted] (name: inner) asset normal.js 102 bytes {615} [emitted] (name: normal) asset prefetched2.js 102 bytes {424} [emitted] (name: prefetched2) asset prefetched3.js 102 bytes {182} [emitted] (name: prefetched3) @@ -1215,7 +1215,7 @@ chunk {182} (runtime: main) prefetched3.js (prefetched3) 1 bytes <{909}> [render chunk {424} (runtime: main) prefetched2.js (prefetched2) 1 bytes <{909}> [rendered] chunk {481} (runtime: main) inner.js (inner) 1 bytes <{674}> [rendered] chunk {615} (runtime: main) normal.js (normal) 1 bytes <{909}> [rendered] -chunk {674} (runtime: main) prefetched.js (prefetched) 228 bytes <{909}> >{481}< >{857}< (prefetch: {481}) [rendered] +chunk {674} (runtime: main) prefetched.js (prefetched) 228 bytes <{909}> >{481}< >{857}< (prefetch: {857} {481}) [rendered] chunk {857} (runtime: main) inner2.js (inner2) 2 bytes <{674}> [rendered] chunk {909} (runtime: main) main.js (main) 436 bytes (javascript) 11 KiB (runtime) >{182}< >{424}< >{615}< >{674}< (prefetch: {424} {674} {182}) [entry] [rendered]" `; diff --git a/tests/webpack-test/statsCases/prefetch/inner.js b/tests/webpack-test/statsCases/prefetch/inner.js index e69de29bb2d1..8b137891791f 100644 --- a/tests/webpack-test/statsCases/prefetch/inner.js +++ b/tests/webpack-test/statsCases/prefetch/inner.js @@ -0,0 +1 @@ + diff --git a/tests/webpack-test/statsCases/prefetch/test.config.js b/tests/webpack-test/statsCases/prefetch/test.config.js index f7cbf1136691..fe6f94bea479 100644 --- a/tests/webpack-test/statsCases/prefetch/test.config.js +++ b/tests/webpack-test/statsCases/prefetch/test.config.js @@ -3,7 +3,6 @@ const path = require("path"); module.exports = { validate(stats, error, actual) { - expect(diffStats(actual, path.basename(__dirname))) .toMatchInlineSnapshot(` "- Expected