Skip to content

Commit 6f19caa

Browse files
authored
fix: concatenation should merge module’s chunk init fragments (#7504)
1 parent 840de57 commit 6f19caa

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

crates/rspack_core/src/concatenated_module.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1655,11 +1655,16 @@ impl ConcatenatedModule {
16551655
let codegen_res = module.code_generation(compilation, runtime, Some(concatenation_scope))?;
16561656
let CodeGenerationResult {
16571657
mut inner,
1658-
chunk_init_fragments,
1658+
mut chunk_init_fragments,
16591659
runtime_requirements,
16601660
concatenation_scope,
16611661
..
16621662
} = codegen_res;
1663+
1664+
if let Some(fragments) = codegen_res.data.get::<ChunkInitFragments>() {
1665+
chunk_init_fragments.extend(fragments.iter().cloned());
1666+
}
1667+
16631668
let concatenation_scope = concatenation_scope.expect("should have concatenation_scope");
16641669
let source = inner
16651670
.remove(&SourceType::JavaScript)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const fileURLToPath = "";
2+
const file = __filename;
3+
const dir = __dirname;
4+
const dir2 = `${__dirname}/`;
5+
6+
export { file, dir, dir2 };
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { dir, dir2, file } from './file.js'
2+
3+
it("should generate correct __dirname", () => {
4+
expect(dir).toMatch(/[\\/]node-shims-in-concatenated-module$/);
5+
expect(dir2).toMatch(/[\\/]node-shims-in-concatenated-module\/$/);
6+
});
7+
8+
it("should generate correct __filename", () => {
9+
expect(file).toMatch(/[\\/]main.mjs$/);
10+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/** @type {import("@rspack/core").Configuration} */
2+
module.exports = {
3+
entry: {
4+
main: "./index.js"
5+
},
6+
output: {
7+
filename: "[name].mjs",
8+
module: true
9+
},
10+
experiments: {
11+
outputModule: true
12+
},
13+
target: "node14"
14+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
findBundle() {
3+
return "./main.mjs";
4+
}
5+
};

0 commit comments

Comments
 (0)