diff --git a/crates/rspack_plugin_runtime/src/runtime_module/create_script_url.rs b/crates/rspack_plugin_runtime/src/runtime_module/create_script_url.rs index 5915782ce1f..1f615a9a71d 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/create_script_url.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/create_script_url.rs @@ -37,7 +37,7 @@ impl RuntimeModule for CreateScriptUrlRuntimeModule { RuntimeGlobals::GET_TRUSTED_TYPES_POLICY ) } else { - "'{url}'".to_string() + "url".to_string() } )) .boxed(), diff --git a/packages/rspack-test-tools/src/compare/replace-runtime-module-name.ts b/packages/rspack-test-tools/src/compare/replace-runtime-module-name.ts index c1bd1de0b09..fad827b0105 100644 --- a/packages/rspack-test-tools/src/compare/replace-runtime-module-name.ts +++ b/packages/rspack-test-tools/src/compare/replace-runtime-module-name.ts @@ -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", diff --git a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-module/create-script-url#with-trusted-types/rspack.config.js b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-module/create-script-url#with-trusted-types/rspack.config.js new file mode 100644 index 00000000000..d4416268aff --- /dev/null +++ b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-module/create-script-url#with-trusted-types/rspack.config.js @@ -0,0 +1,10 @@ +/** @type {import("@rspack/core").Configuration} */ +module.exports = { + output: { + trustedTypes: "customPolicyName", + chunkLoading: "import-scripts" + }, + entry: { + other: "./src/index" + } +}; diff --git a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-module/create-script-url#with-trusted-types/src/index.js b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-module/create-script-url#with-trusted-types/src/index.js new file mode 100644 index 00000000000..c542f2b1368 --- /dev/null +++ b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-module/create-script-url#with-trusted-types/src/index.js @@ -0,0 +1,5 @@ +const worker = new Worker(new URL("./worker.js", import.meta.url), { + type: "module", + name: "worker1" +}); +worker.postMessage("ok"); \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-module/create-script-url#with-trusted-types/src/module.js b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-module/create-script-url#with-trusted-types/src/module.js new file mode 100644 index 00000000000..3a0b527ffb8 --- /dev/null +++ b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-module/create-script-url#with-trusted-types/src/module.js @@ -0,0 +1,3 @@ +export function upper(str) { + return str.toUpperCase(); +} diff --git a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-module/create-script-url#with-trusted-types/src/worker.js b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-module/create-script-url#with-trusted-types/src/worker.js new file mode 100644 index 00000000000..fc12b94a652 --- /dev/null +++ b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-module/create-script-url#with-trusted-types/src/worker.js @@ -0,0 +1,4 @@ +onmessage = async event => { + const { upper } = await import("./module"); + postMessage(`data: ${upper(event.data)}, thanks`); +}; diff --git a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-module/create-script-url#with-trusted-types/test.config.js b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-module/create-script-url#with-trusted-types/test.config.js new file mode 100644 index 00000000000..cb024449f51 --- /dev/null +++ b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-module/create-script-url#with-trusted-types/test.config.js @@ -0,0 +1,5 @@ +/** @type {import("../../..").TDiffCaseConfig} */ +module.exports = { + modules: false, + runtimeModules: true +}; diff --git a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-module/create-script-url#with-trusted-types/webpack.config.js b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-module/create-script-url#with-trusted-types/webpack.config.js new file mode 100644 index 00000000000..7296ad4971c --- /dev/null +++ b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-module/create-script-url#with-trusted-types/webpack.config.js @@ -0,0 +1,10 @@ +/** @type {import("webpack").Configuration} */ +module.exports = { + output: { + trustedTypes: "customPolicyName", + chunkLoading: "import-scripts" + }, + entry: { + other: "./src/index" + } +}; diff --git a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-module/create-script-url/rspack.config.js b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-module/create-script-url/rspack.config.js new file mode 100644 index 00000000000..8db8eb715d1 --- /dev/null +++ b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-module/create-script-url/rspack.config.js @@ -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); + }); + }); + } + }] +}; diff --git a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-module/create-script-url/src/index.js b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-module/create-script-url/src/index.js new file mode 100644 index 00000000000..c542f2b1368 --- /dev/null +++ b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-module/create-script-url/src/index.js @@ -0,0 +1,5 @@ +const worker = new Worker(new URL("./worker.js", import.meta.url), { + type: "module", + name: "worker1" +}); +worker.postMessage("ok"); \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-module/create-script-url/src/module.js b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-module/create-script-url/src/module.js new file mode 100644 index 00000000000..3a0b527ffb8 --- /dev/null +++ b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-module/create-script-url/src/module.js @@ -0,0 +1,3 @@ +export function upper(str) { + return str.toUpperCase(); +} diff --git a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-module/create-script-url/src/worker.js b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-module/create-script-url/src/worker.js new file mode 100644 index 00000000000..fc12b94a652 --- /dev/null +++ b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-module/create-script-url/src/worker.js @@ -0,0 +1,4 @@ +onmessage = async event => { + const { upper } = await import("./module"); + postMessage(`data: ${upper(event.data)}, thanks`); +}; diff --git a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-module/create-script-url/test.config.js b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-module/create-script-url/test.config.js new file mode 100644 index 00000000000..cb024449f51 --- /dev/null +++ b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-module/create-script-url/test.config.js @@ -0,0 +1,5 @@ +/** @type {import("../../..").TDiffCaseConfig} */ +module.exports = { + modules: false, + runtimeModules: true +}; diff --git a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-module/create-script-url/webpack.config.js b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-module/create-script-url/webpack.config.js new file mode 100644 index 00000000000..8effeb6ace7 --- /dev/null +++ b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-module/create-script-url/webpack.config.js @@ -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); + }); + }); + } + }] +};