Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
JSerFeng committed Jan 6, 2025
1 parent 10f9696 commit 9127603
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 15 deletions.
49 changes: 37 additions & 12 deletions crates/rspack_core/src/build_chunk_graph/new_code_splitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -1516,30 +1515,56 @@ 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),
(Some(_), None) => {}
(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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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]"
`;
Expand Down
1 change: 1 addition & 0 deletions tests/webpack-test/statsCases/prefetch/inner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 0 additions & 1 deletion tests/webpack-test/statsCases/prefetch/test.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const path = require("path");

module.exports = {
validate(stats, error, actual) {

expect(diffStats(actual, path.basename(__dirname)))
.toMatchInlineSnapshot(`
"- Expected
Expand Down

0 comments on commit 9127603

Please sign in to comment.