From ab8f3fe2b8cc7e01c9539953c601b4ae039be7c1 Mon Sep 17 00:00:00 2001 From: qixuan <58852732+GiveMe-A-Name@users.noreply.github.com> Date: Thu, 27 Feb 2025 10:24:43 +0800 Subject: [PATCH] feat: render runtime template with dojang (#9450) - render get_trusted_types_policy with dojang - render global with dojang - render has_own_property with dojang - render rspack_version with dojang --- .../get_trusted_types_policy.rs | 40 +++++++++---------- .../src/runtime_module/global.rs | 13 +++++- .../src/runtime_module/has_own_property.rs | 13 +++++- .../src/runtime_module/rspack_version.rs | 26 +++++++----- ...policy.js => get_trusted_types_policy.ejs} | 10 ++--- .../runtime_module/runtime/get_version.ejs | 1 + .../src/runtime_module/runtime/get_version.js | 3 -- .../runtime/{global.js => global.ejs} | 4 +- .../runtime/has_own_property.ejs | 1 + .../runtime/has_own_property.js | 3 -- .../tests/__snapshots__/Config.test.js.snap | 15 ++----- .../NewCodeSplitting-config.test.js.snap | 15 ++----- ...NewCodeSplitting-stats-output.test.js.snap | 16 ++++---- .../tests/__snapshots__/StatsAPI.test.js.snap | 20 +++++----- .../__snapshots__/StatsOutput.test.js.snap | 16 ++++---- .../variant/__snapshots__/output.snap.txt | 2 +- .../rsdoctor/assets/rspack.config.js | 4 +- .../duplicate/output.snap.txt | 5 +-- .../request/output.snap.txt | 5 +-- .../resource/output.snap.txt | 5 +-- .../resource/output.snap.txt | 5 +-- .../tests/statsAPICases/asset-info.js | 2 +- .../build-time-executed-runtime.js | 4 +- .../tests/statsAPICases/exports.js | 4 +- .../tests/statsAPICases/nested-modules.js | 4 +- .../StatsTestCases.basictest.js.snap | 2 +- 26 files changed, 113 insertions(+), 125 deletions(-) rename crates/rspack_plugin_runtime/src/runtime_module/runtime/{get_trusted_types_policy.js => get_trusted_types_policy.ejs} (50%) create mode 100644 crates/rspack_plugin_runtime/src/runtime_module/runtime/get_version.ejs delete mode 100644 crates/rspack_plugin_runtime/src/runtime_module/runtime/get_version.js rename crates/rspack_plugin_runtime/src/runtime_module/runtime/{global.js => global.ejs} (78%) create mode 100644 crates/rspack_plugin_runtime/src/runtime_module/runtime/has_own_property.ejs delete mode 100644 crates/rspack_plugin_runtime/src/runtime_module/runtime/has_own_property.js diff --git a/crates/rspack_plugin_runtime/src/runtime_module/get_trusted_types_policy.rs b/crates/rspack_plugin_runtime/src/runtime_module/get_trusted_types_policy.rs index c45498caa066..abc15d491a3a 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/get_trusted_types_policy.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/get_trusted_types_policy.rs @@ -1,4 +1,3 @@ -use cow_utils::CowUtils; use rspack_collections::Identifier; use rspack_core::{ impl_runtime_module, @@ -29,6 +28,13 @@ impl RuntimeModule for GetTrustedTypesPolicyRuntimeModule { self.id } + fn template(&self) -> Vec<(String, String)> { + vec![( + self.id.to_string(), + include_str!("runtime/get_trusted_types_policy.ejs").to_string(), + )] + } + fn generate(&self, compilation: &Compilation) -> rspack_error::Result { let trusted_types = compilation .options @@ -45,10 +51,6 @@ impl RuntimeModule for GetTrustedTypesPolicyRuntimeModule { OnPolicyCreationFailure::Continue ); - let result = include_str!("runtime/get_trusted_types_policy.js").cow_replace( - "$policyName$", - &trusted_types.policy_name.clone().unwrap_or_default(), - ); let mut policy_content: Vec = Vec::new(); if create_script { policy_content.push( @@ -88,22 +90,18 @@ impl RuntimeModule for GetTrustedTypesPolicyRuntimeModule { } else { "".to_string() }; - Ok( - RawStringSource::from( - result - .cow_replace("$policyContent$", policy_content.join(",\n").as_ref()) - .cow_replace( - "$wrapPolicyCreationTryCatchStart$", - wrap_policy_creation_try_catch_start, - ) - .cow_replace( - "$wrapPolicyCreationTryCatchEnd$", - &wrap_policy_creation_try_catch_end, - ) - .into_owned(), - ) - .boxed(), - ) + + let source = compilation.runtime_template.render( + &self.id, + Some(serde_json::json!({ + "_policy_content": policy_content.join(",\n"), + "_wrap_policy_creation_try_catch_start": wrap_policy_creation_try_catch_start, + "_warp_policy_creation_try_catch_end": wrap_policy_creation_try_catch_end, + "_policy_name": &trusted_types.policy_name.clone().unwrap_or_default(), + })), + )?; + + Ok(RawStringSource::from(source).boxed()) } fn attach(&mut self, chunk: ChunkUkey) { diff --git a/crates/rspack_plugin_runtime/src/runtime_module/global.rs b/crates/rspack_plugin_runtime/src/runtime_module/global.rs index f41383e66465..c246fa93ce40 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/global.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/global.rs @@ -22,7 +22,16 @@ impl RuntimeModule for GlobalRuntimeModule { self.id } - fn generate(&self, _compilation: &Compilation) -> rspack_error::Result { - Ok(RawStringSource::from_static(include_str!("runtime/global.js")).boxed()) + fn template(&self) -> Vec<(String, String)> { + vec![( + self.id.to_string(), + include_str!("runtime/global.ejs").to_string(), + )] + } + + fn generate(&self, compilation: &Compilation) -> rspack_error::Result { + let source = compilation.runtime_template.render(&self.id, None)?; + + Ok(RawStringSource::from(source).boxed()) } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/has_own_property.rs b/crates/rspack_plugin_runtime/src/runtime_module/has_own_property.rs index a570ef6f6eec..80ddd880ee5d 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/has_own_property.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/has_own_property.rs @@ -22,7 +22,16 @@ impl RuntimeModule for HasOwnPropertyRuntimeModule { self.id } - fn generate(&self, _compilation: &Compilation) -> rspack_error::Result { - Ok(RawStringSource::from_static(include_str!("runtime/has_own_property.js")).boxed()) + fn template(&self) -> Vec<(String, String)> { + vec![( + self.id.to_string(), + include_str!("runtime/has_own_property.ejs").to_string(), + )] + } + + fn generate(&self, compilation: &Compilation) -> rspack_error::Result { + let source = compilation.runtime_template.render(&self.id, None)?; + + Ok(RawStringSource::from(source).boxed()) } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/rspack_version.rs b/crates/rspack_plugin_runtime/src/runtime_module/rspack_version.rs index 67ab51f9b854..cf01de91acb0 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/rspack_version.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/rspack_version.rs @@ -1,4 +1,3 @@ -use cow_utils::CowUtils; use rspack_collections::Identifier; use rspack_core::{ impl_runtime_module, @@ -24,14 +23,21 @@ impl RuntimeModule for RspackVersionRuntimeModule { self.id } - fn generate(&self, _: &Compilation) -> rspack_error::Result { - Ok( - RawStringSource::from( - include_str!("runtime/get_version.js") - .cow_replace("$VERSION$", &self.version) - .into_owned(), - ) - .boxed(), - ) + fn template(&self) -> Vec<(String, String)> { + vec![( + self.id.to_string(), + include_str!("runtime/get_version.ejs").to_string(), + )] + } + + fn generate(&self, compilation: &Compilation) -> rspack_error::Result { + let source = compilation.runtime_template.render( + &self.id, + Some(serde_json::json!({ + "_version": format!("\"{}\"", &self.version), + })), + )?; + + Ok(RawStringSource::from(source).boxed()) } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/runtime/get_trusted_types_policy.js b/crates/rspack_plugin_runtime/src/runtime_module/runtime/get_trusted_types_policy.ejs similarity index 50% rename from crates/rspack_plugin_runtime/src/runtime_module/runtime/get_trusted_types_policy.js rename to crates/rspack_plugin_runtime/src/runtime_module/runtime/get_trusted_types_policy.ejs index d53b92dfcd74..220bfe1f8688 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/runtime/get_trusted_types_policy.js +++ b/crates/rspack_plugin_runtime/src/runtime_module/runtime/get_trusted_types_policy.ejs @@ -1,14 +1,14 @@ var policy; -__webpack_require__.tt = function () { +<%- GET_TRUSTED_TYPES_POLICY %> = <%- basicFunction("") %> { // Create Trusted Type policy if Trusted Types are available and the policy doesn't exist yet. if (policy === undefined) { policy = { - $policyContent$ + <%- _policy_content %> }; if (typeof trustedTypes !== "undefined" && trustedTypes.createPolicy) { - $wrapPolicyCreationTryCatchStart$ - policy = trustedTypes.createPolicy("$policyName$", policy); - $wrapPolicyCreationTryCatchEnd$ + <%- _wrap_policy_creation_try_catch_start %> + policy = trustedTypes.createPolicy("<%- _policy_name %>", policy); + <%- _warp_policy_creation_try_catch_end %> } } return policy; diff --git a/crates/rspack_plugin_runtime/src/runtime_module/runtime/get_version.ejs b/crates/rspack_plugin_runtime/src/runtime_module/runtime/get_version.ejs new file mode 100644 index 000000000000..3cc05edf8b17 --- /dev/null +++ b/crates/rspack_plugin_runtime/src/runtime_module/runtime/get_version.ejs @@ -0,0 +1 @@ +<%- RSPACK_VERSION %> = <%- returningFunction(_version, "") %> \ No newline at end of file diff --git a/crates/rspack_plugin_runtime/src/runtime_module/runtime/get_version.js b/crates/rspack_plugin_runtime/src/runtime_module/runtime/get_version.js deleted file mode 100644 index 1cddc9040bee..000000000000 --- a/crates/rspack_plugin_runtime/src/runtime_module/runtime/get_version.js +++ /dev/null @@ -1,3 +0,0 @@ -__webpack_require__.rv = function () { - return "$VERSION$"; -}; diff --git a/crates/rspack_plugin_runtime/src/runtime_module/runtime/global.js b/crates/rspack_plugin_runtime/src/runtime_module/runtime/global.ejs similarity index 78% rename from crates/rspack_plugin_runtime/src/runtime_module/runtime/global.js rename to crates/rspack_plugin_runtime/src/runtime_module/runtime/global.ejs index 077c7c282a3e..931fcf704de6 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/runtime/global.js +++ b/crates/rspack_plugin_runtime/src/runtime_module/runtime/global.ejs @@ -1,8 +1,8 @@ -__webpack_require__.g = (function () { +<%- GLOBAL %> = (<%- basicFunction("") %> { if (typeof globalThis === 'object') return globalThis; try { return this || new Function('return this')(); } catch (e) { if (typeof window === 'object') return window; } -})(); +})(); \ No newline at end of file diff --git a/crates/rspack_plugin_runtime/src/runtime_module/runtime/has_own_property.ejs b/crates/rspack_plugin_runtime/src/runtime_module/runtime/has_own_property.ejs new file mode 100644 index 000000000000..31c07a53899b --- /dev/null +++ b/crates/rspack_plugin_runtime/src/runtime_module/runtime/has_own_property.ejs @@ -0,0 +1 @@ +<%- HAS_OWN_PROPERTY %> = <%- returningFunction("Object.prototype.hasOwnProperty.call(obj, prop)", "obj, prop") %> \ No newline at end of file diff --git a/crates/rspack_plugin_runtime/src/runtime_module/runtime/has_own_property.js b/crates/rspack_plugin_runtime/src/runtime_module/runtime/has_own_property.js deleted file mode 100644 index 8a6d219728d0..000000000000 --- a/crates/rspack_plugin_runtime/src/runtime_module/runtime/has_own_property.js +++ /dev/null @@ -1,3 +0,0 @@ -__webpack_require__.o = function (obj, prop) { - return Object.prototype.hasOwnProperty.call(obj, prop); -}; diff --git a/packages/rspack-test-tools/tests/__snapshots__/Config.test.js.snap b/packages/rspack-test-tools/tests/__snapshots__/Config.test.js.snap index 31f4e79975b5..acb281bdb1b4 100644 --- a/packages/rspack-test-tools/tests/__snapshots__/Config.test.js.snap +++ b/packages/rspack-test-tools/tests/__snapshots__/Config.test.js.snap @@ -492,10 +492,7 @@ __webpack_require__.d = (exports, definition) => { })(); // webpack/runtime/has_own_property (() => { -__webpack_require__.o = function (obj, prop) { - return Object.prototype.hasOwnProperty.call(obj, prop); -}; - +__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) })(); /************************************************************************/ @@ -629,10 +626,7 @@ __webpack_require__.d = (exports, definition) => { })(); // webpack/runtime/has_own_property (() => { -__webpack_require__.o = function (obj, prop) { - return Object.prototype.hasOwnProperty.call(obj, prop); -}; - +__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) })(); /************************************************************************/ @@ -711,10 +705,7 @@ __webpack_require__.d = (exports, definition) => { })(); // webpack/runtime/has_own_property (() => { -__webpack_require__.o = function (obj, prop) { - return Object.prototype.hasOwnProperty.call(obj, prop); -}; - +__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) })(); /************************************************************************/ diff --git a/packages/rspack-test-tools/tests/__snapshots__/NewCodeSplitting-config.test.js.snap b/packages/rspack-test-tools/tests/__snapshots__/NewCodeSplitting-config.test.js.snap index 9663134f9f25..4e4dff9331d2 100644 --- a/packages/rspack-test-tools/tests/__snapshots__/NewCodeSplitting-config.test.js.snap +++ b/packages/rspack-test-tools/tests/__snapshots__/NewCodeSplitting-config.test.js.snap @@ -492,10 +492,7 @@ __webpack_require__.d = (exports, definition) => { })(); // webpack/runtime/has_own_property (() => { -__webpack_require__.o = function (obj, prop) { - return Object.prototype.hasOwnProperty.call(obj, prop); -}; - +__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) })(); /************************************************************************/ @@ -629,10 +626,7 @@ __webpack_require__.d = (exports, definition) => { })(); // webpack/runtime/has_own_property (() => { -__webpack_require__.o = function (obj, prop) { - return Object.prototype.hasOwnProperty.call(obj, prop); -}; - +__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) })(); /************************************************************************/ @@ -711,10 +705,7 @@ __webpack_require__.d = (exports, definition) => { })(); // webpack/runtime/has_own_property (() => { -__webpack_require__.o = function (obj, prop) { - return Object.prototype.hasOwnProperty.call(obj, prop); -}; - +__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) })(); /************************************************************************/ diff --git a/packages/rspack-test-tools/tests/__snapshots__/NewCodeSplitting-stats-output.test.js.snap b/packages/rspack-test-tools/tests/__snapshots__/NewCodeSplitting-stats-output.test.js.snap index 7223e6a17c97..b4df5ec28a08 100644 --- a/packages/rspack-test-tools/tests/__snapshots__/NewCodeSplitting-stats-output.test.js.snap +++ b/packages/rspack-test-tools/tests/__snapshots__/NewCodeSplitting-stats-output.test.js.snap @@ -54,11 +54,11 @@ runtime modules xx KiB webpack/runtime/auto_public_path xx KiB {909} [code generated] [no exports] [used exports unknown] - webpack/runtime/global 223 bytes {909} [code generated] + webpack/runtime/global 216 bytes {909} [code generated] [no exports] [used exports unknown] -Rspack compiled successfully (ea70de85332c1294) +Rspack compiled successfully (27eddb11e03f28d2) `; exports[`new code splitting stats output new code splitting stats output/builtin-swc-loader-parse-error should print correct stats for: NewCodeSplittingStatsOutput 1`] = ` @@ -113,7 +113,7 @@ Rspack x.x.x compiled successfully in X s `; exports[`new code splitting stats output new code splitting stats output/ignore-plugin should print correct stats for: NewCodeSplittingStatsOutput 1`] = ` -runtime modules 107 bytes 1 module +runtime modules 88 bytes 1 module ./index.js 103 bytes [built] [code generated] /tests/statsOutputCases/ignore-plugin/locals|sync|/^\\.\\/.*$/ 160 bytes [built] [code generated] ./locals/en.js 30 bytes [built] [code generated] @@ -199,7 +199,7 @@ DEBUG LOG from TestLoader|/tests/statsOutputCases/logging-loade `; exports[`new code splitting stats output new code splitting stats output/match-resource-data-url should print correct stats for: NewCodeSplittingStatsOutput 1`] = ` -runtime modules 672 bytes 3 modules +runtime modules 653 bytes 3 modules ./index.js 150 bytes [built] [code generated] ./a.js!=!data:javascript,var __looooooooo.. 98 bytes [built] [code generated] `; @@ -414,7 +414,7 @@ Rspack x.x.x compiled with 1 error in X s exports[`new code splitting stats output new code splitting stats output/runtime-modules should print correct stats for: NewCodeSplittingStatsOutput 1`] = ` ./index.js 19 bytes [built] [code generated] webpack/runtime/define_property_getters 285 bytes [code generated] -webpack/runtime/has_own_property 107 bytes [code generated] +webpack/runtime/has_own_property 88 bytes [code generated] webpack/runtime/make_namespace_object 280 bytes [code generated] `; @@ -445,14 +445,14 @@ Rspack x.x.x compiled successfully in X s exports[`new code splitting stats output new code splitting stats output/simple-export should print correct stats for: NewCodeSplittingStatsOutput 1`] = ` asset bundle.js xx KiB [emitted] (name: main) -runtime modules 672 bytes 3 modules +runtime modules 653 bytes 3 modules ./index.js 26 bytes [built] [code generated] Rspack x.x.x compiled successfully in X s `; exports[`new code splitting stats output new code splitting stats output/simple-module-source should print correct stats for: NewCodeSplittingStatsOutput 1`] = ` -asset bundle.js xx KiB [emitted] (name: main) -runtime modules 656 bytes 3 modules +asset bundle.js 2 KiB [emitted] (name: main) +runtime modules 637 bytes 3 modules orphan modules 1 bytes [orphan] 1 module cacheable modules 82 bytes ./index.js 75 bytes [built] [code generated] diff --git a/packages/rspack-test-tools/tests/__snapshots__/StatsAPI.test.js.snap b/packages/rspack-test-tools/tests/__snapshots__/StatsAPI.test.js.snap index b4680d2a1375..c0a0911e3216 100644 --- a/packages/rspack-test-tools/tests/__snapshots__/StatsAPI.test.js.snap +++ b/packages/rspack-test-tools/tests/__snapshots__/StatsAPI.test.js.snap @@ -310,7 +310,7 @@ Object { isOverSizeLimit: false, name: main.js, related: Array [], - size: 435, + size: 420, type: asset, }, ], @@ -330,7 +330,7 @@ Object { main.js, ], filteredModules: undefined, - hash: 4a78afd9e32ae469, + hash: d397ed1b9bacc5b3, id: 909, idHints: Array [], initial: true, @@ -688,7 +688,7 @@ Object { size: 192, sizes: Object { javascript: 192, - runtime: 672, + runtime: 653, }, type: chunk, }, @@ -698,10 +698,10 @@ Object { assets: Array [ Object { name: main.js, - size: 435, + size: 420, }, ], - assetsSize: 435, + assetsSize: 420, auxiliaryAssets: Array [], auxiliaryAssetsSize: 0, childAssets: Object {}, @@ -718,7 +718,7 @@ Object { errorsCount: 0, filteredAssets: undefined, filteredModules: undefined, - hash: c126035081b62e91, + hash: d88e365a9d98fbc3, modules: Array [ Object { assets: Array [], @@ -1399,9 +1399,9 @@ Object { preOrderIndex: undefined, providedExports: Array [], reasons: Array [], - size: 107, + size: 88, sizes: Object { - runtime: 107, + runtime: 88, }, type: module, usedExports: null, @@ -1455,10 +1455,10 @@ Object { assets: Array [ Object { name: main.js, - size: 435, + size: 420, }, ], - assetsSize: 435, + assetsSize: 420, auxiliaryAssets: Array [], auxiliaryAssetsSize: 0, childAssets: Object {}, diff --git a/packages/rspack-test-tools/tests/__snapshots__/StatsOutput.test.js.snap b/packages/rspack-test-tools/tests/__snapshots__/StatsOutput.test.js.snap index 53749cd888b6..15d825fdd81a 100644 --- a/packages/rspack-test-tools/tests/__snapshots__/StatsOutput.test.js.snap +++ b/packages/rspack-test-tools/tests/__snapshots__/StatsOutput.test.js.snap @@ -54,11 +54,11 @@ runtime modules xx KiB webpack/runtime/auto_public_path xx KiB {909} [code generated] [no exports] [used exports unknown] - webpack/runtime/global 223 bytes {909} [code generated] + webpack/runtime/global 216 bytes {909} [code generated] [no exports] [used exports unknown] -Rspack compiled successfully (ea70de85332c1294) +Rspack compiled successfully (27eddb11e03f28d2) `; exports[`statsOutput statsOutput/builtin-swc-loader-parse-error should print correct stats for 1`] = ` @@ -113,7 +113,7 @@ Rspack x.x.x compiled successfully in X s `; exports[`statsOutput statsOutput/ignore-plugin should print correct stats for 1`] = ` -runtime modules 107 bytes 1 module +runtime modules 88 bytes 1 module ./index.js 103 bytes [built] [code generated] /tests/statsOutputCases/ignore-plugin/locals|sync|/^\\.\\/.*$/ 160 bytes [built] [code generated] ./locals/en.js 30 bytes [built] [code generated] @@ -199,7 +199,7 @@ DEBUG LOG from TestLoader|/tests/statsOutputCases/logging-loade `; exports[`statsOutput statsOutput/match-resource-data-url should print correct stats for 1`] = ` -runtime modules 672 bytes 3 modules +runtime modules 653 bytes 3 modules ./index.js 150 bytes [built] [code generated] ./a.js!=!data:javascript,var __looooooooo.. 98 bytes [built] [code generated] `; @@ -414,7 +414,7 @@ Rspack x.x.x compiled with 1 error in X s exports[`statsOutput statsOutput/runtime-modules should print correct stats for 1`] = ` ./index.js 19 bytes [built] [code generated] webpack/runtime/define_property_getters 285 bytes [code generated] -webpack/runtime/has_own_property 107 bytes [code generated] +webpack/runtime/has_own_property 88 bytes [code generated] webpack/runtime/make_namespace_object 280 bytes [code generated] `; @@ -445,14 +445,14 @@ Rspack x.x.x compiled successfully in X s exports[`statsOutput statsOutput/simple-export should print correct stats for 1`] = ` asset bundle.js xx KiB [emitted] (name: main) -runtime modules 672 bytes 3 modules +runtime modules 653 bytes 3 modules ./index.js 26 bytes [built] [code generated] Rspack x.x.x compiled successfully in X s `; exports[`statsOutput statsOutput/simple-module-source should print correct stats for 1`] = ` -asset bundle.js xx KiB [emitted] (name: main) -runtime modules 656 bytes 3 modules +asset bundle.js 2 KiB [emitted] (name: main) +runtime modules 637 bytes 3 modules orphan modules 1 bytes [orphan] 1 module cacheable modules 82 bytes ./index.js 75 bytes [built] [code generated] diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-html/variant/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-html/variant/__snapshots__/output.snap.txt index 68c5cea0f963..f837ff957dc2 100644 --- a/packages/rspack-test-tools/tests/builtinCases/plugin-html/variant/__snapshots__/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-html/variant/__snapshots__/output.snap.txt @@ -1,3 +1,3 @@ ```html title=output.html -Rspack App +Rspack App ``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/configCases/rsdoctor/assets/rspack.config.js b/packages/rspack-test-tools/tests/configCases/rsdoctor/assets/rspack.config.js index 018c3eb4d5a1..18c06390f7fd 100644 --- a/packages/rspack-test-tools/tests/configCases/rsdoctor/assets/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/rsdoctor/assets/rspack.config.js @@ -37,11 +37,11 @@ module.exports = { Array [ Object { path: a.js, - size: 4682, + size: 4663, }, Object { path: b.js, - size: 4682, + size: 4663, }, Object { path: c_js.js, diff --git a/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/duplicate/output.snap.txt b/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/duplicate/output.snap.txt index 8bd28a97912f..78b360309fdb 100644 --- a/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/duplicate/output.snap.txt +++ b/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/duplicate/output.snap.txt @@ -67,10 +67,7 @@ __webpack_require__.d = (exports, definition) => { })(); // webpack/runtime/has_own_property (() => { -__webpack_require__.o = function (obj, prop) { - return Object.prototype.hasOwnProperty.call(obj, prop); -}; - +__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) })(); /************************************************************************/ // This entry needs to be wrapped in an IIFE because it needs to be in strict mode. diff --git a/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/request/output.snap.txt b/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/request/output.snap.txt index 55a2a789f595..900fbfcd92f7 100644 --- a/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/request/output.snap.txt +++ b/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/request/output.snap.txt @@ -62,10 +62,7 @@ __webpack_require__.d = (exports, definition) => { })(); // webpack/runtime/has_own_property (() => { -__webpack_require__.o = function (obj, prop) { - return Object.prototype.hasOwnProperty.call(obj, prop); -}; - +__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) })(); /************************************************************************/ // This entry needs to be wrapped in an IIFE because it needs to be in strict mode. diff --git a/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/resource/output.snap.txt b/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/resource/output.snap.txt index ac48ab92446c..439e0e5251a4 100644 --- a/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/resource/output.snap.txt +++ b/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/resource/output.snap.txt @@ -62,10 +62,7 @@ __webpack_require__.d = (exports, definition) => { })(); // webpack/runtime/has_own_property (() => { -__webpack_require__.o = function (obj, prop) { - return Object.prototype.hasOwnProperty.call(obj, prop); -}; - +__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) })(); /************************************************************************/ // This entry needs to be wrapped in an IIFE because it needs to be in strict mode. diff --git a/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#resolve/resource/output.snap.txt b/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#resolve/resource/output.snap.txt index 5f378f7935c4..170694ac39bf 100644 --- a/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#resolve/resource/output.snap.txt +++ b/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#resolve/resource/output.snap.txt @@ -62,10 +62,7 @@ __webpack_require__.d = (exports, definition) => { })(); // webpack/runtime/has_own_property (() => { -__webpack_require__.o = function (obj, prop) { - return Object.prototype.hasOwnProperty.call(obj, prop); -}; - +__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) })(); /************************************************************************/ // This entry needs to be wrapped in an IIFE because it needs to be in strict mode. diff --git a/packages/rspack-test-tools/tests/statsAPICases/asset-info.js b/packages/rspack-test-tools/tests/statsAPICases/asset-info.js index 9dcf487a03ad..5e84e411c6b7 100644 --- a/packages/rspack-test-tools/tests/statsAPICases/asset-info.js +++ b/packages/rspack-test-tools/tests/statsAPICases/asset-info.js @@ -91,7 +91,7 @@ module.exports = { isOverSizeLimit: false, name: main.js, related: Array [], - size: 2670, + size: 2663, type: asset, }, ] diff --git a/packages/rspack-test-tools/tests/statsAPICases/build-time-executed-runtime.js b/packages/rspack-test-tools/tests/statsAPICases/build-time-executed-runtime.js index 56e61a5cd5ab..e3ed4a20060d 100644 --- a/packages/rspack-test-tools/tests/statsAPICases/build-time-executed-runtime.js +++ b/packages/rspack-test-tools/tests/statsAPICases/build-time-executed-runtime.js @@ -152,9 +152,9 @@ module.exports = { preOrderIndex: undefined, providedExports: Array [], reasons: Array [], - size: 107, + size: 88, sizes: Object { - runtime: 107, + runtime: 88, }, type: module, usedExports: null, diff --git a/packages/rspack-test-tools/tests/statsAPICases/exports.js b/packages/rspack-test-tools/tests/statsAPICases/exports.js index 7a1290f8cfde..1c9c52c25914 100644 --- a/packages/rspack-test-tools/tests/statsAPICases/exports.js +++ b/packages/rspack-test-tools/tests/statsAPICases/exports.js @@ -24,9 +24,9 @@ module.exports = { expect(typeof stats?.hash).toBe("string"); expect(stats?.toJson(statsOptions)).toMatchSnapshot(); expect(stats?.toString(statsOptions)).toMatchInlineSnapshot(` - asset main.js 435 bytes [emitted] (name: main) + asset main.js 420 bytes [emitted] (name: main) orphan modules 192 bytes [orphan] 4 modules - runtime modules 672 bytes 3 modules + runtime modules 653 bytes 3 modules ./fixtures/esm/abc.js + 3 modules 192 bytes [code generated] [no exports] [no exports used] diff --git a/packages/rspack-test-tools/tests/statsAPICases/nested-modules.js b/packages/rspack-test-tools/tests/statsAPICases/nested-modules.js index ba4cfe4f7d16..6aa9af7441ce 100644 --- a/packages/rspack-test-tools/tests/statsAPICases/nested-modules.js +++ b/packages/rspack-test-tools/tests/statsAPICases/nested-modules.js @@ -304,9 +304,9 @@ module.exports = { `); expect(stats?.toString(statsOptions).replace(/\d+ ms/g, "X ms")) .toMatchInlineSnapshot(` - asset main.js 435 bytes [emitted] (name: main) + asset main.js 420 bytes [emitted] (name: main) orphan modules 192 bytes [orphan] 4 modules - runtime modules 672 bytes 3 modules + runtime modules 653 bytes 3 modules ./fixtures/esm/abc.js + 3 modules 192 bytes [code generated] | orphan modules 192 bytes [orphan] 4 modules Rspack compiled successfully diff --git a/tests/webpack-test/__snapshots__/StatsTestCases.basictest.js.snap b/tests/webpack-test/__snapshots__/StatsTestCases.basictest.js.snap index 317727bad172..b8eae9968472 100644 --- a/tests/webpack-test/__snapshots__/StatsTestCases.basictest.js.snap +++ b/tests/webpack-test/__snapshots__/StatsTestCases.basictest.js.snap @@ -497,7 +497,7 @@ Rspack x.x.x compiled successfully in X.23" `; exports[`StatsTestCases should print correct stats for immutable 1`] = ` -"asset e64ad8bcfebbee1e.js xx KiB [emitted] [immutable] (name: main) +"asset d885ba2ea85160b7.js xx KiB [emitted] [immutable] (name: main) asset 7342054f673663df.js xx bytes [emitted] [immutable]" `;