Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: generate params of runtime module #8000

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class IsolateRuntimeModule extends RuntimeModule {
super("mock-isolate");
}

generate(compilation) {
generate() {
return `
__webpack_require__.mock = function() {
return someGlobalValue;
Expand All @@ -23,7 +23,7 @@ class NonIsolateRuntimeModule extends RuntimeModule {
return false;
}

generate(compilation) {
generate() {
return `
var someGlobalValue = "isolated";
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class MockNormalRuntimeModule extends RuntimeModule {
super("mock-normal", RuntimeModule.STAGE_NORMAL);
}

generate(compilation) {
generate() {
return `__webpack_require__.mockNormal = "normal";`;
}
}
Expand All @@ -15,7 +15,7 @@ class MockTriggerRuntimeModule extends RuntimeModule {
super("mock-trigger", RuntimeModule.STAGE_TRIGGER);
}

generate(compilation) {
generate() {
return `__webpack_require__.mockTrigger = "trigger";`;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class MockRuntimeModule extends RuntimeModule {
super("mock");
}

generate(compilation) {
generate() {
const chunkIdToName = this.chunk.getChunkMaps(false).name;
const chunkNameToId = Object.fromEntries(
Object.entries(chunkIdToName).map(([chunkId, chunkName]) => [
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack/etc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -14639,7 +14639,7 @@ export class RuntimeModule {
// (undocumented)
fullHash: boolean;
// (undocumented)
generate(compilation: Compilation): string;
generate(): string;
// (undocumented)
identifier(): string;
// (undocumented)
Expand Down
4 changes: 2 additions & 2 deletions packages/rspack/src/RuntimeModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class RuntimeModule {
return {
name: module.name,
stage: module.stage,
generator: () => module.generate(compilation),
generator: module.generate.bind(module),
cacheable: !(module.fullHash || module.dependentHash),
isolate: module.shouldIsolate()
};
Expand Down Expand Up @@ -67,7 +67,7 @@ export class RuntimeModule {
return true;
}

generate(compilation: Compilation): string {
generate(): string {
throw new Error(
`Should implement "generate" method of runtime module "${this.name}"`
);
Expand Down
3 changes: 2 additions & 1 deletion website/docs/en/api/javascript-api/compilation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,8 @@ module.exports = {
super('custom');
}

generate(compilation) {
generate() {
const compilation = this.compilation;
return `
__webpack_require__.mock = function() {
// ...
Expand Down
3 changes: 2 additions & 1 deletion website/docs/en/api/plugin-api/compilation-hooks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,8 @@ module.exports = {
super('custom');
}

generate(compilation) {
generate() {
const compilation = this.compilation;
return `
__webpack_require__.mock = function(file) {
return ${RuntimeGlobals.publicPath} + "/subpath/" + file;
Expand Down
3 changes: 2 additions & 1 deletion website/docs/zh/api/javascript-api/compilation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,8 @@ module.exports = {
super('custom', RuntimeModule.STAGE_NORMAL);
}

generate(compilation) {
generate() {
const compilation = this.compilation;
return `
__webpack_require__.mock = function() {
// ...
Expand Down
3 changes: 2 additions & 1 deletion website/docs/zh/api/plugin-api/compilation-hooks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,8 @@ module.exports = {
super('custom');
}

generate(compilation) {
generate() {
const compilation = this.compilation;
return `
__webpack_require__.mock = function(file) {
return ${RuntimeGlobals.publicPath} + "/subpath/" + file;
Expand Down
Loading