Skip to content

Commit

Permalink
fix: return url in CreateScriptUrlRuntimeModule (web-infra-dev#8088)
Browse files Browse the repository at this point in the history
* fix: return url in CreateScriptUrlRuntimeModule

* fix: return url in CreateScriptUrlRuntimeModule

* fix: return url in CreateScriptUrlRuntimeModule
  • Loading branch information
LingyuCoder authored Oct 11, 2024
1 parent 6f08e69 commit 3153da6
Show file tree
Hide file tree
Showing 14 changed files with 89 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl RuntimeModule for CreateScriptUrlRuntimeModule {
RuntimeGlobals::GET_TRUSTED_TYPES_POLICY
)
} else {
"'{url}'".to_string()
"url".to_string()
}
))
.boxed(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const RUNTIME_MODULE_NAME_MAPPING = {
"webpack/runtime/compat": "webpack/runtime/compat",
"webpack/runtime/create_fake_namespace_object":
"webpack/runtime/create fake namespace object",
"webpack/runtime/create_script_url":
"webpack/runtime/trusted types script url",
"webpack/runtime/create_script": "webpack/runtime/trusted types script",
"webpack/runtime/define_property_getters":
"webpack/runtime/define property getters",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** @type {import("@rspack/core").Configuration} */
module.exports = {
output: {
trustedTypes: "customPolicyName",
chunkLoading: "import-scripts"
},
entry: {
other: "./src/index"
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const worker = new Worker(new URL("./worker.js", import.meta.url), {
type: "module",
name: "worker1"
});
worker.postMessage("ok");
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function upper(str) {
return str.toUpperCase();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
onmessage = async event => {
const { upper } = await import("./module");
postMessage(`data: ${upper(event.data)}, thanks`);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @type {import("../../..").TDiffCaseConfig} */
module.exports = {
modules: false,
runtimeModules: true
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** @type {import("webpack").Configuration} */
module.exports = {
output: {
trustedTypes: "customPolicyName",
chunkLoading: "import-scripts"
},
entry: {
other: "./src/index"
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/** @type {import("@rspack/core").Configuration} */
module.exports = {
entry: {
other: "./src/index"
},
plugins: [{
apply(compiler) {
const { RuntimeGlobals } = compiler.webpack;
compiler.hooks.thisCompilation.tap("testPlugin", (compilation) => {
compilation.hooks.additionalTreeRuntimeRequirements.tap("testPlugin", (chunk, set) => {
set.add(RuntimeGlobals.createScriptUrl);
});
});
}
}]
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const worker = new Worker(new URL("./worker.js", import.meta.url), {
type: "module",
name: "worker1"
});
worker.postMessage("ok");
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function upper(str) {
return str.toUpperCase();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
onmessage = async event => {
const { upper } = await import("./module");
postMessage(`data: ${upper(event.data)}, thanks`);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @type {import("../../..").TDiffCaseConfig} */
module.exports = {
modules: false,
runtimeModules: true
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/** @type {import("webpack").Configuration} */
module.exports = {
entry: {
other: "./src/index"
},
plugins: [{
apply(compiler) {
const { RuntimeGlobals } = compiler.webpack;
compiler.hooks.thisCompilation.tap("testPlugin", (compilation) => {
compilation.hooks.additionalTreeRuntimeRequirements.tap("testPlugin", (chunk, set) => {
set.add(RuntimeGlobals.createScriptUrl);
});
});
}
}]
};

0 comments on commit 3153da6

Please sign in to comment.