Skip to content

Commit

Permalink
fix: concatenation should merge module’s chunk init fragments (web-in…
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework authored Aug 8, 2024
1 parent 840de57 commit 6f19caa
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
7 changes: 6 additions & 1 deletion crates/rspack_core/src/concatenated_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1655,11 +1655,16 @@ impl ConcatenatedModule {
let codegen_res = module.code_generation(compilation, runtime, Some(concatenation_scope))?;
let CodeGenerationResult {
mut inner,
chunk_init_fragments,
mut chunk_init_fragments,
runtime_requirements,
concatenation_scope,
..
} = codegen_res;

if let Some(fragments) = codegen_res.data.get::<ChunkInitFragments>() {
chunk_init_fragments.extend(fragments.iter().cloned());
}

let concatenation_scope = concatenation_scope.expect("should have concatenation_scope");
let source = inner
.remove(&SourceType::JavaScript)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const fileURLToPath = "";
const file = __filename;
const dir = __dirname;
const dir2 = `${__dirname}/`;

export { file, dir, dir2 };
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { dir, dir2, file } from './file.js'

it("should generate correct __dirname", () => {
expect(dir).toMatch(/[\\/]node-shims-in-concatenated-module$/);
expect(dir2).toMatch(/[\\/]node-shims-in-concatenated-module\/$/);
});

it("should generate correct __filename", () => {
expect(file).toMatch(/[\\/]main.mjs$/);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/** @type {import("@rspack/core").Configuration} */
module.exports = {
entry: {
main: "./index.js"
},
output: {
filename: "[name].mjs",
module: true
},
experiments: {
outputModule: true
},
target: "node14"
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
findBundle() {
return "./main.mjs";
}
};

0 comments on commit 6f19caa

Please sign in to comment.