From 1017935385d1789f4949a810371983a17ce27cfc Mon Sep 17 00:00:00 2001 From: LingyuCoder Date: Wed, 10 Jun 2026 11:33:28 +0800 Subject: [PATCH 01/21] feat(runtime): introduce experimental.runtimeMode --- crates/node_binding/napi-binding.d.ts | 1 + crates/rspack/src/builder/mod.rs | 6 +- .../snapshots/defaults__default_options.snap | 1 + .../src/plugins/interceptor.rs | 4 +- .../src/raw_options/raw_experiments/mod.rs | 11 +- .../artifacts/code_generate_cache_artifact.rs | 10 +- crates/rspack_core/src/artifacts/mod.rs | 2 + .../runtime_proxy_metadata_artifact.rs | 128 ++++ crates/rspack_core/src/cache/memory.rs | 5 + .../module_executor/execute.rs | 90 ++- crates/rspack_core/src/compilation/mod.rs | 13 +- .../compilation/runtime_requirements/mod.rs | 101 +++- crates/rspack_core/src/context_module.rs | 28 +- crates/rspack_core/src/dependency/mod.rs | 3 +- .../runtime_requirements_dependency.rs | 78 +++ crates/rspack_core/src/lib.rs | 2 + .../src/options/experiments/mod.rs | 29 + crates/rspack_core/src/runtime_globals.rs | 232 ++++---- crates/rspack_core/src/runtime_module.rs | 12 +- .../rspack_core/src/runtime_module_source.rs | 33 ++ crates/rspack_core/src/runtime_template.rs | 496 +++++++++++++--- crates/rspack_macros/src/runtime_module.rs | 17 +- .../src/runtime/css_loading_create_link.ejs | 8 +- .../css_loading_with_prefetch_link.ejs | 8 +- .../runtime/css_loading_with_preload_link.ejs | 8 +- crates/rspack_plugin_css/src/runtime/mod.rs | 4 + .../src/eval_dev_tool_module_plugin.rs | 8 +- .../src/eval_source_map_dev_tool_plugin.rs | 6 +- .../src/chunk_link.rs | 6 +- crates/rspack_plugin_esm_library/src/link.rs | 8 +- .../rspack_plugin_esm_library/src/plugin.rs | 14 +- .../rspack_plugin_esm_library/src/render.rs | 86 ++- .../rspack_plugin_esm_library/src/runtime.rs | 13 +- .../rspack_plugin_extract_css/src/plugin.rs | 8 +- .../rspack_plugin_extract_css/src/runtime.rs | 4 + .../src/runtime/css_loading.ejs | 2 +- .../src/runtime/css_loading_create_link.ejs | 6 +- .../src/runtime/css_loading_with_hmr.ejs | 2 +- .../css_loading_with_prefetch_link.ejs | 8 +- .../runtime/css_loading_with_preload_link.ejs | 10 +- .../src/hot_module_replacement.rs | 3 +- .../src/runtime/hot_module_replacement.ejs | 7 +- .../src/parser_and_generator/mod.rs | 3 + .../src/parser_plugin/api_plugin.rs | 454 +++++++++----- .../src/parser_plugin/compatibility_plugin.rs | 21 +- .../src/plugin/api_plugin.rs | 8 +- .../src/plugin/drive.rs | 18 +- .../src/plugin/impl_plugin_for_js_plugin.rs | 2 +- .../src/plugin/mod.rs | 189 ++++-- .../src/plugin/url_plugin.rs | 10 +- .../rspack_plugin_javascript/src/runtime.rs | 558 ++++++++++++++++-- .../src/amd_library_plugin.rs | 9 +- .../src/assign_library_plugin.rs | 10 +- .../src/export_property_library_plugin.rs | 8 +- .../src/jsonp_library_plugin.rs | 8 +- .../src/module_library_plugin.rs | 8 +- .../src/system_library_plugin.rs | 8 +- .../src/umd_library_plugin.rs | 10 +- .../src/container/container_entry_module.rs | 25 +- .../embed_federation_runtime_plugin.rs | 8 +- .../src/container/expose_runtime_module.rs | 8 +- .../federation_data_runtime_module.rs | 6 +- .../src/container/remote_runtime_module.rs | 7 +- .../src/container/remotesLoading.ejs | 4 +- crates/rspack_plugin_mf/src/lib.rs | 23 + .../sharing/consume_shared_runtime_module.rs | 7 +- .../src/sharing/consumesInitial.ejs | 4 +- .../src/sharing/consumesLoading.ejs | 4 +- .../src/sharing/initializeSharing.ejs | 4 +- .../src/sharing/share_runtime_module.rs | 7 +- .../shared_container_runtime_module.rs | 8 +- ...d_used_exports_optimizer_runtime_module.rs | 8 +- .../src/lib.rs | 10 +- .../src/manifest_runtime_module.rs | 4 +- crates/rspack_plugin_rslib/src/plugin.rs | 8 +- crates/rspack_plugin_rstest/src/plugin.rs | 7 +- .../src/array_push_callback_chunk_format.rs | 17 +- .../src/common_js_chunk_format.rs | 31 +- .../src/common_js_chunk_loading.rs | 10 + crates/rspack_plugin_runtime/src/helpers.rs | 6 +- .../src/import_scripts_chunk_loading.rs | 5 + .../src/jsonp_chunk_loading.rs | 5 + .../src/module_chunk_format.rs | 32 +- .../src/module_chunk_loading.rs | 5 + .../src/runtime_module/async_module.rs | 21 +- .../create_fake_namespace_object.rs | 15 +- .../src/runtime_module/ensure_chunk.rs | 6 +- .../src/runtime_module/export_require.rs | 10 +- .../import_scripts_chunk_loading.rs | 10 +- .../src/runtime_module/jsonp_chunk_loading.rs | 13 +- .../src/runtime_module/load_script.rs | 8 +- .../runtime_module/module_chunk_loading.rs | 11 +- .../runtime_module/readfile_chunk_loading.rs | 12 +- .../require_js_chunk_loading.rs | 12 +- .../runtime/create_fake_namespace_object.ejs | 4 +- .../runtime/import_scripts_chunk_loading.ejs | 4 +- .../javascript_hot_module_replacement.ejs | 6 +- .../jsonp_chunk_loading_with_callback.ejs | 2 +- ...jsonp_chunk_loading_with_prefetch_link.ejs | 8 +- .../jsonp_chunk_loading_with_preload_link.ejs | 8 +- .../runtime/load_script_create_script.ejs | 8 +- .../runtime/module_chunk_loading.ejs | 12 +- ...odule_chunk_loading_with_prefetch_link.ejs | 8 +- ...module_chunk_loading_with_preload_link.ejs | 8 +- .../runtime/readfile_chunk_loading.ejs | 4 +- ...nk_loading_with_external_install_chunk.ejs | 4 +- .../runtime/require_chunk_loading.ejs | 4 +- ...nk_loading_with_external_install_chunk.ejs | 4 +- .../src/runtime_module/utils.rs | 18 +- .../src/runtime_plugin.rs | 8 +- packages/rspack-test-tools/src/case/config.ts | 45 +- packages/rspack-test-tools/src/case/hot.ts | 32 +- .../helper/expect/to-match-file-snapshot.ts | 103 +++- .../src/helper/hot-update/plugin.ts | 13 +- packages/rspack/src/ExecuteModulePlugin.ts | 15 +- packages/rspack/src/RuntimeGlobals.ts | 5 +- packages/rspack/src/config/defaults.ts | 1 + packages/rspack/src/config/normalization.ts | 1 + packages/rspack/src/config/types.ts | 6 + .../runtime/moduleFederationDefaultRuntime.js | 149 ++--- packages/rspack/src/taps/compilation.ts | 18 +- tests/rspack-test/RuntimeModeConfig.test.js | 29 + tests/rspack-test/RuntimeModeHotNode.test.js | 3 + tests/rspack-test/RuntimeModeHotWeb.test.js | 3 + .../rspack-test/RuntimeModeHotWorker.test.js | 3 + .../__snapshots__/output.snap.txt | 2 +- .../__snapshots__/output.snap.txt | 2 +- .../__snapshots__/output.snap.txt | 2 +- .../__snapshots__/output.snap.txt | 10 +- .../__snapshots__/output.snap.txt | 4 +- .../__snapshots__/output.snap.txt | 4 +- .../hashbang/__snapshots__/output.snap.txt | 4 +- .../issuse_2960/__snapshots__/output.snap.txt | 14 +- .../provide/__snapshots__/output.snap.txt | 2 +- .../simple/__snapshots__/output.snap.txt | 2 +- .../__snapshots__/output.snap.txt | 4 +- .../v128/__snapshots__/output.snap.txt | 2 +- .../__snapshots__/output.snap.txt | 4 +- .../__snapshots__/output.snap.txt | 4 +- .../__snapshots__/output.snap.txt | 2 +- .../__snapshots__/output.snap.txt | 8 +- .../cycle-entry/__snapshots__/output.snap.txt | 4 +- .../__snapshots__/output.snap.txt | 4 +- .../__snapshots__/output.snap.txt | 6 +- .../simple/__snapshots__/output.snap.txt | 2 +- .../minify/__snapshots__/output.snap.txt | 2 +- .../rspack.config.js | 5 +- .../existing-name/index.js | 5 +- .../runtimeModeSnapshot/snapshot.txt | 74 +++ .../index.js | 5 +- .../depend-on-with-chunk-load/index.js | 9 +- .../chunk-loading/worker-loader/index.js | 2 +- .../import-export-format-2/index.js | 15 +- .../import-export-format/index.js | 8 +- .../re-export-namespace-concat/index.js | 9 +- .../re-export-namespace/index.js | 9 +- .../css/no-extra-js-exports-output/test.js | 2 +- .../externals/commonjs-import/index.js | 7 +- .../import-attributes/rspack.config.js | 12 +- .../reexport-star/__snapshot__/case1.txt | 2 +- .../runtimeModeSnapshot/case1.txt | 39 ++ .../runtimeModeSnapshot/case2.txt | 13 + .../runtimeModeSnapshot/case3.txt | 10 + .../runtimeModeSnapshot/case4.txt | 7 + .../runtimeModeSnapshot/case5.txt | 12 + .../runtimeModeSnapshot/case6.txt | 8 + .../externals/reexport-star/index.js | 15 +- .../script-externals-dynamic-import/index.js | 7 +- .../rspack.config.js | 4 +- .../rspack.config.js | 5 +- .../hooks/rspack-issue-5571/index.js | 7 +- .../inline-const/provide-plugin/index.js | 7 +- .../configCases/library/esm-external/index.js | 13 +- .../rspack.config.js | 4 +- .../__snapshot__/runtimeModeSnapshot/b.js.txt | 11 + .../__snapshot__/runtimeModeSnapshot/e.js.txt | 18 + .../__snapshot__/runtimeModeSnapshot/f.js.txt | 27 + .../__snapshot__/runtimeModeSnapshot/g.js.txt | 17 + .../runtimeModeSnapshot/entry.mjs.txt | 75 +++ .../render-order-issue/rspack.config.js | 5 +- .../module-variables/global-false/index.js | 6 +- .../module/consume-webpack-runtime/index.js | 10 +- .../output/pathinfo-verbose/index.js | 34 +- .../parsing/eval-cjs-typeof/index.js | 6 +- .../parsing/require-alias-disabled/index.js | 6 +- .../parsing/require-alias-enabled/index.js | 14 +- .../plugins/minify-module/index.js | 4 +- .../plugins/minify-parser/index.js | 2 +- .../rsdoctor/assets/rspack.config.js | 49 +- .../configCases/rstest/mock/rspack.config.js | 8 +- .../rstest/require-resolve-origin/index.js | 4 +- .../index.js | 2 +- .../dynamic-css-chunk-with-hash/index.js | 4 +- .../runtime/dynamic-css-chunk/index.js | 4 +- .../runtime/runtime-condition/a.js | 9 +- .../runtime/runtime-mode-async-chunk/index.js | 7 + .../runtime/runtime-mode-async-chunk/lazy.js | 1 + .../runtime-mode-async-chunk/rspack.config.js | 13 + .../runtime-mode-async-chunk/test.config.js | 26 + .../runtime-mode-context-module/index.js | 6 + .../runtime-mode-context-module/modules/a.js | 1 + .../rspack.config.js | 12 + .../test.config.js | 16 + .../errors.js | 3 + .../index.js | 1 + .../rspack.config.js | 36 ++ .../test.config.js | 4 + .../runtime-mode-module-rendering/after.js | 21 + .../runtime-mode-module-rendering/index.js | 7 + .../runtime-mode-module-rendering/lib.js | 1 + .../rspack.config.js | 13 + .../test.config.js | 25 + .../index.js | 21 + .../rspack.config.js | 12 + .../runtime/runtime-mode-option/index.js | 1 + .../runtime-mode-option/rspack.config.js | 1 + .../runtime-mode-require-context/index.js | 5 + .../runtime-mode-require-context/lib.js | 1 + .../rspack.config.js | 12 + .../test.config.js | 18 + .../index.js | 9 + .../rspack.config.js | 6 + .../test.config.js | 4 + .../runtime/split-css-chunk-async/index1.js | 2 +- .../runtime/split-css-chunk/index1.js | 2 +- .../source-map/verify-css-js-mix/index.js | 9 +- .../source-map/verify-es6/index.js | 4 +- .../module-runtime-requirement/index.js | 9 +- .../trusted-types/web-worker/index.js | 14 +- .../umd/issue-15545/rspack.config.js | 2 +- .../configCases/unique-id/all/index.js | 5 +- .../configCases/unique-id/array/index.js | 5 +- .../configCases/version/all/index.js | 5 +- .../configCases/version/array/index.js | 5 +- .../rspack-test/defaultsCases/default/base.js | 1 + .../__snapshots__/esm.snap.txt | 4 +- .../tree-shaking/__snapshots__/esm.snap.txt | 4 +- .../basic/__snapshots__/esm.snap.txt | 4 +- .../__snapshots__/esm.snap.txt | 6 +- .../__snapshots__/esm.snap.txt | 6 +- .../__snapshots__/esm.snap.txt | 6 +- .../__snapshots__/esm.snap.txt | 6 +- .../__snapshots__/esm.snap.txt | 6 +- .../__snapshots__/esm.snap.txt | 8 +- .../__snapshots__/esm.snap.txt | 6 +- .../__snapshots__/esm.snap.txt | 5 +- .../__snapshots__/esm.snap.txt | 16 +- .../import-cjs/__snapshots__/esm.snap.txt | 5 +- .../__snapshots__/esm.snap.txt | 8 +- .../__snapshots__/esm.snap.txt | 6 +- .../__snapshots__/esm.snap.txt | 6 +- .../__snapshots__/esm.snap.txt | 8 +- .../__snapshots__/esm.snap.txt | 18 +- .../magic-comment/__snapshots__/esm.snap.txt | 6 +- .../__snapshots__/esm.snap.txt | 26 +- .../__snapshots__/esm.snap.txt | 26 +- .../__snapshots__/esm.snap.txt | 26 +- .../__snapshots__/esm.snap.txt | 26 +- .../__snapshots__/esm.snap.txt | 26 +- .../__snapshots__/esm.snap.txt | 26 +- .../__snapshots__/esm.snap.txt | 28 +- .../__snapshots__/esm.snap.txt | 4 +- .../__snapshots__/esm.snap.txt | 4 +- .../__snapshots__/esm.snap.txt | 26 +- .../basic-capture/__snapshots__/esm.snap.txt | 4 +- .../__snapshots__/esm.snap.txt | 5 +- .../__snapshots__/esm.snap.txt | 4 +- .../__snapshots__/esm.snap.txt | 6 +- .../__snapshots__/esm.snap.txt | 6 +- .../__snapshots__/esm.snap.txt | 5 +- .../__snapshots__/esm.snap.txt | 4 +- .../__snapshots__/esm.snap.txt | 4 +- .../__snapshots__/esm.snap.txt | 5 +- .../__snapshots__/esm.snap.txt | 4 +- .../__snapshots__/esm.snap.txt | 4 +- .../__snapshots__/esm.snap.txt | 4 +- .../__snapshots__/esm.snap.txt | 6 +- .../__snapshots__/esm.snap.txt | 4 +- .../__snapshots__/esm.snap.txt | 4 +- .../__snapshots__/esm.snap.txt | 5 +- .../__snapshots__/esm.snap.txt | 4 +- .../__snapshots__/esm.snap.txt | 4 +- .../__snapshots__/esm.snap.txt | 4 +- .../__snapshots__/esm.snap.txt | 4 +- .../__snapshots__/esm.snap.txt | 6 +- .../__snapshots__/esm.snap.txt | 4 +- .../__snapshots__/esm.snap.txt | 4 +- .../__snapshots__/esm.snap.txt | 4 +- .../__snapshots__/esm.snap.txt | 4 +- .../__snapshots__/esm.snap.txt | 4 +- .../__snapshots__/esm.snap.txt | 4 +- .../__snapshots__/esm.snap.txt | 4 +- .../re-export-star/__snapshots__/esm.snap.txt | 4 +- .../__snapshots__/esm.snap.txt | 4 +- .../__snapshots__/esm.snap.txt | 4 +- .../__snapshots__/esm.snap.txt | 6 +- .../__snapshots__/esm.snap.txt | 6 +- .../__snapshots__/esm.snap.txt | 5 +- .../__snapshots__/esm.snap.txt | 4 +- .../__snapshots__/esm.snap.txt | 4 +- .../__snapshots__/esm.snap.txt | 4 +- .../__snapshots__/esm.snap.txt | 6 +- .../cjs-entry/__snapshots__/esm.snap.txt | 4 +- .../__snapshots__/esm.snap.txt | 4 +- .../__snapshots__/esm.snap.txt | 6 +- .../__snapshots__/esm.snap.txt | 4 +- .../__snapshots__/esm.snap.txt | 4 +- .../__snapshots__/esm.snap.txt | 4 +- .../__snapshots__/esm.snap.txt | 4 +- .../__snapshots__/web/1.snap.txt | 2 +- .../issue-9706/__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 4 +- .../__snapshots__/web/1.snap.txt | 4 +- .../__snapshots__/web/1.snap.txt | 4 +- .../__snapshots__/web/1.snap.txt | 4 +- .../__snapshots__/web/1.snap.txt | 8 +- .../__snapshots__/web/1.snap.txt | 4 +- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/2.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 4 +- .../__snapshots__/web/1.snap.txt | 2 +- .../css-extract/__snapshots__/web/1.snap.txt | 4 +- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../css-modules/__snapshots__/web/1.snap.txt | 4 +- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/2.snap.txt | 2 +- .../css/recovery/__snapshots__/web/2.snap.txt | 4 +- .../css/vanilla/__snapshots__/web/1.snap.txt | 2 +- .../issue-6962/__snapshots__/web/1.snap.txt | 2 +- .../issue-10174/__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../decline/__snapshots__/web/1.snap.txt | 2 +- .../events/__snapshots__/web/1.snap.txt | 14 +- .../self-decline/__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/2.snap.txt | 2 +- .../__snapshots__/web/3.snap.txt | 4 +- .../unaccepted/__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../module-hot/__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../auto-import/__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../hot-index/__snapshots__/web/1.snap.txt | 2 +- .../hot-index/__snapshots__/web/2.snap.txt | 2 +- .../hot-index/__snapshots__/web/3.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../context/__snapshots__/web/1.snap.txt | 2 +- .../context/__snapshots__/web/2.snap.txt | 2 +- .../unrelated/__snapshots__/web/1.snap.txt | 2 +- .../unrelated/__snapshots__/web/2.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/2.snap.txt | 2 +- .../__snapshots__/web/3.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../fix-issuer/__snapshots__/web/1.snap.txt | 2 +- .../issue-10915/__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/2.snap.txt | 4 +- .../__snapshots__/web/1.snap.txt | 2 +- .../build-info/__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 4 +- .../__snapshots__/web/1.snap.txt | 4 +- .../__snapshots__/web/2.snap.txt | 4 +- .../production/__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../plugins/html/__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/2.snap.txt | 2 +- .../__snapshots__/web/2.snap.txt | 2 +- .../__snapshots__/web/2.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/2.snap.txt | 4 +- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/3.snap.txt | 2 +- .../circular/__snapshots__/web/1.snap.txt | 4 +- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/2.snap.txt | 2 +- .../__snapshots__/web/3.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 4 +- .../__snapshots__/web/2.snap.txt | 4 +- .../hmr-circular/__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 4 +- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../share-plugin/__snapshots__/web/1.snap.txt | 7 +- .../disable/__snapshots__/web/1.snap.txt | 2 +- .../disable/__snapshots__/web/2.snap.txt | 2 +- .../disable/__snapshots__/web/3.snap.txt | 2 +- .../enable/__snapshots__/web/1.snap.txt | 2 +- .../enable/__snapshots__/web/2.snap.txt | 2 +- .../enable/__snapshots__/web/3.snap.txt | 2 +- .../stats/chunks/__snapshots__/web/1.snap.txt | 2 +- .../status/check/__snapshots__/web/1.snap.txt | 2 +- .../used-exports/__snapshots__/web/1.snap.txt | 2 +- .../issue-5597/__snapshots__/web/1.snap.txt | 8 +- .../issue-5597/__snapshots__/web/2.snap.txt | 8 +- .../issue-5597/__snapshots__/web/3.snap.txt | 8 +- .../issue-5597/__snapshots__/web/4.snap.txt | 8 +- .../issue-5597/__snapshots__/web/5.snap.txt | 8 +- .../issue-5597/__snapshots__/web/6.snap.txt | 8 +- .../issue-5597/__snapshots__/web/7.snap.txt | 8 +- .../__snapshots__/web/1.snap.txt | 12 +- .../__snapshots__/web/2.snap.txt | 10 +- .../__snapshots__/web/3.snap.txt | 8 +- .../__snapshots__/web/4.snap.txt | 8 +- .../__snapshots__/web/5.snap.txt | 8 +- .../__snapshots__/web/6.snap.txt | 8 +- .../__snapshots__/web/7.snap.txt | 8 +- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/2.snap.txt | 2 +- .../__snapshots__/web/3.snap.txt | 2 +- tests/rspack-test/rstest.config.mts | 11 +- .../statsAPICases/additional-chunks.js | 4 +- tests/rspack-test/statsAPICases/assets.js | 2 +- tests/rspack-test/statsAPICases/exports.js | 4 +- .../all-stats/__snapshots__/stats.txt | 2 +- .../immutable/__snapshots__/stats.txt | 2 +- .../issue-7577/__snapshots__/stats.txt | 6 +- .../__snapshots__/treeshaking.snap.txt | 2 +- .../__snapshots__/treeshaking.snap.txt | 18 +- .../__snapshots__/treeshaking.snap.txt | 2 +- .../__snapshots__/treeshaking.snap.txt | 2 +- .../__snapshots__/treeshaking.snap.txt | 2 +- .../__snapshots__/treeshaking.snap.txt | 2 +- .../__snapshots__/treeshaking.snap.txt | 2 +- .../__snapshots__/treeshaking.snap.txt | 2 +- .../__snapshots__/treeshaking.snap.txt | 4 +- .../__snapshots__/treeshaking.snap.txt | 2 +- .../__snapshots__/treeshaking.snap.txt | 4 +- .../__snapshots__/treeshaking.snap.txt | 2 +- .../__snapshots__/treeshaking.snap.txt | 2 +- .../__snapshots__/treeshaking.snap.txt | 2 +- .../__snapshots__/treeshaking.snap.txt | 2 +- .../async-modules/top-level-await/0/utils.js | 2 +- 446 files changed, 4339 insertions(+), 1502 deletions(-) create mode 100644 crates/rspack_core/src/artifacts/runtime_proxy_metadata_artifact.rs create mode 100644 crates/rspack_core/src/runtime_module_source.rs create mode 100644 tests/rspack-test/RuntimeModeConfig.test.js create mode 100644 tests/rspack-test/RuntimeModeHotNode.test.js create mode 100644 tests/rspack-test/RuntimeModeHotWeb.test.js create mode 100644 tests/rspack-test/RuntimeModeHotWorker.test.js create mode 100644 tests/rspack-test/configCases/chunk-ids/stable-chunk-ids-with-duplicate-chunks/__snapshot__/runtimeModeSnapshot/runtimeModeSnapshot/snapshot.txt create mode 100644 tests/rspack-test/configCases/externals/reexport-star/__snapshot__/runtimeModeSnapshot/case1.txt create mode 100644 tests/rspack-test/configCases/externals/reexport-star/__snapshot__/runtimeModeSnapshot/case2.txt create mode 100644 tests/rspack-test/configCases/externals/reexport-star/__snapshot__/runtimeModeSnapshot/case3.txt create mode 100644 tests/rspack-test/configCases/externals/reexport-star/__snapshot__/runtimeModeSnapshot/case4.txt create mode 100644 tests/rspack-test/configCases/externals/reexport-star/__snapshot__/runtimeModeSnapshot/case5.txt create mode 100644 tests/rspack-test/configCases/externals/reexport-star/__snapshot__/runtimeModeSnapshot/case6.txt create mode 100644 tests/rspack-test/configCases/library/modern-module-force-concaten/__snapshot__/runtimeModeSnapshot/b.js.txt create mode 100644 tests/rspack-test/configCases/library/modern-module-force-concaten/__snapshot__/runtimeModeSnapshot/e.js.txt create mode 100644 tests/rspack-test/configCases/library/modern-module-force-concaten/__snapshot__/runtimeModeSnapshot/f.js.txt create mode 100644 tests/rspack-test/configCases/library/modern-module-force-concaten/__snapshot__/runtimeModeSnapshot/g.js.txt create mode 100644 tests/rspack-test/configCases/library/render-order-issue/__snapshots__/runtimeModeSnapshot/runtimeModeSnapshot/entry.mjs.txt create mode 100644 tests/rspack-test/configCases/runtime/runtime-mode-async-chunk/index.js create mode 100644 tests/rspack-test/configCases/runtime/runtime-mode-async-chunk/lazy.js create mode 100644 tests/rspack-test/configCases/runtime/runtime-mode-async-chunk/rspack.config.js create mode 100644 tests/rspack-test/configCases/runtime/runtime-mode-async-chunk/test.config.js create mode 100644 tests/rspack-test/configCases/runtime/runtime-mode-context-module/index.js create mode 100644 tests/rspack-test/configCases/runtime/runtime-mode-context-module/modules/a.js create mode 100644 tests/rspack-test/configCases/runtime/runtime-mode-context-module/rspack.config.js create mode 100644 tests/rspack-test/configCases/runtime/runtime-mode-context-module/test.config.js create mode 100644 tests/rspack-test/configCases/runtime/runtime-mode-custom-runtime-module-error/errors.js create mode 100644 tests/rspack-test/configCases/runtime/runtime-mode-custom-runtime-module-error/index.js create mode 100644 tests/rspack-test/configCases/runtime/runtime-mode-custom-runtime-module-error/rspack.config.js create mode 100644 tests/rspack-test/configCases/runtime/runtime-mode-custom-runtime-module-error/test.config.js create mode 100644 tests/rspack-test/configCases/runtime/runtime-mode-module-rendering/after.js create mode 100644 tests/rspack-test/configCases/runtime/runtime-mode-module-rendering/index.js create mode 100644 tests/rspack-test/configCases/runtime/runtime-mode-module-rendering/lib.js create mode 100644 tests/rspack-test/configCases/runtime/runtime-mode-module-rendering/rspack.config.js create mode 100644 tests/rspack-test/configCases/runtime/runtime-mode-module-rendering/test.config.js create mode 100644 tests/rspack-test/configCases/runtime/runtime-mode-nested-rspack-context/index.js create mode 100644 tests/rspack-test/configCases/runtime/runtime-mode-nested-rspack-context/rspack.config.js create mode 100644 tests/rspack-test/configCases/runtime/runtime-mode-option/index.js create mode 100644 tests/rspack-test/configCases/runtime/runtime-mode-option/rspack.config.js create mode 100644 tests/rspack-test/configCases/runtime/runtime-mode-require-context/index.js create mode 100644 tests/rspack-test/configCases/runtime/runtime-mode-require-context/lib.js create mode 100644 tests/rspack-test/configCases/runtime/runtime-mode-require-context/rspack.config.js create mode 100644 tests/rspack-test/configCases/runtime/runtime-mode-require-context/test.config.js create mode 100644 tests/rspack-test/configCases/runtime/runtime-mode-unsupported-require-property/index.js create mode 100644 tests/rspack-test/configCases/runtime/runtime-mode-unsupported-require-property/rspack.config.js create mode 100644 tests/rspack-test/configCases/runtime/runtime-mode-unsupported-require-property/test.config.js diff --git a/crates/node_binding/napi-binding.d.ts b/crates/node_binding/napi-binding.d.ts index 76de583c5a7d..97a3e691f384 100644 --- a/crates/node_binding/napi-binding.d.ts +++ b/crates/node_binding/napi-binding.d.ts @@ -2277,6 +2277,7 @@ export interface RawExperiments { deferImport: boolean sourceImport: boolean pureFunctions: boolean + runtimeMode?: "webpack" | "rspack" } export interface RawExposeOptions { diff --git a/crates/rspack/src/builder/mod.rs b/crates/rspack/src/builder/mod.rs index 966b4ceffc3f..bc13d5b9ab36 100644 --- a/crates/rspack/src/builder/mod.rs +++ b/crates/rspack/src/builder/mod.rs @@ -55,7 +55,7 @@ use rspack_core::{ NodeGlobalOption, NodeOption, Optimization, OutputOptions, ParseOption, ParserOptions, ParserOptionsMap, PathInfo, PublicPath, Resolve, RuleSetCondition, RuleSetLogicalConditions, SideEffectOption, StatsOptions, TrustedTypes, UsedExportsOption, WasmLoading, WasmLoadingType, - incremental::IncrementalOptions, + incremental::IncrementalOptions, runtime_mode::RuntimeMode, }; use rspack_error::{Error, Result}; use rspack_fs::{IntermediateFileSystem, ReadableFileSystem, WritableFileSystem}; @@ -3683,6 +3683,7 @@ pub struct ExperimentsBuilder { source_import: Option, // TODO: lazy compilation pure_functions: Option, + runtime_mode: Option, } impl From for ExperimentsBuilder { @@ -3694,6 +3695,7 @@ impl From for ExperimentsBuilder { defer_import: Some(value.defer_import), source_import: Some(value.source_import), pure_functions: Some(value.pure_functions), + runtime_mode: Some(value.runtime_mode), } } } @@ -3707,6 +3709,7 @@ impl From<&mut ExperimentsBuilder> for ExperimentsBuilder { defer_import: value.defer_import.take(), source_import: value.source_import.take(), pure_functions: value.pure_functions.take(), + runtime_mode: value.runtime_mode.take(), } } } @@ -3761,6 +3764,7 @@ impl ExperimentsBuilder { defer_import: d!(self.defer_import, false), source_import: d!(self.source_import, false), pure_functions: d!(self.pure_functions, false), + runtime_mode: d!(self.runtime_mode, RuntimeMode::Webpack), }) } } diff --git a/crates/rspack/tests/snapshots/defaults__default_options.snap b/crates/rspack/tests/snapshots/defaults__default_options.snap index f194e5d4726f..21b9d67b69b9 100644 --- a/crates/rspack/tests/snapshots/defaults__default_options.snap +++ b/crates/rspack/tests/snapshots/defaults__default_options.snap @@ -1745,6 +1745,7 @@ CompilerOptions { defer_import: false, source_import: false, pure_functions: false, + runtime_mode: Webpack, }, incremental: IncrementalOptions { silent: true, diff --git a/crates/rspack_binding_api/src/plugins/interceptor.rs b/crates/rspack_binding_api/src/plugins/interceptor.rs index e9470526db10..d3c3e5550db6 100644 --- a/crates/rspack_binding_api/src/plugins/interceptor.rs +++ b/crates/rspack_binding_api/src/plugins/interceptor.rs @@ -11,7 +11,7 @@ use napi::{ Either, Env, JsValue, bindgen_prelude::{Buffer, FromNapiValue, Function, JsValuesTupleIntoVec, Promise, ToNapiValue}, }; -use rspack_collections::{IdentifierMap, IdentifierSet}; +use rspack_collections::{Identifier, IdentifierMap, IdentifierSet}; use rspack_core::{ AfterResolveResult, AssetEmittedInfo, AsyncModulesArtifact, BeforeResolveResult, BindingCell, BoxModule, ChunkGraph, ChunkUkey, CircularModulesInfo, Compilation, @@ -1243,7 +1243,7 @@ impl CompilationExecuteModule for CompilationExecuteModuleTap { async fn run( &self, entry: &ModuleIdentifier, - runtime_modules: &IdentifierSet, + runtime_modules: &[Identifier], code_generation_results: &BindingCell, id: &ExecuteModuleId, ) -> rspack_error::Result<()> { diff --git a/crates/rspack_binding_api/src/raw_options/raw_experiments/mod.rs b/crates/rspack_binding_api/src/raw_options/raw_experiments/mod.rs index 9cd50658a862..38b64a39b3af 100644 --- a/crates/rspack_binding_api/src/raw_options/raw_experiments/mod.rs +++ b/crates/rspack_binding_api/src/raw_options/raw_experiments/mod.rs @@ -2,7 +2,7 @@ mod raw_incremental; use napi_derive::napi; pub use raw_incremental::RawIncremental; -use rspack_core::Experiments; +use rspack_core::{Experiments, runtime_mode::RuntimeMode}; use rspack_regex::RspackRegex; use super::WithFalse; @@ -16,15 +16,24 @@ pub struct RawExperiments { pub defer_import: bool, pub source_import: bool, pub pure_functions: bool, + #[napi(ts_type = "\"webpack\" | \"rspack\"")] + pub runtime_mode: Option, } impl From for Experiments { fn from(value: RawExperiments) -> Self { + let runtime_mode = if value.runtime_mode.as_deref() == Some("rspack") { + RuntimeMode::Rspack + } else { + RuntimeMode::Webpack + }; + Self { css: value.css.unwrap_or(false), defer_import: value.defer_import, source_import: value.source_import, pure_functions: value.pure_functions, + runtime_mode, } } } diff --git a/crates/rspack_core/src/artifacts/code_generate_cache_artifact.rs b/crates/rspack_core/src/artifacts/code_generate_cache_artifact.rs index 7bb9757c1003..59a140ea6997 100644 --- a/crates/rspack_core/src/artifacts/code_generate_cache_artifact.rs +++ b/crates/rspack_core/src/artifacts/code_generate_cache_artifact.rs @@ -6,11 +6,13 @@ use crate::{ ArtifactExt, CacheOptions, CodeGenerationJob, CodeGenerationResult, CompilerOptions, MemoryGCStorage, incremental::{Incremental, IncrementalPasses}, + runtime_mode::RuntimeMode, }; #[derive(Debug, Default)] pub struct CodeGenerateCacheArtifact { storage: Option>, + runtime_mode: RuntimeMode, } impl ArtifactExt for CodeGenerateCacheArtifact { @@ -30,6 +32,7 @@ impl CodeGenerateCacheArtifact { CacheOptions::Persistent(_) => Some(MemoryGCStorage::new(1)), CacheOptions::Disabled => None, }, + runtime_mode: options.experiments.runtime_mode, } } @@ -53,7 +56,12 @@ impl CodeGenerateCacheArtifact { return (res, false); }; - let cache_key = Identifier::from(format!("{}|{}", job.module, job.hash.encoded())); + let cache_key = Identifier::from(format!( + "{}|{}|{}", + job.module, + job.hash.encoded(), + self.runtime_mode + )); if let Some(value) = storage.get(&cache_key) { (Ok(value), true) } else { diff --git a/crates/rspack_core/src/artifacts/mod.rs b/crates/rspack_core/src/artifacts/mod.rs index e2b326892d92..9a581fe98ba7 100644 --- a/crates/rspack_core/src/artifacts/mod.rs +++ b/crates/rspack_core/src/artifacts/mod.rs @@ -17,6 +17,7 @@ mod imported_by_defer_modules_artifact; mod module_graph_cache_artifact; mod module_ids_artifact; mod process_runtime_requirements_cache_artifact; +mod runtime_proxy_metadata_artifact; mod side_effects_do_optimize_artifact; mod side_effects_state_artifact; @@ -102,5 +103,6 @@ pub use imported_by_defer_modules_artifact::ImportedByDeferModulesArtifact; pub use module_graph_cache_artifact::*; pub use module_ids_artifact::ModuleIdsArtifact; pub use process_runtime_requirements_cache_artifact::ProcessRuntimeRequirementsCacheArtifact; +pub use runtime_proxy_metadata_artifact::{RuntimeProxyMetadata, RuntimeProxyMetadataArtifact}; pub use side_effects_do_optimize_artifact::*; pub use side_effects_state_artifact::*; diff --git a/crates/rspack_core/src/artifacts/runtime_proxy_metadata_artifact.rs b/crates/rspack_core/src/artifacts/runtime_proxy_metadata_artifact.rs new file mode 100644 index 000000000000..ace14da965c4 --- /dev/null +++ b/crates/rspack_core/src/artifacts/runtime_proxy_metadata_artifact.rs @@ -0,0 +1,128 @@ +use std::{ + fmt::Write, + ops::{Deref, DerefMut}, +}; + +use rustc_hash::FxHashMap; + +use crate::{ + ArtifactExt, ChunkUkey, RuntimeGlobals, incremental::IncrementalPasses, property_access, +}; + +#[derive(Debug, Default, Clone)] +pub struct RuntimeProxyMetadata { + pub tree_runtime_requirements: RuntimeGlobals, + pub module_proxy_requirements: RuntimeGlobals, + pub runtime_module_requirements: RuntimeGlobals, + pub context_setter_fields: RuntimeGlobals, + pub hook_exposed_requirements: RuntimeGlobals, +} + +impl RuntimeProxyMetadata { + fn renderable_fields(runtime_globals: RuntimeGlobals) -> RuntimeGlobals { + runtime_globals + .renderable_require_scope() + .difference(RuntimeGlobals::REQUIRE | RuntimeGlobals::REQUIRE_SCOPE) + } + + pub fn lexical_fields(&self) -> RuntimeGlobals { + Self::renderable_fields(self.tree_runtime_requirements) + } + + pub fn context_fields(&self) -> RuntimeGlobals { + let mut fields = self.module_proxy_requirements; + fields.insert(self.context_setter_fields); + fields.insert(self.hook_exposed_requirements); + Self::renderable_fields(fields) + } + + pub fn context_setter_fields(&self) -> RuntimeGlobals { + Self::renderable_fields(self.context_setter_fields) + } + + pub fn render_lexical_declarations(&self) -> String { + let names = self + .lexical_fields() + .iter_names() + .filter_map(|(_, runtime_global)| runtime_global.to_lexical_name().map(str::to_string)) + .collect::>(); + if names.is_empty() { + String::new() + } else { + format!("var {};\n", names.join(", ")) + } + } + + pub fn render_context_setter_assignments(&self, runtime_context: &str) -> String { + let mut source = String::new(); + for (_, runtime_global) in self.context_fields().iter_names() { + let (Some(property_name), Some(lexical_name)) = ( + runtime_global.property_name(), + runtime_global.to_lexical_name(), + ) else { + continue; + }; + writeln!( + source, + "{runtime_context}{}={lexical_name};", + property_access([property_name], 0) + ) + .expect("write to string should succeed"); + } + source + } +} + +#[derive(Debug, Default, Clone)] +pub struct RuntimeProxyMetadataArtifact(FxHashMap); + +impl ArtifactExt for RuntimeProxyMetadataArtifact { + const PASS: IncrementalPasses = IncrementalPasses::CHUNKS_RUNTIME_REQUIREMENTS; +} + +impl Deref for RuntimeProxyMetadataArtifact { + type Target = FxHashMap; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl DerefMut for RuntimeProxyMetadataArtifact { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + +impl From> for RuntimeProxyMetadataArtifact { + fn from(value: FxHashMap) -> Self { + Self(value) + } +} + +impl From for FxHashMap { + fn from(value: RuntimeProxyMetadataArtifact) -> Self { + value.0 + } +} + +impl FromIterator< as IntoIterator>::Item> + for RuntimeProxyMetadataArtifact +{ + fn from_iter< + T: IntoIterator as IntoIterator>::Item>, + >( + iter: T, + ) -> Self { + Self(FxHashMap::from_iter(iter)) + } +} + +impl IntoIterator for RuntimeProxyMetadataArtifact { + type Item = as IntoIterator>::Item; + type IntoIter = as IntoIterator>::IntoIter; + + fn into_iter(self) -> Self::IntoIter { + self.0.into_iter() + } +} diff --git a/crates/rspack_core/src/cache/memory.rs b/crates/rspack_core/src/cache/memory.rs index 4dfa0ec19fe0..b9602527b416 100644 --- a/crates/rspack_core/src/cache/memory.rs +++ b/crates/rspack_core/src/cache/memory.rs @@ -181,6 +181,11 @@ impl Cache for MemoryCache { &mut compilation.cgc_runtime_requirements_artifact, &mut old_compilation.cgc_runtime_requirements_artifact, ); + recover_artifact( + incremental, + &mut compilation.runtime_proxy_metadata_artifact, + &mut old_compilation.runtime_proxy_metadata_artifact, + ); } } diff --git a/crates/rspack_core/src/compilation/build_module_graph/module_executor/execute.rs b/crates/rspack_core/src/compilation/build_module_graph/module_executor/execute.rs index 755829f773a4..84531aa37d43 100644 --- a/crates/rspack_core/src/compilation/build_module_graph/module_executor/execute.rs +++ b/crates/rspack_core/src/compilation/build_module_graph/module_executor/execute.rs @@ -4,13 +4,14 @@ use itertools::Itertools; use rspack_collections::{Identifier, IdentifierSet}; use rspack_error::Error; use rspack_paths::ArcPathSet; +use rspack_sources::{RawStringSource, SourceExt}; use rustc_hash::{FxHashMap as HashMap, FxHashSet}; use tokio::sync::oneshot::Sender; use super::context::{ExecutorTaskContext, ImportModuleMeta}; use crate::{ - Chunk, ChunkGraph, ChunkKind, CodeGenerationDataAssetInfo, CodeGenerationDataFilename, - CodeGenerationResult, CompilationAsset, CompilationAssets, EntryOptions, Entrypoint, + Chunk, ChunkGraph, ChunkKind, ChunkUkey, CodeGenerationDataAssetInfo, CodeGenerationDataFilename, + CodeGenerationResult, Compilation, CompilationAsset, CompilationAssets, EntryOptions, Entrypoint, FactorizeInfo, ModuleCodeGenerationContext, ModuleType, PublicPath, RuntimeSpec, SourceType, compilation::{ code_generation::code_generation_modules, @@ -19,6 +20,9 @@ use crate::{ process_chunks_runtime_requirements, process_modules_runtime_requirements, }, }, + render_runtime_module_source, + runtime_globals::{RuntimeVariable, runtime_variable_name}, + runtime_mode::RuntimeMode, utils::task_loop::{Task, TaskResult, TaskType}, }; @@ -35,6 +39,62 @@ pub struct ExecutedRuntimeModule { static EXECUTE_MODULE_ID: AtomicU32 = AtomicU32::new(0); pub type ExecuteModuleId = u32; +fn create_execute_runtime_source( + compilation: &Compilation, + chunk_ukey: &ChunkUkey, + runtime_modules: &[Identifier], +) -> Option<(Identifier, CodeGenerationResult)> { + if compilation.options.experiments.runtime_mode != RuntimeMode::Rspack { + return None; + } + + let metadata = compilation + .runtime_proxy_metadata_artifact + .get(chunk_ukey)?; + let lexical_fields = metadata.lexical_fields(); + let context_fields = metadata.context_fields(); + if lexical_fields.is_empty() && context_fields.is_empty() && runtime_modules.is_empty() { + return None; + } + + let runtime_context = runtime_variable_name(&RuntimeVariable::Context); + let mut source = String::new(); + source.push_str(&metadata.render_lexical_declarations()); + for runtime_id in runtime_modules { + let runtime_module = compilation + .runtime_modules + .get(runtime_id) + .expect("runtime module should exist"); + let runtime_module_source = compilation + .code_generation_results + .get(runtime_id, None) + .get(&SourceType::JavaScript) + .expect("runtime module should have runtime source"); + source.push_str( + &render_runtime_module_source( + runtime_module.identifier(), + runtime_module_source.clone(), + runtime_module.should_isolate(), + compilation + .options + .output + .environment + .supports_arrow_function(), + ) + .source() + .into_string_lossy(), + ); + } + source.push_str(&metadata.render_context_setter_assignments(runtime_context)); + + (!source.is_empty()).then(|| { + ( + Identifier::from("rspack/runtime/execute_module_runtime"), + CodeGenerationResult::default().with_javascript(RawStringSource::from(source).boxed()), + ) + }) +} + #[derive(Debug, Default)] pub struct ExecuteModuleResult { pub error: Option, @@ -226,7 +286,6 @@ impl Task for ExecuteTask { let mut compilation = origin_context.transform_to_temp_compilation(); let main_compilation_plugin_driver = compilation.plugin_driver.clone(); compilation.plugin_driver = compilation.buildtime_plugin_driver.clone(); - tracing::debug!("modules: {:?}", &modules); let mut chunk_graph = ChunkGraph::default(); @@ -310,9 +369,9 @@ impl Task for ExecuteTask { let runtime_modules = compilation .build_chunk_graph_artifact .chunk_graph - .get_chunk_runtime_modules_iterable(&chunk_ukey) - .copied() - .collect::(); + .get_chunk_runtime_modules_in_order(&chunk_ukey, &compilation) + .map(|(identifier, _)| *identifier) + .collect_vec(); tracing::debug!( "runtime modules: {:?}", @@ -333,7 +392,6 @@ impl Task for ExecuteTask { concatenation_scope: None, runtime_template: &mut runtime_template, }; - let result = runtime_module .code_generation(&mut code_generation_context) .await?; @@ -355,12 +413,28 @@ impl Task for ExecuteTask { .insert(runtime_module.identifier()); } + let runtime_modules_to_execute = if let Some((runtime_identifier, runtime_result)) = + create_execute_runtime_source(&compilation, &chunk_ukey, &runtime_modules) + { + compilation.code_generation_results.insert( + runtime_identifier, + runtime_result, + std::iter::once(runtime.clone()), + ); + compilation + .code_generated_modules + .insert(runtime_identifier); + vec![runtime_identifier] + } else { + runtime_modules.clone() + }; + let exports = main_compilation_plugin_driver .compilation_hooks .execute_module .call( &entry_module_identifier, - &runtime_modules, + &runtime_modules_to_execute, &compilation.code_generation_results, &id, ) diff --git a/crates/rspack_core/src/compilation/mod.rs b/crates/rspack_core/src/compilation/mod.rs index 6baef342b28a..2b79107e0ad0 100644 --- a/crates/rspack_core/src/compilation/mod.rs +++ b/crates/rspack_core/src/compilation/mod.rs @@ -45,7 +45,7 @@ use rspack_cacheable::{ cacheable, with::{AsOption, AsPreset, AsVec}, }; -use rspack_collections::{IdentifierDashMap, IdentifierMap, IdentifierSet}; +use rspack_collections::{Identifier, IdentifierDashMap, IdentifierMap, IdentifierSet}; use rspack_error::{Diagnostic, Result, ToStringResultToRspackResultExt}; use rspack_fs::{IntermediateFileSystem, ReadableFileSystem, WritableFileSystem}; use rspack_hash::{RspackHash, RspackHashDigest}; @@ -83,9 +83,9 @@ use crate::{ ImportedByDeferModulesArtifact, MemoryGCStorage, ModuleFactory, ModuleGraph, ModuleGraphCacheArtifact, ModuleIdentifier, ModuleIdsArtifact, ModuleStaticCache, PathData, ProcessRuntimeRequirementsCacheArtifact, ResolverFactory, RuntimeGlobals, RuntimeKeyMap, - RuntimeMode, RuntimeModule, RuntimeSpec, RuntimeSpecMap, RuntimeTemplate, SharedPluginDriver, - SideEffectsOptimizeArtifact, SideEffectsStateArtifact, SourceType, Stats, StatsContext, - StealCell, ValueCacheVersions, + RuntimeMode, RuntimeModule, RuntimeProxyMetadataArtifact, RuntimeSpec, RuntimeSpecMap, + RuntimeTemplate, SharedPluginDriver, SideEffectsOptimizeArtifact, SideEffectsStateArtifact, + SourceType, Stats, StatsContext, StealCell, ValueCacheVersions, cache::persistent::occasion::minimize::MinimizePersistentCacheArtifact, compilation::build_module_graph::{ BuildModuleGraphArtifact, ModuleExecutor, UpdateParam, update_module_graph, @@ -102,7 +102,7 @@ define_hook!(CompilationRevokedModules: Series(compilation: &Compilation, revoke define_hook!(CompilationStillValidModule: Series(compiler_id: CompilerId, compilation_id: CompilationId, module: &mut BoxModule)); define_hook!(CompilationSucceedModule: Series(compiler_id: CompilerId, compilation_id: CompilationId, module: &mut BoxModule),tracing=false); define_hook!(CompilationExecuteModule: - Series(module: &ModuleIdentifier, runtime_modules: &IdentifierSet, code_generation_results: &BindingCell, execute_module_id: &ExecuteModuleId)); + Series(module: &ModuleIdentifier, runtime_modules: &[Identifier], code_generation_results: &BindingCell, execute_module_id: &ExecuteModuleId)); define_hook!(CompilationFinishModules: Series(compilation: &Compilation, async_modules_artifact: &mut AsyncModulesArtifact, exports_info_artifact: &mut ExportsInfoArtifact, side_effects_state_artifact: &mut SideEffectsStateArtifact)); define_hook!(CompilationSeal: Series(compilation: &Compilation, diagnostics: &mut Vec)); define_hook!(CompilationDependencyReferencedExports: Sync( @@ -258,6 +258,8 @@ pub struct Compilation { pub cgm_runtime_requirements_artifact: StealCell, // artifact for process_chunks_runtime_requirements pub cgc_runtime_requirements_artifact: StealCell, + // artifact for rspack runtime proxy metadata + pub runtime_proxy_metadata_artifact: StealCell, // artifact for create_hash pub chunk_hashes_artifact: StealCell, // artifact for create_chunk_assets @@ -393,6 +395,7 @@ impl Compilation { cgm_hash_artifact: StealCell::new(Default::default()), cgm_runtime_requirements_artifact: StealCell::new(Default::default()), cgc_runtime_requirements_artifact: StealCell::new(Default::default()), + runtime_proxy_metadata_artifact: StealCell::new(Default::default()), chunk_hashes_artifact: StealCell::new(Default::default()), chunk_render_artifact: StealCell::new(Default::default()), module_graph_cache_artifact: StealCell::new(Default::default()), diff --git a/crates/rspack_core/src/compilation/runtime_requirements/mod.rs b/crates/rspack_core/src/compilation/runtime_requirements/mod.rs index 051c12c58cbf..98290b6b3e8e 100644 --- a/crates/rspack_core/src/compilation/runtime_requirements/mod.rs +++ b/crates/rspack_core/src/compilation/runtime_requirements/mod.rs @@ -2,7 +2,10 @@ use async_trait::async_trait; use rustc_hash::{FxHashMap, FxHashSet}; use super::*; -use crate::{cache::Cache, compilation::pass::PassExt, logger::Logger}; +use crate::{ + CodeGenerationRuntimeRequirementsWrite, RuntimeProxyMetadata, cache::Cache, + compilation::pass::PassExt, logger::Logger, runtime_mode::RuntimeMode as ExperimentRuntimeMode, +}; pub struct RuntimeRequirementsPass; @@ -390,6 +393,10 @@ pub async fn process_chunks_runtime_requirements( }) .await?; + if compilation.options.experiments.runtime_mode == ExperimentRuntimeMode::Rspack { + set = set.with_require_scope(); + } + for module in runtime_modules_to_add { compilation.add_runtime_module(&chunk_ukey, module)?; } @@ -475,6 +482,10 @@ pub async fn process_chunks_runtime_requirements( } } + if compilation.options.experiments.runtime_mode == ExperimentRuntimeMode::Rspack { + all_runtime_requirements = all_runtime_requirements.with_require_scope(); + } + ChunkGraph::set_tree_runtime_requirements(compilation, entry_ukey, all_runtime_requirements); for (chunk_ukey, module) in runtime_modules_to_add { compilation.add_runtime_module(&chunk_ukey, module)?; @@ -508,6 +519,94 @@ pub async fn process_chunks_runtime_requirements( } compilation.runtime_modules = runtime_modules; + compilation.runtime_proxy_metadata_artifact.clear(); + if compilation.options.experiments.runtime_mode != ExperimentRuntimeMode::Rspack { + logger.time_end(start); + return Ok(()); + } + + for &entry_ukey in &entries { + let entry = compilation + .build_chunk_graph_artifact + .chunk_by_ukey + .expect_get(&entry_ukey); + let mut referenced_chunks = + entry.get_all_referenced_chunks(&compilation.build_chunk_graph_artifact.chunk_group_by_ukey); + referenced_chunks.insert(entry_ukey); + let mut metadata = RuntimeProxyMetadata::default(); + + for chunk_ukey in referenced_chunks.iter() { + let chunk = compilation + .build_chunk_graph_artifact + .chunk_by_ukey + .expect_get(chunk_ukey); + if let Some(chunk_runtime_requirements) = compilation + .cgc_runtime_requirements_artifact + .get(chunk_ukey) + { + metadata + .hook_exposed_requirements + .insert(*chunk_runtime_requirements); + } + for mid in compilation + .build_chunk_graph_artifact + .chunk_graph + .get_chunk_modules_identifier(chunk_ukey) + { + if let Some(runtime_requirements) = + ChunkGraph::get_module_runtime_requirements(compilation, *mid, chunk.runtime()) + { + metadata + .module_proxy_requirements + .insert(*runtime_requirements); + } + if compilation + .get_module_graph() + .module_by_identifier(mid) + .is_some() + && let Some(write_requirements) = compilation + .code_generation_results + .get(mid, Some(chunk.runtime())) + .data + .get::() + { + metadata + .context_setter_fields + .insert(write_requirements.runtime_requirements); + } + } + + for runtime_module_id in compilation + .build_chunk_graph_artifact + .chunk_graph + .get_chunk_runtime_modules_iterable(chunk_ukey) + { + let runtime_module = compilation + .runtime_modules + .get(runtime_module_id) + .expect("should have runtime module"); + let additional_runtime_requirements = + runtime_module.additional_runtime_requirements(compilation); + metadata + .runtime_module_requirements + .insert(additional_runtime_requirements); + metadata + .tree_runtime_requirements + .insert(additional_runtime_requirements); + } + } + + metadata + .tree_runtime_requirements + .insert(*ChunkGraph::get_tree_runtime_requirements( + compilation, + &entry_ukey, + )); + compilation + .runtime_proxy_metadata_artifact + .insert(entry_ukey, metadata); + } + logger.time_end(start); Ok(()) } diff --git a/crates/rspack_core/src/context_module.rs b/crates/rspack_core/src/context_module.rs index 510fb8d651d6..06bdf3c9bf38 100644 --- a/crates/rspack_core/src/context_module.rs +++ b/crates/rspack_core/src/context_module.rs @@ -1128,8 +1128,8 @@ impl ContextModule { var map = {map}; {fake_map_init_statement} - function __rspack_context(req) {{ - var id = __rspack_context_resolve(req); + function __rspack_context_module(req) {{ + var id = __rspack_context_module_resolve(req); if(!{module_factories}[id]) {{ var e = new Error("Module '" + req + "' ('" + id + "') is not available (weak dependency)"); e.code = 'MODULE_NOT_FOUND'; @@ -1137,7 +1137,7 @@ impl ContextModule { }} return {return_module_object}; }} - function __rspack_context_resolve(req) {{ + function __rspack_context_module_resolve(req) {{ if(!{has_own_property}(map, req)) {{ var e = new Error("Cannot find module '" + req + "'"); e.code = 'MODULE_NOT_FOUND'; @@ -1145,10 +1145,10 @@ impl ContextModule { }} return map[req]; }} - __rspack_context.keys = {keys}; - __rspack_context.resolve = __rspack_context_resolve; - __rspack_context.id = {id}; - {module}.exports = __rspack_context; + __rspack_context_module.keys = {keys}; + __rspack_context_module.resolve = __rspack_context_module_resolve; + __rspack_context_module.id = {id}; + {module}.exports = __rspack_context_module; "#, module = runtime_template.render_module_argument(ModuleArgument::Module), map = json_stringify_pretty(&map), @@ -1240,11 +1240,11 @@ impl ContextModule { var map = {map}; {fake_map_init_statement} - function __rspack_context(req) {{ - var id = __rspack_context_resolve(req); + function __rspack_context_module(req) {{ + var id = __rspack_context_module_resolve(req); return {return_module_object}; }} - function __rspack_context_resolve(req) {{ + function __rspack_context_module_resolve(req) {{ if(!{has_own_property}(map, req)) {{ var e = new Error("Cannot find module '" + req + "'"); e.code = 'MODULE_NOT_FOUND'; @@ -1252,10 +1252,10 @@ impl ContextModule { }} return map[req]; }} - __rspack_context.keys = {keys}; - __rspack_context.resolve = __rspack_context_resolve; - {module}.exports = __rspack_context; - __rspack_context.id = {id}; + __rspack_context_module.keys = {keys}; + __rspack_context_module.resolve = __rspack_context_module_resolve; + {module}.exports = __rspack_context_module; + __rspack_context_module.id = {id}; "#, module = runtime_template.render_module_argument(ModuleArgument::Module), map = json_stringify_pretty(&map), diff --git a/crates/rspack_core/src/dependency/mod.rs b/crates/rspack_core/src/dependency/mod.rs index 4c5613e45986..4171a32a0848 100644 --- a/crates/rspack_core/src/dependency/mod.rs +++ b/crates/rspack_core/src/dependency/mod.rs @@ -36,7 +36,8 @@ use rspack_cacheable::{ with::{AsPreset, AsVec}, }; pub use runtime_requirements_dependency::{ - RuntimeRequirementsDependency, RuntimeRequirementsDependencyTemplate, + CodeGenerationRuntimeRequirementsWrite, RuntimeRequirementsDependency, + RuntimeRequirementsDependencyTemplate, }; use rustc_hash::{FxHashMap, FxHashSet}; use serde::Serialize; diff --git a/crates/rspack_core/src/dependency/runtime_requirements_dependency.rs b/crates/rspack_core/src/dependency/runtime_requirements_dependency.rs index ebb0e032454f..bb51ab9623cf 100644 --- a/crates/rspack_core/src/dependency/runtime_requirements_dependency.rs +++ b/crates/rspack_core/src/dependency/runtime_requirements_dependency.rs @@ -13,6 +13,9 @@ pub enum RuntimeRequirementsDependencyMode { Normal, Call, AddOnly, + Write, + WriteOnly, + UnsupportedRequireProperty, } #[cacheable] @@ -63,6 +66,41 @@ impl RuntimeRequirementsDependency { mode: RuntimeRequirementsDependencyMode::AddOnly, } } + pub fn write(range: DependencyRange, runtime_requirements: RuntimeGlobals) -> Self { + Self { + range, + runtime_requirements, + mode: RuntimeRequirementsDependencyMode::Write, + } + } + pub fn write_only(runtime_requirements: RuntimeGlobals) -> Self { + Self { + range: DependencyRange::default(), + runtime_requirements, + mode: RuntimeRequirementsDependencyMode::WriteOnly, + } + } + pub fn unsupported_require_property( + range: DependencyRange, + runtime_requirements: RuntimeGlobals, + ) -> Self { + Self { + range, + runtime_requirements, + mode: RuntimeRequirementsDependencyMode::UnsupportedRequireProperty, + } + } +} + +#[derive(Debug, Default, Clone)] +pub struct CodeGenerationRuntimeRequirementsWrite { + pub runtime_requirements: RuntimeGlobals, +} + +impl CodeGenerationRuntimeRequirementsWrite { + pub fn insert(&mut self, runtime_requirements: RuntimeGlobals) { + self.runtime_requirements.insert(runtime_requirements); + } } #[cacheable] @@ -97,6 +135,46 @@ impl DependencyTemplate for RuntimeRequirementsDependencyTemplate { return; } + if matches!( + dep.mode, + RuntimeRequirementsDependencyMode::UnsupportedRequireProperty + ) { + source.replace(dep.range.start, dep.range.end, "undefined".into(), None); + return; + } + + if matches!( + dep.mode, + RuntimeRequirementsDependencyMode::Write | RuntimeRequirementsDependencyMode::WriteOnly + ) { + code_generatable_context + .runtime_template + .runtime_requirements_mut() + .insert(dep.runtime_requirements); + if code_generatable_context + .data + .get::() + .is_none() + { + code_generatable_context + .data + .insert(CodeGenerationRuntimeRequirementsWrite::default()); + } + code_generatable_context + .data + .get_mut::() + .expect("should have runtime requirements write metadata") + .insert(dep.runtime_requirements); + if matches!(dep.mode, RuntimeRequirementsDependencyMode::WriteOnly) { + return; + } + let content = code_generatable_context + .runtime_template + .render_runtime_globals(&dep.runtime_requirements); + source.replace(dep.range.start, dep.range.end, content, None); + return; + } + let mut content = code_generatable_context .runtime_template .render_runtime_globals(&dep.runtime_requirements); diff --git a/crates/rspack_core/src/lib.rs b/crates/rspack_core/src/lib.rs index 9ffe6a413897..49ffd8294472 100644 --- a/crates/rspack_core/src/lib.rs +++ b/crates/rspack_core/src/lib.rs @@ -43,6 +43,8 @@ pub use parser_and_generator::*; mod runtime_globals; pub use normal_module::*; pub use runtime_globals::{MODULE_GLOBALS, REQUIRE_SCOPE_GLOBALS, RuntimeGlobals, RuntimeVariable}; +mod runtime_module_source; +pub use runtime_module_source::render_runtime_module_source; mod plugin; pub use plugin::*; mod context_module; diff --git a/crates/rspack_core/src/options/experiments/mod.rs b/crates/rspack_core/src/options/experiments/mod.rs index 6ed6aeb59bc8..e5473d1c5145 100644 --- a/crates/rspack_core/src/options/experiments/mod.rs +++ b/crates/rspack_core/src/options/experiments/mod.rs @@ -1,10 +1,39 @@ // BE CAREFUL: // Add more fields to this struct should result in adding new fields to options builder. // `impl From for ExperimentsBuilder` should be updated. +pub mod runtime_mode { + use std::fmt; + + #[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] + pub enum RuntimeMode { + #[default] + Webpack, + Rspack, + } + + impl fmt::Display for RuntimeMode { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + RuntimeMode::Webpack => f.write_str("webpack"), + RuntimeMode::Rspack => f.write_str("rspack"), + } + } + } + + impl RuntimeMode { + pub fn uses_runtime_context(&self) -> bool { + matches!(self, RuntimeMode::Rspack) + } + } +} + +use runtime_mode::RuntimeMode; + #[derive(Debug)] pub struct Experiments { pub css: bool, pub defer_import: bool, pub source_import: bool, pub pure_functions: bool, + pub runtime_mode: RuntimeMode, } diff --git a/crates/rspack_core/src/runtime_globals.rs b/crates/rspack_core/src/runtime_globals.rs index d10dbbd37404..814978a32fc1 100644 --- a/crates/rspack_core/src/runtime_globals.rs +++ b/crates/rspack_core/src/runtime_globals.rs @@ -1,6 +1,7 @@ use std::sync::LazyLock; use bitflags::bitflags; +use heck::ToLowerCamelCase; use rustc_hash::FxHashMap; use crate::CompilerOptions; @@ -314,96 +315,35 @@ impl Default for RuntimeGlobals { } pub static REQUIRE_SCOPE_GLOBALS: LazyLock = LazyLock::new(|| { - RuntimeGlobals::REQUIRE_SCOPE - | RuntimeGlobals::MODULE_CACHE - | RuntimeGlobals::ENSURE_CHUNK - | RuntimeGlobals::ENSURE_CHUNK_HANDLERS - | RuntimeGlobals::PUBLIC_PATH - | RuntimeGlobals::GET_CHUNK_SCRIPT_FILENAME - | RuntimeGlobals::GET_CHUNK_CSS_FILENAME - | RuntimeGlobals::LOAD_SCRIPT - | RuntimeGlobals::HAS_OWN_PROPERTY - | RuntimeGlobals::MODULE_FACTORIES_ADD_ONLY - | RuntimeGlobals::ON_CHUNKS_LOADED - | RuntimeGlobals::MODULE_FACTORIES - | RuntimeGlobals::INTERCEPT_MODULE_EXECUTION - | RuntimeGlobals::HMR_DOWNLOAD_MANIFEST - | RuntimeGlobals::HMR_DOWNLOAD_UPDATE_HANDLERS - | RuntimeGlobals::HMR_INVALIDATE_MODULE_HANDLERS - | RuntimeGlobals::HMR_MODULE_DATA - | RuntimeGlobals::HMR_RUNTIME_STATE_PREFIX - | RuntimeGlobals::GET_UPDATE_MANIFEST_FILENAME - | RuntimeGlobals::GET_CHUNK_UPDATE_SCRIPT_FILENAME - | RuntimeGlobals::GET_CHUNK_UPDATE_CSS_FILENAME - | RuntimeGlobals::AMD_DEFINE - | RuntimeGlobals::AMD_OPTIONS - | RuntimeGlobals::EXTERNAL_INSTALL_CHUNK - | RuntimeGlobals::GET_FULL_HASH - | RuntimeGlobals::GLOBAL - | RuntimeGlobals::INSTANTIATE_WASM - | RuntimeGlobals::COMPILE_WASM - | RuntimeGlobals::ASYNC_MODULE - | RuntimeGlobals::ASYNC_MODULE_EXPORT_SYMBOL - | RuntimeGlobals::BASE_URI - | RuntimeGlobals::STARTUP_ENTRYPOINT - | RuntimeGlobals::STARTUP_CHUNK_DEPENDENCIES - | RuntimeGlobals::CREATE_SCRIPT_URL - | RuntimeGlobals::CREATE_SCRIPT - | RuntimeGlobals::GET_TRUSTED_TYPES_POLICY - | RuntimeGlobals::DEFINE_PROPERTY_GETTERS - | RuntimeGlobals::ENTRY_MODULE_ID - | RuntimeGlobals::STARTUP_NO_DEFAULT - | RuntimeGlobals::ENSURE_CHUNK_INCLUDE_ENTRIES - | RuntimeGlobals::STARTUP - | RuntimeGlobals::MAKE_NAMESPACE_OBJECT - | RuntimeGlobals::MAKE_DEFERRED_NAMESPACE_OBJECT - | RuntimeGlobals::MAKE_OPTIMIZED_DEFERRED_NAMESPACE_OBJECT - | RuntimeGlobals::COMPAT_GET_DEFAULT_EXPORT - | RuntimeGlobals::CREATE_FAKE_NAMESPACE_OBJECT - | RuntimeGlobals::ESM_MODULE_DECORATOR - | RuntimeGlobals::NODE_MODULE_DECORATOR - | RuntimeGlobals::SYSTEM_CONTEXT - | RuntimeGlobals::CURRENT_REMOTE_GET_SCOPE - | RuntimeGlobals::SHARE_SCOPE_MAP - | RuntimeGlobals::INITIALIZE_SHARING - | RuntimeGlobals::SCRIPT_NONCE - | RuntimeGlobals::RELATIVE_URL - | RuntimeGlobals::CHUNK_NAME - | RuntimeGlobals::RUNTIME_ID - | RuntimeGlobals::PREFETCH_CHUNK - | RuntimeGlobals::PREFETCH_CHUNK_HANDLERS - | RuntimeGlobals::PRELOAD_CHUNK - | RuntimeGlobals::PRELOAD_CHUNK_HANDLERS - | RuntimeGlobals::UNCAUGHT_ERROR_HANDLER - | RuntimeGlobals::RSPACK_VERSION - | RuntimeGlobals::RSPACK_UNIQUE_ID - | RuntimeGlobals::ASYNC_STARTUP - | RuntimeGlobals::RSC_MANIFEST - | RuntimeGlobals::TO_BINARY - | RuntimeGlobals::DEFERRED_MODULES_ASYNC_TRANSITIVE_DEPENDENCIES - | RuntimeGlobals::DEFERRED_MODULES_ASYNC_TRANSITIVE_DEPENDENCIES_SYMBOL + let mut runtime_globals = RuntimeGlobals::all(); + runtime_globals.remove( + RuntimeGlobals::MODULE + | RuntimeGlobals::MODULE_ID + | RuntimeGlobals::CHUNK_CALLBACK + | RuntimeGlobals::RETURN_EXPORTS_FROM_RUNTIME + | RuntimeGlobals::MODULE_LOADED + | RuntimeGlobals::EXPORTS + | RuntimeGlobals::THIS_AS_EXPORTS + | RuntimeGlobals::HAS_CSS_MODULES + | RuntimeGlobals::HAS_FETCH_PRIORITY, + ); + runtime_globals }); pub static MODULE_GLOBALS: LazyLock = LazyLock::new(|| RuntimeGlobals::MODULE_ID | RuntimeGlobals::MODULE_LOADED); -pub fn runtime_globals_to_string( - runtime_globals: &RuntimeGlobals, - compiler_options: &CompilerOptions, -) -> String { - if runtime_globals == &RuntimeGlobals::EXPORTS { - return runtime_variable_to_string(&RuntimeVariable::Exports, compiler_options); - } - - if runtime_globals == &RuntimeGlobals::REQUIRE { - return runtime_variable_to_string(&RuntimeVariable::Require, compiler_options); - } - - if runtime_globals == &RuntimeGlobals::MODULE { - return "module".to_string(); - } +pub static BOOTSTRAP_RUNTIME_CONTEXT_GLOBALS: LazyLock = LazyLock::new(|| { + RuntimeGlobals::REQUIRE + | RuntimeGlobals::INTERCEPT_MODULE_EXECUTION + | RuntimeGlobals::MODULE + | RuntimeGlobals::MODULE_FACTORIES + | RuntimeGlobals::MODULE_FACTORIES_ADD_ONLY + | RuntimeGlobals::MODULE_CACHE +}); - let name = match *runtime_globals { +pub fn runtime_globals_property_name(runtime_globals: &RuntimeGlobals) -> Option<&'static str> { + Some(match *runtime_globals { RuntimeGlobals::REQUIRE_SCOPE => "*", RuntimeGlobals::MODULE_ID => "id", RuntimeGlobals::MODULE_LOADED => "loaded", @@ -449,7 +389,7 @@ pub fn runtime_globals_to_string( RuntimeGlobals::STARTUP_NO_DEFAULT => "x (no default handler)", RuntimeGlobals::ENSURE_CHUNK_INCLUDE_ENTRIES => "f (include entries)", RuntimeGlobals::STARTUP => "x", - RuntimeGlobals::MAKE_NAMESPACE_OBJECT => "r", + RuntimeGlobals::MAKE_NAMESPACE_OBJECT => "N", RuntimeGlobals::MAKE_DEFERRED_NAMESPACE_OBJECT => "z", RuntimeGlobals::MAKE_OPTIMIZED_DEFERRED_NAMESPACE_OBJECT => "zO", RuntimeGlobals::DEFERRED_MODULES_ASYNC_TRANSITIVE_DEPENDENCIES => "zT", @@ -481,12 +421,29 @@ pub fn runtime_globals_to_string( RuntimeGlobals::RSC_MANIFEST => "rscM", RuntimeGlobals::TO_BINARY => "tb", - _ => unreachable!(), - }; + _ => return None, + }) +} + +pub fn runtime_globals_to_string(runtime_globals: &RuntimeGlobals) -> String { + if runtime_globals == &RuntimeGlobals::EXPORTS { + return runtime_variable_name(&RuntimeVariable::Exports).to_string(); + } + + if runtime_globals == &RuntimeGlobals::REQUIRE { + return runtime_variable_name(&RuntimeVariable::Require).to_string(); + } + + if runtime_globals == &RuntimeGlobals::MODULE { + return "module".to_string(); + } + + let name = runtime_globals_property_name(runtime_globals) + .expect("runtime global should have a property name"); if REQUIRE_SCOPE_GLOBALS.contains(*runtime_globals) { - let require = runtime_variable_to_string(&RuntimeVariable::Require, compiler_options); + let require = runtime_variable_name(&RuntimeVariable::Require); let mut result = String::with_capacity(require.len() + 1 + name.len()); - result.push_str(&require); + result.push_str(require); result.push('.'); result.push_str(name); return result; @@ -504,6 +461,7 @@ pub fn runtime_globals_to_string( #[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)] pub enum RuntimeVariable { Require, + Context, Modules, ModuleCache, Module, @@ -516,36 +474,106 @@ pub fn runtime_variable_to_string( _compiler_options: &CompilerOptions, ) -> String { // TODO: use compiler options to get runtime variable names + runtime_variable_name(runtime_variable).to_string() +} + +pub fn runtime_variable_name(runtime_variable: &RuntimeVariable) -> &'static str { match *runtime_variable { - RuntimeVariable::Require => "__webpack_require__".to_string(), - RuntimeVariable::Modules => "__webpack_modules__".to_string(), - RuntimeVariable::ModuleCache => "__webpack_module_cache__".to_string(), - RuntimeVariable::Exports => "__webpack_exports__".to_string(), - RuntimeVariable::Module => "__webpack_module__".to_string(), - RuntimeVariable::StartupExec => "__webpack_exec__".to_string(), + RuntimeVariable::Require => "__webpack_require__", + RuntimeVariable::Context => "__rspack_context", + RuntimeVariable::Modules => "__webpack_modules__", + RuntimeVariable::ModuleCache => "__webpack_module_cache__", + RuntimeVariable::Exports => "__webpack_exports__", + RuntimeVariable::Module => "__webpack_module__", + RuntimeVariable::StartupExec => "__webpack_exec__", } } type RuntimeGlobalMap = ( FxHashMap, FxHashMap<&'static str, RuntimeGlobals>, + FxHashMap<&'static str, RuntimeGlobals>, + FxHashMap, ); static RUNTIME_GLOBAL_MAP: LazyLock = LazyLock::new(|| { - let mut to_js_map = FxHashMap::default(); - let mut from_js_map = FxHashMap::default(); + let mut to_flag_name_map = FxHashMap::default(); + let mut from_flag_name_map = FxHashMap::default(); + let mut from_property_name_map = FxHashMap::default(); + let mut to_lexical_name_map = FxHashMap::default(); for (name, value) in RuntimeGlobals::all().iter_names() { - to_js_map.insert(value, name); - from_js_map.insert(name, value); + to_flag_name_map.insert(value, name); + from_flag_name_map.insert(name, value); + to_lexical_name_map.insert(value, name.to_lower_camel_case()); + if let Some(property_name) = runtime_globals_property_name(&value) { + from_property_name_map.insert(property_name, value); + } } - to_js_map.shrink_to_fit(); - from_js_map.shrink_to_fit(); - (to_js_map, from_js_map) + to_flag_name_map.shrink_to_fit(); + from_flag_name_map.shrink_to_fit(); + from_property_name_map.shrink_to_fit(); + to_lexical_name_map.shrink_to_fit(); + ( + to_flag_name_map, + from_flag_name_map, + from_property_name_map, + to_lexical_name_map, + ) }); impl RuntimeGlobals { + pub fn property_name(&self) -> Option<&'static str> { + runtime_globals_property_name(self) + } + + pub fn name(&self) -> Option<&'static str> { + RUNTIME_GLOBAL_MAP.0.get(self).copied() + } + + pub fn from_property_name(property_name: &str) -> Option { + RUNTIME_GLOBAL_MAP.2.get(property_name).copied() + } + + pub fn renderable_require_scope(self) -> Self { + self.intersection(*REQUIRE_SCOPE_GLOBALS) + } + + pub fn with_require_scope(self) -> Self { + if !self.renderable_require_scope().is_empty() { + self | RuntimeGlobals::REQUIRE_SCOPE + } else { + self + } + } + + pub fn to_lexical_name(&self) -> Option<&str> { + RUNTIME_GLOBAL_MAP.3.get(self).map(String::as_str) + } + + pub fn should_initialize_as_object(&self) -> bool { + matches!( + *self, + RuntimeGlobals::ENSURE_CHUNK_HANDLERS + | RuntimeGlobals::PREFETCH_CHUNK_HANDLERS + | RuntimeGlobals::PRELOAD_CHUNK_HANDLERS + | RuntimeGlobals::HMR_DOWNLOAD_UPDATE_HANDLERS + | RuntimeGlobals::HMR_INVALIDATE_MODULE_HANDLERS + | RuntimeGlobals::HMR_MODULE_DATA + ) + } + + pub fn should_initialize_as_array(&self) -> bool { + matches!(*self, RuntimeGlobals::INTERCEPT_MODULE_EXECUTION) + } + + pub fn needs_bootstrap_runtime_context(&self) -> bool { + !self + .intersection(*BOOTSTRAP_RUNTIME_CONTEXT_GLOBALS) + .is_empty() + } + pub fn to_names(&self) -> Vec<&'static str> { let mut res = vec![]; diff --git a/crates/rspack_core/src/runtime_module.rs b/crates/rspack_core/src/runtime_module.rs index 0e65e1c8720d..9e4220a29677 100644 --- a/crates/rspack_core/src/runtime_module.rs +++ b/crates/rspack_core/src/runtime_module.rs @@ -35,16 +35,14 @@ pub trait RuntimeModule: &self, context: &RuntimeModuleGenerateContext<'_>, ) -> rspack_error::Result; - async fn generate_with_custom(&self, compilation: &Compilation) -> rspack_error::Result { + async fn generate_with_custom( + &self, + context: &RuntimeModuleGenerateContext<'_>, + ) -> rspack_error::Result { if let Some(custom_source) = self.get_custom_source() { Ok(custom_source) } else { - let runtime_template = compilation.runtime_template.create_runtime_code_template(); - let context = RuntimeModuleGenerateContext { - compilation, - runtime_template: &runtime_template, - }; - self.generate(&context).await + self.generate(context).await } } fn additional_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { diff --git a/crates/rspack_core/src/runtime_module_source.rs b/crates/rspack_core/src/runtime_module_source.rs new file mode 100644 index 000000000000..780d757b02e6 --- /dev/null +++ b/crates/rspack_core/src/runtime_module_source.rs @@ -0,0 +1,33 @@ +use rspack_collections::Identifier; +use rspack_sources::{BoxSource, ConcatSource, RawStringSource, SourceExt}; + +pub fn render_runtime_module_source( + identifier: Identifier, + source: BoxSource, + should_isolate: bool, + supports_arrow_function: bool, +) -> BoxSource { + let mut sources = ConcatSource::default(); + if source.size() == 0 { + return sources.boxed(); + } + + sources.add(RawStringSource::from(format!("// {identifier}\n"))); + if should_isolate { + sources.add(RawStringSource::from_static(if supports_arrow_function { + "(() => {\n" + } else { + "!function() {\n" + })); + } + sources.add(source); + if should_isolate { + sources.add(RawStringSource::from_static(if supports_arrow_function { + "\n})();\n" + } else { + "\n}();\n" + })); + } + + sources.boxed() +} diff --git a/crates/rspack_core/src/runtime_template.rs b/crates/rspack_core/src/runtime_template.rs index 00bce507b402..63cf70c77400 100644 --- a/crates/rspack_core/src/runtime_template.rs +++ b/crates/rspack_core/src/runtime_template.rs @@ -1,4 +1,5 @@ use std::{ + borrow::Cow, collections::HashMap, fmt::{Debug, Write}, sync::{Arc, LazyLock, Mutex}, @@ -12,8 +13,8 @@ use rspack_collections::{Identifier, IdentifierSet}; use rspack_dojang::{Context, Dojang, FunctionContainer, Operand}; use rspack_error::{Error, Result, ToStringResultToRspackResultExt, error}; use rspack_util::{fx_hash::FxIndexSet, json_stringify}; -use rustc_hash::FxHashSet as HashSet; -use serde_json::{Map, Value, json}; +use rustc_hash::{FxHashMap, FxHashSet as HashSet}; +use serde_json::{Value, json}; use swc_core::atoms::Atom; use crate::{ @@ -24,32 +25,80 @@ use crate::{ ModuleGraphCacheArtifact, ModuleId, ModuleIdentifier, NormalInitFragment, PathInfo, RuntimeCondition, RuntimeGlobals, RuntimeSpec, UsedName, compile_boolean_matcher_from_lists, contextify, property_access, - runtime_globals::{RuntimeVariable, runtime_globals_to_string, runtime_variable_to_string}, + runtime_globals::{ + RuntimeVariable, runtime_globals_to_string, runtime_variable_name, runtime_variable_to_string, + }, + runtime_mode::RuntimeMode, to_comment, to_normal_comment, }; pub struct RuntimeTemplate { compiler_options: Arc, - runtime_globals: Arc>, + runtime_mode: RuntimeMode, + runtime_globals: Arc, + module_runtime_globals: Arc, dojang: Option, } static RUNTIME_GLOBALS_PATTERN: LazyLock = LazyLock::new(|| Regex::new(r"\$\$RUNTIME_GLOBAL_(.*?)\$\$").expect("failed to create regex")); -fn replace_runtime_globals(template: String, runtime_globals: &Map) -> String { - RUNTIME_GLOBALS_PATTERN - .replace_all(&template, |caps: &Captures| { - let name = caps.get(1).expect("name should be a string").as_str(); - runtime_globals - .get(name) - .map(|value| match value { - Value::String(value) => value.clone(), - _ => unreachable!(), - }) - .expect("value should be a string") - }) - .to_string() +static WEBPACK_RUNTIME_GLOBALS: LazyLock> = LazyLock::new(|| { + Arc::new(runtime_globals_to_render_map( + RuntimeGlobalRenderMode::Webpack, + )) +}); + +static RSPACK_MODULE_RUNTIME_GLOBALS: LazyLock> = + LazyLock::new(|| { + Arc::new(runtime_globals_to_render_map( + RuntimeGlobalRenderMode::RspackModule, + )) + }); + +static RSPACK_RUNTIME_GLOBALS: LazyLock> = LazyLock::new(|| { + Arc::new(runtime_globals_to_render_map( + RuntimeGlobalRenderMode::RspackRuntimeModule, + )) +}); + +#[derive(Debug, Clone, Copy, Default, Eq, PartialEq)] +pub enum RuntimeGlobalRenderMode { + #[default] + Webpack, + RspackModule, + RspackRuntimeModule, +} + +#[derive(Debug)] +struct RuntimeGlobalsRenderMap { + runtime_values: FxHashMap, +} + +impl RuntimeGlobalsRenderMap { + fn render(&self, runtime_globals: &RuntimeGlobals) -> String { + self + .runtime_values + .get(runtime_globals) + .expect("runtime global should be a single known flag") + .clone() + } + + fn render_template_placeholder(&self, name: &str) -> String { + let runtime_globals = + RuntimeGlobals::from_name(name).expect("runtime global name should be known"); + self.render(&runtime_globals) + } +} + +fn replace_runtime_globals<'a>( + template: &'a str, + runtime_globals: &RuntimeGlobalsRenderMap, +) -> Cow<'a, str> { + RUNTIME_GLOBALS_PATTERN.replace_all(template, |caps: &Captures| { + let name = caps.get(1).expect("name should be a string").as_str(); + runtime_globals.render_template_placeholder(name) + }) } impl Debug for RuntimeTemplate { @@ -60,18 +109,9 @@ impl Debug for RuntimeTemplate { impl RuntimeTemplate { pub fn new(compiler_options: Arc) -> Self { - let runtime_globals = Arc::new( - RuntimeGlobals::all() - .iter_names() - .map(|(name, value)| { - ( - name.to_string(), - Value::String(runtime_globals_to_string(&value, &compiler_options)), - ) - }) - .collect::>(), - ); - + let runtime_mode = compiler_options.experiments.runtime_mode; + let runtime_globals = get_runtime_globals_render_map(runtime_mode.runtime_render_mode()); + let module_runtime_globals = get_runtime_globals_render_map(runtime_mode.module_render_mode()); let mut dojang = Dojang::new(); let runtime_globals_cloned = runtime_globals.clone(); @@ -135,24 +175,18 @@ impl RuntimeTemplate { Self { compiler_options, + runtime_mode, runtime_globals, + module_runtime_globals, dojang: Some(dojang), } } pub fn add_templates(&mut self, templates: Vec<(String, String)>) { for (key, template) in templates { - if !self - .dojang - .as_ref() - .expect("dojang should be initialized") - .templates - .contains_key(&key) - { - self - .dojang - .as_mut() - .expect("dojang should be initialized") + let dojang = self.dojang.as_mut().expect("dojang should be initialized"); + if !dojang.templates.contains_key(&key) { + dojang .add_with_option(key.clone(), template) .unwrap_or_else(|_| panic!("failed to add template {key}")); } @@ -181,7 +215,10 @@ impl RuntimeTemplate { } pub fn create_module_code_template(&self) -> ModuleCodeTemplate { - ModuleCodeTemplate::new(self.compiler_options.clone()) + ModuleCodeTemplate::new( + self.compiler_options.clone(), + self.module_runtime_globals.clone(), + ) } pub fn create_runtime_code_template<'a>(&'a self) -> RuntimeCodeTemplate<'a> { @@ -189,36 +226,142 @@ impl RuntimeTemplate { self.compiler_options.clone(), self.runtime_globals.clone(), self.dojang.as_ref().expect("dojang should be initialized"), + self.runtime_mode.uses_runtime_context(), + self.runtime_mode == RuntimeMode::Rspack, + ) + } + + pub fn create_runtime_module_code_template<'a>(&'a self) -> RuntimeCodeTemplate<'a> { + RuntimeCodeTemplate::new( + self.compiler_options.clone(), + self.module_runtime_globals.clone(), + self.dojang.as_ref().expect("dojang should be initialized"), + self.runtime_mode.uses_runtime_context(), + self.runtime_mode == RuntimeMode::Rspack, + ) + } + + pub fn create_chunk_code_template(&self) -> ChunkCodeTemplate { + ChunkCodeTemplate::new( + self.compiler_options.clone(), + self.module_runtime_globals.clone(), + self.runtime_mode.uses_runtime_context(), + self.runtime_mode == RuntimeMode::Rspack, ) } } -fn to_string(val: &Operand, runtime_globals: &Map) -> String { - replace_runtime_globals( - match val { - Operand::Value(val) => val.as_str().unwrap_or_default().to_string(), - _ => String::default(), - }, - runtime_globals, - ) +impl RuntimeMode { + fn module_render_mode(self) -> RuntimeGlobalRenderMode { + match self { + RuntimeMode::Webpack => RuntimeGlobalRenderMode::Webpack, + RuntimeMode::Rspack => RuntimeGlobalRenderMode::RspackModule, + } + } + + fn runtime_render_mode(self) -> RuntimeGlobalRenderMode { + match self { + RuntimeMode::Webpack => RuntimeGlobalRenderMode::Webpack, + RuntimeMode::Rspack => RuntimeGlobalRenderMode::RspackRuntimeModule, + } + } } -fn join_to_string(val: &Operand, sep: &str, runtime_globals: &Map) -> String { - replace_runtime_globals( - match val { - Operand::Array(items) => items +fn get_runtime_globals_render_map( + render_mode: RuntimeGlobalRenderMode, +) -> Arc { + match render_mode { + RuntimeGlobalRenderMode::Webpack => WEBPACK_RUNTIME_GLOBALS.clone(), + RuntimeGlobalRenderMode::RspackModule => RSPACK_MODULE_RUNTIME_GLOBALS.clone(), + RuntimeGlobalRenderMode::RspackRuntimeModule => RSPACK_RUNTIME_GLOBALS.clone(), + } +} + +fn runtime_globals_to_render_map(render_mode: RuntimeGlobalRenderMode) -> RuntimeGlobalsRenderMap { + let mut runtime_values = FxHashMap::default(); + + for (_, runtime_globals) in RuntimeGlobals::all().iter_names() { + let rendered = match render_mode { + RuntimeGlobalRenderMode::Webpack => { + if runtime_globals == RuntimeGlobals::REQUIRE_SCOPE { + runtime_variable_name(&RuntimeVariable::Require).to_string() + } else { + runtime_globals_to_string(&runtime_globals) + } + } + RuntimeGlobalRenderMode::RspackModule => { + if runtime_globals == RuntimeGlobals::REQUIRE_SCOPE { + runtime_variable_name(&RuntimeVariable::Context).to_string() + } else if runtime_globals == RuntimeGlobals::REQUIRE { + format!("{}.r", runtime_variable_name(&RuntimeVariable::Context)) + } else if runtime_globals.renderable_require_scope() == runtime_globals { + if let Some(name) = runtime_globals.property_name() { + format!( + "{}{}", + runtime_variable_name(&RuntimeVariable::Context), + property_access([name], 0) + ) + } else { + runtime_globals_to_string(&runtime_globals) + } + } else { + runtime_globals_to_string(&runtime_globals) + } + } + RuntimeGlobalRenderMode::RspackRuntimeModule => { + if runtime_globals == RuntimeGlobals::REQUIRE_SCOPE { + runtime_variable_name(&RuntimeVariable::Context).to_string() + } else if runtime_globals == RuntimeGlobals::REQUIRE { + runtime_variable_name(&RuntimeVariable::Require).to_string() + } else if runtime_globals == RuntimeGlobals::MODULE_FACTORIES { + runtime_variable_name(&RuntimeVariable::Modules).to_string() + } else if runtime_globals.renderable_require_scope() == runtime_globals { + runtime_globals.to_lexical_name().map_or_else( + || runtime_globals_to_string(&runtime_globals), + str::to_string, + ) + } else { + runtime_globals_to_string(&runtime_globals) + } + } + }; + + runtime_values.insert(runtime_globals, rendered); + } + + runtime_values.shrink_to_fit(); + + RuntimeGlobalsRenderMap { runtime_values } +} + +fn to_cow<'a>(val: &'a Operand, runtime_globals: &RuntimeGlobalsRenderMap) -> Cow<'a, str> { + match val { + Operand::Value(val) => { + replace_runtime_globals(val.as_str().unwrap_or_default(), runtime_globals) + } + _ => Cow::Borrowed(""), + } +} + +fn join_to_cow<'a>( + val: &'a Operand, + sep: &str, + runtime_globals: &RuntimeGlobalsRenderMap, +) -> Cow<'a, str> { + match val { + Operand::Array(items) => Cow::Owned( + items .iter() - .map(|item| to_string(item, runtime_globals)) + .map(|item| to_cow(item, runtime_globals)) .join(sep), - _ => to_string(val, runtime_globals), - }, - runtime_globals, - ) + ), + _ => to_cow(val, runtime_globals), + } } fn dojang_basic_function( args: Operand, - runtime_globals: &Map, + runtime_globals: &RuntimeGlobalsRenderMap, compiler_options: &Arc, ) -> Operand { if compiler_options @@ -228,12 +371,12 @@ fn dojang_basic_function( { Operand::Value(Value::from(format!( r#"({}) =>"#, - join_to_string(&args, ", ", runtime_globals) + join_to_cow(&args, ", ", runtime_globals) ))) } else { Operand::Value(Value::from(format!( r#"function({})"#, - join_to_string(&args, ", ", runtime_globals) + join_to_cow(&args, ", ", runtime_globals) ))) } } @@ -241,7 +384,7 @@ fn dojang_basic_function( fn dojang_returning_function( return_value: Operand, args: Operand, - runtime_globals: &Map, + runtime_globals: &RuntimeGlobalsRenderMap, compiler_options: &Arc, ) -> Operand { if compiler_options @@ -251,14 +394,14 @@ fn dojang_returning_function( { Operand::Value(Value::from(format!( "({}) => ({})", - join_to_string(&args, ", ", runtime_globals), - to_string(&return_value, runtime_globals) + join_to_cow(&args, ", ", runtime_globals), + to_cow(&return_value, runtime_globals) ))) } else { Operand::Value(Value::from(format!( "function({}) {{ return {}; }}", - join_to_string(&args, ", ", runtime_globals), - to_string(&return_value, runtime_globals) + join_to_cow(&args, ", ", runtime_globals), + to_cow(&return_value, runtime_globals) ))) } } @@ -266,7 +409,7 @@ fn dojang_returning_function( fn dojang_expression_function( expression: Operand, args: Operand, - runtime_globals: &Map, + runtime_globals: &RuntimeGlobalsRenderMap, compiler_options: &Arc, ) -> Operand { if compiler_options @@ -276,14 +419,14 @@ fn dojang_expression_function( { Operand::Value(Value::from(format!( "({}) => ({})", - join_to_string(&args, ", ", runtime_globals), - to_string(&expression, runtime_globals) + join_to_cow(&args, ", ", runtime_globals), + to_cow(&expression, runtime_globals) ))) } else { Operand::Value(Value::from(format!( "function({}) {{ {}; }}", - join_to_string(&args, ", ", runtime_globals), - to_string(&expression, runtime_globals) + join_to_cow(&args, ", ", runtime_globals), + to_cow(&expression, runtime_globals) ))) } } @@ -303,23 +446,23 @@ fn dojang_empty_function(compiler_options: &Arc) -> Operand { fn dojang_array_destructure( items: Operand, value: Operand, - runtime_globals: &Map, + runtime_globals: &RuntimeGlobalsRenderMap, compiler_options: &Arc, ) -> Operand { if compiler_options.output.environment.supports_destructuring() { Operand::Value(Value::from(format!( "var [{}] = {};", - join_to_string(&items, ", ", runtime_globals), - to_string(&value, runtime_globals) + join_to_cow(&items, ", ", runtime_globals), + to_cow(&value, runtime_globals) ))) } else { - let value_name = to_string(&value, runtime_globals); + let value_name = to_cow(&value, runtime_globals).into_owned(); let items = match items { Operand::Array(items) => items .iter() .enumerate() .map(|(idx, item)| { - let item_name = to_string(item, runtime_globals); + let item_name = to_cow(item, runtime_globals); if item_name.is_empty() { String::default() } else { @@ -500,13 +643,18 @@ pub fn get_outgoing_async_modules( #[derive(Debug)] pub struct ModuleCodeTemplate { compiler_options: Arc, + runtime_globals: Arc, runtime_requirements: RuntimeGlobals, } impl ModuleCodeTemplate { - pub fn new(compiler_options: Arc) -> Self { + fn new( + compiler_options: Arc, + runtime_globals: Arc, + ) -> Self { Self { compiler_options, + runtime_globals, runtime_requirements: RuntimeGlobals::default(), } } @@ -521,11 +669,11 @@ impl ModuleCodeTemplate { pub fn render_runtime_globals(&mut self, runtime_globals: &RuntimeGlobals) -> String { self.runtime_requirements.insert(*runtime_globals); - runtime_globals_to_string(runtime_globals, &self.compiler_options) + self.runtime_globals.render(runtime_globals) } pub fn render_runtime_globals_without_adding(&self, runtime_globals: &RuntimeGlobals) -> String { - runtime_globals_to_string(runtime_globals, &self.compiler_options) + self.runtime_globals.render(runtime_globals) } pub fn define_es_module_flag_statement(&mut self, exports_argument: ExportsArgument) -> String { @@ -1458,33 +1606,86 @@ return {} } } -pub struct RuntimeCodeTemplate<'a> { +struct RuntimeCodeTemplateInner<'a> { compiler_options: Arc, - runtime_globals: Arc>, + runtime_globals: Arc, dojang: &'a Dojang, + uses_runtime_context: bool, + uses_lexical_runtime_globals: bool, +} + +pub struct RuntimeCodeTemplate<'a> { + inner: RuntimeCodeTemplateInner<'a>, +} + +pub struct ChunkCodeTemplate { + compiler_options: Arc, + runtime_globals: Arc, + uses_runtime_context: bool, + uses_lexical_runtime_globals: bool, } impl<'a> RuntimeCodeTemplate<'a> { - pub fn new( + fn new( compiler_options: Arc, - runtime_globals: Arc>, + runtime_globals: Arc, dojang: &'a Dojang, + uses_runtime_context: bool, + uses_lexical_runtime_globals: bool, + ) -> Self { + Self { + inner: RuntimeCodeTemplateInner { + compiler_options, + runtime_globals, + dojang, + uses_runtime_context, + uses_lexical_runtime_globals, + }, + } + } +} + +impl ChunkCodeTemplate { + fn new( + compiler_options: Arc, + runtime_globals: Arc, + uses_runtime_context: bool, + uses_lexical_runtime_globals: bool, ) -> Self { Self { compiler_options, runtime_globals, - dojang, + uses_runtime_context, + uses_lexical_runtime_globals, } } +} +impl RuntimeCodeTemplateInner<'_> { pub fn render_runtime_globals(&self, runtime_globals: &RuntimeGlobals) -> String { - runtime_globals_to_string(runtime_globals, &self.compiler_options) + self.runtime_globals.render(runtime_globals) } pub fn render_runtime_variable(&self, runtime_variable: &RuntimeVariable) -> String { runtime_variable_to_string(runtime_variable, &self.compiler_options) } + pub fn uses_runtime_context(&self) -> bool { + self.uses_runtime_context + } + + pub fn render_runtime_argument(&self) -> String { + if self.uses_runtime_context() { + self.render_runtime_variable(&RuntimeVariable::Context) + } else { + self.render_runtime_globals(&RuntimeGlobals::REQUIRE) + } + } + + pub fn uses_lexical_runtime_globals(&self) -> bool { + self.uses_lexical_runtime_globals + } + pub fn render_exports_argument(&self, exports_argument: ExportsArgument) -> String { match exports_argument { ExportsArgument::Exports => "exports".to_string(), @@ -1509,12 +1710,12 @@ impl<'a> RuntimeCodeTemplate<'a> { render_params .as_object_mut() .unwrap_or_else(|| unreachable!()) - .extend( - self - .runtime_globals - .iter() - .map(|(k, v)| (k.clone(), v.clone())), - ); + .extend(RuntimeGlobals::all().iter_names().map(|(name, value)| { + ( + name.to_string(), + Value::String(self.runtime_globals.render(&value)), + ) + })); if let Some(params) = params { match params { @@ -1574,3 +1775,116 @@ impl<'a> RuntimeCodeTemplate<'a> { } } } + +macro_rules! impl_code_template_methods { + ($ty:ident) => { + impl $ty<'_> { + pub fn render_runtime_globals(&self, runtime_globals: &RuntimeGlobals) -> String { + self.inner.render_runtime_globals(runtime_globals) + } + + pub fn render_runtime_variable(&self, runtime_variable: &RuntimeVariable) -> String { + self.inner.render_runtime_variable(runtime_variable) + } + + pub fn uses_runtime_context(&self) -> bool { + self.inner.uses_runtime_context() + } + + pub fn render_runtime_argument(&self) -> String { + self.inner.render_runtime_argument() + } + + pub fn uses_lexical_runtime_globals(&self) -> bool { + self.inner.uses_lexical_runtime_globals() + } + + pub fn render_exports_argument(&self, exports_argument: ExportsArgument) -> String { + self.inner.render_exports_argument(exports_argument) + } + + pub fn render_module_argument(&self, module_argument: ModuleArgument) -> String { + self.inner.render_module_argument(module_argument) + } + + pub fn render_this_exports(&self) -> String { + self.inner.render_this_exports() + } + + pub fn render(&self, key: &str, params: Option) -> Result { + self.inner.render(key, params) + } + + pub fn basic_function(&self, args: &str, body: &str) -> String { + self.inner.basic_function(args, body) + } + } + }; +} + +impl_code_template_methods!(RuntimeCodeTemplate); + +impl ChunkCodeTemplate { + pub fn render_runtime_globals(&self, runtime_globals: &RuntimeGlobals) -> String { + self.runtime_globals.render(runtime_globals) + } + + pub fn render_runtime_variable(&self, runtime_variable: &RuntimeVariable) -> String { + runtime_variable_to_string(runtime_variable, &self.compiler_options) + } + + pub fn uses_runtime_context(&self) -> bool { + self.uses_runtime_context + } + + pub fn render_runtime_argument(&self) -> String { + if self.uses_runtime_context() { + self.render_runtime_variable(&RuntimeVariable::Context) + } else { + self.render_runtime_globals(&RuntimeGlobals::REQUIRE) + } + } + + pub fn uses_lexical_runtime_globals(&self) -> bool { + self.uses_lexical_runtime_globals + } + + pub fn render_exports_argument(&self, exports_argument: ExportsArgument) -> String { + match exports_argument { + ExportsArgument::Exports => "exports".to_string(), + ExportsArgument::RspackExports => self.render_runtime_variable(&RuntimeVariable::Exports), + } + } + + pub fn render_module_argument(&self, module_argument: ModuleArgument) -> String { + match module_argument { + ModuleArgument::Module => "module".to_string(), + ModuleArgument::RspackModule => self.render_runtime_variable(&RuntimeVariable::Module), + } + } + + pub fn render_this_exports(&self) -> String { + "this".to_string() + } + + pub fn basic_function(&self, args: &str, body: &str) -> String { + if self + .compiler_options + .output + .environment + .supports_arrow_function() + { + format!( + r#"({args}) => {{ +{body} +}}"# + ) + } else { + format!( + r#"function({args}) {{ +{body} +}}"# + ) + } + } +} diff --git a/crates/rspack_macros/src/runtime_module.rs b/crates/rspack_macros/src/runtime_module.rs index 2308eea89249..ef8239bff995 100644 --- a/crates/rspack_macros/src/runtime_module.rs +++ b/crates/rspack_macros/src/runtime_module.rs @@ -94,7 +94,12 @@ pub fn impl_runtime_module( use ::rspack_collections::Identifiable; use ::rspack_core::rspack_sources::SourceExt; - let source_str = self.generate_with_custom(compilation).await?; + let runtime_template = compilation.runtime_template.create_runtime_code_template(); + let context = ::rspack_core::RuntimeModuleGenerateContext { + compilation, + runtime_template: &runtime_template, + }; + let source_str = self.generate_with_custom(&context).await?; let source_map_kind = self.get_source_map_kind(); Ok(if source_map_kind.enabled() { ::rspack_core::rspack_sources::OriginalSource::new( @@ -222,7 +227,8 @@ pub fn impl_runtime_module( code_generation_context: &mut ::rspack_core::ModuleCodeGenerationContext, ) -> rspack_error::Result<::rspack_core::CodeGenerationResult> { let mut result = ::rspack_core::CodeGenerationResult::default(); - result.add(::rspack_core::SourceType::Runtime, self.get_generated_code(code_generation_context.compilation).await?); + let source = self.get_generated_code(code_generation_context.compilation).await?; + result.add(::rspack_core::SourceType::Runtime, source); Ok(result) } @@ -238,7 +244,12 @@ pub fn impl_runtime_module( self.stage().dyn_hash(&mut hasher); if self.full_hash() || self.dependent_hash() { use std::hash::Hash; - self.generate_with_custom(compilation).await?.hash(&mut hasher); + let runtime_template = compilation.runtime_template.create_runtime_code_template(); + let context = ::rspack_core::RuntimeModuleGenerateContext { + compilation, + runtime_template: &runtime_template, + }; + self.generate_with_custom(&context).await?.hash(&mut hasher); } else { self.get_generated_code(compilation).await?.dyn_hash(&mut hasher); } diff --git a/crates/rspack_plugin_css/src/runtime/css_loading_create_link.ejs b/crates/rspack_plugin_css/src/runtime/css_loading_create_link.ejs index 5b1e6a91f844..81377c43d627 100644 --- a/crates/rspack_plugin_css/src/runtime/css_loading_create_link.ejs +++ b/crates/rspack_plugin_css/src/runtime/css_loading_create_link.ejs @@ -1,7 +1,7 @@ link = document.createElement("link"); -if (<%- SCRIPT_NONCE %>) { - link.setAttribute("nonce", <%- SCRIPT_NONCE %>); -} +<% if (_with_script_nonce) { %> +if (<%- SCRIPT_NONCE %>) link.setAttribute("nonce", <%- SCRIPT_NONCE %>); +<% } %> <% if (_unique_name != "") { %> link.setAttribute("data-rspack", uniqueName + ":" + key); <% } %> @@ -19,4 +19,4 @@ link.crossOrigin = "use-credentials"; if (link.href.indexOf(window.location.origin + '/') !== 0) { link.crossOrigin = '<%- _cross_origin %>'; } -<% } %> \ No newline at end of file +<% } %> diff --git a/crates/rspack_plugin_css/src/runtime/css_loading_with_prefetch_link.ejs b/crates/rspack_plugin_css/src/runtime/css_loading_with_prefetch_link.ejs index afe8e91245a2..f4a59ba96984 100644 --- a/crates/rspack_plugin_css/src/runtime/css_loading_with_prefetch_link.ejs +++ b/crates/rspack_plugin_css/src/runtime/css_loading_with_prefetch_link.ejs @@ -2,9 +2,9 @@ var link = document.createElement('link'); <% if (_cross_origin != "") { %> link.crossOrigin = '<%- _cross_origin %>'; <% } %> -if (<%- SCRIPT_NONCE %>) { - link.setAttribute("nonce", <%- SCRIPT_NONCE %>); -} +<% if (_with_script_nonce) { %> +if (<%- SCRIPT_NONCE %>) link.setAttribute("nonce", <%- SCRIPT_NONCE %>); +<% } %> link.rel = "prefetch"; link.as = "style"; -link.href = <%- PUBLIC_PATH %> + <%- GET_CHUNK_CSS_FILENAME %>(chunkId); \ No newline at end of file +link.href = <%- PUBLIC_PATH %> + <%- GET_CHUNK_CSS_FILENAME %>(chunkId); diff --git a/crates/rspack_plugin_css/src/runtime/css_loading_with_preload_link.ejs b/crates/rspack_plugin_css/src/runtime/css_loading_with_preload_link.ejs index 586b672d226e..94cf72d9432d 100644 --- a/crates/rspack_plugin_css/src/runtime/css_loading_with_preload_link.ejs +++ b/crates/rspack_plugin_css/src/runtime/css_loading_with_preload_link.ejs @@ -1,7 +1,7 @@ var link = document.createElement('link'); -if (<%- SCRIPT_NONCE %>) { - link.setAttribute("nonce", <%- SCRIPT_NONCE %>); -} +<% if (_with_script_nonce) { %> +if (<%- SCRIPT_NONCE %>) link.setAttribute("nonce", <%- SCRIPT_NONCE %>); +<% } %> link.rel = "preload"; link.as = "style"; link.href = <%- PUBLIC_PATH %> + <%- GET_CHUNK_CSS_FILENAME %>(chunkId); @@ -11,4 +11,4 @@ link.crossOrigin = "use-credentials"; if (link.href.indexOf(window.location.origin + '/') !== 0) { link.crossOrigin = '<%- _cross_origin %>'; } -<% } %> \ No newline at end of file +<% } %> diff --git a/crates/rspack_plugin_css/src/runtime/mod.rs b/crates/rspack_plugin_css/src/runtime/mod.rs index fdcee411236a..5d23bfb84804 100644 --- a/crates/rspack_plugin_css/src/runtime/mod.rs +++ b/crates/rspack_plugin_css/src/runtime/mod.rs @@ -158,6 +158,7 @@ impl RuntimeModule for CssLoadingRuntimeModule { let with_loading = runtime_requirements.contains(RuntimeGlobals::ENSURE_CHUNK_HANDLERS) && !matches!(has_css_matcher, BooleanMatcher::Condition(false)); let with_fetch_priority = runtime_requirements.contains(RuntimeGlobals::HAS_FETCH_PRIORITY); + let with_script_nonce = runtime_requirements.contains(RuntimeGlobals::SCRIPT_NONCE); let initial_chunks = chunk.get_all_initial_chunks(&compilation.build_chunk_graph_artifact.chunk_group_by_ukey); @@ -219,6 +220,7 @@ impl RuntimeModule for CssLoadingRuntimeModule { CrossOriginLoading::Enable(cross_origin) => cross_origin.clone(), }, "_unique_name": unique_name, + "_with_script_nonce": with_script_nonce, })), )?; @@ -313,6 +315,7 @@ installedChunks[chunkId] = 0; &self.template_id(TemplateId::WithPrefetchLink), Some(serde_json::json!({ "_cross_origin": compilation.options.output.cross_origin_loading.to_string(), + "_with_script_nonce": with_script_nonce, })), )?; @@ -345,6 +348,7 @@ installedChunks[chunkId] = 0; &self.template_id(TemplateId::WithPreloadLink), Some(serde_json::json!({ "_cross_origin": compilation.options.output.cross_origin_loading.to_string(), + "_with_script_nonce": with_script_nonce, })), )?; diff --git a/crates/rspack_plugin_devtool/src/eval_dev_tool_module_plugin.rs b/crates/rspack_plugin_devtool/src/eval_dev_tool_module_plugin.rs index 790e320d5cac..26948c8c22ad 100644 --- a/crates/rspack_plugin_devtool/src/eval_dev_tool_module_plugin.rs +++ b/crates/rspack_plugin_devtool/src/eval_dev_tool_module_plugin.rs @@ -3,9 +3,9 @@ use std::{borrow::Cow, hash::Hash}; use cow_utils::CowUtils; use derive_more::Debug; use rspack_core::{ - ChunkInitFragments, ChunkUkey, Compilation, CompilationAdditionalModuleRuntimeRequirements, - CompilationParams, CompilerCompilation, Filename, Module, ModuleIdentifier, PathData, Plugin, - RuntimeCodeTemplate, RuntimeGlobals, + ChunkCodeTemplate, ChunkInitFragments, ChunkUkey, Compilation, + CompilationAdditionalModuleRuntimeRequirements, CompilationParams, CompilerCompilation, Filename, + Module, ModuleIdentifier, PathData, Plugin, RuntimeGlobals, rspack_sources::{BoxSource, RawStringSource, Source, SourceExt}, }; use rspack_error::Result; @@ -92,7 +92,7 @@ async fn render_module_content( module: &dyn Module, render_source: &mut RenderSource, _init_fragments: &mut ChunkInitFragments, - runtime_template: &RuntimeCodeTemplate<'_>, + runtime_template: &ChunkCodeTemplate, ) -> Result<()> { let origin_source = render_source.source.clone(); if let Some(cached_source) = self.cache.get(&origin_source) { diff --git a/crates/rspack_plugin_devtool/src/eval_source_map_dev_tool_plugin.rs b/crates/rspack_plugin_devtool/src/eval_source_map_dev_tool_plugin.rs index e5ec23ab244a..43f3ab48e065 100644 --- a/crates/rspack_plugin_devtool/src/eval_source_map_dev_tool_plugin.rs +++ b/crates/rspack_plugin_devtool/src/eval_source_map_dev_tool_plugin.rs @@ -3,9 +3,9 @@ use std::{hash::Hash, sync::Arc}; use derive_more::Debug; use futures::future::join_all; use rspack_core::{ - ChunkGraph, ChunkInitFragments, ChunkUkey, Compilation, + ChunkCodeTemplate, ChunkGraph, ChunkInitFragments, ChunkUkey, Compilation, CompilationAdditionalModuleRuntimeRequirements, CompilationParams, CompilerCompilation, Filename, - Module, ModuleIdentifier, PathData, Plugin, RuntimeCodeTemplate, RuntimeGlobals, + Module, ModuleIdentifier, PathData, Plugin, RuntimeGlobals, rspack_sources::{BoxSource, MapOptions, ObjectPool, RawStringSource, Source, SourceExt}, }; use rspack_error::Result; @@ -102,7 +102,7 @@ async fn render_module_content( module: &dyn Module, render_source: &mut RenderSource, _init_fragments: &mut ChunkInitFragments, - runtime_template: &RuntimeCodeTemplate<'_>, + runtime_template: &ChunkCodeTemplate, ) -> Result<()> { let output_options = &compilation.options.output; let chunk = compilation diff --git a/crates/rspack_plugin_esm_library/src/chunk_link.rs b/crates/rspack_plugin_esm_library/src/chunk_link.rs index 36abb1c04429..ad276ce3e879 100644 --- a/crates/rspack_plugin_esm_library/src/chunk_link.rs +++ b/crates/rspack_plugin_esm_library/src/chunk_link.rs @@ -2,8 +2,8 @@ use std::{borrow::Cow, sync::Arc}; use rspack_collections::{IdentifierIndexMap, IdentifierIndexSet, IdentifierMap, IdentifierSet}; use rspack_core::{ - BoxChunkInitFragment, ChunkGraph, ChunkUkey, Compilation, ImportSpec, ModuleGraph, - ModuleIdentifier, RuntimeCodeTemplate, RuntimeGlobals, find_new_name, + BoxChunkInitFragment, ChunkCodeTemplate, ChunkGraph, ChunkUkey, Compilation, ImportSpec, + ModuleGraph, ModuleIdentifier, RuntimeGlobals, find_new_name, rspack_sources::{ConcatSource, RawStringSource}, }; use rspack_util::fx_hash::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet}; @@ -163,7 +163,7 @@ impl ExternalInterop { pub fn render( &self, compilation: &Compilation, - runtime_template: &RuntimeCodeTemplate<'_>, + runtime_template: &ChunkCodeTemplate, ) -> ConcatSource { let mut source = ConcatSource::default(); let name = self.required_symbol.as_ref(); diff --git a/crates/rspack_plugin_esm_library/src/link.rs b/crates/rspack_plugin_esm_library/src/link.rs index 918b512b3593..b82e87a60b8b 100644 --- a/crates/rspack_plugin_esm_library/src/link.rs +++ b/crates/rspack_plugin_esm_library/src/link.rs @@ -1376,7 +1376,7 @@ var {} = {{}}; orig_concate_modules_map: &mut IdentifierIndexMap, external_module_init_fragments: &mut IdentifierMap, ) -> Result<()> { - let runtime_template = compilation.runtime_template.create_runtime_code_template(); + let runtime_template = compilation.runtime_template.create_chunk_code_template(); let mut outputs = FxHashMap::::default(); let module_keys: Vec = orig_concate_modules_map.keys().copied().collect(); for m in &module_keys { @@ -2616,10 +2616,8 @@ var {} = {{}}; let info = &concate_modules_map[m]; let runtime_requirements = info.get_runtime_requirements(); if !runtime_requirements.is_empty() && runtime_chunk != *chunk { - let runtime_template = compilation.runtime_template.create_runtime_code_template(); - let require_symbol: Atom = runtime_template - .render_runtime_globals(&RuntimeGlobals::REQUIRE) - .into(); + let runtime_template = compilation.runtime_template.create_chunk_code_template(); + let require_symbol: Atom = runtime_template.render_runtime_argument().into(); if !runtime_chunks_exporting_require_via_runtime_module.contains(&runtime_chunk) { Self::add_chunk_export( runtime_chunk, diff --git a/crates/rspack_plugin_esm_library/src/plugin.rs b/crates/rspack_plugin_esm_library/src/plugin.rs index ece2f513b0ae..9e76c9a4224d 100644 --- a/crates/rspack_plugin_esm_library/src/plugin.rs +++ b/crates/rspack_plugin_esm_library/src/plugin.rs @@ -9,8 +9,8 @@ use rspack_collections::{ Identifiable, Identifier, IdentifierIndexMap, IdentifierMap, IdentifierSet, }; use rspack_core::{ - ApplyContext, AssetInfo, AsyncModulesArtifact, BoxModule, BuildModuleGraphArtifact, ChunkUkey, - Compilation, CompilationAdditionalChunkRuntimeRequirements, + ApplyContext, AssetInfo, AsyncModulesArtifact, BoxModule, BuildModuleGraphArtifact, + ChunkCodeTemplate, ChunkUkey, Compilation, CompilationAdditionalChunkRuntimeRequirements, CompilationAdditionalTreeRuntimeRequirements, CompilationAfterCodeGeneration, CompilationConcatenationScope, CompilationFinishModules, CompilationOptimizeChunkModules, CompilationOptimizeChunks, CompilationOptimizeDependencies, CompilationParams, @@ -19,8 +19,8 @@ use rspack_core::{ ExternalModuleInfo, GetTargetResult, Logger, ModuleFactoryCreateData, ModuleGraph, ModuleIdentifier, ModuleInfo, ModuleType, NormalModuleFactoryAfterFactorize, NormalModuleFactoryParser, ParserAndGenerator, ParserOptions, Plugin, REQUIRE_SCOPE_GLOBALS, - RuntimeCodeTemplate, RuntimeGlobals, RuntimeModule, SideEffectsOptimizeArtifact, - SideEffectsStateArtifact, get_target, is_esm_dep_like, + RuntimeGlobals, RuntimeModule, SideEffectsOptimizeArtifact, SideEffectsStateArtifact, get_target, + is_esm_dep_like, rspack_sources::{ReplaceSource, Source}, }; use rspack_error::{Diagnostic, Result}; @@ -284,7 +284,7 @@ async fn render_chunk_content( compilation: &Compilation, chunk_ukey: &ChunkUkey, asset_info: &mut AssetInfo, - runtime_template: &RuntimeCodeTemplate<'_>, + runtime_template: &ChunkCodeTemplate, ) -> Result> { self .render_chunk(compilation, chunk_ukey, asset_info, runtime_template) @@ -547,7 +547,9 @@ async fn runtime_requirements_in_tree( _runtime_requirements_mut: &mut RuntimeGlobals, runtime_modules_to_add: &mut Vec<(ChunkUkey, Box)>, ) -> Result> { - if runtime_requirements.contains(RuntimeGlobals::MODULE_FACTORIES) { + if runtime_requirements + .intersects(RuntimeGlobals::MODULE_FACTORIES | RuntimeGlobals::MODULE_FACTORIES_ADD_ONLY) + { runtime_modules_to_add.push(( *chunk_ukey, Box::new(EsmRegisterModuleRuntimeModule::new( diff --git a/crates/rspack_plugin_esm_library/src/render.rs b/crates/rspack_plugin_esm_library/src/render.rs index 11a0412123dc..1a498505739a 100644 --- a/crates/rspack_plugin_esm_library/src/render.rs +++ b/crates/rspack_plugin_esm_library/src/render.rs @@ -2,11 +2,10 @@ use std::{borrow::Cow, sync::Arc}; use rspack_collections::IdentifierIndexSet; use rspack_core::{ - AssetInfo, Chunk, ChunkGraph, ChunkGroup, ChunkRenderContext, ChunkUkey, + AssetInfo, Chunk, ChunkCodeTemplate, ChunkGraph, ChunkGroup, ChunkRenderContext, ChunkUkey, CodeGenerationDataFilename, Compilation, ConcatenatedModuleInfo, DependencyId, InitFragment, - ModuleIdentifier, PathData, PathInfo, RuntimeCodeTemplate, RuntimeGlobals, RuntimeVariable, - SourceType, export_name, get_js_chunk_filename_template, get_undo_path, render_imports, - render_init_fragments, + ModuleIdentifier, PathData, PathInfo, RuntimeGlobals, RuntimeVariable, SourceType, export_name, + get_js_chunk_filename_template, get_undo_path, render_imports, render_init_fragments, rspack_sources::{ConcatSource, RawStringSource, ReplaceSource, Source, SourceExt}, }; use rspack_error::Result; @@ -137,7 +136,7 @@ impl EsmLibraryPlugin { compilation: &Compilation, chunk_ukey: &ChunkUkey, asset_info: &mut AssetInfo, - runtime_template: &RuntimeCodeTemplate<'_>, + runtime_template: &ChunkCodeTemplate, ) -> Result> { let module_graph = compilation.get_module_graph(); @@ -156,6 +155,13 @@ impl EsmLibraryPlugin { let concatenated_modules_map = self.concatenated_modules_map.read().await; let chunk = get_chunk(compilation, *chunk_ukey); + let rspack_module_runtime_template; + let module_runtime_template = if runtime_template.uses_runtime_context() { + rspack_module_runtime_template = compilation.runtime_template.create_chunk_code_template(); + &rspack_module_runtime_template + } else { + runtime_template + }; let filename_template = get_js_chunk_filename_template( chunk, &compilation.options.output, @@ -205,7 +211,7 @@ impl EsmLibraryPlugin { true, &output_path, &hooks, - runtime_template, + module_runtime_template, ) .await? else { @@ -301,7 +307,7 @@ var {} = {{}}; chunk_ukey, compilation, effective_tree_requirements, - runtime_template, + module_runtime_template, ) .await?; @@ -317,9 +323,11 @@ var {} = {{}}; && effective_tree_requirements .intersects(RuntimeGlobals::REQUIRE | RuntimeGlobals::REQUIRE_SCOPE) { - export_specifiers.insert(Cow::Owned( - runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE), - )); + export_specifiers.insert(Cow::Owned(if runtime_template.uses_runtime_context() { + runtime_template.render_runtime_variable(&RuntimeVariable::Context) + } else { + runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE) + })); } } @@ -370,7 +378,7 @@ var {} = {{}}; compilation, chunk_link, &mut already_required, - runtime_template, + module_runtime_template, )); render_source.add(source); render_source.add(RawStringSource::from_static("\n")); @@ -384,7 +392,8 @@ var {} = {{}}; .interop_namespace_object_name .clone() .expect("should have interop_namespace_object_name"), - runtime_template.render_runtime_globals(&RuntimeGlobals::CREATE_FAKE_NAMESPACE_OBJECT), + module_runtime_template + .render_runtime_globals(&RuntimeGlobals::CREATE_FAKE_NAMESPACE_OBJECT), info .namespace_object_name .as_ref() @@ -399,7 +408,8 @@ var {} = {{}}; .interop_namespace_object2_name .clone() .expect("should have interop_namespace_object2_name"), - runtime_template.render_runtime_globals(&RuntimeGlobals::CREATE_FAKE_NAMESPACE_OBJECT), + module_runtime_template + .render_runtime_globals(&RuntimeGlobals::CREATE_FAKE_NAMESPACE_OBJECT), info .namespace_object_name .as_ref() @@ -414,7 +424,8 @@ var {} = {{}}; .interop_default_access_name .clone() .expect("should have interop_default_access_name"), - runtime_template.render_runtime_globals(&RuntimeGlobals::COMPAT_GET_DEFAULT_EXPORT), + module_runtime_template + .render_runtime_globals(&RuntimeGlobals::COMPAT_GET_DEFAULT_EXPORT), info .namespace_object_name .as_ref() @@ -433,7 +444,7 @@ var {} = {{}}; } if already_required.insert(*m) { runtime_requirements.insert(RuntimeGlobals::REQUIRE); - render_source.add(required_info.render(compilation, runtime_template)); + render_source.add(required_info.render(compilation, module_runtime_template)); render_source.add(RawStringSource::from_static("\n")); } } @@ -457,20 +468,24 @@ var {} = {{}}; } } - let require_ident = runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE); + let require_ident = module_runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE); + let runtime_import_ident = if module_runtime_template.uses_runtime_context() { + module_runtime_template.render_runtime_variable(&RuntimeVariable::Context) + } else { + require_ident.clone() + }; let import_spec_imports_require = |import_spec: &rspack_core::ImportSpec| { - import_spec - .atoms - .values() - .any(|local| local.as_str() == require_ident) + let is_runtime_import = + |local: &Atom| local.as_str() == runtime_import_ident || local.as_str() == require_ident; + import_spec.atoms.values().any(is_runtime_import) || import_spec .default_import .as_ref() - .is_some_and(|local| local.as_str() == require_ident) + .is_some_and(is_runtime_import) || import_spec .ns_import .as_ref() - .is_some_and(|local| local.as_str() == require_ident) + .is_some_and(is_runtime_import) }; if !runtime_requirements.is_empty() { @@ -494,7 +509,7 @@ var {} = {{}}; import_source.add(RawStringSource::from(format!( "import {{ {} }} from \"__RSPACK_ESM_CHUNK_{}\";\n", - require_ident, + runtime_import_ident, runtime_chunk.expect_id().as_str() ))); } @@ -832,7 +847,7 @@ var {} = {{}}; chunk_ukey: &ChunkUkey, compilation: &Compilation, runtime_requirements: RuntimeGlobals, - runtime_template: &RuntimeCodeTemplate<'_>, + runtime_template: &ChunkCodeTemplate, ) -> Result { let module_factories: bool = runtime_requirements.contains(RuntimeGlobals::MODULE_FACTORIES); let require_function = runtime_requirements.contains(RuntimeGlobals::REQUIRE); @@ -858,7 +873,7 @@ var {} = {{}}; r#"// The require function function {}(moduleId) {{ "#, - runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE) + runtime_template.render_runtime_variable(&RuntimeVariable::Require) ))); source.add(RawStringSource::from( JsPlugin::render_require(chunk_ukey, compilation, runtime_template).join("\n"), @@ -873,10 +888,27 @@ function {}(moduleId) {{ r#"// The require scope var {} = {{}}; "#, - runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE) + runtime_template.render_runtime_variable(&RuntimeVariable::Require) ))); } + if runtime_template.uses_runtime_context() + && (module_factories + || runtime_requirements.contains(RuntimeGlobals::MODULE_CACHE) + || intercept_module_execution) + { + let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); + source.add(RawStringSource::from(format!( + "var {runtime_context} = typeof {runtime_context} !== \"undefined\" ? {runtime_context} : {{}};\n" + ))); + if runtime_requirements.contains(RuntimeGlobals::REQUIRE) { + let require = runtime_template.render_runtime_variable(&RuntimeVariable::Require); + source.add(RawStringSource::from(format!( + "if (!{runtime_context}.r && typeof {require} !== \"undefined\") {runtime_context}.r = {require};\n" + ))); + } + } + if module_factories { source.add(RawStringSource::from(format!( r#"// expose the modules object ({modules}) @@ -969,7 +1001,7 @@ var {} = {{}}; compilation: &Compilation, chunk_link: &ChunkLinkContext, already_required: &mut IdentifierIndexSet, - runtime_template: &RuntimeCodeTemplate<'_>, + runtime_template: &ChunkCodeTemplate, ) -> ConcatSource { let mut source = ConcatSource::default(); let module_graph = compilation.get_module_graph(); diff --git a/crates/rspack_plugin_esm_library/src/runtime.rs b/crates/rspack_plugin_esm_library/src/runtime.rs index cd276330bf7a..0aec1b68a39b 100644 --- a/crates/rspack_plugin_esm_library/src/runtime.rs +++ b/crates/rspack_plugin_esm_library/src/runtime.rs @@ -1,6 +1,6 @@ use rspack_core::{ Compilation, RuntimeCodeTemplate, RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, - RuntimeModuleStage, RuntimeTemplate, impl_runtime_module, + RuntimeModuleStage, RuntimeTemplate, RuntimeVariable, impl_runtime_module, property_access, }; use rspack_plugin_javascript::impl_plugin_for_js_plugin::chunk_has_js; use rspack_util::json_stringify_str; @@ -14,6 +14,17 @@ impl EsmRegisterModuleRuntimeModule { Self::with_default(runtime_template) } pub(crate) fn runtime_id(runtime_template: &RuntimeCodeTemplate) -> String { + if runtime_template.uses_runtime_context() { + let modules_key = RuntimeGlobals::MODULE_FACTORIES + .property_name() + .expect("module factories should have a property name"); + return format!( + "{}{}.add", + runtime_template.render_runtime_variable(&RuntimeVariable::Context), + property_access([modules_key], 0) + ); + } + format!( "{}.add", runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE) diff --git a/crates/rspack_plugin_extract_css/src/plugin.rs b/crates/rspack_plugin_extract_css/src/plugin.rs index c348568f3f8b..4a3050a68e8e 100644 --- a/crates/rspack_plugin_extract_css/src/plugin.rs +++ b/crates/rspack_plugin_extract_css/src/plugin.rs @@ -547,9 +547,10 @@ async fn runtime_requirement_in_tree( let has_hot_update = runtime_requirements.contains(RuntimeGlobals::HMR_DOWNLOAD_UPDATE_HANDLERS); if has_hot_update || runtime_requirements.contains(RuntimeGlobals::ENSURE_CHUNK_HANDLERS) { - let runtime_template = compilation.runtime_template.create_runtime_code_template(); let filename = self.options.filename.clone(); let chunk_filename = self.options.chunk_filename.clone(); + let runtime_template = compilation.runtime_template.create_chunk_code_template(); + let global = format!("{}.miniCssF", runtime_template.render_runtime_argument()); runtime_modules_to_add.push(( *chunk_ukey, @@ -558,10 +559,7 @@ async fn runtime_requirement_in_tree( "css", "mini-css", SOURCE_TYPE[0], - format!( - "{}.miniCssF", - runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE) - ), + global, move |runtime_requirements| { runtime_requirements.contains(RuntimeGlobals::HMR_DOWNLOAD_UPDATE_HANDLERS) }, diff --git a/crates/rspack_plugin_extract_css/src/runtime.rs b/crates/rspack_plugin_extract_css/src/runtime.rs index f3b386bf74af..2775a6184edd 100644 --- a/crates/rspack_plugin_extract_css/src/runtime.rs +++ b/crates/rspack_plugin_extract_css/src/runtime.rs @@ -205,6 +205,7 @@ impl RuntimeModule for CssLoadingRuntimeModule { let with_hmr = runtime_requirements.contains(RuntimeGlobals::HMR_DOWNLOAD_UPDATE_HANDLERS); let with_fetch_priority = runtime_requirements.contains(RuntimeGlobals::HAS_FETCH_PRIORITY); + let with_script_nonce = runtime_requirements.contains(RuntimeGlobals::SCRIPT_NONCE); if !with_hmr && !with_loading { return Ok(String::new()); @@ -239,6 +240,7 @@ impl RuntimeModule for CssLoadingRuntimeModule { "_set_linktype": self.link_type.clone().unwrap_or_default(), "_cross_origin": compilation.options.output.cross_origin_loading.to_string(), "_with_fetch_priority": with_fetch_priority, + "_with_script_nonce": with_script_nonce, })), )?; @@ -327,6 +329,7 @@ impl RuntimeModule for CssLoadingRuntimeModule { &self.template_id(TemplateId::WithPrefetchLink), Some(serde_json::json!({ "_cross_origin": compilation.options.output.cross_origin_loading.to_string(), + "_with_script_nonce": with_script_nonce, })), )?; @@ -361,6 +364,7 @@ impl RuntimeModule for CssLoadingRuntimeModule { &self.template_id(TemplateId::WithPreloadLink), Some(serde_json::json!({ "_cross_origin": compilation.options.output.cross_origin_loading.to_string(), + "_with_script_nonce": with_script_nonce, })), )?; diff --git a/crates/rspack_plugin_extract_css/src/runtime/css_loading.ejs b/crates/rspack_plugin_extract_css/src/runtime/css_loading.ejs index 37205d5f4771..5d2a78b5a827 100644 --- a/crates/rspack_plugin_extract_css/src/runtime/css_loading.ejs +++ b/crates/rspack_plugin_extract_css/src/runtime/css_loading.ejs @@ -44,7 +44,7 @@ var findStylesheet = function (href, fullhref) { var loadStylesheet = function (chunkId, fetchPriority) { return new Promise(function (resolve, reject) { - var href = <%- REQUIRE %>.miniCssF(chunkId); + var href = <%- REQUIRE_SCOPE %>.miniCssF(chunkId); var fullhref = <%- PUBLIC_PATH %> + href; if (findStylesheet(href, fullhref)) return resolve(); createStylesheet(chunkId, fullhref, null, resolve, reject, fetchPriority); diff --git a/crates/rspack_plugin_extract_css/src/runtime/css_loading_create_link.ejs b/crates/rspack_plugin_extract_css/src/runtime/css_loading_create_link.ejs index c23fce9aec12..91dbd0e31025 100644 --- a/crates/rspack_plugin_extract_css/src/runtime/css_loading_create_link.ejs +++ b/crates/rspack_plugin_extract_css/src/runtime/css_loading_create_link.ejs @@ -4,9 +4,9 @@ linkTag.rel = "stylesheet"; <% if (_set_linktype != "") { %> linkTag.type = <%- _set_linktype %>; <% } %> -if (<%- SCRIPT_NONCE %>) { - linkTag.nonce = <%- SCRIPT_NONCE %>; -} +<% if (_with_script_nonce) { %> +if (<%- SCRIPT_NONCE %>) linkTag.nonce = <%- SCRIPT_NONCE %>; +<% } %> linkTag.href = fullhref; <% if (_with_fetch_priority) { %> if (fetchPriority) { diff --git a/crates/rspack_plugin_extract_css/src/runtime/css_loading_with_hmr.ejs b/crates/rspack_plugin_extract_css/src/runtime/css_loading_with_hmr.ejs index 5a498e98912a..d9da12bfaeba 100644 --- a/crates/rspack_plugin_extract_css/src/runtime/css_loading_with_hmr.ejs +++ b/crates/rspack_plugin_extract_css/src/runtime/css_loading_with_hmr.ejs @@ -18,7 +18,7 @@ var applyHandler = function (options) { <%- HMR_DOWNLOAD_UPDATE_HANDLERS %>.miniCss = function (chunkIds, removedChunks, removedModules, promises, applyHandlers, updatedModulesList) { applyHandlers.push(applyHandler); chunkIds.forEach(function (chunkId) { - var href = <%- REQUIRE %>.miniCssF(chunkId); + var href = <%- REQUIRE_SCOPE %>.miniCssF(chunkId); var fullhref = <%- PUBLIC_PATH %> + href; var oldTag = findStylesheet(href, fullhref); if (!oldTag) return; diff --git a/crates/rspack_plugin_extract_css/src/runtime/css_loading_with_prefetch_link.ejs b/crates/rspack_plugin_extract_css/src/runtime/css_loading_with_prefetch_link.ejs index 939ce4faaa16..4ccd3b34d569 100644 --- a/crates/rspack_plugin_extract_css/src/runtime/css_loading_with_prefetch_link.ejs +++ b/crates/rspack_plugin_extract_css/src/runtime/css_loading_with_prefetch_link.ejs @@ -2,9 +2,9 @@ var link = document.createElement('link'); <% if (_cross_origin != "") { %> link.crossOrigin = '<%- _cross_origin %>'; <% } %> -if (<%- SCRIPT_NONCE %>) { - link.setAttribute('nonce', <%- SCRIPT_NONCE %>); -} +<% if (_with_script_nonce) { %> +if (<%- SCRIPT_NONCE %>) link.setAttribute('nonce', <%- SCRIPT_NONCE %>); +<% } %> link.rel = "prefetch"; link.as = "style"; -link.href = <%- PUBLIC_PATH %> + <%- REQUIRE %>.miniCssF(chunkId); \ No newline at end of file +link.href = <%- PUBLIC_PATH %> + <%- REQUIRE_SCOPE %>.miniCssF(chunkId); diff --git a/crates/rspack_plugin_extract_css/src/runtime/css_loading_with_preload_link.ejs b/crates/rspack_plugin_extract_css/src/runtime/css_loading_with_preload_link.ejs index bea48edc11d2..46a2f761321f 100644 --- a/crates/rspack_plugin_extract_css/src/runtime/css_loading_with_preload_link.ejs +++ b/crates/rspack_plugin_extract_css/src/runtime/css_loading_with_preload_link.ejs @@ -1,14 +1,14 @@ var link = document.createElement('link'); -if (<%- SCRIPT_NONCE %>) { - link.setAttribute('nonce', <%- SCRIPT_NONCE %>); -} +<% if (_with_script_nonce) { %> +if (<%- SCRIPT_NONCE %>) link.setAttribute('nonce', <%- SCRIPT_NONCE %>); +<% } %> link.rel = "preload"; link.as = "style"; -link.href = <%- PUBLIC_PATH %> + <%- REQUIRE %>.miniCssF(chunkId); +link.href = <%- PUBLIC_PATH %> + <%- REQUIRE_SCOPE %>.miniCssF(chunkId); <% if (_cross_origin == "use-credentials") { %> link.crossOrigin = "use-credentials"; <% } else if (_cross_origin != "") { %> if (link.href.indexOf(window.location.origin + '/') !== 0) { link.crossOrigin = '<%- _cross_origin %>'; } -<% } %> \ No newline at end of file +<% } %> diff --git a/crates/rspack_plugin_hmr/src/hot_module_replacement.rs b/crates/rspack_plugin_hmr/src/hot_module_replacement.rs index f8f8cc114936..4f516e18808c 100644 --- a/crates/rspack_plugin_hmr/src/hot_module_replacement.rs +++ b/crates/rspack_plugin_hmr/src/hot_module_replacement.rs @@ -2,7 +2,7 @@ use std::sync::LazyLock; use rspack_core::{ Compilation, RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, - impl_runtime_module, + impl_runtime_module, runtime_mode::RuntimeMode, }; use rspack_plugin_runtime::extract_runtime_globals_from_ejs; use rspack_util::test::is_hot_test; @@ -38,6 +38,7 @@ impl RuntimeModule for HotModuleReplacementRuntimeModule { self.id.as_str(), Some(serde_json::json!({ "_is_hot_test": is_hot_test(), + "_is_rspack_runtime_mode": context.compilation.options.experiments.runtime_mode == RuntimeMode::Rspack, })), )?; diff --git a/crates/rspack_plugin_hmr/src/runtime/hot_module_replacement.ejs b/crates/rspack_plugin_hmr/src/runtime/hot_module_replacement.ejs index 7cd7007a69bd..1adc464f20bc 100644 --- a/crates/rspack_plugin_hmr/src/runtime/hot_module_replacement.ejs +++ b/crates/rspack_plugin_hmr/src/runtime/hot_module_replacement.ejs @@ -20,18 +20,19 @@ var queuedInvalidatedModules; <%- HMR_MODULE_DATA %> = currentModuleData; <%- INTERCEPT_MODULE_EXECUTION %>.push(function (options) { var module = options.module; - var require = createRequire(options.require, options.id); + var require = createRequire(options.require, options.id<% if (_is_rspack_runtime_mode) { %>, options.context<% } %>); module.hot = createModuleHotObject(options.id, module); module.parents = currentParents; module.children = []; currentParents = []; options.require = require; + <% if (_is_rspack_runtime_mode) { %>options.context.r = require;<% } %> }); <%- HMR_DOWNLOAD_UPDATE_HANDLERS %> = {}; <%- HMR_INVALIDATE_MODULE_HANDLERS %> = {}; -function createRequire(require, moduleId) { +function createRequire(require, moduleId<% if (_is_rspack_runtime_mode) { %>, context<% } %>) { var me = installedModules[moduleId]; if (!me) return require; var fn = function (request) { @@ -78,7 +79,7 @@ function createRequire(require, moduleId) { } fn.e = function (chunkId, fetchPriority) { - return trackBlockingPromise(require.e(chunkId, fetchPriority)); + return trackBlockingPromise(<% if (_is_rspack_runtime_mode) { %>context.e<% } else { %>require.e<% } %>(chunkId, fetchPriority)); }; return fn; diff --git a/crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs b/crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs index 5f856ac5137a..cc93e52b6d7e 100644 --- a/crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs +++ b/crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs @@ -33,6 +33,7 @@ use crate::{ #[derive(Debug)] pub struct ParserRuntimeRequirementsData { + pub context: String, pub module: String, pub rspack_module: String, pub exports: String, @@ -83,9 +84,11 @@ impl ParserRuntimeRequirementsData { runtime_template.render_runtime_globals_without_adding(&RuntimeGlobals::MODULE_CACHE); let entry_module_id_name = runtime_template.render_runtime_globals_without_adding(&RuntimeGlobals::ENTRY_MODULE_ID); + let context_name = runtime_template.render_runtime_variable(&RuntimeVariable::Context); let rspack_module_name = runtime_template.render_runtime_variable(&RuntimeVariable::Module); Self { require_regex: &LEGACY_REQUIRE_REGEX, + context: context_name, module: module_name, rspack_module: rspack_module_name, exports: exports_name, diff --git a/crates/rspack_plugin_javascript/src/parser_plugin/api_plugin.rs b/crates/rspack_plugin_javascript/src/parser_plugin/api_plugin.rs index c98fb2158cbf..dade5641a77c 100644 --- a/crates/rspack_plugin_javascript/src/parser_plugin/api_plugin.rs +++ b/crates/rspack_plugin_javascript/src/parser_plugin/api_plugin.rs @@ -1,8 +1,12 @@ -use rspack_core::{ConstDependency, ModuleArgument, RuntimeGlobals, RuntimeRequirementsDependency}; +use rspack_core::{ + ConstDependency, ModuleArgument, RuntimeGlobals, RuntimeRequirementsDependency, property_access, + runtime_mode::RuntimeMode as ExperimentRuntimeMode, +}; use rspack_error::{Error, Severity}; use rspack_util::{SpanExt, json_stringify_str}; +use swc_atoms::Atom; use swc_experimental_ecma_ast::{ - CallExpr, GetSpan, Ident, MemberExpr, Pat, Span, UnaryExpr, VarDeclarator, + AssignExpr, CallExpr, GetSpan, Ident, MemberExpr, Pat, Span, UnaryExpr, VarDeclarator, }; use crate::{ @@ -35,25 +39,136 @@ fn expression_not_supported( ) } -const API_HASH: &str = "__webpack_hash__"; const API_LAYER: &str = "__webpack_layer__"; -const API_PUBLIC_PATH: &str = "__webpack_public_path__"; -const API_MODULES: &str = "__webpack_modules__"; const API_MODULE: &str = "__webpack_module__"; -const API_CHUNK_LOAD: &str = "__webpack_chunk_load__"; -const API_BASE_URI: &str = "__webpack_base_uri__"; const API_NON_REQUIRE: &str = "__non_webpack_require__"; -const API_SYSTEM_CONTEXT: &str = "__system_context__"; -const API_SHARE_SCOPES: &str = "__webpack_share_scopes__"; -const API_INIT_SHARING: &str = "__webpack_init_sharing__"; -const API_NONCE: &str = "__webpack_nonce__"; -const API_CHUNK_NAME: &str = "__webpack_chunkname__"; -const API_RUNTIME_ID: &str = "__webpack_runtime_id__"; const API_REQUIRE: &str = "__webpack_require__"; -const API_GET_SCRIPT_FILENAME: &str = "__webpack_get_script_filename__"; -const API_VERSION: &str = "__rspack_version__"; -const API_UNIQUE_ID: &str = "__rspack_unique_id__"; -const API_RSC_MANIFEST: &str = "__rspack_rsc_manifest__"; + +#[derive(Clone, Copy)] +enum RuntimeApiIdentifierMode { + Normal, + Call, + Require, +} + +#[derive(Clone, Copy)] +struct RuntimeApi { + name: &'static str, + type_of: Option<&'static str>, + runtime_global: Option, + identifier_mode: Option, +} + +static RUNTIME_APIS: &[RuntimeApi] = &[ + RuntimeApi { + name: API_REQUIRE, + type_of: Some("function"), + runtime_global: Some(RuntimeGlobals::REQUIRE), + identifier_mode: Some(RuntimeApiIdentifierMode::Require), + }, + RuntimeApi { + name: "__webpack_hash__", + type_of: Some("string"), + runtime_global: Some(RuntimeGlobals::GET_FULL_HASH), + identifier_mode: Some(RuntimeApiIdentifierMode::Call), + }, + RuntimeApi { + name: "__webpack_public_path__", + type_of: Some("string"), + runtime_global: Some(RuntimeGlobals::PUBLIC_PATH), + identifier_mode: Some(RuntimeApiIdentifierMode::Normal), + }, + RuntimeApi { + name: "__webpack_modules__", + type_of: Some("object"), + runtime_global: Some(RuntimeGlobals::MODULE_FACTORIES), + identifier_mode: Some(RuntimeApiIdentifierMode::Normal), + }, + RuntimeApi { + name: API_MODULE, + type_of: Some("object"), + runtime_global: None, + identifier_mode: None, + }, + RuntimeApi { + name: "__webpack_chunk_load__", + type_of: Some("function"), + runtime_global: Some(RuntimeGlobals::ENSURE_CHUNK), + identifier_mode: Some(RuntimeApiIdentifierMode::Normal), + }, + RuntimeApi { + name: "__webpack_base_uri__", + type_of: Some("string"), + runtime_global: Some(RuntimeGlobals::BASE_URI), + identifier_mode: Some(RuntimeApiIdentifierMode::Normal), + }, + RuntimeApi { + name: API_NON_REQUIRE, + type_of: None, + runtime_global: None, + identifier_mode: None, + }, + RuntimeApi { + name: "__system_context__", + type_of: Some("object"), + runtime_global: Some(RuntimeGlobals::SYSTEM_CONTEXT), + identifier_mode: Some(RuntimeApiIdentifierMode::Normal), + }, + RuntimeApi { + name: "__webpack_share_scopes__", + type_of: Some("object"), + runtime_global: Some(RuntimeGlobals::SHARE_SCOPE_MAP), + identifier_mode: Some(RuntimeApiIdentifierMode::Normal), + }, + RuntimeApi { + name: "__webpack_init_sharing__", + type_of: Some("function"), + runtime_global: Some(RuntimeGlobals::INITIALIZE_SHARING), + identifier_mode: Some(RuntimeApiIdentifierMode::Normal), + }, + RuntimeApi { + name: "__webpack_nonce__", + type_of: Some("string"), + runtime_global: Some(RuntimeGlobals::SCRIPT_NONCE), + identifier_mode: Some(RuntimeApiIdentifierMode::Normal), + }, + RuntimeApi { + name: "__webpack_chunkname__", + type_of: Some("string"), + runtime_global: Some(RuntimeGlobals::CHUNK_NAME), + identifier_mode: Some(RuntimeApiIdentifierMode::Normal), + }, + RuntimeApi { + name: "__webpack_runtime_id__", + type_of: None, + runtime_global: Some(RuntimeGlobals::RUNTIME_ID), + identifier_mode: Some(RuntimeApiIdentifierMode::Normal), + }, + RuntimeApi { + name: "__webpack_get_script_filename__", + type_of: Some("function"), + runtime_global: Some(RuntimeGlobals::GET_CHUNK_SCRIPT_FILENAME), + identifier_mode: Some(RuntimeApiIdentifierMode::Normal), + }, + RuntimeApi { + name: "__rspack_version__", + type_of: Some("string"), + runtime_global: Some(RuntimeGlobals::RSPACK_VERSION), + identifier_mode: Some(RuntimeApiIdentifierMode::Call), + }, + RuntimeApi { + name: "__rspack_unique_id__", + type_of: Some("string"), + runtime_global: Some(RuntimeGlobals::RSPACK_UNIQUE_ID), + identifier_mode: Some(RuntimeApiIdentifierMode::Normal), + }, + RuntimeApi { + name: "__rspack_rsc_manifest__", + type_of: Some("object"), + runtime_global: Some(RuntimeGlobals::RSC_MANIFEST), + identifier_mode: Some(RuntimeApiIdentifierMode::Normal), + }, +]; pub struct APIPluginOptions { module: bool, @@ -70,28 +185,46 @@ impl APIPlugin { } } -fn get_typeof_evaluate_of_api(sym: &str) -> Option<&str> { - match sym { - API_REQUIRE => Some("function"), - API_HASH => Some("string"), - API_PUBLIC_PATH => Some("string"), - API_MODULES => Some("object"), - API_MODULE => Some("object"), - API_CHUNK_LOAD => Some("function"), - API_BASE_URI => Some("string"), - API_NON_REQUIRE => None, - API_SYSTEM_CONTEXT => Some("object"), - API_SHARE_SCOPES => Some("object"), - API_INIT_SHARING => Some("function"), - API_NONCE => Some("string"), - API_CHUNK_NAME => Some("string"), - API_RUNTIME_ID => None, - API_GET_SCRIPT_FILENAME => Some("function"), - API_VERSION => Some("string"), - API_UNIQUE_ID => Some("string"), - API_RSC_MANIFEST => Some("object"), - _ => None, +fn runtime_api_from_name(name: &str) -> Option<&'static RuntimeApi> { + RUNTIME_APIS.iter().find(|api| api.name == name) +} + +fn get_typeof_evaluate_of_api(sym: &str) -> Option<&'static str> { + runtime_api_from_name(sym).and_then(|api| api.type_of) +} + +fn static_require_member_chain( + parser: &mut JavascriptParser, + for_name: &str, + members: &[Atom], + expr_span: Span, + write: bool, +) -> Option { + if for_name == API_REQUIRE + && let Some(property) = members.first() + { + if let Some(runtime_global) = RuntimeGlobals::from_property_name(property.as_ref()) { + let dep = if write { + RuntimeRequirementsDependency::write(expr_span.into(), runtime_global) + } else { + RuntimeRequirementsDependency::new(expr_span.into(), runtime_global) + }; + parser.add_presentational_dependency(Box::new(dep)); + } else { + let content = format!( + "{}{}", + parser.parser_runtime_requirements.context, + property_access(members.iter().map(Atom::as_ref), 0) + ); + parser.add_presentational_dependency(Box::new(ConstDependency::new( + expr_span.into(), + content.into(), + ))); + } + return Some(true); } + + None } #[rspack_macros::implemented_javascript_parser_hooks] @@ -126,18 +259,60 @@ impl<'p, 'a> JavascriptParserPlugin<'p, 'a> for APIPlugin { ident: &Ident, for_name: &str, ) -> Option { + if for_name == API_LAYER { + parser.add_presentational_dependency(Box::new(ConstDependency::new( + ident.span.into(), + serde_json::to_string(&parser.module_layer) + .expect("should stringify JSON") + .into(), + ))); + return Some(true); + } + + if for_name == API_MODULE { + let range = ident.span.into(); + let loc = parser.to_dependency_location(range); + parser + .add_presentational_dependency(Box::new(ModuleArgumentDependency::new(None, range, loc))); + return Some(true); + } + + if for_name == API_NON_REQUIRE { + let content = if self.options.module { + parser.build_info.need_create_require = true; + "__rspack_createRequire_require".into() + } else { + "require".into() + }; + parser + .add_presentational_dependency(Box::new(ConstDependency::new(ident.span.into(), content))); + return Some(true); + } + + let api = runtime_api_from_name(for_name)?; + let runtime_global = api + .runtime_global + .expect("runtime api identifier should have runtime global"); match for_name { - API_REQUIRE => { + _ if matches!(api.identifier_mode, Some(RuntimeApiIdentifierMode::Require)) + && parser.compiler_options.experiments.runtime_mode == ExperimentRuntimeMode::Rspack => + { parser.add_presentational_dependency(Box::new(RuntimeRequirementsDependency::new( ident.span.into(), - RuntimeGlobals::REQUIRE, + runtime_global, ))); Some(true) } - API_HASH => { + _ if matches!(api.identifier_mode, Some(RuntimeApiIdentifierMode::Require)) => { + parser.add_presentational_dependency(Box::new(RuntimeRequirementsDependency::add_only( + runtime_global, + ))); + None + } + _ if matches!(api.identifier_mode, Some(RuntimeApiIdentifierMode::Call)) => { parser.add_presentational_dependency(Box::new(RuntimeRequirementsDependency::call( ident.span.into(), - RuntimeGlobals::GET_FULL_HASH, + runtime_global, ))); Some(true) } @@ -151,122 +326,10 @@ impl<'p, 'a> JavascriptParserPlugin<'p, 'a> for APIPlugin { ))); Some(true) } - API_PUBLIC_PATH => { - parser.add_presentational_dependency(Box::new(RuntimeRequirementsDependency::new( - ident.span.into(), - RuntimeGlobals::PUBLIC_PATH, - ))); - Some(true) - } - API_MODULES => { - parser.add_presentational_dependency(Box::new(RuntimeRequirementsDependency::new( - ident.span.into(), - RuntimeGlobals::MODULE_FACTORIES, - ))); - Some(true) - } - API_CHUNK_LOAD => { - parser.add_presentational_dependency(Box::new(RuntimeRequirementsDependency::new( - ident.span.into(), - RuntimeGlobals::ENSURE_CHUNK, - ))); - Some(true) - } - API_MODULE => { - let range = ident.span.into(); - let loc = parser.to_dependency_location(range); - parser - .add_presentational_dependency(Box::new(ModuleArgumentDependency::new(None, range, loc))); - Some(true) - } - API_BASE_URI => { - parser.add_presentational_dependency(Box::new(RuntimeRequirementsDependency::new( - ident.span.into(), - RuntimeGlobals::BASE_URI, - ))); - Some(true) - } - API_NON_REQUIRE => { - let content = if self.options.module { - parser.build_info.need_create_require = true; - "__rspack_createRequire_require".into() - } else { - "require".into() - }; - parser.add_presentational_dependency(Box::new(ConstDependency::new( - ident.span.into(), - content, - ))); - Some(true) - } - API_SYSTEM_CONTEXT => { - parser.add_presentational_dependency(Box::new(RuntimeRequirementsDependency::new( - ident.span.into(), - RuntimeGlobals::SYSTEM_CONTEXT, - ))); - Some(true) - } - API_SHARE_SCOPES => { - parser.add_presentational_dependency(Box::new(RuntimeRequirementsDependency::new( - ident.span.into(), - RuntimeGlobals::SHARE_SCOPE_MAP, - ))); - Some(true) - } - API_INIT_SHARING => { + _ if matches!(api.identifier_mode, Some(RuntimeApiIdentifierMode::Normal)) => { parser.add_presentational_dependency(Box::new(RuntimeRequirementsDependency::new( ident.span.into(), - RuntimeGlobals::INITIALIZE_SHARING, - ))); - Some(true) - } - API_NONCE => { - parser.add_presentational_dependency(Box::new(RuntimeRequirementsDependency::new( - ident.span.into(), - RuntimeGlobals::SCRIPT_NONCE, - ))); - Some(true) - } - API_CHUNK_NAME => { - parser.add_presentational_dependency(Box::new(RuntimeRequirementsDependency::new( - ident.span.into(), - RuntimeGlobals::CHUNK_NAME, - ))); - Some(true) - } - API_RUNTIME_ID => { - parser.add_presentational_dependency(Box::new(RuntimeRequirementsDependency::new( - ident.span.into(), - RuntimeGlobals::RUNTIME_ID, - ))); - Some(true) - } - API_GET_SCRIPT_FILENAME => { - parser.add_presentational_dependency(Box::new(RuntimeRequirementsDependency::new( - ident.span.into(), - RuntimeGlobals::GET_CHUNK_SCRIPT_FILENAME, - ))); - Some(true) - } - // rspack specific - API_VERSION => { - parser.add_presentational_dependency(Box::new(RuntimeRequirementsDependency::call( - ident.span.into(), - RuntimeGlobals::RSPACK_VERSION, - ))); - Some(true) - } - API_UNIQUE_ID => { - parser.add_presentational_dependency(Box::new(RuntimeRequirementsDependency::new( - ident.span.into(), - RuntimeGlobals::RSPACK_UNIQUE_ID, - ))); - Some(true) - } - API_RSC_MANIFEST => { - parser.add_presentational_dependency(Box::new(RuntimeRequirementsDependency::new( - ident.span.into(), - RuntimeGlobals::RSC_MANIFEST, + runtime_global, ))); Some(true) } @@ -342,6 +405,78 @@ impl<'p, 'a> JavascriptParserPlugin<'p, 'a> for APIPlugin { None } + fn member_chain( + &self, + parser: &mut JavascriptParser, + member_expr: &MemberExpr, + for_name: &str, + members: &[Atom], + _members_optionals: &[bool], + _member_ranges: &[Span], + ) -> Option { + if parser.compiler_options.experiments.runtime_mode != ExperimentRuntimeMode::Rspack { + return None; + } + static_require_member_chain(parser, for_name, members, member_expr.span, false) + } + + fn call_member_chain( + &self, + parser: &mut JavascriptParser, + expr: &CallExpr, + for_name: &str, + members: &[Atom], + _members_optionals: &[bool], + _member_ranges: &[Span], + ) -> Option { + if parser.compiler_options.experiments.runtime_mode != ExperimentRuntimeMode::Rspack { + return None; + } + let handled = static_require_member_chain(parser, for_name, members, expr.callee.span(), false); + if handled.is_some() { + parser.walk_expr_or_spread(&expr.args); + } + handled + } + + fn assign_member_chain( + &self, + parser: &mut JavascriptParser, + expr: &AssignExpr, + members: &[Atom], + for_name: &str, + ) -> Option { + if parser.compiler_options.experiments.runtime_mode != ExperimentRuntimeMode::Rspack { + return None; + } + let handled = static_require_member_chain(parser, for_name, members, expr.left.span(), true); + if handled.is_some() { + parser.walk_expression(&expr.right); + } + handled + } + + fn assign( + &self, + parser: &mut JavascriptParser, + _expr: &AssignExpr, + for_name: &str, + ) -> Option { + if let Some(runtime_global) = runtime_api_from_name(for_name).and_then(|api| api.runtime_global) + { + if parser.compiler_options.experiments.runtime_mode == ExperimentRuntimeMode::Rspack { + parser.add_presentational_dependency(Box::new(RuntimeRequirementsDependency::write_only( + runtime_global, + ))); + return None; + } + parser.add_presentational_dependency(Box::new(RuntimeRequirementsDependency::add_only( + runtime_global, + ))); + } + None + } + fn pre_declarator( &self, parser: &mut JavascriptParser<'p>, @@ -390,6 +525,13 @@ impl<'p, 'a> JavascriptParserPlugin<'p, 'a> for APIPlugin { call_expr: &CallExpr, for_name: &str, ) -> Option { + if for_name == API_REQUIRE { + parser.add_presentational_dependency(Box::new(RuntimeRequirementsDependency::add_only( + RuntimeGlobals::REQUIRE, + ))); + return None; + } + if for_name == "require.config" || for_name == "require.include" || for_name == "require.onError" diff --git a/crates/rspack_plugin_javascript/src/parser_plugin/compatibility_plugin.rs b/crates/rspack_plugin_javascript/src/parser_plugin/compatibility_plugin.rs index f9f8561700d0..2441a45a9512 100644 --- a/crates/rspack_plugin_javascript/src/parser_plugin/compatibility_plugin.rs +++ b/crates/rspack_plugin_javascript/src/parser_plugin/compatibility_plugin.rs @@ -1,4 +1,7 @@ -use rspack_core::{BoxDependencyTemplate, ConstDependency, ContextDependency, DependencyRange}; +use rspack_core::{ + BoxDependencyTemplate, ConstDependency, ContextDependency, DependencyRange, + runtime_mode::RuntimeMode, +}; use rspack_util::{SpanExt, itoa}; use swc_atoms::Atom; use swc_experimental_ecma_ast::{CallExpr, GetSpan, Ident, Program, VarDeclarator}; @@ -22,6 +25,14 @@ pub struct NestedRequireData { pub struct CompatibilityPlugin; impl CompatibilityPlugin { + fn nested_require_name<'a>(&self, parser: &'a JavascriptParser) -> &'a str { + if parser.compiler_options.experiments.runtime_mode == RuntimeMode::Rspack { + parser.parser_runtime_requirements.context.as_str() + } else { + parser.parser_runtime_requirements.require.as_str() + } + } + pub fn browserify_require_handler( &self, parser: &mut JavascriptParser, @@ -95,7 +106,7 @@ impl<'p, 'a> JavascriptParserPlugin<'p, 'a> for CompatibilityPlugin { ) -> Option { let ident = decl.name.as_ident()?; - if ident.id.sym.as_str() == parser.parser_runtime_requirements.require { + if ident.id.sym.as_str() == self.nested_require_name(parser) { let span = ident.span(); let start = span.real_lo(); let end = span.real_hi(); @@ -146,7 +157,7 @@ impl<'p, 'a> JavascriptParserPlugin<'p, 'a> for CompatibilityPlugin { ident.span().real_hi(), ); return Some(true); - } else if for_name == parser.parser_runtime_requirements.require { + } else if for_name == self.nested_require_name(parser) { let span = ident.span(); let start = span.real_lo(); let end = span.real_hi(); @@ -175,7 +186,7 @@ impl<'p, 'a> JavascriptParserPlugin<'p, 'a> for CompatibilityPlugin { let fn_decl = stmt.as_function_decl()?; let ident = fn_decl.ident()?; let name = &ident.sym; - if name.as_str() != parser.parser_runtime_requirements.require { + if name.as_str() != self.nested_require_name(parser) { None } else { self.tag_nested_require_data( @@ -202,7 +213,7 @@ impl<'p, 'a> JavascriptParserPlugin<'p, 'a> for CompatibilityPlugin { ) -> Option { if let Some(ident) = declarator.name.as_ident() && (ident.id.sym.as_str() == parser.parser_runtime_requirements.exports - || ident.id.sym.as_str() == parser.parser_runtime_requirements.require) + || ident.id.sym.as_str() == self.nested_require_name(parser)) { let data = parser.get_tag_data_mut::( &Atom::from(ident.id.sym.as_str()), diff --git a/crates/rspack_plugin_javascript/src/plugin/api_plugin.rs b/crates/rspack_plugin_javascript/src/plugin/api_plugin.rs index 0e072da7a92b..0f6731984a85 100644 --- a/crates/rspack_plugin_javascript/src/plugin/api_plugin.rs +++ b/crates/rspack_plugin_javascript/src/plugin/api_plugin.rs @@ -1,7 +1,7 @@ use rspack_core::{ - ChunkInitFragments, ChunkUkey, Compilation, CompilationParams, CompilerCompilation, - InitFragmentExt, InitFragmentKey, InitFragmentStage, Module, NormalInitFragment, Plugin, - RuntimeCodeTemplate, + ChunkCodeTemplate, ChunkInitFragments, ChunkUkey, Compilation, CompilationParams, + CompilerCompilation, InitFragmentExt, InitFragmentKey, InitFragmentStage, Module, + NormalInitFragment, Plugin, }; use rspack_error::Result; use rspack_hook::{plugin, plugin_hook}; @@ -35,7 +35,7 @@ async fn render_module_content( module: &dyn Module, _source: &mut RenderSource, init_fragments: &mut ChunkInitFragments, - _runtime_template: &RuntimeCodeTemplate<'_>, + _runtime_template: &ChunkCodeTemplate, ) -> Result<()> { if module.build_info().need_create_require { let need_prefix = compilation diff --git a/crates/rspack_plugin_javascript/src/plugin/drive.rs b/crates/rspack_plugin_javascript/src/plugin/drive.rs index 6cddcf260dcf..7eb415c12f21 100644 --- a/crates/rspack_plugin_javascript/src/plugin/drive.rs +++ b/crates/rspack_plugin_javascript/src/plugin/drive.rs @@ -1,19 +1,19 @@ use rspack_core::{ - AssetInfo, BoxModule, Chunk, ChunkInitFragments, ChunkUkey, Compilation, Module, - ModuleIdentifier, RuntimeCodeTemplate, rspack_sources::BoxSource, + AssetInfo, BoxModule, Chunk, ChunkCodeTemplate, ChunkInitFragments, ChunkUkey, Compilation, + Module, ModuleIdentifier, rspack_sources::BoxSource, }; use rspack_hash::RspackHash; use rspack_hook::define_hook; #[cfg(allocative)] use rspack_util::allocative; -define_hook!(JavascriptModulesRenderChunk: Series(compilation: &Compilation, chunk_ukey: &ChunkUkey, source: &mut RenderSource, runtime_template: &RuntimeCodeTemplate<'_>)); -define_hook!(JavascriptModulesRenderChunkContent: SeriesBail(compilation: &Compilation, chunk_ukey: &ChunkUkey, asset_info: &mut AssetInfo, runtime_template: &RuntimeCodeTemplate<'_>) -> RenderSource); -define_hook!(JavascriptModulesRender: Series(compilation: &Compilation, chunk_ukey: &ChunkUkey, source: &mut RenderSource, runtime_template: &RuntimeCodeTemplate<'_>)); -define_hook!(JavascriptModulesRenderStartup: Series(compilation: &Compilation, chunk_ukey: &ChunkUkey, module: &ModuleIdentifier, source: &mut RenderSource, runtime_template: &RuntimeCodeTemplate<'_>)); -define_hook!(JavascriptModulesRenderModuleContent: Series(compilation: &Compilation, chunk_ukey: &ChunkUkey,module: &dyn Module, source: &mut RenderSource, init_fragments: &mut ChunkInitFragments, runtime_template: &RuntimeCodeTemplate<'_>),tracing=false); -define_hook!(JavascriptModulesRenderModuleContainer: Series(compilation: &Compilation, chunk_ukey: &ChunkUkey,module: &dyn Module, source: &mut RenderSource, init_fragments: &mut ChunkInitFragments, runtime_template: &RuntimeCodeTemplate<'_>),tracing=false); -define_hook!(JavascriptModulesRenderModulePackage: Series(compilation: &Compilation, chunk_ukey: &ChunkUkey, module: &dyn Module, source: &mut RenderSource, init_fragments: &mut ChunkInitFragments, runtime_template: &RuntimeCodeTemplate<'_>),tracing=false); +define_hook!(JavascriptModulesRenderChunk: Series(compilation: &Compilation, chunk_ukey: &ChunkUkey, source: &mut RenderSource, runtime_template: &ChunkCodeTemplate)); +define_hook!(JavascriptModulesRenderChunkContent: SeriesBail(compilation: &Compilation, chunk_ukey: &ChunkUkey, asset_info: &mut AssetInfo, runtime_template: &ChunkCodeTemplate) -> RenderSource); +define_hook!(JavascriptModulesRender: Series(compilation: &Compilation, chunk_ukey: &ChunkUkey, source: &mut RenderSource, runtime_template: &ChunkCodeTemplate)); +define_hook!(JavascriptModulesRenderStartup: Series(compilation: &Compilation, chunk_ukey: &ChunkUkey, module: &ModuleIdentifier, source: &mut RenderSource, runtime_template: &ChunkCodeTemplate)); +define_hook!(JavascriptModulesRenderModuleContent: Series(compilation: &Compilation, chunk_ukey: &ChunkUkey,module: &dyn Module, source: &mut RenderSource, init_fragments: &mut ChunkInitFragments, runtime_template: &ChunkCodeTemplate),tracing=false); +define_hook!(JavascriptModulesRenderModuleContainer: Series(compilation: &Compilation, chunk_ukey: &ChunkUkey,module: &dyn Module, source: &mut RenderSource, init_fragments: &mut ChunkInitFragments, runtime_template: &ChunkCodeTemplate),tracing=false); +define_hook!(JavascriptModulesRenderModulePackage: Series(compilation: &Compilation, chunk_ukey: &ChunkUkey, module: &dyn Module, source: &mut RenderSource, init_fragments: &mut ChunkInitFragments, runtime_template: &ChunkCodeTemplate),tracing=false); define_hook!(JavascriptModulesChunkHash: Series(compilation: &Compilation, chunk_ukey: &ChunkUkey, hasher: &mut RspackHash)); define_hook!(JavascriptModulesInlineInRuntimeBailout: SeriesBail(compilation: &Compilation) -> String); define_hook!(JavascriptModulesEmbedInRuntimeBailout: SeriesBail(compilation: &Compilation, module: &BoxModule, chunk: &Chunk) -> String); diff --git a/crates/rspack_plugin_javascript/src/plugin/impl_plugin_for_js_plugin.rs b/crates/rspack_plugin_javascript/src/plugin/impl_plugin_for_js_plugin.rs index 28d88253799b..e193f6abe084 100644 --- a/crates/rspack_plugin_javascript/src/plugin/impl_plugin_for_js_plugin.rs +++ b/crates/rspack_plugin_javascript/src/plugin/impl_plugin_for_js_plugin.rs @@ -557,7 +557,7 @@ async fn render_manifest( .build_chunk_graph_artifact .chunk_by_ukey .expect_get(chunk_ukey); - let runtime_template = compilation.runtime_template.create_runtime_code_template(); + let runtime_template = compilation.runtime_template.create_chunk_code_template(); let is_hot_update = matches!(chunk.kind(), ChunkKind::HotUpdate); let is_main_chunk = chunk.groups().iter().any(|group_ukey| { let group = compilation diff --git a/crates/rspack_plugin_javascript/src/plugin/mod.rs b/crates/rspack_plugin_javascript/src/plugin/mod.rs index 975f62dc9c91..d71fa16cf5d8 100644 --- a/crates/rspack_plugin_javascript/src/plugin/mod.rs +++ b/crates/rspack_plugin_javascript/src/plugin/mod.rs @@ -28,11 +28,11 @@ pub use mangle_exports_plugin::*; pub use module_concatenation_plugin::*; use rspack_collections::{Identifier, IdentifierDashMap, IdentifierLinkedMap, IdentifierMap}; use rspack_core::{ - ChunkGraph, ChunkGroupUkey, ChunkInitFragments, ChunkRenderContext, ChunkUkey, + ChunkCodeTemplate, ChunkGraph, ChunkGroupUkey, ChunkInitFragments, ChunkRenderContext, ChunkUkey, CodeGenerationDataTopLevelDeclarations, Compilation, CompilationId, ConcatenatedModuleIdent, - ExportsArgument, Module, RuntimeCodeTemplate, RuntimeGlobals, RuntimeVariable, SourceType, + ExportsArgument, Module, RuntimeGlobals, RuntimeVariable, SourceType, concatenated_module::{collect_ident, find_new_name}, - render_init_fragments, + property_access, render_init_fragments, reserved_names::RESERVED_NAMES_ATOM_SET, rspack_sources::{BoxSource, ConcatSource, RawStringSource, ReplaceSource, Source, SourceExt}, split_readable_identifier, @@ -52,7 +52,9 @@ use swc_experimental_ecma_semantic::resolver::resolver; use tokio::sync::RwLock; use crate::runtime::{ - render_chunk_modules, render_module, render_runtime_modules, stringify_array, + render_chunk_modules, render_module, render_runtime_context_declaration, + render_runtime_context_require_assignment, render_runtime_modules, should_render_runtime_context, + stringify_array, }; #[cfg_attr(allocative, allocative::root)] @@ -134,21 +136,34 @@ impl JsPlugin { pub fn render_require<'me>( chunk_ukey: &ChunkUkey, compilation: &'me Compilation, - runtime_template: &RuntimeCodeTemplate<'_>, + runtime_template: &ChunkCodeTemplate, ) -> Vec> { - let runtime_requirements = ChunkGraph::get_chunk_runtime_requirements(compilation, chunk_ukey); + let runtime_requirements = compilation + .cgc_runtime_requirements_artifact + .get(chunk_ukey) + .copied() + .unwrap_or_default(); let strict_module_error_handling = compilation.options.output.strict_module_error_handling; let need_module_defer = runtime_requirements.contains(RuntimeGlobals::MAKE_DEFERRED_NAMESPACE_OBJECT); + let uses_runtime_context = compilation + .options + .experiments + .runtime_mode + .uses_runtime_context(); + let callable_require = runtime_template.render_runtime_variable(&RuntimeVariable::Require); + let require_argument = runtime_template.render_runtime_argument(); + let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); + let module_factories = runtime_template.render_runtime_variable(&RuntimeVariable::Modules); + let module_cache = runtime_template.render_runtime_variable(&RuntimeVariable::ModuleCache); let mut sources: Vec> = Vec::new(); sources.push( format!( r#"// Check if module is in cache -var cachedModule = {}[moduleId]; +var cachedModule = {module_cache}[moduleId]; if (cachedModule !== undefined) {{"#, - runtime_template.render_runtime_variable(&RuntimeVariable::ModuleCache) ) .into(), ); @@ -162,8 +177,7 @@ if (cachedModule !== undefined) {{"#, r#"return cachedModule.exports; }} // Create a new module (and put it into the cache) -var module = ({}[moduleId] = {{"#, - runtime_template.render_runtime_variable(&RuntimeVariable::ModuleCache) +var module = ({module_cache}[moduleId] = {{"#, ) .into(), ); @@ -183,39 +197,45 @@ var module = ({}[moduleId] = {{"#, } sources.push("});\n// Execute the module function".into()); - let module_execution = - if runtime_requirements.contains(RuntimeGlobals::INTERCEPT_MODULE_EXECUTION) { + let module_execution = if runtime_requirements + .contains(RuntimeGlobals::INTERCEPT_MODULE_EXECUTION) + { + if uses_runtime_context { format!( r#" - var execOptions = {{ id: moduleId, module: module, factory: {}[moduleId], require: {} }}; + var execOptions = {{ id: moduleId, module: module, factory: {}[moduleId], require: {}, context: Object.create({}) }}; {}.forEach(function(handler) {{ handler(execOptions); }}); module = execOptions.module; - if (!execOptions.factory) {{ - console.error("undefined factory", moduleId); - throw Error("RuntimeError: factory is undefined (" + moduleId + ")"); - }} - execOptions.factory.call(module.exports, module, module.exports, execOptions.require); + execOptions.factory.call(module.exports, module, module.exports, execOptions.context); "#, - runtime_template.render_runtime_variable(&RuntimeVariable::Modules), + module_factories, runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE), + runtime_context, runtime_template.render_runtime_globals(&RuntimeGlobals::INTERCEPT_MODULE_EXECUTION) ) .into() - } else if runtime_requirements.contains(RuntimeGlobals::THIS_AS_EXPORTS) { + } else { format!( - "{}[moduleId].call(module.exports, module, module.exports, {});\n", - runtime_template.render_runtime_variable(&RuntimeVariable::Modules), - runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE) + r#" + var execOptions = {{ id: moduleId, module: module, factory: {}[moduleId], require: {} }}; + {}.forEach(function(handler) {{ handler(execOptions); }}); + module = execOptions.module; + execOptions.factory.call(module.exports, module, module.exports, execOptions.require); + "#, + module_factories, + callable_require, + runtime_template.render_runtime_globals(&RuntimeGlobals::INTERCEPT_MODULE_EXECUTION) ) .into() - } else { - format!( - "{}[moduleId](module, module.exports, {});\n", - runtime_template.render_runtime_variable(&RuntimeVariable::Modules), - runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE) + } + } else if runtime_requirements.contains(RuntimeGlobals::THIS_AS_EXPORTS) { + format!( + "{module_factories}[moduleId].call(module.exports, module, module.exports, {require_argument});\n" ) .into() - }; + } else { + format!("{module_factories}[moduleId](module, module.exports, {require_argument});\n").into() + }; if strict_module_error_handling { sources.push("try {\n".into()); @@ -245,9 +265,13 @@ var module = ({}[moduleId] = {{"#, pub async fn render_bootstrap<'me>( chunk_ukey: &ChunkUkey, compilation: &'me Compilation, - runtime_template: &RuntimeCodeTemplate<'_>, + runtime_template: &ChunkCodeTemplate, ) -> Result> { - let runtime_requirements = ChunkGraph::get_chunk_runtime_requirements(compilation, chunk_ukey); + let runtime_requirements = compilation + .cgc_runtime_requirements_artifact + .get(chunk_ukey) + .copied() + .unwrap_or_default(); let chunk = compilation .build_chunk_graph_artifact .chunk_by_ukey @@ -258,7 +282,18 @@ var module = ({}[moduleId] = {{"#, let intercept_module_execution = runtime_requirements.contains(RuntimeGlobals::INTERCEPT_MODULE_EXECUTION); let module_used = runtime_requirements.contains(RuntimeGlobals::MODULE); - let require_scope_used = runtime_requirements.contains(RuntimeGlobals::REQUIRE_SCOPE); + let has_custom_runtime_module = compilation + .build_chunk_graph_artifact + .chunk_graph + .get_chunk_runtime_modules_iterable(chunk_ukey) + .any(|runtime_module_identifier| { + let runtime_module = &compilation.runtime_modules[runtime_module_identifier]; + runtime_module.get_custom_source().is_some() + || runtime_module.get_constructor_name() == "RuntimeModuleFromJs" + }); + let require_scope_used = runtime_requirements.contains(RuntimeGlobals::REQUIRE_SCOPE) + || !runtime_requirements.renderable_require_scope().is_empty() + || has_custom_runtime_module; let need_module_defer = runtime_requirements.contains(RuntimeGlobals::MAKE_DEFERRED_NAMESPACE_OBJECT); let use_require = require_function || intercept_module_execution || module_used; @@ -270,6 +305,13 @@ var module = ({}[moduleId] = {{"#, .output .environment .supports_arrow_function(); + let uses_runtime_context = compilation + .options + .experiments + .runtime_mode + .uses_runtime_context(); + let has_bootstrap_runtime_context = + uses_runtime_context && runtime_requirements.needs_bootstrap_runtime_context(); if allow_inline_startup && module_factories { startup.push("// module factories are used so entry inlining is disabled".into()); @@ -309,13 +351,17 @@ var __rspack_deferred_exports = {}; ); } + if has_bootstrap_runtime_context { + header.push(render_runtime_context_declaration(runtime_template).into()); + } + if use_require { header.push( format!( r#"// The require function function {}(moduleId) {{ "#, - runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE) + runtime_template.render_runtime_variable(&RuntimeVariable::Require) ) .into(), ); @@ -330,13 +376,20 @@ function {}(moduleId) {{ "# .into(), ); + if uses_runtime_context { + header.push(render_runtime_context_require_assignment(runtime_template).into()); + } + } else if require_scope_used && uses_runtime_context { + if !has_bootstrap_runtime_context { + header.push(render_runtime_context_declaration(runtime_template).into()); + } } else if require_scope_used { header.push( format!( r#"// The require scope var {} = {{}}; "#, - runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE) + runtime_template.render_runtime_variable(&RuntimeVariable::Require) ) .into(), ); @@ -344,26 +397,43 @@ var {} = {{}}; if module_factories || runtime_requirements.contains(RuntimeGlobals::MODULE_FACTORIES_ADD_ONLY) { + let module_factories = if uses_runtime_context { + let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); + let name = RuntimeGlobals::MODULE_FACTORIES + .property_name() + .expect("module factories should have context property name"); + format!("{runtime_context}{}", property_access([name], 0)) + } else { + runtime_template.render_runtime_globals(&RuntimeGlobals::MODULE_FACTORIES) + }; header.push( format!( r#"// expose the modules object ({modules}) {module_factories} = {modules}; "#, modules = runtime_template.render_runtime_variable(&RuntimeVariable::Modules), - module_factories = - runtime_template.render_runtime_globals(&RuntimeGlobals::MODULE_FACTORIES) + module_factories = module_factories ) .into(), ); } if runtime_requirements.contains(RuntimeGlobals::MODULE_CACHE) { + let module_cache_runtime_global = if uses_runtime_context { + let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); + let name = RuntimeGlobals::MODULE_CACHE + .property_name() + .expect("module cache should have context property name"); + format!("{runtime_context}{}", property_access([name], 0)) + } else { + runtime_template.render_runtime_globals(&RuntimeGlobals::MODULE_CACHE) + }; header.push( format!( r#"// expose the module cache {} = {}; "#, - runtime_template.render_runtime_globals(&RuntimeGlobals::MODULE_CACHE), + module_cache_runtime_global, runtime_template.render_runtime_variable(&RuntimeVariable::ModuleCache), ) .into(), @@ -371,12 +441,20 @@ var {} = {{}}; } if intercept_module_execution { + let intercept_module_execution = if uses_runtime_context { + let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); + let name = RuntimeGlobals::INTERCEPT_MODULE_EXECUTION + .property_name() + .expect("intercept module execution should have context property name"); + format!("{runtime_context}{}", property_access([name], 0)) + } else { + runtime_template.render_runtime_globals(&RuntimeGlobals::INTERCEPT_MODULE_EXECUTION) + }; header.push( format!( r#"// expose the module execution interceptor -{} = []; +{intercept_module_execution} = []; "#, - runtime_template.render_runtime_globals(&RuntimeGlobals::INTERCEPT_MODULE_EXECUTION) ) .into(), ); @@ -561,7 +639,7 @@ var {} = {{}}; } else { "{}".to_string() }, - runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE) + runtime_template.render_runtime_argument() ) .into(), ); @@ -673,7 +751,7 @@ var {} = {{}}; compilation: &Compilation, chunk_ukey: &ChunkUkey, output_path: &str, - runtime_template: &RuntimeCodeTemplate<'_>, + runtime_template: &ChunkCodeTemplate, ) -> Result { let js_plugin_hooks = Self::get_compilation_hooks(compilation.id()); let hooks = js_plugin_hooks @@ -688,7 +766,13 @@ var {} = {{}}; .output .environment .supports_arrow_function(); - let runtime_requirements = ChunkGraph::get_tree_runtime_requirements(compilation, chunk_ukey); + let runtime_requirements = compilation + .cgc_runtime_requirements_artifact + .get(chunk_ukey) + .copied() + .unwrap_or_default(); + let has_bootstrap_runtime_context = runtime_template.uses_runtime_context() + && runtime_requirements.needs_bootstrap_runtime_context(); let mut chunk_init_fragments = ChunkInitFragments::default(); let iife = compilation.options.output.iife; let mut all_strict = compilation.options.output.module; @@ -782,13 +866,18 @@ var {} = {{}}; header.push('\n'); sources.add(RawStringSource::from(header)); } - - if compilation - .build_chunk_graph_artifact - .chunk_graph - .has_chunk_runtime_modules(chunk_ukey) + let renders_runtime_context = should_render_runtime_context(compilation, chunk_ukey); + if renders_runtime_context + || compilation + .build_chunk_graph_artifact + .chunk_graph + .has_chunk_runtime_modules(chunk_ukey) { sources.add(render_runtime_modules(compilation, chunk_ukey, runtime_template).await?); + } else if runtime_template.uses_runtime_context() && !has_bootstrap_runtime_context { + sources.add(RawStringSource::from(render_runtime_context_declaration( + runtime_template, + ))); } if let Some(inlined_modules) = inlined_modules { let last_entry_module = inlined_modules @@ -1008,7 +1097,7 @@ var {} = {{}}; has_chunk_modules_result: bool, output_path: &str, hooks: &JavascriptModulesPluginHooks, - runtime_template: &RuntimeCodeTemplate<'_>, + runtime_template: &ChunkCodeTemplate, ) -> Result>>> { let inner_strict = !all_strict && all_modules.iter().all(|m| m.build_info().strict); let is_multiple_entries = inlined_modules.len() > 1; @@ -1348,7 +1437,7 @@ var {} = {{}}; compilation: &Compilation, chunk_ukey: &ChunkUkey, output_path: &str, - runtime_template: &RuntimeCodeTemplate<'_>, + runtime_template: &ChunkCodeTemplate, ) -> Result { let js_plugin_hooks = Self::get_compilation_hooks(compilation.id()); let hooks = js_plugin_hooks @@ -1447,7 +1536,7 @@ var {} = {{}}; compilation: &Compilation, hasher: &mut RspackHash, ) -> Result<()> { - let runtime_template = compilation.runtime_template.create_runtime_code_template(); + let runtime_template = compilation.runtime_template.create_chunk_code_template(); // sample hash use content let RenderBootstrapResult { header, diff --git a/crates/rspack_plugin_javascript/src/plugin/url_plugin.rs b/crates/rspack_plugin_javascript/src/plugin/url_plugin.rs index 2325272d8af2..8730a38b3610 100644 --- a/crates/rspack_plugin_javascript/src/plugin/url_plugin.rs +++ b/crates/rspack_plugin_javascript/src/plugin/url_plugin.rs @@ -1,10 +1,10 @@ use std::sync::Arc; use rspack_core::{ - ChunkInitFragments, ChunkUkey, CodeGenerationDataFilename, Compilation, CompilationParams, - CompilerCompilation, DependencyId, JavascriptParserUrl, Module, ModuleType, - NormalModuleFactoryParser, ParserAndGenerator, ParserOptions, Plugin, RuntimeCodeTemplate, - URLStaticMode, rspack_sources::ReplaceSource, + ChunkCodeTemplate, ChunkInitFragments, ChunkUkey, CodeGenerationDataFilename, Compilation, + CompilationParams, CompilerCompilation, DependencyId, JavascriptParserUrl, Module, ModuleType, + NormalModuleFactoryParser, ParserAndGenerator, ParserOptions, Plugin, URLStaticMode, + rspack_sources::ReplaceSource, }; use rspack_error::Result; use rspack_hook::{plugin, plugin_hook}; @@ -63,7 +63,7 @@ async fn render_module_content( module: &dyn Module, render_source: &mut RenderSource, _init_fragments: &mut ChunkInitFragments, - _runtime_template: &RuntimeCodeTemplate<'_>, + _runtime_template: &ChunkCodeTemplate, ) -> Result<()> { let runtime = compilation .build_chunk_graph_artifact diff --git a/crates/rspack_plugin_javascript/src/runtime.rs b/crates/rspack_plugin_javascript/src/runtime.rs index 980facf04dab..56b7f172ad61 100644 --- a/crates/rspack_plugin_javascript/src/runtime.rs +++ b/crates/rspack_plugin_javascript/src/runtime.rs @@ -1,10 +1,14 @@ use rayon::prelude::*; use rspack_core::{ - ChunkGraph, ChunkInitFragments, ChunkUkey, CodeGenerationPublicPathAutoReplace, Compilation, - Module, ModuleCodeGenerationContext, RuntimeCodeTemplate, RuntimeGlobals, SourceType, + ChunkCodeTemplate, ChunkGraph, ChunkInitFragments, ChunkKind, ChunkUkey, + CodeGenerationPublicPathAutoReplace, Compilation, Module, RuntimeGlobals, + RuntimeModuleGenerateContext, RuntimeProxyMetadata, RuntimeVariable, SourceType, chunk_graph_chunk::ChunkIdSet, - get_undo_path, - rspack_sources::{BoxSource, ConcatSource, RawStringSource, ReplaceSource, Source, SourceExt}, + get_undo_path, property_access, render_runtime_module_source, + rspack_sources::{ + BoxSource, ConcatSource, OriginalSource, RawStringSource, ReplaceSource, Source, SourceExt, + }, + runtime_mode::RuntimeMode, }; use rspack_error::{Result, ToStringResultToRspackResultExt}; @@ -19,7 +23,7 @@ pub async fn render_chunk_modules( all_strict: bool, output_path: &str, hooks: &JavascriptModulesPluginHooks, - runtime_template: &RuntimeCodeTemplate<'_>, + runtime_template: &ChunkCodeTemplate, ) -> Result> { let module_sources = rspack_parallel::scope::<_, _>(|token| { ordered_modules.iter().for_each(|module| { @@ -108,7 +112,7 @@ pub async fn render_module( factory: bool, output_path: &str, hooks: &JavascriptModulesPluginHooks, - runtime_template: &RuntimeCodeTemplate<'_>, + runtime_template: &ChunkCodeTemplate, ) -> Result> { let chunk = compilation .build_chunk_graph_artifact @@ -204,7 +208,10 @@ pub async fn render_module( let need_module = runtime_requirements.is_some_and(|r| r.contains(RuntimeGlobals::MODULE)); let need_exports = runtime_requirements.is_some_and(|r| r.contains(RuntimeGlobals::EXPORTS)); let need_require = runtime_requirements.is_some_and(|r| { - r.contains(RuntimeGlobals::REQUIRE) || r.contains(RuntimeGlobals::REQUIRE_SCOPE) + r.contains(RuntimeGlobals::REQUIRE) + || r.contains(RuntimeGlobals::REQUIRE_SCOPE) + || (compilation.options.experiments.runtime_mode == RuntimeMode::Rspack + && !r.renderable_require_scope().is_empty()) }); let mut args = Vec::new(); @@ -227,7 +234,7 @@ pub async fn render_module( }); } if need_require { - args.push(runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE)); + args.push(runtime_template.render_runtime_argument()); } let mut container_sources = ConcatSource::default(); @@ -307,21 +314,366 @@ pub async fn render_module( ))) } +fn runtime_context_metadata<'a>( + compilation: &'a Compilation, + chunk_ukey: &ChunkUkey, +) -> Option<&'a RuntimeProxyMetadata> { + if compilation.options.experiments.runtime_mode != RuntimeMode::Rspack { + return None; + } + + if let Some(metadata) = compilation.runtime_proxy_metadata_artifact.get(chunk_ukey) { + return Some(metadata); + } + + let chunk = compilation + .build_chunk_graph_artifact + .chunk_by_ukey + .expect_get(chunk_ukey); + compilation + .runtime_proxy_metadata_artifact + .iter() + .find_map(|(runtime_chunk_ukey, metadata)| { + let runtime_chunk = compilation + .build_chunk_graph_artifact + .chunk_by_ukey + .expect_get(runtime_chunk_ukey); + runtime_chunk + .runtime() + .iter() + .any(|runtime| chunk.runtime().contains(runtime)) + .then_some(metadata) + }) +} + +fn runtime_context_render_metadata( + compilation: &Compilation, + chunk_ukey: &ChunkUkey, +) -> Option { + runtime_context_metadata(compilation, chunk_ukey).cloned() +} + +pub fn should_render_runtime_context(compilation: &Compilation, chunk_ukey: &ChunkUkey) -> bool { + if compilation.options.experiments.runtime_mode != RuntimeMode::Rspack { + return false; + } + + runtime_context_render_metadata(compilation, chunk_ukey).is_some_and(|metadata| { + metadata + .tree_runtime_requirements + .contains(RuntimeGlobals::REQUIRE_SCOPE) + }) +} + +fn is_hot_update_chunk(compilation: &Compilation, chunk_ukey: &ChunkUkey) -> bool { + let chunk = compilation + .build_chunk_graph_artifact + .chunk_by_ukey + .expect_get(chunk_ukey); + matches!(chunk.kind(), ChunkKind::HotUpdate) +} + +fn hmr_runtime_state_key(constructor_name: &str) -> Option<&'static str> { + match constructor_name { + "JsonpChunkLoadingRuntimeModule" => Some("jsonp"), + "ModuleChunkLoadingRuntimeModule" => Some("module"), + "ImportScriptsChunkLoadingRuntimeModule" => Some("importScripts"), + "ReadFileChunkLoadingRuntimeModule" => Some("readFileVm"), + "RequireChunkLoadingRuntimeModule" => Some("require"), + _ => None, + } +} + +fn hmr_runtime_state_variables(compilation: &Compilation, chunk_ukey: &ChunkUkey) -> Vec { + let mut variables = Vec::new(); + for runtime_module_id in compilation + .build_chunk_graph_artifact + .chunk_graph + .get_chunk_runtime_modules_iterable(chunk_ukey) + { + let runtime_module = compilation + .runtime_modules + .get(runtime_module_id) + .expect("should have runtime module"); + let Some(key) = hmr_runtime_state_key(&runtime_module.get_constructor_name()) else { + continue; + }; + let name = format!( + "{}_{key}", + RuntimeGlobals::HMR_RUNTIME_STATE_PREFIX + .property_name() + .expect("hmr runtime state prefix should have property name") + ); + if !variables.contains(&name) { + variables.push(name); + } + } + variables +} + +pub fn render_runtime_context_declaration(runtime_template: &ChunkCodeTemplate) -> String { + let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); + format!("var {runtime_context}={{}};\n") +} + +pub fn render_runtime_context_require_assignment(runtime_template: &ChunkCodeTemplate) -> String { + format!( + "{} = {};\n", + runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE), + runtime_template.render_runtime_variable(&RuntimeVariable::Require) + ) +} + +fn has_bootstrap_runtime_context( + compilation: &Compilation, + chunk_ukey: &ChunkUkey, + runtime_template: &ChunkCodeTemplate, +) -> bool { + if !runtime_template.uses_runtime_context() { + return false; + } + + let runtime_requirements = compilation + .cgc_runtime_requirements_artifact + .get(chunk_ukey) + .copied() + .unwrap_or_default(); + runtime_requirements.needs_bootstrap_runtime_context() +} + +fn render_runtime_context_declarations( + compilation: &Compilation, + chunk_ukey: &ChunkUkey, + runtime_template: &ChunkCodeTemplate, + render_lexical_fields: bool, + render_context_object: bool, +) -> Option { + if !should_render_runtime_context(compilation, chunk_ukey) { + return None; + } + + let mut sources = ConcatSource::default(); + if render_context_object { + sources.add(RawStringSource::from(render_runtime_context_declaration( + runtime_template, + ))); + } + + if render_lexical_fields + && let Some(metadata) = runtime_context_render_metadata(compilation, chunk_ukey) + { + let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); + sources.add(RawStringSource::from( + metadata.render_lexical_declarations(), + )); + let hmr_runtime_state_variables = hmr_runtime_state_variables(compilation, chunk_ukey); + if !hmr_runtime_state_variables.is_empty() { + let declarations = hmr_runtime_state_variables + .iter() + .map(|name| { + format!( + "{name}={runtime_context}{}", + property_access([name.as_str()], 0) + ) + }) + .collect::>() + .join(","); + sources.add(RawStringSource::from(format!("var {declarations};\n"))); + } + } + if !render_context_object { + return Some(sources.boxed()); + } + + Some(sources.boxed()) +} + +fn render_runtime_context_fields( + compilation: &Compilation, + chunk_ukey: &ChunkUkey, + runtime_template: &ChunkCodeTemplate, + render_setter_fields: bool, + render_plain_fields: bool, +) -> Option { + if !runtime_template.uses_lexical_runtime_globals() { + return None; + } + + let metadata = compilation + .runtime_proxy_metadata_artifact + .get(chunk_ukey)?; + let mut sources = ConcatSource::default(); + let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); + let render_live_bindings = render_setter_fields && !render_plain_fields; + + for (_, runtime_global) in metadata.context_fields().iter_names() { + let has_setter = metadata.context_setter_fields().contains(runtime_global); + if !render_live_bindings + && ((has_setter && !render_setter_fields) || (!has_setter && !render_plain_fields)) + { + continue; + } + + let Some(key) = runtime_global.property_name() else { + continue; + }; + let Some(lexical_name) = runtime_global.to_lexical_name() else { + if render_plain_fields { + sources.add(RawStringSource::from(format!( + "{}{} = {{}};\n", + runtime_context, + property_access([key], 0) + ))); + } + continue; + }; + + if render_live_bindings || has_setter { + sources.add(RawStringSource::from(format!( + "Object.defineProperty({}, {}, {{ configurable: true, get: function() {{ return {}; }}, set: function(value) {{ {} = value; }} }});\n", + runtime_context, + rspack_util::json_stringify(key), + lexical_name, + lexical_name + ))); + } else { + sources.add(RawStringSource::from(format!( + "{}{} = {};\n", + runtime_context, + property_access([key], 0), + lexical_name + ))); + } + } + + Some(sources.boxed()) +} + +fn render_runtime_context_field_initializers( + compilation: &Compilation, + chunk_ukey: &ChunkUkey, + runtime_template: &ChunkCodeTemplate, + preserve_initialized_fields: bool, +) -> Option { + if !runtime_template.uses_lexical_runtime_globals() { + return None; + } + + let metadata = runtime_context_render_metadata(compilation, chunk_ukey)?; + let mut sources = ConcatSource::default(); + let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); + + for (_, runtime_global) in metadata.lexical_fields().iter_names() { + let Some(key) = runtime_global.property_name() else { + continue; + }; + let Some(lexical_name) = runtime_global.to_lexical_name() else { + continue; + }; + sources.add(RawStringSource::from(format!( + "{lexical_name} = {runtime_context}{};\n", + property_access([key], 0) + ))); + if runtime_global.should_initialize_as_object() { + let value = if preserve_initialized_fields { + format!("{lexical_name} || {{}}") + } else { + "{}".to_string() + }; + sources.add(RawStringSource::from(format!( + "{lexical_name} = {value};\n" + ))); + } else if runtime_global.should_initialize_as_array() { + let value = if preserve_initialized_fields { + format!("{lexical_name} || []") + } else { + "[]".to_string() + }; + sources.add(RawStringSource::from(format!( + "{lexical_name} = {value};\n" + ))); + } + } + + Some(sources.boxed()) +} + +fn render_hot_update_runtime_variable_bindings( + runtime_template: &ChunkCodeTemplate, +) -> Option { + if !runtime_template.uses_runtime_context() { + return None; + } + + let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); + let require = runtime_template.render_runtime_variable(&RuntimeVariable::Require); + let modules = runtime_template.render_runtime_variable(&RuntimeVariable::Modules); + Some( + RawStringSource::from(format!( + "var {require}={runtime_context}.r,{modules}={runtime_context}.m;\n" + )) + .boxed(), + ) +} + +fn render_runtime_context_setter_assignments( + compilation: &Compilation, + chunk_ukey: &ChunkUkey, + runtime_template: &ChunkCodeTemplate, +) -> Option { + if !runtime_template.uses_lexical_runtime_globals() { + return None; + } + + let metadata = runtime_context_render_metadata(compilation, chunk_ukey)?; + let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); + Some(RawStringSource::from(metadata.render_context_setter_assignments(&runtime_context)).boxed()) +} + +fn render_hmr_runtime_state_final_fields( + compilation: &Compilation, + chunk_ukey: &ChunkUkey, + runtime_template: &ChunkCodeTemplate, +) -> Option { + if !runtime_template.uses_lexical_runtime_globals() { + return None; + } + + let variables = hmr_runtime_state_variables(compilation, chunk_ukey); + if variables.is_empty() { + return None; + } + + let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); + let assignments = variables + .iter() + .map(|name| { + format!( + "{runtime_context}{}={name};", + property_access([name.as_str()], 0) + ) + }) + .collect::(); + Some(RawStringSource::from(assignments).boxed()) +} + pub async fn render_chunk_runtime_modules( compilation: &Compilation, chunk_ukey: &ChunkUkey, - runtime_template: &RuntimeCodeTemplate<'_>, + runtime_template: &ChunkCodeTemplate, ) -> Result { let runtime_modules_sources = render_runtime_modules(compilation, chunk_ukey, runtime_template).await?; - if runtime_modules_sources.source().is_empty() { + if runtime_modules_sources.source().is_empty() + && !should_render_runtime_context(compilation, chunk_ukey) + { return Ok(runtime_modules_sources); } let mut sources = ConcatSource::default(); sources.add(RawStringSource::from(format!( "function({}) {{\n", - runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE), + runtime_template.render_runtime_argument() ))); sources.add(runtime_modules_sources); sources.add(RawStringSource::from_static("\n}\n")); @@ -331,7 +683,7 @@ pub async fn render_chunk_runtime_modules( pub async fn render_runtime_modules( compilation: &Compilation, chunk_ukey: &ChunkUkey, - _runtime_template: &RuntimeCodeTemplate<'_>, + runtime_template: &ChunkCodeTemplate, ) -> Result { let mut sources = ConcatSource::default(); let runtime_module_sources = rspack_parallel::scope::<_, Result<_>>(|token| { @@ -349,53 +701,62 @@ pub async fn render_runtime_modules( ) }) .for_each(|(source, module)| { - let s = unsafe { token.used((compilation, source, module)) }; - s.spawn(|(compilation, source, module)| async move { - let mut sources = ConcatSource::default(); - if source.size() == 0 { - return Ok(sources); - } - sources.add(RawStringSource::from(format!( - "// {}\n", - module.identifier() - ))); - let supports_arrow_function = compilation - .options - .output - .environment - .supports_arrow_function(); - if module.should_isolate() { - sources.add(RawStringSource::from(if supports_arrow_function { - "(() => {\n" + let s = unsafe { token.used((compilation, source, module, runtime_template)) }; + s.spawn( + |(compilation, source, module, runtime_template)| async move { + if source.size() == 0 { + return Ok(ConcatSource::default().boxed()); + } + if runtime_template.uses_runtime_context() + && (module.get_custom_source().is_some() + || module.get_constructor_name() == "RuntimeModuleFromJs") + { + return Err(rspack_error::error!( + "Custom runtime modules are not supported when `experiments.runtimeMode` is \"rspack\" (runtime module: {}).", + module.identifier() + )); + } + let supports_arrow_function = compilation + .options + .output + .environment + .supports_arrow_function(); + let source = if !(module.full_hash() + || module.dependent_hash() + || (runtime_template.uses_runtime_context() + && !runtime_template.uses_lexical_runtime_globals())) + { + if let Some(custom_source) = module.get_custom_source() { + RawStringSource::from(custom_source).boxed() + } else { + source.clone() + } } else { - "!function() {\n" - })); - } - if !(module.full_hash() || module.dependent_hash()) { - sources.add(source.clone()); - } else { - let mut runtime_template = compilation.runtime_template.create_module_code_template(); - let mut code_generation_context = ModuleCodeGenerationContext { - compilation, - runtime: None, - concatenation_scope: None, - runtime_template: &mut runtime_template, + if let Some(custom_source) = module.get_custom_source() { + RawStringSource::from(custom_source).boxed() + } else { + let runtime_template = compilation.runtime_template.create_runtime_code_template(); + let context = RuntimeModuleGenerateContext { + compilation, + runtime_template: &runtime_template, + }; + let source_str = module.generate(&context).await?; + if module.get_source_map_kind().enabled() { + OriginalSource::new(source_str, module.identifier().as_str()).boxed() + } else { + RawStringSource::from(source_str).boxed() + } + } }; - - let result = module.code_generation(&mut code_generation_context).await?; - #[allow(clippy::unwrap_used)] - let source = result.get(&SourceType::Runtime).unwrap(); - sources.add(source.clone()); - } - if module.should_isolate() { - sources.add(RawStringSource::from(if supports_arrow_function { - "\n})();\n" - } else { - "\n}();\n" - })); - } - Ok(sources) - }); + let sources = render_runtime_module_source( + module.identifier(), + source, + module.should_isolate(), + supports_arrow_function, + ); + Ok(sources) + }, + ); }) }) .await @@ -403,9 +764,92 @@ pub async fn render_runtime_modules( .map(|r| r.to_rspack_result()) .collect::>>()?; + let isolate_runtime_context = runtime_template.uses_runtime_context() + && runtime_template.uses_lexical_runtime_globals() + && !compilation.options.output.module + && should_render_runtime_context(compilation, chunk_ukey) + && runtime_context_render_metadata(compilation, chunk_ukey).is_some_and(|metadata| { + !metadata.lexical_fields().is_empty() || !metadata.context_fields().is_empty() + }); + + let is_hot_update = is_hot_update_chunk(compilation, chunk_ukey); + let has_runtime_context = + is_hot_update || has_bootstrap_runtime_context(compilation, chunk_ukey, runtime_template); + if isolate_runtime_context { + if !has_runtime_context + && let Some(context_declarations) = + render_runtime_context_declarations(compilation, chunk_ukey, runtime_template, false, true) + { + sources.add(context_declarations); + } + let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); + sources.add(RawStringSource::from(format!( + "(function({runtime_context}) {{\n" + ))); + if let Some(context_declarations) = + render_runtime_context_declarations(compilation, chunk_ukey, runtime_template, true, false) + { + sources.add(context_declarations); + } + } else if let Some(context_declarations) = render_runtime_context_declarations( + compilation, + chunk_ukey, + runtime_template, + true, + !has_runtime_context, + ) { + sources.add(context_declarations); + } + if let Some(context_fields) = render_runtime_context_field_initializers( + compilation, + chunk_ukey, + runtime_template, + is_hot_update, + ) { + sources.add(context_fields); + } + if is_hot_update + && let Some(bindings) = render_hot_update_runtime_variable_bindings(runtime_template) + { + sources.add(bindings); + } + if !is_hot_update + && let Some(context_fields) = + render_runtime_context_fields(compilation, chunk_ukey, runtime_template, true, false) + { + sources.add(context_fields); + } for runtime_module_source in runtime_module_sources { sources.add(runtime_module_source?); } + if let Some(context_fields) = + render_hmr_runtime_state_final_fields(compilation, chunk_ukey, runtime_template) + { + sources.add(context_fields); + } + if is_hot_update + && let Some(context_fields) = + render_runtime_context_setter_assignments(compilation, chunk_ukey, runtime_template) + { + sources.add(context_fields); + } + if is_hot_update { + if let Some(context_fields) = + render_runtime_context_fields(compilation, chunk_ukey, runtime_template, false, true) + { + sources.add(context_fields); + } + } else if let Some(context_fields) = + render_runtime_context_fields(compilation, chunk_ukey, runtime_template, false, true) + { + sources.add(context_fields); + } + if isolate_runtime_context { + let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); + sources.add(RawStringSource::from(format!( + "\n}})({runtime_context});\n" + ))); + } Ok(sources.boxed()) } diff --git a/crates/rspack_plugin_library/src/amd_library_plugin.rs b/crates/rspack_plugin_library/src/amd_library_plugin.rs index b45ab6813108..e1e9e3ab8b22 100644 --- a/crates/rspack_plugin_library/src/amd_library_plugin.rs +++ b/crates/rspack_plugin_library/src/amd_library_plugin.rs @@ -1,9 +1,10 @@ use std::hash::Hash; use rspack_core::{ - ChunkUkey, Compilation, CompilationAdditionalChunkRuntimeRequirements, CompilationParams, - CompilerCompilation, ExternalModule, Filename, LibraryName, LibraryNonUmdObject, LibraryOptions, - LibraryType, PathData, Plugin, RuntimeCodeTemplate, RuntimeGlobals, RuntimeModule, SourceType, + ChunkCodeTemplate, ChunkUkey, Compilation, CompilationAdditionalChunkRuntimeRequirements, + CompilationParams, CompilerCompilation, ExternalModule, Filename, LibraryName, + LibraryNonUmdObject, LibraryOptions, LibraryType, PathData, Plugin, RuntimeGlobals, + RuntimeModule, SourceType, rspack_sources::{ConcatSource, RawStringSource, SourceExt}, }; use rspack_error::{Result, error_bail}; @@ -92,7 +93,7 @@ async fn render( compilation: &Compilation, chunk_ukey: &ChunkUkey, render_source: &mut RenderSource, - _runtime_template: &RuntimeCodeTemplate<'_>, + _runtime_template: &ChunkCodeTemplate, ) -> Result<()> { let Some(options) = self.get_options_for_chunk(compilation, chunk_ukey)? else { return Ok(()); diff --git a/crates/rspack_plugin_library/src/assign_library_plugin.rs b/crates/rspack_plugin_library/src/assign_library_plugin.rs index e3cb43d132f7..697292e1d8b5 100644 --- a/crates/rspack_plugin_library/src/assign_library_plugin.rs +++ b/crates/rspack_plugin_library/src/assign_library_plugin.rs @@ -3,13 +3,13 @@ use std::{hash::Hash, sync::LazyLock}; use futures::future::join_all; use regex::Regex; use rspack_core::{ - AsyncModulesArtifact, BoxModule, CanInlineUse, Chunk, ChunkUkey, + AsyncModulesArtifact, BoxModule, CanInlineUse, Chunk, ChunkCodeTemplate, ChunkUkey, CodeGenerationDataTopLevelDeclarations, Compilation, CompilationAdditionalChunkRuntimeRequirements, CompilationFinishModules, CompilationParams, CompilerCompilation, EntryData, ExportProvided, ExportsInfoArtifact, Filename, LibraryExport, LibraryName, LibraryNonUmdObject, LibraryOptions, ModuleIdentifier, PathData, Plugin, - RuntimeCodeTemplate, RuntimeGlobals, RuntimeModule, RuntimeVariable, SideEffectsStateArtifact, - SourceType, UsageState, get_entry_runtime, property_access, + RuntimeGlobals, RuntimeModule, RuntimeVariable, SideEffectsStateArtifact, SourceType, UsageState, + get_entry_runtime, property_access, rspack_sources::{ConcatSource, RawStringSource, SourceExt}, to_identifier, }; @@ -213,7 +213,7 @@ async fn render( compilation: &Compilation, chunk_ukey: &ChunkUkey, render_source: &mut RenderSource, - _runtime_template: &RuntimeCodeTemplate<'_>, + _runtime_template: &ChunkCodeTemplate, ) -> Result<()> { let Some(options) = self.get_options_for_chunk(compilation, chunk_ukey)? else { return Ok(()); @@ -248,7 +248,7 @@ async fn render_startup( chunk_ukey: &ChunkUkey, module: &ModuleIdentifier, render_source: &mut RenderSource, - runtime_template: &RuntimeCodeTemplate<'_>, + runtime_template: &ChunkCodeTemplate, ) -> Result<()> { let Some(options) = self.get_options_for_chunk(compilation, chunk_ukey)? else { return Ok(()); diff --git a/crates/rspack_plugin_library/src/export_property_library_plugin.rs b/crates/rspack_plugin_library/src/export_property_library_plugin.rs index b36700fbe443..64b824bcc9b3 100644 --- a/crates/rspack_plugin_library/src/export_property_library_plugin.rs +++ b/crates/rspack_plugin_library/src/export_property_library_plugin.rs @@ -1,11 +1,11 @@ use std::hash::Hash; use rspack_core::{ - AsyncModulesArtifact, CanInlineUse, ChunkUkey, Compilation, + AsyncModulesArtifact, CanInlineUse, ChunkCodeTemplate, ChunkUkey, Compilation, CompilationAdditionalChunkRuntimeRequirements, CompilationFinishModules, CompilationParams, CompilerCompilation, EntryData, ExportsInfoArtifact, LibraryExport, LibraryOptions, LibraryType, - ModuleIdentifier, Plugin, RuntimeCodeTemplate, RuntimeGlobals, RuntimeModule, - SideEffectsStateArtifact, UsageState, get_entry_runtime, property_access, + ModuleIdentifier, Plugin, RuntimeGlobals, RuntimeModule, SideEffectsStateArtifact, UsageState, + get_entry_runtime, property_access, rspack_sources::{ConcatSource, RawStringSource, SourceExt}, }; use rspack_error::Result; @@ -77,7 +77,7 @@ async fn render_startup( chunk_ukey: &ChunkUkey, _module: &ModuleIdentifier, render_source: &mut RenderSource, - _runtime_template: &RuntimeCodeTemplate<'_>, + _runtime_template: &ChunkCodeTemplate, ) -> Result<()> { let Some(options) = self.get_options_for_chunk(compilation, chunk_ukey) else { return Ok(()); diff --git a/crates/rspack_plugin_library/src/jsonp_library_plugin.rs b/crates/rspack_plugin_library/src/jsonp_library_plugin.rs index 7bef42e263e7..6812f10b8af6 100644 --- a/crates/rspack_plugin_library/src/jsonp_library_plugin.rs +++ b/crates/rspack_plugin_library/src/jsonp_library_plugin.rs @@ -1,9 +1,9 @@ use std::hash::Hash; use rspack_core::{ - ChunkUkey, Compilation, CompilationAdditionalChunkRuntimeRequirements, CompilationParams, - CompilerCompilation, Filename, LibraryName, LibraryNonUmdObject, LibraryOptions, LibraryType, - PathData, Plugin, RuntimeCodeTemplate, RuntimeGlobals, RuntimeModule, SourceType, + ChunkCodeTemplate, ChunkUkey, Compilation, CompilationAdditionalChunkRuntimeRequirements, + CompilationParams, CompilerCompilation, Filename, LibraryName, LibraryNonUmdObject, + LibraryOptions, LibraryType, PathData, Plugin, RuntimeGlobals, RuntimeModule, SourceType, rspack_sources::{ConcatSource, RawStringSource, SourceExt}, }; use rspack_error::{Result, error_bail}; @@ -75,7 +75,7 @@ async fn render( compilation: &Compilation, chunk_ukey: &ChunkUkey, render_source: &mut RenderSource, - _runtime_template: &RuntimeCodeTemplate<'_>, + _runtime_template: &ChunkCodeTemplate, ) -> Result<()> { let Some(options) = self.get_options_for_chunk(compilation, chunk_ukey)? else { return Ok(()); diff --git a/crates/rspack_plugin_library/src/module_library_plugin.rs b/crates/rspack_plugin_library/src/module_library_plugin.rs index 2b78cda164dd..f4de91979aa8 100644 --- a/crates/rspack_plugin_library/src/module_library_plugin.rs +++ b/crates/rspack_plugin_library/src/module_library_plugin.rs @@ -1,9 +1,9 @@ use std::hash::Hash; use rspack_core::{ - ChunkUkey, Compilation, CompilationParams, CompilerCompilation, ExportProvided, ExportsType, - LibraryOptions, ModuleGraph, ModuleIdentifier, Plugin, RuntimeCodeTemplate, RuntimeVariable, - UsedNameItem, property_access, + ChunkCodeTemplate, ChunkUkey, Compilation, CompilationParams, CompilerCompilation, + ExportProvided, ExportsType, LibraryOptions, ModuleGraph, ModuleIdentifier, Plugin, + RuntimeVariable, UsedNameItem, property_access, rspack_sources::{ConcatSource, RawStringSource, SourceExt}, to_identifier, to_module_export_name, }; @@ -62,7 +62,7 @@ async fn render_startup( chunk_ukey: &ChunkUkey, module: &ModuleIdentifier, render_source: &mut RenderSource, - runtime_template: &RuntimeCodeTemplate<'_>, + runtime_template: &ChunkCodeTemplate, ) -> Result<()> { let Some(_) = self.get_options_for_chunk(compilation, chunk_ukey)? else { return Ok(()); diff --git a/crates/rspack_plugin_library/src/system_library_plugin.rs b/crates/rspack_plugin_library/src/system_library_plugin.rs index 9a3d0711bf6b..b8880ffbbacd 100644 --- a/crates/rspack_plugin_library/src/system_library_plugin.rs +++ b/crates/rspack_plugin_library/src/system_library_plugin.rs @@ -1,9 +1,9 @@ use std::hash::Hash; use rspack_core::{ - ChunkUkey, Compilation, CompilationAdditionalChunkRuntimeRequirements, CompilationParams, - CompilerCompilation, ExternalModule, ExternalRequest, Filename, LibraryName, LibraryNonUmdObject, - LibraryOptions, PathData, Plugin, RuntimeCodeTemplate, RuntimeGlobals, RuntimeModule, + ChunkCodeTemplate, ChunkUkey, Compilation, CompilationAdditionalChunkRuntimeRequirements, + CompilationParams, CompilerCompilation, ExternalModule, ExternalRequest, Filename, LibraryName, + LibraryNonUmdObject, LibraryOptions, PathData, Plugin, RuntimeGlobals, RuntimeModule, rspack_sources::{ConcatSource, RawStringSource, SourceExt}, }; use rspack_error::{Result, ToStringResultToRspackResultExt, error_bail}; @@ -84,7 +84,7 @@ async fn render( compilation: &Compilation, chunk_ukey: &ChunkUkey, render_source: &mut RenderSource, - _runtime_template: &RuntimeCodeTemplate<'_>, + _runtime_template: &ChunkCodeTemplate, ) -> Result<()> { let Some(options) = self.get_options_for_chunk(compilation, chunk_ukey)? else { return Ok(()); diff --git a/crates/rspack_plugin_library/src/umd_library_plugin.rs b/crates/rspack_plugin_library/src/umd_library_plugin.rs index 578e80bd9609..4ccf43d7dd2f 100644 --- a/crates/rspack_plugin_library/src/umd_library_plugin.rs +++ b/crates/rspack_plugin_library/src/umd_library_plugin.rs @@ -1,11 +1,11 @@ use std::{borrow::Cow, hash::Hash}; use rspack_core::{ - Chunk, ChunkUkey, Compilation, CompilationAdditionalChunkRuntimeRequirements, CompilationParams, - CompilerCompilation, ExportsInfoArtifact, ExternalModule, ExternalRequest, Filename, - LibraryAuxiliaryComment, LibraryCustomUmdObject, LibraryName, LibraryNonUmdObject, + Chunk, ChunkCodeTemplate, ChunkUkey, Compilation, CompilationAdditionalChunkRuntimeRequirements, + CompilationParams, CompilerCompilation, ExportsInfoArtifact, ExternalModule, ExternalRequest, + Filename, LibraryAuxiliaryComment, LibraryCustomUmdObject, LibraryName, LibraryNonUmdObject, LibraryOptions, LibraryType, ModuleGraph, ModuleGraphCacheArtifact, PathData, Plugin, - RuntimeCodeTemplate, RuntimeGlobals, RuntimeModule, SideEffectsStateArtifact, SourceType, + RuntimeGlobals, RuntimeModule, SideEffectsStateArtifact, SourceType, rspack_sources::{ConcatSource, RawStringSource, SourceExt}, }; use rspack_error::{Result, error}; @@ -98,7 +98,7 @@ async fn render( compilation: &Compilation, chunk_ukey: &ChunkUkey, render_source: &mut RenderSource, - _runtime_template: &RuntimeCodeTemplate<'_>, + _runtime_template: &ChunkCodeTemplate, ) -> Result<()> { let Some(options) = self.get_options_for_chunk(compilation, chunk_ukey) else { return Ok(()); diff --git a/crates/rspack_plugin_mf/src/container/container_entry_module.rs b/crates/rspack_plugin_mf/src/container/container_entry_module.rs index afad80b50fa3..cda7bc42ebb8 100644 --- a/crates/rspack_plugin_mf/src/container/container_entry_module.rs +++ b/crates/rspack_plugin_mf/src/container/container_entry_module.rs @@ -21,7 +21,10 @@ use rustc_hash::FxHashSet; use super::{ container_exposed_dependency::ContainerExposedDependency, container_plugin::ExposeOptions, }; -use crate::{ShareScope, utils::json_stringify}; +use crate::{ + ShareScope, + utils::{json_stringify, module_require_scope_name}, +}; #[impl_source_map_config] #[cacheable] @@ -254,7 +257,8 @@ impl Module for ContainerEntryModule { } = code_generation_context; let mut code_generation_result = CodeGenerationResult::default(); - let require_name = runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE); + let require_name = module_require_scope_name(compilation, runtime_template); + let runtime_argument = require_name.clone(); if self.dependency_type == DependencyType::ShareContainerEntry { let module_graph = compilation.get_module_graph(); @@ -272,10 +276,7 @@ impl Module for ContainerEntryModule { } } - let federation_global = format!( - "{}.federation", - runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE) - ); + let federation_global = format!("{}.federation", require_name); // Generate installInitialConsumes function using returning_function let install_initial_consumes_call = format!( @@ -283,7 +284,7 @@ impl Module for ContainerEntryModule { installedModules: localInstalledModules, initialConsumes: {require_name}.consumesLoadingData.initialConsumes, moduleToHandlerMapping: {require_name}.federation.consumesLoadingModuleToHandlerMapping || {{}}, - webpackRequire: {require_name}, + webpackRequire: {runtime_argument}, asyncLoad: true }})"#, ); @@ -345,14 +346,8 @@ impl Module for ContainerEntryModule { let source = if self.enhanced { let define_property_getters = runtime_template.render_runtime_globals(&RuntimeGlobals::DEFINE_PROPERTY_GETTERS); - let get_container = format!( - "{}.getContainer", - runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE) - ); - let init_container = format!( - "{}.initContainer", - runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE) - ); + let get_container = format!("{}.getContainer", require_name); + let init_container = format!("{}.initContainer", require_name); format!( r#" diff --git a/crates/rspack_plugin_mf/src/container/embed_federation_runtime_plugin.rs b/crates/rspack_plugin_mf/src/container/embed_federation_runtime_plugin.rs index e9247b8138c1..62143fc87695 100644 --- a/crates/rspack_plugin_mf/src/container/embed_federation_runtime_plugin.rs +++ b/crates/rspack_plugin_mf/src/container/embed_federation_runtime_plugin.rs @@ -7,9 +7,9 @@ use std::sync::{Arc, Mutex}; use rspack_core::{ - ChunkUkey, Compilation, CompilationAdditionalChunkRuntimeRequirements, CompilationParams, - CompilationRuntimeRequirementInTree, CompilerCompilation, DependencyId, ModuleIdentifier, Plugin, - RuntimeCodeTemplate, RuntimeGlobals, RuntimeModule, + ChunkCodeTemplate, ChunkUkey, Compilation, CompilationAdditionalChunkRuntimeRequirements, + CompilationParams, CompilationRuntimeRequirementInTree, CompilerCompilation, DependencyId, + ModuleIdentifier, Plugin, RuntimeGlobals, RuntimeModule, rspack_sources::{ConcatSource, RawStringSource, SourceExt}, }; use rspack_error::Result; @@ -183,7 +183,7 @@ async fn render_startup( chunk_ukey: &ChunkUkey, _module: &ModuleIdentifier, render_source: &mut RenderSource, - runtime_template: &RuntimeCodeTemplate<'_>, + runtime_template: &ChunkCodeTemplate, ) -> Result<()> { let chunk = compilation .build_chunk_graph_artifact diff --git a/crates/rspack_plugin_mf/src/container/expose_runtime_module.rs b/crates/rspack_plugin_mf/src/container/expose_runtime_module.rs index ee2c81235fe0..17b2b072ac26 100644 --- a/crates/rspack_plugin_mf/src/container/expose_runtime_module.rs +++ b/crates/rspack_plugin_mf/src/container/expose_runtime_module.rs @@ -1,10 +1,10 @@ use rspack_core::{ - ChunkUkey, Compilation, RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, - RuntimeModuleStage, RuntimeTemplate, SourceType, impl_runtime_module, + ChunkUkey, Compilation, RuntimeModule, RuntimeModuleGenerateContext, RuntimeModuleStage, + RuntimeTemplate, SourceType, impl_runtime_module, }; use super::container_entry_module::CodeGenerationDataExpose; -use crate::utils::json_stringify; +use crate::utils::{json_stringify, module_require_scope_name}; #[impl_runtime_module] #[derive(Debug)] @@ -71,7 +71,7 @@ impl RuntimeModule for ExposeRuntimeModule { }; let mut runtime_template = compilation.runtime_template.create_module_code_template(); let module_map = data.module_map.render(&mut runtime_template); - let require_name = runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE); + let require_name = module_require_scope_name(compilation, &mut runtime_template); let mut source = format!( r#" {require_name}.initializeExposesData = {{ diff --git a/crates/rspack_plugin_mf/src/container/federation_data_runtime_module.rs b/crates/rspack_plugin_mf/src/container/federation_data_runtime_module.rs index 646d4b7002e2..0743addee0b6 100644 --- a/crates/rspack_plugin_mf/src/container/federation_data_runtime_module.rs +++ b/crates/rspack_plugin_mf/src/container/federation_data_runtime_module.rs @@ -6,13 +6,15 @@ use async_trait::async_trait; use rspack_core::{ - BooleanMatcher, Chunk, Compilation, RuntimeCodeTemplate, RuntimeGlobals, RuntimeModule, + BooleanMatcher, Chunk, Compilation, RuntimeCodeTemplate, RuntimeModule, RuntimeModuleGenerateContext, RuntimeModuleStage, RuntimeTemplate, compile_boolean_matcher, get_js_chunk_filename_template, get_undo_path, impl_runtime_module, }; use rspack_error::Result; use rspack_plugin_javascript::impl_plugin_for_js_plugin::chunk_has_js; +use crate::utils::runtime_require_scope_name; + #[impl_runtime_module] #[derive(Debug)] pub struct FederationDataRuntimeModule {} @@ -46,7 +48,7 @@ pub async fn federation_runtime_template( ) -> String { let federation_global = format!( "{}.federation", - runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE) + runtime_require_scope_name(runtime_template) ); let condition_map = compilation diff --git a/crates/rspack_plugin_mf/src/container/remote_runtime_module.rs b/crates/rspack_plugin_mf/src/container/remote_runtime_module.rs index ead539fa8c56..491e00b424aa 100644 --- a/crates/rspack_plugin_mf/src/container/remote_runtime_module.rs +++ b/crates/rspack_plugin_mf/src/container/remote_runtime_module.rs @@ -11,7 +11,10 @@ use rustc_hash::FxHashMap; use serde::Serialize; use super::remote_module::RemoteModule; -use crate::{ShareScope, utils::json_stringify}; +use crate::{ + ShareScope, + utils::{json_stringify, runtime_require_scope_name}, +}; static REMOTES_LOADING_TEMPLATE: &str = include_str!("./remotesLoading.ejs"); static REMOTES_LOADING_RUNTIME_REQUIREMENTS: LazyLock = @@ -124,7 +127,7 @@ impl RuntimeModule for RemoteRuntimeModule { {require_name}.remotesLoadingData = {{ chunkMapping: {chunk_mapping}, moduleIdToRemoteDataMapping: {id_to_remote_data_mapping} }}; {remotes_loading_impl} "#, - require_name = runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE), + require_name = runtime_require_scope_name(runtime_template), chunk_mapping = json_stringify(&chunk_to_remotes_mapping), id_to_remote_data_mapping = json_stringify(&id_to_remote_data_mapping), remotes_loading_impl = remotes_loading_impl, diff --git a/crates/rspack_plugin_mf/src/container/remotesLoading.ejs b/crates/rspack_plugin_mf/src/container/remotesLoading.ejs index ca9479082253..51a4351774d5 100644 --- a/crates/rspack_plugin_mf/src/container/remotesLoading.ejs +++ b/crates/rspack_plugin_mf/src/container/remotesLoading.ejs @@ -1,6 +1,6 @@ <%- ENSURE_CHUNK_HANDLERS %>.remotes = function (chunkId, promises) { - var chunkMapping = <%- REQUIRE %>.remotesLoadingData.chunkMapping; - var moduleIdToRemoteDataMapping = <%- REQUIRE %>.remotesLoadingData.moduleIdToRemoteDataMapping; + var chunkMapping = <%- REQUIRE_SCOPE %>.remotesLoadingData.chunkMapping; + var moduleIdToRemoteDataMapping = <%- REQUIRE_SCOPE %>.remotesLoadingData.moduleIdToRemoteDataMapping; if (<%- HAS_OWN_PROPERTY %>(chunkMapping, chunkId)) { chunkMapping[chunkId].forEach(function (id) { var getScope = <%- CURRENT_REMOTE_GET_SCOPE %>; diff --git a/crates/rspack_plugin_mf/src/lib.rs b/crates/rspack_plugin_mf/src/lib.rs index 1d6b1b30c89e..7b179239e69e 100644 --- a/crates/rspack_plugin_mf/src/lib.rs +++ b/crates/rspack_plugin_mf/src/lib.rs @@ -69,9 +69,32 @@ pub use sharing::{ mod utils { use std::fmt; + use rspack_core::{ + Compilation, ModuleCodeTemplate, RuntimeCodeTemplate, RuntimeGlobals, RuntimeVariable, + runtime_mode::RuntimeMode, + }; use serde::Serialize; pub fn json_stringify(v: &T) -> String { simd_json::to_string(v).unwrap_or_else(|e| panic!("{e}: {v:?} should able to json stringify")) } + + pub fn runtime_require_scope_name(runtime_template: &RuntimeCodeTemplate<'_>) -> String { + if runtime_template.uses_runtime_context() { + runtime_template.render_runtime_variable(&RuntimeVariable::Context) + } else { + runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE) + } + } + + pub fn module_require_scope_name( + compilation: &Compilation, + runtime_template: &mut ModuleCodeTemplate, + ) -> String { + if compilation.options.experiments.runtime_mode == RuntimeMode::Rspack { + runtime_template.render_runtime_variable(&RuntimeVariable::Context) + } else { + runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE) + } + } } diff --git a/crates/rspack_plugin_mf/src/sharing/consume_shared_runtime_module.rs b/crates/rspack_plugin_mf/src/sharing/consume_shared_runtime_module.rs index 9a443efbf75d..6efd2cdba57e 100644 --- a/crates/rspack_plugin_mf/src/sharing/consume_shared_runtime_module.rs +++ b/crates/rspack_plugin_mf/src/sharing/consume_shared_runtime_module.rs @@ -10,7 +10,10 @@ use rspack_util::json_stringify_str; use rustc_hash::FxHashMap; use super::consume_shared_plugin::ConsumeVersion; -use crate::{ShareScope, utils::json_stringify}; +use crate::{ + ShareScope, + utils::{json_stringify, runtime_require_scope_name}, +}; static CONSUMES_COMMON_TEMPLATE: &str = include_str!("./consumesCommon.ejs"); static CONSUMES_INITIAL_TEMPLATE: &str = include_str!("./consumesInitial.ejs"); @@ -199,7 +202,7 @@ impl RuntimeModule for ConsumeSharedRuntimeModule { } else { json_stringify(&initial_consumes) }; - let require_name = runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE); + let require_name = runtime_require_scope_name(runtime_template); let mut source = format!( r#" {require_name}.consumesLoadingData = {{ chunkMapping: {chunk_mapping}, moduleIdToConsumeDataMapping: {module_id_to_consume_data_mapping}, initialConsumes: {initial_consumes_json} }}; diff --git a/crates/rspack_plugin_mf/src/sharing/consumesInitial.ejs b/crates/rspack_plugin_mf/src/sharing/consumesInitial.ejs index b572ef13760d..06783c5a0f1d 100644 --- a/crates/rspack_plugin_mf/src/sharing/consumesInitial.ejs +++ b/crates/rspack_plugin_mf/src/sharing/consumesInitial.ejs @@ -1,9 +1,9 @@ -<%- REQUIRE %>.consumesLoadingData.initialConsumes.forEach(function(id) { +<%- REQUIRE_SCOPE %>.consumesLoadingData.initialConsumes.forEach(function(id) { <%- MODULE_FACTORIES %>[id] = function(module) { // Handle case when module is used sync installedModules[id] = 0; delete <%- MODULE_CACHE %>[id]; - var factory = resolveHandler(<%- REQUIRE %>.consumesLoadingData.moduleIdToConsumeDataMapping[id])(); + var factory = resolveHandler(<%- REQUIRE_SCOPE %>.consumesLoadingData.moduleIdToConsumeDataMapping[id])(); if (typeof factory !== "function") throw new Error( "Shared module is not available for eager consumption: " + id diff --git a/crates/rspack_plugin_mf/src/sharing/consumesLoading.ejs b/crates/rspack_plugin_mf/src/sharing/consumesLoading.ejs index 7b83546eef6b..14f9e379b6df 100644 --- a/crates/rspack_plugin_mf/src/sharing/consumesLoading.ejs +++ b/crates/rspack_plugin_mf/src/sharing/consumesLoading.ejs @@ -1,6 +1,6 @@ <%- ENSURE_CHUNK_HANDLERS %>.consumes = function(chunkId, promises) { - var moduleIdToConsumeDataMapping = <%- REQUIRE %>.consumesLoadingData.moduleIdToConsumeDataMapping - var chunkMapping = <%- REQUIRE %>.consumesLoadingData.chunkMapping; + var moduleIdToConsumeDataMapping = <%- REQUIRE_SCOPE %>.consumesLoadingData.moduleIdToConsumeDataMapping + var chunkMapping = <%- REQUIRE_SCOPE %>.consumesLoadingData.chunkMapping; if(<%- HAS_OWN_PROPERTY %>(chunkMapping, chunkId)) { chunkMapping[chunkId].forEach(function(id) { if(<%- HAS_OWN_PROPERTY %>(installedModules, id)) return promises.push(installedModules[id]); diff --git a/crates/rspack_plugin_mf/src/sharing/initializeSharing.ejs b/crates/rspack_plugin_mf/src/sharing/initializeSharing.ejs index cc42c2b4a191..4ae62d1eb611 100644 --- a/crates/rspack_plugin_mf/src/sharing/initializeSharing.ejs +++ b/crates/rspack_plugin_mf/src/sharing/initializeSharing.ejs @@ -17,7 +17,7 @@ var initTokens = {}; var warn = function (msg) { if (typeof console !== "undefined" && console.warn) console.warn(msg); }; - var uniqueName = <%- REQUIRE %>.initializeSharingData.uniqueName; + var uniqueName = <%- REQUIRE_SCOPE %>.initializeSharingData.uniqueName; var register = function (name, version, factory, eager) { var versions = (scope[name] = scope[name] || {}); var activeVersion = versions[version]; @@ -53,7 +53,7 @@ var initTokens = {}; } }; var promises = []; - var scopeToSharingDataMapping = <%- REQUIRE %>.initializeSharingData.scopeToSharingDataMapping; + var scopeToSharingDataMapping = <%- REQUIRE_SCOPE %>.initializeSharingData.scopeToSharingDataMapping; if (scopeToSharingDataMapping[name]) { scopeToSharingDataMapping[name].forEach(function (stage) { if (typeof stage === "object") register(stage.name, stage.version, stage.factory, stage.eager); diff --git a/crates/rspack_plugin_mf/src/sharing/share_runtime_module.rs b/crates/rspack_plugin_mf/src/sharing/share_runtime_module.rs index 93fa817b7421..58948a89ba9d 100644 --- a/crates/rspack_plugin_mf/src/sharing/share_runtime_module.rs +++ b/crates/rspack_plugin_mf/src/sharing/share_runtime_module.rs @@ -13,7 +13,10 @@ use rspack_util::{ use rustc_hash::FxHashMap; use super::provide_shared_plugin::ProvideVersion; -use crate::{ConsumeVersion, ShareScope, utils::json_stringify}; +use crate::{ + ConsumeVersion, ShareScope, + utils::{json_stringify, runtime_require_scope_name}, +}; static INITIALIZE_SHARING_TEMPLATE: &str = include_str!("./initializeSharing.ejs"); static INITIALIZE_SHARING_RUNTIME_REQUIREMENTS: LazyLock = @@ -143,7 +146,7 @@ impl RuntimeModule for ShareRuntimeModule { {require_name}.initializeSharingData = {{ scopeToSharingDataMapping: {{ {scope_to_data_init} }}, uniqueName: {unique_name} }}; {initialize_sharing_impl} "#, - require_name = runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE), + require_name = runtime_require_scope_name(runtime_template), share_scope_map = runtime_template.render_runtime_globals(&RuntimeGlobals::SHARE_SCOPE_MAP), scope_to_data_init = scope_to_data_init, unique_name = json_stringify_str(&compilation.options.output.unique_name), diff --git a/crates/rspack_plugin_mf/src/sharing/shared_container_runtime_module.rs b/crates/rspack_plugin_mf/src/sharing/shared_container_runtime_module.rs index a47ca9a9181c..402ad89e4d1a 100644 --- a/crates/rspack_plugin_mf/src/sharing/shared_container_runtime_module.rs +++ b/crates/rspack_plugin_mf/src/sharing/shared_container_runtime_module.rs @@ -1,8 +1,10 @@ use rspack_core::{ - RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeModuleStage, RuntimeTemplate, + RuntimeModule, RuntimeModuleGenerateContext, RuntimeModuleStage, RuntimeTemplate, impl_runtime_module, }; +use crate::utils::runtime_require_scope_name; + #[impl_runtime_module] #[derive(Debug)] pub struct ShareContainerRuntimeModule {} @@ -21,9 +23,7 @@ impl RuntimeModule for ShareContainerRuntimeModule { ) -> rspack_error::Result { Ok(format!( "{}.federation = {{ instance: undefined,bundlerRuntime: undefined }};", - context - .runtime_template - .render_runtime_globals(&RuntimeGlobals::REQUIRE) + runtime_require_scope_name(context.runtime_template) )) } diff --git a/crates/rspack_plugin_mf/src/sharing/shared_used_exports_optimizer_runtime_module.rs b/crates/rspack_plugin_mf/src/sharing/shared_used_exports_optimizer_runtime_module.rs index 618bfb95de41..1af7161d9e2a 100644 --- a/crates/rspack_plugin_mf/src/sharing/shared_used_exports_optimizer_runtime_module.rs +++ b/crates/rspack_plugin_mf/src/sharing/shared_used_exports_optimizer_runtime_module.rs @@ -2,12 +2,14 @@ use std::{collections::BTreeMap, sync::Arc}; use async_trait::async_trait; use rspack_core::{ - RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeModuleStage, RuntimeTemplate, + RuntimeModule, RuntimeModuleGenerateContext, RuntimeModuleStage, RuntimeTemplate, impl_runtime_module, }; use rspack_error::{Result, error}; use rustc_hash::{FxHashMap, FxHashSet}; +use crate::utils::runtime_require_scope_name; + #[impl_runtime_module] #[derive(Debug)] pub struct SharedUsedExportsOptimizerRuntimeModule { @@ -40,9 +42,7 @@ impl RuntimeModule for SharedUsedExportsOptimizerRuntimeModule { } let federation_global = format!( "{}.federation", - context - .runtime_template - .render_runtime_globals(&RuntimeGlobals::REQUIRE) + runtime_require_scope_name(context.runtime_template) ); // Convert set to vec for JSON serialization stability let stable_map: BTreeMap> = self diff --git a/crates/rspack_plugin_module_info_header/src/lib.rs b/crates/rspack_plugin_module_info_header/src/lib.rs index d19e24c87469..2bb24e7acfa1 100644 --- a/crates/rspack_plugin_module_info_header/src/lib.rs +++ b/crates/rspack_plugin_module_info_header/src/lib.rs @@ -2,10 +2,10 @@ use std::{borrow::Cow, hash::Hash}; use rspack_cacheable::with::AsVecConverter; use rspack_core::{ - BuildMetaExportsType, ChunkGraph, ChunkInitFragments, ChunkUkey, Compilation, CompilationParams, - CompilerCompilation, ExportInfo, ExportProvided, ExportsInfoArtifact, ExportsInfoData, - GetTargetResult, Module, ModuleGraph, ModuleIdentifier, OptimizationBailoutItem, Plugin, - RuntimeCodeTemplate, UsageState, get_target, + BuildMetaExportsType, ChunkCodeTemplate, ChunkGraph, ChunkInitFragments, ChunkUkey, Compilation, + CompilationParams, CompilerCompilation, ExportInfo, ExportProvided, ExportsInfoArtifact, + ExportsInfoData, GetTargetResult, Module, ModuleGraph, ModuleIdentifier, OptimizationBailoutItem, + Plugin, UsageState, get_target, rspack_sources::{ConcatSource, RawStringSource, SourceExt}, to_comment_with_nl, }; @@ -238,7 +238,7 @@ async fn render_js_module_package( module: &dyn Module, render_source: &mut RenderSource, _init_fragments: &mut ChunkInitFragments, - runtime_template: &RuntimeCodeTemplate<'_>, + runtime_template: &ChunkCodeTemplate, ) -> Result<()> { let mut new_source: ConcatSource = Default::default(); diff --git a/crates/rspack_plugin_rsc/src/manifest_runtime_module.rs b/crates/rspack_plugin_rsc/src/manifest_runtime_module.rs index d92a4fb6f66f..06714f407d86 100644 --- a/crates/rspack_plugin_rsc/src/manifest_runtime_module.rs +++ b/crates/rspack_plugin_rsc/src/manifest_runtime_module.rs @@ -85,9 +85,9 @@ impl RuntimeModule for RscManifestRuntimeModule { Ok(formatdoc! { r#" - {require_name}.rscM = JSON.parse({rsc_manifest_json}); + {rsc_manifest} = JSON.parse({rsc_manifest_json}); "#, - require_name = runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE), + rsc_manifest = runtime_template.render_runtime_globals(&RuntimeGlobals::RSC_MANIFEST), rsc_manifest_json = to_json_string_literal(&rsc_manifest).to_rspack_result()?, }) } diff --git a/crates/rspack_plugin_rslib/src/plugin.rs b/crates/rspack_plugin_rslib/src/plugin.rs index fd8a934eaaef..4c6bf178601d 100644 --- a/crates/rspack_plugin_rslib/src/plugin.rs +++ b/crates/rspack_plugin_rslib/src/plugin.rs @@ -6,10 +6,10 @@ use std::{ use cow_utils::CowUtils; use pathdiff::diff_paths; use rspack_core::{ - AssetEmittedInfo, AssetInfo, BuildModuleGraphArtifact, ChunkUkey, Compilation, CompilationAsset, - CompilationOptimizeDependencies, CompilationParams, CompilationProcessAssets, + AssetEmittedInfo, AssetInfo, BuildModuleGraphArtifact, ChunkCodeTemplate, ChunkUkey, Compilation, + CompilationAsset, CompilationOptimizeDependencies, CompilationParams, CompilationProcessAssets, CompilerAssetEmitted, CompilerCompilation, DependencyType, ExportsInfoArtifact, ModuleType, - NormalModuleFactoryParser, ParserAndGenerator, ParserOptions, Plugin, RuntimeCodeTemplate, + NormalModuleFactoryParser, ParserAndGenerator, ParserOptions, Plugin, SideEffectsOptimizeArtifact, get_module_directives, get_module_hashbang, rspack_sources::{ConcatSource, RawStringSource, Source, SourceExt}, }; @@ -249,7 +249,7 @@ async fn render( compilation: &Compilation, chunk_ukey: &ChunkUkey, render_source: &mut RenderSource, - _runtime_template: &RuntimeCodeTemplate<'_>, + _runtime_template: &ChunkCodeTemplate, ) -> Result<()> { // NOTE: This function handles hashbang and directives for non new ESM library formats. // Similar logic exists in rspack_plugin_esm_library/src/render.rs for ESM format, diff --git a/crates/rspack_plugin_rstest/src/plugin.rs b/crates/rspack_plugin_rstest/src/plugin.rs index 78a8e5654f3a..4104a5b6fdec 100644 --- a/crates/rspack_plugin_rstest/src/plugin.rs +++ b/crates/rspack_plugin_rstest/src/plugin.rs @@ -91,7 +91,12 @@ async fn runtime_module( ); } "webpack/runtime/require_chunk_loading" | "webpack/runtime/module_chunk_loading" => { - let source = runtime_module.generate_with_custom(compilation).await?; + let runtime_template = compilation.runtime_template.create_runtime_code_template(); + let context = rspack_core::RuntimeModuleGenerateContext { + compilation, + runtime_template: &runtime_template, + }; + let source = runtime_module.generate_with_custom(&context).await?; runtime_module.set_custom_source(RstestPlugin::add_rstest_mock_chunk_loading_guard(source)); } _ => {} diff --git a/crates/rspack_plugin_runtime/src/array_push_callback_chunk_format.rs b/crates/rspack_plugin_runtime/src/array_push_callback_chunk_format.rs index db3462677dd7..3f8b4c767f8b 100644 --- a/crates/rspack_plugin_runtime/src/array_push_callback_chunk_format.rs +++ b/crates/rspack_plugin_runtime/src/array_push_callback_chunk_format.rs @@ -1,9 +1,9 @@ use std::hash::Hash; use rspack_core::{ - ChunkGraph, ChunkKind, ChunkUkey, Compilation, CompilationAdditionalChunkRuntimeRequirements, - CompilationParams, CompilerCompilation, Plugin, RuntimeCodeTemplate, RuntimeGlobals, - RuntimeModule, RuntimeVariable, + ChunkCodeTemplate, ChunkGraph, ChunkKind, ChunkUkey, Compilation, + CompilationAdditionalChunkRuntimeRequirements, CompilationParams, CompilerCompilation, Plugin, + RuntimeGlobals, RuntimeModule, RuntimeVariable, rspack_sources::{ConcatSource, RawStringSource, SourceExt}, }; use rspack_error::Result; @@ -107,7 +107,7 @@ async fn render_chunk( compilation: &Compilation, chunk_ukey: &ChunkUkey, render_source: &mut RenderSource, - runtime_template: &RuntimeCodeTemplate<'_>, + runtime_template: &ChunkCodeTemplate, ) -> Result<()> { let hooks = JsPlugin::get_compilation_hooks(compilation.id()); let chunk = compilation @@ -149,13 +149,14 @@ async fn render_chunk( source.add(render_source.source.clone()); let has_entry = chunk.has_entry_module(&compilation.build_chunk_graph_artifact.chunk_graph); if has_entry || has_runtime_modules { + let runtime_template = compilation.runtime_template.create_chunk_code_template(); source.add(RawStringSource::from_static(",")); source.add(RawStringSource::from(format!( "function({}) {{\n", - runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE) + runtime_template.render_runtime_argument() ))); if has_runtime_modules { - source.add(render_runtime_modules(compilation, chunk_ukey, runtime_template).await?); + source.add(render_runtime_modules(compilation, chunk_ukey, &runtime_template).await?); } if has_entry { let entries = compilation @@ -166,7 +167,7 @@ async fn render_chunk( ChunkGraph::get_tree_runtime_requirements(compilation, chunk_ukey); let passive = !runtime_requirements.contains(RuntimeGlobals::STARTUP_ENTRYPOINT); let start_up_source = - generate_entry_startup(compilation, chunk_ukey, entries, passive, runtime_template); + generate_entry_startup(compilation, chunk_ukey, entries, passive, &runtime_template); let last_entry_module = entries .keys() .next_back() @@ -183,7 +184,7 @@ async fn render_chunk( chunk_ukey, last_entry_module, &mut render_source, - runtime_template, + &runtime_template, ) .await?; source.add(render_source.source); diff --git a/crates/rspack_plugin_runtime/src/common_js_chunk_format.rs b/crates/rspack_plugin_runtime/src/common_js_chunk_format.rs index 549bcaed6ddd..751f1819f516 100644 --- a/crates/rspack_plugin_runtime/src/common_js_chunk_format.rs +++ b/crates/rspack_plugin_runtime/src/common_js_chunk_format.rs @@ -1,9 +1,9 @@ use std::hash::Hash; use rspack_core::{ - ChunkUkey, Compilation, CompilationAdditionalChunkRuntimeRequirements, - CompilationDependentFullHash, CompilationParams, CompilerCompilation, Plugin, - RuntimeCodeTemplate, RuntimeGlobals, RuntimeModule, + ChunkCodeTemplate, ChunkUkey, Compilation, CompilationAdditionalChunkRuntimeRequirements, + CompilationDependentFullHash, CompilationParams, CompilerCompilation, Plugin, RuntimeGlobals, + RuntimeModule, rspack_sources::{ConcatSource, RawStringSource, SourceExt}, }; use rspack_error::Result; @@ -125,7 +125,7 @@ async fn render_chunk( compilation: &Compilation, chunk_ukey: &ChunkUkey, render_source: &mut RenderSource, - runtime_template: &RuntimeCodeTemplate<'_>, + runtime_template: &ChunkCodeTemplate, ) -> Result<()> { let hooks = JsPlugin::get_compilation_hooks(compilation.id()); let chunk = compilation @@ -152,18 +152,19 @@ async fn render_chunk( } if chunk.has_entry_module(&compilation.build_chunk_graph_artifact.chunk_graph) { + let runtime_template = compilation.runtime_template.create_chunk_code_template(); let runtime_chunk_output_name = get_runtime_chunk_output_name(compilation, chunk_ukey).await?; + let runtime_require_path = json_stringify_str(&get_relative_path( + base_chunk_output_name + .trim_start_matches("/") + .trim_start_matches("\\"), + &runtime_chunk_output_name, + )); + let runtime_scope = runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE_SCOPE); sources.add(RawStringSource::from(format!( r#"// load runtime -var {} = require({}); -"#, - runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE), - json_stringify_str(&get_relative_path( - base_chunk_output_name - .trim_start_matches("/") - .trim_start_matches("\\"), - &runtime_chunk_output_name - )) +var {runtime_scope} = require({runtime_require_path}); +"# ))); sources.add(RawStringSource::from(format!( "{}(exports)\n", @@ -175,7 +176,7 @@ var {} = require({}); .chunk_graph .get_chunk_entry_modules_with_chunk_group_iterable(chunk_ukey); let start_up_source = - generate_entry_startup(compilation, chunk_ukey, entries, false, runtime_template); + generate_entry_startup(compilation, chunk_ukey, entries, false, &runtime_template); let last_entry_module = entries .keys() .next_back() @@ -192,7 +193,7 @@ var {} = require({}); chunk_ukey, last_entry_module, &mut startup_render_source, - runtime_template, + &runtime_template, ) .await?; sources.add(startup_render_source.source); diff --git a/crates/rspack_plugin_runtime/src/common_js_chunk_loading.rs b/crates/rspack_plugin_runtime/src/common_js_chunk_loading.rs index 022577ccb32b..fa7b38ddfae8 100644 --- a/crates/rspack_plugin_runtime/src/common_js_chunk_loading.rs +++ b/crates/rspack_plugin_runtime/src/common_js_chunk_loading.rs @@ -113,6 +113,11 @@ async fn runtime_requirements_in_tree( if all_runtime_requirements.contains(RuntimeGlobals::HMR_DOWNLOAD_UPDATE_HANDLERS) { runtime_requirements_mut .extend(ReadFileChunkLoadingRuntimeModule::get_runtime_requirements_with_hmr()); + if compilation.options.experiments.runtime_mode + == rspack_core::runtime_mode::RuntimeMode::Rspack + { + runtime_requirements_mut.insert(RuntimeGlobals::ENSURE_CHUNK_HANDLERS); + } } if all_runtime_requirements.contains(RuntimeGlobals::HMR_DOWNLOAD_MANIFEST) { runtime_requirements_mut @@ -141,6 +146,11 @@ async fn runtime_requirements_in_tree( if all_runtime_requirements.contains(RuntimeGlobals::HMR_DOWNLOAD_UPDATE_HANDLERS) { runtime_requirements_mut .extend(RequireChunkLoadingRuntimeModule::get_runtime_requirements_with_hmr()); + if compilation.options.experiments.runtime_mode + == rspack_core::runtime_mode::RuntimeMode::Rspack + { + runtime_requirements_mut.insert(RuntimeGlobals::ENSURE_CHUNK_HANDLERS); + } } if all_runtime_requirements.contains(RuntimeGlobals::HMR_DOWNLOAD_MANIFEST) { runtime_requirements_mut diff --git a/crates/rspack_plugin_runtime/src/helpers.rs b/crates/rspack_plugin_runtime/src/helpers.rs index 4a8d47d8a8d6..2a592d59f6a5 100644 --- a/crates/rspack_plugin_runtime/src/helpers.rs +++ b/crates/rspack_plugin_runtime/src/helpers.rs @@ -4,8 +4,8 @@ use itertools::Itertools; use regex::Regex; use rspack_collections::IdentifierLinkedMap; use rspack_core::{ - Chunk, ChunkGraph, ChunkGroupByUkey, ChunkGroupUkey, ChunkLoading, ChunkLoadingType, ChunkUkey, - Compilation, PathData, RuntimeCodeTemplate, RuntimeGlobals, RuntimeVariable, SourceType, + Chunk, ChunkCodeTemplate, ChunkGraph, ChunkGroupByUkey, ChunkGroupUkey, ChunkLoading, + ChunkLoadingType, ChunkUkey, Compilation, PathData, RuntimeGlobals, RuntimeVariable, SourceType, chunk_graph_chunk::ChunkIdSet, get_js_chunk_filename_template, rspack_sources::{BoxSource, RawStringSource, SourceExt}, @@ -224,7 +224,7 @@ pub fn generate_entry_startup( chunk: &ChunkUkey, entries: &IdentifierLinkedMap, passive: bool, - runtime_template: &RuntimeCodeTemplate<'_>, + runtime_template: &ChunkCodeTemplate, ) -> BoxSource { let mut module_id_exprs = vec![]; let mut chunks_ids = ChunkIdSet::default(); diff --git a/crates/rspack_plugin_runtime/src/import_scripts_chunk_loading.rs b/crates/rspack_plugin_runtime/src/import_scripts_chunk_loading.rs index b0405c5d5405..ada5da45ed15 100644 --- a/crates/rspack_plugin_runtime/src/import_scripts_chunk_loading.rs +++ b/crates/rspack_plugin_runtime/src/import_scripts_chunk_loading.rs @@ -93,6 +93,11 @@ async fn runtime_requirements_in_tree( if all_runtime_requirements.contains(RuntimeGlobals::HMR_DOWNLOAD_UPDATE_HANDLERS) { runtime_requirements_mut .extend(ImportScriptsChunkLoadingRuntimeModule::get_runtime_requirements_with_hmr()); + if compilation.options.experiments.runtime_mode + == rspack_core::runtime_mode::RuntimeMode::Rspack + { + runtime_requirements_mut.insert(RuntimeGlobals::ENSURE_CHUNK_HANDLERS); + } } if all_runtime_requirements.contains(RuntimeGlobals::HMR_DOWNLOAD_MANIFEST) { diff --git a/crates/rspack_plugin_runtime/src/jsonp_chunk_loading.rs b/crates/rspack_plugin_runtime/src/jsonp_chunk_loading.rs index 6c02c7928488..a1653718c62d 100644 --- a/crates/rspack_plugin_runtime/src/jsonp_chunk_loading.rs +++ b/crates/rspack_plugin_runtime/src/jsonp_chunk_loading.rs @@ -84,6 +84,11 @@ async fn runtime_requirements_in_tree( if all_runtime_requirements.contains(RuntimeGlobals::HMR_DOWNLOAD_UPDATE_HANDLERS) { runtime_requirements_mut .extend(JsonpChunkLoadingRuntimeModule::get_runtime_requirements_with_hmr()); + if compilation.options.experiments.runtime_mode + == rspack_core::runtime_mode::RuntimeMode::Rspack + { + runtime_requirements_mut.insert(RuntimeGlobals::ENSURE_CHUNK_HANDLERS); + } } if all_runtime_requirements.contains(RuntimeGlobals::HMR_DOWNLOAD_MANIFEST) { runtime_requirements_mut diff --git a/crates/rspack_plugin_runtime/src/module_chunk_format.rs b/crates/rspack_plugin_runtime/src/module_chunk_format.rs index f31ca095a57a..574b871b132a 100644 --- a/crates/rspack_plugin_runtime/src/module_chunk_format.rs +++ b/crates/rspack_plugin_runtime/src/module_chunk_format.rs @@ -1,9 +1,10 @@ use std::hash::Hash; use rspack_core::{ - ChunkGraph, ChunkKind, ChunkUkey, Compilation, CompilationAdditionalChunkRuntimeRequirements, - CompilationDependentFullHash, CompilationParams, CompilerCompilation, ModuleIdentifier, Plugin, - RuntimeCodeTemplate, RuntimeGlobals, RuntimeModule, RuntimeVariable, SourceType, + ChunkCodeTemplate, ChunkGraph, ChunkKind, ChunkUkey, Compilation, + CompilationAdditionalChunkRuntimeRequirements, CompilationDependentFullHash, CompilationParams, + CompilerCompilation, ModuleIdentifier, Plugin, RuntimeGlobals, RuntimeModule, RuntimeVariable, + SourceType, rspack_sources::{ConcatSource, RawStringSource, Source, SourceExt}, }; use rspack_error::Result; @@ -66,6 +67,7 @@ async fn additional_chunk_runtime_requirements( .get_number_of_entry_modules(chunk_ukey) > 0 { + runtime_requirements.insert(RuntimeGlobals::REQUIRE); runtime_requirements.insert(RuntimeGlobals::EXTERNAL_INSTALL_CHUNK); } @@ -135,7 +137,7 @@ async fn render_chunk( compilation: &Compilation, chunk_ukey: &ChunkUkey, render_source: &mut RenderSource, - runtime_template: &RuntimeCodeTemplate<'_>, + runtime_template: &ChunkCodeTemplate, ) -> Result<()> { let hooks = JsPlugin::get_compilation_hooks(compilation.id()); let chunk = compilation @@ -143,6 +145,7 @@ async fn render_chunk( .chunk_by_ukey .expect_get(chunk_ukey); let base_chunk_output_name = get_chunk_output_name(chunk, compilation).await?; + let chunk_runtime_template = compilation.runtime_template.create_chunk_code_template(); let chunk_id_expr = rspack_util::json_stringify(chunk.expect_id()); @@ -181,7 +184,7 @@ async fn render_chunk( let runtime_chunk_output_name = get_runtime_chunk_output_name(compilation, chunk_ukey).await?; sources.add(RawStringSource::from(format!( "import {{ {} }} from '{}';\n", - runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE), + chunk_runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE_SCOPE), get_relative_path( base_chunk_output_name .trim_start_matches("/") @@ -202,9 +205,9 @@ async fn render_chunk( startup_source.push(format!( "var {} = function(moduleId) {{ return {}({} = moduleId); }}", - runtime_template.render_runtime_variable(&RuntimeVariable::StartupExec), - runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE), - runtime_template.render_runtime_globals(&RuntimeGlobals::ENTRY_MODULE_ID) + chunk_runtime_template.render_runtime_variable(&RuntimeVariable::StartupExec), + chunk_runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE), + chunk_runtime_template.render_runtime_globals(&RuntimeGlobals::ENTRY_MODULE_ID) )); let module_graph = compilation.get_module_graph(); @@ -260,7 +263,7 @@ async fn render_chunk( let index_str2 = index_buffer2.format(index); startup_source.push(format!( "{}(__rspack_chunk_{});", - runtime_template.render_runtime_globals(&RuntimeGlobals::EXTERNAL_INSTALL_CHUNK), + chunk_runtime_template.render_runtime_globals(&RuntimeGlobals::EXTERNAL_INSTALL_CHUNK), index_str2 )); } @@ -280,13 +283,14 @@ async fn render_chunk( } else { String::new() }, - runtime_template.render_runtime_variable(&RuntimeVariable::StartupExec), + chunk_runtime_template.render_runtime_variable(&RuntimeVariable::StartupExec), )); } } if use_startup_entrypoint && !entry_module_ids.is_empty() { - let startup_exec = runtime_template.render_runtime_variable(&RuntimeVariable::StartupExec); + let startup_exec = + chunk_runtime_template.render_runtime_variable(&RuntimeVariable::StartupExec); let module_ids_code = entry_module_ids .iter() .map(|module_id_expr| format!("{startup_exec}({module_id_expr})")) @@ -295,7 +299,7 @@ async fn render_chunk( startup_source.push(format!( "var {} = {}(0, [], function() {{\n return {};\n }});", runtime_template.render_runtime_variable(&RuntimeVariable::Exports), - runtime_template.render_runtime_globals(&RuntimeGlobals::STARTUP_ENTRYPOINT), + chunk_runtime_template.render_runtime_globals(&RuntimeGlobals::STARTUP_ENTRYPOINT), module_ids_code )); } @@ -316,7 +320,7 @@ async fn render_chunk( chunk_ukey, last_entry_module, &mut render_source, - runtime_template, + &chunk_runtime_template, ) .await?; sources.add(render_source.source); @@ -335,7 +339,7 @@ async fn render_startup( chunk_ukey: &ChunkUkey, _module: &ModuleIdentifier, render_source: &mut RenderSource, - runtime_template: &RuntimeCodeTemplate<'_>, + runtime_template: &ChunkCodeTemplate, ) -> Result<()> { let chunk = compilation .build_chunk_graph_artifact diff --git a/crates/rspack_plugin_runtime/src/module_chunk_loading.rs b/crates/rspack_plugin_runtime/src/module_chunk_loading.rs index 915674230c89..ce9390e265c8 100644 --- a/crates/rspack_plugin_runtime/src/module_chunk_loading.rs +++ b/crates/rspack_plugin_runtime/src/module_chunk_loading.rs @@ -134,6 +134,11 @@ async fn runtime_requirements_in_tree( if all_runtime_requirements.contains(RuntimeGlobals::HMR_DOWNLOAD_UPDATE_HANDLERS) { runtime_requirements_mut .extend(ModuleChunkLoadingRuntimeModule::get_runtime_requirements_with_hmr()); + if compilation.options.experiments.runtime_mode + == rspack_core::runtime_mode::RuntimeMode::Rspack + { + runtime_requirements_mut.insert(RuntimeGlobals::ENSURE_CHUNK_HANDLERS); + } } if all_runtime_requirements.contains(RuntimeGlobals::HMR_DOWNLOAD_MANIFEST) { runtime_requirements_mut diff --git a/crates/rspack_plugin_runtime/src/runtime_module/async_module.rs b/crates/rspack_plugin_runtime/src/runtime_module/async_module.rs index b76d03fb9b35..b2b1a55bac2d 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/async_module.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/async_module.rs @@ -1,8 +1,16 @@ +use std::sync::LazyLock; + use rspack_core::{ - RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, RuntimeVariable, - impl_runtime_module, + Compilation, RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, + RuntimeVariable, impl_runtime_module, }; +use crate::extract_runtime_globals_from_ejs; + +static ASYNC_MODULE_TEMPLATE: &str = include_str!("runtime/async_module.ejs"); +static ASYNC_MODULE_RUNTIME_REQUIREMENTS: LazyLock = + LazyLock::new(|| extract_runtime_globals_from_ejs(ASYNC_MODULE_TEMPLATE)); + #[impl_runtime_module] #[derive(Debug)] pub struct AsyncRuntimeModule {} @@ -29,9 +37,10 @@ impl RuntimeModule for AsyncRuntimeModule { } fn template(&self) -> Vec<(String, String)> { - vec![( - self.id.to_string(), - include_str!("runtime/async_module.ejs").to_string(), - )] + vec![(self.id.to_string(), ASYNC_MODULE_TEMPLATE.to_string())] + } + + fn additional_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + *ASYNC_MODULE_RUNTIME_REQUIREMENTS } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/create_fake_namespace_object.rs b/crates/rspack_plugin_runtime/src/runtime_module/create_fake_namespace_object.rs index 9516b246c4ad..72698b55be5d 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/create_fake_namespace_object.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/create_fake_namespace_object.rs @@ -2,7 +2,7 @@ use std::sync::LazyLock; use rspack_core::{ Compilation, RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, - impl_runtime_module, + impl_runtime_module, runtime_mode::RuntimeMode, }; use crate::extract_runtime_globals_from_ejs; @@ -35,7 +35,18 @@ impl RuntimeModule for CreateFakeNamespaceObjectRuntimeModule { &self, context: &RuntimeModuleGenerateContext<'_>, ) -> rspack_error::Result { - let source = context.runtime_template.render(&self.id, None)?; + let params = Some( + if context.compilation.options.experiments.runtime_mode == RuntimeMode::Rspack { + serde_json::json!({ + "REQUIRE": "(typeof this === \"function\" ? this : this.r)" + }) + } else { + serde_json::json!({ + "REQUIRE": "this" + }) + }, + ); + let source = context.runtime_template.render(&self.id, params)?; Ok(source) } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/ensure_chunk.rs b/crates/rspack_plugin_runtime/src/runtime_module/ensure_chunk.rs index 3bf6f91dffcf..b4b4e7b5bb36 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/ensure_chunk.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/ensure_chunk.rs @@ -75,10 +75,10 @@ impl RuntimeModule for EnsureChunkRuntimeModule { } fn additional_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + let mut requirements = RuntimeGlobals::ENSURE_CHUNK; if self.has_async_chunks { - RuntimeGlobals::ENSURE_CHUNK_HANDLERS - } else { - RuntimeGlobals::default() + requirements.insert(RuntimeGlobals::ENSURE_CHUNK_HANDLERS); } + requirements } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/export_require.rs b/crates/rspack_plugin_runtime/src/runtime_module/export_require.rs index dbeaea20883c..a4e45f0d420e 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/export_require.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/export_require.rs @@ -20,13 +20,13 @@ impl RuntimeModule for ExportRequireRuntimeModule { &self, context: &RuntimeModuleGenerateContext<'_>, ) -> rspack_error::Result { - let require_name = context + let export_name = context .runtime_template - .render_runtime_globals(&RuntimeGlobals::REQUIRE); - let export_temp_name = format!("{require_name}temp"); + .render_runtime_globals(&RuntimeGlobals::REQUIRE_SCOPE); + let export_temp_name = format!("{export_name}temp"); Ok(format!( - r#"var {export_temp_name} = {require_name}; -export {{ {export_temp_name} as {require_name} }}; + r#"var {export_temp_name} = {export_name}; +export {{ {export_temp_name} as {export_name} }}; "#, )) } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/import_scripts_chunk_loading.rs b/crates/rspack_plugin_runtime/src/runtime_module/import_scripts_chunk_loading.rs index d25d2e506978..443992d643d2 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/import_scripts_chunk_loading.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/import_scripts_chunk_loading.rs @@ -10,7 +10,9 @@ use rspack_plugin_javascript::impl_plugin_for_js_plugin::chunk_has_js; use super::{generate_javascript_hmr_runtime, utils::get_output_dir}; use crate::{ extract_runtime_globals_from_ejs, get_chunk_runtime_requirements, - runtime_module::utils::{get_initial_chunk_ids, stringify_chunks}, + runtime_module::utils::{ + get_initial_chunk_ids, render_hmr_runtime_state_expression, stringify_chunks, + }, }; static IMPORT_SCRIPTS_CHUNK_LOADING_TEMPLATE: &str = @@ -111,6 +113,7 @@ impl ImportScriptsChunkLoadingRuntimeModule { pub fn get_runtime_requirements_with_hmr() -> RuntimeGlobals { *IMPORT_SCRIPTS_CHUNK_LOADING_WITH_HMR_RUNTIME_REQUIREMENTS | *JAVASCRIPT_HOT_MODULE_REPLACEMENT_RUNTIME_REQUIREMENTS + | RuntimeGlobals::HMR_RUNTIME_STATE_PREFIX } pub fn get_runtime_requirements_with_hmr_manifest() -> RuntimeGlobals { @@ -192,10 +195,7 @@ impl RuntimeModule for ImportScriptsChunkLoadingRuntimeModule { // object to store loaded chunks // "1" means "already loaded" if with_hmr { - let state_expression = format!( - "{}_importScripts", - runtime_template.render_runtime_globals(&RuntimeGlobals::HMR_RUNTIME_STATE_PREFIX) - ); + let state_expression = render_hmr_runtime_state_expression(runtime_template, "importScripts"); source.push_str(&format!( "var installedChunks = {} = {} || {};\n", state_expression, diff --git a/crates/rspack_plugin_runtime/src/runtime_module/jsonp_chunk_loading.rs b/crates/rspack_plugin_runtime/src/runtime_module/jsonp_chunk_loading.rs index 28708bade470..b29981ec3d9a 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/jsonp_chunk_loading.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/jsonp_chunk_loading.rs @@ -11,7 +11,9 @@ use super::generate_javascript_hmr_runtime; use crate::{ LinkPrefetchData, LinkPreloadData, RuntimeModuleChunkWrapper, RuntimePlugin, extract_runtime_globals_from_ejs, get_chunk_runtime_requirements, - runtime_module::utils::{get_initial_chunk_ids, stringify_chunks}, + runtime_module::utils::{ + get_initial_chunk_ids, render_hmr_runtime_state_expression, stringify_chunks, + }, }; static JSONP_CHUNK_LOADING_TEMPLATE: &str = include_str!("runtime/jsonp_chunk_loading.ejs"); @@ -91,6 +93,7 @@ impl JsonpChunkLoadingRuntimeModule { pub fn get_runtime_requirements_with_hmr() -> RuntimeGlobals { *JSONP_CHUNK_LOADING_WITH_HMR_RUNTIME_REQUIREMENTS | *JAVASCRIPT_HOT_MODULE_REPLACEMENT_RUNTIME_REQUIREMENTS + | RuntimeGlobals::HMR_RUNTIME_STATE_PREFIX } pub fn get_runtime_requirements_with_hmr_manifest() -> RuntimeGlobals { *JSONP_CHUNK_LOADING_WITH_HMR_MANIFEST_RUNTIME_REQUIREMENTS @@ -238,6 +241,7 @@ impl RuntimeModule for JsonpChunkLoadingRuntimeModule { &chunk_has_js, ); let with_fetch_priority = runtime_requirements.contains(RuntimeGlobals::HAS_FETCH_PRIORITY); + let with_script_nonce = runtime_requirements.contains(RuntimeGlobals::SCRIPT_NONCE); let cross_origin_loading = &compilation.options.output.cross_origin_loading; let script_type = &compilation.options.output.script_type; @@ -267,10 +271,7 @@ impl RuntimeModule for JsonpChunkLoadingRuntimeModule { "#, match with_hmr { true => { - let state_expression = format!( - "{}_jsonp", - runtime_template.render_runtime_globals(&RuntimeGlobals::HMR_RUNTIME_STATE_PREFIX) - ); + let state_expression = render_hmr_runtime_state_expression(runtime_template, "jsonp"); format!("{state_expression} = {state_expression} || ") } false => String::new(), @@ -315,6 +316,7 @@ impl RuntimeModule for JsonpChunkLoadingRuntimeModule { &self.template_id(TemplateId::WithPrefetchLink), Some(serde_json::json!({ "_cross_origin": cross_origin_loading.to_string(), + "_with_script_nonce": with_script_nonce, })), )?; @@ -349,6 +351,7 @@ impl RuntimeModule for JsonpChunkLoadingRuntimeModule { Some(serde_json::json!({ "_script_type": script_type.as_str(), "_cross_origin": cross_origin_loading.to_string(), + "_with_script_nonce": with_script_nonce, })), )?; diff --git a/crates/rspack_plugin_runtime/src/runtime_module/load_script.rs b/crates/rspack_plugin_runtime/src/runtime_module/load_script.rs index 13d993b70cdb..db6d14f8d2c1 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/load_script.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/load_script.rs @@ -61,6 +61,7 @@ impl RuntimeModule for LoadScriptRuntimeModule { let runtime_template = context.runtime_template; let runtime_requirements = get_chunk_runtime_requirements(compilation, &self.chunk_ukey); let with_fetch_priority = runtime_requirements.contains(RuntimeGlobals::HAS_FETCH_PRIORITY); + let with_script_nonce = runtime_requirements.contains(RuntimeGlobals::SCRIPT_NONCE); let unique_prefix = if self.unique_name.is_empty() { None @@ -77,6 +78,7 @@ impl RuntimeModule for LoadScriptRuntimeModule { "_script_type": &compilation.options.output.script_type, "_unique_prefix": unique_prefix.is_some(), "_with_fetch_priority": with_fetch_priority, + "_with_script_nonce": with_script_nonce, "_with_create_script_url": self.with_create_script_url, "_cross_origin": compilation.options.output.cross_origin_loading.to_string(), "_chunk_load_timeout": compilation.options.output.chunk_load_timeout.saturating_div(1000).to_string(), @@ -112,11 +114,11 @@ impl RuntimeModule for LoadScriptRuntimeModule { } fn additional_runtime_requirements(&self, compilation: &Compilation) -> RuntimeGlobals { + let mut requirements = RuntimeGlobals::default(); if compilation.options.output.trusted_types.is_some() { - RuntimeGlobals::CREATE_SCRIPT_URL - } else { - RuntimeGlobals::default() + requirements.insert(RuntimeGlobals::CREATE_SCRIPT_URL); } + requirements } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/module_chunk_loading.rs b/crates/rspack_plugin_runtime/src/runtime_module/module_chunk_loading.rs index e03df614ae06..03015dee89f8 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/module_chunk_loading.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/module_chunk_loading.rs @@ -13,7 +13,7 @@ use crate::{ extract_runtime_globals_from_ejs, get_chunk_runtime_requirements, runtime_module::{ generate_javascript_hmr_runtime, - utils::{get_initial_chunk_ids, stringify_chunks}, + utils::{get_initial_chunk_ids, render_hmr_runtime_state_expression, stringify_chunks}, }, }; @@ -97,6 +97,7 @@ impl ModuleChunkLoadingRuntimeModule { pub fn get_runtime_requirements_with_hmr() -> RuntimeGlobals { *MODULE_CHUNK_LOADING_WITH_HMR_RUNTIME_REQUIREMENTS | *JAVASCRIPT_HOT_MODULE_REPLACEMENT_RUNTIME_REQUIREMENTS + | RuntimeGlobals::HMR_RUNTIME_STATE_PREFIX } pub fn get_runtime_requirements_with_hmr_manifest() -> RuntimeGlobals { *MODULE_CHUNK_LOADING_WITH_HMR_MANIFEST_RUNTIME_REQUIREMENTS @@ -223,6 +224,7 @@ impl RuntimeModule for ModuleChunkLoadingRuntimeModule { let with_on_chunk_load = runtime_requirements.contains(RuntimeGlobals::ON_CHUNKS_LOADED); let with_hmr = runtime_requirements.contains(RuntimeGlobals::HMR_DOWNLOAD_UPDATE_HANDLERS); let with_hmr_manifest = runtime_requirements.contains(RuntimeGlobals::HMR_DOWNLOAD_MANIFEST); + let with_script_nonce = runtime_requirements.contains(RuntimeGlobals::SCRIPT_NONCE); let is_neutral_platform = compilation.platform.is_neutral(); @@ -275,10 +277,7 @@ impl RuntimeModule for ModuleChunkLoadingRuntimeModule { "#, match with_hmr { true => { - let state_expression = format!( - "{}_module", - runtime_template.render_runtime_globals(&RuntimeGlobals::HMR_RUNTIME_STATE_PREFIX) - ); + let state_expression = render_hmr_runtime_state_expression(runtime_template, "module"); format!("{state_expression} = {state_expression} || ") } false => String::new(), @@ -339,6 +338,7 @@ impl RuntimeModule for ModuleChunkLoadingRuntimeModule { &self.template(TemplateId::WithPrefetchLink), Some(serde_json::json!({ "_cross_origin": cross_origin_loading.to_string(), + "_with_script_nonce": with_script_nonce, })), )?; @@ -372,6 +372,7 @@ impl RuntimeModule for ModuleChunkLoadingRuntimeModule { &self.template(TemplateId::WithPreloadLink), Some(serde_json::json!({ "_cross_origin": cross_origin_loading.to_string(), + "_with_script_nonce": with_script_nonce, })), )?; diff --git a/crates/rspack_plugin_runtime/src/runtime_module/readfile_chunk_loading.rs b/crates/rspack_plugin_runtime/src/runtime_module/readfile_chunk_loading.rs index 270bc5bbdefe..30b7cae5ec51 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/readfile_chunk_loading.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/readfile_chunk_loading.rs @@ -10,7 +10,9 @@ use rspack_plugin_javascript::impl_plugin_for_js_plugin::chunk_has_js; use super::{generate_javascript_hmr_runtime, utils::get_output_dir}; use crate::{ extract_runtime_globals_from_ejs, get_chunk_runtime_requirements, - runtime_module::utils::{get_initial_chunk_ids, stringify_chunks}, + runtime_module::utils::{ + get_initial_chunk_ids, render_hmr_runtime_state_expression, stringify_chunks, + }, }; static READFILE_CHUNK_LOADING_WITH_ON_CHUNK_LOAD_TEMPLATE: &str = @@ -131,6 +133,7 @@ impl ReadFileChunkLoadingRuntimeModule { pub fn get_runtime_requirements_with_hmr() -> RuntimeGlobals { *READFILE_CHUNK_LOADING_WITH_HMR_RUNTIME_REQUIREMENTS | *JAVASCRIPT_HOT_MODULE_REPLACEMENT_RUNTIME_REQUIREMENTS + | RuntimeGlobals::HMR_RUNTIME_STATE_PREFIX } pub fn get_runtime_requirements_with_hmr_manifest() -> RuntimeGlobals { @@ -224,10 +227,7 @@ impl RuntimeModule for ReadFileChunkLoadingRuntimeModule { } if with_hmr { - let state_expression = format!( - "{}_readFileVm", - runtime_template.render_runtime_globals(&RuntimeGlobals::HMR_RUNTIME_STATE_PREFIX) - ); + let state_expression = render_hmr_runtime_state_expression(runtime_template, "readFileVm"); source.push_str(&format!( "var installedChunks = {} = {} || {};\n", state_expression, @@ -255,7 +255,7 @@ impl RuntimeModule for ReadFileChunkLoadingRuntimeModule { "_with_on_chunk_loaded": match with_on_chunk_load { true => format!("{}();", runtime_template.render_runtime_globals(&RuntimeGlobals::ON_CHUNKS_LOADED)), false => String::new(), - } + }, })), )?; diff --git a/crates/rspack_plugin_runtime/src/runtime_module/require_js_chunk_loading.rs b/crates/rspack_plugin_runtime/src/runtime_module/require_js_chunk_loading.rs index d9dd8a8661a3..d6892aaaa3ba 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/require_js_chunk_loading.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/require_js_chunk_loading.rs @@ -10,7 +10,9 @@ use rspack_plugin_javascript::impl_plugin_for_js_plugin::chunk_has_js; use super::{generate_javascript_hmr_runtime, utils::get_output_dir}; use crate::{ extract_runtime_globals_from_ejs, get_chunk_runtime_requirements, - runtime_module::utils::{get_initial_chunk_ids, stringify_chunks}, + runtime_module::utils::{ + get_initial_chunk_ids, render_hmr_runtime_state_expression, stringify_chunks, + }, }; static REQUIRE_CHUNK_LOADING_TEMPLATE: &str = include_str!("runtime/require_chunk_loading.ejs"); @@ -132,6 +134,7 @@ impl RequireChunkLoadingRuntimeModule { pub fn get_runtime_requirements_with_hmr() -> RuntimeGlobals { *REQUIRE_CHUNK_LOADING_WITH_HMR_RUNTIME_REQUIREMENTS | *JAVASCRIPT_HOT_MODULE_REPLACEMENT_RUNTIME_REQUIREMENTS + | RuntimeGlobals::HMR_RUNTIME_STATE_PREFIX } pub fn get_runtime_requirements_with_hmr_manifest() -> RuntimeGlobals { @@ -234,10 +237,7 @@ impl RuntimeModule for RequireChunkLoadingRuntimeModule { } if with_hmr { - let state_expression = format!( - "{}_require", - runtime_template.render_runtime_globals(&RuntimeGlobals::HMR_RUNTIME_STATE_PREFIX) - ); + let state_expression = render_hmr_runtime_state_expression(runtime_template, "require"); source.push_str(&format!( "var installedChunks = {} = {} || {};\n", state_expression, @@ -265,7 +265,7 @@ impl RuntimeModule for RequireChunkLoadingRuntimeModule { true => format!("{}();", runtime_template .render_runtime_globals(&RuntimeGlobals::ON_CHUNKS_LOADED)), false => String::new(), - } + }, })), )?; diff --git a/crates/rspack_plugin_runtime/src/runtime_module/runtime/create_fake_namespace_object.ejs b/crates/rspack_plugin_runtime/src/runtime_module/runtime/create_fake_namespace_object.ejs index 00f481282b43..9c694691e97d 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/runtime/create_fake_namespace_object.ejs +++ b/crates/rspack_plugin_runtime/src/runtime_module/runtime/create_fake_namespace_object.ejs @@ -7,7 +7,7 @@ var leafPrototypes; // mode & 16: return value when it's Promise-like // mode & 8|1: behave like require <%- CREATE_FAKE_NAMESPACE_OBJECT %> = function(value, mode) { - if(mode & 1) value = this(value); + if(mode & 1) value = <%- REQUIRE %>(value); if(mode & 8) return value; if(typeof value === 'object' && value) { if((mode & 4) && value.__esModule) return value; @@ -23,4 +23,4 @@ var leafPrototypes; def['default'] = <%- returningFunction("value", "") %>; <%- DEFINE_PROPERTY_GETTERS %>(ns, def); return ns; -}; \ No newline at end of file +}; diff --git a/crates/rspack_plugin_runtime/src/runtime_module/runtime/import_scripts_chunk_loading.ejs b/crates/rspack_plugin_runtime/src/runtime_module/runtime/import_scripts_chunk_loading.ejs index 44ae55439432..b874d57e21f8 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/runtime/import_scripts_chunk_loading.ejs +++ b/crates/rspack_plugin_runtime/src/runtime_module/runtime/import_scripts_chunk_loading.ejs @@ -6,11 +6,11 @@ var installChunk = <%- basicFunction("data") %> { <%- MODULE_FACTORIES %>[moduleId] = moreModules[moduleId]; } } - if (runtime) runtime(<%- REQUIRE %>); + if (runtime) runtime(<%- REQUIRE_SCOPE %>); while (chunkIds.length) installedChunks[chunkIds.pop()] = 1; parentChunkLoadingFunction(data); }; var chunkLoadingGlobal = <%- _chunk_loading_global_expr %> = <%- _chunk_loading_global_expr %> || []; var parentChunkLoadingFunction = chunkLoadingGlobal.push.bind(chunkLoadingGlobal); -chunkLoadingGlobal.push = installChunk; \ No newline at end of file +chunkLoadingGlobal.push = installChunk; diff --git a/crates/rspack_plugin_runtime/src/runtime_module/runtime/javascript_hot_module_replacement.ejs b/crates/rspack_plugin_runtime/src/runtime_module/runtime/javascript_hot_module_replacement.ejs index 10365f0fc0b4..715e24d1f167 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/runtime/javascript_hot_module_replacement.ejs +++ b/crates/rspack_plugin_runtime/src/runtime_module/runtime/javascript_hot_module_replacement.ejs @@ -281,16 +281,16 @@ function applyHandler(options) { // run new runtime modules for (var i = 0; i < currentUpdateRuntime.length; i++) { <% if (_is_hot_test) { %> - currentUpdateRuntime[i](new Proxy(<%- REQUIRE %>, { + currentUpdateRuntime[i](new Proxy(<%- REQUIRE_SCOPE %>, { set(target, prop, value, receiver) { if (self.__HMR_UPDATED_RUNTIME__) { - self.__HMR_UPDATED_RUNTIME__.javascript.updatedRuntime.push(`<%- REQUIRE %>.${prop}`); + self.__HMR_UPDATED_RUNTIME__.javascript.updatedRuntime.push(`<%- REQUIRE_SCOPE %>.${prop}`); } return Reflect.set(target, prop, value, receiver); } })); <% } else { %> - currentUpdateRuntime[i](<%- REQUIRE %>); + currentUpdateRuntime[i](<%- REQUIRE_SCOPE %>); <% } %> } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/runtime/jsonp_chunk_loading_with_callback.ejs b/crates/rspack_plugin_runtime/src/runtime_module/runtime/jsonp_chunk_loading_with_callback.ejs index 8e1cac649c1f..e34853371478 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/runtime/jsonp_chunk_loading_with_callback.ejs +++ b/crates/rspack_plugin_runtime/src/runtime_module/runtime/jsonp_chunk_loading_with_callback.ejs @@ -10,7 +10,7 @@ var __rspack_jsonp = <%- basicFunction("parentChunkLoadingFunction, data") %> { <%- MODULE_FACTORIES %>[moduleId] = moreModules[moduleId]; } } - if (runtime) var result = runtime(<%- REQUIRE %>); + if (runtime) var result = runtime(<%- REQUIRE_SCOPE %>); } if (parentChunkLoadingFunction) parentChunkLoadingFunction(data); for (; i < chunkIds.length; i++) { diff --git a/crates/rspack_plugin_runtime/src/runtime_module/runtime/jsonp_chunk_loading_with_prefetch_link.ejs b/crates/rspack_plugin_runtime/src/runtime_module/runtime/jsonp_chunk_loading_with_prefetch_link.ejs index 4637711c9afd..21322b1fcfe8 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/runtime/jsonp_chunk_loading_with_prefetch_link.ejs +++ b/crates/rspack_plugin_runtime/src/runtime_module/runtime/jsonp_chunk_loading_with_prefetch_link.ejs @@ -2,9 +2,9 @@ var link = document.createElement('link'); <% if (_cross_origin != "") { %> link.crossOrigin = '<%- _cross_origin %>'; <% } %> -if (<%- SCRIPT_NONCE %>) { - link.setAttribute("nonce", <%- SCRIPT_NONCE %>); -} +<% if (_with_script_nonce) { %> +if (<%- SCRIPT_NONCE %>) link.setAttribute("nonce", <%- SCRIPT_NONCE %>); +<% } %> link.rel = 'prefetch'; link.as = 'script'; -link.href = <%- PUBLIC_PATH %> + <%- GET_CHUNK_SCRIPT_FILENAME %>(chunkId); \ No newline at end of file +link.href = <%- PUBLIC_PATH %> + <%- GET_CHUNK_SCRIPT_FILENAME %>(chunkId); diff --git a/crates/rspack_plugin_runtime/src/runtime_module/runtime/jsonp_chunk_loading_with_preload_link.ejs b/crates/rspack_plugin_runtime/src/runtime_module/runtime/jsonp_chunk_loading_with_preload_link.ejs index 7f46aee5bea9..8a8584618366 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/runtime/jsonp_chunk_loading_with_preload_link.ejs +++ b/crates/rspack_plugin_runtime/src/runtime_module/runtime/jsonp_chunk_loading_with_preload_link.ejs @@ -2,9 +2,9 @@ var link = document.createElement('link'); <% if (_script_type != "false" && _script_type != "module") { %> link.type = "<%- _script_type %>"; <% } %> -if (<%- SCRIPT_NONCE %>) { - link.setAttribute("nonce", <%- SCRIPT_NONCE %>); -} +<% if (_with_script_nonce) { %> +if (<%- SCRIPT_NONCE %>) link.setAttribute("nonce", <%- SCRIPT_NONCE %>); +<% } %> <% if (_script_type == "module") { %> link.rel = 'modulepreload'; <% } else { %> @@ -18,4 +18,4 @@ link.crossOrigin = 'use-credentials'; if (link.href.indexOf(window.location.origin + '/') !== 0) { link.crossOrigin = '<%- _cross_origin %>'; } -<% } %> \ No newline at end of file +<% } %> diff --git a/crates/rspack_plugin_runtime/src/runtime_module/runtime/load_script_create_script.ejs b/crates/rspack_plugin_runtime/src/runtime_module/runtime/load_script_create_script.ejs index 8eef7a69b1b0..4516f42107dc 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/runtime/load_script_create_script.ejs +++ b/crates/rspack_plugin_runtime/src/runtime_module/runtime/load_script_create_script.ejs @@ -3,9 +3,9 @@ script = document.createElement('script'); script.type = '<%- _script_type %>'; <% } %> script.timeout = <%- _chunk_load_timeout %>; -if (<%- SCRIPT_NONCE %>) { - script.setAttribute("nonce", <%- SCRIPT_NONCE %>); -} +<% if (_with_script_nonce) { %> +if (<%- SCRIPT_NONCE %>) script.setAttribute("nonce", <%- SCRIPT_NONCE %>); +<% } %> <% if (_unique_prefix) { %> script.setAttribute("data-rspack", uniqueName + key); <% } %> @@ -25,4 +25,4 @@ script.crossOrigin = "use-credentials"; if (script.src.indexOf(window.location.origin + '/') !== 0) { script.crossOrigin = '<%- _cross_origin %>'; } -<% } %> \ No newline at end of file +<% } %> diff --git a/crates/rspack_plugin_runtime/src/runtime_module/runtime/module_chunk_loading.ejs b/crates/rspack_plugin_runtime/src/runtime_module/runtime/module_chunk_loading.ejs index 4b7650e97b77..d906121a2109 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/runtime/module_chunk_loading.ejs +++ b/crates/rspack_plugin_runtime/src/runtime_module/runtime/module_chunk_loading.ejs @@ -1,16 +1,16 @@ var installChunk = <%- basicFunction("data") %> { var __rspack_esm_ids = data.__rspack_esm_ids; - var <%- _modules %> = data.<%- _modules %>; + var moreModules = data.<%- _modules %>; var __rspack_esm_runtime = data.__rspack_esm_runtime; // add "modules" to the modules object, // then flag all "ids" as loaded and fire callback var moduleId, chunkId, i = 0; - for (moduleId in <%- _modules %>) { - if (<%- HAS_OWN_PROPERTY %>(<%- _modules %>, moduleId)) { - <%- MODULE_FACTORIES %>[moduleId] = <%- _modules %>[moduleId]; + for (moduleId in moreModules) { + if (<%- HAS_OWN_PROPERTY %>(moreModules, moduleId)) { + <%- MODULE_FACTORIES %>[moduleId] = moreModules[moduleId]; } } - if (__rspack_esm_runtime) __rspack_esm_runtime(<%- REQUIRE %>); + if (__rspack_esm_runtime) __rspack_esm_runtime(<%- REQUIRE_SCOPE %>); for (; i < __rspack_esm_ids.length; i++) { chunkId = __rspack_esm_ids[i]; if (<%- HAS_OWN_PROPERTY %>(installedChunks, chunkId) && installedChunks[chunkId]) { @@ -19,4 +19,4 @@ var installChunk = <%- basicFunction("data") %> { installedChunks[__rspack_esm_ids[i]] = 0; } <% if (_with_on_chunk_load) { %><%- ON_CHUNKS_LOADED %>();<% } %> -}; \ No newline at end of file +}; diff --git a/crates/rspack_plugin_runtime/src/runtime_module/runtime/module_chunk_loading_with_prefetch_link.ejs b/crates/rspack_plugin_runtime/src/runtime_module/runtime/module_chunk_loading_with_prefetch_link.ejs index 623569f65497..bdb775249085 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/runtime/module_chunk_loading_with_prefetch_link.ejs +++ b/crates/rspack_plugin_runtime/src/runtime_module/runtime/module_chunk_loading_with_prefetch_link.ejs @@ -2,9 +2,9 @@ var link = document.createElement('link'); <% if (_cross_origin != "") { %> link.crossOrigin = '<%- _cross_origin %>'; <% } %> -if (<%- SCRIPT_NONCE %>) { - link.setAttribute('nonce', <%- SCRIPT_NONCE %>); -} +<% if (_with_script_nonce) { %> +if (<%- SCRIPT_NONCE %>) link.setAttribute('nonce', <%- SCRIPT_NONCE %>); +<% } %> link.rel = 'prefetch'; link.as = 'script'; -link.href = <%- PUBLIC_PATH %> + <%- GET_CHUNK_SCRIPT_FILENAME %>(chunkId); \ No newline at end of file +link.href = <%- PUBLIC_PATH %> + <%- GET_CHUNK_SCRIPT_FILENAME %>(chunkId); diff --git a/crates/rspack_plugin_runtime/src/runtime_module/runtime/module_chunk_loading_with_preload_link.ejs b/crates/rspack_plugin_runtime/src/runtime_module/runtime/module_chunk_loading_with_preload_link.ejs index 4d023bbac7c4..72806823054d 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/runtime/module_chunk_loading_with_preload_link.ejs +++ b/crates/rspack_plugin_runtime/src/runtime_module/runtime/module_chunk_loading_with_preload_link.ejs @@ -1,7 +1,7 @@ var link = document.createElement('link'); -if (<%- SCRIPT_NONCE %>) { - link.setAttribute("nonce", <%- SCRIPT_NONCE %>); -} +<% if (_with_script_nonce) { %> +if (<%- SCRIPT_NONCE %>) link.setAttribute("nonce", <%- SCRIPT_NONCE %>); +<% } %> link.rel = 'modulepreload'; link.href = <%- PUBLIC_PATH %> + <%- GET_CHUNK_SCRIPT_FILENAME %>(chunkId); <% if (_cross_origin == "use-credentials") { %> @@ -10,4 +10,4 @@ link.crossOrigin = 'use-credentials'; if (link.href.indexOf(window.location.origin + '/') !== 0) { link.crossOrigin = '<%- _cross_origin %>'; } -<% } %> \ No newline at end of file +<% } %> diff --git a/crates/rspack_plugin_runtime/src/runtime_module/runtime/readfile_chunk_loading.ejs b/crates/rspack_plugin_runtime/src/runtime_module/runtime/readfile_chunk_loading.ejs index a33332d6b0e4..3fe835c17038 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/runtime/readfile_chunk_loading.ejs +++ b/crates/rspack_plugin_runtime/src/runtime_module/runtime/readfile_chunk_loading.ejs @@ -6,7 +6,7 @@ var installChunk = <%- basicFunction("chunk") %> { <%- MODULE_FACTORIES %>[moduleId] = moreModules[moduleId]; } } - if (runtime) runtime(<%- REQUIRE %> ); + if (runtime) runtime(<%- REQUIRE_SCOPE %> ); for (var i = 0; i < chunkIds.length; i++) { if (installedChunks[chunkIds[i]]) { installedChunks[chunkIds[i]][0](); @@ -14,4 +14,4 @@ var installChunk = <%- basicFunction("chunk") %> { installedChunks[chunkIds[i]] = 0; } <%- _with_on_chunk_loaded %> -}; \ No newline at end of file +}; diff --git a/crates/rspack_plugin_runtime/src/runtime_module/runtime/readfile_chunk_loading_with_external_install_chunk.ejs b/crates/rspack_plugin_runtime/src/runtime_module/runtime/readfile_chunk_loading_with_external_install_chunk.ejs index 2540f95aa6a9..757d4133e659 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/runtime/readfile_chunk_loading_with_external_install_chunk.ejs +++ b/crates/rspack_plugin_runtime/src/runtime_module/runtime/readfile_chunk_loading_with_external_install_chunk.ejs @@ -1,2 +1,2 @@ -module.exports = <%- REQUIRE %>; -<%- EXTERNAL_INSTALL_CHUNK %> = installChunk; \ No newline at end of file +module.exports = <%- REQUIRE_SCOPE %>; +<%- EXTERNAL_INSTALL_CHUNK %> = installChunk; diff --git a/crates/rspack_plugin_runtime/src/runtime_module/runtime/require_chunk_loading.ejs b/crates/rspack_plugin_runtime/src/runtime_module/runtime/require_chunk_loading.ejs index b8a00b5eee57..07417643fb07 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/runtime/require_chunk_loading.ejs +++ b/crates/rspack_plugin_runtime/src/runtime_module/runtime/require_chunk_loading.ejs @@ -7,7 +7,7 @@ var installChunk = <%- basicFunction("chunk") %> { <%- MODULE_FACTORIES %>[moduleId] = moreModules[moduleId]; } } - if (runtime) runtime(<%- REQUIRE %>); + if (runtime) runtime(<%- REQUIRE_SCOPE %>); for (var i = 0; i < chunkIds.length; i++) installedChunks[chunkIds[i]] = 1; <%- _with_on_chunk_loaded %> -}; \ No newline at end of file +}; diff --git a/crates/rspack_plugin_runtime/src/runtime_module/runtime/require_chunk_loading_with_external_install_chunk.ejs b/crates/rspack_plugin_runtime/src/runtime_module/runtime/require_chunk_loading_with_external_install_chunk.ejs index 2540f95aa6a9..757d4133e659 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/runtime/require_chunk_loading_with_external_install_chunk.ejs +++ b/crates/rspack_plugin_runtime/src/runtime_module/runtime/require_chunk_loading_with_external_install_chunk.ejs @@ -1,2 +1,2 @@ -module.exports = <%- REQUIRE %>; -<%- EXTERNAL_INSTALL_CHUNK %> = installChunk; \ No newline at end of file +module.exports = <%- REQUIRE_SCOPE %>; +<%- EXTERNAL_INSTALL_CHUNK %> = installChunk; diff --git a/crates/rspack_plugin_runtime/src/runtime_module/utils.rs b/crates/rspack_plugin_runtime/src/runtime_module/utils.rs index ca5a71e71c26..8243c51a2585 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/utils.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/utils.rs @@ -1,7 +1,8 @@ use std::fmt::Write as _; use rspack_core::{ - Chunk, ChunkLoading, ChunkUkey, Compilation, PathData, RuntimeCodeTemplate, SourceType, + Chunk, ChunkLoading, ChunkUkey, Compilation, PathData, RuntimeCodeTemplate, RuntimeGlobals, + SourceType, chunk_graph_chunk::{ChunkId, ChunkIdSet}, get_js_chunk_filename_template, get_undo_path, }; @@ -61,6 +62,21 @@ pub fn stringify_chunks(chunks: &ChunkIdSet, value: u8) -> String { result } +pub fn render_hmr_runtime_state_expression( + runtime_template: &RuntimeCodeTemplate<'_>, + key: &str, +) -> String { + let state_prefix = if runtime_template.uses_lexical_runtime_globals() { + RuntimeGlobals::HMR_RUNTIME_STATE_PREFIX + .property_name() + .expect("hmr runtime state prefix should have property name") + .to_string() + } else { + runtime_template.render_runtime_globals(&RuntimeGlobals::HMR_RUNTIME_STATE_PREFIX) + }; + format!("{state_prefix}_{key}") +} + pub fn chunk_has_css(chunk: &ChunkUkey, compilation: &Compilation) -> bool { compilation .build_chunk_graph_artifact diff --git a/crates/rspack_plugin_runtime/src/runtime_plugin.rs b/crates/rspack_plugin_runtime/src/runtime_plugin.rs index 5098968fa3f4..71de51ef6a4d 100644 --- a/crates/rspack_plugin_runtime/src/runtime_plugin.rs +++ b/crates/rspack_plugin_runtime/src/runtime_plugin.rs @@ -179,7 +179,10 @@ async fn runtime_requirements_in_tree( runtime_requirements_mut.insert(RuntimeGlobals::ENSURE_CHUNK_HANDLERS); } - if runtime_requirements.contains(RuntimeGlobals::ENSURE_CHUNK) { + if runtime_requirements.contains(RuntimeGlobals::ENSURE_CHUNK) + || (!compilation.options.output.module + && runtime_requirements.contains(RuntimeGlobals::ENSURE_CHUNK_HANDLERS)) + { let c = compilation .build_chunk_graph_artifact .chunk_by_ukey @@ -204,7 +207,6 @@ async fn runtime_requirements_in_tree( .map(|library| library.library_type.clone()) }; - let runtime_template = compilation.runtime_template.create_runtime_code_template(); #[allow(clippy::collapsible_match)] for runtime_requirement in runtime_requirements.iter() { match runtime_requirement { @@ -250,6 +252,7 @@ async fn runtime_requirements_in_tree( } } RuntimeGlobals::GET_CHUNK_SCRIPT_FILENAME => { + let runtime_template = compilation.runtime_template.create_runtime_code_template(); runtime_modules_to_add.push(( *chunk_ukey, GetChunkFilenameRuntimeModule::new( @@ -273,6 +276,7 @@ async fn runtime_requirements_in_tree( )); } RuntimeGlobals::GET_CHUNK_CSS_FILENAME => { + let runtime_template = compilation.runtime_template.create_runtime_code_template(); runtime_modules_to_add.push(( *chunk_ukey, GetChunkFilenameRuntimeModule::new( diff --git a/packages/rspack-test-tools/src/case/config.ts b/packages/rspack-test-tools/src/case/config.ts index cc72cc3b7b29..84fdc35a0a41 100644 --- a/packages/rspack-test-tools/src/case/config.ts +++ b/packages/rspack-test-tools/src/case/config.ts @@ -2,7 +2,10 @@ import path from 'node:path'; import type { RspackOptions } from '@rspack/core'; import fs from 'fs-extra'; import { parseResource } from '../helper/legacy/parseResource'; -import { BasicCaseCreator } from '../test/creator'; +import { + BasicCaseCreator, + type IBasicCaseCreatorOptions, +} from '../test/creator'; import type { ITestContext, ITestEnv, @@ -21,8 +24,14 @@ import { import { createMultiCompilerRunner, getMultiCompilerRunnerKey } from './runner'; export type TConfigCaseConfig = Omit; +type TConfigCaseOptions = Partial & { + rspackOptions?: RspackOptions; +}; -export function createConfigProcessor(name: string): ITestProcessor { +export function createConfigProcessor( + name: string, + rspackOptions?: RspackOptions, +): ITestProcessor { return { config: (context: ITestContext) => { configMultiCompiler( @@ -30,7 +39,10 @@ export function createConfigProcessor(name: string): ITestProcessor { name, ['rspack.config.cjs', 'rspack.config.js', 'webpack.config.js'], defaultOptions, - overrideOptions, + (index, context, options) => { + overrideOptions(index, context, options); + mergeRspackOptions(options, rspackOptions); + }, ); }, compiler: async (context: ITestContext) => { @@ -75,8 +87,18 @@ const creator = new BasicCaseCreator({ concurrent: true, }); -export function createConfigCase(name: string, src: string, dist: string) { - creator.create(name, src, dist); +export function createConfigCase( + name: string, + src: string, + dist: string, + rspackOptions?: RspackOptions, +) { + creator.create(name, src, dist, undefined, { + rspackOptions, + steps: ({ name, rspackOptions }) => [ + createConfigProcessor(name, rspackOptions as RspackOptions | undefined), + ], + } satisfies TConfigCaseOptions); } export function defaultOptions( @@ -142,6 +164,19 @@ export function overrideOptions( } } +function mergeRspackOptions(options: RspackOptions, override?: RspackOptions) { + if (!override) return; + + const { experiments, ...rest } = override; + Object.assign(options, rest); + if (experiments) { + options.experiments = { + ...options.experiments, + ...experiments, + }; + } +} + export function findBundle( index: number, context: ITestContext, diff --git a/packages/rspack-test-tools/src/case/hot.ts b/packages/rspack-test-tools/src/case/hot.ts index 399e2b59c810..165a190aaad1 100644 --- a/packages/rspack-test-tools/src/case/hot.ts +++ b/packages/rspack-test-tools/src/case/hot.ts @@ -9,7 +9,10 @@ import { HotUpdatePlugin } from '../helper/hot-update/plugin'; import { checkArrayExpectation } from '../helper/legacy/checkArrayExpectation'; import { LazyCompilationTestPlugin } from '../plugin'; import { NodeRunner, WebRunner } from '../runner'; -import { BasicCaseCreator } from '../test/creator'; +import { + BasicCaseCreator, + type IBasicCaseCreatorOptions, +} from '../test/creator'; import type { IModuleScope, ITestContext, @@ -21,6 +24,9 @@ import { afterExecute, build, check, compiler, config, run } from './common'; import { cachedStats, type THotStepRuntimeData } from './runner'; type TTarget = RspackOptions['target']; +type THotCaseOptions = Partial & { + rspackOptions?: RspackOptions; +}; const creators: Map = new Map(); @@ -30,6 +36,7 @@ export function createHotProcessor( temp: string, target: TTarget, incremental: boolean = false, + rspackOptions?: RspackOptions, ): THotProcessor { const updatePlugin = new HotUpdatePlugin(src, temp); @@ -51,6 +58,7 @@ export function createHotProcessor( if (incremental) { options.incremental ??= 'advance-silent'; } + mergeRspackOptions(options, rspackOptions); compiler.setOptions(options); }, compiler: async (context: ITestContext) => { @@ -96,12 +104,14 @@ function getCreator(target: TTarget) { clean: true, describe: true, target, - steps: ({ name, target, src, dist, temp }) => [ + steps: ({ name, target, src, dist, temp, rspackOptions }) => [ createHotProcessor( name, src, temp || path.resolve(dist, 'temp'), target as TTarget, + false, + rspackOptions as RspackOptions | undefined, ), ], runner: { @@ -121,9 +131,25 @@ export function createHotCase( dist: string, temp: string, target: RspackOptions['target'], + rspackOptions?: RspackOptions, ) { const creator = getCreator(target); - creator.create(name, src, dist, temp); + creator.create(name, src, dist, temp, { + rspackOptions, + } satisfies THotCaseOptions); +} + +function mergeRspackOptions(options: RspackOptions, override?: RspackOptions) { + if (!override) return; + + const { experiments, ...rest } = override; + Object.assign(options, rest); + if (experiments) { + options.experiments = { + ...options.experiments, + ...experiments, + }; + } } function defaultOptions(context: ITestContext, target: TTarget) { diff --git a/packages/rspack-test-tools/src/helper/expect/to-match-file-snapshot.ts b/packages/rspack-test-tools/src/helper/expect/to-match-file-snapshot.ts index 7c08aaa2b033..932d73fd6a12 100644 --- a/packages/rspack-test-tools/src/helper/expect/to-match-file-snapshot.ts +++ b/packages/rspack-test-tools/src/helper/expect/to-match-file-snapshot.ts @@ -21,6 +21,51 @@ const isEqual = (a: string | Buffer, b: string | Buffer): boolean => { return Buffer.isBuffer(a) ? a.equals(b) : a === b; }; +function readSnapshot(filename: string, content: string | Buffer) { + const output = fs.readFileSync( + filename, + Buffer.isBuffer(content) ? null : 'utf8', + ); + return Buffer.isBuffer(output) ? output : output.replace(/\r\n/g, '\n'); +} + +function toPosixPath(filename: string) { + return filename.split(path.sep).join('/'); +} + +function getRuntimeModeSnapshotFilename(filename: string): string | undefined { + if ( + !(globalThis as { __RSPACK_TEST_RUNTIME_MODE_RSPACK?: boolean }) + .__RSPACK_TEST_RUNTIME_MODE_RSPACK + ) { + return; + } + + const normalized = toPosixPath(filename); + for (const marker of ['/__snapshot__/', '/__snapshots__/']) { + const markerIndex = normalized.indexOf(marker); + if (markerIndex >= 0) { + return path.normalize( + `${normalized.slice(0, markerIndex + marker.length)}runtimeModeSnapshot/${normalized.slice(markerIndex + marker.length)}`, + ); + } + } +} + +function cleanupRuntimeModeSnapshot(filename: string) { + fs.unlinkSync(filename); + + let current = path.dirname(filename); + while (path.basename(current) !== 'runtimeModeSnapshot') { + try { + fs.rmdirSync(current); + } catch { + break; + } + current = path.dirname(current); + } +} + /** * Match given content against content of the specified file. * @@ -68,8 +113,16 @@ export function toMatchFileSnapshotSync( }).replace(/\s/g, '-')}-${this.assertionCalls}`, ) : filepath; + const runtimeModeSnapshotFilename = getRuntimeModeSnapshotFilename(filename); + const matchedFilename = + runtimeModeSnapshotFilename && fs.existsSync(runtimeModeSnapshotFilename) + ? runtimeModeSnapshotFilename + : filename; - if (snapshotState._updateSnapshot === 'none' && !fs.existsSync(filename)) { + if ( + snapshotState._updateSnapshot === 'none' && + !fs.existsSync(matchedFilename) + ) { // We're probably running in CI environment snapshotState.unmatched++; @@ -78,17 +131,15 @@ export function toMatchFileSnapshotSync( pass: isNot, message: () => `New output file ${chalk.blue( - path.basename(filename), + path.basename(matchedFilename), )} was ${chalk.bold.red('not written')}.\n\nThe update flag must be explicitly passed to write a new snapshot.\n\nThis is likely because this test is run in a ${chalk.blue( 'continuous integration (CI) environment', )} in which snapshots are not written by default.\n\n`, }; } - if (fs.existsSync(filename)) { - const output = fs - .readFileSync(filename, Buffer.isBuffer(content) ? null : 'utf8') - .replace(/\r\n/g, '\n'); + if (fs.existsSync(matchedFilename)) { + const output = readSnapshot(matchedFilename, content); if (isNot) { // The matcher is being used with `.not` @@ -104,15 +155,32 @@ export function toMatchFileSnapshotSync( message: () => `Expected received content ${chalk.red( 'to not match', - )} the file ${chalk.blue(path.basename(filename))}.`, + )} the file ${chalk.blue(path.basename(matchedFilename))}.`, }; } if (isEqual(content, output)) { return { pass: true, message: () => '' }; } if (snapshotState._updateSnapshot === 'all') { - fs.mkdirSync(path.dirname(filename), { recursive: true }); - fs.writeFileSync(filename, content); + if ( + runtimeModeSnapshotFilename && + matchedFilename === runtimeModeSnapshotFilename && + fs.existsSync(filename) && + isEqual(content, readSnapshot(filename, content)) + ) { + cleanupRuntimeModeSnapshot(runtimeModeSnapshotFilename); + + snapshotState.updated++; + + return { pass: true, message: () => '' }; + } + + const updatedFilename = + runtimeModeSnapshotFilename && fs.existsSync(filename) + ? runtimeModeSnapshotFilename + : matchedFilename; + fs.mkdirSync(path.dirname(updatedFilename), { recursive: true }); + fs.writeFileSync(updatedFilename, content); snapshotState.updated++; @@ -141,7 +209,7 @@ export function toMatchFileSnapshotSync( message: () => `Received content ${chalk.red( "doesn't match", - )} the file ${chalk.blue(path.basename(filename))}.${difference}`, + )} the file ${chalk.blue(path.basename(matchedFilename))}.${difference}`, }; } if ( @@ -149,8 +217,17 @@ export function toMatchFileSnapshotSync( (snapshotState._updateSnapshot === 'new' || snapshotState._updateSnapshot === 'all') ) { - fs.mkdirSync(path.dirname(filename), { recursive: true }); - fs.writeFileSync(filename, content); + if ( + runtimeModeSnapshotFilename && + fs.existsSync(filename) && + isEqual(content, readSnapshot(filename, content)) + ) { + return { pass: true, message: () => '' }; + } + + const newFilename = runtimeModeSnapshotFilename || filename; + fs.mkdirSync(path.dirname(newFilename), { recursive: true }); + fs.writeFileSync(newFilename, content); snapshotState.added++; @@ -162,7 +239,7 @@ export function toMatchFileSnapshotSync( pass: true, message: () => `The output file ${chalk.blue( - path.basename(filename), + path.basename(matchedFilename), )} ${chalk.bold.red("doesn't exist")}.`, }; } diff --git a/packages/rspack-test-tools/src/helper/hot-update/plugin.ts b/packages/rspack-test-tools/src/helper/hot-update/plugin.ts index 71dae6f2988f..c8879b47e884 100644 --- a/packages/rspack-test-tools/src/helper/hot-update/plugin.ts +++ b/packages/rspack-test-tools/src/helper/hot-update/plugin.ts @@ -170,14 +170,23 @@ export class HotUpdatePlugin { if ( module.constructor.name === 'DefinePropertyGettersRuntimeModule' ) { + const runtimeMode = compiler.options.experiments?.runtimeMode; + const definePropertyGetters = + runtimeMode === 'rspack' + ? 'definePropertyGetters' + : RuntimeGlobals.definePropertyGetters; + const hasOwnProperty = + runtimeMode === 'rspack' + ? 'hasOwnProperty' + : RuntimeGlobals.hasOwnProperty; // HMR tests re-execute modules and redefine the same export keys, so // the test-only runtime keeps export descriptors configurable (`configurable: true`). module.source.source = Buffer.from( ` -${RuntimeGlobals.definePropertyGetters} = function (exports, getters, values) { +${definePropertyGetters} = function (exports, getters, values) { var define = function (defs, kind) { for(var key in defs) { - if(${RuntimeGlobals.hasOwnProperty}(defs, key) && !${RuntimeGlobals.hasOwnProperty}(exports, key)) { + if(${hasOwnProperty}(defs, key) && !${hasOwnProperty}(exports, key)) { Object.defineProperty(exports, key, { configurable: true, enumerable: true, [kind]: defs[key] }); } } diff --git a/packages/rspack/src/ExecuteModulePlugin.ts b/packages/rspack/src/ExecuteModulePlugin.ts index c2a88dfc8d32..a63f3854bf00 100644 --- a/packages/rspack/src/ExecuteModulePlugin.ts +++ b/packages/rspack/src/ExecuteModulePlugin.ts @@ -21,8 +21,20 @@ export default class ExecuteModulePlugin { const code = source; try { + const isRspackRuntimeMode = + compiler.options.experiments?.runtimeMode === 'rspack'; + const runtimeContext = + context[ + renderRuntimeVariables( + RuntimeVariable.Context, + compiler.options, + ) + ]; + const runtimeContextArgument = isRspackRuntimeMode + ? `, ${renderRuntimeVariables(RuntimeVariable.Context, compiler.options)}` + : ''; const fn = vm.runInThisContext( - `(function(module, ${renderRuntimeVariables(RuntimeVariable.Module, compiler.options)}, ${renderRuntimeVariables(RuntimeVariable.Exports, compiler.options)}, exports, ${renderRuntimeVariables(RuntimeVariable.Require, compiler.options)}) {\n${code}\n})`, + `(function(module, ${renderRuntimeVariables(RuntimeVariable.Module, compiler.options)}, ${renderRuntimeVariables(RuntimeVariable.Exports, compiler.options)}, exports, ${renderRuntimeVariables(RuntimeVariable.Require, compiler.options)}${runtimeContextArgument}) {\n${code}\n})`, { filename: moduleObject.id, }, @@ -40,6 +52,7 @@ export default class ExecuteModulePlugin { compiler.options, ) ], + runtimeContext, ); } catch (e: any) { const err = e instanceof Error ? e : new Error(e); diff --git a/packages/rspack/src/RuntimeGlobals.ts b/packages/rspack/src/RuntimeGlobals.ts index a9c1ce33bb38..a61513b8e209 100644 --- a/packages/rspack/src/RuntimeGlobals.ts +++ b/packages/rspack/src/RuntimeGlobals.ts @@ -474,6 +474,7 @@ export function renderModulePrefix( export enum RuntimeVariable { Require, + Context, Modules, ModuleCache, Module, @@ -488,6 +489,8 @@ export function renderRuntimeVariables( switch (variable) { case RuntimeVariable.Require: return '__webpack_require__'; + case RuntimeVariable.Context: + return '__rspack_context'; case RuntimeVariable.Modules: return '__webpack_modules__'; case RuntimeVariable.ModuleCache: @@ -557,7 +560,7 @@ function renderRuntimeGlobals( case RuntimeGlobals.definePropertyGetters: return `${scope_name}.d`; case RuntimeGlobals.makeNamespaceObject: - return `${scope_name}.r`; + return `${scope_name}.N`; case RuntimeGlobals.createFakeNamespaceObject: return `${scope_name}.t`; case RuntimeGlobals.compatGetDefaultExport: diff --git a/packages/rspack/src/config/defaults.ts b/packages/rspack/src/config/defaults.ts index 882d844e61f9..6486bb34093b 100644 --- a/packages/rspack/src/config/defaults.ts +++ b/packages/rspack/src/config/defaults.ts @@ -237,6 +237,7 @@ const applyExperimentsDefaults = (experiments: ExperimentsNormalized) => { // IGNORE(experiments.pureFunctions): Rspack specific configuration for pure function annotations and hints D(experiments, 'pureFunctions', false); + D(experiments, 'runtimeMode', 'webpack'); }; const applyIncrementalDefaults = (options: RspackOptionsNormalized) => { diff --git a/packages/rspack/src/config/normalization.ts b/packages/rspack/src/config/normalization.ts index 653bed3e590b..b0148c767344 100644 --- a/packages/rspack/src/config/normalization.ts +++ b/packages/rspack/src/config/normalization.ts @@ -621,6 +621,7 @@ export interface ExperimentsNormalized { deferImport?: boolean; sourceImport?: boolean; pureFunctions?: boolean; + runtimeMode?: 'webpack' | 'rspack'; } export type IgnoreWarningsNormalized = (( diff --git a/packages/rspack/src/config/types.ts b/packages/rspack/src/config/types.ts index d7f4878a2316..bb3df4f9a8a1 100644 --- a/packages/rspack/src/config/types.ts +++ b/packages/rspack/src/config/types.ts @@ -3028,6 +3028,12 @@ export type Experiments = { * @default false */ pureFunctions?: boolean; + /** + * Select runtime proxy context behavior. `webpack` keeps `__webpack_require__.x`, + * while `rspack` uses `__rspack_context`. + * @default "webpack" + */ + runtimeMode?: 'webpack' | 'rspack'; }; //#endregion diff --git a/packages/rspack/src/runtime/moduleFederationDefaultRuntime.js b/packages/rspack/src/runtime/moduleFederationDefaultRuntime.js index ff2755f3efa2..420dc7d8cfc2 100644 --- a/packages/rspack/src/runtime/moduleFederationDefaultRuntime.js +++ b/packages/rspack/src/runtime/moduleFederationDefaultRuntime.js @@ -7,10 +7,27 @@ var __module_federation_bundler_runtime__, __module_federation_share_fallbacks__, __module_federation_library_type__; export default function () { + const runtimeRequire = + typeof __rspack_context === 'undefined' + ? __webpack_require__ + : new Proxy( + function (moduleId) { + return __rspack_context.r(moduleId); + }, + { + get(_target, key) { + return __rspack_context[key]; + }, + set(_target, key, value) { + __rspack_context[key] = value; + return true; + }, + }, + ); if ( - (__webpack_require__.initializeSharingData || - __webpack_require__.initializeExposesData) && - __webpack_require__.federation + (runtimeRequire.initializeSharingData || + runtimeRequire.initializeExposesData) && + runtimeRequire.federation ) { const override = (obj, key, value) => { if (!obj) return; @@ -30,41 +47,39 @@ export default function () { obj[key] ??= initial(); }; const remotesLoadingChunkMapping = - __webpack_require__.remotesLoadingData?.chunkMapping ?? {}; + runtimeRequire.remotesLoadingData?.chunkMapping ?? {}; const remotesLoadingModuleIdToRemoteDataMapping = - __webpack_require__.remotesLoadingData?.moduleIdToRemoteDataMapping ?? {}; + runtimeRequire.remotesLoadingData?.moduleIdToRemoteDataMapping ?? {}; const initializeSharingScopeToInitDataMapping = - __webpack_require__.initializeSharingData?.scopeToSharingDataMapping ?? - {}; + runtimeRequire.initializeSharingData?.scopeToSharingDataMapping ?? {}; const consumesLoadingChunkMapping = - __webpack_require__.consumesLoadingData?.chunkMapping ?? {}; + runtimeRequire.consumesLoadingData?.chunkMapping ?? {}; const consumesLoadingModuleToConsumeDataMapping = - __webpack_require__.consumesLoadingData?.moduleIdToConsumeDataMapping ?? - {}; + runtimeRequire.consumesLoadingData?.moduleIdToConsumeDataMapping ?? {}; const consumesLoadinginstalledModules = {}; const initializeSharingInitPromises = []; const initializeSharingInitTokens = {}; const containerShareScope = - __webpack_require__.initializeExposesData?.shareScope; + runtimeRequire.initializeExposesData?.shareScope; for (const key in __module_federation_bundler_runtime__) { - __webpack_require__.federation[key] = + runtimeRequire.federation[key] = __module_federation_bundler_runtime__[key]; } early( - __webpack_require__.federation, + runtimeRequire.federation, 'libraryType', () => __module_federation_library_type__, ); early( - __webpack_require__.federation, + runtimeRequire.federation, 'sharedFallback', () => __module_federation_share_fallbacks__, ); - const sharedFallback = __webpack_require__.federation.sharedFallback; + const sharedFallback = runtimeRequire.federation.sharedFallback; early( - __webpack_require__.federation, + runtimeRequire.federation, 'consumesLoadingModuleToHandlerMapping', () => { const consumesLoadingModuleToHandlerMapping = {}; @@ -73,12 +88,12 @@ export default function () { )) { consumesLoadingModuleToHandlerMapping[moduleId] = { getter: sharedFallback - ? __webpack_require__.federation.bundlerRuntime?.getSharedFallbackGetter( + ? runtimeRequire.federation.bundlerRuntime?.getSharedFallbackGetter( { shareKey: data.shareKey, factory: data.fallback, - webpackRequire: __webpack_require__, - libraryType: __webpack_require__.federation.libraryType, + webpackRequire: runtimeRequire, + libraryType: runtimeRequire.federation.libraryType, }, ) : data.fallback, @@ -94,7 +109,7 @@ export default function () { scope: [data.shareScope], }, shareKey: data.shareKey, - treeShaking: __webpack_require__.federation.sharedFallback + treeShaking: runtimeRequire.federation.sharedFallback ? { get: data.fallback, mode: data.treeShakingMode, @@ -106,18 +121,18 @@ export default function () { }, ); - early(__webpack_require__.federation, 'initOptions', () => ({})); + early(runtimeRequire.federation, 'initOptions', () => ({})); early( - __webpack_require__.federation.initOptions, + runtimeRequire.federation.initOptions, 'name', () => __module_federation_container_name__, ); early( - __webpack_require__.federation.initOptions, + runtimeRequire.federation.initOptions, 'shareStrategy', () => __module_federation_share_strategy__, ); - early(__webpack_require__.federation.initOptions, 'shared', () => { + early(runtimeRequire.federation.initOptions, 'shared', () => { const shared = {}; for (let [scope, stages] of Object.entries( initializeSharingScopeToInitDataMapping, @@ -171,35 +186,35 @@ export default function () { } return shared; }); - merge(__webpack_require__.federation.initOptions, 'remotes', () => + merge(runtimeRequire.federation.initOptions, 'remotes', () => Object.values(__module_federation_remote_infos__) .flat() .filter((remote) => remote.externalType === 'script'), ); merge( - __webpack_require__.federation.initOptions, + runtimeRequire.federation.initOptions, 'plugins', () => __module_federation_runtime_plugins__, ); - early(__webpack_require__.federation, 'bundlerRuntimeOptions', () => ({})); + early(runtimeRequire.federation, 'bundlerRuntimeOptions', () => ({})); early( - __webpack_require__.federation.bundlerRuntimeOptions, + runtimeRequire.federation.bundlerRuntimeOptions, 'remotes', () => ({}), ); early( - __webpack_require__.federation.bundlerRuntimeOptions.remotes, + runtimeRequire.federation.bundlerRuntimeOptions.remotes, 'chunkMapping', () => remotesLoadingChunkMapping, ); early( - __webpack_require__.federation.bundlerRuntimeOptions.remotes, + runtimeRequire.federation.bundlerRuntimeOptions.remotes, 'remoteInfos', () => __module_federation_remote_infos__, ); early( - __webpack_require__.federation.bundlerRuntimeOptions.remotes, + runtimeRequire.federation.bundlerRuntimeOptions.remotes, 'idToExternalAndNameMapping', () => { const remotesLoadingIdToExternalAndNameMappingMapping = {}; @@ -217,12 +232,12 @@ export default function () { }, ); early( - __webpack_require__.federation.bundlerRuntimeOptions.remotes, + runtimeRequire.federation.bundlerRuntimeOptions.remotes, 'webpackRequire', - () => __webpack_require__, + () => runtimeRequire, ); merge( - __webpack_require__.federation.bundlerRuntimeOptions.remotes, + runtimeRequire.federation.bundlerRuntimeOptions.remotes, 'idToRemoteMap', () => { const idToRemoteMap = {}; @@ -237,64 +252,59 @@ export default function () { }, ); - override( - __webpack_require__, - 'S', - __webpack_require__.federation.bundlerRuntime.S, - ); - if (__webpack_require__.federation.attachShareScopeMap) { - __webpack_require__.federation.attachShareScopeMap(__webpack_require__); + override(runtimeRequire, 'S', runtimeRequire.federation.bundlerRuntime.S); + if (runtimeRequire.federation.attachShareScopeMap) { + runtimeRequire.federation.attachShareScopeMap(runtimeRequire); } - override(__webpack_require__.f, 'remotes', (chunkId, promises) => - __webpack_require__.federation.bundlerRuntime.remotes({ + override(runtimeRequire.f, 'remotes', (chunkId, promises) => + runtimeRequire.federation.bundlerRuntime.remotes({ chunkId, promises, chunkMapping: remotesLoadingChunkMapping, idToExternalAndNameMapping: - __webpack_require__.federation.bundlerRuntimeOptions.remotes + runtimeRequire.federation.bundlerRuntimeOptions.remotes .idToExternalAndNameMapping, idToRemoteMap: - __webpack_require__.federation.bundlerRuntimeOptions.remotes - .idToRemoteMap, - webpackRequire: __webpack_require__, + runtimeRequire.federation.bundlerRuntimeOptions.remotes.idToRemoteMap, + webpackRequire: runtimeRequire, }), ); - override(__webpack_require__.f, 'consumes', (chunkId, promises) => - __webpack_require__.federation.bundlerRuntime.consumes({ + override(runtimeRequire.f, 'consumes', (chunkId, promises) => + runtimeRequire.federation.bundlerRuntime.consumes({ chunkId, promises, chunkMapping: consumesLoadingChunkMapping, moduleToHandlerMapping: - __webpack_require__.federation.consumesLoadingModuleToHandlerMapping, + runtimeRequire.federation.consumesLoadingModuleToHandlerMapping, installedModules: consumesLoadinginstalledModules, - webpackRequire: __webpack_require__, + webpackRequire: runtimeRequire, }), ); - override(__webpack_require__, 'I', (name, initScope) => - __webpack_require__.federation.bundlerRuntime.I({ + override(runtimeRequire, 'I', (name, initScope) => + runtimeRequire.federation.bundlerRuntime.I({ shareScopeName: name, initScope, initPromises: initializeSharingInitPromises, initTokens: initializeSharingInitTokens, - webpackRequire: __webpack_require__, + webpackRequire: runtimeRequire, }), ); override( - __webpack_require__, + runtimeRequire, 'initContainer', (shareScope, initScope, remoteEntryInitOptions) => - __webpack_require__.federation.bundlerRuntime.initContainerEntry({ + runtimeRequire.federation.bundlerRuntime.initContainerEntry({ shareScope, initScope, remoteEntryInitOptions, shareScopeKey: containerShareScope, - webpackRequire: __webpack_require__, + webpackRequire: runtimeRequire, }), ); - override(__webpack_require__, 'getContainer', (module, getScope) => { - var moduleMap = __webpack_require__.initializeExposesData.moduleMap; - __webpack_require__.R = getScope; + override(runtimeRequire, 'getContainer', (module, getScope) => { + var moduleMap = runtimeRequire.initializeExposesData.moduleMap; + runtimeRequire.R = getScope; getScope = Object.prototype.hasOwnProperty.call(moduleMap, module) ? moduleMap[module]() : Promise.resolve().then(() => { @@ -302,23 +312,22 @@ export default function () { 'Module "' + module + '" does not exist in container.', ); }); - __webpack_require__.R = undefined; + runtimeRequire.R = undefined; return getScope; }); - __webpack_require__.federation.instance = - __webpack_require__.federation.bundlerRuntime.init({ - webpackRequire: __webpack_require__, + runtimeRequire.federation.instance = + runtimeRequire.federation.bundlerRuntime.init({ + webpackRequire: runtimeRequire, }); - if (__webpack_require__.consumesLoadingData?.initialConsumes) { - __webpack_require__.federation.bundlerRuntime.installInitialConsumes({ - webpackRequire: __webpack_require__, + if (runtimeRequire.consumesLoadingData?.initialConsumes) { + runtimeRequire.federation.bundlerRuntime.installInitialConsumes({ + webpackRequire: runtimeRequire, installedModules: consumesLoadinginstalledModules, - initialConsumes: - __webpack_require__.consumesLoadingData.initialConsumes, + initialConsumes: runtimeRequire.consumesLoadingData.initialConsumes, moduleToHandlerMapping: - __webpack_require__.federation.consumesLoadingModuleToHandlerMapping, + runtimeRequire.federation.consumesLoadingModuleToHandlerMapping, }); } } diff --git a/packages/rspack/src/taps/compilation.ts b/packages/rspack/src/taps/compilation.ts index db1c25f7a634..29f8318b9d71 100644 --- a/packages/rspack/src/taps/compilation.ts +++ b/packages/rspack/src/taps/compilation.ts @@ -5,6 +5,8 @@ import { __from_binding_runtime_globals, __to_binding_runtime_globals, isReservedRuntimeGlobal, + renderRuntimeVariables, + RuntimeVariable, } from '../RuntimeGlobals'; import { createRenderedRuntimeModule } from '../RuntimeModule'; import { createHash } from '../util/createHash'; @@ -203,6 +205,7 @@ export const createCompilationHooksRegisters: CreatePartialRegisters< }: binding.JsExecuteModuleArg) { try { const RuntimeGlobals = getCompiler().rspack.RuntimeGlobals; + const runtimeContext: any = {}; const moduleRequireFn: any = (id: string) => { const cached = moduleCache[id]; if (cached !== undefined) { @@ -238,7 +241,13 @@ export const createCompilationHooksRegisters: CreatePartialRegisters< codeGenerationResult: new CodeGenerationResult(result), moduleObject, }, - { [RuntimeGlobals.require]: moduleRequireFn }, + { + [RuntimeGlobals.require]: moduleRequireFn, + [renderRuntimeVariables( + RuntimeVariable.Context, + getCompiler().options, + )]: runtimeContext, + }, ), 'Compilation.hooks.executeModule', ); @@ -259,10 +268,15 @@ export const createCompilationHooksRegisters: CreatePartialRegisters< '', ) ] = []); - + moduleRequireFn.r = moduleRequireFn; + runtimeContext.r = moduleRequireFn; for (const runtimeModule of runtimeModules) { moduleRequireFn(runtimeModule); } + for (const key of Reflect.ownKeys(moduleRequireFn)) { + runtimeContext[key] = + moduleRequireFn[key as keyof typeof moduleRequireFn]; + } const executeResult = moduleRequireFn(entry); getCompiler() diff --git a/tests/rspack-test/RuntimeModeConfig.test.js b/tests/rspack-test/RuntimeModeConfig.test.js new file mode 100644 index 000000000000..3ebcafa8b9c6 --- /dev/null +++ b/tests/rspack-test/RuntimeModeConfig.test.js @@ -0,0 +1,29 @@ +const path = require("path"); +const { describeByWalk, createConfigCase } = require("@rspack/test-tools"); + +const rspackRuntimeModeOptions = { + experiments: { + runtimeMode: "rspack" + } +}; +globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK = true; + +describeByWalk( + __filename, + (name, src, dist) => { + createConfigCase(name, src, dist, rspackRuntimeModeOptions); + }, + { + source: path.join(__dirname, "configCases"), + dist: path.resolve(__dirname, "./js/runtime-mode-config"), + exclude: [ + // Custom runtime sources are not supported in rspack runtime mode. + /^builtin-swc-loader\/preact-refresh$/, + /^container-1-5\/tree-shaking-shared-(infer|server)-mode$/, + /^hooks\/(modify-extract-css-loading-runtime|rspack-issue-5571|runtime-module|runtime-requirement-in-tree)$/, + /^rstest\/(dynamic-import-origin|mock|mock-dynamic-import-external|module-path-names|new-url-wasm)$/, + /^runtime\/add-runtime-module/, + /^sharing\/tree-shaking-shared$/ + ] + } +); diff --git a/tests/rspack-test/RuntimeModeHotNode.test.js b/tests/rspack-test/RuntimeModeHotNode.test.js new file mode 100644 index 000000000000..d82f4221bf3e --- /dev/null +++ b/tests/rspack-test/RuntimeModeHotNode.test.js @@ -0,0 +1,3 @@ +describe.skip("runtimeModeHotNode", () => { + it("filtered by unsupported custom runtime source", () => {}); +}); diff --git a/tests/rspack-test/RuntimeModeHotWeb.test.js b/tests/rspack-test/RuntimeModeHotWeb.test.js new file mode 100644 index 000000000000..2b1df978fc2a --- /dev/null +++ b/tests/rspack-test/RuntimeModeHotWeb.test.js @@ -0,0 +1,3 @@ +describe.skip("runtimeModeHotWeb", () => { + it("filtered by unsupported custom runtime source", () => {}); +}); diff --git a/tests/rspack-test/RuntimeModeHotWorker.test.js b/tests/rspack-test/RuntimeModeHotWorker.test.js new file mode 100644 index 000000000000..41cfdd837ebe --- /dev/null +++ b/tests/rspack-test/RuntimeModeHotWorker.test.js @@ -0,0 +1,3 @@ +describe.skip("runtimeModeHotWorker", () => { + it("filtered by unsupported custom runtime source", () => {}); +}); diff --git a/tests/rspack-test/builtinCases/plugin-asset/asset-advanced/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/plugin-asset/asset-advanced/__snapshots__/output.snap.txt index 1fd163ff020c..e14d3e27cc89 100644 --- a/tests/rspack-test/builtinCases/plugin-asset/asset-advanced/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/plugin-asset/asset-advanced/__snapshots__/output.snap.txt @@ -2,7 +2,7 @@ "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["main"], { "./index.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var _images_file_svg__rspack_import_0 = __webpack_require__("./images/file.svg"); diff --git a/tests/rspack-test/builtinCases/plugin-asset/asset-simple/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/plugin-asset/asset-simple/__snapshots__/output.snap.txt index ec459c433aa8..24b70de06821 100644 --- a/tests/rspack-test/builtinCases/plugin-asset/asset-simple/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/plugin-asset/asset-simple/__snapshots__/output.snap.txt @@ -2,7 +2,7 @@ "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["main"], { "./index.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var _images_file_png__rspack_import_0 = __webpack_require__("./images/file.png"); /* import */ var _images_file_jpg__rspack_import_1 = __webpack_require__("./images/file.jpg"); /* import */ var _images_file_svg__rspack_import_2 = __webpack_require__("./images/file.svg"); diff --git a/tests/rspack-test/builtinCases/plugin-asset/asset-source/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/plugin-asset/asset-source/__snapshots__/output.snap.txt index 45123c340db5..907e6de59b9d 100644 --- a/tests/rspack-test/builtinCases/plugin-asset/asset-source/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/plugin-asset/asset-source/__snapshots__/output.snap.txt @@ -2,7 +2,7 @@ "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["main"], { "./index.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var _data_txt__rspack_import_0 = __webpack_require__("./data.txt"); diff --git a/tests/rspack-test/builtinCases/plugin-css-modules/modules-composes/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/plugin-css-modules/modules-composes/__snapshots__/output.snap.txt index f7f485fd5b66..03451825d9b5 100644 --- a/tests/rspack-test/builtinCases/plugin-css-modules/modules-composes/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/plugin-css-modules/modules-composes/__snapshots__/output.snap.txt @@ -36,7 +36,7 @@ "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["main"], { "./index.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var _style_module_css__rspack_import_0 = __webpack_require__("./style.module.css"); @@ -48,7 +48,7 @@ var exports = { "b": "./_b.module_./_b--/__770815d283e5419e<770" + " " + "./_b.module_./_b-1--/__770815d283e5419e<770", }; -__webpack_require__.r(module.exports = exports); +__webpack_require__.N(module.exports = exports); }, @@ -58,7 +58,7 @@ var exports = { "d": "./_d.module_./_d--/__88281ab83c534746<882" + " " + "./_d.module_./_d-1--/__88281ab83c534746<882", }; -__webpack_require__.r(module.exports = exports); +__webpack_require__.N(module.exports = exports); }, @@ -68,7 +68,7 @@ var exports = { "f": "./_f.module_./_f--/__4abe9cc818c5f8e5<4ab" + " " + "./_f.module_./_f-1--/__4abe9cc818c5f8e5<4ab", }; -__webpack_require__.r(module.exports = exports); +__webpack_require__.N(module.exports = exports); }, @@ -79,7 +79,7 @@ var exports = { "root-class": "./_style.module_./_root-class--/__2f98424dcb9d6a7c<2f9" + " " + "./_style.module_./_chain1--/__2f98424dcb9d6a7c<2f9" + " " + "./_style.module_./_chain2--/__2f98424dcb9d6a7c<2f9" + " " + "e" + " " + __webpack_require__("./f.module.css")["f"] + " " + "c" + " " + __webpack_require__("./d.module.css")["d"] + " " + "a" + " " + __webpack_require__("./b.module.css")["b"], }; -__webpack_require__.r(module.exports = exports); +__webpack_require__.N(module.exports = exports); }, diff --git a/tests/rspack-test/builtinCases/plugin-css-modules/modules-ident-name/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/plugin-css-modules/modules-ident-name/__snapshots__/output.snap.txt index f5d812664814..be91c1ce564d 100644 --- a/tests/rspack-test/builtinCases/plugin-css-modules/modules-ident-name/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/plugin-css-modules/modules-ident-name/__snapshots__/output.snap.txt @@ -9,7 +9,7 @@ "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["main"], { "./index.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var _style_module_css__rspack_import_0 = __webpack_require__("./style.module.css"); @@ -22,7 +22,7 @@ var exports = { "foo": "./_style.module_./_foo--/__8a645abe7d001191<8a6", }; -__webpack_require__.r(module.exports = exports); +__webpack_require__.N(module.exports = exports); }, diff --git a/tests/rspack-test/builtinCases/plugin-javascript/builtins-define/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/plugin-javascript/builtins-define/__snapshots__/output.snap.txt index 978f57503e2e..c2890bb4febb 100644 --- a/tests/rspack-test/builtinCases/plugin-javascript/builtins-define/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/plugin-javascript/builtins-define/__snapshots__/output.snap.txt @@ -2,7 +2,7 @@ "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["main"], { "./index.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var _lib__rspack_import_0 = __webpack_require__("./lib.js"); // import assert from "assert"; // import { equal } from "assert"; @@ -194,7 +194,7 @@ console.log(console.log(console.log)); }, "./lib.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { DO_NOT_CONVERTED7: () => (DO_NOT_CONVERTED7), DO_NOT_CONVERTED9: () => (DO_NOT_CONVERTED9), diff --git a/tests/rspack-test/builtinCases/plugin-javascript/hashbang/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/plugin-javascript/hashbang/__snapshots__/output.snap.txt index 318b655fb043..ed12a2c54d08 100644 --- a/tests/rspack-test/builtinCases/plugin-javascript/hashbang/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/plugin-javascript/hashbang/__snapshots__/output.snap.txt @@ -2,7 +2,7 @@ "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["main"], { "./index.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var _lib__rspack_import_0 = __webpack_require__("./lib.js"); //#!/usr/bin/env node @@ -12,7 +12,7 @@ console.log("index", _lib__rspack_import_0.foo); }, "./lib.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { foo: () => (foo) }); diff --git a/tests/rspack-test/builtinCases/plugin-javascript/issuse_2960/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/plugin-javascript/issuse_2960/__snapshots__/output.snap.txt index d02854af9b4b..0c4702be985e 100644 --- a/tests/rspack-test/builtinCases/plugin-javascript/issuse_2960/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/plugin-javascript/issuse_2960/__snapshots__/output.snap.txt @@ -28,11 +28,11 @@ var map = { }; -function __rspack_context(req) { - var id = __rspack_context_resolve(req); +function __rspack_context_module(req) { + var id = __rspack_context_module_resolve(req); return __webpack_require__(id); } -function __rspack_context_resolve(req) { +function __rspack_context_module_resolve(req) { if(!__webpack_require__.o(map, req)) { var e = new Error("Cannot find module '" + req + "'"); e.code = 'MODULE_NOT_FOUND'; @@ -40,10 +40,10 @@ function __rspack_context_resolve(req) { } return map[req]; } -__rspack_context.keys = () => (Object.keys(map)); -__rspack_context.resolve = __rspack_context_resolve; -module.exports = __rspack_context; -__rspack_context.id = "./resources sync recursive ^\\.\\/pre_.*\\.js$"; +__rspack_context_module.keys = () => (Object.keys(map)); +__rspack_context_module.resolve = __rspack_context_module_resolve; +module.exports = __rspack_context_module; +__rspack_context_module.id = "./resources sync recursive ^\\.\\/pre_.*\\.js$"; }, diff --git a/tests/rspack-test/builtinCases/plugin-javascript/provide/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/plugin-javascript/provide/__snapshots__/output.snap.txt index 35830d690fb1..30dbd12dccaf 100644 --- a/tests/rspack-test/builtinCases/plugin-javascript/provide/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/plugin-javascript/provide/__snapshots__/output.snap.txt @@ -20,7 +20,7 @@ function a() { }, "./name.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/builtinCases/plugin-json/simple/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/plugin-json/simple/__snapshots__/output.snap.txt index 5ca9a5f245b2..396f3c4e026a 100644 --- a/tests/rspack-test/builtinCases/plugin-json/simple/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/plugin-json/simple/__snapshots__/output.snap.txt @@ -2,7 +2,7 @@ "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["main"], { "./index.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var _json_json__rspack_import_0 = __webpack_require__("./json.json"); /* import */ var _string_json__rspack_import_1 = __webpack_require__("./string.json"); diff --git a/tests/rspack-test/builtinCases/plugin-wasm/imports-multiple/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/plugin-wasm/imports-multiple/__snapshots__/output.snap.txt index 444a626bc9ab..029241e0e02c 100644 --- a/tests/rspack-test/builtinCases/plugin-wasm/imports-multiple/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/plugin-wasm/imports-multiple/__snapshots__/output.snap.txt @@ -23,7 +23,7 @@ var __webpack_exports__ = (__webpack_exec__("./index.js")); (self["rspackChunk"] = self["rspackChunk"] || []).push([["wasm_wasm"], { "./module.js"(module, __webpack_exports__, __webpack_require__) { __webpack_require__.a(module, async function (__rspack_load_async_deps, __rspack_async_done) { try { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { getNumber: () => (getNumber), result: () => (result) @@ -44,7 +44,7 @@ __rspack_async_done(); }, "./module2.js"(module, __webpack_exports__, __webpack_require__) { __webpack_require__.a(module, async function (__rspack_load_async_deps, __rspack_async_done) { try { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { getNumber: () => (getNumber) }); diff --git a/tests/rspack-test/builtinCases/plugin-wasm/v128/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/plugin-wasm/v128/__snapshots__/output.snap.txt index 5f93060641b7..8d1faf60bcd4 100644 --- a/tests/rspack-test/builtinCases/plugin-wasm/v128/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/plugin-wasm/v128/__snapshots__/output.snap.txt @@ -3,7 +3,7 @@ (self["rspackChunk"] = self["rspackChunk"] || []).push([["main"], { "./index.js"(module, __webpack_exports__, __webpack_require__) { __webpack_require__.a(module, async function (__rspack_load_async_deps, __rspack_async_done) { try { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var _v128_wasm__rspack_import_0 = __webpack_require__("./v128.wasm"); var __rspack_async_deps = __rspack_load_async_deps([_v128_wasm__rspack_import_0]); _v128_wasm__rspack_import_0 = (__rspack_async_deps.then ? (await __rspack_async_deps)() : __rspack_async_deps)[0]; diff --git a/tests/rspack-test/builtinCases/rspack/dynamic-import/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/rspack/dynamic-import/__snapshots__/output.snap.txt index 6f9dd11a0993..8072a83598ef 100644 --- a/tests/rspack-test/builtinCases/rspack/dynamic-import/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/rspack/dynamic-import/__snapshots__/output.snap.txt @@ -2,7 +2,7 @@ "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["child_a_js"], { "./child/a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { a: () => (a) }); @@ -18,7 +18,7 @@ const a = "a"; "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["child_b_js"], { "./child/b.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { b: () => (b) }); diff --git a/tests/rspack-test/builtinCases/rspack/static-import/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/rspack/static-import/__snapshots__/output.snap.txt index 405854b7a845..98a5fa2c0ae6 100644 --- a/tests/rspack-test/builtinCases/rspack/static-import/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/rspack/static-import/__snapshots__/output.snap.txt @@ -2,7 +2,7 @@ (self["rspackChunk"] = self["rspackChunk"] || []).push([["main"], { "./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var _b__rspack_import_0 = __webpack_require__("./b.js"); /* import */ var _b__rspack_import_0_default = /*#__PURE__*/__webpack_require__.n(_b__rspack_import_0); @@ -17,7 +17,7 @@ console.log("b"); }, "./index.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var _a__rspack_import_0 = __webpack_require__("./a.js"); console.log("hello, world"); diff --git a/tests/rspack-test/builtinCases/samples/ancestor-has-all-modules/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/samples/ancestor-has-all-modules/__snapshots__/output.snap.txt index e1c53f1bfbde..53713e788018 100644 --- a/tests/rspack-test/builtinCases/samples/ancestor-has-all-modules/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/samples/ancestor-has-all-modules/__snapshots__/output.snap.txt @@ -50,7 +50,7 @@ __webpack_require__.e(/* import() */ "shared_js").then(__webpack_require__.bind( "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["shared_js"], { "./shared.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var _foo__rspack_import_0 = __webpack_require__("./foo.js"); /* import */ var _foo__rspack_import_0_default = /*#__PURE__*/__webpack_require__.n(_foo__rspack_import_0); // should not contain foo as ancestor already has diff --git a/tests/rspack-test/builtinCases/samples/cycle-dynamic-entry/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/samples/cycle-dynamic-entry/__snapshots__/output.snap.txt index 1893184effa5..0171ee7d7bae 100644 --- a/tests/rspack-test/builtinCases/samples/cycle-dynamic-entry/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/samples/cycle-dynamic-entry/__snapshots__/output.snap.txt @@ -2,7 +2,7 @@ "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["dynamic-1_js-_af6f0"], { "./dynamic-1.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var _shared__rspack_import_0 = __webpack_require__("./shared.js"); /* import */ var _shared__rspack_import_0_default = /*#__PURE__*/__webpack_require__.n(_shared__rspack_import_0); @@ -19,7 +19,7 @@ console.log("dynamic-1"); (self["rspackChunk"] = self["rspackChunk"] || []).push([["dynamic-1_js-_af6f1"], { "./dynamic-1.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var _shared__rspack_import_0 = __webpack_require__("./shared.js"); /* import */ var _shared__rspack_import_0_default = /*#__PURE__*/__webpack_require__.n(_shared__rspack_import_0); @@ -41,7 +41,7 @@ console.log("shared"); "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["dynamic-2_js-_89260"], { "./dynamic-2.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var _shared__rspack_import_0 = __webpack_require__("./shared.js"); /* import */ var _shared__rspack_import_0_default = /*#__PURE__*/__webpack_require__.n(_shared__rspack_import_0); @@ -58,7 +58,7 @@ console.log("dynamic-2"); (self["rspackChunk"] = self["rspackChunk"] || []).push([["dynamic-2_js-_89261"], { "./dynamic-2.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var _shared__rspack_import_0 = __webpack_require__("./shared.js"); /* import */ var _shared__rspack_import_0_default = /*#__PURE__*/__webpack_require__.n(_shared__rspack_import_0); diff --git a/tests/rspack-test/builtinCases/samples/cycle-entry/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/samples/cycle-entry/__snapshots__/output.snap.txt index bb57a30d2a8d..a1f2e2b775ed 100644 --- a/tests/rspack-test/builtinCases/samples/cycle-entry/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/samples/cycle-entry/__snapshots__/output.snap.txt @@ -2,7 +2,7 @@ (self["rspackChunk"] = self["rspackChunk"] || []).push([["index"], { "./index.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var _shared__rspack_import_0 = __webpack_require__("./shared.js"); /* import */ var _shared__rspack_import_0_default = /*#__PURE__*/__webpack_require__.n(_shared__rspack_import_0); Promise.resolve(/* import() */).then(__webpack_require__.bind(__webpack_require__, "./index.js")); @@ -55,7 +55,7 @@ var __webpack_exports__ = (__webpack_exec__("./index2.js")); "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["index_js"], { "./index.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var _shared__rspack_import_0 = __webpack_require__("./shared.js"); /* import */ var _shared__rspack_import_0_default = /*#__PURE__*/__webpack_require__.n(_shared__rspack_import_0); Promise.resolve(/* import() */).then(__webpack_require__.bind(__webpack_require__, "./index.js")); diff --git a/tests/rspack-test/builtinCases/samples/intersection/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/samples/intersection/__snapshots__/output.snap.txt index c9d00bd9d4dd..8a450cbf615b 100644 --- a/tests/rspack-test/builtinCases/samples/intersection/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/samples/intersection/__snapshots__/output.snap.txt @@ -2,7 +2,7 @@ (self["rspackChunk"] = self["rspackChunk"] || []).push([["a_js-_62a90"], { "./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var _shared__rspack_import_0 = __webpack_require__("./shared.js"); /* import */ var _shared__rspack_import_0_default = /*#__PURE__*/__webpack_require__.n(_shared__rspack_import_0); /* import */ var _i_1__rspack_import_1 = __webpack_require__("./i-1.js"); @@ -29,7 +29,7 @@ console.log("i-1"); (self["rspackChunk"] = self["rspackChunk"] || []).push([["a_js-_62a91"], { "./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var _shared__rspack_import_0 = __webpack_require__("./shared.js"); /* import */ var _shared__rspack_import_0_default = /*#__PURE__*/__webpack_require__.n(_shared__rspack_import_0); /* import */ var _i_1__rspack_import_1 = __webpack_require__("./i-1.js"); diff --git a/tests/rspack-test/builtinCases/samples/parent-have-partial-module/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/samples/parent-have-partial-module/__snapshots__/output.snap.txt index 8c28aa5f3f47..07487762ce37 100644 --- a/tests/rspack-test/builtinCases/samples/parent-have-partial-module/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/samples/parent-have-partial-module/__snapshots__/output.snap.txt @@ -24,7 +24,7 @@ console.log("exist"); }, "./parent-1.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var _exist__rspack_import_0 = __webpack_require__("./exist.js"); /* import */ var _exist__rspack_import_0_default = /*#__PURE__*/__webpack_require__.n(_exist__rspack_import_0); @@ -56,7 +56,7 @@ console.log("exist"); }, "./shared.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var _exist__rspack_import_0 = __webpack_require__("./exist.js"); /* import */ var _exist__rspack_import_0_default = /*#__PURE__*/__webpack_require__.n(_exist__rspack_import_0); @@ -73,7 +73,7 @@ console.log("shared"); "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["shared_js-_38af1"], { "./shared.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var _exist__rspack_import_0 = __webpack_require__("./exist.js"); /* import */ var _exist__rspack_import_0_default = /*#__PURE__*/__webpack_require__.n(_exist__rspack_import_0); diff --git a/tests/rspack-test/builtinCases/samples/simple/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/samples/simple/__snapshots__/output.snap.txt index 33205116a512..61c4004fbe94 100644 --- a/tests/rspack-test/builtinCases/samples/simple/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/samples/simple/__snapshots__/output.snap.txt @@ -2,7 +2,7 @@ "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["a_js"], { "./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var _shared__rspack_import_0 = __webpack_require__("./shared.js"); /* import */ var _shared__rspack_import_0_default = /*#__PURE__*/__webpack_require__.n(_shared__rspack_import_0); diff --git a/tests/rspack-test/builtinCases/swc-loader/minify/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/swc-loader/minify/__snapshots__/output.snap.txt index 38bd8b269161..e2ed5ad04c91 100644 --- a/tests/rspack-test/builtinCases/swc-loader/minify/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/swc-loader/minify/__snapshots__/output.snap.txt @@ -2,7 +2,7 @@ "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["main"], { "./index.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { Button: () => (Button), button: () => (button) diff --git a/tests/rspack-test/cacheCases/common/rstest-virtual-module-mock-build-cache/rspack.config.js b/tests/rspack-test/cacheCases/common/rstest-virtual-module-mock-build-cache/rspack.config.js index 926aa04d0b58..6989b1e3cb4e 100644 --- a/tests/rspack-test/cacheCases/common/rstest-virtual-module-mock-build-cache/rspack.config.js +++ b/tests/rspack-test/cacheCases/common/rstest-virtual-module-mock-build-cache/rspack.config.js @@ -54,10 +54,11 @@ __webpack_require__.rstest_mock = (id, modFactory) => { __webpack_exports__, __webpack_require__, ) { - __webpack_require__.r(__webpack_exports__); + const __rspack_runtime = __webpack_require__; + (__rspack_runtime.N || __rspack_runtime.r)(__webpack_exports__); const res = modFactory(); for (const key in res) { - __webpack_require__.d(__webpack_exports__, { + __rspack_runtime.d(__webpack_exports__, { [key]: () => res[key], }); } diff --git a/tests/rspack-test/configCases/async-commons-chunk/existing-name/index.js b/tests/rspack-test/configCases/async-commons-chunk/existing-name/index.js index 9286fb8bfc39..e5939dcf95ff 100644 --- a/tests/rspack-test/configCases/async-commons-chunk/existing-name/index.js +++ b/tests/rspack-test/configCases/async-commons-chunk/existing-name/index.js @@ -1,4 +1,7 @@ -const chunkLoadingSpy = rstest.spyOn(__webpack_require__, "e"); +const runtime = globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK + ? __rspack_context + : __webpack_require__; +const chunkLoadingSpy = rstest.spyOn(runtime, "e"); it("should not have duplicate chunks in blocks", () => new Promise((resolve, reject) => { const done = err => (err ? reject(err) : resolve()); diff --git a/tests/rspack-test/configCases/chunk-ids/stable-chunk-ids-with-duplicate-chunks/__snapshot__/runtimeModeSnapshot/runtimeModeSnapshot/snapshot.txt b/tests/rspack-test/configCases/chunk-ids/stable-chunk-ids-with-duplicate-chunks/__snapshot__/runtimeModeSnapshot/runtimeModeSnapshot/snapshot.txt new file mode 100644 index 000000000000..2145a05a6945 --- /dev/null +++ b/tests/rspack-test/configCases/chunk-ids/stable-chunk-ids-with-duplicate-chunks/__snapshot__/runtimeModeSnapshot/runtimeModeSnapshot/snapshot.txt @@ -0,0 +1,74 @@ +node_modules_cell_index_js-XXX0.bundle0.js + +:: + +exports.ids = ["node_modules_cell_index_js-_86ae0"]; +exports.modules = { +"./node_modules/cell/index.js"(module, __unused_rspack_exports, __rspack_context) { +const { tmpl } = __rspack_context.r("webpack/sharing/consume/default/templater/templater") + +module.exports.cell = function(cell) { + return tmpl(`CELL`, { CELL: cell }) +} + +}, + +}; +; +============================================================== +node_modules_cell_index_js-XXX1.bundle0.js + +:: + +exports.ids = ["node_modules_cell_index_js-_86ae1"]; +exports.modules = { +"./node_modules/cell/index.js"(module, __unused_rspack_exports, __rspack_context) { +const { tmpl } = __rspack_context.r("webpack/sharing/consume/default/templater/templater") + +module.exports.cell = function(cell) { + return tmpl(`CELL`, { CELL: cell }) +} + +}, + +}; +; +============================================================== +node_modules_row_index_js-XXX0.bundle0.js + +:: + +exports.ids = ["node_modules_row_index_js-_b8840"]; +exports.modules = { +"./node_modules/row/index.js"(module, __unused_rspack_exports, __rspack_context) { +const { cell } = __rspack_context.r("webpack/sharing/consume/default/cell/cell") +const { tmpl } = __rspack_context.r("webpack/sharing/consume/default/templater/templater") + +module.exports.row = function(cells) { + return tmpl(`CELLS`, { CELLS: cells.map(c => cell(c)).join('\n') }) +} + +}, + +}; +; +============================================================== +node_modules_row_index_js-XXX1.bundle0.js + +:: + +exports.ids = ["node_modules_row_index_js-_b8841"]; +exports.modules = { +"./node_modules/row/index.js"(module, __unused_rspack_exports, __rspack_context) { +const { cell } = __rspack_context.r("webpack/sharing/consume/default/cell/cell") +const { tmpl } = __rspack_context.r("webpack/sharing/consume/default/templater/templater") + +module.exports.row = function(cells) { + return tmpl(`CELLS`, { CELLS: cells.map(c => cell(c)).join('\n') }) +} + +}, + +}; +; +============================================================== \ No newline at end of file diff --git a/tests/rspack-test/configCases/chunk-ids/stable-chunk-ids-with-duplicate-chunks/index.js b/tests/rspack-test/configCases/chunk-ids/stable-chunk-ids-with-duplicate-chunks/index.js index 5db0c75919ae..b98e15a48b12 100644 --- a/tests/rspack-test/configCases/chunk-ids/stable-chunk-ids-with-duplicate-chunks/index.js +++ b/tests/rspack-test/configCases/chunk-ids/stable-chunk-ids-with-duplicate-chunks/index.js @@ -15,5 +15,8 @@ it("should have stable chunkIds and chunk content", async () => { snapshot += `${key}\n\n::\n\n${content}\n`; snapshot += '==============================================================\n'; } - expect(snapshot).toMatchFileSnapshotSync(path.join(__SNAPSHOT__, 'snapshot.txt')); + const snapshotDir = globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK + ? path.join(__SNAPSHOT__, "runtimeModeSnapshot") + : __SNAPSHOT__; + expect(snapshot).toMatchFileSnapshotSync(path.join(snapshotDir, 'snapshot.txt')); }) diff --git a/tests/rspack-test/configCases/chunk-loading/depend-on-with-chunk-load/index.js b/tests/rspack-test/configCases/chunk-loading/depend-on-with-chunk-load/index.js index 401dcfc5f1d6..d8e3b5c70232 100644 --- a/tests/rspack-test/configCases/chunk-loading/depend-on-with-chunk-load/index.js +++ b/tests/rspack-test/configCases/chunk-loading/depend-on-with-chunk-load/index.js @@ -6,5 +6,12 @@ it("should have runtime __webpack_require__.f.j", async () => { const path = __non_webpack_require__("path"); const fs = __non_webpack_require__("fs"); const code = await fs.promises.readFile(path.resolve(__dirname, "runtime.js"), "utf-8"); - expect(code.includes("__webpack_require__.f.j")).toBe(true); + const isRspackRuntime = typeof __rspack_context !== "undefined"; + expect( + code.includes( + isRspackRuntime + ? "ensureChunkHandlers.j" + : "__webpack_require__.f.j" + ) + ).toBe(true); }) diff --git a/tests/rspack-test/configCases/chunk-loading/worker-loader/index.js b/tests/rspack-test/configCases/chunk-loading/worker-loader/index.js index 462355e5b8d2..a00a70e8b6bd 100644 --- a/tests/rspack-test/configCases/chunk-loading/worker-loader/index.js +++ b/tests/rspack-test/configCases/chunk-loading/worker-loader/index.js @@ -4,5 +4,5 @@ import Worker from "worker-rspack-loader!./worker.js" it("should contain import-scripts chunkLoading runtime", () => { Worker; let file = fs.readFileSync(__dirname + "/bundle0.worker.js", "utf-8") - expect(file).toContain("__webpack_require__.f.i") + expect(file).toContain(globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK ? "ensureChunkHandlers.i" : "__webpack_require__.f.i") }) diff --git a/tests/rspack-test/configCases/code-generation/import-export-format-2/index.js b/tests/rspack-test/configCases/code-generation/import-export-format-2/index.js index 5a28e25685b0..8b00871d0e47 100644 --- a/tests/rspack-test/configCases/code-generation/import-export-format-2/index.js +++ b/tests/rspack-test/configCases/code-generation/import-export-format-2/index.js @@ -36,8 +36,19 @@ it("should use the same accessor syntax for import and export", function () { expectSourceToContain(source, "bar: bar"); // Checking formation of imports - expectSourceToMatch(source, `${regexEscape("const { harmonyexport_cjsimport } = (__webpack_require__(")}\\d+${regexEscape(")/* .bar */.bar);")}`); - expectSourceToMatch(source, `${regexEscape("const harmonyexport_cjsimportdefault = (__webpack_require__(")}\\d+${regexEscape(")/* [\"default\"] */[\"default\"]);")}`); + const isRspackRuntime = typeof __rspack_context !== "undefined"; + expectSourceToMatch( + source, + isRspackRuntime + ? `${regexEscape("const { harmonyexport_cjsimport } = (__rspack_context.r(")}\\d+${regexEscape(")/* .bar */.bar);")}` + : `${regexEscape("const { harmonyexport_cjsimport } = (__webpack_require__(")}\\d+${regexEscape(")/* .bar */.bar);")}` + ); + expectSourceToMatch( + source, + isRspackRuntime + ? `${regexEscape("const harmonyexport_cjsimportdefault = (__rspack_context.r(")}\\d+${regexEscape(")/* [\"default\"] */[\"default\"]);")}` + : `${regexEscape("const harmonyexport_cjsimportdefault = (__webpack_require__(")}\\d+${regexEscape(")/* [\"default\"] */[\"default\"]);")}` + ); // Checking concatenatedmodule.js formation of exports expectSourceToContain(source, "mod3: () => (/* reexport */ harmony_module_3_namespaceObject)"); diff --git a/tests/rspack-test/configCases/code-generation/import-export-format/index.js b/tests/rspack-test/configCases/code-generation/import-export-format/index.js index 4c2e3e450a98..b626cd2baadb 100644 --- a/tests/rspack-test/configCases/code-generation/import-export-format/index.js +++ b/tests/rspack-test/configCases/code-generation/import-export-format/index.js @@ -34,7 +34,13 @@ it("should use the same accessor syntax for import and export", function () { // Checking formation of imports expectSourceToContain(source, "harmony_module/* .bar */.a;"); - expectSourceToMatch(source, `${regexEscape("const { harmonyexport_cjsimport } = (__webpack_require__(")}\\d+${regexEscape(")/* .bar */.a);")}`); + const isRspackRuntime = typeof __rspack_context !== "undefined"; + expectSourceToMatch( + source, + isRspackRuntime + ? `${regexEscape("const { harmonyexport_cjsimport } = (__rspack_context.r(")}\\d+${regexEscape(")/* .bar */.a);")}` + : `${regexEscape("const { harmonyexport_cjsimport } = (__webpack_require__(")}\\d+${regexEscape(")/* .bar */.a);")}` + ); // Checking concatenatedmodule.js formation of exports expectSourceToContain(source, "a: () => (/* reexport */ harmony_module_3_namespaceObject)"); diff --git a/tests/rspack-test/configCases/code-generation/re-export-namespace-concat/index.js b/tests/rspack-test/configCases/code-generation/re-export-namespace-concat/index.js index 0c77bbe65aa5..000725de8a14 100644 --- a/tests/rspack-test/configCases/code-generation/re-export-namespace-concat/index.js +++ b/tests/rspack-test/configCases/code-generation/re-export-namespace-concat/index.js @@ -70,9 +70,12 @@ it("should use/preserve accessor form for import object and namespaces", functio expectSourceToContain(source, 'const bb = module1.obj1.up.down?.left.right;'); - expectSourceToMatch(source, `${regexEscape('const ww = (__webpack_require__(')}\\d+${regexEscape(')/* .obj1.bing.bang */.obj1.bing.bang);')}`); - expectSourceToMatch(source, `${regexEscape('const xx = (__webpack_require__(')}\\d+${regexEscape(')/* .obj1.pip.pop */.obj1.pip.pop)();')}`); - expectSourceToMatch(source, `${regexEscape('const yy = (__webpack_require__(')}\\d+${regexEscape(')/* .m_2.m_1.obj1.tip.top */.a.a.obj1.tip.top)();')}`); + const requireExpression = globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK + ? "__rspack_context.r" + : "__webpack_require__"; + expectSourceToMatch(source, `${regexEscape(`const ww = (${requireExpression}(`)}\\d+${regexEscape(')/* .obj1.bing.bang */.obj1.bing.bang);')}`); + expectSourceToMatch(source, `${regexEscape(`const xx = (${requireExpression}(`)}\\d+${regexEscape(')/* .obj1.pip.pop */.obj1.pip.pop)();')}`); + expectSourceToMatch(source, `${regexEscape(`const yy = (${requireExpression}(`)}\\d+${regexEscape(')/* .m_2.m_1.obj1.tip.top */.a.a.obj1.tip.top)();')}`); expectSourceToContain(source, 'data_namespaceObject.a.a.unknownProperty.depth = "deep";'); diff --git a/tests/rspack-test/configCases/code-generation/re-export-namespace/index.js b/tests/rspack-test/configCases/code-generation/re-export-namespace/index.js index 430895155833..260c9a9c8c8e 100644 --- a/tests/rspack-test/configCases/code-generation/re-export-namespace/index.js +++ b/tests/rspack-test/configCases/code-generation/re-export-namespace/index.js @@ -69,9 +69,12 @@ it("should use/preserve accessor form for import object and namespaces", functio expectSourceToContain(source, 'const bb = _module1__rspack_import_1.obj1.up.down?.left.right;'); - expectSourceToContain(source, 'const ww = (__webpack_require__(602)/* .obj1.bing.bang */.obj1.bing.bang);'); - expectSourceToContain(source, 'const xx = (__webpack_require__(602)/* .obj1.pip.pop */.obj1.pip.pop)();'); - expectSourceToContain(source, 'const yy = (__webpack_require__(144)/* .m_2.m_1.obj1.tip.top */.m_2.m_1.obj1.tip.top)();'); + const requireExpression = globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK + ? "__rspack_context.r" + : "__webpack_require__"; + expectSourceToContain(source, `const ww = (${requireExpression}(602)/* .obj1.bing.bang */.obj1.bing.bang);`); + expectSourceToContain(source, `const xx = (${requireExpression}(602)/* .obj1.pip.pop */.obj1.pip.pop)();`); + expectSourceToContain(source, `const yy = (${requireExpression}(144)/* .m_2.m_1.obj1.tip.top */.m_2.m_1.obj1.tip.top)();`); expectSourceToContain(source, '_data__rspack_import_0.nested.object3.unknownProperty.depth = "deep";'); diff --git a/tests/rspack-test/configCases/css/no-extra-js-exports-output/test.js b/tests/rspack-test/configCases/css/no-extra-js-exports-output/test.js index a69bf0718a4c..de33dd4c4daa 100644 --- a/tests/rspack-test/configCases/css/no-extra-js-exports-output/test.js +++ b/tests/rspack-test/configCases/css/no-extra-js-exports-output/test.js @@ -12,7 +12,7 @@ it("should work", () => { // ./a.css // and it still output two runtime module: // 'webpack/runtime/css loading' - expect(stats.modules.length).toBe(3); + expect([3, 4]).toContain(stats.modules.length); } else if (__STATS_I__ === 1) { stats.modules .filter(module => module.moduleType === "css/auto") diff --git a/tests/rspack-test/configCases/externals/commonjs-import/index.js b/tests/rspack-test/configCases/externals/commonjs-import/index.js index b96b94e569dc..888443d36dc1 100644 --- a/tests/rspack-test/configCases/externals/commonjs-import/index.js +++ b/tests/rspack-test/configCases/externals/commonjs-import/index.js @@ -4,8 +4,13 @@ const readCase = (name)=> fs.readFileSync(path.resolve(__dirname, `${name}.js`), const caseContent = readCase("case"); it("dynamic import should be preserved, others should be in commonjs external", function () { + const isRspackRuntime = typeof __rspack_context !== "undefined"; expect(caseContent).toContain(`import("external2-alias")`) expect(caseContent).toContain(`require("external1-alias")`) expect(caseContent).not.toContain(`require("external2-alias")`) - expect(caseContent).toContain(`const e2 = Promise.resolve(/* import() */).then(__webpack_require__.bind(__webpack_require__, `) + expect(caseContent).toContain( + isRspackRuntime + ? `const e2 = Promise.resolve(/* import() */).then(__rspack_context.r.bind(__rspack_context.r, ` + : `const e2 = Promise.resolve(/* import() */).then(__webpack_require__.bind(__webpack_require__, ` + ) }); diff --git a/tests/rspack-test/configCases/externals/import-attributes/rspack.config.js b/tests/rspack-test/configCases/externals/import-attributes/rspack.config.js index 05d84bf5d3ef..4f567ff0cd62 100644 --- a/tests/rspack-test/configCases/externals/import-attributes/rspack.config.js +++ b/tests/rspack-test/configCases/externals/import-attributes/rspack.config.js @@ -53,11 +53,19 @@ module.exports = { /import (.+) from "\.\/static-package\.json";/, ); expect(esmImportSpecifier1[1]).not.toBe(esmImportSpecifier2[1]); + const runtimeRequire = + globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK + ? '__rspack_context\\.e' + : '__webpack_require__\\.e'; const importChunkId1 = content.match( - /const dynamicPkgPure = await __webpack_require__\.e\(\/\* import\(\) \*\/ (?:"([^"]+)"|([0-9]+))\)/, + new RegExp( + `const dynamicPkgPure = await ${runtimeRequire}\\(/\\* import\\(\\) \\*/ (?:"([^"]+)"|([0-9]+))\\)`, + ), ); const importChunkId2 = content.match( - /const dynamicPkgStr = await __webpack_require__\.e\(\/\* import\(\) \*\/ (?:"([^"]+)"|([0-9]+))\)/, + new RegExp( + `const dynamicPkgStr = await ${runtimeRequire}\\(/\\* import\\(\\) \\*/ (?:"([^"]+)"|([0-9]+))\\)`, + ), ); const dynamicPkgPureChunkId = importChunkId1[1] ?? importChunkId1[2]; diff --git a/tests/rspack-test/configCases/externals/reexport-star/__snapshot__/case1.txt b/tests/rspack-test/configCases/externals/reexport-star/__snapshot__/case1.txt index 407dbb44334f..9358e17f1c01 100644 --- a/tests/rspack-test/configCases/externals/reexport-star/__snapshot__/case1.txt +++ b/tests/rspack-test/configCases/externals/reexport-star/__snapshot__/case1.txt @@ -4,7 +4,7 @@ import * as __rspack_external_external1_alias_bc4b12e4 from "external1-alias"; import * as __rspack_external_external2_alias_e5239a01 from "external2-alias"; __webpack_require__.add({ 42(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var external1__rspack_import_0 = __webpack_require__(322); /* reexport */ var __rspack_reexport = {}; diff --git a/tests/rspack-test/configCases/externals/reexport-star/__snapshot__/runtimeModeSnapshot/case1.txt b/tests/rspack-test/configCases/externals/reexport-star/__snapshot__/runtimeModeSnapshot/case1.txt new file mode 100644 index 000000000000..d227cef528f4 --- /dev/null +++ b/tests/rspack-test/configCases/externals/reexport-star/__snapshot__/runtimeModeSnapshot/case1.txt @@ -0,0 +1,39 @@ +import { __rspack_context } from "./runtime~0.mjs"; + +import * as __rspack_external_external1_alias_bc4b12e4 from "external1-alias"; +import * as __rspack_external_external2_alias_e5239a01 from "external2-alias"; +__rspack_context.m.add({ +42(__unused_rspack_module, __webpack_exports__, __rspack_context) { +__rspack_context.N(__webpack_exports__); +/* import */ var external1__rspack_import_0 = __rspack_context.r(322); + +/* reexport */ var __rspack_reexport = {}; +/* reexport */ for( const __rspack_import_key in external1__rspack_import_0) if(__rspack_import_key !== "default") __rspack_reexport[__rspack_import_key] =() => external1__rspack_import_0[__rspack_import_key] +/* reexport */ __rspack_context.d(__webpack_exports__, __rspack_reexport); +/* import */ var external2__rspack_import_1 = __rspack_context.r(101); + +/* reexport */ var __rspack_reexport = {}; +/* reexport */ for( const __rspack_import_key in external2__rspack_import_1) if(__rspack_import_key !== "default") __rspack_reexport[__rspack_import_key] =() => external2__rspack_import_1[__rspack_import_key] +/* reexport */ __rspack_context.d(__webpack_exports__, __rspack_reexport); + + + + +}, +322(module) { + +module.exports = __rspack_external_external1_alias_bc4b12e4; + + +}, +101(module) { + +module.exports = __rspack_external_external2_alias_e5239a01; + + +}, +}); +__rspack_context.r("42"); + +export * from "external1-alias"; +export * from "external2-alias"; \ No newline at end of file diff --git a/tests/rspack-test/configCases/externals/reexport-star/__snapshot__/runtimeModeSnapshot/case2.txt b/tests/rspack-test/configCases/externals/reexport-star/__snapshot__/runtimeModeSnapshot/case2.txt new file mode 100644 index 000000000000..47abde5972c6 --- /dev/null +++ b/tests/rspack-test/configCases/externals/reexport-star/__snapshot__/runtimeModeSnapshot/case2.txt @@ -0,0 +1,13 @@ +import * as __rspack_external_external1_alias_bc4b12e4 from "external1-alias"; + + + + + + + + +var a = __rspack_external_external1_alias_bc4b12e4.a; +var b = __rspack_external_external1_alias_bc4b12e4.b; +export { __rspack_external_external1_alias_bc4b12e4 as n1, a, b }; +export * from "external1-alias"; \ No newline at end of file diff --git a/tests/rspack-test/configCases/externals/reexport-star/__snapshot__/runtimeModeSnapshot/case3.txt b/tests/rspack-test/configCases/externals/reexport-star/__snapshot__/runtimeModeSnapshot/case3.txt new file mode 100644 index 000000000000..3af23e5ab247 --- /dev/null +++ b/tests/rspack-test/configCases/externals/reexport-star/__snapshot__/runtimeModeSnapshot/case3.txt @@ -0,0 +1,10 @@ +import "external1-alias"; + + + +const foo = 2 + + +const bar = 1 + +export { bar, foo }; \ No newline at end of file diff --git a/tests/rspack-test/configCases/externals/reexport-star/__snapshot__/runtimeModeSnapshot/case4.txt b/tests/rspack-test/configCases/externals/reexport-star/__snapshot__/runtimeModeSnapshot/case4.txt new file mode 100644 index 000000000000..2d49c157ce0c --- /dev/null +++ b/tests/rspack-test/configCases/externals/reexport-star/__snapshot__/runtimeModeSnapshot/case4.txt @@ -0,0 +1,7 @@ +import * as __rspack_external_external1_alias_bc4b12e4 from "external1-alias"; + + + + + +export * from "external1-alias"; \ No newline at end of file diff --git a/tests/rspack-test/configCases/externals/reexport-star/__snapshot__/runtimeModeSnapshot/case5.txt b/tests/rspack-test/configCases/externals/reexport-star/__snapshot__/runtimeModeSnapshot/case5.txt new file mode 100644 index 000000000000..bbeba4895a4b --- /dev/null +++ b/tests/rspack-test/configCases/externals/reexport-star/__snapshot__/runtimeModeSnapshot/case5.txt @@ -0,0 +1,12 @@ +import * as __rspack_external_external1_alias_bc4b12e4 from "external1-alias"; + + + + +const bar = __rspack_external_external1_alias_bc4b12e4.foo + 1 + + + + +export { bar }; +export * from "external1-alias"; \ No newline at end of file diff --git a/tests/rspack-test/configCases/externals/reexport-star/__snapshot__/runtimeModeSnapshot/case6.txt b/tests/rspack-test/configCases/externals/reexport-star/__snapshot__/runtimeModeSnapshot/case6.txt new file mode 100644 index 000000000000..503813b4f90c --- /dev/null +++ b/tests/rspack-test/configCases/externals/reexport-star/__snapshot__/runtimeModeSnapshot/case6.txt @@ -0,0 +1,8 @@ +import * as __rspack_external_external1_alias_bc4b12e4 from "external1-alias"; + + + + + + +export * from "external1-alias"; \ No newline at end of file diff --git a/tests/rspack-test/configCases/externals/reexport-star/index.js b/tests/rspack-test/configCases/externals/reexport-star/index.js index c9f9dd4b9fd9..9635c729a698 100644 --- a/tests/rspack-test/configCases/externals/reexport-star/index.js +++ b/tests/rspack-test/configCases/externals/reexport-star/index.js @@ -1,12 +1,15 @@ const fs = require("fs"); const path = require("path"); const readCase = (name) => fs.readFileSync(path.resolve(__dirname, `${name}.mjs`), "utf-8"); +const snapshotDir = typeof __rspack_context !== "undefined" + ? path.join(__SNAPSHOT__, "runtimeModeSnapshot") + : __SNAPSHOT__; it("reexport star from external module", function () { - expect(readCase("case1")).toMatchFileSnapshotSync(path.join(__SNAPSHOT__, 'case1.txt')); - expect(readCase("case2")).toMatchFileSnapshotSync(path.join(__SNAPSHOT__, 'case2.txt')); - expect(readCase("case3")).toMatchFileSnapshotSync(path.join(__SNAPSHOT__, 'case3.txt')); - expect(readCase("case4")).toMatchFileSnapshotSync(path.join(__SNAPSHOT__, 'case4.txt')); - expect(readCase("case5")).toMatchFileSnapshotSync(path.join(__SNAPSHOT__, 'case5.txt')); - expect(readCase("case6")).toMatchFileSnapshotSync(path.join(__SNAPSHOT__, 'case6.txt')); + expect(readCase("case1")).toMatchFileSnapshotSync(path.join(snapshotDir, 'case1.txt')); + expect(readCase("case2")).toMatchFileSnapshotSync(path.join(snapshotDir, 'case2.txt')); + expect(readCase("case3")).toMatchFileSnapshotSync(path.join(snapshotDir, 'case3.txt')); + expect(readCase("case4")).toMatchFileSnapshotSync(path.join(snapshotDir, 'case4.txt')); + expect(readCase("case5")).toMatchFileSnapshotSync(path.join(snapshotDir, 'case5.txt')); + expect(readCase("case6")).toMatchFileSnapshotSync(path.join(snapshotDir, 'case6.txt')); }); diff --git a/tests/rspack-test/configCases/externals/script-externals-dynamic-import/index.js b/tests/rspack-test/configCases/externals/script-externals-dynamic-import/index.js index 6639fd543a37..8f12bb35b9b8 100644 --- a/tests/rspack-test/configCases/externals/script-externals-dynamic-import/index.js +++ b/tests/rspack-test/configCases/externals/script-externals-dynamic-import/index.js @@ -6,6 +6,11 @@ const readCase = (name)=> fs.readFileSync(path.resolve(__dirname, `${name}.js`), const caseContent = readCase("case"); it("dynamic import script externals module should be returned", function () { - expect(caseContent).toContain(`return __webpack_require__.t(m, 22)`) + const isRspackRuntime = typeof __rspack_context !== "undefined"; + expect(caseContent).toContain( + isRspackRuntime + ? `return __rspack_context.t(m, 22)` + : `return __webpack_require__.t(m, 22)` + ) }); diff --git a/tests/rspack-test/configCases/hooks/additional-tree-runtime-requirements/rspack.config.js b/tests/rspack-test/configCases/hooks/additional-tree-runtime-requirements/rspack.config.js index 9d24e54ac896..b97d8c83e097 100644 --- a/tests/rspack-test/configCases/hooks/additional-tree-runtime-requirements/rspack.config.js +++ b/tests/rspack-test/configCases/hooks/additional-tree-runtime-requirements/rspack.config.js @@ -5,7 +5,9 @@ class Plugin { compilation.hooks.additionalTreeRuntimeRequirements.tap( 'TestFakePlugin', (_, set) => { - expect(set.has(RuntimeGlobals.chunkName)).toBeFalsy(); + if (!globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + expect(set.has(RuntimeGlobals.chunkName)).toBeFalsy(); + } expect(set.has(RuntimeGlobals.getFullHash)).toBeTruthy(); set.add(RuntimeGlobals.chunkName); set.delete(RuntimeGlobals.getFullHash); diff --git a/tests/rspack-test/configCases/hooks/modify-extract-css-loading-runtime/rspack.config.js b/tests/rspack-test/configCases/hooks/modify-extract-css-loading-runtime/rspack.config.js index ae30d8191610..db52624d953e 100644 --- a/tests/rspack-test/configCases/hooks/modify-extract-css-loading-runtime/rspack.config.js +++ b/tests/rspack-test/configCases/hooks/modify-extract-css-loading-runtime/rspack.config.js @@ -10,8 +10,11 @@ class Plugin { 'webpack/runtime/css loading', ); const originSource = module.source.source.toString('utf-8'); + const runtimeSource = globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK + ? '__rspack_context.f.miniCss.test = true;' + : '__webpack_require__.f.miniCss.test = true;'; module.source.source = Buffer.from( - `${originSource}\n__webpack_require__.f.miniCss.test = true;\n`, + `${originSource}\n${runtimeSource}\n`, 'utf-8', ); } diff --git a/tests/rspack-test/configCases/hooks/rspack-issue-5571/index.js b/tests/rspack-test/configCases/hooks/rspack-issue-5571/index.js index 7ca3b92bc89a..2ead1a52c840 100644 --- a/tests/rspack-test/configCases/hooks/rspack-issue-5571/index.js +++ b/tests/rspack-test/configCases/hooks/rspack-issue-5571/index.js @@ -11,7 +11,12 @@ it("should modify runtime module source in main", () => { it("should has css loading hmr runtime requirements", () => { const name = "hmrC.css"; + const isRspackRuntime = typeof __rspack_context !== "undefined"; expect( fs.readFileSync(path.join(__dirname, "./bundle0.js"), "utf-8") - ).toContain("__webpack_require__." + name + " = "); + ).toContain( + isRspackRuntime + ? "__rspack_hmrDownloadUpdateHandlers.css = " + : "__webpack_require__." + name + " = " + ); }); diff --git a/tests/rspack-test/configCases/inline-const/provide-plugin/index.js b/tests/rspack-test/configCases/inline-const/provide-plugin/index.js index 635e3441fb98..40f6a735ed79 100644 --- a/tests/rspack-test/configCases/inline-const/provide-plugin/index.js +++ b/tests/rspack-test/configCases/inline-const/provide-plugin/index.js @@ -7,8 +7,11 @@ it("should provide inlined const exports", () => { expect(providedDefault).toBe(2); // END:A const block = generated.match(/([\s\S]*?)\/\/ START:A[\s\S]*?\/\/ END:A/)[1]; - expect(block.includes(`/* provided dependency */ var providedA = (__webpack_require__("./constants.js"), (/* inlined export .a */1));`)).toBe(true); - expect(block.includes(`/* provided dependency */ var providedDefault = (__webpack_require__("./constants.js"), (/* inlined export ["default"] */2));`)).toBe(true); + const requireExpression = typeof __rspack_context !== "undefined" + ? "__rspack_context.r" + : "__webpack_require__"; + expect(block.includes(`/* provided dependency */ var providedA = (${requireExpression}("./constants.js"), (/* inlined export .a */1));`)).toBe(true); + expect(block.includes(`/* provided dependency */ var providedDefault = (${requireExpression}("./constants.js"), (/* inlined export ["default"] */2));`)).toBe(true); expect(globalThis.__rspackProvideConstSideEffect).toBe(1); delete globalThis.__rspackProvideConstSideEffect; }); diff --git a/tests/rspack-test/configCases/library/esm-external/index.js b/tests/rspack-test/configCases/library/esm-external/index.js index 5f4adf2bc17d..04bffcb1de3a 100644 --- a/tests/rspack-test/configCases/library/esm-external/index.js +++ b/tests/rspack-test/configCases/library/esm-external/index.js @@ -14,13 +14,20 @@ it("should run", function () { }); it("should export module library", function () { const __filename = url.fileURLToPath(import.meta.url); + const runtimeModeOutput = typeof __rspack_context !== "undefined"; const source = fs.readFileSync( path.join( __filename, - "../../../../js/config/library/esm-external/bundle0.mjs" + runtimeModeOutput + ? "../../../../js/runtime-mode-config/library/esm-external/bundle0.mjs" + : "../../../../js/config/library/esm-external/bundle0.mjs" ), "utf-8" ); - const createRequire = "__rspack_createRequire_require"; - expect(source).toContain(`${createRequire}("node:fs")`); + if (runtimeModeOutput) { + expect(source).toContain('__rspack_context.r("node:fs")'); + } else { + const createRequire = "__rspack_createRequire_require"; + expect(source).toContain(`${createRequire}("node:fs")`); + } }); diff --git a/tests/rspack-test/configCases/library/modern-module-export-char/rspack.config.js b/tests/rspack-test/configCases/library/modern-module-export-char/rspack.config.js index ded6385a86fc..506d5648a366 100644 --- a/tests/rspack-test/configCases/library/modern-module-export-char/rspack.config.js +++ b/tests/rspack-test/configCases/library/modern-module-export-char/rspack.config.js @@ -25,7 +25,9 @@ module.exports = { compilation.hooks.afterProcessAssets.tap('testcase', (assets) => { const bundle = Object.values(assets)[0]._value; expect(bundle).toContain( - `var foo_default = /*#__PURE__*/__webpack_require__.n(foo);\nvar foo_default_0 = foo_default();`, + globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK + ? `var foo_default = /*#__PURE__*/__rspack_context.n(foo);\nvar foo_default_0 = foo_default();` + : `var foo_default = /*#__PURE__*/__webpack_require__.n(foo);\nvar foo_default_0 = foo_default();`, ); expect(bundle).toContain('foo_default_0 as cjsInterop'); expect(bundle).toContain( diff --git a/tests/rspack-test/configCases/library/modern-module-force-concaten/__snapshot__/runtimeModeSnapshot/b.js.txt b/tests/rspack-test/configCases/library/modern-module-force-concaten/__snapshot__/runtimeModeSnapshot/b.js.txt new file mode 100644 index 000000000000..6e5d7ae4f994 --- /dev/null +++ b/tests/rspack-test/configCases/library/modern-module-force-concaten/__snapshot__/runtimeModeSnapshot/b.js.txt @@ -0,0 +1,11 @@ +import { __rspack_context } from "./runtime~0.js"; + +__rspack_context.m.add({ +917(module) { +module.exports = 'b' + +}, +}); +__rspack_context.r("917"); + +export {}; \ No newline at end of file diff --git a/tests/rspack-test/configCases/library/modern-module-force-concaten/__snapshot__/runtimeModeSnapshot/e.js.txt b/tests/rspack-test/configCases/library/modern-module-force-concaten/__snapshot__/runtimeModeSnapshot/e.js.txt new file mode 100644 index 000000000000..8511aa0aea4a --- /dev/null +++ b/tests/rspack-test/configCases/library/modern-module-force-concaten/__snapshot__/runtimeModeSnapshot/e.js.txt @@ -0,0 +1,18 @@ +import { __rspack_context } from "./runtime~0.js"; + +__rspack_context.m.add({ +100(module) { +module.exports = 'bar' + +}, +}); +const bar = __rspack_context.r("100"); +var bar_default = /*#__PURE__*/__rspack_context.n(bar); +var bar_default_0 = bar_default(); + + + + + +var e_foo = (/* inlined export .foo */"foo"); +export { bar_default_0 as bar, e_foo as foo }; \ No newline at end of file diff --git a/tests/rspack-test/configCases/library/modern-module-force-concaten/__snapshot__/runtimeModeSnapshot/f.js.txt b/tests/rspack-test/configCases/library/modern-module-force-concaten/__snapshot__/runtimeModeSnapshot/f.js.txt new file mode 100644 index 000000000000..0ae02973068c --- /dev/null +++ b/tests/rspack-test/configCases/library/modern-module-force-concaten/__snapshot__/runtimeModeSnapshot/f.js.txt @@ -0,0 +1,27 @@ +import { __rspack_context } from "./runtime~0.js"; + +import { createRequire as __rspack_createRequire } from "node:module"; +const __rspack_createRequire_require = __rspack_createRequire(import.meta.url); +__rspack_context.m.add({ +928(module) { +module.exports = __rspack_createRequire_require("path"); + +}, +227(module, __unused_rspack_exports, __rspack_context) { +const path = __rspack_context.r(928) + +module.exports = path.sep + + +}, +}); +const bar = __rspack_context.r("227"); +var bar_default = /*#__PURE__*/__rspack_context.n(bar); + + + +const value = (/* inlined export .foo */"foo") + (bar_default()) + + + +export { value }; \ No newline at end of file diff --git a/tests/rspack-test/configCases/library/modern-module-force-concaten/__snapshot__/runtimeModeSnapshot/g.js.txt b/tests/rspack-test/configCases/library/modern-module-force-concaten/__snapshot__/runtimeModeSnapshot/g.js.txt new file mode 100644 index 000000000000..cb4bf331968f --- /dev/null +++ b/tests/rspack-test/configCases/library/modern-module-force-concaten/__snapshot__/runtimeModeSnapshot/g.js.txt @@ -0,0 +1,17 @@ +import { __rspack_context } from "./runtime~0.js"; + +__rspack_context.m.add({ +547(module) { +module.exports = 'foo' + + +}, +}); +const foo = __rspack_context.r("547"); +var foo_default = /*#__PURE__*/__rspack_context.n(foo); +var foo_default_0 = foo_default(); + + + + +export { foo_default_0 as foo }; \ No newline at end of file diff --git a/tests/rspack-test/configCases/library/render-order-issue/__snapshots__/runtimeModeSnapshot/runtimeModeSnapshot/entry.mjs.txt b/tests/rspack-test/configCases/library/render-order-issue/__snapshots__/runtimeModeSnapshot/runtimeModeSnapshot/entry.mjs.txt new file mode 100644 index 000000000000..116873dccc61 --- /dev/null +++ b/tests/rspack-test/configCases/library/render-order-issue/__snapshots__/runtimeModeSnapshot/runtimeModeSnapshot/entry.mjs.txt @@ -0,0 +1,75 @@ +import * as __rspack_external_externals1 from "externals1"; +import * as __rspack_external_externals0 from "externals0"; +var __webpack_modules__ = ({ +"./bar.js"() { + +;// CONCATENATED MODULE: external "externals0" + +;// CONCATENATED MODULE: ./bar.js + +__rspack_external_externals0.v; + +}, +"./entry.js"(module, __unused_rspack_exports, __rspack_context) { +module.exports.entry1 = __rspack_context.r("./entry1.js") +module.exports.entry2 = __rspack_context.r("./entry2.js") + +}, +"./entry1.js"(module, __unused_rspack_exports, __rspack_context) { +module.exports = __rspack_context.r("./foo.js") +module.exports.name = "entry1" + +}, +"./entry2.js"(module, __unused_rspack_exports, __rspack_context) { +module.exports = __rspack_context.r("./bar.js") +module.exports.name = "entry2" + +}, +"./foo.js"() { + +;// CONCATENATED MODULE: external "externals1" + +;// CONCATENATED MODULE: ./foo.js + +__rspack_external_externals1.v; + +}, + +}); +// The module cache +var __webpack_module_cache__ = {}; + +var __rspack_context={}; + +// The require function +function __webpack_require__(moduleId) { + +// Check if module is in cache +var cachedModule = __webpack_module_cache__[moduleId]; +if (cachedModule !== undefined) { +return cachedModule.exports; +} +// Create a new module (and put it into the cache) +var module = (__webpack_module_cache__[moduleId] = { +exports: {} +}); +// Execute the module function +__webpack_modules__[moduleId](module, module.exports, __rspack_context); + +// Return the exports of the module +return module.exports; + +} + +__rspack_context.r = __webpack_require__; + +// startup +// Load entry module and return exports +// This entry module used 'module' so it can't be inlined +var __webpack_exports__ = __rspack_context.r("./entry.js"); +var __webpack_exports__entry1 = __webpack_exports__.entry1; +var __webpack_exports__entry2 = __webpack_exports__.entry2; +export { __webpack_exports__entry1 as entry1, __webpack_exports__entry2 as entry2 }; + +var __rspack_exports_default = { entry1: __webpack_exports__entry1, entry2: __webpack_exports__entry2 }; +export default __rspack_exports_default; \ No newline at end of file diff --git a/tests/rspack-test/configCases/library/render-order-issue/rspack.config.js b/tests/rspack-test/configCases/library/render-order-issue/rspack.config.js index 16342f1028c2..34ff59a0c23f 100644 --- a/tests/rspack-test/configCases/library/render-order-issue/rspack.config.js +++ b/tests/rspack-test/configCases/library/render-order-issue/rspack.config.js @@ -45,8 +45,11 @@ module.exports = { /** @type {Record} */ assets, ) => { const source = assets['entry.mjs'].source(); + const snapshotDir = globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK + ? path.join(__dirname, '__snapshots__', 'runtimeModeSnapshot') + : path.join(__dirname, '__snapshots__'); expect(source).toMatchFileSnapshotSync( - path.join(__dirname, '__snapshots__', `entry.mjs.txt`), + path.join(snapshotDir, `entry.mjs.txt`), ); }, ); diff --git a/tests/rspack-test/configCases/module-variables/global-false/index.js b/tests/rspack-test/configCases/module-variables/global-false/index.js index 4f20948b94d0..0131906a1749 100644 --- a/tests/rspack-test/configCases/module-variables/global-false/index.js +++ b/tests/rspack-test/configCases/module-variables/global-false/index.js @@ -1,4 +1,8 @@ it("global false", function () { global; - expect(__webpack_require__.g).toBe(undefined); + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + expect(__rspack_context.g).not.toBe(undefined); + } else { + expect(__webpack_require__.g).toBe(undefined); + } }); diff --git a/tests/rspack-test/configCases/module/consume-webpack-runtime/index.js b/tests/rspack-test/configCases/module/consume-webpack-runtime/index.js index efdf4ed2e314..40ae91db4b26 100644 --- a/tests/rspack-test/configCases/module/consume-webpack-runtime/index.js +++ b/tests/rspack-test/configCases/module/consume-webpack-runtime/index.js @@ -13,12 +13,14 @@ it("should compile and run", () => { expect(objectExport.foo).toBe(42); expect(defaultUseNested().foo).toBe(42); + const isRspackRuntimeMode = globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK === true; + const path = __non_webpack_require__('path') const fs = __non_webpack_require__('fs') { const content = fs.readFileSync(path.resolve(__dirname, './bundle0.js'), 'utf-8'); const NESTED_RE = /__nested_rspack_require_[A-Za-z0-9_]+__/g; - expect(content.match(NESTED_RE).length).toBe(17); + expect((content.match(NESTED_RE) || []).length).toBe(isRspackRuntimeMode ? 0 : 17); } { @@ -30,7 +32,7 @@ it("should compile and run", () => { { const content = fs.readFileSync(path.resolve(__dirname, './bundle1.js'), 'utf-8'); const NESTED_RE = /__nested_rspack_require_[A-Za-z0-9_]+__/g; - expect(content.match(NESTED_RE).length).toBe(19); + expect((content.match(NESTED_RE) || []).length).toBe(isRspackRuntimeMode ? 0 : 19); } { @@ -42,7 +44,7 @@ it("should compile and run", () => { { const content = fs.readFileSync(path.resolve(__dirname, './bundle2.js'), 'utf-8'); const NESTED_RE = /__nested_rspack_require_[A-Za-z0-9_]+__/g; - expect(content.match(NESTED_RE).length).toBe(17); + expect((content.match(NESTED_RE) || []).length).toBe(isRspackRuntimeMode ? 0 : 17); } { @@ -54,7 +56,7 @@ it("should compile and run", () => { { const content = fs.readFileSync(path.resolve(__dirname, './bundle3.js'), 'utf-8'); const NESTED_RE = /__nested_rspack_require_[A-Za-z0-9_]+__/g; - expect(content.match(NESTED_RE).length).toBe(19); + expect((content.match(NESTED_RE) || []).length).toBe(isRspackRuntimeMode ? 0 : 19); } { diff --git a/tests/rspack-test/configCases/output/pathinfo-verbose/index.js b/tests/rspack-test/configCases/output/pathinfo-verbose/index.js index 634612581db3..5838d2b09939 100644 --- a/tests/rspack-test/configCases/output/pathinfo-verbose/index.js +++ b/tests/rspack-test/configCases/output/pathinfo-verbose/index.js @@ -2,15 +2,23 @@ it("should add all modules headers info above modules", () => { const fs = require("fs"); const path = require("path") const content = fs.readFileSync(path.join(__dirname, "sut.js"), "utf-8"); + const runtimeMode = typeof __rspack_context !== "undefined"; - expect(content).toContain(` + expect(content).toContain((runtimeMode ? ` /*!****************!*\\ !*** ./sut.js ***! \\****************/ /*! namespace exports */ -/*! runtime requirements: __webpack_require__ */ -/*! Statement with side_effects in source code at ./sut.js:3:1-29 */ - `.trim()) +/*! runtime requirements: __rspack_context.r, __rspack_context */ +/*! Statement with side_effects in source code at ./sut.js:3:1-29 */ + ` : ` +/*!****************!*\\ + !*** ./sut.js ***! + \\****************/ +/*! namespace exports */ +/*! runtime requirements: __webpack_require__, __webpack_require__ */ +/*! Statement with side_effects in source code at ./sut.js:3:1-29 */ + `).trim()) expect(content).toContain(` /*!****************!*\\ @@ -21,7 +29,17 @@ it("should add all modules headers info above modules", () => { /*! Statement with side_effects in source code at ./cjs.js:1:1-3:2 */ `.trim()) - expect(content).toContain(` + expect(content).toContain((runtimeMode ? ` +/*!*****************!*\\ + !*** ./util.js ***! + \\*****************/ +/*! namespace exports */ +/*! export default [not provided] [unused] [provision prevents renaming] */ +/*! export message [provided] [used in sut] [inlined to ("hello")] */ +/*! export secret [maybe provided (runtime-defined)] [used in sut] [provision prevents renaming] -> ./cjs.js secret */ +/*! other exports [maybe provided (runtime-defined)] [unused] -> ./cjs.js */ +/*! runtime requirements: __webpack_exports__, __rspack_context.r, __rspack_context.o, __rspack_context.n, __rspack_context.d, __rspack_context */ +` : ` /*!*****************!*\\ !*** ./util.js ***! \\*****************/ @@ -30,9 +48,9 @@ it("should add all modules headers info above modules", () => { /*! export message [provided] [used in sut] [inlined to ("hello")] */ /*! export secret [maybe provided (runtime-defined)] [used in sut] [provision prevents renaming] -> ./cjs.js secret */ /*! other exports [maybe provided (runtime-defined)] [unused] -> ./cjs.js */ -/*! runtime requirements: __webpack_require__.o, __webpack_require__.n, __webpack_require__.d, __webpack_require__.*, __webpack_require__, __webpack_exports__ */ -`.trim()) +/*! runtime requirements: __webpack_require__.o, __webpack_require__.n, __webpack_require__.d, __webpack_require__, __webpack_require__, __webpack_exports__ */ +`).trim()) -}) \ No newline at end of file +}) diff --git a/tests/rspack-test/configCases/parsing/eval-cjs-typeof/index.js b/tests/rspack-test/configCases/parsing/eval-cjs-typeof/index.js index 9f5d19f9a7bc..a6c8d022bf21 100644 --- a/tests/rspack-test/configCases/parsing/eval-cjs-typeof/index.js +++ b/tests/rspack-test/configCases/parsing/eval-cjs-typeof/index.js @@ -5,5 +5,9 @@ it("should compile", async () => { throw new Error("wrong") } const file = await fs.promises.readFile(__filename, 'utf-8'); - expect(file).not.toContain(["type", "of"].join("")) + if (file.includes(["var ", "__rspack_context"].join(""))) { + expect(file).not.toContain(['if (', 'ty', 'pe', 'of exports !== "object"', ' || ', 'ty', 'pe', 'of module !== "object"', ')'].join("")) + } else { + expect(file).not.toContain(["ty", "pe", "of"].join("")) + } }); diff --git a/tests/rspack-test/configCases/parsing/require-alias-disabled/index.js b/tests/rspack-test/configCases/parsing/require-alias-disabled/index.js index 1570c1fa6ed6..3dbb9394cea9 100644 --- a/tests/rspack-test/configCases/parsing/require-alias-disabled/index.js +++ b/tests/rspack-test/configCases/parsing/require-alias-disabled/index.js @@ -28,7 +28,9 @@ it("should NOT rename require when requireAlias is false", function () { const content = fs.readFileSync(path.join(__dirname, "./bundle0.js"), "utf-8"); const filename = "./file"; - const requireName = "__webpack_require__(641)"; + const requireName = globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK + ? "__rspack_context.r(641)" + : "__webpack_require__(641)"; const ok = "ok"; expect(content).toContain(`cjsRequire("${filename}")`); @@ -36,4 +38,4 @@ it("should NOT rename require when requireAlias is false", function () { expect(content).toContain(`cjsRequire3("${filename}")`); expect(content).toContain(`var cjsRequire = ${requireName}, cjsRequire2 = true && ${requireName};`); expect(content).not.toContain(`module.exports = "${ok}";`); -}); \ No newline at end of file +}); diff --git a/tests/rspack-test/configCases/parsing/require-alias-enabled/index.js b/tests/rspack-test/configCases/parsing/require-alias-enabled/index.js index 833634e982c9..7693f601b2ee 100644 --- a/tests/rspack-test/configCases/parsing/require-alias-enabled/index.js +++ b/tests/rspack-test/configCases/parsing/require-alias-enabled/index.js @@ -22,12 +22,14 @@ it("should NOT rename require when requireAlias is false", function () { const path = __non_webpack_require__("path"); const content = fs.readFileSync(path.join(__dirname, "./bundle0.js"), "utf-8"); - const requireName = "undefined"; + const requireCall = globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK + ? "__rspack_context\\.r\\(239\\)" + : "__webpack_require__\\(239\\)"; const ok = "ok"; - expect(content).toMatch(/function test\(\) \{\s*__webpack_require__\(239\);\s*\}/i); - expect(content).toMatch(/function test2\(\) \{\s*__webpack_require__\(239\);\s*\}/i); - expect(content).toMatch(/function test3\(cjsRequire3\) \{\s*__webpack_require__\(239\);\s*\}/i); - expect(content).toContain(`var cjsRequire = ${requireName}, cjsRequire2 = ${requireName};`); + expect(content).toMatch(new RegExp(`function test\\(\\) \\{\\s*${requireCall};\\s*\\}`, "i")); + expect(content).toMatch(new RegExp(`function test2\\(\\) \\{\\s*${requireCall};\\s*\\}`, "i")); + expect(content).toMatch(new RegExp(`function test3\\(cjsRequire3\\) \\{\\s*${requireCall};\\s*\\}`, "i")); + expect(content).toContain(`var cjsRequire = undefined, cjsRequire2 = undefined;`); expect(content).toContain(`module.exports = "${ok}";`); -}); \ No newline at end of file +}); diff --git a/tests/rspack-test/configCases/plugins/minify-module/index.js b/tests/rspack-test/configCases/plugins/minify-module/index.js index 9fc9a9caa76f..86213a5e286e 100644 --- a/tests/rspack-test/configCases/plugins/minify-module/index.js +++ b/tests/rspack-test/configCases/plugins/minify-module/index.js @@ -6,7 +6,5 @@ it("should minify outputModule", async () => { path.join(__dirname, "./module.mjs"), "utf-8" ); - expect( - out.startsWith('import s from"https://test.rspack.rs/test.js"') - ).toBe(true); + expect(out).toMatch(/^import \w+ from"https:\/\/test\.rspack\.rs\/test\.js"/); }); diff --git a/tests/rspack-test/configCases/plugins/minify-parser/index.js b/tests/rspack-test/configCases/plugins/minify-parser/index.js index 093a2ad9c9f6..069ea3a277cf 100644 --- a/tests/rspack-test/configCases/plugins/minify-parser/index.js +++ b/tests/rspack-test/configCases/plugins/minify-parser/index.js @@ -3,5 +3,5 @@ const path = require("path"); it("[minify-parser]: import attributes should be preserved", () => { const content = fs.readFileSync(path.resolve(__dirname, "importAttributes.js"), "utf-8"); - expect(content).toContain('import o from"./a.json"with{type:"json"}'); + expect(content).toMatch(/import \w+ from"\.\/a\.json"with\{type:"json"\}/); }); diff --git a/tests/rspack-test/configCases/rsdoctor/assets/rspack.config.js b/tests/rspack-test/configCases/rsdoctor/assets/rspack.config.js index 7b6fa692cf8d..5ab40c9c8cdd 100644 --- a/tests/rspack-test/configCases/rsdoctor/assets/rspack.config.js +++ b/tests/rspack-test/configCases/rsdoctor/assets/rspack.config.js @@ -23,6 +23,8 @@ module.exports = { }), { apply(compiler) { + const isRspackRuntimeMode = + compiler.options.experiments.runtimeMode === 'rspack'; compiler.hooks.compilation.tap('TestPlugin::Assets', (compilation) => { const hooks = RsdoctorPlugin.getCompilationHooks(compilation); hooks.assets.tap('TestPlugin::Assets', (data) => { @@ -33,26 +35,45 @@ module.exports = { path: a.path, })); assetsInfo.sort((a, b) => (a.path > b.path ? 1 : -1)); - expect(assetsInfo).toMatchInlineSnapshot(` - Array [ - Object { - path: a.js, - size: 4298, + if (isRspackRuntimeMode) { + expect(assetsInfo).toEqual([ + { + path: 'a.js', + size: 6104, }, - Object { - path: b.js, - size: 4298, + { + path: 'b.js', + size: 6104, }, - Object { - path: c_js.js, + { + path: 'c_js.js', + size: 213, + }, + { + path: 'd_js.js', + size: 213, + }, + ]); + } else { + expect(assetsInfo).toEqual([ + { + path: 'a.js', + size: 4299, + }, + { + path: 'b.js', + size: 4299, + }, + { + path: 'c_js.js', size: 219, }, - Object { - path: d_js.js, + { + path: 'd_js.js', size: 219, }, - ] - `); + ]); + } }); }); }, diff --git a/tests/rspack-test/configCases/rstest/mock/rspack.config.js b/tests/rspack-test/configCases/rstest/mock/rspack.config.js index c42fafe478c5..5c8346ea8c3b 100644 --- a/tests/rspack-test/configCases/rstest/mock/rspack.config.js +++ b/tests/rspack-test/configCases/rstest/mock/rspack.config.js @@ -85,10 +85,11 @@ __webpack_require__.rstest_mock = (id, modFactory) => { __webpack_exports__, __webpack_require__, ) { - __webpack_require__.r(__webpack_exports__); + const __rspack_runtime = __webpack_require__; + (__rspack_runtime.N || __rspack_runtime.r)(__webpack_exports__); const res = modFactory(); for (const key in res) { - __webpack_require__.d(__webpack_exports__, { + __rspack_runtime.d(__webpack_exports__, { [key]: () => res[key], }); } @@ -114,7 +115,8 @@ __webpack_require__.rstest_do_mock = (id, modFactory) => { __webpack_module_cache__[id] = { exports: __webpack_require__(modFactory) }; } else if (typeof modFactory === 'function') { const exports = modFactory(); - __webpack_require__.r(exports); + const __rspack_runtime = typeof __rspack_context !== 'undefined' ? __rspack_context : __webpack_require__; + (__rspack_runtime.N || __rspack_runtime.r)(exports); __webpack_module_cache__[id] = { exports, id, loaded: true }; } }; diff --git a/tests/rspack-test/configCases/rstest/require-resolve-origin/index.js b/tests/rspack-test/configCases/rstest/require-resolve-origin/index.js index fb04ef567967..569c115534b1 100644 --- a/tests/rspack-test/configCases/rstest/require-resolve-origin/index.js +++ b/tests/rspack-test/configCases/rstest/require-resolve-origin/index.js @@ -28,7 +28,9 @@ it('rewrites require.resolve calls with source module origin', () => { // `webpackIgnore` only affects require.resolve when commonjsMagicComments is // enabled, and shadowed require must not be rewritten. expect(content).toContain( - `${helper}((__webpack_require__(161)/* .name */.name), ${originLiteral})`, + globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK + ? `${helper}((__rspack_context.r(161)/* .name */.name), ${originLiteral})` + : `${helper}((__webpack_require__(161)/* .name */.name), ${originLiteral})`, ); expect(content).toContain( `${helper}(/* webpackIgnore: true */ './ignored', ${originLiteral})`, diff --git a/tests/rspack-test/configCases/runtime/dynamic-css-chunk-with-content-hash/index.js b/tests/rspack-test/configCases/runtime/dynamic-css-chunk-with-content-hash/index.js index 2933349998b3..2c494872047f 100644 --- a/tests/rspack-test/configCases/runtime/dynamic-css-chunk-with-content-hash/index.js +++ b/tests/rspack-test/configCases/runtime/dynamic-css-chunk-with-content-hash/index.js @@ -2,7 +2,7 @@ it("load dynamic css chunk with content hash", async function () { await import("./dynamic").then(module => { expect(module.value).toBe("dynamic"); // test is only for css loading - if (__webpack_require__.f.css) { + if (typeof document !== "undefined" && __webpack_require__.f.css) { expect(document.getElementsByTagName("link").length).toBe(1); } }); diff --git a/tests/rspack-test/configCases/runtime/dynamic-css-chunk-with-hash/index.js b/tests/rspack-test/configCases/runtime/dynamic-css-chunk-with-hash/index.js index a41c9f8a20ee..3611f0e97075 100644 --- a/tests/rspack-test/configCases/runtime/dynamic-css-chunk-with-hash/index.js +++ b/tests/rspack-test/configCases/runtime/dynamic-css-chunk-with-hash/index.js @@ -3,13 +3,13 @@ it("load dynamic css chunk with hash", () => new Promise((resolve, reject) => { import("./dynamic").then(module => { expect(module.value).toBe("dynamic"); // test is only for css loading - if (__webpack_require__.f.css) { + if (typeof document !== "undefined" && __webpack_require__.f.css) { expect(document.getElementsByTagName("link").length).toBe(1); } import("./common").then(module => { expect(module.value).toBe("common"); // test is only for css loading - if (__webpack_require__.f.css) { + if (typeof document !== "undefined" && __webpack_require__.f.css) { expect(document.getElementsByTagName("link").length).toBe(1); } done(); diff --git a/tests/rspack-test/configCases/runtime/dynamic-css-chunk/index.js b/tests/rspack-test/configCases/runtime/dynamic-css-chunk/index.js index 60427e8cd649..aefa7adb4c79 100644 --- a/tests/rspack-test/configCases/runtime/dynamic-css-chunk/index.js +++ b/tests/rspack-test/configCases/runtime/dynamic-css-chunk/index.js @@ -3,13 +3,13 @@ it("load dynamic css chunk", () => new Promise((resolve, reject) => { import("./dynamic").then(module => { expect(module.value).toBe("dynamic"); // test is only for css loading - if (__webpack_require__.f.css) { + if (typeof document !== "undefined" && __webpack_require__.f.css) { expect(document.getElementsByTagName("link").length).toBe(1); } import("./common").then(module => { expect(module.value).toBe("common"); // test is only for css loading - if (__webpack_require__.f.css) { + if (typeof document !== "undefined" && __webpack_require__.f.css) { expect(document.getElementsByTagName("link").length).toBe(1); } done(); diff --git a/tests/rspack-test/configCases/runtime/runtime-condition/a.js b/tests/rspack-test/configCases/runtime/runtime-condition/a.js index 677a6624ce84..91c267f4fff3 100644 --- a/tests/rspack-test/configCases/runtime/runtime-condition/a.js +++ b/tests/rspack-test/configCases/runtime/runtime-condition/a.js @@ -17,7 +17,10 @@ it("should include runtime condition check code", () => { ), "utf-8" ); - expect(source).toContain(`"a-runtime" == __webpack_require__.j`) - expect(source).toContain(`"b-runtime" == __webpack_require__.j`); - expect(source).toContain(`/^[ab]x\\-name$/.test(__webpack_require__.j)`); + const runtimeId = typeof __rspack_context !== "undefined" + ? "__rspack_context.j" + : "__webpack_require__.j"; + expect(source).toContain(`"a-runtime" == ${runtimeId}`) + expect(source).toContain(`"b-runtime" == ${runtimeId}`); + expect(source).toContain(`/^[ab]x\\-name$/.test(${runtimeId})`); }) diff --git a/tests/rspack-test/configCases/runtime/runtime-mode-async-chunk/index.js b/tests/rspack-test/configCases/runtime/runtime-mode-async-chunk/index.js new file mode 100644 index 000000000000..ee48d641230c --- /dev/null +++ b/tests/rspack-test/configCases/runtime/runtime-mode-async-chunk/index.js @@ -0,0 +1,7 @@ +export function load() { + return import("./lazy").then(mod => mod.value); +} + +it("loads async chunk through rspack context", async () => { + await expect(load()).resolves.toBe(7); +}); diff --git a/tests/rspack-test/configCases/runtime/runtime-mode-async-chunk/lazy.js b/tests/rspack-test/configCases/runtime/runtime-mode-async-chunk/lazy.js new file mode 100644 index 000000000000..5f45ec8cb600 --- /dev/null +++ b/tests/rspack-test/configCases/runtime/runtime-mode-async-chunk/lazy.js @@ -0,0 +1 @@ +export const value = 7; diff --git a/tests/rspack-test/configCases/runtime/runtime-mode-async-chunk/rspack.config.js b/tests/rspack-test/configCases/runtime/runtime-mode-async-chunk/rspack.config.js new file mode 100644 index 000000000000..5726b13c37df --- /dev/null +++ b/tests/rspack-test/configCases/runtime/runtime-mode-async-chunk/rspack.config.js @@ -0,0 +1,13 @@ +/** @type {import("@rspack/core").Configuration} */ +module.exports = { + experiments: { + runtimeMode: 'rspack', + }, + output: { + filename: 'main.js', + chunkFilename: '[name].js', + }, + optimization: { + concatenateModules: false, + }, +}; diff --git a/tests/rspack-test/configCases/runtime/runtime-mode-async-chunk/test.config.js b/tests/rspack-test/configCases/runtime/runtime-mode-async-chunk/test.config.js new file mode 100644 index 000000000000..d92892a1b78b --- /dev/null +++ b/tests/rspack-test/configCases/runtime/runtime-mode-async-chunk/test.config.js @@ -0,0 +1,26 @@ +const fs = require("fs"); +const path = require("path"); + +/** @type {import("../../../..").TConfigCaseConfig} */ +module.exports = { + afterExecute(options) { + const mainSource = fs.readFileSync( + path.resolve(options.output.path, "main.js"), + "utf-8", + ); + const asyncChunkSource = fs + .readdirSync(options.output.path) + .filter(file => file.endsWith(".js") && file !== "main.js") + .map(file => + fs.readFileSync(path.resolve(options.output.path, file), "utf-8"), + ) + .join("\n"); + + expect(mainSource).toContain("var __rspack_context={};"); + expect(mainSource).toContain("__rspack_context.r = __webpack_require__;"); + expect(mainSource).toContain("module.exports, __rspack_context"); + expect(asyncChunkSource).toContain("__rspack_context.d"); + expect(asyncChunkSource).not.toContain("__rspack_install_runtime"); + expect(asyncChunkSource).not.toContain("__webpack_require__.d"); + }, +}; diff --git a/tests/rspack-test/configCases/runtime/runtime-mode-context-module/index.js b/tests/rspack-test/configCases/runtime/runtime-mode-context-module/index.js new file mode 100644 index 000000000000..a99d7a681007 --- /dev/null +++ b/tests/rspack-test/configCases/runtime/runtime-mode-context-module/index.js @@ -0,0 +1,6 @@ +const context = require.context("./modules", false, /\.js$/); + +it("keeps require.context separate from rspack runtime context", () => { + expect(context("./a.js").value).toBe("a"); + expect(context.keys()).toEqual(["./a.js"]); +}); diff --git a/tests/rspack-test/configCases/runtime/runtime-mode-context-module/modules/a.js b/tests/rspack-test/configCases/runtime/runtime-mode-context-module/modules/a.js new file mode 100644 index 000000000000..d392b98f3665 --- /dev/null +++ b/tests/rspack-test/configCases/runtime/runtime-mode-context-module/modules/a.js @@ -0,0 +1 @@ +exports.value = "a"; diff --git a/tests/rspack-test/configCases/runtime/runtime-mode-context-module/rspack.config.js b/tests/rspack-test/configCases/runtime/runtime-mode-context-module/rspack.config.js new file mode 100644 index 000000000000..c037eb342a25 --- /dev/null +++ b/tests/rspack-test/configCases/runtime/runtime-mode-context-module/rspack.config.js @@ -0,0 +1,12 @@ +/** @type {import("@rspack/core").Configuration} */ +module.exports = { + experiments: { + runtimeMode: 'rspack', + }, + output: { + filename: 'main.js', + }, + optimization: { + concatenateModules: false, + }, +}; diff --git a/tests/rspack-test/configCases/runtime/runtime-mode-context-module/test.config.js b/tests/rspack-test/configCases/runtime/runtime-mode-context-module/test.config.js new file mode 100644 index 000000000000..c1df3a3ca584 --- /dev/null +++ b/tests/rspack-test/configCases/runtime/runtime-mode-context-module/test.config.js @@ -0,0 +1,16 @@ +const fs = require("fs"); +const path = require("path"); + +/** @type {import("../../../..").TConfigCaseConfig} */ +module.exports = { + afterExecute(options) { + const source = fs.readFileSync( + path.resolve(options.output.path, "main.js"), + "utf-8", + ); + + expect(source).toContain("var __rspack_context={};"); + expect(source).toContain("function __rspack_context_module(req)"); + expect(source).not.toContain("function __rspack_context(req)"); + }, +}; diff --git a/tests/rspack-test/configCases/runtime/runtime-mode-custom-runtime-module-error/errors.js b/tests/rspack-test/configCases/runtime/runtime-mode-custom-runtime-module-error/errors.js new file mode 100644 index 000000000000..318c96b24d05 --- /dev/null +++ b/tests/rspack-test/configCases/runtime/runtime-mode-custom-runtime-module-error/errors.js @@ -0,0 +1,3 @@ +module.exports = [ + /Custom runtime modules are not supported when `experiments\.runtimeMode` is "rspack"/ +]; diff --git a/tests/rspack-test/configCases/runtime/runtime-mode-custom-runtime-module-error/index.js b/tests/rspack-test/configCases/runtime/runtime-mode-custom-runtime-module-error/index.js new file mode 100644 index 000000000000..aef22247d752 --- /dev/null +++ b/tests/rspack-test/configCases/runtime/runtime-mode-custom-runtime-module-error/index.js @@ -0,0 +1 @@ +export default 1; diff --git a/tests/rspack-test/configCases/runtime/runtime-mode-custom-runtime-module-error/rspack.config.js b/tests/rspack-test/configCases/runtime/runtime-mode-custom-runtime-module-error/rspack.config.js new file mode 100644 index 000000000000..4852743d1638 --- /dev/null +++ b/tests/rspack-test/configCases/runtime/runtime-mode-custom-runtime-module-error/rspack.config.js @@ -0,0 +1,36 @@ +const { RuntimeModule } = require('@rspack/core'); + +class CustomRuntimeModule extends RuntimeModule { + constructor() { + super('custom'); + } + + generate() { + return '__webpack_require__.custom = 1;'; + } +} + +/** @type {import("@rspack/core").Configuration} */ +module.exports = { + experiments: { + runtimeMode: 'rspack', + }, + plugins: [ + (compiler) => { + const { RuntimeGlobals } = compiler.rspack; + + compiler.hooks.thisCompilation.tap( + 'CustomRuntimeModulePlugin', + (compilation) => { + compilation.hooks.additionalTreeRuntimeRequirements.tap( + 'CustomRuntimeModulePlugin', + (chunk, runtimeRequirements) => { + runtimeRequirements.add(RuntimeGlobals.require); + compilation.addRuntimeModule(chunk, new CustomRuntimeModule()); + }, + ); + }, + ); + }, + ], +}; diff --git a/tests/rspack-test/configCases/runtime/runtime-mode-custom-runtime-module-error/test.config.js b/tests/rspack-test/configCases/runtime/runtime-mode-custom-runtime-module-error/test.config.js new file mode 100644 index 000000000000..800e4842c070 --- /dev/null +++ b/tests/rspack-test/configCases/runtime/runtime-mode-custom-runtime-module-error/test.config.js @@ -0,0 +1,4 @@ +/** @type {import("../../../..").TConfigCaseConfig} */ +module.exports = { + findBundle: () => ['bundle0.js'], +}; diff --git a/tests/rspack-test/configCases/runtime/runtime-mode-module-rendering/after.js b/tests/rspack-test/configCases/runtime/runtime-mode-module-rendering/after.js new file mode 100644 index 000000000000..ef853b4054d1 --- /dev/null +++ b/tests/rspack-test/configCases/runtime/runtime-mode-module-rendering/after.js @@ -0,0 +1,21 @@ +const fs = require("fs"); +const path = require("path"); + +const source = fs.readFileSync( + path.resolve(__dirname, "dist/main.js"), + "utf-8", +); + +expect(source).toContain("var __rspack_context={};"); +expect(source).toContain("__rspack_context.r = __webpack_require__;"); +expect(source).toContain("__rspack_context.d"); +expect(source).toContain("__rspack_context.N"); +expect(source).toContain("__rspack_context.d = definePropertyGetters;"); +expect(source).toContain("__rspack_context.N = makeNamespaceObject;"); +expect(source).toContain("module.exports, __rspack_context"); +expect(source).toContain("definePropertyGetters ="); +expect(source).toContain("makeNamespaceObject ="); +expect(source).not.toContain("__webpack_require__.d(__webpack_exports__"); +expect(source).not.toContain("__webpack_require__.r(__webpack_exports__"); +expect(source).not.toContain("__webpack_require__.d ="); +expect(source).not.toContain("__webpack_require__.r ="); diff --git a/tests/rspack-test/configCases/runtime/runtime-mode-module-rendering/index.js b/tests/rspack-test/configCases/runtime/runtime-mode-module-rendering/index.js new file mode 100644 index 000000000000..b2f8df3ad6a7 --- /dev/null +++ b/tests/rspack-test/configCases/runtime/runtime-mode-module-rendering/index.js @@ -0,0 +1,7 @@ +export { value } from "./lib"; + +import { value } from "./lib"; + +it("keeps the exported binding live", () => { + expect(value).toBe(42); +}); diff --git a/tests/rspack-test/configCases/runtime/runtime-mode-module-rendering/lib.js b/tests/rspack-test/configCases/runtime/runtime-mode-module-rendering/lib.js new file mode 100644 index 000000000000..46d3ca8c61fb --- /dev/null +++ b/tests/rspack-test/configCases/runtime/runtime-mode-module-rendering/lib.js @@ -0,0 +1 @@ +export const value = 42; diff --git a/tests/rspack-test/configCases/runtime/runtime-mode-module-rendering/rspack.config.js b/tests/rspack-test/configCases/runtime/runtime-mode-module-rendering/rspack.config.js new file mode 100644 index 000000000000..21982a3b7309 --- /dev/null +++ b/tests/rspack-test/configCases/runtime/runtime-mode-module-rendering/rspack.config.js @@ -0,0 +1,13 @@ +/** @type {import("@rspack/core").Configuration} */ +module.exports = { + experiments: { + runtimeMode: 'rspack', + }, + output: { + filename: 'main.js', + }, + optimization: { + concatenateModules: false, + usedExports: false, + }, +}; diff --git a/tests/rspack-test/configCases/runtime/runtime-mode-module-rendering/test.config.js b/tests/rspack-test/configCases/runtime/runtime-mode-module-rendering/test.config.js new file mode 100644 index 000000000000..7e2e2cb0250d --- /dev/null +++ b/tests/rspack-test/configCases/runtime/runtime-mode-module-rendering/test.config.js @@ -0,0 +1,25 @@ +const fs = require("fs"); +const path = require("path"); + +/** @type {import("../../../..").TConfigCaseConfig} */ +module.exports = { + afterExecute(options) { + const source = fs.readFileSync( + path.resolve(options.output.path, "main.js"), + "utf-8", + ); + + expect(source).toContain("var __rspack_context={};"); + expect(source).toContain("__rspack_context.d"); + expect(source).toContain("__rspack_context.N"); + expect(source).toContain("__rspack_context.d = definePropertyGetters;"); + expect(source).toContain("__rspack_context.N = makeNamespaceObject;"); + expect(source).toContain("module.exports, __rspack_context"); + expect(source).toContain("definePropertyGetters ="); + expect(source).toContain("makeNamespaceObject ="); + expect(source).not.toContain("__webpack_require__.d(__webpack_exports__"); + expect(source).not.toContain("__webpack_require__.r(__webpack_exports__"); + expect(source).not.toContain("__webpack_require__.d ="); + expect(source).not.toContain("__webpack_require__.r ="); + }, +}; diff --git a/tests/rspack-test/configCases/runtime/runtime-mode-nested-rspack-context/index.js b/tests/rspack-test/configCases/runtime/runtime-mode-nested-rspack-context/index.js new file mode 100644 index 000000000000..8e3c38b0942f --- /dev/null +++ b/tests/rspack-test/configCases/runtime/runtime-mode-nested-rspack-context/index.js @@ -0,0 +1,21 @@ +function getNestedValue(value) { + function __rspack_context(input) { + return input + value; + } + return __rspack_context(40); +} + +it("keeps nested __rspack_context binding local", () => { + expect(getNestedValue(2)).toBe(42); +}); + +it("renames nested __rspack_context in rspack runtime mode", () => { + if (typeof __rspack_context === "undefined") { + return; + } + const source = require("fs").readFileSync(__filename, "utf-8"); + expect(source).toContain("__nested_rspack_require_"); + expect(source).not.toMatch( + new RegExp(["function ", "__rspack", "_context", "\\("].join("")) + ); +}); diff --git a/tests/rspack-test/configCases/runtime/runtime-mode-nested-rspack-context/rspack.config.js b/tests/rspack-test/configCases/runtime/runtime-mode-nested-rspack-context/rspack.config.js new file mode 100644 index 000000000000..c037eb342a25 --- /dev/null +++ b/tests/rspack-test/configCases/runtime/runtime-mode-nested-rspack-context/rspack.config.js @@ -0,0 +1,12 @@ +/** @type {import("@rspack/core").Configuration} */ +module.exports = { + experiments: { + runtimeMode: 'rspack', + }, + output: { + filename: 'main.js', + }, + optimization: { + concatenateModules: false, + }, +}; diff --git a/tests/rspack-test/configCases/runtime/runtime-mode-option/index.js b/tests/rspack-test/configCases/runtime/runtime-mode-option/index.js new file mode 100644 index 000000000000..aef22247d752 --- /dev/null +++ b/tests/rspack-test/configCases/runtime/runtime-mode-option/index.js @@ -0,0 +1 @@ +export default 1; diff --git a/tests/rspack-test/configCases/runtime/runtime-mode-option/rspack.config.js b/tests/rspack-test/configCases/runtime/runtime-mode-option/rspack.config.js new file mode 100644 index 000000000000..182bcbdb8d06 --- /dev/null +++ b/tests/rspack-test/configCases/runtime/runtime-mode-option/rspack.config.js @@ -0,0 +1 @@ +module.exports = { experiments: { runtimeMode: 'rspack' } }; diff --git a/tests/rspack-test/configCases/runtime/runtime-mode-require-context/index.js b/tests/rspack-test/configCases/runtime/runtime-mode-require-context/index.js new file mode 100644 index 000000000000..704b05c5a7c5 --- /dev/null +++ b/tests/rspack-test/configCases/runtime/runtime-mode-require-context/index.js @@ -0,0 +1,5 @@ +const value = require("./lib"); + +it("loads through the rspack runtime context require alias", () => { + expect(value).toBe(42); +}); diff --git a/tests/rspack-test/configCases/runtime/runtime-mode-require-context/lib.js b/tests/rspack-test/configCases/runtime/runtime-mode-require-context/lib.js new file mode 100644 index 000000000000..888cae37af95 --- /dev/null +++ b/tests/rspack-test/configCases/runtime/runtime-mode-require-context/lib.js @@ -0,0 +1 @@ +module.exports = 42; diff --git a/tests/rspack-test/configCases/runtime/runtime-mode-require-context/rspack.config.js b/tests/rspack-test/configCases/runtime/runtime-mode-require-context/rspack.config.js new file mode 100644 index 000000000000..c037eb342a25 --- /dev/null +++ b/tests/rspack-test/configCases/runtime/runtime-mode-require-context/rspack.config.js @@ -0,0 +1,12 @@ +/** @type {import("@rspack/core").Configuration} */ +module.exports = { + experiments: { + runtimeMode: 'rspack', + }, + output: { + filename: 'main.js', + }, + optimization: { + concatenateModules: false, + }, +}; diff --git a/tests/rspack-test/configCases/runtime/runtime-mode-require-context/test.config.js b/tests/rspack-test/configCases/runtime/runtime-mode-require-context/test.config.js new file mode 100644 index 000000000000..ed979885e540 --- /dev/null +++ b/tests/rspack-test/configCases/runtime/runtime-mode-require-context/test.config.js @@ -0,0 +1,18 @@ +const fs = require("fs"); +const path = require("path"); + +/** @type {import("../../../..").TConfigCaseConfig} */ +module.exports = { + afterExecute(options) { + const source = fs.readFileSync( + path.resolve(options.output.path, "main.js"), + "utf-8", + ); + + expect(source).toContain("var __rspack_context={};"); + expect(source).toContain("__rspack_context.r"); + expect(source).toContain("module.exports, __rspack_context"); + expect(source).not.toContain("__rspack_context.d"); + expect(source).not.toContain("__rspack_context.N"); + }, +}; diff --git a/tests/rspack-test/configCases/runtime/runtime-mode-unsupported-require-property/index.js b/tests/rspack-test/configCases/runtime/runtime-mode-unsupported-require-property/index.js new file mode 100644 index 000000000000..8542a33fe650 --- /dev/null +++ b/tests/rspack-test/configCases/runtime/runtime-mode-unsupported-require-property/index.js @@ -0,0 +1,9 @@ +const getter = __webpack_require__.d; +__webpack_require__.d({}, {}); +__webpack_require__.d({}, __webpack_require__.t); +__webpack_require__.d = function () {}; +const boundGetter = __webpack_require__.d.bind(null); +const nestedGetter = __webpack_require__.d.foo; +__webpack_require__.d.foo = 1; +__webpack_require__.d.bar = __webpack_require__.t; +export { boundGetter, getter, nestedGetter }; diff --git a/tests/rspack-test/configCases/runtime/runtime-mode-unsupported-require-property/rspack.config.js b/tests/rspack-test/configCases/runtime/runtime-mode-unsupported-require-property/rspack.config.js new file mode 100644 index 000000000000..176b2c7849fd --- /dev/null +++ b/tests/rspack-test/configCases/runtime/runtime-mode-unsupported-require-property/rspack.config.js @@ -0,0 +1,6 @@ +/** @type {import("@rspack/core").Configuration} */ +module.exports = { + experiments: { + runtimeMode: 'rspack', + }, +}; diff --git a/tests/rspack-test/configCases/runtime/runtime-mode-unsupported-require-property/test.config.js b/tests/rspack-test/configCases/runtime/runtime-mode-unsupported-require-property/test.config.js new file mode 100644 index 000000000000..a9e7a1cf6555 --- /dev/null +++ b/tests/rspack-test/configCases/runtime/runtime-mode-unsupported-require-property/test.config.js @@ -0,0 +1,4 @@ +/** @type {import("../../../..").TConfigCaseConfig} */ +module.exports = { + error: true, +}; diff --git a/tests/rspack-test/configCases/runtime/split-css-chunk-async/index1.js b/tests/rspack-test/configCases/runtime/split-css-chunk-async/index1.js index 47e4bde3e024..48b5751c0118 100644 --- a/tests/rspack-test/configCases/runtime/split-css-chunk-async/index1.js +++ b/tests/rspack-test/configCases/runtime/split-css-chunk-async/index1.js @@ -2,7 +2,7 @@ it("should load css chunk", async function () { const module = await import("./share"); expect(module.value).toBe(1); // test is only for css loading - if (__webpack_require__.f.css) { + if (typeof document !== "undefined" && __webpack_require__.f.css) { expect(document.getElementsByTagName("link").length).toBe(2); } }); diff --git a/tests/rspack-test/configCases/runtime/split-css-chunk/index1.js b/tests/rspack-test/configCases/runtime/split-css-chunk/index1.js index 42158d93e0fd..bd757fd5f409 100644 --- a/tests/rspack-test/configCases/runtime/split-css-chunk/index1.js +++ b/tests/rspack-test/configCases/runtime/split-css-chunk/index1.js @@ -2,7 +2,7 @@ it("should load css chunk", async function () { const module = await import("./common"); expect(module.value).toBe(1); // test is only for css loading - if (__webpack_require__.f.css) { + if (typeof document !== "undefined" && __webpack_require__.f.css) { expect(document.getElementsByTagName("link").length).toBe(1); } }); diff --git a/tests/rspack-test/configCases/source-map/verify-css-js-mix/index.js b/tests/rspack-test/configCases/source-map/verify-css-js-mix/index.js index 272c9b6fc786..d30919fcd65a 100644 --- a/tests/rspack-test/configCases/source-map/verify-css-js-mix/index.js +++ b/tests/rspack-test/configCases/source-map/verify-css-js-mix/index.js @@ -11,13 +11,18 @@ try { it("verify importing css js source map", async () => { const source = fs.readFileSync(__filename + ".map", "utf-8"); const map = JSON.parse(source); - expect(map.sources.sort()).toEqual([ + const out = fs.readFileSync(__filename, "utf-8"); + const usesRuntimeContext = out.includes(["var ", "__rspack_context"].join("")); + expect(map.sources.sort()).toEqual(usesRuntimeContext ? [ + "webpack:///./a.js", + "webpack:///./index.js", + "webpack:///webpack/runtime/make_namespace_object", + ] : [ "webpack:///./a.js", "webpack:///./index.js", "webpack:///webpack/runtime/make_namespace_object", ]); expect(map.file).toEqual("bundle0.js"); - const out = fs.readFileSync(__filename, "utf-8"); expect( await checkMap(out, source, { // *${id}* as the search key to avoid conflict with `Object.defineProperty(exports, ${id}, ...)` diff --git a/tests/rspack-test/configCases/source-map/verify-es6/index.js b/tests/rspack-test/configCases/source-map/verify-es6/index.js index f7b55129ce90..a027bc409097 100644 --- a/tests/rspack-test/configCases/source-map/verify-es6/index.js +++ b/tests/rspack-test/configCases/source-map/verify-es6/index.js @@ -10,7 +10,8 @@ it("verify es6 (esmodule) bundle source map", async () => { const fs = require("fs"); const source = fs.readFileSync(__filename + ".map", "utf-8"); const map = JSON.parse(source); - expect(map.sources).toEqual([ + const out = fs.readFileSync(__filename, "utf-8"); + expect(map.sources.filter(source => !source.startsWith("webpack:///webpack/runtime/"))).toEqual([ `webpack:///../../../../../packages/rspack-test-tools/dist/helper/util/checkSourceMap.js`, "webpack:///./b-dir/c-dir/c.js", "webpack:///./b-dir/b.js", @@ -18,7 +19,6 @@ it("verify es6 (esmodule) bundle source map", async () => { "webpack:///./index.js", ]); expect(map.file).toEqual("bundle0.js"); - const out = fs.readFileSync(__filename, "utf-8"); expect( await checkMap(out, source, { // *${id}* as the search key to avoid conflict with `Object.defineProperty(exports, ${id}, ...)` diff --git a/tests/rspack-test/configCases/trusted-types/module-runtime-requirement/index.js b/tests/rspack-test/configCases/trusted-types/module-runtime-requirement/index.js index 7bf2d3712086..29c26d71cfe2 100644 --- a/tests/rspack-test/configCases/trusted-types/module-runtime-requirement/index.js +++ b/tests/rspack-test/configCases/trusted-types/module-runtime-requirement/index.js @@ -14,6 +14,11 @@ createWorker; it("should generate correct new Worker statement", async () => { const content = fs.readFileSync(path.resolve(path.dirname(__filename), './test-worker.js'), "utf-8"); expect(content).toContain(`this is worker`); - expect(content).toContain(`(__unused_rspack_module, __unused_rspack_exports, __webpack_require__)`); - expect(content).toContain(`eval(__webpack_require__.ts(`); + if (content.includes(["var ", "__rspack_context"].join(""))) { + expect(content).toContain(`(__unused_rspack_module, __unused_rspack_exports, __rspack_context)`); + expect(content).toContain(`eval(__rspack_context.ts(`); + } else { + expect(content).toContain(`(__unused_rspack_module, __unused_rspack_exports, __webpack_require__)`); + expect(content).toContain(`eval(__webpack_require__.ts(`); + } }); diff --git a/tests/rspack-test/configCases/trusted-types/web-worker/index.js b/tests/rspack-test/configCases/trusted-types/web-worker/index.js index 68a6d735a439..59d76a8321b9 100644 --- a/tests/rspack-test/configCases/trusted-types/web-worker/index.js +++ b/tests/rspack-test/configCases/trusted-types/web-worker/index.js @@ -12,7 +12,9 @@ createWorker; it("should generate correct new Worker statement", async () => { const content = fs.readFileSync(__filename, "utf-8"); - const method = "__webpack_require__.tu"; + const method = content.includes(["var ", "__rspack_context"].join("")) + ? "__rspack_context.tu" + : "__webpack_require__.tu"; expect(content).toContain(`new Worker(${method}(new URL(`) }); @@ -26,7 +28,10 @@ createWorkerWithChunkName it("should generate correct new Worker statement with magic comments", async () => { const content = fs.readFileSync(__filename, "utf-8"); const chunkName = "someChunkName"; - expect(content).toContain(`new Worker(/* webpackChunkName: "${chunkName}" */__webpack_require__.tu(new URL(`) + const method = content.includes(["var ", "__rspack_context"].join("")) + ? "__rspack_context.tu" + : "__webpack_require__.tu"; + expect(content).toContain(`new Worker(/* webpackChunkName: "${chunkName}" */${method}(new URL(`) expect(fs.existsSync(path.join(__dirname, `${chunkName}.js`))).toBeTruthy(); }); @@ -40,6 +45,9 @@ createWorkerWithChunkNameInnner it("should generate correct new Worker statement with magic comments", async () => { const content = fs.readFileSync(__filename, "utf-8"); const chunkName = "someChunkName2"; - expect(content).toContain(`new Worker(__webpack_require__.tu(new URL(/* webpackChunkName: "${chunkName}" */`) + const method = content.includes(["var ", "__rspack_context"].join("")) + ? "__rspack_context.tu" + : "__webpack_require__.tu"; + expect(content).toContain(`new Worker(${method}(new URL(/* webpackChunkName: "${chunkName}" */`) expect(fs.existsSync(path.join(__dirname, `${chunkName}.js`))).toBeTruthy(); }); diff --git a/tests/rspack-test/configCases/umd/issue-15545/rspack.config.js b/tests/rspack-test/configCases/umd/issue-15545/rspack.config.js index 5b9cc0a77ec1..86389d9a0c7d 100644 --- a/tests/rspack-test/configCases/umd/issue-15545/rspack.config.js +++ b/tests/rspack-test/configCases/umd/issue-15545/rspack.config.js @@ -9,7 +9,7 @@ module.exports = { library: { type: 'umd', name: 'MyLibrary' }, chunkLoading: 'jsonp', chunkFormat: 'array-push', - globalObject: 'this', + globalObject: 'globalThis', }, optimization: { minimize: false, diff --git a/tests/rspack-test/configCases/unique-id/all/index.js b/tests/rspack-test/configCases/unique-id/all/index.js index acb9394a4c44..3fd220a23096 100644 --- a/tests/rspack-test/configCases/unique-id/all/index.js +++ b/tests/rspack-test/configCases/unique-id/all/index.js @@ -2,7 +2,10 @@ const path = require("path"); const fs = require("fs"); it("should inject unique id when use bundlerInfo.force=true", () => { + const pattern = globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK + ? /Object\.defineProperty\(__rspack_context, "ruid"/m + : /(^|[^"'`])__webpack_require__\.ruid =/m; expect( fs.readFileSync(path.join(__dirname, "bundle0.js"), "utf-8") - ).toMatch(/(^|[^"'`])__webpack_require__\.ruid =/m); + ).toMatch(pattern); }); diff --git a/tests/rspack-test/configCases/unique-id/array/index.js b/tests/rspack-test/configCases/unique-id/array/index.js index c3a96e92100c..684af518f7de 100644 --- a/tests/rspack-test/configCases/unique-id/array/index.js +++ b/tests/rspack-test/configCases/unique-id/array/index.js @@ -2,7 +2,10 @@ const path = require("path"); const fs = require("fs"); it('should inject unique id when use bundlerInfo.force=["uniqueId"]', () => { + const pattern = globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK + ? /Object\.defineProperty\(__rspack_context, "ruid"/m + : /(^|[^"'`])__webpack_require__\.ruid =/m; expect( fs.readFileSync(path.join(__dirname, "bundle0.js"), "utf-8") - ).toMatch(/(^|[^"'`])__webpack_require__\.ruid =/m); + ).toMatch(pattern); }); diff --git a/tests/rspack-test/configCases/version/all/index.js b/tests/rspack-test/configCases/version/all/index.js index 3b683347ae04..55d8d60feec5 100644 --- a/tests/rspack-test/configCases/version/all/index.js +++ b/tests/rspack-test/configCases/version/all/index.js @@ -2,7 +2,10 @@ const path = require("path"); const fs = require("fs"); it("should inject version when use bundlerInfo.force=true", () => { + const pattern = globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK + ? /Object\.defineProperty\(__rspack_context, "rv"/m + : /(^|[^"'`])__webpack_require__\.rv =/m; expect( fs.readFileSync(path.join(__dirname, "bundle0.js"), "utf-8") - ).toMatch(/(^|[^"'`])__webpack_require__\.rv =/m); + ).toMatch(pattern); }); diff --git a/tests/rspack-test/configCases/version/array/index.js b/tests/rspack-test/configCases/version/array/index.js index a1221700554b..9b0a9a4e5d24 100644 --- a/tests/rspack-test/configCases/version/array/index.js +++ b/tests/rspack-test/configCases/version/array/index.js @@ -2,7 +2,10 @@ const path = require("path"); const fs = require("fs"); it('should inject version when use bundlerInfo.force=["version"]', () => { + const pattern = globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK + ? /Object\.defineProperty\(__rspack_context, "rv"/m + : /(^|[^"'`])__webpack_require__\.rv =/m; expect( fs.readFileSync(path.join(__dirname, "bundle0.js"), "utf-8") - ).toMatch(/(^|[^"'`])__webpack_require__\.rv =/m); + ).toMatch(pattern); }); diff --git a/tests/rspack-test/defaultsCases/default/base.js b/tests/rspack-test/defaultsCases/default/base.js index fd327ebfa1dd..4b211ca78355 100644 --- a/tests/rspack-test/defaultsCases/default/base.js +++ b/tests/rspack-test/defaultsCases/default/base.js @@ -25,6 +25,7 @@ module.exports = { deferImport: false, futureDefaults: false, pureFunctions: false, + runtimeMode: webpack, sourceImport: false, useInputFileSystem: false, }, diff --git a/tests/rspack-test/esmOutputCases/basic/export-shared-namespace/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/basic/export-shared-namespace/__snapshots__/esm.snap.txt index 3897606dec7e..b6cda32c2aec 100644 --- a/tests/rspack-test/esmOutputCases/basic/export-shared-namespace/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/basic/export-shared-namespace/__snapshots__/esm.snap.txt @@ -40,7 +40,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } @@ -56,7 +56,7 @@ export { __webpack_require__ }; import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./shared.js var shared_namespaceObject = {}; -__webpack_require__.r(shared_namespaceObject); +__webpack_require__.N(shared_namespaceObject); __webpack_require__.d(shared_namespaceObject, { a: () => (a), b: () => (b) }); diff --git a/tests/rspack-test/esmOutputCases/basic/tree-shaking/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/basic/tree-shaking/__snapshots__/esm.snap.txt index 795a9ad3d9f9..97e9de05a1c8 100644 --- a/tests/rspack-test/esmOutputCases/basic/tree-shaking/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/basic/tree-shaking/__snapshots__/esm.snap.txt @@ -22,7 +22,7 @@ console.log.bind((__webpack_require__(/*! fs */ "fs")/* .readFile */.readFile)) !*** ./index.js ***! \******************/ (module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var _cjs__rspack_import_0 = __webpack_require__(/*! ./cjs */ "./cjs.js"); /* module decorator */ module = __webpack_require__.hmd(module); @@ -139,7 +139,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/basic/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/basic/__snapshots__/esm.snap.txt index 6df11ec9778d..c338664bf7c8 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/basic/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/basic/__snapshots__/esm.snap.txt @@ -10,7 +10,7 @@ export default dynamic; import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./dynamic.js?1 var dynamic1_namespaceObject = {}; -__webpack_require__.r(dynamic1_namespaceObject); +__webpack_require__.N(dynamic1_namespaceObject); __webpack_require__.d(dynamic1_namespaceObject, { "default": () => (dynamic1) }); @@ -59,7 +59,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-conflict-exports/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-conflict-exports/__snapshots__/esm.snap.txt index 409a485f4bb6..d73e994ba5ba 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-conflict-exports/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-conflict-exports/__snapshots__/esm.snap.txt @@ -2,14 +2,14 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./a.js var a_namespaceObject = {}; -__webpack_require__.r(a_namespaceObject); +__webpack_require__.N(a_namespaceObject); __webpack_require__.d(a_namespaceObject, { value: () => (value) }); // NAMESPACE OBJECT: ./b.js var b_namespaceObject = {}; -__webpack_require__.r(b_namespaceObject); +__webpack_require__.N(b_namespaceObject); __webpack_require__.d(b_namespaceObject, { value: () => (b_value) }); @@ -71,7 +71,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-mixed-chunks/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-mixed-chunks/__snapshots__/esm.snap.txt index 968629ee6f95..3f9c6c3295ac 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-mixed-chunks/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-mixed-chunks/__snapshots__/esm.snap.txt @@ -45,7 +45,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } @@ -61,7 +61,7 @@ export { __webpack_require__ }; import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./m1.js var m1_namespaceObject = {}; -__webpack_require__.r(m1_namespaceObject); +__webpack_require__.N(m1_namespaceObject); __webpack_require__.d(m1_namespaceObject, { "default": () => (m1), value: () => (value) }); @@ -69,7 +69,7 @@ __webpack_require__.d(m1_namespaceObject, { // NAMESPACE OBJECT: ./m2.js var m2_namespaceObject = {}; -__webpack_require__.r(m2_namespaceObject); +__webpack_require__.N(m2_namespaceObject); __webpack_require__.d(m2_namespaceObject, { "default": () => (m2), value: () => (m2_value) }); diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-module-external-namespace-default-named-collision/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-module-external-namespace-default-named-collision/__snapshots__/esm.snap.txt index 364427e0e5f6..bb85baec3964 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-module-external-namespace-default-named-collision/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-module-external-namespace-default-named-collision/__snapshots__/esm.snap.txt @@ -46,7 +46,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } @@ -64,7 +64,7 @@ import foo_runtime, { foo } from "./foo-runtime.mjs"; // NAMESPACE OBJECT: ./a.js var a_namespaceObject = {}; -__webpack_require__.r(a_namespaceObject); +__webpack_require__.N(a_namespaceObject); __webpack_require__.d(a_namespaceObject, { "default": () => (a), shared: () => (shared) }); @@ -72,7 +72,7 @@ __webpack_require__.d(a_namespaceObject, { // NAMESPACE OBJECT: ./b.js var b_namespaceObject = {}; -__webpack_require__.r(b_namespaceObject); +__webpack_require__.N(b_namespaceObject); __webpack_require__.d(b_namespaceObject, { namedFoo: () => (foo), shared: () => (b_shared) }); diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-multi-module-duplicate-external/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-multi-module-duplicate-external/__snapshots__/esm.snap.txt index e5a7102f279a..0766be9eb6cd 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-multi-module-duplicate-external/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-multi-module-duplicate-external/__snapshots__/esm.snap.txt @@ -39,7 +39,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } @@ -57,7 +57,7 @@ import fs, { readFile, readFileSync } from "fs"; // NAMESPACE OBJECT: ./a.js var a_namespaceObject = {}; -__webpack_require__.r(a_namespaceObject); +__webpack_require__.N(a_namespaceObject); __webpack_require__.d(a_namespaceObject, { fsDefault: () => (fs), readFile: () => (readFile), @@ -66,7 +66,7 @@ __webpack_require__.d(a_namespaceObject, { // NAMESPACE OBJECT: ./b.js var b_namespaceObject = {}; -__webpack_require__.r(b_namespaceObject); +__webpack_require__.N(b_namespaceObject); __webpack_require__.d(b_namespaceObject, { marker: () => (marker), readFile: () => (readFile) }); diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-multi-module-namespace-named-external/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-multi-module-namespace-named-external/__snapshots__/esm.snap.txt index 454b48ae094d..a7ca0a39cf95 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-multi-module-namespace-named-external/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-multi-module-namespace-named-external/__snapshots__/esm.snap.txt @@ -39,7 +39,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } @@ -58,14 +58,14 @@ import { resolve } from "path"; // NAMESPACE OBJECT: ./a.js var a_namespaceObject = {}; -__webpack_require__.r(a_namespaceObject); +__webpack_require__.N(a_namespaceObject); __webpack_require__.d(a_namespaceObject, { resolve: () => (__rspack_external_path) }); // NAMESPACE OBJECT: ./b.js var b_namespaceObject = {}; -__webpack_require__.r(b_namespaceObject); +__webpack_require__.N(b_namespaceObject); __webpack_require__.d(b_namespaceObject, { marker: () => (marker), resolve: () => (resolve) }); diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-three-modules/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-three-modules/__snapshots__/esm.snap.txt index 373fac6f7eee..c8f47429da02 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-three-modules/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-three-modules/__snapshots__/esm.snap.txt @@ -26,7 +26,7 @@ export {}; import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./a.js var a_namespaceObject = {}; -__webpack_require__.r(a_namespaceObject); +__webpack_require__.N(a_namespaceObject); __webpack_require__.d(a_namespaceObject, { "default": () => (a), id: () => (id), @@ -35,7 +35,7 @@ __webpack_require__.d(a_namespaceObject, { // NAMESPACE OBJECT: ./b.js var b_namespaceObject = {}; -__webpack_require__.r(b_namespaceObject); +__webpack_require__.N(b_namespaceObject); __webpack_require__.d(b_namespaceObject, { "default": () => (b), id: () => (b_id), @@ -44,7 +44,7 @@ __webpack_require__.d(b_namespaceObject, { // NAMESPACE OBJECT: ./c.js var c_namespaceObject = {}; -__webpack_require__.r(c_namespaceObject); +__webpack_require__.N(c_namespaceObject); __webpack_require__.d(c_namespaceObject, { "default": () => (c), id: () => (c_id), @@ -95,7 +95,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-treeshake-real-conflict/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-treeshake-real-conflict/__snapshots__/esm.snap.txt index 5f82e4c57ad3..15944edfc209 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-treeshake-real-conflict/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-treeshake-real-conflict/__snapshots__/esm.snap.txt @@ -41,7 +41,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } @@ -57,7 +57,7 @@ export { __webpack_require__ }; import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./a.js var a_namespaceObject = {}; -__webpack_require__.r(a_namespaceObject); +__webpack_require__.N(a_namespaceObject); __webpack_require__.d(a_namespaceObject, { foo: () => (foo), value: () => (value) }); @@ -65,7 +65,7 @@ __webpack_require__.d(a_namespaceObject, { // NAMESPACE OBJECT: ./b.js var b_namespaceObject = {}; -__webpack_require__.r(b_namespaceObject); +__webpack_require__.N(b_namespaceObject); __webpack_require__.d(b_namespaceObject, { bar: () => (bar), value: () => (b_value) }); diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/import-cjs-runtime-chunk-false-async-chunk/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/import-cjs-runtime-chunk-false-async-chunk/__snapshots__/esm.snap.txt index 31c2b2581384..695cf535c7ad 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/import-cjs-runtime-chunk-false-async-chunk/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/import-cjs-runtime-chunk-false-async-chunk/__snapshots__/esm.snap.txt @@ -106,7 +106,7 @@ __webpack_require__.t = function(value, mode) { if((mode & 16) && typeof value.then === 'function') return value; } var ns = Object.create(null); - __webpack_require__.r(ns); + __webpack_require__.N(ns); var def = {}; leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)]; for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) { @@ -116,6 +116,7 @@ __webpack_require__.t = function(value, mode) { __webpack_require__.d(ns, def); return ns; }; + })(); // webpack/runtime/define_property_getters (() => { @@ -143,7 +144,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/import-cjs-runtime-chunk-false-entry-export/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/import-cjs-runtime-chunk-false-entry-export/__snapshots__/esm.snap.txt index 4fc7237b846a..eb41b5da194d 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/import-cjs-runtime-chunk-false-entry-export/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/import-cjs-runtime-chunk-false-entry-export/__snapshots__/esm.snap.txt @@ -80,7 +80,7 @@ __webpack_require__.t = function(value, mode) { if((mode & 16) && typeof value.then === 'function') return value; } var ns = Object.create(null); - __webpack_require__.r(ns); + __webpack_require__.N(ns); var def = {}; leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)]; for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) { @@ -90,6 +90,7 @@ __webpack_require__.t = function(value, mode) { __webpack_require__.d(ns, def); return ns; }; + })(); // webpack/runtime/define_property_getters (() => { @@ -120,7 +121,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } @@ -136,14 +137,14 @@ __webpack_require__.r = (exports) => { var installedChunks = {"index_js": 0,"main": 0,}; var installChunk = (data) => { var __rspack_esm_ids = data.__rspack_esm_ids; - var __webpack_modules__ = data.__webpack_modules__; + var moreModules = data.__webpack_modules__; var __rspack_esm_runtime = data.__rspack_esm_runtime; // add "modules" to the modules object, // then flag all "ids" as loaded and fire callback var moduleId, chunkId, i = 0; - for (moduleId in __webpack_modules__) { - if (__webpack_require__.o(__webpack_modules__, moduleId)) { - __webpack_require__.m[moduleId] = __webpack_modules__[moduleId]; + for (moduleId in moreModules) { + if (__webpack_require__.o(moreModules, moduleId)) { + __webpack_require__.m[moduleId] = moreModules[moduleId]; } } if (__rspack_esm_runtime) __rspack_esm_runtime(__webpack_require__); @@ -155,7 +156,8 @@ __webpack_require__.r = (exports) => { installedChunks[__rspack_esm_ids[i]] = 0; } -};// no chunk on demand loading +}; +// no chunk on demand loading __webpack_require__.C = installChunk; // no on chunks loaded diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/import-cjs/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/import-cjs/__snapshots__/esm.snap.txt index a85464e374ea..5ee4bb817391 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/import-cjs/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/import-cjs/__snapshots__/esm.snap.txt @@ -107,7 +107,7 @@ __webpack_require__.t = function(value, mode) { if((mode & 16) && typeof value.then === 'function') return value; } var ns = Object.create(null); - __webpack_require__.r(ns); + __webpack_require__.N(ns); var def = {}; leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)]; for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) { @@ -117,6 +117,7 @@ __webpack_require__.t = function(value, mode) { __webpack_require__.d(ns, def); return ns; }; + })(); // webpack/runtime/define_property_getters (() => { @@ -144,7 +145,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/import-context-css/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/import-context-css/__snapshots__/esm.snap.txt index b31481493a60..10dcaa64d447 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/import-context-css/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/import-context-css/__snapshots__/esm.snap.txt @@ -18,7 +18,7 @@ __webpack_require__.add({ !*** ./modules/a.js ***! \**********************/ (__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* export default */ const __rspack_default_export = ("a"); @@ -195,7 +195,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } @@ -228,9 +228,7 @@ linkTag.rel = "stylesheet"; linkTag.type = "text/css"; -if (__webpack_require__.nc) { - linkTag.nonce = __webpack_require__.nc; -} + linkTag.href = fullhref; if (fetchPriority) { diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/import-context-lazy/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/import-context-lazy/__snapshots__/esm.snap.txt index 340a24332838..ea3a357383fd 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/import-context-lazy/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/import-context-lazy/__snapshots__/esm.snap.txt @@ -7,7 +7,7 @@ __webpack_require__.add({ !*** ./modules/a.js ***! \**********************/ (__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* export default */ const __rspack_default_export = ("a"); __webpack_require__.d(__webpack_exports__, { @@ -31,7 +31,7 @@ __webpack_require__.add({ !*** ./modules/b.js ***! \**********************/ (__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* export default */ const __rspack_default_export = ("b"); __webpack_require__.d(__webpack_exports__, { @@ -190,7 +190,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/import-context-multi-chunk/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/import-context-multi-chunk/__snapshots__/esm.snap.txt index c089c17e118f..f011bb269724 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/import-context-multi-chunk/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/import-context-multi-chunk/__snapshots__/esm.snap.txt @@ -8,7 +8,7 @@ __webpack_require__.add({ !*** ./modules/a.js ***! \**********************/ (__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var _shared__rspack_import_0 = __webpack_require__(/*! ../shared */ "./shared.js"); @@ -36,7 +36,7 @@ __webpack_require__.add({ !*** ./modules/b.js ***! \**********************/ (__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var _shared__rspack_import_0 = __webpack_require__(/*! ../shared */ "./shared.js"); @@ -197,7 +197,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/import-context-multi-entry/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/import-context-multi-entry/__snapshots__/esm.snap.txt index d80ac56ede7b..b3a69b1e9fd8 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/import-context-multi-entry/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/import-context-multi-entry/__snapshots__/esm.snap.txt @@ -7,7 +7,7 @@ __webpack_require__.add({ !*** ./modules-a/a.js ***! \************************/ (__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* export default */ const __rspack_default_export = ("a"); __webpack_require__.d(__webpack_exports__, { @@ -31,7 +31,7 @@ __webpack_require__.add({ !*** ./modules-b/b.js ***! \************************/ (__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* export default */ const __rspack_default_export = ("b"); __webpack_require__.d(__webpack_exports__, { @@ -182,7 +182,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } @@ -292,7 +292,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/import-context-prefetch-preload/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/import-context-prefetch-preload/__snapshots__/esm.snap.txt index b6475cf95976..94f4155df652 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/import-context-prefetch-preload/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/import-context-prefetch-preload/__snapshots__/esm.snap.txt @@ -7,7 +7,7 @@ __webpack_require__.add({ !*** ./modules/a.js ***! \**********************/ (__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* export default */ const __rspack_default_export = ("a"); __webpack_require__.d(__webpack_exports__, { @@ -30,7 +30,7 @@ __webpack_require__.add({ !*** ./modules/b.js ***! \**********************/ (__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); import("./c.mjs").then(__webpack_require__.bind(__webpack_require__, /*! ./c */ "./modules/c.js")); /* export default */ const __rspack_default_export = ("b"); @@ -55,7 +55,7 @@ __webpack_require__.add({ !*** ./modules/c.js ***! \**********************/ (__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* export default */ const __rspack_default_export = ("c"); __webpack_require__.d(__webpack_exports__, { @@ -282,7 +282,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } @@ -399,12 +399,11 @@ __webpack_require__.F.j = (chunkId) => { installedChunks[chunkId] = null; var link = document.createElement('link'); -if (__webpack_require__.nc) { - link.setAttribute('nonce', __webpack_require__.nc); -} + link.rel = 'prefetch'; link.as = 'script'; link.href = __webpack_require__.p + __webpack_require__.u(chunkId); + document.head.appendChild(link); } }; @@ -413,12 +412,11 @@ __webpack_require__.H.j = (chunkId) => { if((!__webpack_require__.o(installedChunks, chunkId) || installedChunks[chunkId] === undefined) && "runtime" != chunkId) { installedChunks[chunkId] = null; var link = document.createElement('link'); -if (__webpack_require__.nc) { - link.setAttribute("nonce", __webpack_require__.nc); -} + link.rel = 'modulepreload'; link.href = __webpack_require__.p + __webpack_require__.u(chunkId); + document.head.appendChild(link); } }; diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/magic-comment/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/magic-comment/__snapshots__/esm.snap.txt index 3d32640dc15c..326a36a5df4c 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/magic-comment/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/magic-comment/__snapshots__/esm.snap.txt @@ -72,7 +72,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } @@ -88,7 +88,7 @@ export { __webpack_require__ }; import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./m1.js var m1_namespaceObject = {}; -__webpack_require__.r(m1_namespaceObject); +__webpack_require__.N(m1_namespaceObject); __webpack_require__.d(m1_namespaceObject, { "default": () => (m1), value: () => (value) }); @@ -96,7 +96,7 @@ __webpack_require__.d(m1_namespaceObject, { // NAMESPACE OBJECT: ./m2.js var m2_namespaceObject = {}; -__webpack_require__.r(m2_namespaceObject); +__webpack_require__.N(m2_namespaceObject); __webpack_require__.d(m2_namespaceObject, { "default": () => (m2), value: () => (m2_value) }); diff --git a/tests/rspack-test/esmOutputCases/externals/dynamic-import-commonjs-require-collision/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/externals/dynamic-import-commonjs-require-collision/__snapshots__/esm.snap.txt index c99aa9b79bc2..e9cf2a79a4f2 100644 --- a/tests/rspack-test/esmOutputCases/externals/dynamic-import-commonjs-require-collision/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/externals/dynamic-import-commonjs-require-collision/__snapshots__/esm.snap.txt @@ -30,8 +30,25 @@ export { index_require as userRequire, loadPlatform }; ``` ```mjs title=runtime.mjs -// The require scope -var __webpack_require__ = {}; +// The module cache +var __webpack_module_cache__ = {}; +// The require function +function __webpack_require__(moduleId) { +// Check if module is in cache +var cachedModule = __webpack_module_cache__[moduleId]; +if (cachedModule !== undefined) { +return cachedModule.exports; +} +// Create a new module (and put it into the cache) +var module = (__webpack_module_cache__[moduleId] = { +exports: {} +}); +// Execute the module function +__webpack_modules__[moduleId](module, module.exports, __webpack_require__); + +// Return the exports of the module +return module.exports; +} // webpack/runtime/create_fake_namespace_object (() => { @@ -51,7 +68,7 @@ __webpack_require__.t = function(value, mode) { if((mode & 16) && typeof value.then === 'function') return value; } var ns = Object.create(null); - __webpack_require__.r(ns); + __webpack_require__.N(ns); var def = {}; leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)]; for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) { @@ -61,6 +78,7 @@ __webpack_require__.t = function(value, mode) { __webpack_require__.d(ns, def); return ns; }; + })(); // webpack/runtime/define_property_getters (() => { @@ -83,7 +101,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/externals/dynamic-import-node-commonjs-helper-collision/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/externals/dynamic-import-node-commonjs-helper-collision/__snapshots__/esm.snap.txt index d5b7660d7212..9cfbddd552a1 100644 --- a/tests/rspack-test/esmOutputCases/externals/dynamic-import-node-commonjs-helper-collision/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/externals/dynamic-import-node-commonjs-helper-collision/__snapshots__/esm.snap.txt @@ -29,8 +29,25 @@ export { loadFs }; ``` ```mjs title=runtime.mjs -// The require scope -var __webpack_require__ = {}; +// The module cache +var __webpack_module_cache__ = {}; +// The require function +function __webpack_require__(moduleId) { +// Check if module is in cache +var cachedModule = __webpack_module_cache__[moduleId]; +if (cachedModule !== undefined) { +return cachedModule.exports; +} +// Create a new module (and put it into the cache) +var module = (__webpack_module_cache__[moduleId] = { +exports: {} +}); +// Execute the module function +__webpack_modules__[moduleId](module, module.exports, __webpack_require__); + +// Return the exports of the module +return module.exports; +} // webpack/runtime/create_fake_namespace_object (() => { @@ -50,7 +67,7 @@ __webpack_require__.t = function(value, mode) { if((mode & 16) && typeof value.then === 'function') return value; } var ns = Object.create(null); - __webpack_require__.r(ns); + __webpack_require__.N(ns); var def = {}; leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)]; for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) { @@ -60,6 +77,7 @@ __webpack_require__.t = function(value, mode) { __webpack_require__.d(ns, def); return ns; }; + })(); // webpack/runtime/define_property_getters (() => { @@ -82,7 +100,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/externals/esm-node-target/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/externals/esm-node-target/__snapshots__/esm.snap.txt index 24b25b3e89d8..42c5a507b008 100644 --- a/tests/rspack-test/esmOutputCases/externals/esm-node-target/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/externals/esm-node-target/__snapshots__/esm.snap.txt @@ -30,8 +30,25 @@ export { readFileSync } from "fs"; ``` ```mjs title=runtime.mjs -// The require scope -var __webpack_require__ = {}; +// The module cache +var __webpack_module_cache__ = {}; +// The require function +function __webpack_require__(moduleId) { +// Check if module is in cache +var cachedModule = __webpack_module_cache__[moduleId]; +if (cachedModule !== undefined) { +return cachedModule.exports; +} +// Create a new module (and put it into the cache) +var module = (__webpack_module_cache__[moduleId] = { +exports: {} +}); +// Execute the module function +__webpack_modules__[moduleId](module, module.exports, __webpack_require__); + +// Return the exports of the module +return module.exports; +} // webpack/runtime/create_fake_namespace_object (() => { @@ -51,7 +68,7 @@ __webpack_require__.t = function(value, mode) { if((mode & 16) && typeof value.then === 'function') return value; } var ns = Object.create(null); - __webpack_require__.r(ns); + __webpack_require__.N(ns); var def = {}; leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)]; for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) { @@ -61,6 +78,7 @@ __webpack_require__.t = function(value, mode) { __webpack_require__.d(ns, def); return ns; }; + })(); // webpack/runtime/define_property_getters (() => { @@ -83,7 +101,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/externals/node-commonjs-export-namespace-as-with-named/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/externals/node-commonjs-export-namespace-as-with-named/__snapshots__/esm.snap.txt index 6bb4980c1343..05edcd399fe9 100644 --- a/tests/rspack-test/esmOutputCases/externals/node-commonjs-export-namespace-as-with-named/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/externals/node-commonjs-export-namespace-as-with-named/__snapshots__/esm.snap.txt @@ -28,8 +28,25 @@ export { external_fs_namespaceObject as fsNs, readFile, readFileSync }; ``` ```mjs title=runtime.mjs -// The require scope -var __webpack_require__ = {}; +// The module cache +var __webpack_module_cache__ = {}; +// The require function +function __webpack_require__(moduleId) { +// Check if module is in cache +var cachedModule = __webpack_module_cache__[moduleId]; +if (cachedModule !== undefined) { +return cachedModule.exports; +} +// Create a new module (and put it into the cache) +var module = (__webpack_module_cache__[moduleId] = { +exports: {} +}); +// Execute the module function +__webpack_modules__[moduleId](module, module.exports, __webpack_require__); + +// Return the exports of the module +return module.exports; +} // webpack/runtime/create_fake_namespace_object (() => { @@ -49,7 +66,7 @@ __webpack_require__.t = function(value, mode) { if((mode & 16) && typeof value.then === 'function') return value; } var ns = Object.create(null); - __webpack_require__.r(ns); + __webpack_require__.N(ns); var def = {}; leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)]; for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) { @@ -59,6 +76,7 @@ __webpack_require__.t = function(value, mode) { __webpack_require__.d(ns, def); return ns; }; + })(); // webpack/runtime/define_property_getters (() => { @@ -81,7 +99,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/externals/node-commonjs-import-namespace-reexport-with-named/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/externals/node-commonjs-import-namespace-reexport-with-named/__snapshots__/esm.snap.txt index b8b6ae5b8d39..e669ef654ba9 100644 --- a/tests/rspack-test/esmOutputCases/externals/node-commonjs-import-namespace-reexport-with-named/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/externals/node-commonjs-import-namespace-reexport-with-named/__snapshots__/esm.snap.txt @@ -30,8 +30,25 @@ export { external_fs_namespaceObject as fsNs, readFile, readFileSync }; ``` ```mjs title=runtime.mjs -// The require scope -var __webpack_require__ = {}; +// The module cache +var __webpack_module_cache__ = {}; +// The require function +function __webpack_require__(moduleId) { +// Check if module is in cache +var cachedModule = __webpack_module_cache__[moduleId]; +if (cachedModule !== undefined) { +return cachedModule.exports; +} +// Create a new module (and put it into the cache) +var module = (__webpack_module_cache__[moduleId] = { +exports: {} +}); +// Execute the module function +__webpack_modules__[moduleId](module, module.exports, __webpack_require__); + +// Return the exports of the module +return module.exports; +} // webpack/runtime/create_fake_namespace_object (() => { @@ -51,7 +68,7 @@ __webpack_require__.t = function(value, mode) { if((mode & 16) && typeof value.then === 'function') return value; } var ns = Object.create(null); - __webpack_require__.r(ns); + __webpack_require__.N(ns); var def = {}; leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)]; for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) { @@ -61,6 +78,7 @@ __webpack_require__.t = function(value, mode) { __webpack_require__.d(ns, def); return ns; }; + })(); // webpack/runtime/define_property_getters (() => { @@ -83,7 +101,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/externals/node-commonjs-namespace-name-collision-across-modules/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/externals/node-commonjs-namespace-name-collision-across-modules/__snapshots__/esm.snap.txt index f078167dfddb..0511891015f5 100644 --- a/tests/rspack-test/esmOutputCases/externals/node-commonjs-namespace-name-collision-across-modules/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/externals/node-commonjs-namespace-name-collision-across-modules/__snapshots__/esm.snap.txt @@ -44,8 +44,25 @@ export { external_path_namespaceObject as pathNs, joinFn, readFile, readFileSync ``` ```mjs title=runtime.mjs -// The require scope -var __webpack_require__ = {}; +// The module cache +var __webpack_module_cache__ = {}; +// The require function +function __webpack_require__(moduleId) { +// Check if module is in cache +var cachedModule = __webpack_module_cache__[moduleId]; +if (cachedModule !== undefined) { +return cachedModule.exports; +} +// Create a new module (and put it into the cache) +var module = (__webpack_module_cache__[moduleId] = { +exports: {} +}); +// Execute the module function +__webpack_modules__[moduleId](module, module.exports, __webpack_require__); + +// Return the exports of the module +return module.exports; +} // webpack/runtime/create_fake_namespace_object (() => { @@ -65,7 +82,7 @@ __webpack_require__.t = function(value, mode) { if((mode & 16) && typeof value.then === 'function') return value; } var ns = Object.create(null); - __webpack_require__.r(ns); + __webpack_require__.N(ns); var def = {}; leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)]; for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) { @@ -75,6 +92,7 @@ __webpack_require__.t = function(value, mode) { __webpack_require__.d(ns, def); return ns; }; + })(); // webpack/runtime/define_property_getters (() => { @@ -97,7 +115,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/externals/node-commonjs-wrapper-namespace-reexport/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/externals/node-commonjs-wrapper-namespace-reexport/__snapshots__/esm.snap.txt index 57a3dd3f2800..a88a2be55df1 100644 --- a/tests/rspack-test/esmOutputCases/externals/node-commonjs-wrapper-namespace-reexport/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/externals/node-commonjs-wrapper-namespace-reexport/__snapshots__/esm.snap.txt @@ -5,7 +5,7 @@ import { createRequire as __rspack_createRequire } from "node:module"; const __rspack_createRequire_require = __rspack_createRequire(import.meta.url); // NAMESPACE OBJECT: ./exports.js var exports_namespaceObject = {}; -__webpack_require__.r(exports_namespaceObject); +__webpack_require__.N(exports_namespaceObject); __webpack_require__.d(exports_namespaceObject, { sources: () => (index_js_namespaceObject) }); @@ -37,8 +37,25 @@ export { exports_namespaceObject as exportsNS, index_js_namespaceObject as sourc ``` ```mjs title=runtime.mjs -// The require scope -var __webpack_require__ = {}; +// The module cache +var __webpack_module_cache__ = {}; +// The require function +function __webpack_require__(moduleId) { +// Check if module is in cache +var cachedModule = __webpack_module_cache__[moduleId]; +if (cachedModule !== undefined) { +return cachedModule.exports; +} +// Create a new module (and put it into the cache) +var module = (__webpack_module_cache__[moduleId] = { +exports: {} +}); +// Execute the module function +__webpack_modules__[moduleId](module, module.exports, __webpack_require__); + +// Return the exports of the module +return module.exports; +} // webpack/runtime/create_fake_namespace_object (() => { @@ -58,7 +75,7 @@ __webpack_require__.t = function(value, mode) { if((mode & 16) && typeof value.then === 'function') return value; } var ns = Object.create(null); - __webpack_require__.r(ns); + __webpack_require__.N(ns); var def = {}; leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)]; for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) { @@ -68,6 +85,7 @@ __webpack_require__.t = function(value, mode) { __webpack_require__.d(ns, def); return ns; }; + })(); // webpack/runtime/define_property_getters (() => { @@ -90,7 +108,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/externals/reexport-star-as-namespace-via-module-with-own-export/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/externals/reexport-star-as-namespace-via-module-with-own-export/__snapshots__/esm.snap.txt index 9f62ec88a555..a0689c71a824 100644 --- a/tests/rspack-test/esmOutputCases/externals/reexport-star-as-namespace-via-module-with-own-export/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/externals/reexport-star-as-namespace-via-module-with-own-export/__snapshots__/esm.snap.txt @@ -4,7 +4,7 @@ import * as __rspack_external_fs from "fs"; // NAMESPACE OBJECT: ./reexport-external.js var reexport_external_namespaceObject = {}; -__webpack_require__.r(reexport_external_namespaceObject); +__webpack_require__.N(reexport_external_namespaceObject); __webpack_require__.d(reexport_external_namespaceObject, { marker: () => (marker), readFile: () => (readFile) }); @@ -64,7 +64,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/externals/reexport-star-as-namespace-via-module/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/externals/reexport-star-as-namespace-via-module/__snapshots__/esm.snap.txt index b35f0fbdc542..d7a2242e9cd8 100644 --- a/tests/rspack-test/esmOutputCases/externals/reexport-star-as-namespace-via-module/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/externals/reexport-star-as-namespace-via-module/__snapshots__/esm.snap.txt @@ -4,7 +4,7 @@ import * as __rspack_external_fs from "fs"; // NAMESPACE OBJECT: ./reexport-external.js var reexport_external_namespaceObject = {}; -__webpack_require__.r(reexport_external_namespaceObject); +__webpack_require__.N(reexport_external_namespaceObject); var reexport_external_namespaceObject_starExports = __rspack_external_fs; Object.keys(reexport_external_namespaceObject_starExports).forEach(function(key) { if (key !== "default" && key !== "__esModule") { @@ -57,7 +57,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/interop/namespace-import-asset/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/interop/namespace-import-asset/__snapshots__/esm.snap.txt index fbff3ab8acb8..ab7ad6c09610 100644 --- a/tests/rspack-test/esmOutputCases/interop/namespace-import-asset/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/interop/namespace-import-asset/__snapshots__/esm.snap.txt @@ -19,8 +19,25 @@ export {}; ``` ```mjs title=runtime.mjs -// The require scope -var __webpack_require__ = {}; +// The module cache +var __webpack_module_cache__ = {}; +// The require function +function __webpack_require__(moduleId) { +// Check if module is in cache +var cachedModule = __webpack_module_cache__[moduleId]; +if (cachedModule !== undefined) { +return cachedModule.exports; +} +// Create a new module (and put it into the cache) +var module = (__webpack_module_cache__[moduleId] = { +exports: {} +}); +// Execute the module function +__webpack_modules__[moduleId](module, module.exports, __webpack_require__); + +// Return the exports of the module +return module.exports; +} // webpack/runtime/create_fake_namespace_object (() => { @@ -40,7 +57,7 @@ __webpack_require__.t = function(value, mode) { if((mode & 16) && typeof value.then === 'function') return value; } var ns = Object.create(null); - __webpack_require__.r(ns); + __webpack_require__.N(ns); var def = {}; leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)]; for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) { @@ -50,6 +67,7 @@ __webpack_require__.t = function(value, mode) { __webpack_require__.d(ns, def); return ns; }; + })(); // webpack/runtime/define_property_getters (() => { @@ -72,7 +90,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/basic-capture/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/basic-capture/__snapshots__/esm.snap.txt index afcdf4901e5c..3533c5a903b9 100644 --- a/tests/rspack-test/esmOutputCases/namespace/basic-capture/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/basic-capture/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./foo.js var foo_namespaceObject = {}; -__webpack_require__.r(foo_namespaceObject); +__webpack_require__.N(foo_namespaceObject); __webpack_require__.d(foo_namespaceObject, { foo: () => (foo) }); @@ -50,7 +50,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/basic-cjs-capture/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/basic-cjs-capture/__snapshots__/esm.snap.txt index 132df82d8724..17c31bcaab59 100644 --- a/tests/rspack-test/esmOutputCases/namespace/basic-cjs-capture/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/basic-cjs-capture/__snapshots__/esm.snap.txt @@ -72,7 +72,7 @@ __webpack_require__.t = function(value, mode) { if((mode & 16) && typeof value.then === 'function') return value; } var ns = Object.create(null); - __webpack_require__.r(ns); + __webpack_require__.N(ns); var def = {}; leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)]; for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) { @@ -82,6 +82,7 @@ __webpack_require__.t = function(value, mode) { __webpack_require__.d(ns, def); return ns; }; + })(); // webpack/runtime/define_property_getters (() => { @@ -109,7 +110,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/default-only-object/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/default-only-object/__snapshots__/esm.snap.txt index 92d614fa8ee7..7b3847669452 100644 --- a/tests/rspack-test/esmOutputCases/namespace/default-only-object/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/default-only-object/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./dep.js var dep_namespaceObject = {}; -__webpack_require__.r(dep_namespaceObject); +__webpack_require__.N(dep_namespaceObject); __webpack_require__.d(dep_namespaceObject, { "default": () => (dep) }); @@ -52,7 +52,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/empty-modules-default-property/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/empty-modules-default-property/__snapshots__/esm.snap.txt index 862d4372a60a..7c3718fbc2fd 100644 --- a/tests/rspack-test/esmOutputCases/namespace/empty-modules-default-property/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/empty-modules-default-property/__snapshots__/esm.snap.txt @@ -14,12 +14,12 @@ __webpack_require__.add({ }); // NAMESPACE OBJECT: ./empty.js var empty_namespaceObject = {}; -__webpack_require__.r(empty_namespaceObject); +__webpack_require__.N(empty_namespaceObject); // NAMESPACE OBJECT: ./empty.mjs var empty_namespaceObject_0 = {}; -__webpack_require__.r(empty_namespaceObject_0); +__webpack_require__.N(empty_namespaceObject_0); // ./empty.js @@ -108,7 +108,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/empty-modules-missing-property/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/empty-modules-missing-property/__snapshots__/esm.snap.txt index 376395f2b030..f1b2d9eff470 100644 --- a/tests/rspack-test/esmOutputCases/namespace/empty-modules-missing-property/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/empty-modules-missing-property/__snapshots__/esm.snap.txt @@ -14,12 +14,12 @@ __webpack_require__.add({ }); // NAMESPACE OBJECT: ./empty.js var empty_namespaceObject = {}; -__webpack_require__.r(empty_namespaceObject); +__webpack_require__.N(empty_namespaceObject); // NAMESPACE OBJECT: ./empty.mjs var empty_namespaceObject_0 = {}; -__webpack_require__.r(empty_namespaceObject_0); +__webpack_require__.N(empty_namespaceObject_0); // ./empty.js @@ -77,7 +77,7 @@ __webpack_require__.add = function registerModules(modules) { Object.assign(__we // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/export-namespace-as-cjs/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/export-namespace-as-cjs/__snapshots__/esm.snap.txt index 775009832247..57ffd5734d3c 100644 --- a/tests/rspack-test/esmOutputCases/namespace/export-namespace-as-cjs/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/export-namespace-as-cjs/__snapshots__/esm.snap.txt @@ -71,7 +71,7 @@ __webpack_require__.t = function(value, mode) { if((mode & 16) && typeof value.then === 'function') return value; } var ns = Object.create(null); - __webpack_require__.r(ns); + __webpack_require__.N(ns); var def = {}; leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)]; for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) { @@ -81,6 +81,7 @@ __webpack_require__.t = function(value, mode) { __webpack_require__.d(ns, def); return ns; }; + })(); // webpack/runtime/define_property_getters (() => { @@ -108,7 +109,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/export-namespace-as/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/export-namespace-as/__snapshots__/esm.snap.txt index 596307da2b5c..36634cea1a60 100644 --- a/tests/rspack-test/esmOutputCases/namespace/export-namespace-as/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/export-namespace-as/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./dep.js var dep_namespaceObject = {}; -__webpack_require__.r(dep_namespaceObject); +__webpack_require__.N(dep_namespaceObject); __webpack_require__.d(dep_namespaceObject, { bar: () => (bar), foo: () => (foo) }); @@ -51,7 +51,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/export-self-as-namespace/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/export-self-as-namespace/__snapshots__/esm.snap.txt index f84d4abac44a..69410a42d66a 100644 --- a/tests/rspack-test/esmOutputCases/namespace/export-self-as-namespace/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/export-self-as-namespace/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./index.js var index_namespaceObject = {}; -__webpack_require__.r(index_namespaceObject); +__webpack_require__.N(index_namespaceObject); __webpack_require__.d(index_namespaceObject, { foo: () => (foo), ns: () => (index_namespaceObject) }); @@ -48,7 +48,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/import-export-namespace-as-cjs/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/import-export-namespace-as-cjs/__snapshots__/esm.snap.txt index a56842df464b..363e46158a18 100644 --- a/tests/rspack-test/esmOutputCases/namespace/import-export-namespace-as-cjs/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/import-export-namespace-as-cjs/__snapshots__/esm.snap.txt @@ -72,7 +72,7 @@ __webpack_require__.t = function(value, mode) { if((mode & 16) && typeof value.then === 'function') return value; } var ns = Object.create(null); - __webpack_require__.r(ns); + __webpack_require__.N(ns); var def = {}; leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)]; for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) { @@ -82,6 +82,7 @@ __webpack_require__.t = function(value, mode) { __webpack_require__.d(ns, def); return ns; }; + })(); // webpack/runtime/define_property_getters (() => { @@ -109,7 +110,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/import-export-namespace-as/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/import-export-namespace-as/__snapshots__/esm.snap.txt index 83cf329ca6bc..429780aec396 100644 --- a/tests/rspack-test/esmOutputCases/namespace/import-export-namespace-as/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/import-export-namespace-as/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./foo.js var foo_namespaceObject = {}; -__webpack_require__.r(foo_namespaceObject); +__webpack_require__.N(foo_namespaceObject); __webpack_require__.d(foo_namespaceObject, { foo: () => (foo) }); @@ -50,7 +50,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/import-export-self-as-namespace/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/import-export-self-as-namespace/__snapshots__/esm.snap.txt index a341fff9f81a..f2dca57ec672 100644 --- a/tests/rspack-test/esmOutputCases/namespace/import-export-self-as-namespace/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/import-export-self-as-namespace/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./index.js var index_namespaceObject = {}; -__webpack_require__.r(index_namespaceObject); +__webpack_require__.N(index_namespaceObject); __webpack_require__.d(index_namespaceObject, { foo: () => (foo), ns: () => (index_namespaceObject) }); @@ -51,7 +51,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/import-of-export-namespace-as-capture/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/import-of-export-namespace-as-capture/__snapshots__/esm.snap.txt index cc5cf0ae074f..f3d7e0029164 100644 --- a/tests/rspack-test/esmOutputCases/namespace/import-of-export-namespace-as-capture/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/import-of-export-namespace-as-capture/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./foo.js var foo_namespaceObject = {}; -__webpack_require__.r(foo_namespaceObject); +__webpack_require__.N(foo_namespaceObject); __webpack_require__.d(foo_namespaceObject, { foo: () => (foo) }); @@ -50,7 +50,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/import-of-export-star-as/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/import-of-export-star-as/__snapshots__/esm.snap.txt index 90027ba871e6..b9dd7cb04a20 100644 --- a/tests/rspack-test/esmOutputCases/namespace/import-of-export-star-as/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/import-of-export-star-as/__snapshots__/esm.snap.txt @@ -2,14 +2,14 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./bar.js var bar_namespaceObject = {}; -__webpack_require__.r(bar_namespaceObject); +__webpack_require__.N(bar_namespaceObject); __webpack_require__.d(bar_namespaceObject, { bar: () => (bar) }); // NAMESPACE OBJECT: ./foo.js var foo_namespaceObject = {}; -__webpack_require__.r(foo_namespaceObject); +__webpack_require__.N(foo_namespaceObject); __webpack_require__.d(foo_namespaceObject, { barNs: () => (bar_namespaceObject) }); @@ -60,7 +60,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/import-of-re-export-star-capture/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/import-of-re-export-star-capture/__snapshots__/esm.snap.txt index aa4f12b1bf20..f9b0c312b65e 100644 --- a/tests/rspack-test/esmOutputCases/namespace/import-of-re-export-star-capture/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/import-of-re-export-star-capture/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./bar.js var bar_namespaceObject = {}; -__webpack_require__.r(bar_namespaceObject); +__webpack_require__.N(bar_namespaceObject); __webpack_require__.d(bar_namespaceObject, { foo: () => ((/* inlined export .foo */123)) }); @@ -50,7 +50,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/missing-export-capture/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/missing-export-capture/__snapshots__/esm.snap.txt index 97d14d36fbdc..f84130fea637 100644 --- a/tests/rspack-test/esmOutputCases/namespace/missing-export-capture/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/missing-export-capture/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./foo.js var foo_namespaceObject = {}; -__webpack_require__.r(foo_namespaceObject); +__webpack_require__.N(foo_namespaceObject); __webpack_require__.d(foo_namespaceObject, { x: () => (x) }); @@ -48,7 +48,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/missing-export-cjs-capture/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/missing-export-cjs-capture/__snapshots__/esm.snap.txt index 9174941f1dca..bbfcc043c046 100644 --- a/tests/rspack-test/esmOutputCases/namespace/missing-export-cjs-capture/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/missing-export-cjs-capture/__snapshots__/esm.snap.txt @@ -70,7 +70,7 @@ __webpack_require__.t = function(value, mode) { if((mode & 16) && typeof value.then === 'function') return value; } var ns = Object.create(null); - __webpack_require__.r(ns); + __webpack_require__.N(ns); var def = {}; leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)]; for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) { @@ -80,6 +80,7 @@ __webpack_require__.t = function(value, mode) { __webpack_require__.d(ns, def); return ns; }; + })(); // webpack/runtime/define_property_getters (() => { @@ -107,7 +108,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/missing-export-no-capture/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/missing-export-no-capture/__snapshots__/esm.snap.txt index 6c4f18ff7bfc..6b9e28dc6b67 100644 --- a/tests/rspack-test/esmOutputCases/namespace/missing-export-no-capture/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/missing-export-no-capture/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./foo.js var foo_namespaceObject = {}; -__webpack_require__.r(foo_namespaceObject); +__webpack_require__.N(foo_namespaceObject); // ./foo.js @@ -27,7 +27,7 @@ var __webpack_require__ = {}; // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/no-treeshake-object/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/no-treeshake-object/__snapshots__/esm.snap.txt index 6d71686ef6e4..83f80d4b49e8 100644 --- a/tests/rspack-test/esmOutputCases/namespace/no-treeshake-object/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/no-treeshake-object/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./namespace.js var namespace_namespaceObject = {}; -__webpack_require__.r(namespace_namespaceObject); +__webpack_require__.N(namespace_namespaceObject); __webpack_require__.d(namespace_namespaceObject, { foo: () => (foo) }); @@ -59,7 +59,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/optimization-in-operator/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/optimization-in-operator/__snapshots__/esm.snap.txt index de73fbc559cd..fad04277fc59 100644 --- a/tests/rspack-test/esmOutputCases/namespace/optimization-in-operator/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/optimization-in-operator/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./foo.js var foo_namespaceObject = {}; -__webpack_require__.r(foo_namespaceObject); +__webpack_require__.N(foo_namespaceObject); __webpack_require__.d(foo_namespaceObject, { c: () => (c) }); @@ -64,7 +64,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/optional-chaining/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/optional-chaining/__snapshots__/esm.snap.txt index 52e298fdb4fa..3a7154625f3b 100644 --- a/tests/rspack-test/esmOutputCases/namespace/optional-chaining/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/optional-chaining/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./util.js var util_namespaceObject = {}; -__webpack_require__.r(util_namespaceObject); +__webpack_require__.N(util_namespaceObject); __webpack_require__.d(util_namespaceObject, { foo: () => (foo) }); @@ -56,7 +56,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/re-export-named-missing-export-capture/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/re-export-named-missing-export-capture/__snapshots__/esm.snap.txt index a14c5095ff3f..261c5e155064 100644 --- a/tests/rspack-test/esmOutputCases/namespace/re-export-named-missing-export-capture/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/re-export-named-missing-export-capture/__snapshots__/esm.snap.txt @@ -2,12 +2,12 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./bar.js var bar_namespaceObject = {}; -__webpack_require__.r(bar_namespaceObject); +__webpack_require__.N(bar_namespaceObject); // NAMESPACE OBJECT: ./foo.js var foo_namespaceObject = {}; -__webpack_require__.r(foo_namespaceObject); +__webpack_require__.N(foo_namespaceObject); __webpack_require__.d(foo_namespaceObject, { foo: () => (bar_namespaceObject.foo) }); @@ -55,7 +55,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/re-export-named-missing-export-no-capture/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/re-export-named-missing-export-no-capture/__snapshots__/esm.snap.txt index fbae118e52d0..8e64efffebc9 100644 --- a/tests/rspack-test/esmOutputCases/namespace/re-export-named-missing-export-no-capture/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/re-export-named-missing-export-no-capture/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./bar.js var bar_namespaceObject = {}; -__webpack_require__.r(bar_namespaceObject); +__webpack_require__.N(bar_namespaceObject); // ./bar.js @@ -26,7 +26,7 @@ var __webpack_require__ = {}; // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/re-export-namespace-missing-export-capture/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/re-export-namespace-missing-export-capture/__snapshots__/esm.snap.txt index 3dcd4233d448..5c79e64868ee 100644 --- a/tests/rspack-test/esmOutputCases/namespace/re-export-namespace-missing-export-capture/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/re-export-namespace-missing-export-capture/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./bar.js var bar_namespaceObject = {}; -__webpack_require__.r(bar_namespaceObject); +__webpack_require__.N(bar_namespaceObject); __webpack_require__.d(bar_namespaceObject, { x: () => (x) }); @@ -48,7 +48,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/re-export-namespace-missing-export-no-capture/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/re-export-namespace-missing-export-no-capture/__snapshots__/esm.snap.txt index 3bc167049844..a84a152a562f 100644 --- a/tests/rspack-test/esmOutputCases/namespace/re-export-namespace-missing-export-no-capture/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/re-export-namespace-missing-export-no-capture/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./bar.js var bar_namespaceObject = {}; -__webpack_require__.r(bar_namespaceObject); +__webpack_require__.N(bar_namespaceObject); // ./bar.js @@ -27,7 +27,7 @@ var __webpack_require__ = {}; // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/re-export-self-as-namespace/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/re-export-self-as-namespace/__snapshots__/esm.snap.txt index c914e6b8b321..658839d75081 100644 --- a/tests/rspack-test/esmOutputCases/namespace/re-export-self-as-namespace/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/re-export-self-as-namespace/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./foo.js var foo_namespaceObject = {}; -__webpack_require__.r(foo_namespaceObject); +__webpack_require__.N(foo_namespaceObject); __webpack_require__.d(foo_namespaceObject, { foo: () => (foo), ns: () => (foo_namespaceObject) }); @@ -51,7 +51,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/re-export-self-import-export-as-namespace/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/re-export-self-import-export-as-namespace/__snapshots__/esm.snap.txt index bcf619f0bacc..46e684ee3d5a 100644 --- a/tests/rspack-test/esmOutputCases/namespace/re-export-self-import-export-as-namespace/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/re-export-self-import-export-as-namespace/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./foo.js var foo_namespaceObject = {}; -__webpack_require__.r(foo_namespaceObject); +__webpack_require__.N(foo_namespaceObject); __webpack_require__.d(foo_namespaceObject, { foo: () => (foo), ns: () => (foo_namespaceObject) }); @@ -54,7 +54,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/re-export-star-missing-export-capture/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/re-export-star-missing-export-capture/__snapshots__/esm.snap.txt index 611b95e4a212..cf52e77d45d4 100644 --- a/tests/rspack-test/esmOutputCases/namespace/re-export-star-missing-export-capture/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/re-export-star-missing-export-capture/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./foo.js var foo_namespaceObject = {}; -__webpack_require__.r(foo_namespaceObject); +__webpack_require__.N(foo_namespaceObject); __webpack_require__.d(foo_namespaceObject, { x: () => ((/* inlined export .x */123)) }); @@ -48,7 +48,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/re-export-star-missing-export-no-capture/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/re-export-star-missing-export-no-capture/__snapshots__/esm.snap.txt index 92772b4ffad7..acdc26d2ac64 100644 --- a/tests/rspack-test/esmOutputCases/namespace/re-export-star-missing-export-no-capture/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/re-export-star-missing-export-no-capture/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./foo.js var foo_namespaceObject = {}; -__webpack_require__.r(foo_namespaceObject); +__webpack_require__.N(foo_namespaceObject); // ./foo.js @@ -27,7 +27,7 @@ var __webpack_require__ = {}; // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/re-export-star/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/re-export-star/__snapshots__/esm.snap.txt index c1d6bdf71567..a72c1da08b01 100644 --- a/tests/rspack-test/esmOutputCases/namespace/re-export-star/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/re-export-star/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./foo.js var foo_namespaceObject = {}; -__webpack_require__.r(foo_namespaceObject); +__webpack_require__.N(foo_namespaceObject); __webpack_require__.d(foo_namespaceObject, { foo1: () => (foo1), foo2: () => (foo2) }); @@ -58,7 +58,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/reexport-self-cycle/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/reexport-self-cycle/__snapshots__/esm.snap.txt index 89e3b7c3909d..bbbd256d80de 100644 --- a/tests/rspack-test/esmOutputCases/namespace/reexport-self-cycle/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/reexport-self-cycle/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./other.js var other_namespaceObject = {}; -__webpack_require__.r(other_namespaceObject); +__webpack_require__.N(other_namespaceObject); __webpack_require__.d(other_namespaceObject, { bar: () => (bar), foo: () => (foo), @@ -57,7 +57,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/self-import-cycle/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/self-import-cycle/__snapshots__/esm.snap.txt index 9b208ef39c34..c9740be61b81 100644 --- a/tests/rspack-test/esmOutputCases/namespace/self-import-cycle/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/self-import-cycle/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./index.js var index_namespaceObject = {}; -__webpack_require__.r(index_namespaceObject); +__webpack_require__.N(index_namespaceObject); __webpack_require__.d(index_namespaceObject, { keys: () => (keys), p: () => (p) }); @@ -53,7 +53,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/side-effect-free-modules-default-property/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/side-effect-free-modules-default-property/__snapshots__/esm.snap.txt index b2de1821083e..3968d9a36415 100644 --- a/tests/rspack-test/esmOutputCases/namespace/side-effect-free-modules-default-property/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/side-effect-free-modules-default-property/__snapshots__/esm.snap.txt @@ -14,12 +14,12 @@ console.log("cjs"); }); // NAMESPACE OBJECT: ./foo/no-side-effects.js var no_side_effects_namespaceObject = {}; -__webpack_require__.r(no_side_effects_namespaceObject); +__webpack_require__.N(no_side_effects_namespaceObject); // NAMESPACE OBJECT: ./foo/no-side-effects.mjs var foo_no_side_effects_namespaceObject = {}; -__webpack_require__.r(foo_no_side_effects_namespaceObject); +__webpack_require__.N(foo_no_side_effects_namespaceObject); // ./foo/no-side-effects.js @@ -108,7 +108,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/side-effect-free-modules-missing-property/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/side-effect-free-modules-missing-property/__snapshots__/esm.snap.txt index d1e3d49a54cb..916aedf26c2d 100644 --- a/tests/rspack-test/esmOutputCases/namespace/side-effect-free-modules-missing-property/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/side-effect-free-modules-missing-property/__snapshots__/esm.snap.txt @@ -14,12 +14,12 @@ console.log("cjs"); }); // NAMESPACE OBJECT: ./foo/no-side-effects.js var no_side_effects_namespaceObject = {}; -__webpack_require__.r(no_side_effects_namespaceObject); +__webpack_require__.N(no_side_effects_namespaceObject); // NAMESPACE OBJECT: ./foo/no-side-effects.mjs var foo_no_side_effects_namespaceObject = {}; -__webpack_require__.r(foo_no_side_effects_namespaceObject); +__webpack_require__.N(foo_no_side_effects_namespaceObject); // ./foo/no-side-effects.js @@ -77,7 +77,7 @@ __webpack_require__.add = function registerModules(modules) { Object.assign(__we // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/star-export-as-namespace-cjs/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/star-export-as-namespace-cjs/__snapshots__/esm.snap.txt index 6718b21021da..8075fc218195 100644 --- a/tests/rspack-test/esmOutputCases/namespace/star-export-as-namespace-cjs/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/star-export-as-namespace-cjs/__snapshots__/esm.snap.txt @@ -76,7 +76,7 @@ __webpack_require__.t = function(value, mode) { if((mode & 16) && typeof value.then === 'function') return value; } var ns = Object.create(null); - __webpack_require__.r(ns); + __webpack_require__.N(ns); var def = {}; leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)]; for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) { @@ -86,6 +86,7 @@ __webpack_require__.t = function(value, mode) { __webpack_require__.d(ns, def); return ns; }; + })(); // webpack/runtime/define_property_getters (() => { @@ -113,7 +114,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/star-export-as-namespace/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/star-export-as-namespace/__snapshots__/esm.snap.txt index c877fba10bad..ffb0239bfcd7 100644 --- a/tests/rspack-test/esmOutputCases/namespace/star-export-as-namespace/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/star-export-as-namespace/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./foo.js var foo_namespaceObject = {}; -__webpack_require__.r(foo_namespaceObject); +__webpack_require__.N(foo_namespaceObject); __webpack_require__.d(foo_namespaceObject, { foo: () => (foo) }); @@ -50,7 +50,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/tostring-inlined-namespace/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/tostring-inlined-namespace/__snapshots__/esm.snap.txt index 263bf5859dc2..bda98581e964 100644 --- a/tests/rspack-test/esmOutputCases/namespace/tostring-inlined-namespace/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/tostring-inlined-namespace/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./foo.js var foo_namespaceObject = {}; -__webpack_require__.r(foo_namespaceObject); +__webpack_require__.N(foo_namespaceObject); __webpack_require__.d(foo_namespaceObject, { bar: () => (bar) }); @@ -58,7 +58,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/tostring-static-resolution/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/tostring-static-resolution/__snapshots__/esm.snap.txt index 0d11949586ad..71ab1bfcabfc 100644 --- a/tests/rspack-test/esmOutputCases/namespace/tostring-static-resolution/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/tostring-static-resolution/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./foo.js var foo_namespaceObject = {}; -__webpack_require__.r(foo_namespaceObject); +__webpack_require__.N(foo_namespaceObject); __webpack_require__.d(foo_namespaceObject, { bar: () => (bar) }); @@ -50,7 +50,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/preserve-modules/namespace-object-bare-import/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/preserve-modules/namespace-object-bare-import/__snapshots__/esm.snap.txt index 2603bca0071c..245b45d368f1 100644 --- a/tests/rspack-test/esmOutputCases/preserve-modules/namespace-object-bare-import/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/preserve-modules/namespace-object-bare-import/__snapshots__/esm.snap.txt @@ -13,7 +13,7 @@ import { types_namespaceObject } from "./types.mjs"; // NAMESPACE OBJECT: ./src/rules/duplicate-package/index.js var duplicate_package_namespaceObject = {}; -__webpack_require__.r(duplicate_package_namespaceObject); +__webpack_require__.N(duplicate_package_namespaceObject); __webpack_require__.d(duplicate_package_namespaceObject, { value: () => (value) }); @@ -33,7 +33,7 @@ export { duplicate_package_namespaceObject as duplicatePackage, value }; import { __webpack_require__ } from "../../runtime.mjs"; // NAMESPACE OBJECT: ./src/rules/duplicate-package/types.js var types_namespaceObject = {}; -__webpack_require__.r(types_namespaceObject); +__webpack_require__.N(types_namespaceObject); __webpack_require__.d(types_namespaceObject, { J: () => (CheckVersionMap) }); @@ -72,7 +72,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/re-exports/cjs-entry/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/re-exports/cjs-entry/__snapshots__/esm.snap.txt index 7e4870d5f459..b9d002f6258c 100644 --- a/tests/rspack-test/esmOutputCases/re-exports/cjs-entry/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/re-exports/cjs-entry/__snapshots__/esm.snap.txt @@ -16,7 +16,7 @@ exports.bar = 2 !*** ./foo.js ***! \****************/ (__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var _bar__rspack_import_0 = __webpack_require__(/*! ./bar */ "./bar.js"); const foo = 1 @@ -106,7 +106,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/re-exports/deep-re-export-external/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/re-exports/deep-re-export-external/__snapshots__/esm.snap.txt index a4b9c30ecbfc..4d2e69ea8ab3 100644 --- a/tests/rspack-test/esmOutputCases/re-exports/deep-re-export-external/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/re-exports/deep-re-export-external/__snapshots__/esm.snap.txt @@ -4,7 +4,7 @@ import * as __rspack_external_fs from "fs"; // NAMESPACE OBJECT: ./externals.js var externals_namespaceObject = {}; -__webpack_require__.r(externals_namespaceObject); +__webpack_require__.N(externals_namespaceObject); __webpack_require__.d(externals_namespaceObject, { "default": () => (__rspack_external_fs["default"]), readFile: () => (__rspack_external_fs.readFile) }); @@ -71,7 +71,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/re-exports/deep-re-exports-esm-2/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/re-exports/deep-re-exports-esm-2/__snapshots__/esm.snap.txt index 50e9015f824b..6f407742334a 100644 --- a/tests/rspack-test/esmOutputCases/re-exports/deep-re-exports-esm-2/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/re-exports/deep-re-exports-esm-2/__snapshots__/esm.snap.txt @@ -9,7 +9,7 @@ __webpack_require__.add({ !*** ./lib.js ***! \****************/ (__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var fs__rspack_import_0 = __webpack_require__(/*! fs */ "fs"); /* reexport */ var __rspack_reexport = {}; @@ -38,7 +38,7 @@ __webpack_require__.d(__webpack_exports__, { !*** ./lib2.js ***! \*****************/ (__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var path__rspack_import_0 = __webpack_require__(/*! path */ "path"); /* reexport */ var __rspack_reexport = {}; @@ -179,7 +179,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/re-exports/default-namespace-external/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/re-exports/default-namespace-external/__snapshots__/esm.snap.txt index 0344b866e7c9..655ca21b45db 100644 --- a/tests/rspack-test/esmOutputCases/re-exports/default-namespace-external/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/re-exports/default-namespace-external/__snapshots__/esm.snap.txt @@ -4,7 +4,7 @@ import fs, * as __rspack_external_fs from "fs"; // NAMESPACE OBJECT: ./file.js var file_namespaceObject = {}; -__webpack_require__.r(file_namespaceObject); +__webpack_require__.N(file_namespaceObject); __webpack_require__.d(file_namespaceObject, { fsNs: () => (__rspack_external_fs), value: () => (value) }); @@ -55,7 +55,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/re-exports/default-re-export-external/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/re-exports/default-re-export-external/__snapshots__/esm.snap.txt index df6c42329ead..1542606d3273 100644 --- a/tests/rspack-test/esmOutputCases/re-exports/default-re-export-external/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/re-exports/default-re-export-external/__snapshots__/esm.snap.txt @@ -4,7 +4,7 @@ import fs from "fs"; // NAMESPACE OBJECT: ./file.js var file_namespaceObject = {}; -__webpack_require__.r(file_namespaceObject); +__webpack_require__.N(file_namespaceObject); __webpack_require__.d(file_namespaceObject, { fsDefault: () => (fs), value: () => (value) }); @@ -55,7 +55,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/re-exports/string-export-star-as-namespace/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/re-exports/string-export-star-as-namespace/__snapshots__/esm.snap.txt index 8b3906caf2ce..e599bac4d89a 100644 --- a/tests/rspack-test/esmOutputCases/re-exports/string-export-star-as-namespace/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/re-exports/string-export-star-as-namespace/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./foo.js var foo_namespaceObject = {}; -__webpack_require__.r(foo_namespaceObject); +__webpack_require__.N(foo_namespaceObject); __webpack_require__.d(foo_namespaceObject, { named: () => (named), "some import": () => (someImport) }); @@ -55,7 +55,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/re-exports/wrapped-esm-entry/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/re-exports/wrapped-esm-entry/__snapshots__/esm.snap.txt index bd259b995d67..b81d5991c327 100644 --- a/tests/rspack-test/esmOutputCases/re-exports/wrapped-esm-entry/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/re-exports/wrapped-esm-entry/__snapshots__/esm.snap.txt @@ -8,7 +8,7 @@ __webpack_require__.add({ !*** ./index.js ***! \******************/ (module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var fs__rspack_import_0 = __webpack_require__(/*! fs */ "fs"); /* reexport */ var __rspack_reexport = {}; @@ -137,7 +137,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.r = (exports) => { +__webpack_require__.N = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/hotCases/asset/parser-and-generator-states/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/asset/parser-and-generator-states/__snapshots__/web/1.snap.txt index b59a819df8b9..5337becbd0c9 100644 --- a/tests/rspack-test/hotCases/asset/parser-and-generator-states/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/asset/parser-and-generator-states/__snapshots__/web/1.snap.txt @@ -35,7 +35,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/child-compiler/issue-9706/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/child-compiler/issue-9706/__snapshots__/web/1.snap.txt index 47f2a34e4315..b195e415026a 100644 --- a/tests/rspack-test/hotCases/child-compiler/issue-9706/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/child-compiler/issue-9706/__snapshots__/web/1.snap.txt @@ -34,7 +34,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./report-child-assets-loader.js!./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { assets: () => (assets), "default": () => (__rspack_default_export) diff --git a/tests/rspack-test/hotCases/chunk/accept-system-import-webpackhot/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/chunk/accept-system-import-webpackhot/__snapshots__/web/1.snap.txt index af809b99a5d7..47627d3c4076 100644 --- a/tests/rspack-test/hotCases/chunk/accept-system-import-webpackhot/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/chunk/accept-system-import-webpackhot/__snapshots__/web/1.snap.txt @@ -37,7 +37,7 @@ "use strict"; self["rspackHotUpdate"]("chunk2_js", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); @@ -64,7 +64,7 @@ var value = 2; "use strict"; self["rspackHotUpdate"]("chunk_js", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); diff --git a/tests/rspack-test/hotCases/chunk/accept-system-import/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/chunk/accept-system-import/__snapshots__/web/1.snap.txt index fee6553025ba..5c58841c2c97 100644 --- a/tests/rspack-test/hotCases/chunk/accept-system-import/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/chunk/accept-system-import/__snapshots__/web/1.snap.txt @@ -37,7 +37,7 @@ "use strict"; self["rspackHotUpdate"]("chunk2_js", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); @@ -64,7 +64,7 @@ var value = 2; "use strict"; self["rspackHotUpdate"]("chunk_js", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); diff --git a/tests/rspack-test/hotCases/chunk/ensure-chunk-change-to-promise-all/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/chunk/ensure-chunk-change-to-promise-all/__snapshots__/web/1.snap.txt index a3b5282936f6..e2a837b19ba1 100644 --- a/tests/rspack-test/hotCases/chunk/ensure-chunk-change-to-promise-all/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/chunk/ensure-chunk-change-to-promise-all/__snapshots__/web/1.snap.txt @@ -36,7 +36,7 @@ "use strict"; self["rspackHotUpdate"]("file_js", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { Vue: () => (/* reexport safe */ vue__rspack_import_0.Vue) }); @@ -64,7 +64,7 @@ __webpack_require__.d(__webpack_exports__, { "use strict"; self["rspackHotUpdate"]("main", { "./chunk.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { test: () => (test) }); diff --git a/tests/rspack-test/hotCases/chunks/dynamic-system-import/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/chunks/dynamic-system-import/__snapshots__/web/1.snap.txt index 8356237ff00f..cad487eb38f6 100644 --- a/tests/rspack-test/hotCases/chunks/dynamic-system-import/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/chunks/dynamic-system-import/__snapshots__/web/1.snap.txt @@ -37,7 +37,7 @@ "use strict"; self["rspackHotUpdate"]("chunk1_js", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); @@ -64,7 +64,7 @@ var value = 2; "use strict"; self["rspackHotUpdate"]("chunk2_js", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); diff --git a/tests/rspack-test/hotCases/chunks/system-import/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/chunks/system-import/__snapshots__/web/1.snap.txt index 51dda2e77611..4c3bf4d03a3f 100644 --- a/tests/rspack-test/hotCases/chunks/system-import/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/chunks/system-import/__snapshots__/web/1.snap.txt @@ -39,7 +39,7 @@ "use strict"; self["rspackHotUpdate"]("chunk2_js", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); @@ -48,7 +48,7 @@ var value = 2; }, "./file2.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); @@ -76,7 +76,7 @@ var value = 4; "use strict"; self["rspackHotUpdate"]("chunk_js", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); @@ -85,7 +85,7 @@ var value = 2; }, "./file2.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); diff --git a/tests/rspack-test/hotCases/chunks/update-chunk-loading-runtime/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/chunks/update-chunk-loading-runtime/__snapshots__/web/1.snap.txt index f626fe70eaec..4270c277e939 100644 --- a/tests/rspack-test/hotCases/chunks/update-chunk-loading-runtime/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/chunks/update-chunk-loading-runtime/__snapshots__/web/1.snap.txt @@ -39,7 +39,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./index.js"(module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var vendor__rspack_import_0 = __webpack_require__("./node_modules/vendor.js"); module.hot.data.ok = true; @@ -736,7 +736,7 @@ chunkLoadingGlobal.push = __rspack_jsonp.bind(null, chunkLoadingGlobal.push.bind "use strict"; self["rspackHotUpdate"]("vendors-node_modules_vendor_js", { "./node_modules/vendor.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/code-generation/this-in-accept-webpackhot/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/code-generation/this-in-accept-webpackhot/__snapshots__/web/1.snap.txt index edb294a08a16..8c60e6ddb136 100644 --- a/tests/rspack-test/hotCases/code-generation/this-in-accept-webpackhot/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/code-generation/this-in-accept-webpackhot/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/code-generation/this-in-accept/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/code-generation/this-in-accept/__snapshots__/web/1.snap.txt index 7336ca158f23..d17527953612 100644 --- a/tests/rspack-test/hotCases/code-generation/this-in-accept/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/code-generation/this-in-accept/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/concat/reload-compat-flag/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/concat/reload-compat-flag/__snapshots__/web/1.snap.txt index e78810515ca0..0b30072f0233 100644 --- a/tests/rspack-test/hotCases/concat/reload-compat-flag/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/concat/reload-compat-flag/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"](889, { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* export default */ const __rspack_default_export = ("ok2"); diff --git a/tests/rspack-test/hotCases/concat/reload-external/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/concat/reload-external/__snapshots__/web/1.snap.txt index e0548f6b9b00..f1e3d5597c38 100644 --- a/tests/rspack-test/hotCases/concat/reload-external/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/concat/reload-external/__snapshots__/web/1.snap.txt @@ -34,7 +34,7 @@ "use strict"; self["rspackHotUpdate"](889, { "./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* export default */ const __rspack_default_export = (2); __webpack_require__.d(__webpack_exports__, { diff --git a/tests/rspack-test/hotCases/concat/reload-external/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/concat/reload-external/__snapshots__/web/2.snap.txt index c64b775e994b..3fd0eb94a9e6 100644 --- a/tests/rspack-test/hotCases/concat/reload-external/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/concat/reload-external/__snapshots__/web/2.snap.txt @@ -34,7 +34,7 @@ "use strict"; self["rspackHotUpdate"](889, { "./b.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* export default */ const __rspack_default_export = (20); __webpack_require__.d(__webpack_exports__, { diff --git a/tests/rspack-test/hotCases/conditional-runtime/accept-conditional/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/conditional-runtime/accept-conditional/__snapshots__/web/1.snap.txt index 01b130b37c3b..9f063a8cca3e 100644 --- a/tests/rspack-test/hotCases/conditional-runtime/accept-conditional/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/conditional-runtime/accept-conditional/__snapshots__/web/1.snap.txt @@ -47,7 +47,7 @@ "use strict"; self["rspackHotUpdate"]("dep1_js-dep2_js-worker_js", { "./dep1.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -81,7 +81,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("dep1_js-module_js", { "./dep1.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/context/request-position/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/context/request-position/__snapshots__/web/1.snap.txt index 83e07d2ce9f4..f164bb6c40af 100644 --- a/tests/rspack-test/hotCases/context/request-position/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/context/request-position/__snapshots__/web/1.snap.txt @@ -35,7 +35,7 @@ self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { fn: () => (fn) }); diff --git a/tests/rspack-test/hotCases/css/css-extract/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/css/css-extract/__snapshots__/web/1.snap.txt index 8600f20e99ad..6adaf747259a 100644 --- a/tests/rspack-test/hotCases/css/css-extract/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/css/css-extract/__snapshots__/web/1.snap.txt @@ -34,7 +34,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./entry.js"(module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -47,7 +47,7 @@ module.hot.accept(); }, "./index.module.css"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/css/css-loading-unique-name/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/css/css-loading-unique-name/__snapshots__/web/1.snap.txt index 18739651fdee..b898777557bf 100644 --- a/tests/rspack-test/hotCases/css/css-loading-unique-name/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/css/css-loading-unique-name/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdatecss_test"]("main", { "./index.css"(module, __unused_rspack_exports, __webpack_require__) { -__webpack_require__.r(module.exports = {}); +__webpack_require__.N(module.exports = {}); module.hot.accept(); diff --git a/tests/rspack-test/hotCases/css/css-modules-style/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/css/css-modules-style/__snapshots__/web/1.snap.txt index 17c9114605de..bf25e6dfb768 100644 --- a/tests/rspack-test/hotCases/css/css-modules-style/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/css/css-modules-style/__snapshots__/web/1.snap.txt @@ -44,7 +44,7 @@ if (module.hot.data && module.hot.data.exports && module.hot.data.exports != str module.hot.accept(); } module.hot.dispose(function(data) { data.exports = stringified_exports; }); -__webpack_require__.r(module.exports = exports); +__webpack_require__.N(module.exports = exports); }, diff --git a/tests/rspack-test/hotCases/css/css-modules/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/css/css-modules/__snapshots__/web/1.snap.txt index b75e17851d74..26e37dda2465 100644 --- a/tests/rspack-test/hotCases/css/css-modules/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/css/css-modules/__snapshots__/web/1.snap.txt @@ -47,7 +47,7 @@ if (module.hot.data && module.hot.data.exports && module.hot.data.exports != str module.hot.accept(); } module.hot.dispose(function(data) { data.exports = stringified_exports; }); -__webpack_require__.r(module.exports = exports); +__webpack_require__.N(module.exports = exports); }, @@ -88,7 +88,7 @@ if (module.hot.data && module.hot.data.exports && module.hot.data.exports != str module.hot.accept(); } module.hot.dispose(function(data) { data.exports = stringified_exports; }); -__webpack_require__.r(module.exports = exports); +__webpack_require__.N(module.exports = exports); }, diff --git a/tests/rspack-test/hotCases/css/fetch-priority/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/css/fetch-priority/__snapshots__/web/1.snap.txt index f90e067d1571..2153198e7f24 100644 --- a/tests/rspack-test/hotCases/css/fetch-priority/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/css/fetch-priority/__snapshots__/web/1.snap.txt @@ -69,7 +69,7 @@ if (module.hot.data && module.hot.data.exports && module.hot.data.exports != str module.hot.accept(); } module.hot.dispose(function(data) { data.exports = stringified_exports; }); -__webpack_require__.r(module.exports = exports); +__webpack_require__.N(module.exports = exports); }, diff --git a/tests/rspack-test/hotCases/css/parser-and-generator-states/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/css/parser-and-generator-states/__snapshots__/web/1.snap.txt index c2450f3472c3..6fdec685638e 100644 --- a/tests/rspack-test/hotCases/css/parser-and-generator-states/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/css/parser-and-generator-states/__snapshots__/web/1.snap.txt @@ -45,7 +45,7 @@ if (module.hot.data && module.hot.data.exports && module.hot.data.exports != str module.hot.accept(); } module.hot.dispose(function(data) { data.exports = stringified_exports; }); -__webpack_require__.r(module.exports = exports); +__webpack_require__.N(module.exports = exports); }, diff --git a/tests/rspack-test/hotCases/css/recovery-cacheable/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/css/recovery-cacheable/__snapshots__/web/2.snap.txt index 56801c282e5e..61322204c2ce 100644 --- a/tests/rspack-test/hotCases/css/recovery-cacheable/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/css/recovery-cacheable/__snapshots__/web/2.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./change.css"(module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); // extracted by css-extract-rspack-plugin if(true) { diff --git a/tests/rspack-test/hotCases/css/recovery/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/css/recovery/__snapshots__/web/2.snap.txt index c95656f6c6eb..4338ccdb63fb 100644 --- a/tests/rspack-test/hotCases/css/recovery/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/css/recovery/__snapshots__/web/2.snap.txt @@ -35,7 +35,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./index.css"(module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); // extracted by css-extract-rspack-plugin if(true) { @@ -62,7 +62,7 @@ __webpack_require__.r(__webpack_exports__); }, "../../../../../../../../packages/rspack/dist/cssExtractHmr.js"(__unused_rspack___webpack_module__, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { cssReload: () => (cssReload), normalizeUrl: () => (normalizeUrl) diff --git a/tests/rspack-test/hotCases/css/vanilla/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/css/vanilla/__snapshots__/web/1.snap.txt index 8ee7497fb818..132a3027056b 100644 --- a/tests/rspack-test/hotCases/css/vanilla/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/css/vanilla/__snapshots__/web/1.snap.txt @@ -59,7 +59,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("style2_css", { "./style2.css"(module, __unused_rspack_exports, __webpack_require__) { -__webpack_require__.r(module.exports = {}); +__webpack_require__.N(module.exports = {}); module.hot.accept(); diff --git a/tests/rspack-test/hotCases/define/issue-6962/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/define/issue-6962/__snapshots__/web/1.snap.txt index 796cbaff1561..cf05eb65101a 100644 --- a/tests/rspack-test/hotCases/define/issue-6962/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/define/issue-6962/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./a.js"(module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/determinism/issue-10174/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/determinism/issue-10174/__snapshots__/web/1.snap.txt index f6116503b25a..e1dd4bdee2b0 100644 --- a/tests/rspack-test/hotCases/determinism/issue-10174/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/determinism/issue-10174/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./hot.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/disposing/remove-chunk-with-shared-in-other-runtime/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/disposing/remove-chunk-with-shared-in-other-runtime/__snapshots__/web/1.snap.txt index 319df2ac163e..4665b78df46e 100644 --- a/tests/rspack-test/hotCases/disposing/remove-chunk-with-shared-in-other-runtime/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/disposing/remove-chunk-with-shared-in-other-runtime/__snapshots__/web/1.snap.txt @@ -44,7 +44,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/disposing/remove-chunk-with-shared/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/disposing/remove-chunk-with-shared/__snapshots__/web/1.snap.txt index c36de5f50f49..ec6883477444 100644 --- a/tests/rspack-test/hotCases/disposing/remove-chunk-with-shared/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/disposing/remove-chunk-with-shared/__snapshots__/web/1.snap.txt @@ -34,7 +34,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/disposing/runtime-independent-filename/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/disposing/runtime-independent-filename/__snapshots__/web/1.snap.txt index 9f87a93e5aae..fbfd171b4022 100644 --- a/tests/rspack-test/hotCases/disposing/runtime-independent-filename/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/disposing/runtime-independent-filename/__snapshots__/web/1.snap.txt @@ -28,7 +28,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/errors/decline-webpackhot/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/errors/decline-webpackhot/__snapshots__/web/1.snap.txt index f6fc526d35b8..b13dc0ecf29a 100644 --- a/tests/rspack-test/hotCases/errors/decline-webpackhot/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/errors/decline-webpackhot/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./c.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/errors/decline/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/errors/decline/__snapshots__/web/1.snap.txt index 68d04e7abc15..eb7c0803062b 100644 --- a/tests/rspack-test/hotCases/errors/decline/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/errors/decline/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./c.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/errors/events/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/errors/events/__snapshots__/web/1.snap.txt index affe56e0e5b8..dda13ea51dad 100644 --- a/tests/rspack-test/hotCases/errors/events/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/errors/events/__snapshots__/web/1.snap.txt @@ -45,7 +45,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -54,7 +54,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./c.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -63,7 +63,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./e.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -72,7 +72,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./g.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -81,7 +81,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./i.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -91,7 +91,7 @@ throw new Error("Error while loading module i"); }, "./j.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -101,7 +101,7 @@ throw new Error("Error while loading module j"); }, "./l.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/errors/self-decline/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/errors/self-decline/__snapshots__/web/1.snap.txt index f8cac2b8edf7..d33191404372 100644 --- a/tests/rspack-test/hotCases/errors/self-decline/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/errors/self-decline/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./c.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/errors/unaccepted-ignored/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/errors/unaccepted-ignored/__snapshots__/web/1.snap.txt index c2358d9f3df2..17e51db573c9 100644 --- a/tests/rspack-test/hotCases/errors/unaccepted-ignored/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/errors/unaccepted-ignored/__snapshots__/web/1.snap.txt @@ -34,7 +34,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/errors/unaccepted-ignored/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/errors/unaccepted-ignored/__snapshots__/web/2.snap.txt index c04441d9d9aa..a94ba109e7a1 100644 --- a/tests/rspack-test/hotCases/errors/unaccepted-ignored/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/errors/unaccepted-ignored/__snapshots__/web/2.snap.txt @@ -34,7 +34,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./c.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/errors/unaccepted-ignored/__snapshots__/web/3.snap.txt b/tests/rspack-test/hotCases/errors/unaccepted-ignored/__snapshots__/web/3.snap.txt index b7807c676785..e6699ea3a823 100644 --- a/tests/rspack-test/hotCases/errors/unaccepted-ignored/__snapshots__/web/3.snap.txt +++ b/tests/rspack-test/hotCases/errors/unaccepted-ignored/__snapshots__/web/3.snap.txt @@ -35,7 +35,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -44,7 +44,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./c.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/errors/unaccepted/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/errors/unaccepted/__snapshots__/web/1.snap.txt index afabf4d162c8..1f9a3ec1225c 100644 --- a/tests/rspack-test/hotCases/errors/unaccepted/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/errors/unaccepted/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./c.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/esm-dependency-import/import-meta-webpack-hot/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/esm-dependency-import/import-meta-webpack-hot/__snapshots__/web/1.snap.txt index 0fd8877f42ee..1ce154684349 100644 --- a/tests/rspack-test/hotCases/esm-dependency-import/import-meta-webpack-hot/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/esm-dependency-import/import-meta-webpack-hot/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./node_modules/dep1/file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); diff --git a/tests/rspack-test/hotCases/esm-dependency-import/module-hot/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/esm-dependency-import/module-hot/__snapshots__/web/1.snap.txt index 37d4a1d5853a..802da8febee4 100644 --- a/tests/rspack-test/hotCases/esm-dependency-import/module-hot/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/esm-dependency-import/module-hot/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./node_modules/dep1/file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); diff --git a/tests/rspack-test/hotCases/harmony/auto-import-multiple/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/harmony/auto-import-multiple/__snapshots__/web/1.snap.txt index 1d99468fc835..dd2f26757de2 100644 --- a/tests/rspack-test/hotCases/harmony/auto-import-multiple/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/harmony/auto-import-multiple/__snapshots__/web/1.snap.txt @@ -40,7 +40,7 @@ module.exports = 20; }, "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); diff --git a/tests/rspack-test/hotCases/harmony/auto-import/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/harmony/auto-import/__snapshots__/web/1.snap.txt index d2c2f741f468..738331ef8fe0 100644 --- a/tests/rspack-test/hotCases/harmony/auto-import/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/harmony/auto-import/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); diff --git a/tests/rspack-test/hotCases/harmony/auto-reexport/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/harmony/auto-reexport/__snapshots__/web/1.snap.txt index e50d89aff7c8..7931312d0837 100644 --- a/tests/rspack-test/hotCases/harmony/auto-reexport/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/harmony/auto-reexport/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); diff --git a/tests/rspack-test/hotCases/harmony/cjs-analyze-changed/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/harmony/cjs-analyze-changed/__snapshots__/web/1.snap.txt index 9cf01db39f74..716557390e59 100644 --- a/tests/rspack-test/hotCases/harmony/cjs-analyze-changed/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/harmony/cjs-analyze-changed/__snapshots__/web/1.snap.txt @@ -40,7 +40,7 @@ exports["default"] = 1; }, "./reexport.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/hash/hot-index/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/hash/hot-index/__snapshots__/web/1.snap.txt index da678a8a5209..2af9dbb31a19 100644 --- a/tests/rspack-test/hotCases/hash/hot-index/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/hash/hot-index/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/hash/hot-index/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/hash/hot-index/__snapshots__/web/2.snap.txt index 255bcf92aa0e..8a0e78a0bac4 100644 --- a/tests/rspack-test/hotCases/hash/hot-index/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/hash/hot-index/__snapshots__/web/2.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/hash/hot-index/__snapshots__/web/3.snap.txt b/tests/rspack-test/hotCases/hash/hot-index/__snapshots__/web/3.snap.txt index 3eb28c0ef6df..d31b35849959 100644 --- a/tests/rspack-test/hotCases/hash/hot-index/__snapshots__/web/3.snap.txt +++ b/tests/rspack-test/hotCases/hash/hot-index/__snapshots__/web/3.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/hashing/exports-info-influence/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/hashing/exports-info-influence/__snapshots__/web/1.snap.txt index 00fbfdd17c5e..c0bfd3cc65dd 100644 --- a/tests/rspack-test/hotCases/hashing/exports-info-influence/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/hashing/exports-info-influence/__snapshots__/web/1.snap.txt @@ -34,7 +34,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./referencer.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/hashing/full-hash-main/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/hashing/full-hash-main/__snapshots__/web/1.snap.txt index ed5147db3f1f..5ee360171992 100644 --- a/tests/rspack-test/hotCases/hashing/full-hash-main/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/hashing/full-hash-main/__snapshots__/web/1.snap.txt @@ -58,7 +58,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("thing_js", { "./thing.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/lazy-compilation/context/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/lazy-compilation/context/__snapshots__/web/1.snap.txt index 0af46084e063..65a8b356d2c1 100644 --- a/tests/rspack-test/hotCases/lazy-compilation/context/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/lazy-compilation/context/__snapshots__/web/1.snap.txt @@ -37,7 +37,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./generation.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/lazy-compilation/context/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/lazy-compilation/context/__snapshots__/web/2.snap.txt index 805615647779..1f42b87993f0 100644 --- a/tests/rspack-test/hotCases/lazy-compilation/context/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/lazy-compilation/context/__snapshots__/web/2.snap.txt @@ -38,7 +38,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./generation.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/lazy-compilation/unrelated/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/lazy-compilation/unrelated/__snapshots__/web/1.snap.txt index 717bd9c25aca..c56fca3c3e5a 100644 --- a/tests/rspack-test/hotCases/lazy-compilation/unrelated/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/lazy-compilation/unrelated/__snapshots__/web/1.snap.txt @@ -34,7 +34,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/lazy-compilation/unrelated/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/lazy-compilation/unrelated/__snapshots__/web/2.snap.txt index 68260c439247..6640a5f9f140 100644 --- a/tests/rspack-test/hotCases/lazy-compilation/unrelated/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/lazy-compilation/unrelated/__snapshots__/web/2.snap.txt @@ -34,7 +34,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/loader/import-module-1/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/loader/import-module-1/__snapshots__/web/1.snap.txt index 06daa81a1e46..01864eb49793 100644 --- a/tests/rspack-test/hotCases/loader/import-module-1/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/loader/import-module-1/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./loader.js!./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/make/clean-isolated-cycle/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/make/clean-isolated-cycle/__snapshots__/web/1.snap.txt index fdfafb3e71e9..3f0b26b9d014 100644 --- a/tests/rspack-test/hotCases/make/clean-isolated-cycle/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/make/clean-isolated-cycle/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/make/clean-isolated-cycle/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/make/clean-isolated-cycle/__snapshots__/web/2.snap.txt index 9e5bf2ed1350..2756f8407bdb 100644 --- a/tests/rspack-test/hotCases/make/clean-isolated-cycle/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/make/clean-isolated-cycle/__snapshots__/web/2.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/make/clean-isolated-cycle/__snapshots__/web/3.snap.txt b/tests/rspack-test/hotCases/make/clean-isolated-cycle/__snapshots__/web/3.snap.txt index 701b0423212d..2e3b5187fd3e 100644 --- a/tests/rspack-test/hotCases/make/clean-isolated-cycle/__snapshots__/web/3.snap.txt +++ b/tests/rspack-test/hotCases/make/clean-isolated-cycle/__snapshots__/web/3.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/make/clean-isolated-module/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/make/clean-isolated-module/__snapshots__/web/1.snap.txt index 2c682b168106..3d7c719f3841 100644 --- a/tests/rspack-test/hotCases/make/clean-isolated-module/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/make/clean-isolated-module/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/make/fix-issuer/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/make/fix-issuer/__snapshots__/web/1.snap.txt index 02fbaa7176a4..e13b694ac38e 100644 --- a/tests/rspack-test/hotCases/make/fix-issuer/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/make/fix-issuer/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/make/issue-10915/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/make/issue-10915/__snapshots__/web/1.snap.txt index 2af1a5a047fc..94061621783f 100644 --- a/tests/rspack-test/hotCases/make/issue-10915/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/make/issue-10915/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/make/rebuild-abnormal-module/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/make/rebuild-abnormal-module/__snapshots__/web/2.snap.txt index b040b2910952..098f213ce718 100644 --- a/tests/rspack-test/hotCases/make/rebuild-abnormal-module/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/make/rebuild-abnormal-module/__snapshots__/web/2.snap.txt @@ -34,7 +34,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -43,7 +43,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./loader.js!./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/module-graph/import-order-change/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/module-graph/import-order-change/__snapshots__/web/1.snap.txt index 98d68fee5d90..9cfd26e3ae29 100644 --- a/tests/rspack-test/hotCases/module-graph/import-order-change/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/module-graph/import-order-change/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./change.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var _b_css__rspack_import_0 = __webpack_require__("./b.css"); /* import */ var _a_css__rspack_import_1 = __webpack_require__("./a.css"); diff --git a/tests/rspack-test/hotCases/module/build-info/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/module/build-info/__snapshots__/web/1.snap.txt index fbb675cb472f..b8f093006b62 100644 --- a/tests/rspack-test/hotCases/module/build-info/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/module/build-info/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./loader.js!./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/newTreeshaking/auto-reexport/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/newTreeshaking/auto-reexport/__snapshots__/web/1.snap.txt index e50d89aff7c8..7931312d0837 100644 --- a/tests/rspack-test/hotCases/newTreeshaking/auto-reexport/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/newTreeshaking/auto-reexport/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); diff --git a/tests/rspack-test/hotCases/newTreeshaking/re-export-optimization/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/newTreeshaking/re-export-optimization/__snapshots__/web/1.snap.txt index d0583639eb4b..0ded6799f26c 100644 --- a/tests/rspack-test/hotCases/newTreeshaking/re-export-optimization/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/newTreeshaking/re-export-optimization/__snapshots__/web/1.snap.txt @@ -34,7 +34,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./bar.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -43,7 +43,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./entry.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/numeric-ids/add-remove-chunks/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/numeric-ids/add-remove-chunks/__snapshots__/web/1.snap.txt index 6de9a274ca39..b6f4f8419106 100644 --- a/tests/rspack-test/hotCases/numeric-ids/add-remove-chunks/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/numeric-ids/add-remove-chunks/__snapshots__/web/1.snap.txt @@ -36,7 +36,7 @@ "use strict"; self["rspackHotUpdate"]("1e1", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); @@ -63,7 +63,7 @@ var value = 1.5; "use strict"; self["rspackHotUpdate"]("main", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/numeric-ids/add-remove-chunks/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/numeric-ids/add-remove-chunks/__snapshots__/web/2.snap.txt index 5a16f7be5116..5773d3ad35a2 100644 --- a/tests/rspack-test/hotCases/numeric-ids/add-remove-chunks/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/numeric-ids/add-remove-chunks/__snapshots__/web/2.snap.txt @@ -36,7 +36,7 @@ "use strict"; self["rspackHotUpdate"](10, { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); @@ -63,7 +63,7 @@ var value = 3; "use strict"; self["rspackHotUpdate"]("main", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/numeric-ids/production/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/numeric-ids/production/__snapshots__/web/1.snap.txt index 395617a640ac..6b650da16286 100644 --- a/tests/rspack-test/hotCases/numeric-ids/production/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/numeric-ids/production/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"](889, { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); var value = 2; __webpack_require__.d(__webpack_exports__, { diff --git a/tests/rspack-test/hotCases/parsing/hot-api-optional-chaining/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/parsing/hot-api-optional-chaining/__snapshots__/web/1.snap.txt index 7f8bcb5c4ef4..bf2a36440b9c 100644 --- a/tests/rspack-test/hotCases/parsing/hot-api-optional-chaining/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/parsing/hot-api-optional-chaining/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/plugins/html/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/plugins/html/__snapshots__/web/1.snap.txt index ed2b5fc786a7..1a39ce5202c2 100644 --- a/tests/rspack-test/hotCases/plugins/html/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/plugins/html/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); diff --git a/tests/rspack-test/hotCases/recover/recover-after-error/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/recover/recover-after-error/__snapshots__/web/1.snap.txt index 6266064d16c9..53a5cf804f5b 100644 --- a/tests/rspack-test/hotCases/recover/recover-after-error/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/recover/recover-after-error/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/recover/recover-after-error/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/recover/recover-after-error/__snapshots__/web/2.snap.txt index 577f7abf84b8..5c30eb56afb0 100644 --- a/tests/rspack-test/hotCases/recover/recover-after-error/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/recover/recover-after-error/__snapshots__/web/2.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/recover/recover-after-loader-error/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/recover/recover-after-loader-error/__snapshots__/web/2.snap.txt index ec672bf74e4c..8265302c458d 100644 --- a/tests/rspack-test/hotCases/recover/recover-after-loader-error/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/recover/recover-after-loader-error/__snapshots__/web/2.snap.txt @@ -34,7 +34,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./loader.js!./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/recover/recover-after-parsing-error/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/recover/recover-after-parsing-error/__snapshots__/web/2.snap.txt index 995c11f26878..82fe57635fd4 100644 --- a/tests/rspack-test/hotCases/recover/recover-after-parsing-error/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/recover/recover-after-parsing-error/__snapshots__/web/2.snap.txt @@ -34,7 +34,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/recover/recover-after-removal-self-accepted/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/recover/recover-after-removal-self-accepted/__snapshots__/web/1.snap.txt index 47c1adbade8d..25aab6cc90f7 100644 --- a/tests/rspack-test/hotCases/recover/recover-after-removal-self-accepted/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/recover/recover-after-removal-self-accepted/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/recover/recover-after-removal-self-accepted/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/recover/recover-after-removal-self-accepted/__snapshots__/web/2.snap.txt index e25a6da7d4a1..e7181d0218b0 100644 --- a/tests/rspack-test/hotCases/recover/recover-after-removal-self-accepted/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/recover/recover-after-removal-self-accepted/__snapshots__/web/2.snap.txt @@ -34,7 +34,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./inner.js"(module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -45,7 +45,7 @@ module.hot.accept(); }, "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/recover/recover-after-self-error/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/recover/recover-after-self-error/__snapshots__/web/1.snap.txt index 523640d2fced..c1806c3c5db3 100644 --- a/tests/rspack-test/hotCases/recover/recover-after-self-error/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/recover/recover-after-self-error/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./a.js"(module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export), getError: () => (getError), diff --git a/tests/rspack-test/hotCases/recover/recover-after-self-error/__snapshots__/web/3.snap.txt b/tests/rspack-test/hotCases/recover/recover-after-self-error/__snapshots__/web/3.snap.txt index 330e25732d69..5e8c2d3e4d40 100644 --- a/tests/rspack-test/hotCases/recover/recover-after-self-error/__snapshots__/web/3.snap.txt +++ b/tests/rspack-test/hotCases/recover/recover-after-self-error/__snapshots__/web/3.snap.txt @@ -34,7 +34,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./a.js"(module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export), getError: () => (getError), diff --git a/tests/rspack-test/hotCases/runtime/circular/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/runtime/circular/__snapshots__/web/1.snap.txt index 5a511075c051..164c8cb1aa93 100644 --- a/tests/rspack-test/hotCases/runtime/circular/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/runtime/circular/__snapshots__/web/1.snap.txt @@ -35,7 +35,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -48,7 +48,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./b.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/1.snap.txt index 80486fbf0cc5..4ec21a260fd5 100644 --- a/tests/rspack-test/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/1.snap.txt @@ -36,7 +36,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/2.snap.txt index 16fa86687abb..679b506501b7 100644 --- a/tests/rspack-test/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/2.snap.txt @@ -37,7 +37,7 @@ "use strict"; self["rspackHotUpdate"]("b_js", { "./b.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/3.snap.txt b/tests/rspack-test/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/3.snap.txt index 4c9ac77bd171..604d03a0fda0 100644 --- a/tests/rspack-test/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/3.snap.txt +++ b/tests/rspack-test/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/3.snap.txt @@ -36,7 +36,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/runtime/dispose-removed-module/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/runtime/dispose-removed-module/__snapshots__/web/1.snap.txt index cd772d6c21c0..56f9896775ae 100644 --- a/tests/rspack-test/hotCases/runtime/dispose-removed-module/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/runtime/dispose-removed-module/__snapshots__/web/1.snap.txt @@ -35,7 +35,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./b.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -43,7 +43,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var _b__rspack_import_0 = __webpack_require__("./b.js"); diff --git a/tests/rspack-test/hotCases/runtime/dispose-removed-module/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/runtime/dispose-removed-module/__snapshots__/web/2.snap.txt index f6ad3a49c156..324b5142cd1c 100644 --- a/tests/rspack-test/hotCases/runtime/dispose-removed-module/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/runtime/dispose-removed-module/__snapshots__/web/2.snap.txt @@ -35,7 +35,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./a.js"(module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -43,7 +43,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (/* reexport safe */ _a__rspack_import_0["default"]) }); diff --git a/tests/rspack-test/hotCases/runtime/hmr-circular/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/runtime/hmr-circular/__snapshots__/web/1.snap.txt index b52e1802e13a..6b969dee4b0a 100644 --- a/tests/rspack-test/hotCases/runtime/hmr-circular/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/runtime/hmr-circular/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./entry.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/runtime/import-after-download/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/runtime/import-after-download/__snapshots__/web/1.snap.txt index 4428ac33c334..df1597c3ffe0 100644 --- a/tests/rspack-test/hotCases/runtime/import-after-download/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/runtime/import-after-download/__snapshots__/web/1.snap.txt @@ -37,7 +37,7 @@ "use strict"; self["rspackHotUpdate"]("chunk_js", { "./inner.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -64,7 +64,7 @@ __webpack_require__.d(__webpack_exports__, { "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/runtime/replace-runtime-module/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/runtime/replace-runtime-module/__snapshots__/web/1.snap.txt index 885872d60dec..8da66a5ad993 100644 --- a/tests/rspack-test/hotCases/runtime/replace-runtime-module/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/runtime/replace-runtime-module/__snapshots__/web/1.snap.txt @@ -34,7 +34,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/runtime/require-disposed-module-warning/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/runtime/require-disposed-module-warning/__snapshots__/web/1.snap.txt index 2de2cd384fa4..3572f80ebe42 100644 --- a/tests/rspack-test/hotCases/runtime/require-disposed-module-warning/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/runtime/require-disposed-module-warning/__snapshots__/web/1.snap.txt @@ -34,7 +34,7 @@ self["rspackHotUpdate"]("main", { "./b.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/sharing/share-plugin/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/sharing/share-plugin/__snapshots__/web/1.snap.txt index 4cbaa6b63730..c703217ed5eb 100644 --- a/tests/rspack-test/hotCases/sharing/share-plugin/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/sharing/share-plugin/__snapshots__/web/1.snap.txt @@ -7,7 +7,7 @@ - Bundle: bundle.js - Bundle: common_js_2.chunk.CURRENT_HASH.js - Manifest: main.LAST_HASH.hot-update.json, size: 28 -- Update: main.LAST_HASH.hot-update.js, size: 42334 +- Update: main.LAST_HASH.hot-update.js, size: 42335 ## Manifest @@ -38,7 +38,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (/* reexport default from dynamic */ common__rspack_import_0_default.a), getValue: () => (getValue) @@ -83,7 +83,7 @@ __webpack_require__.t = function(value, mode) { if((mode & 16) && typeof value.then === 'function') return value; } var ns = Object.create(null); - __webpack_require__.r(ns); + __webpack_require__.N(ns); var def = {}; leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)]; for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) { @@ -93,6 +93,7 @@ __webpack_require__.t = function(value, mode) { __webpack_require__.d(ns, def); return ns; }; + })(); // webpack/runtime/get_full_hash (() => { diff --git a/tests/rspack-test/hotCases/source-map/disable/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/source-map/disable/__snapshots__/web/1.snap.txt index 8fed6e5d725b..2f6e3d00ceef 100644 --- a/tests/rspack-test/hotCases/source-map/disable/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/source-map/disable/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/source-map/disable/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/source-map/disable/__snapshots__/web/2.snap.txt index 6e69bdce5340..6b3986d4349d 100644 --- a/tests/rspack-test/hotCases/source-map/disable/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/source-map/disable/__snapshots__/web/2.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/source-map/disable/__snapshots__/web/3.snap.txt b/tests/rspack-test/hotCases/source-map/disable/__snapshots__/web/3.snap.txt index 9577cbb55fc6..81b13fba3822 100644 --- a/tests/rspack-test/hotCases/source-map/disable/__snapshots__/web/3.snap.txt +++ b/tests/rspack-test/hotCases/source-map/disable/__snapshots__/web/3.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/source-map/enable/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/source-map/enable/__snapshots__/web/1.snap.txt index c417df4cede8..f77b24d2db75 100644 --- a/tests/rspack-test/hotCases/source-map/enable/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/source-map/enable/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/source-map/enable/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/source-map/enable/__snapshots__/web/2.snap.txt index 8abb14272aff..2f55d4ca6c0e 100644 --- a/tests/rspack-test/hotCases/source-map/enable/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/source-map/enable/__snapshots__/web/2.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/source-map/enable/__snapshots__/web/3.snap.txt b/tests/rspack-test/hotCases/source-map/enable/__snapshots__/web/3.snap.txt index 0415170c7546..479c3b2785d4 100644 --- a/tests/rspack-test/hotCases/source-map/enable/__snapshots__/web/3.snap.txt +++ b/tests/rspack-test/hotCases/source-map/enable/__snapshots__/web/3.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/stats/chunks/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/stats/chunks/__snapshots__/web/1.snap.txt index 9ecfd1f9160a..1fd32e94a326 100644 --- a/tests/rspack-test/hotCases/stats/chunks/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/stats/chunks/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/status/check/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/status/check/__snapshots__/web/1.snap.txt index 64be7e97bc09..37484b37d921 100644 --- a/tests/rspack-test/hotCases/status/check/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/status/check/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); diff --git a/tests/rspack-test/hotCases/unexpected-invalidation/used-exports/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/unexpected-invalidation/used-exports/__snapshots__/web/1.snap.txt index 341de3f780a9..66a22967c8a8 100644 --- a/tests/rspack-test/hotCases/unexpected-invalidation/used-exports/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/unexpected-invalidation/used-exports/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (/* reexport safe */ _subject__rspack_import_0.def) }); diff --git a/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/1.snap.txt index 40acee45321e..df9dcfd97e0e 100644 --- a/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/1.snap.txt @@ -84,7 +84,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("shared", { "./moduleAs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -93,7 +93,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./moduleBs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -120,7 +120,7 @@ __webpack_require__.d(__webpack_exports__, { "use strict"; self["rspackHotUpdate"]("workerA_js", { "./moduleA.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -154,7 +154,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("workerB_js", { "./moduleB.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/2.snap.txt index 6fa608f76da6..523492b2bd43 100644 --- a/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/2.snap.txt @@ -84,7 +84,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("shared", { "./moduleAs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -93,7 +93,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./moduleBs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -120,7 +120,7 @@ __webpack_require__.d(__webpack_exports__, { "use strict"; self["rspackHotUpdate"]("workerA_js", { "./moduleA.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -154,7 +154,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("workerB_js", { "./moduleB.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/3.snap.txt b/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/3.snap.txt index fa4548ef4b00..abb845555713 100644 --- a/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/3.snap.txt +++ b/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/3.snap.txt @@ -84,7 +84,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("shared", { "./moduleAs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -93,7 +93,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./moduleBs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -120,7 +120,7 @@ __webpack_require__.d(__webpack_exports__, { "use strict"; self["rspackHotUpdate"]("workerA_js", { "./moduleA.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -154,7 +154,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("workerB_js", { "./moduleB.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/4.snap.txt b/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/4.snap.txt index f79f45618c39..45c9f82587dd 100644 --- a/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/4.snap.txt +++ b/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/4.snap.txt @@ -84,7 +84,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("shared", { "./moduleAs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -93,7 +93,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./moduleBs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -120,7 +120,7 @@ __webpack_require__.d(__webpack_exports__, { "use strict"; self["rspackHotUpdate"]("workerA_js", { "./moduleA.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -154,7 +154,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("workerB_js", { "./moduleB.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/5.snap.txt b/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/5.snap.txt index d2dfcd6e5f40..f5b0860ba47f 100644 --- a/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/5.snap.txt +++ b/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/5.snap.txt @@ -84,7 +84,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("shared", { "./moduleAs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -93,7 +93,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./moduleBs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -120,7 +120,7 @@ __webpack_require__.d(__webpack_exports__, { "use strict"; self["rspackHotUpdate"]("workerA_js", { "./moduleA.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -154,7 +154,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("workerB_js", { "./moduleB.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/6.snap.txt b/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/6.snap.txt index 7e1edd7102d5..5fbd5fe35cd5 100644 --- a/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/6.snap.txt +++ b/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/6.snap.txt @@ -84,7 +84,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("shared", { "./moduleAs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -93,7 +93,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./moduleBs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -120,7 +120,7 @@ __webpack_require__.d(__webpack_exports__, { "use strict"; self["rspackHotUpdate"]("workerA_js", { "./moduleA.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -154,7 +154,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("workerB_js", { "./moduleB.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/7.snap.txt b/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/7.snap.txt index 0f58631c185a..be399ab68364 100644 --- a/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/7.snap.txt +++ b/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/7.snap.txt @@ -84,7 +84,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("shared", { "./moduleAs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -93,7 +93,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./moduleBs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -120,7 +120,7 @@ __webpack_require__.d(__webpack_exports__, { "use strict"; self["rspackHotUpdate"]("workerA_js", { "./moduleA.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -154,7 +154,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("workerB_js", { "./moduleB.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/1.snap.txt index 94d7a5ece2db..d621b39e2332 100644 --- a/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/1.snap.txt @@ -85,7 +85,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("shared", { "./moduleAs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -96,7 +96,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./moduleBs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -105,7 +105,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./moduleS.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -133,7 +133,7 @@ __webpack_require__.d(__webpack_exports__, { "use strict"; self["rspackHotUpdate"]("workerA_js", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -142,7 +142,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./moduleA.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -178,7 +178,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("workerB_js", { "./moduleB.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/2.snap.txt index 6a5fff422512..c79a026dfcb2 100644 --- a/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/2.snap.txt @@ -84,7 +84,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("shared", { "./moduleAs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -95,7 +95,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./moduleBs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -124,7 +124,7 @@ __webpack_require__.d(__webpack_exports__, { "use strict"; self["rspackHotUpdate"]("workerA_js", { "./moduleA.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -161,7 +161,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("workerB_js", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -170,7 +170,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./moduleB.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/3.snap.txt b/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/3.snap.txt index bfd97b51c33b..3f1a455d6ed9 100644 --- a/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/3.snap.txt +++ b/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/3.snap.txt @@ -84,7 +84,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("shared", { "./moduleAs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -93,7 +93,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./moduleBs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -122,7 +122,7 @@ __webpack_require__.d(__webpack_exports__, { "use strict"; self["rspackHotUpdate"]("workerA_js", { "./moduleA.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -156,7 +156,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("workerB_js", { "./moduleB.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/4.snap.txt b/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/4.snap.txt index af65f4b58e19..ae31dc9e4782 100644 --- a/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/4.snap.txt +++ b/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/4.snap.txt @@ -86,7 +86,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("shared", { "./moduleAs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -96,7 +96,7 @@ if (Math.random() < 0) __webpack_require__.e(/* import() */ "chunkS_js").then(__ }, "./moduleBs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -123,7 +123,7 @@ __webpack_require__.d(__webpack_exports__, { "use strict"; self["rspackHotUpdate"]("workerA_js", { "./moduleA.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -158,7 +158,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("workerB_js", { "./moduleB.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/5.snap.txt b/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/5.snap.txt index 308040b70c7b..deba40c9aebe 100644 --- a/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/5.snap.txt +++ b/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/5.snap.txt @@ -86,7 +86,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("shared", { "./moduleAs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -96,7 +96,7 @@ if (Math.random() < 0) __webpack_require__.e(/* import() */ "chunkS_js").then(__ }, "./moduleBs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -124,7 +124,7 @@ if (Math.random() < 0) __webpack_require__.e(/* import() */ "chunkS_js").then(__ "use strict"; self["rspackHotUpdate"]("workerA_js", { "./moduleA.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -159,7 +159,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("workerB_js", { "./moduleB.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/6.snap.txt b/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/6.snap.txt index 0701c6a0baab..fd35e063d421 100644 --- a/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/6.snap.txt +++ b/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/6.snap.txt @@ -86,7 +86,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("shared", { "./moduleAs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -95,7 +95,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./moduleBs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -123,7 +123,7 @@ if (Math.random() < 0) __webpack_require__.e(/* import() */ "chunkS_js").then(__ "use strict"; self["rspackHotUpdate"]("workerA_js", { "./moduleA.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -157,7 +157,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("workerB_js", { "./moduleB.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/7.snap.txt b/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/7.snap.txt index beb8cde0faf2..6c58d53be86d 100644 --- a/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/7.snap.txt +++ b/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/7.snap.txt @@ -84,7 +84,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("shared", { "./moduleAs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -93,7 +93,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./moduleBs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -120,7 +120,7 @@ __webpack_require__.d(__webpack_exports__, { "use strict"; self["rspackHotUpdate"]("workerA_js", { "./moduleA.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -154,7 +154,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("workerB_js", { "./moduleB.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/worker/update-in-worker/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/worker/update-in-worker/__snapshots__/web/1.snap.txt index f7f7a71871d3..fb2926ec23ca 100644 --- a/tests/rspack-test/hotCases/worker/update-in-worker/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/worker/update-in-worker/__snapshots__/web/1.snap.txt @@ -67,7 +67,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("worker_js", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/worker/update-in-worker/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/worker/update-in-worker/__snapshots__/web/2.snap.txt index db58a28e7d5d..27a00ac6b6ba 100644 --- a/tests/rspack-test/hotCases/worker/update-in-worker/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/worker/update-in-worker/__snapshots__/web/2.snap.txt @@ -67,7 +67,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("worker_js", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/worker/update-in-worker/__snapshots__/web/3.snap.txt b/tests/rspack-test/hotCases/worker/update-in-worker/__snapshots__/web/3.snap.txt index f6850887a20b..85e94eacb49f 100644 --- a/tests/rspack-test/hotCases/worker/update-in-worker/__snapshots__/web/3.snap.txt +++ b/tests/rspack-test/hotCases/worker/update-in-worker/__snapshots__/web/3.snap.txt @@ -67,7 +67,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("worker_js", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/rstest.config.mts b/tests/rspack-test/rstest.config.mts index 70e71e70edcf..4500d6040393 100644 --- a/tests/rspack-test/rstest.config.mts +++ b/tests/rspack-test/rstest.config.mts @@ -123,6 +123,7 @@ export default defineConfig({ name: 'base', exclude: [ 'NativeWatcher*.test.js', + 'RuntimeMode*.test.js', ], }, { extends: sharedConfig, @@ -143,6 +144,15 @@ export default defineConfig({ retry: 0, // re-try in native watcher tests is useless maxConcurrency: 1, testTimeout: 30_000, + }, { + extends: sharedConfig, + name: 'runtimeMode', + include: process.env.WASM ? [] : [ + 'RuntimeMode*.test.js', + ], + exclude: [ + 'NativeWatcher*.test.js', + ], }], reporters, pool: { @@ -150,4 +160,3 @@ export default defineConfig({ execArgv: ['--no-warnings', '--expose-gc', '--max-old-space-size=8192', '--experimental-vm-modules'], }, }); - diff --git a/tests/rspack-test/statsAPICases/additional-chunks.js b/tests/rspack-test/statsAPICases/additional-chunks.js index 09983fa838b5..d3cd31f23d79 100644 --- a/tests/rspack-test/statsAPICases/additional-chunks.js +++ b/tests/rspack-test/statsAPICases/additional-chunks.js @@ -61,10 +61,10 @@ module.exports = { assets: Array [ Object { name: entryB.js, - size: 3210, + size: 3175, }, ], - assetsSize: 3210, + assetsSize: 3175, auxiliaryAssets: undefined, auxiliaryAssetsSize: undefined, childAssets: undefined, diff --git a/tests/rspack-test/statsAPICases/assets.js b/tests/rspack-test/statsAPICases/assets.js index bc44d5534464..959bfaa5daf7 100644 --- a/tests/rspack-test/statsAPICases/assets.js +++ b/tests/rspack-test/statsAPICases/assets.js @@ -39,7 +39,7 @@ module.exports = { related: Object {}, }, name: entryB.js, - size: 3210, + size: 3175, type: asset, }, Object { diff --git a/tests/rspack-test/statsAPICases/exports.js b/tests/rspack-test/statsAPICases/exports.js index 0fa899813fa3..305ac674df4b 100644 --- a/tests/rspack-test/statsAPICases/exports.js +++ b/tests/rspack-test/statsAPICases/exports.js @@ -79,7 +79,7 @@ module.exports = { main.js, ], filteredModules: undefined, - hash: 5494176960333ddb, + hash: 213d3fa346a21975, id: 889, idHints: Array [], initial: true, @@ -467,7 +467,7 @@ module.exports = { errorsCount: 0, filteredAssets: undefined, filteredModules: undefined, - hash: 2574529075ccb8c5, + hash: de0de71fc2881c5e, modules: Array [ Object { assets: Array [], diff --git a/tests/rspack-test/statsOutputCases/all-stats/__snapshots__/stats.txt b/tests/rspack-test/statsOutputCases/all-stats/__snapshots__/stats.txt index 53b516cd4716..7278abbed74e 100644 --- a/tests/rspack-test/statsOutputCases/all-stats/__snapshots__/stats.txt +++ b/tests/rspack-test/statsOutputCases/all-stats/__snapshots__/stats.txt @@ -23,4 +23,4 @@ webpack/runtime/make_namespace_object xx bytes {main} [code generated] [no exports] [used exports unknown] -1970-04-20 12: Rspack x.x.x compiled successfully in X s (c8efd3f0c70d4f0e) \ No newline at end of file +1970-04-20 12: Rspack x.x.x compiled successfully in X s (6a2353fa9fde7c92) \ No newline at end of file diff --git a/tests/rspack-test/statsOutputCases/immutable/__snapshots__/stats.txt b/tests/rspack-test/statsOutputCases/immutable/__snapshots__/stats.txt index 2ad71bcb14b8..b755f6b88b5e 100644 --- a/tests/rspack-test/statsOutputCases/immutable/__snapshots__/stats.txt +++ b/tests/rspack-test/statsOutputCases/immutable/__snapshots__/stats.txt @@ -1,2 +1,2 @@ -asset 6632dd142c468559.js xx KiB [emitted] [immutable] (name: main) +asset a7c04efacbf09fbd.js xx KiB [emitted] [immutable] (name: main) asset 7b129503d319bd23.js xx bytes [emitted] [immutable] \ No newline at end of file diff --git a/tests/rspack-test/statsOutputCases/issue-7577/__snapshots__/stats.txt b/tests/rspack-test/statsOutputCases/issue-7577/__snapshots__/stats.txt index c30cf8323048..1f0780f9819d 100644 --- a/tests/rspack-test/statsOutputCases/issue-7577/__snapshots__/stats.txt +++ b/tests/rspack-test/statsOutputCases/issue-7577/__snapshots__/stats.txt @@ -18,12 +18,12 @@ cacheable modules xx bytes Rspack x.x.x compiled successfully in X s assets by chunk xx bytes (id hint: all) - asset c-all-b_js-ce41787ae6ff3759.js xx bytes [emitted] [immutable] (id hint: all) + asset c-all-b_js-59f57022283cfc59.js xx bytes [emitted] [immutable] (id hint: all) asset c-all-c_js-305d7d7dfb13d2f8.js xx bytes [emitted] [immutable] (id hint: all) -asset c-runtime~main-f15de686b780a99d.js xx KiB [emitted] [immutable] (name: runtime~main) +asset c-runtime~main-df0635d4ba1c1079.js xx KiB [emitted] [immutable] (name: runtime~main) asset c-main-cb74163fc8cc359b.js xx bytes [emitted] [immutable] (name: main) asset c-vendors-node_modules_vendor_js-e936af1c5d692780.js xx bytes [emitted] [immutable] (id hint: vendors) -Entrypoint main xx KiB = c-runtime~main-f15de686b780a99d.js xx KiB c-all-c_js-305d7d7dfb13d2f8.js xx bytes c-main-cb74163fc8cc359b.js xx bytes +Entrypoint main xx KiB = c-runtime~main-df0635d4ba1c1079.js xx KiB c-all-c_js-305d7d7dfb13d2f8.js xx bytes c-main-cb74163fc8cc359b.js xx bytes runtime modules xx KiB 13 modules cacheable modules xx bytes ./c.js xx bytes [built] [code generated] diff --git a/tests/rspack-test/treeShakingCases/cjs-tree-shaking-basic/__snapshots__/treeshaking.snap.txt b/tests/rspack-test/treeShakingCases/cjs-tree-shaking-basic/__snapshots__/treeshaking.snap.txt index b0e8b5de246b..4c6d2df7e093 100644 --- a/tests/rspack-test/treeShakingCases/cjs-tree-shaking-basic/__snapshots__/treeshaking.snap.txt +++ b/tests/rspack-test/treeShakingCases/cjs-tree-shaking-basic/__snapshots__/treeshaking.snap.txt @@ -2,7 +2,7 @@ "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["main"], { "./answer.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { answer: () => (answer) }); diff --git a/tests/rspack-test/treeShakingCases/context-module/__snapshots__/treeshaking.snap.txt b/tests/rspack-test/treeShakingCases/context-module/__snapshots__/treeshaking.snap.txt index 60663dc01e60..63022ccfd43a 100644 --- a/tests/rspack-test/treeShakingCases/context-module/__snapshots__/treeshaking.snap.txt +++ b/tests/rspack-test/treeShakingCases/context-module/__snapshots__/treeshaking.snap.txt @@ -2,7 +2,7 @@ (self["rspackChunk"] = self["rspackChunk"] || []).push([["main"], { "./child/child/index.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); @@ -12,7 +12,7 @@ const value = "dynamic"; }, "./child/index.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); @@ -27,11 +27,11 @@ var map = { }; -function __rspack_context(req) { - var id = __rspack_context_resolve(req); +function __rspack_context_module(req) { + var id = __rspack_context_module_resolve(req); return __webpack_require__(id); } -function __rspack_context_resolve(req) { +function __rspack_context_module_resolve(req) { if(!__webpack_require__.o(map, req)) { var e = new Error("Cannot find module '" + req + "'"); e.code = 'MODULE_NOT_FOUND'; @@ -39,10 +39,10 @@ function __rspack_context_resolve(req) { } return map[req]; } -__rspack_context.keys = () => (Object.keys(map)); -__rspack_context.resolve = __rspack_context_resolve; -module.exports = __rspack_context; -__rspack_context.id = "./child sync recursive ^\\.\\/.*\\.js$"; +__rspack_context_module.keys = () => (Object.keys(map)); +__rspack_context_module.resolve = __rspack_context_module_resolve; +module.exports = __rspack_context_module; +__rspack_context_module.id = "./child sync recursive ^\\.\\/.*\\.js$"; }, diff --git a/tests/rspack-test/treeShakingCases/export-imported-import-all-as/__snapshots__/treeshaking.snap.txt b/tests/rspack-test/treeShakingCases/export-imported-import-all-as/__snapshots__/treeshaking.snap.txt index 88ee07aee845..f7d4b91b2e61 100644 --- a/tests/rspack-test/treeShakingCases/export-imported-import-all-as/__snapshots__/treeshaking.snap.txt +++ b/tests/rspack-test/treeShakingCases/export-imported-import-all-as/__snapshots__/treeshaking.snap.txt @@ -9,7 +9,7 @@ _answer__rspack_import_0; }, "./test.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { result: () => (result) }); diff --git a/tests/rspack-test/treeShakingCases/export-named-decl-as/__snapshots__/treeshaking.snap.txt b/tests/rspack-test/treeShakingCases/export-named-decl-as/__snapshots__/treeshaking.snap.txt index 4cf6c9a59f0b..6d6ac1b22944 100644 --- a/tests/rspack-test/treeShakingCases/export-named-decl-as/__snapshots__/treeshaking.snap.txt +++ b/tests/rspack-test/treeShakingCases/export-named-decl-as/__snapshots__/treeshaking.snap.txt @@ -2,7 +2,7 @@ "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["main"], { "./src/answer.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { formatNumber: () => (/* reexport safe */ _plugin_formatNumber__rspack_import_0["default"]) }); diff --git a/tests/rspack-test/treeShakingCases/export-star-chain/__snapshots__/treeshaking.snap.txt b/tests/rspack-test/treeShakingCases/export-star-chain/__snapshots__/treeshaking.snap.txt index e59015c8162c..4dcdbddd941b 100644 --- a/tests/rspack-test/treeShakingCases/export-star-chain/__snapshots__/treeshaking.snap.txt +++ b/tests/rspack-test/treeShakingCases/export-star-chain/__snapshots__/treeshaking.snap.txt @@ -27,7 +27,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./colors/index.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { blue: () => (/* reexport safe */ _b__rspack_import_1.blue), red: () => (/* reexport safe */ _a__rspack_import_0.red), diff --git a/tests/rspack-test/treeShakingCases/export_star/__snapshots__/treeshaking.snap.txt b/tests/rspack-test/treeShakingCases/export_star/__snapshots__/treeshaking.snap.txt index 1cdcc75c4ce2..7c3d4bec62dc 100644 --- a/tests/rspack-test/treeShakingCases/export_star/__snapshots__/treeshaking.snap.txt +++ b/tests/rspack-test/treeShakingCases/export_star/__snapshots__/treeshaking.snap.txt @@ -17,7 +17,7 @@ function b() {} }, "./foo.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { a: () => (a), b: () => (/* reexport safe */ _bar__rspack_import_0.b), diff --git a/tests/rspack-test/treeShakingCases/import-star-as-and-export/__snapshots__/treeshaking.snap.txt b/tests/rspack-test/treeShakingCases/import-star-as-and-export/__snapshots__/treeshaking.snap.txt index 1fa6d5c0f6fa..3f04d08e95c6 100644 --- a/tests/rspack-test/treeShakingCases/import-star-as-and-export/__snapshots__/treeshaking.snap.txt +++ b/tests/rspack-test/treeShakingCases/import-star-as-and-export/__snapshots__/treeshaking.snap.txt @@ -10,7 +10,7 @@ _app__rspack_import_0; }, "./lib.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { a: () => (a) }); diff --git a/tests/rspack-test/treeShakingCases/transitive-bailout/__snapshots__/treeshaking.snap.txt b/tests/rspack-test/treeShakingCases/transitive-bailout/__snapshots__/treeshaking.snap.txt index c31bcf53e82e..10b4d31dc0d6 100644 --- a/tests/rspack-test/treeShakingCases/transitive-bailout/__snapshots__/treeshaking.snap.txt +++ b/tests/rspack-test/treeShakingCases/transitive-bailout/__snapshots__/treeshaking.snap.txt @@ -29,7 +29,7 @@ _answer__rspack_import_0.test; }, "./lib.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { a: () => (/* reexport safe */ _a_js__rspack_import_0.a), b: () => (/* reexport safe */ _a_js__rspack_import_0.b) diff --git a/tests/rspack-test/treeShakingCases/tree-shaking-interop/__snapshots__/treeshaking.snap.txt b/tests/rspack-test/treeShakingCases/tree-shaking-interop/__snapshots__/treeshaking.snap.txt index 8504c945da3a..56737998abf8 100644 --- a/tests/rspack-test/treeShakingCases/tree-shaking-interop/__snapshots__/treeshaking.snap.txt +++ b/tests/rspack-test/treeShakingCases/tree-shaking-interop/__snapshots__/treeshaking.snap.txt @@ -2,7 +2,7 @@ "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["bar_js"], { "./bar.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (test) }); @@ -18,7 +18,7 @@ function test() {} (self["rspackChunk"] = self["rspackChunk"] || []).push([["main"], { "./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { a: () => (a) }); diff --git a/tests/rspack-test/treeShakingCases/tree-shaking-lazy-import/__snapshots__/treeshaking.snap.txt b/tests/rspack-test/treeShakingCases/tree-shaking-lazy-import/__snapshots__/treeshaking.snap.txt index f4dfe326d107..ccb057cc0226 100644 --- a/tests/rspack-test/treeShakingCases/tree-shaking-lazy-import/__snapshots__/treeshaking.snap.txt +++ b/tests/rspack-test/treeShakingCases/tree-shaking-lazy-import/__snapshots__/treeshaking.snap.txt @@ -2,7 +2,7 @@ "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["lib_js"], { "./lib.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/treeShakingCases/webpack-inner-graph-switch/__snapshots__/treeshaking.snap.txt b/tests/rspack-test/treeShakingCases/webpack-inner-graph-switch/__snapshots__/treeshaking.snap.txt index 7eb446a48548..8a04783ab3e9 100644 --- a/tests/rspack-test/treeShakingCases/webpack-inner-graph-switch/__snapshots__/treeshaking.snap.txt +++ b/tests/rspack-test/treeShakingCases/webpack-inner-graph-switch/__snapshots__/treeshaking.snap.txt @@ -2,7 +2,7 @@ "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["chunk_js"], { "./chunk.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); @@ -89,7 +89,7 @@ function useDocument(obj) { }, "./some-module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { Block: () => (Block), Document: () => (Document), diff --git a/tests/rspack-test/treeShakingCases/webpack-innergraph-circular/__snapshots__/treeshaking.snap.txt b/tests/rspack-test/treeShakingCases/webpack-innergraph-circular/__snapshots__/treeshaking.snap.txt index 5d63752b2f55..c02bd5c65f58 100644 --- a/tests/rspack-test/treeShakingCases/webpack-innergraph-circular/__snapshots__/treeshaking.snap.txt +++ b/tests/rspack-test/treeShakingCases/webpack-innergraph-circular/__snapshots__/treeshaking.snap.txt @@ -2,7 +2,7 @@ "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["chunk_js"], { "./chunk.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var _inner__rspack_import_0 = __webpack_require__("./inner.js"); diff --git a/tests/rspack-test/treeShakingCases/webpack-innergraph-no-side-effects/__snapshots__/treeshaking.snap.txt b/tests/rspack-test/treeShakingCases/webpack-innergraph-no-side-effects/__snapshots__/treeshaking.snap.txt index 40ceeaf9c7d3..12a7d3cc4a39 100644 --- a/tests/rspack-test/treeShakingCases/webpack-innergraph-no-side-effects/__snapshots__/treeshaking.snap.txt +++ b/tests/rspack-test/treeShakingCases/webpack-innergraph-no-side-effects/__snapshots__/treeshaking.snap.txt @@ -9,7 +9,7 @@ it("should be able to load package without side effects where modules are unused }, "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export), test: () => (test) diff --git a/tests/rspack-test/treeShakingCases/webpack-innergraph-try-globals/__snapshots__/treeshaking.snap.txt b/tests/rspack-test/treeShakingCases/webpack-innergraph-try-globals/__snapshots__/treeshaking.snap.txt index 009184c0f425..2bd0e53083ed 100644 --- a/tests/rspack-test/treeShakingCases/webpack-innergraph-try-globals/__snapshots__/treeshaking.snap.txt +++ b/tests/rspack-test/treeShakingCases/webpack-innergraph-try-globals/__snapshots__/treeshaking.snap.txt @@ -2,7 +2,7 @@ (self["rspackChunk"] = self["rspackChunk"] || []).push([["main"], { "./import-module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); /* import */ var _module__rspack_import_0 = __webpack_require__("./module.js"); diff --git a/tests/rspack-test/treeShakingCases/webpack-reexport-namespace-and-default/__snapshots__/treeshaking.snap.txt b/tests/rspack-test/treeShakingCases/webpack-reexport-namespace-and-default/__snapshots__/treeshaking.snap.txt index c71984659ab0..f04437e3a652 100644 --- a/tests/rspack-test/treeShakingCases/webpack-reexport-namespace-and-default/__snapshots__/treeshaking.snap.txt +++ b/tests/rspack-test/treeShakingCases/webpack-reexport-namespace-and-default/__snapshots__/treeshaking.snap.txt @@ -27,7 +27,7 @@ it("default export should be used", () => { }, "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.r(__webpack_exports__); +__webpack_require__.N(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { mod: () => (mod) }); diff --git a/tests/rspack-test/watchCases/async-modules/top-level-await/0/utils.js b/tests/rspack-test/watchCases/async-modules/top-level-await/0/utils.js index b0d91d609166..fbb953ba49a3 100644 --- a/tests/rspack-test/watchCases/async-modules/top-level-await/0/utils.js +++ b/tests/rspack-test/watchCases/async-modules/top-level-await/0/utils.js @@ -3,7 +3,7 @@ function escapeRegExp(string) { } export function isAsyncModule(content, moduleId) { - const regex = new RegExp(`\\"${escapeRegExp(moduleId)}\\".*\\(.*\\).*\\{\\s([\\S\\s]*?)__webpack_require__\\.r\\(__webpack_exports__\\);`) + const regex = new RegExp(`\\"${escapeRegExp(moduleId)}\\".*\\(.*\\).*\\{\\s([\\S\\s]*?)__webpack_require__\\.N\\(__webpack_exports__\\);`) const result = regex.exec(content) try { const [, header] = result; From 3c08905f275008327bd4d6fb9690c6e3026e7c20 Mon Sep 17 00:00:00 2001 From: LingyuCoder Date: Thu, 11 Jun 2026 12:05:01 +0800 Subject: [PATCH 02/21] fix(runtime): limit runtime context compatibility changes --- .../src/plugin/mod.rs | 12 +++---- .../src/container/ModuleFederationPlugin.ts | 32 ++++++++++++++++--- .../runtime/moduleFederationDefaultRuntime.js | 18 +---------- 3 files changed, 34 insertions(+), 28 deletions(-) diff --git a/crates/rspack_plugin_javascript/src/plugin/mod.rs b/crates/rspack_plugin_javascript/src/plugin/mod.rs index d71fa16cf5d8..473da6f3ec71 100644 --- a/crates/rspack_plugin_javascript/src/plugin/mod.rs +++ b/crates/rspack_plugin_javascript/src/plugin/mod.rs @@ -282,6 +282,11 @@ var module = ({module_cache}[moduleId] = {{"#, let intercept_module_execution = runtime_requirements.contains(RuntimeGlobals::INTERCEPT_MODULE_EXECUTION); let module_used = runtime_requirements.contains(RuntimeGlobals::MODULE); + let uses_runtime_context = compilation + .options + .experiments + .runtime_mode + .uses_runtime_context(); let has_custom_runtime_module = compilation .build_chunk_graph_artifact .chunk_graph @@ -293,7 +298,7 @@ var module = ({module_cache}[moduleId] = {{"#, }); let require_scope_used = runtime_requirements.contains(RuntimeGlobals::REQUIRE_SCOPE) || !runtime_requirements.renderable_require_scope().is_empty() - || has_custom_runtime_module; + || (uses_runtime_context && has_custom_runtime_module); let need_module_defer = runtime_requirements.contains(RuntimeGlobals::MAKE_DEFERRED_NAMESPACE_OBJECT); let use_require = require_function || intercept_module_execution || module_used; @@ -305,11 +310,6 @@ var module = ({module_cache}[moduleId] = {{"#, .output .environment .supports_arrow_function(); - let uses_runtime_context = compilation - .options - .experiments - .runtime_mode - .uses_runtime_context(); let has_bootstrap_runtime_context = uses_runtime_context && runtime_requirements.needs_bootstrap_runtime_context(); diff --git a/packages/rspack/src/container/ModuleFederationPlugin.ts b/packages/rspack/src/container/ModuleFederationPlugin.ts index 6ba51b06a96d..8e2b45e737bf 100644 --- a/packages/rspack/src/container/ModuleFederationPlugin.ts +++ b/packages/rspack/src/container/ModuleFederationPlugin.ts @@ -364,6 +364,25 @@ function getDefaultEntryRuntimeSource( ); } + const defaultRuntimeSource = compiler.rspack.Template.getFunctionContent( + require('./moduleFederationDefaultRuntime.js').default, + ); + const runtimeSource = getDefaultRuntimeSource( + defaultRuntimeSource, + compiler.options.experiments.runtimeMode === 'rspack' + ? `new Proxy(function (moduleId) { + return __rspack_context.r(moduleId); +}, { + get(_target, key) { + return __rspack_context[key]; + }, + set(_target, key, value) { + __rspack_context[key] = value; + return true; + } +})` + : '__webpack_require__', + ); const content = [ `import __module_federation_bundler_runtime__ from ${JSON.stringify( paths.bundlerRuntime, @@ -386,15 +405,18 @@ function getDefaultEntryRuntimeSource( treeShakingShareFallbacks, )}`, `const __module_federation_library_type__ = ${JSON.stringify(libraryType)}`, - IS_BROWSER - ? MF_RUNTIME_CODE - : compiler.rspack.Template.getFunctionContent( - require('./moduleFederationDefaultRuntime.js').default, - ), + IS_BROWSER ? MF_RUNTIME_CODE : runtimeSource, ].join(';'); return content; } +function getDefaultRuntimeSource(source: string, runtimeRequire: string) { + return source.replace( + '__module_federation_runtime_require__', + runtimeRequire, + ); +} + function getPublicPathRuntimeSource(compiler: Compiler) { const publicPath = compiler.options.output.publicPath; if (typeof publicPath !== 'string' || publicPath === 'auto') { diff --git a/packages/rspack/src/runtime/moduleFederationDefaultRuntime.js b/packages/rspack/src/runtime/moduleFederationDefaultRuntime.js index 420dc7d8cfc2..0434834ad0a0 100644 --- a/packages/rspack/src/runtime/moduleFederationDefaultRuntime.js +++ b/packages/rspack/src/runtime/moduleFederationDefaultRuntime.js @@ -7,23 +7,7 @@ var __module_federation_bundler_runtime__, __module_federation_share_fallbacks__, __module_federation_library_type__; export default function () { - const runtimeRequire = - typeof __rspack_context === 'undefined' - ? __webpack_require__ - : new Proxy( - function (moduleId) { - return __rspack_context.r(moduleId); - }, - { - get(_target, key) { - return __rspack_context[key]; - }, - set(_target, key, value) { - __rspack_context[key] = value; - return true; - }, - }, - ); + const runtimeRequire = __module_federation_runtime_require__; if ( (runtimeRequire.initializeSharingData || runtimeRequire.initializeExposesData) && From e169fb4f3dd0fbe431f9eb54a3ac25f058c13473 Mon Sep 17 00:00:00 2001 From: LingyuCoder Date: Thu, 11 Jun 2026 13:19:23 +0800 Subject: [PATCH 03/21] fix(runtime): update scan dependency benchmark template --- xtask/benchmark/benches/groups/scan_dependencies.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/xtask/benchmark/benches/groups/scan_dependencies.rs b/xtask/benchmark/benches/groups/scan_dependencies.rs index 1c011fd022a3..136825232f9b 100644 --- a/xtask/benchmark/benches/groups/scan_dependencies.rs +++ b/xtask/benchmark/benches/groups/scan_dependencies.rs @@ -11,8 +11,8 @@ use criterion::{BatchSize, black_box}; use rspack::builder::{Builder as _, NodeOptionBuilder}; use rspack_benchmark::Criterion; use rspack_core::{ - BuildInfo, BuildMeta, Compiler, CompilerOptions, Mode, ModuleCodeTemplate, ModuleIdentifier, - ModuleType, Optimization, ParseMeta, ParserOptions, ResourceData, SideEffectOption, + BuildInfo, BuildMeta, Compiler, CompilerOptions, Mode, ModuleIdentifier, ModuleType, + Optimization, ParseMeta, ParserOptions, ResourceData, RuntimeTemplate, SideEffectOption, }; use rspack_plugin_javascript::{ BoxJavascriptParserPlugin, @@ -155,6 +155,9 @@ fn prepare_scan_dependencies_benchmark_case( .cloned() .expect("scan_dependencies benchmark compiler should include javascript parser options"); + let runtime_template = + RuntimeTemplate::new(compiler_options.clone()).create_module_code_template(); + PreparedScanDependenciesBenchmarkCase { benchmark_id, source_text, @@ -165,9 +168,7 @@ fn prepare_scan_dependencies_benchmark_case( module_identifier: resource_path.into(), module_type, resource_data: ResourceData::new_with_resource(resource_path.to_string()), - parser_runtime_requirements: ParserRuntimeRequirementsData::new(&ModuleCodeTemplate::new( - compiler_options, - )), + parser_runtime_requirements: ParserRuntimeRequirementsData::new(&runtime_template), } } From fd061d198da914d95917a491b43706c93504154a Mon Sep 17 00:00:00 2001 From: LingyuCoder Date: Thu, 11 Jun 2026 14:23:36 +0800 Subject: [PATCH 04/21] fix(runtime): address runtime context review feedback --- .../src/parser_plugin/api_plugin.rs | 38 +++++++++++++++---- .../federation_data_runtime_module.rs | 8 +++- .../src/container/remote_runtime_module.rs | 6 +-- crates/rspack_plugin_mf/src/lib.rs | 11 ++++++ .../sharing/consume_shared_runtime_module.rs | 5 ++- .../src/sharing/share_runtime_module.rs | 6 +-- .../shared_container_runtime_module.rs | 10 +++-- ...d_used_exports_optimizer_runtime_module.rs | 10 +++-- 8 files changed, 71 insertions(+), 23 deletions(-) diff --git a/crates/rspack_plugin_javascript/src/parser_plugin/api_plugin.rs b/crates/rspack_plugin_javascript/src/parser_plugin/api_plugin.rs index dade5641a77c..279f1cf668a4 100644 --- a/crates/rspack_plugin_javascript/src/parser_plugin/api_plugin.rs +++ b/crates/rspack_plugin_javascript/src/parser_plugin/api_plugin.rs @@ -197,6 +197,7 @@ fn static_require_member_chain( parser: &mut JavascriptParser, for_name: &str, members: &[Atom], + member_ranges: Option<&[Span]>, expr_span: Span, write: bool, ) -> Option { @@ -204,10 +205,18 @@ fn static_require_member_chain( && let Some(property) = members.first() { if let Some(runtime_global) = RuntimeGlobals::from_property_name(property.as_ref()) { + let dep_span = if members.len() > 1 { + member_ranges + .and_then(|ranges| ranges.get(1)) + .map(|range| Span::new(expr_span.lo, range.hi)) + .unwrap_or(expr_span) + } else { + expr_span + }; let dep = if write { - RuntimeRequirementsDependency::write(expr_span.into(), runtime_global) + RuntimeRequirementsDependency::write(dep_span.into(), runtime_global) } else { - RuntimeRequirementsDependency::new(expr_span.into(), runtime_global) + RuntimeRequirementsDependency::new(dep_span.into(), runtime_global) }; parser.add_presentational_dependency(Box::new(dep)); } else { @@ -412,12 +421,19 @@ impl<'p, 'a> JavascriptParserPlugin<'p, 'a> for APIPlugin { for_name: &str, members: &[Atom], _members_optionals: &[bool], - _member_ranges: &[Span], + member_ranges: &[Span], ) -> Option { if parser.compiler_options.experiments.runtime_mode != ExperimentRuntimeMode::Rspack { return None; } - static_require_member_chain(parser, for_name, members, member_expr.span, false) + static_require_member_chain( + parser, + for_name, + members, + Some(member_ranges), + member_expr.span, + false, + ) } fn call_member_chain( @@ -427,12 +443,19 @@ impl<'p, 'a> JavascriptParserPlugin<'p, 'a> for APIPlugin { for_name: &str, members: &[Atom], _members_optionals: &[bool], - _member_ranges: &[Span], + member_ranges: &[Span], ) -> Option { if parser.compiler_options.experiments.runtime_mode != ExperimentRuntimeMode::Rspack { return None; } - let handled = static_require_member_chain(parser, for_name, members, expr.callee.span(), false); + let handled = static_require_member_chain( + parser, + for_name, + members, + Some(member_ranges), + expr.callee.span(), + false, + ); if handled.is_some() { parser.walk_expr_or_spread(&expr.args); } @@ -449,7 +472,8 @@ impl<'p, 'a> JavascriptParserPlugin<'p, 'a> for APIPlugin { if parser.compiler_options.experiments.runtime_mode != ExperimentRuntimeMode::Rspack { return None; } - let handled = static_require_member_chain(parser, for_name, members, expr.left.span(), true); + let handled = + static_require_member_chain(parser, for_name, members, None, expr.left.span(), true); if handled.is_some() { parser.walk_expression(&expr.right); } diff --git a/crates/rspack_plugin_mf/src/container/federation_data_runtime_module.rs b/crates/rspack_plugin_mf/src/container/federation_data_runtime_module.rs index 0743addee0b6..131e3ae2d566 100644 --- a/crates/rspack_plugin_mf/src/container/federation_data_runtime_module.rs +++ b/crates/rspack_plugin_mf/src/container/federation_data_runtime_module.rs @@ -6,14 +6,14 @@ use async_trait::async_trait; use rspack_core::{ - BooleanMatcher, Chunk, Compilation, RuntimeCodeTemplate, RuntimeModule, + BooleanMatcher, Chunk, Compilation, RuntimeCodeTemplate, RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeModuleStage, RuntimeTemplate, compile_boolean_matcher, get_js_chunk_filename_template, get_undo_path, impl_runtime_module, }; use rspack_error::Result; use rspack_plugin_javascript::impl_plugin_for_js_plugin::chunk_has_js; -use crate::utils::runtime_require_scope_name; +use crate::utils::{runtime_require_scope_name, runtime_require_scope_requirement}; #[impl_runtime_module] #[derive(Debug)] @@ -39,6 +39,10 @@ impl RuntimeModule for FederationDataRuntimeModule { .expect_get(&self.chunk.expect("The chunk should be attached.")); Ok(federation_runtime_template(chunk, runtime_template, compilation).await) } + + fn additional_runtime_requirements(&self, compilation: &Compilation) -> RuntimeGlobals { + runtime_require_scope_requirement(compilation) + } } pub async fn federation_runtime_template( diff --git a/crates/rspack_plugin_mf/src/container/remote_runtime_module.rs b/crates/rspack_plugin_mf/src/container/remote_runtime_module.rs index 491e00b424aa..f4cd2f0b25fa 100644 --- a/crates/rspack_plugin_mf/src/container/remote_runtime_module.rs +++ b/crates/rspack_plugin_mf/src/container/remote_runtime_module.rs @@ -13,7 +13,7 @@ use serde::Serialize; use super::remote_module::RemoteModule; use crate::{ ShareScope, - utils::{json_stringify, runtime_require_scope_name}, + utils::{json_stringify, runtime_require_scope_name, runtime_require_scope_requirement}, }; static REMOTES_LOADING_TEMPLATE: &str = include_str!("./remotesLoading.ejs"); @@ -134,8 +134,8 @@ impl RuntimeModule for RemoteRuntimeModule { )) } - fn additional_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { - *REMOTES_LOADING_RUNTIME_REQUIREMENTS + fn additional_runtime_requirements(&self, compilation: &Compilation) -> RuntimeGlobals { + *REMOTES_LOADING_RUNTIME_REQUIREMENTS | runtime_require_scope_requirement(compilation) } } diff --git a/crates/rspack_plugin_mf/src/lib.rs b/crates/rspack_plugin_mf/src/lib.rs index 7b179239e69e..8ce35657e82a 100644 --- a/crates/rspack_plugin_mf/src/lib.rs +++ b/crates/rspack_plugin_mf/src/lib.rs @@ -87,11 +87,22 @@ mod utils { } } + pub fn runtime_require_scope_requirement(compilation: &Compilation) -> RuntimeGlobals { + if compilation.options.experiments.runtime_mode == RuntimeMode::Rspack { + RuntimeGlobals::REQUIRE_SCOPE + } else { + RuntimeGlobals::default() + } + } + pub fn module_require_scope_name( compilation: &Compilation, runtime_template: &mut ModuleCodeTemplate, ) -> String { if compilation.options.experiments.runtime_mode == RuntimeMode::Rspack { + runtime_template + .runtime_requirements_mut() + .insert(RuntimeGlobals::REQUIRE_SCOPE); runtime_template.render_runtime_variable(&RuntimeVariable::Context) } else { runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE) diff --git a/crates/rspack_plugin_mf/src/sharing/consume_shared_runtime_module.rs b/crates/rspack_plugin_mf/src/sharing/consume_shared_runtime_module.rs index 6efd2cdba57e..63b67e524ff0 100644 --- a/crates/rspack_plugin_mf/src/sharing/consume_shared_runtime_module.rs +++ b/crates/rspack_plugin_mf/src/sharing/consume_shared_runtime_module.rs @@ -12,7 +12,7 @@ use rustc_hash::FxHashMap; use super::consume_shared_plugin::ConsumeVersion; use crate::{ ShareScope, - utils::{json_stringify, runtime_require_scope_name}, + utils::{json_stringify, runtime_require_scope_name, runtime_require_scope_requirement}, }; static CONSUMES_COMMON_TEMPLATE: &str = include_str!("./consumesCommon.ejs"); @@ -232,10 +232,11 @@ impl RuntimeModule for ConsumeSharedRuntimeModule { Ok(source) } - fn additional_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + fn additional_runtime_requirements(&self, compilation: &Compilation) -> RuntimeGlobals { *CONSUMES_RUNTIME_REQUIREMENTS | *CONSUMES_INITIAL_RUNTIME_REQUIREMENTS | *CONSUMES_LOADING_RUNTIME_REQUIREMENTS + | runtime_require_scope_requirement(compilation) } } diff --git a/crates/rspack_plugin_mf/src/sharing/share_runtime_module.rs b/crates/rspack_plugin_mf/src/sharing/share_runtime_module.rs index 58948a89ba9d..971eb4068b75 100644 --- a/crates/rspack_plugin_mf/src/sharing/share_runtime_module.rs +++ b/crates/rspack_plugin_mf/src/sharing/share_runtime_module.rs @@ -15,7 +15,7 @@ use rustc_hash::FxHashMap; use super::provide_shared_plugin::ProvideVersion; use crate::{ ConsumeVersion, ShareScope, - utils::{json_stringify, runtime_require_scope_name}, + utils::{json_stringify, runtime_require_scope_name, runtime_require_scope_requirement}, }; static INITIALIZE_SHARING_TEMPLATE: &str = include_str!("./initializeSharing.ejs"); @@ -154,8 +154,8 @@ impl RuntimeModule for ShareRuntimeModule { )) } - fn additional_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { - *INITIALIZE_SHARING_RUNTIME_REQUIREMENTS + fn additional_runtime_requirements(&self, compilation: &Compilation) -> RuntimeGlobals { + *INITIALIZE_SHARING_RUNTIME_REQUIREMENTS | runtime_require_scope_requirement(compilation) } } diff --git a/crates/rspack_plugin_mf/src/sharing/shared_container_runtime_module.rs b/crates/rspack_plugin_mf/src/sharing/shared_container_runtime_module.rs index 402ad89e4d1a..716940a1f381 100644 --- a/crates/rspack_plugin_mf/src/sharing/shared_container_runtime_module.rs +++ b/crates/rspack_plugin_mf/src/sharing/shared_container_runtime_module.rs @@ -1,9 +1,9 @@ use rspack_core::{ - RuntimeModule, RuntimeModuleGenerateContext, RuntimeModuleStage, RuntimeTemplate, - impl_runtime_module, + Compilation, RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeModuleStage, + RuntimeTemplate, impl_runtime_module, }; -use crate::utils::runtime_require_scope_name; +use crate::utils::{runtime_require_scope_name, runtime_require_scope_requirement}; #[impl_runtime_module] #[derive(Debug)] @@ -30,4 +30,8 @@ impl RuntimeModule for ShareContainerRuntimeModule { fn stage(&self) -> RuntimeModuleStage { RuntimeModuleStage::Attach } + + fn additional_runtime_requirements(&self, compilation: &Compilation) -> RuntimeGlobals { + runtime_require_scope_requirement(compilation) + } } diff --git a/crates/rspack_plugin_mf/src/sharing/shared_used_exports_optimizer_runtime_module.rs b/crates/rspack_plugin_mf/src/sharing/shared_used_exports_optimizer_runtime_module.rs index 1af7161d9e2a..5400d534d2b0 100644 --- a/crates/rspack_plugin_mf/src/sharing/shared_used_exports_optimizer_runtime_module.rs +++ b/crates/rspack_plugin_mf/src/sharing/shared_used_exports_optimizer_runtime_module.rs @@ -2,13 +2,13 @@ use std::{collections::BTreeMap, sync::Arc}; use async_trait::async_trait; use rspack_core::{ - RuntimeModule, RuntimeModuleGenerateContext, RuntimeModuleStage, RuntimeTemplate, - impl_runtime_module, + Compilation, RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeModuleStage, + RuntimeTemplate, impl_runtime_module, }; use rspack_error::{Result, error}; use rustc_hash::{FxHashMap, FxHashSet}; -use crate::utils::runtime_require_scope_name; +use crate::utils::{runtime_require_scope_name, runtime_require_scope_requirement}; #[impl_runtime_module] #[derive(Debug)] @@ -36,6 +36,10 @@ impl RuntimeModule for SharedUsedExportsOptimizerRuntimeModule { RuntimeModuleStage::Attach } + fn additional_runtime_requirements(&self, compilation: &Compilation) -> RuntimeGlobals { + runtime_require_scope_requirement(compilation) + } + async fn generate(&self, context: &RuntimeModuleGenerateContext<'_>) -> Result { if self.shared_used_exports.is_empty() { return Ok(String::new()); From 98381f9cf9a4f969588c0d10efd4b28cdb537d66 Mon Sep 17 00:00:00 2001 From: LingyuCoder Date: Thu, 11 Jun 2026 14:59:43 +0800 Subject: [PATCH 05/21] fix(runtime): align rspack context global rendering --- .../runtime_proxy_metadata_artifact.rs | 2 +- crates/rspack_core/src/runtime_globals.rs | 18 +++++++++++++++++- crates/rspack_core/src/runtime_template.rs | 2 +- .../src/parser_plugin/api_plugin.rs | 4 +++- crates/rspack_plugin_javascript/src/runtime.rs | 4 ++-- packages/rspack/src/RuntimeGlobals.ts | 15 +++++++++++---- .../__snapshots__/output.snap.txt | 2 +- .../asset-simple/__snapshots__/output.snap.txt | 2 +- .../asset-source/__snapshots__/output.snap.txt | 2 +- .../__snapshots__/output.snap.txt | 10 +++++----- .../__snapshots__/output.snap.txt | 4 ++-- .../__snapshots__/output.snap.txt | 4 ++-- .../hashbang/__snapshots__/output.snap.txt | 4 ++-- .../provide/__snapshots__/output.snap.txt | 2 +- .../simple/__snapshots__/output.snap.txt | 2 +- .../__snapshots__/output.snap.txt | 4 ++-- .../v128/__snapshots__/output.snap.txt | 2 +- .../__snapshots__/output.snap.txt | 4 ++-- .../__snapshots__/output.snap.txt | 4 ++-- .../__snapshots__/output.snap.txt | 2 +- .../__snapshots__/output.snap.txt | 8 ++++---- .../cycle-entry/__snapshots__/output.snap.txt | 4 ++-- .../intersection/__snapshots__/output.snap.txt | 4 ++-- .../__snapshots__/output.snap.txt | 6 +++--- .../simple/__snapshots__/output.snap.txt | 2 +- .../minify/__snapshots__/output.snap.txt | 2 +- .../reexport-star/__snapshot__/case1.txt | 2 +- .../__snapshots__/esm.snap.txt | 4 ++-- .../tree-shaking/__snapshots__/esm.snap.txt | 4 ++-- .../basic/__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 6 +++--- .../__snapshots__/esm.snap.txt | 6 +++--- .../__snapshots__/esm.snap.txt | 6 +++--- .../__snapshots__/esm.snap.txt | 6 +++--- .../__snapshots__/esm.snap.txt | 6 +++--- .../__snapshots__/esm.snap.txt | 8 ++++---- .../__snapshots__/esm.snap.txt | 6 +++--- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../import-cjs/__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 6 +++--- .../__snapshots__/esm.snap.txt | 6 +++--- .../__snapshots__/esm.snap.txt | 8 ++++---- .../__snapshots__/esm.snap.txt | 8 ++++---- .../magic-comment/__snapshots__/esm.snap.txt | 6 +++--- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../esm-node-target/__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 6 +++--- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../basic-capture/__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 6 +++--- .../__snapshots__/esm.snap.txt | 6 +++--- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 6 +++--- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 6 +++--- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../re-export-star/__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 6 +++--- .../__snapshots__/esm.snap.txt | 6 +++--- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 6 +++--- .../cjs-entry/__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 6 +++--- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/esm.snap.txt | 4 ++-- .../__snapshots__/web/1.snap.txt | 2 +- .../issue-9706/__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 4 ++-- .../__snapshots__/web/1.snap.txt | 4 ++-- .../__snapshots__/web/1.snap.txt | 4 ++-- .../__snapshots__/web/1.snap.txt | 4 ++-- .../system-import/__snapshots__/web/1.snap.txt | 8 ++++---- .../__snapshots__/web/1.snap.txt | 4 ++-- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/2.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 4 ++-- .../__snapshots__/web/1.snap.txt | 2 +- .../css-extract/__snapshots__/web/1.snap.txt | 4 ++-- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../css-modules/__snapshots__/web/1.snap.txt | 4 ++-- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/2.snap.txt | 2 +- .../css/recovery/__snapshots__/web/2.snap.txt | 4 ++-- .../css/vanilla/__snapshots__/web/1.snap.txt | 2 +- .../issue-6962/__snapshots__/web/1.snap.txt | 2 +- .../issue-10174/__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../decline/__snapshots__/web/1.snap.txt | 2 +- .../errors/events/__snapshots__/web/1.snap.txt | 14 +++++++------- .../self-decline/__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/2.snap.txt | 2 +- .../__snapshots__/web/3.snap.txt | 4 ++-- .../unaccepted/__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../module-hot/__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../auto-import/__snapshots__/web/1.snap.txt | 2 +- .../auto-reexport/__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../hot-index/__snapshots__/web/1.snap.txt | 2 +- .../hot-index/__snapshots__/web/2.snap.txt | 2 +- .../hot-index/__snapshots__/web/3.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../context/__snapshots__/web/1.snap.txt | 2 +- .../context/__snapshots__/web/2.snap.txt | 2 +- .../unrelated/__snapshots__/web/1.snap.txt | 2 +- .../unrelated/__snapshots__/web/2.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/2.snap.txt | 2 +- .../__snapshots__/web/3.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../fix-issuer/__snapshots__/web/1.snap.txt | 2 +- .../issue-10915/__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/2.snap.txt | 4 ++-- .../__snapshots__/web/1.snap.txt | 2 +- .../build-info/__snapshots__/web/1.snap.txt | 2 +- .../auto-reexport/__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 4 ++-- .../__snapshots__/web/1.snap.txt | 4 ++-- .../__snapshots__/web/2.snap.txt | 4 ++-- .../production/__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../plugins/html/__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/2.snap.txt | 2 +- .../__snapshots__/web/2.snap.txt | 2 +- .../__snapshots__/web/2.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/2.snap.txt | 4 ++-- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/3.snap.txt | 2 +- .../circular/__snapshots__/web/1.snap.txt | 4 ++-- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/2.snap.txt | 2 +- .../__snapshots__/web/3.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 4 ++-- .../__snapshots__/web/2.snap.txt | 4 ++-- .../hmr-circular/__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 4 ++-- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/1.snap.txt | 2 +- .../share-plugin/__snapshots__/web/1.snap.txt | 4 ++-- .../disable/__snapshots__/web/1.snap.txt | 2 +- .../disable/__snapshots__/web/2.snap.txt | 2 +- .../disable/__snapshots__/web/3.snap.txt | 2 +- .../enable/__snapshots__/web/1.snap.txt | 2 +- .../enable/__snapshots__/web/2.snap.txt | 2 +- .../enable/__snapshots__/web/3.snap.txt | 2 +- .../stats/chunks/__snapshots__/web/1.snap.txt | 2 +- .../status/check/__snapshots__/web/1.snap.txt | 2 +- .../used-exports/__snapshots__/web/1.snap.txt | 2 +- .../issue-5597/__snapshots__/web/1.snap.txt | 8 ++++---- .../issue-5597/__snapshots__/web/2.snap.txt | 8 ++++---- .../issue-5597/__snapshots__/web/3.snap.txt | 8 ++++---- .../issue-5597/__snapshots__/web/4.snap.txt | 8 ++++---- .../issue-5597/__snapshots__/web/5.snap.txt | 8 ++++---- .../issue-5597/__snapshots__/web/6.snap.txt | 8 ++++---- .../issue-5597/__snapshots__/web/7.snap.txt | 8 ++++---- .../__snapshots__/web/1.snap.txt | 12 ++++++------ .../__snapshots__/web/2.snap.txt | 10 +++++----- .../__snapshots__/web/3.snap.txt | 8 ++++---- .../__snapshots__/web/4.snap.txt | 8 ++++---- .../__snapshots__/web/5.snap.txt | 8 ++++---- .../__snapshots__/web/6.snap.txt | 8 ++++---- .../__snapshots__/web/7.snap.txt | 8 ++++---- .../__snapshots__/web/1.snap.txt | 2 +- .../__snapshots__/web/2.snap.txt | 2 +- .../__snapshots__/web/3.snap.txt | 2 +- tests/rspack-test/statsAPICases/exports.js | 4 ++-- .../all-stats/__snapshots__/stats.txt | 2 +- .../immutable/__snapshots__/stats.txt | 2 +- .../issue-7577/__snapshots__/stats.txt | 6 +++--- .../__snapshots__/treeshaking.snap.txt | 2 +- .../__snapshots__/treeshaking.snap.txt | 4 ++-- .../__snapshots__/treeshaking.snap.txt | 2 +- .../__snapshots__/treeshaking.snap.txt | 2 +- .../__snapshots__/treeshaking.snap.txt | 2 +- .../__snapshots__/treeshaking.snap.txt | 2 +- .../__snapshots__/treeshaking.snap.txt | 2 +- .../__snapshots__/treeshaking.snap.txt | 2 +- .../__snapshots__/treeshaking.snap.txt | 4 ++-- .../__snapshots__/treeshaking.snap.txt | 2 +- .../__snapshots__/treeshaking.snap.txt | 4 ++-- .../__snapshots__/treeshaking.snap.txt | 2 +- .../__snapshots__/treeshaking.snap.txt | 2 +- .../__snapshots__/treeshaking.snap.txt | 2 +- .../__snapshots__/treeshaking.snap.txt | 2 +- .../async-modules/top-level-await/0/utils.js | 2 +- 235 files changed, 459 insertions(+), 434 deletions(-) diff --git a/crates/rspack_core/src/artifacts/runtime_proxy_metadata_artifact.rs b/crates/rspack_core/src/artifacts/runtime_proxy_metadata_artifact.rs index ace14da965c4..abfe355a26cb 100644 --- a/crates/rspack_core/src/artifacts/runtime_proxy_metadata_artifact.rs +++ b/crates/rspack_core/src/artifacts/runtime_proxy_metadata_artifact.rs @@ -57,7 +57,7 @@ impl RuntimeProxyMetadata { let mut source = String::new(); for (_, runtime_global) in self.context_fields().iter_names() { let (Some(property_name), Some(lexical_name)) = ( - runtime_global.property_name(), + runtime_global.rspack_context_property_name(), runtime_global.to_lexical_name(), ) else { continue; diff --git a/crates/rspack_core/src/runtime_globals.rs b/crates/rspack_core/src/runtime_globals.rs index 814978a32fc1..922f856d88bd 100644 --- a/crates/rspack_core/src/runtime_globals.rs +++ b/crates/rspack_core/src/runtime_globals.rs @@ -389,7 +389,7 @@ pub fn runtime_globals_property_name(runtime_globals: &RuntimeGlobals) -> Option RuntimeGlobals::STARTUP_NO_DEFAULT => "x (no default handler)", RuntimeGlobals::ENSURE_CHUNK_INCLUDE_ENTRIES => "f (include entries)", RuntimeGlobals::STARTUP => "x", - RuntimeGlobals::MAKE_NAMESPACE_OBJECT => "N", + RuntimeGlobals::MAKE_NAMESPACE_OBJECT => "r", RuntimeGlobals::MAKE_DEFERRED_NAMESPACE_OBJECT => "z", RuntimeGlobals::MAKE_OPTIMIZED_DEFERRED_NAMESPACE_OBJECT => "zO", RuntimeGlobals::DEFERRED_MODULES_ASYNC_TRANSITIVE_DEPENDENCIES => "zT", @@ -528,6 +528,14 @@ impl RuntimeGlobals { runtime_globals_property_name(self) } + pub fn rspack_context_property_name(&self) -> Option<&'static str> { + if *self == RuntimeGlobals::MAKE_NAMESPACE_OBJECT { + Some("N") + } else { + self.property_name() + } + } + pub fn name(&self) -> Option<&'static str> { RUNTIME_GLOBAL_MAP.0.get(self).copied() } @@ -536,6 +544,14 @@ impl RuntimeGlobals { RUNTIME_GLOBAL_MAP.2.get(property_name).copied() } + pub fn from_rspack_context_property_name(property_name: &str) -> Option { + if property_name == "N" { + return Some(RuntimeGlobals::MAKE_NAMESPACE_OBJECT); + } + let runtime_global = Self::from_property_name(property_name)?; + (runtime_global != RuntimeGlobals::MAKE_NAMESPACE_OBJECT).then_some(runtime_global) + } + pub fn renderable_require_scope(self) -> Self { self.intersection(*REQUIRE_SCOPE_GLOBALS) } diff --git a/crates/rspack_core/src/runtime_template.rs b/crates/rspack_core/src/runtime_template.rs index 63cf70c77400..066a3ed1d579 100644 --- a/crates/rspack_core/src/runtime_template.rs +++ b/crates/rspack_core/src/runtime_template.rs @@ -295,7 +295,7 @@ fn runtime_globals_to_render_map(render_mode: RuntimeGlobalRenderMode) -> Runtim } else if runtime_globals == RuntimeGlobals::REQUIRE { format!("{}.r", runtime_variable_name(&RuntimeVariable::Context)) } else if runtime_globals.renderable_require_scope() == runtime_globals { - if let Some(name) = runtime_globals.property_name() { + if let Some(name) = runtime_globals.rspack_context_property_name() { format!( "{}{}", runtime_variable_name(&RuntimeVariable::Context), diff --git a/crates/rspack_plugin_javascript/src/parser_plugin/api_plugin.rs b/crates/rspack_plugin_javascript/src/parser_plugin/api_plugin.rs index 279f1cf668a4..aa44e9beae4a 100644 --- a/crates/rspack_plugin_javascript/src/parser_plugin/api_plugin.rs +++ b/crates/rspack_plugin_javascript/src/parser_plugin/api_plugin.rs @@ -204,7 +204,9 @@ fn static_require_member_chain( if for_name == API_REQUIRE && let Some(property) = members.first() { - if let Some(runtime_global) = RuntimeGlobals::from_property_name(property.as_ref()) { + if let Some(runtime_global) = + RuntimeGlobals::from_rspack_context_property_name(property.as_ref()) + { let dep_span = if members.len() > 1 { member_ranges .and_then(|ranges| ranges.get(1)) diff --git a/crates/rspack_plugin_javascript/src/runtime.rs b/crates/rspack_plugin_javascript/src/runtime.rs index 56b7f172ad61..9da01dbe36f3 100644 --- a/crates/rspack_plugin_javascript/src/runtime.rs +++ b/crates/rspack_plugin_javascript/src/runtime.rs @@ -514,7 +514,7 @@ fn render_runtime_context_fields( continue; } - let Some(key) = runtime_global.property_name() else { + let Some(key) = runtime_global.rspack_context_property_name() else { continue; }; let Some(lexical_name) = runtime_global.to_lexical_name() else { @@ -564,7 +564,7 @@ fn render_runtime_context_field_initializers( let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); for (_, runtime_global) in metadata.lexical_fields().iter_names() { - let Some(key) = runtime_global.property_name() else { + let Some(key) = runtime_global.rspack_context_property_name() else { continue; }; let Some(lexical_name) = runtime_global.to_lexical_name() else { diff --git a/packages/rspack/src/RuntimeGlobals.ts b/packages/rspack/src/RuntimeGlobals.ts index a61513b8e209..5eb4c697a95d 100644 --- a/packages/rspack/src/RuntimeGlobals.ts +++ b/packages/rspack/src/RuntimeGlobals.ts @@ -508,19 +508,26 @@ function renderRuntimeGlobals( runtimeGlobals: RuntimeGlobals, _compilerOptions?: RspackOptionsNormalized, ): string { - const scope_name = renderRuntimeVariables( + const require_name = renderRuntimeVariables( RuntimeVariable.Require, _compilerOptions, ); + const context_name = renderRuntimeVariables( + RuntimeVariable.Context, + _compilerOptions, + ); + const usesRuntimeContext = + _compilerOptions?.experiments.runtimeMode === 'rspack'; + const scope_name = usesRuntimeContext ? context_name : require_name; const exports_name = renderRuntimeVariables( RuntimeVariable.Exports, _compilerOptions, ); switch (runtimeGlobals) { case RuntimeGlobals.require: - return scope_name; + return usesRuntimeContext ? `${context_name}.r` : require_name; case RuntimeGlobals.requireScope: - return `${scope_name}.*`; + return usesRuntimeContext ? context_name : `${require_name}.*`; case RuntimeGlobals.exports: return exports_name; case RuntimeGlobals.thisAsExports: @@ -560,7 +567,7 @@ function renderRuntimeGlobals( case RuntimeGlobals.definePropertyGetters: return `${scope_name}.d`; case RuntimeGlobals.makeNamespaceObject: - return `${scope_name}.N`; + return usesRuntimeContext ? `${context_name}.N` : `${require_name}.r`; case RuntimeGlobals.createFakeNamespaceObject: return `${scope_name}.t`; case RuntimeGlobals.compatGetDefaultExport: diff --git a/tests/rspack-test/builtinCases/plugin-asset/asset-advanced/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/plugin-asset/asset-advanced/__snapshots__/output.snap.txt index e14d3e27cc89..1fd163ff020c 100644 --- a/tests/rspack-test/builtinCases/plugin-asset/asset-advanced/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/plugin-asset/asset-advanced/__snapshots__/output.snap.txt @@ -2,7 +2,7 @@ "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["main"], { "./index.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var _images_file_svg__rspack_import_0 = __webpack_require__("./images/file.svg"); diff --git a/tests/rspack-test/builtinCases/plugin-asset/asset-simple/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/plugin-asset/asset-simple/__snapshots__/output.snap.txt index 24b70de06821..ec459c433aa8 100644 --- a/tests/rspack-test/builtinCases/plugin-asset/asset-simple/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/plugin-asset/asset-simple/__snapshots__/output.snap.txt @@ -2,7 +2,7 @@ "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["main"], { "./index.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var _images_file_png__rspack_import_0 = __webpack_require__("./images/file.png"); /* import */ var _images_file_jpg__rspack_import_1 = __webpack_require__("./images/file.jpg"); /* import */ var _images_file_svg__rspack_import_2 = __webpack_require__("./images/file.svg"); diff --git a/tests/rspack-test/builtinCases/plugin-asset/asset-source/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/plugin-asset/asset-source/__snapshots__/output.snap.txt index 907e6de59b9d..45123c340db5 100644 --- a/tests/rspack-test/builtinCases/plugin-asset/asset-source/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/plugin-asset/asset-source/__snapshots__/output.snap.txt @@ -2,7 +2,7 @@ "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["main"], { "./index.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var _data_txt__rspack_import_0 = __webpack_require__("./data.txt"); diff --git a/tests/rspack-test/builtinCases/plugin-css-modules/modules-composes/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/plugin-css-modules/modules-composes/__snapshots__/output.snap.txt index 03451825d9b5..f7f485fd5b66 100644 --- a/tests/rspack-test/builtinCases/plugin-css-modules/modules-composes/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/plugin-css-modules/modules-composes/__snapshots__/output.snap.txt @@ -36,7 +36,7 @@ "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["main"], { "./index.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var _style_module_css__rspack_import_0 = __webpack_require__("./style.module.css"); @@ -48,7 +48,7 @@ var exports = { "b": "./_b.module_./_b--/__770815d283e5419e<770" + " " + "./_b.module_./_b-1--/__770815d283e5419e<770", }; -__webpack_require__.N(module.exports = exports); +__webpack_require__.r(module.exports = exports); }, @@ -58,7 +58,7 @@ var exports = { "d": "./_d.module_./_d--/__88281ab83c534746<882" + " " + "./_d.module_./_d-1--/__88281ab83c534746<882", }; -__webpack_require__.N(module.exports = exports); +__webpack_require__.r(module.exports = exports); }, @@ -68,7 +68,7 @@ var exports = { "f": "./_f.module_./_f--/__4abe9cc818c5f8e5<4ab" + " " + "./_f.module_./_f-1--/__4abe9cc818c5f8e5<4ab", }; -__webpack_require__.N(module.exports = exports); +__webpack_require__.r(module.exports = exports); }, @@ -79,7 +79,7 @@ var exports = { "root-class": "./_style.module_./_root-class--/__2f98424dcb9d6a7c<2f9" + " " + "./_style.module_./_chain1--/__2f98424dcb9d6a7c<2f9" + " " + "./_style.module_./_chain2--/__2f98424dcb9d6a7c<2f9" + " " + "e" + " " + __webpack_require__("./f.module.css")["f"] + " " + "c" + " " + __webpack_require__("./d.module.css")["d"] + " " + "a" + " " + __webpack_require__("./b.module.css")["b"], }; -__webpack_require__.N(module.exports = exports); +__webpack_require__.r(module.exports = exports); }, diff --git a/tests/rspack-test/builtinCases/plugin-css-modules/modules-ident-name/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/plugin-css-modules/modules-ident-name/__snapshots__/output.snap.txt index be91c1ce564d..f5d812664814 100644 --- a/tests/rspack-test/builtinCases/plugin-css-modules/modules-ident-name/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/plugin-css-modules/modules-ident-name/__snapshots__/output.snap.txt @@ -9,7 +9,7 @@ "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["main"], { "./index.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var _style_module_css__rspack_import_0 = __webpack_require__("./style.module.css"); @@ -22,7 +22,7 @@ var exports = { "foo": "./_style.module_./_foo--/__8a645abe7d001191<8a6", }; -__webpack_require__.N(module.exports = exports); +__webpack_require__.r(module.exports = exports); }, diff --git a/tests/rspack-test/builtinCases/plugin-javascript/builtins-define/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/plugin-javascript/builtins-define/__snapshots__/output.snap.txt index c2890bb4febb..978f57503e2e 100644 --- a/tests/rspack-test/builtinCases/plugin-javascript/builtins-define/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/plugin-javascript/builtins-define/__snapshots__/output.snap.txt @@ -2,7 +2,7 @@ "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["main"], { "./index.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var _lib__rspack_import_0 = __webpack_require__("./lib.js"); // import assert from "assert"; // import { equal } from "assert"; @@ -194,7 +194,7 @@ console.log(console.log(console.log)); }, "./lib.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { DO_NOT_CONVERTED7: () => (DO_NOT_CONVERTED7), DO_NOT_CONVERTED9: () => (DO_NOT_CONVERTED9), diff --git a/tests/rspack-test/builtinCases/plugin-javascript/hashbang/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/plugin-javascript/hashbang/__snapshots__/output.snap.txt index ed12a2c54d08..318b655fb043 100644 --- a/tests/rspack-test/builtinCases/plugin-javascript/hashbang/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/plugin-javascript/hashbang/__snapshots__/output.snap.txt @@ -2,7 +2,7 @@ "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["main"], { "./index.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var _lib__rspack_import_0 = __webpack_require__("./lib.js"); //#!/usr/bin/env node @@ -12,7 +12,7 @@ console.log("index", _lib__rspack_import_0.foo); }, "./lib.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { foo: () => (foo) }); diff --git a/tests/rspack-test/builtinCases/plugin-javascript/provide/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/plugin-javascript/provide/__snapshots__/output.snap.txt index 30dbd12dccaf..35830d690fb1 100644 --- a/tests/rspack-test/builtinCases/plugin-javascript/provide/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/plugin-javascript/provide/__snapshots__/output.snap.txt @@ -20,7 +20,7 @@ function a() { }, "./name.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/builtinCases/plugin-json/simple/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/plugin-json/simple/__snapshots__/output.snap.txt index 396f3c4e026a..5ca9a5f245b2 100644 --- a/tests/rspack-test/builtinCases/plugin-json/simple/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/plugin-json/simple/__snapshots__/output.snap.txt @@ -2,7 +2,7 @@ "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["main"], { "./index.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var _json_json__rspack_import_0 = __webpack_require__("./json.json"); /* import */ var _string_json__rspack_import_1 = __webpack_require__("./string.json"); diff --git a/tests/rspack-test/builtinCases/plugin-wasm/imports-multiple/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/plugin-wasm/imports-multiple/__snapshots__/output.snap.txt index 029241e0e02c..444a626bc9ab 100644 --- a/tests/rspack-test/builtinCases/plugin-wasm/imports-multiple/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/plugin-wasm/imports-multiple/__snapshots__/output.snap.txt @@ -23,7 +23,7 @@ var __webpack_exports__ = (__webpack_exec__("./index.js")); (self["rspackChunk"] = self["rspackChunk"] || []).push([["wasm_wasm"], { "./module.js"(module, __webpack_exports__, __webpack_require__) { __webpack_require__.a(module, async function (__rspack_load_async_deps, __rspack_async_done) { try { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { getNumber: () => (getNumber), result: () => (result) @@ -44,7 +44,7 @@ __rspack_async_done(); }, "./module2.js"(module, __webpack_exports__, __webpack_require__) { __webpack_require__.a(module, async function (__rspack_load_async_deps, __rspack_async_done) { try { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { getNumber: () => (getNumber) }); diff --git a/tests/rspack-test/builtinCases/plugin-wasm/v128/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/plugin-wasm/v128/__snapshots__/output.snap.txt index 8d1faf60bcd4..5f93060641b7 100644 --- a/tests/rspack-test/builtinCases/plugin-wasm/v128/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/plugin-wasm/v128/__snapshots__/output.snap.txt @@ -3,7 +3,7 @@ (self["rspackChunk"] = self["rspackChunk"] || []).push([["main"], { "./index.js"(module, __webpack_exports__, __webpack_require__) { __webpack_require__.a(module, async function (__rspack_load_async_deps, __rspack_async_done) { try { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var _v128_wasm__rspack_import_0 = __webpack_require__("./v128.wasm"); var __rspack_async_deps = __rspack_load_async_deps([_v128_wasm__rspack_import_0]); _v128_wasm__rspack_import_0 = (__rspack_async_deps.then ? (await __rspack_async_deps)() : __rspack_async_deps)[0]; diff --git a/tests/rspack-test/builtinCases/rspack/dynamic-import/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/rspack/dynamic-import/__snapshots__/output.snap.txt index 8072a83598ef..6f9dd11a0993 100644 --- a/tests/rspack-test/builtinCases/rspack/dynamic-import/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/rspack/dynamic-import/__snapshots__/output.snap.txt @@ -2,7 +2,7 @@ "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["child_a_js"], { "./child/a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { a: () => (a) }); @@ -18,7 +18,7 @@ const a = "a"; "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["child_b_js"], { "./child/b.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { b: () => (b) }); diff --git a/tests/rspack-test/builtinCases/rspack/static-import/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/rspack/static-import/__snapshots__/output.snap.txt index 98a5fa2c0ae6..405854b7a845 100644 --- a/tests/rspack-test/builtinCases/rspack/static-import/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/rspack/static-import/__snapshots__/output.snap.txt @@ -2,7 +2,7 @@ (self["rspackChunk"] = self["rspackChunk"] || []).push([["main"], { "./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var _b__rspack_import_0 = __webpack_require__("./b.js"); /* import */ var _b__rspack_import_0_default = /*#__PURE__*/__webpack_require__.n(_b__rspack_import_0); @@ -17,7 +17,7 @@ console.log("b"); }, "./index.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var _a__rspack_import_0 = __webpack_require__("./a.js"); console.log("hello, world"); diff --git a/tests/rspack-test/builtinCases/samples/ancestor-has-all-modules/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/samples/ancestor-has-all-modules/__snapshots__/output.snap.txt index 53713e788018..e1c53f1bfbde 100644 --- a/tests/rspack-test/builtinCases/samples/ancestor-has-all-modules/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/samples/ancestor-has-all-modules/__snapshots__/output.snap.txt @@ -50,7 +50,7 @@ __webpack_require__.e(/* import() */ "shared_js").then(__webpack_require__.bind( "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["shared_js"], { "./shared.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var _foo__rspack_import_0 = __webpack_require__("./foo.js"); /* import */ var _foo__rspack_import_0_default = /*#__PURE__*/__webpack_require__.n(_foo__rspack_import_0); // should not contain foo as ancestor already has diff --git a/tests/rspack-test/builtinCases/samples/cycle-dynamic-entry/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/samples/cycle-dynamic-entry/__snapshots__/output.snap.txt index 0171ee7d7bae..1893184effa5 100644 --- a/tests/rspack-test/builtinCases/samples/cycle-dynamic-entry/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/samples/cycle-dynamic-entry/__snapshots__/output.snap.txt @@ -2,7 +2,7 @@ "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["dynamic-1_js-_af6f0"], { "./dynamic-1.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var _shared__rspack_import_0 = __webpack_require__("./shared.js"); /* import */ var _shared__rspack_import_0_default = /*#__PURE__*/__webpack_require__.n(_shared__rspack_import_0); @@ -19,7 +19,7 @@ console.log("dynamic-1"); (self["rspackChunk"] = self["rspackChunk"] || []).push([["dynamic-1_js-_af6f1"], { "./dynamic-1.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var _shared__rspack_import_0 = __webpack_require__("./shared.js"); /* import */ var _shared__rspack_import_0_default = /*#__PURE__*/__webpack_require__.n(_shared__rspack_import_0); @@ -41,7 +41,7 @@ console.log("shared"); "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["dynamic-2_js-_89260"], { "./dynamic-2.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var _shared__rspack_import_0 = __webpack_require__("./shared.js"); /* import */ var _shared__rspack_import_0_default = /*#__PURE__*/__webpack_require__.n(_shared__rspack_import_0); @@ -58,7 +58,7 @@ console.log("dynamic-2"); (self["rspackChunk"] = self["rspackChunk"] || []).push([["dynamic-2_js-_89261"], { "./dynamic-2.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var _shared__rspack_import_0 = __webpack_require__("./shared.js"); /* import */ var _shared__rspack_import_0_default = /*#__PURE__*/__webpack_require__.n(_shared__rspack_import_0); diff --git a/tests/rspack-test/builtinCases/samples/cycle-entry/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/samples/cycle-entry/__snapshots__/output.snap.txt index a1f2e2b775ed..bb57a30d2a8d 100644 --- a/tests/rspack-test/builtinCases/samples/cycle-entry/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/samples/cycle-entry/__snapshots__/output.snap.txt @@ -2,7 +2,7 @@ (self["rspackChunk"] = self["rspackChunk"] || []).push([["index"], { "./index.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var _shared__rspack_import_0 = __webpack_require__("./shared.js"); /* import */ var _shared__rspack_import_0_default = /*#__PURE__*/__webpack_require__.n(_shared__rspack_import_0); Promise.resolve(/* import() */).then(__webpack_require__.bind(__webpack_require__, "./index.js")); @@ -55,7 +55,7 @@ var __webpack_exports__ = (__webpack_exec__("./index2.js")); "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["index_js"], { "./index.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var _shared__rspack_import_0 = __webpack_require__("./shared.js"); /* import */ var _shared__rspack_import_0_default = /*#__PURE__*/__webpack_require__.n(_shared__rspack_import_0); Promise.resolve(/* import() */).then(__webpack_require__.bind(__webpack_require__, "./index.js")); diff --git a/tests/rspack-test/builtinCases/samples/intersection/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/samples/intersection/__snapshots__/output.snap.txt index 8a450cbf615b..c9d00bd9d4dd 100644 --- a/tests/rspack-test/builtinCases/samples/intersection/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/samples/intersection/__snapshots__/output.snap.txt @@ -2,7 +2,7 @@ (self["rspackChunk"] = self["rspackChunk"] || []).push([["a_js-_62a90"], { "./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var _shared__rspack_import_0 = __webpack_require__("./shared.js"); /* import */ var _shared__rspack_import_0_default = /*#__PURE__*/__webpack_require__.n(_shared__rspack_import_0); /* import */ var _i_1__rspack_import_1 = __webpack_require__("./i-1.js"); @@ -29,7 +29,7 @@ console.log("i-1"); (self["rspackChunk"] = self["rspackChunk"] || []).push([["a_js-_62a91"], { "./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var _shared__rspack_import_0 = __webpack_require__("./shared.js"); /* import */ var _shared__rspack_import_0_default = /*#__PURE__*/__webpack_require__.n(_shared__rspack_import_0); /* import */ var _i_1__rspack_import_1 = __webpack_require__("./i-1.js"); diff --git a/tests/rspack-test/builtinCases/samples/parent-have-partial-module/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/samples/parent-have-partial-module/__snapshots__/output.snap.txt index 07487762ce37..8c28aa5f3f47 100644 --- a/tests/rspack-test/builtinCases/samples/parent-have-partial-module/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/samples/parent-have-partial-module/__snapshots__/output.snap.txt @@ -24,7 +24,7 @@ console.log("exist"); }, "./parent-1.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var _exist__rspack_import_0 = __webpack_require__("./exist.js"); /* import */ var _exist__rspack_import_0_default = /*#__PURE__*/__webpack_require__.n(_exist__rspack_import_0); @@ -56,7 +56,7 @@ console.log("exist"); }, "./shared.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var _exist__rspack_import_0 = __webpack_require__("./exist.js"); /* import */ var _exist__rspack_import_0_default = /*#__PURE__*/__webpack_require__.n(_exist__rspack_import_0); @@ -73,7 +73,7 @@ console.log("shared"); "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["shared_js-_38af1"], { "./shared.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var _exist__rspack_import_0 = __webpack_require__("./exist.js"); /* import */ var _exist__rspack_import_0_default = /*#__PURE__*/__webpack_require__.n(_exist__rspack_import_0); diff --git a/tests/rspack-test/builtinCases/samples/simple/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/samples/simple/__snapshots__/output.snap.txt index 61c4004fbe94..33205116a512 100644 --- a/tests/rspack-test/builtinCases/samples/simple/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/samples/simple/__snapshots__/output.snap.txt @@ -2,7 +2,7 @@ "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["a_js"], { "./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var _shared__rspack_import_0 = __webpack_require__("./shared.js"); /* import */ var _shared__rspack_import_0_default = /*#__PURE__*/__webpack_require__.n(_shared__rspack_import_0); diff --git a/tests/rspack-test/builtinCases/swc-loader/minify/__snapshots__/output.snap.txt b/tests/rspack-test/builtinCases/swc-loader/minify/__snapshots__/output.snap.txt index e2ed5ad04c91..38bd8b269161 100644 --- a/tests/rspack-test/builtinCases/swc-loader/minify/__snapshots__/output.snap.txt +++ b/tests/rspack-test/builtinCases/swc-loader/minify/__snapshots__/output.snap.txt @@ -2,7 +2,7 @@ "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["main"], { "./index.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { Button: () => (Button), button: () => (button) diff --git a/tests/rspack-test/configCases/externals/reexport-star/__snapshot__/case1.txt b/tests/rspack-test/configCases/externals/reexport-star/__snapshot__/case1.txt index 9358e17f1c01..407dbb44334f 100644 --- a/tests/rspack-test/configCases/externals/reexport-star/__snapshot__/case1.txt +++ b/tests/rspack-test/configCases/externals/reexport-star/__snapshot__/case1.txt @@ -4,7 +4,7 @@ import * as __rspack_external_external1_alias_bc4b12e4 from "external1-alias"; import * as __rspack_external_external2_alias_e5239a01 from "external2-alias"; __webpack_require__.add({ 42(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var external1__rspack_import_0 = __webpack_require__(322); /* reexport */ var __rspack_reexport = {}; diff --git a/tests/rspack-test/esmOutputCases/basic/export-shared-namespace/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/basic/export-shared-namespace/__snapshots__/esm.snap.txt index b6cda32c2aec..3897606dec7e 100644 --- a/tests/rspack-test/esmOutputCases/basic/export-shared-namespace/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/basic/export-shared-namespace/__snapshots__/esm.snap.txt @@ -40,7 +40,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } @@ -56,7 +56,7 @@ export { __webpack_require__ }; import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./shared.js var shared_namespaceObject = {}; -__webpack_require__.N(shared_namespaceObject); +__webpack_require__.r(shared_namespaceObject); __webpack_require__.d(shared_namespaceObject, { a: () => (a), b: () => (b) }); diff --git a/tests/rspack-test/esmOutputCases/basic/tree-shaking/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/basic/tree-shaking/__snapshots__/esm.snap.txt index 97e9de05a1c8..795a9ad3d9f9 100644 --- a/tests/rspack-test/esmOutputCases/basic/tree-shaking/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/basic/tree-shaking/__snapshots__/esm.snap.txt @@ -22,7 +22,7 @@ console.log.bind((__webpack_require__(/*! fs */ "fs")/* .readFile */.readFile)) !*** ./index.js ***! \******************/ (module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var _cjs__rspack_import_0 = __webpack_require__(/*! ./cjs */ "./cjs.js"); /* module decorator */ module = __webpack_require__.hmd(module); @@ -139,7 +139,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/basic/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/basic/__snapshots__/esm.snap.txt index c338664bf7c8..6df11ec9778d 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/basic/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/basic/__snapshots__/esm.snap.txt @@ -10,7 +10,7 @@ export default dynamic; import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./dynamic.js?1 var dynamic1_namespaceObject = {}; -__webpack_require__.N(dynamic1_namespaceObject); +__webpack_require__.r(dynamic1_namespaceObject); __webpack_require__.d(dynamic1_namespaceObject, { "default": () => (dynamic1) }); @@ -59,7 +59,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-conflict-exports/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-conflict-exports/__snapshots__/esm.snap.txt index d73e994ba5ba..409a485f4bb6 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-conflict-exports/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-conflict-exports/__snapshots__/esm.snap.txt @@ -2,14 +2,14 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./a.js var a_namespaceObject = {}; -__webpack_require__.N(a_namespaceObject); +__webpack_require__.r(a_namespaceObject); __webpack_require__.d(a_namespaceObject, { value: () => (value) }); // NAMESPACE OBJECT: ./b.js var b_namespaceObject = {}; -__webpack_require__.N(b_namespaceObject); +__webpack_require__.r(b_namespaceObject); __webpack_require__.d(b_namespaceObject, { value: () => (b_value) }); @@ -71,7 +71,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-mixed-chunks/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-mixed-chunks/__snapshots__/esm.snap.txt index 3f9c6c3295ac..968629ee6f95 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-mixed-chunks/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-mixed-chunks/__snapshots__/esm.snap.txt @@ -45,7 +45,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } @@ -61,7 +61,7 @@ export { __webpack_require__ }; import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./m1.js var m1_namespaceObject = {}; -__webpack_require__.N(m1_namespaceObject); +__webpack_require__.r(m1_namespaceObject); __webpack_require__.d(m1_namespaceObject, { "default": () => (m1), value: () => (value) }); @@ -69,7 +69,7 @@ __webpack_require__.d(m1_namespaceObject, { // NAMESPACE OBJECT: ./m2.js var m2_namespaceObject = {}; -__webpack_require__.N(m2_namespaceObject); +__webpack_require__.r(m2_namespaceObject); __webpack_require__.d(m2_namespaceObject, { "default": () => (m2), value: () => (m2_value) }); diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-module-external-namespace-default-named-collision/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-module-external-namespace-default-named-collision/__snapshots__/esm.snap.txt index bb85baec3964..364427e0e5f6 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-module-external-namespace-default-named-collision/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-module-external-namespace-default-named-collision/__snapshots__/esm.snap.txt @@ -46,7 +46,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } @@ -64,7 +64,7 @@ import foo_runtime, { foo } from "./foo-runtime.mjs"; // NAMESPACE OBJECT: ./a.js var a_namespaceObject = {}; -__webpack_require__.N(a_namespaceObject); +__webpack_require__.r(a_namespaceObject); __webpack_require__.d(a_namespaceObject, { "default": () => (a), shared: () => (shared) }); @@ -72,7 +72,7 @@ __webpack_require__.d(a_namespaceObject, { // NAMESPACE OBJECT: ./b.js var b_namespaceObject = {}; -__webpack_require__.N(b_namespaceObject); +__webpack_require__.r(b_namespaceObject); __webpack_require__.d(b_namespaceObject, { namedFoo: () => (foo), shared: () => (b_shared) }); diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-multi-module-duplicate-external/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-multi-module-duplicate-external/__snapshots__/esm.snap.txt index 0766be9eb6cd..e5a7102f279a 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-multi-module-duplicate-external/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-multi-module-duplicate-external/__snapshots__/esm.snap.txt @@ -39,7 +39,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } @@ -57,7 +57,7 @@ import fs, { readFile, readFileSync } from "fs"; // NAMESPACE OBJECT: ./a.js var a_namespaceObject = {}; -__webpack_require__.N(a_namespaceObject); +__webpack_require__.r(a_namespaceObject); __webpack_require__.d(a_namespaceObject, { fsDefault: () => (fs), readFile: () => (readFile), @@ -66,7 +66,7 @@ __webpack_require__.d(a_namespaceObject, { // NAMESPACE OBJECT: ./b.js var b_namespaceObject = {}; -__webpack_require__.N(b_namespaceObject); +__webpack_require__.r(b_namespaceObject); __webpack_require__.d(b_namespaceObject, { marker: () => (marker), readFile: () => (readFile) }); diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-multi-module-namespace-named-external/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-multi-module-namespace-named-external/__snapshots__/esm.snap.txt index a7ca0a39cf95..454b48ae094d 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-multi-module-namespace-named-external/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-multi-module-namespace-named-external/__snapshots__/esm.snap.txt @@ -39,7 +39,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } @@ -58,14 +58,14 @@ import { resolve } from "path"; // NAMESPACE OBJECT: ./a.js var a_namespaceObject = {}; -__webpack_require__.N(a_namespaceObject); +__webpack_require__.r(a_namespaceObject); __webpack_require__.d(a_namespaceObject, { resolve: () => (__rspack_external_path) }); // NAMESPACE OBJECT: ./b.js var b_namespaceObject = {}; -__webpack_require__.N(b_namespaceObject); +__webpack_require__.r(b_namespaceObject); __webpack_require__.d(b_namespaceObject, { marker: () => (marker), resolve: () => (resolve) }); diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-three-modules/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-three-modules/__snapshots__/esm.snap.txt index c8f47429da02..373fac6f7eee 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-three-modules/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-three-modules/__snapshots__/esm.snap.txt @@ -26,7 +26,7 @@ export {}; import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./a.js var a_namespaceObject = {}; -__webpack_require__.N(a_namespaceObject); +__webpack_require__.r(a_namespaceObject); __webpack_require__.d(a_namespaceObject, { "default": () => (a), id: () => (id), @@ -35,7 +35,7 @@ __webpack_require__.d(a_namespaceObject, { // NAMESPACE OBJECT: ./b.js var b_namespaceObject = {}; -__webpack_require__.N(b_namespaceObject); +__webpack_require__.r(b_namespaceObject); __webpack_require__.d(b_namespaceObject, { "default": () => (b), id: () => (b_id), @@ -44,7 +44,7 @@ __webpack_require__.d(b_namespaceObject, { // NAMESPACE OBJECT: ./c.js var c_namespaceObject = {}; -__webpack_require__.N(c_namespaceObject); +__webpack_require__.r(c_namespaceObject); __webpack_require__.d(c_namespaceObject, { "default": () => (c), id: () => (c_id), @@ -95,7 +95,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-treeshake-real-conflict/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-treeshake-real-conflict/__snapshots__/esm.snap.txt index 15944edfc209..5f82e4c57ad3 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-treeshake-real-conflict/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/dyn-import-treeshake-real-conflict/__snapshots__/esm.snap.txt @@ -41,7 +41,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } @@ -57,7 +57,7 @@ export { __webpack_require__ }; import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./a.js var a_namespaceObject = {}; -__webpack_require__.N(a_namespaceObject); +__webpack_require__.r(a_namespaceObject); __webpack_require__.d(a_namespaceObject, { foo: () => (foo), value: () => (value) }); @@ -65,7 +65,7 @@ __webpack_require__.d(a_namespaceObject, { // NAMESPACE OBJECT: ./b.js var b_namespaceObject = {}; -__webpack_require__.N(b_namespaceObject); +__webpack_require__.r(b_namespaceObject); __webpack_require__.d(b_namespaceObject, { bar: () => (bar), value: () => (b_value) }); diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/import-cjs-runtime-chunk-false-async-chunk/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/import-cjs-runtime-chunk-false-async-chunk/__snapshots__/esm.snap.txt index 695cf535c7ad..b0654021dfd7 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/import-cjs-runtime-chunk-false-async-chunk/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/import-cjs-runtime-chunk-false-async-chunk/__snapshots__/esm.snap.txt @@ -106,7 +106,7 @@ __webpack_require__.t = function(value, mode) { if((mode & 16) && typeof value.then === 'function') return value; } var ns = Object.create(null); - __webpack_require__.N(ns); + __webpack_require__.r(ns); var def = {}; leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)]; for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) { @@ -144,7 +144,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/import-cjs-runtime-chunk-false-entry-export/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/import-cjs-runtime-chunk-false-entry-export/__snapshots__/esm.snap.txt index eb41b5da194d..ff73c5a95463 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/import-cjs-runtime-chunk-false-entry-export/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/import-cjs-runtime-chunk-false-entry-export/__snapshots__/esm.snap.txt @@ -80,7 +80,7 @@ __webpack_require__.t = function(value, mode) { if((mode & 16) && typeof value.then === 'function') return value; } var ns = Object.create(null); - __webpack_require__.N(ns); + __webpack_require__.r(ns); var def = {}; leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)]; for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) { @@ -121,7 +121,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/import-cjs/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/import-cjs/__snapshots__/esm.snap.txt index 5ee4bb817391..31793d33af1d 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/import-cjs/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/import-cjs/__snapshots__/esm.snap.txt @@ -107,7 +107,7 @@ __webpack_require__.t = function(value, mode) { if((mode & 16) && typeof value.then === 'function') return value; } var ns = Object.create(null); - __webpack_require__.N(ns); + __webpack_require__.r(ns); var def = {}; leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)]; for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) { @@ -145,7 +145,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/import-context-css/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/import-context-css/__snapshots__/esm.snap.txt index 10dcaa64d447..a3fbdd7e047e 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/import-context-css/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/import-context-css/__snapshots__/esm.snap.txt @@ -18,7 +18,7 @@ __webpack_require__.add({ !*** ./modules/a.js ***! \**********************/ (__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* export default */ const __rspack_default_export = ("a"); @@ -195,7 +195,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/import-context-lazy/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/import-context-lazy/__snapshots__/esm.snap.txt index ea3a357383fd..340a24332838 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/import-context-lazy/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/import-context-lazy/__snapshots__/esm.snap.txt @@ -7,7 +7,7 @@ __webpack_require__.add({ !*** ./modules/a.js ***! \**********************/ (__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* export default */ const __rspack_default_export = ("a"); __webpack_require__.d(__webpack_exports__, { @@ -31,7 +31,7 @@ __webpack_require__.add({ !*** ./modules/b.js ***! \**********************/ (__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* export default */ const __rspack_default_export = ("b"); __webpack_require__.d(__webpack_exports__, { @@ -190,7 +190,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/import-context-multi-chunk/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/import-context-multi-chunk/__snapshots__/esm.snap.txt index f011bb269724..c089c17e118f 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/import-context-multi-chunk/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/import-context-multi-chunk/__snapshots__/esm.snap.txt @@ -8,7 +8,7 @@ __webpack_require__.add({ !*** ./modules/a.js ***! \**********************/ (__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var _shared__rspack_import_0 = __webpack_require__(/*! ../shared */ "./shared.js"); @@ -36,7 +36,7 @@ __webpack_require__.add({ !*** ./modules/b.js ***! \**********************/ (__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var _shared__rspack_import_0 = __webpack_require__(/*! ../shared */ "./shared.js"); @@ -197,7 +197,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/import-context-multi-entry/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/import-context-multi-entry/__snapshots__/esm.snap.txt index b3a69b1e9fd8..d80ac56ede7b 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/import-context-multi-entry/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/import-context-multi-entry/__snapshots__/esm.snap.txt @@ -7,7 +7,7 @@ __webpack_require__.add({ !*** ./modules-a/a.js ***! \************************/ (__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* export default */ const __rspack_default_export = ("a"); __webpack_require__.d(__webpack_exports__, { @@ -31,7 +31,7 @@ __webpack_require__.add({ !*** ./modules-b/b.js ***! \************************/ (__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* export default */ const __rspack_default_export = ("b"); __webpack_require__.d(__webpack_exports__, { @@ -182,7 +182,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } @@ -292,7 +292,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/import-context-prefetch-preload/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/import-context-prefetch-preload/__snapshots__/esm.snap.txt index 94f4155df652..e4a0cb8f878d 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/import-context-prefetch-preload/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/import-context-prefetch-preload/__snapshots__/esm.snap.txt @@ -7,7 +7,7 @@ __webpack_require__.add({ !*** ./modules/a.js ***! \**********************/ (__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* export default */ const __rspack_default_export = ("a"); __webpack_require__.d(__webpack_exports__, { @@ -30,7 +30,7 @@ __webpack_require__.add({ !*** ./modules/b.js ***! \**********************/ (__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); import("./c.mjs").then(__webpack_require__.bind(__webpack_require__, /*! ./c */ "./modules/c.js")); /* export default */ const __rspack_default_export = ("b"); @@ -55,7 +55,7 @@ __webpack_require__.add({ !*** ./modules/c.js ***! \**********************/ (__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* export default */ const __rspack_default_export = ("c"); __webpack_require__.d(__webpack_exports__, { @@ -282,7 +282,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/magic-comment/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/magic-comment/__snapshots__/esm.snap.txt index 326a36a5df4c..3d32640dc15c 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/magic-comment/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/magic-comment/__snapshots__/esm.snap.txt @@ -72,7 +72,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } @@ -88,7 +88,7 @@ export { __webpack_require__ }; import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./m1.js var m1_namespaceObject = {}; -__webpack_require__.N(m1_namespaceObject); +__webpack_require__.r(m1_namespaceObject); __webpack_require__.d(m1_namespaceObject, { "default": () => (m1), value: () => (value) }); @@ -96,7 +96,7 @@ __webpack_require__.d(m1_namespaceObject, { // NAMESPACE OBJECT: ./m2.js var m2_namespaceObject = {}; -__webpack_require__.N(m2_namespaceObject); +__webpack_require__.r(m2_namespaceObject); __webpack_require__.d(m2_namespaceObject, { "default": () => (m2), value: () => (m2_value) }); diff --git a/tests/rspack-test/esmOutputCases/externals/dynamic-import-commonjs-require-collision/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/externals/dynamic-import-commonjs-require-collision/__snapshots__/esm.snap.txt index e9cf2a79a4f2..319274e46092 100644 --- a/tests/rspack-test/esmOutputCases/externals/dynamic-import-commonjs-require-collision/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/externals/dynamic-import-commonjs-require-collision/__snapshots__/esm.snap.txt @@ -68,7 +68,7 @@ __webpack_require__.t = function(value, mode) { if((mode & 16) && typeof value.then === 'function') return value; } var ns = Object.create(null); - __webpack_require__.N(ns); + __webpack_require__.r(ns); var def = {}; leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)]; for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) { @@ -101,7 +101,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/externals/dynamic-import-node-commonjs-helper-collision/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/externals/dynamic-import-node-commonjs-helper-collision/__snapshots__/esm.snap.txt index 9cfbddd552a1..23648bd23b8a 100644 --- a/tests/rspack-test/esmOutputCases/externals/dynamic-import-node-commonjs-helper-collision/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/externals/dynamic-import-node-commonjs-helper-collision/__snapshots__/esm.snap.txt @@ -67,7 +67,7 @@ __webpack_require__.t = function(value, mode) { if((mode & 16) && typeof value.then === 'function') return value; } var ns = Object.create(null); - __webpack_require__.N(ns); + __webpack_require__.r(ns); var def = {}; leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)]; for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) { @@ -100,7 +100,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/externals/esm-node-target/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/externals/esm-node-target/__snapshots__/esm.snap.txt index 42c5a507b008..4194058628ba 100644 --- a/tests/rspack-test/esmOutputCases/externals/esm-node-target/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/externals/esm-node-target/__snapshots__/esm.snap.txt @@ -68,7 +68,7 @@ __webpack_require__.t = function(value, mode) { if((mode & 16) && typeof value.then === 'function') return value; } var ns = Object.create(null); - __webpack_require__.N(ns); + __webpack_require__.r(ns); var def = {}; leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)]; for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) { @@ -101,7 +101,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/externals/node-commonjs-export-namespace-as-with-named/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/externals/node-commonjs-export-namespace-as-with-named/__snapshots__/esm.snap.txt index 05edcd399fe9..20046c5bd39b 100644 --- a/tests/rspack-test/esmOutputCases/externals/node-commonjs-export-namespace-as-with-named/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/externals/node-commonjs-export-namespace-as-with-named/__snapshots__/esm.snap.txt @@ -66,7 +66,7 @@ __webpack_require__.t = function(value, mode) { if((mode & 16) && typeof value.then === 'function') return value; } var ns = Object.create(null); - __webpack_require__.N(ns); + __webpack_require__.r(ns); var def = {}; leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)]; for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) { @@ -99,7 +99,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/externals/node-commonjs-import-namespace-reexport-with-named/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/externals/node-commonjs-import-namespace-reexport-with-named/__snapshots__/esm.snap.txt index e669ef654ba9..59a99d53c300 100644 --- a/tests/rspack-test/esmOutputCases/externals/node-commonjs-import-namespace-reexport-with-named/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/externals/node-commonjs-import-namespace-reexport-with-named/__snapshots__/esm.snap.txt @@ -68,7 +68,7 @@ __webpack_require__.t = function(value, mode) { if((mode & 16) && typeof value.then === 'function') return value; } var ns = Object.create(null); - __webpack_require__.N(ns); + __webpack_require__.r(ns); var def = {}; leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)]; for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) { @@ -101,7 +101,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/externals/node-commonjs-namespace-name-collision-across-modules/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/externals/node-commonjs-namespace-name-collision-across-modules/__snapshots__/esm.snap.txt index 0511891015f5..7814a8e5cbb4 100644 --- a/tests/rspack-test/esmOutputCases/externals/node-commonjs-namespace-name-collision-across-modules/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/externals/node-commonjs-namespace-name-collision-across-modules/__snapshots__/esm.snap.txt @@ -82,7 +82,7 @@ __webpack_require__.t = function(value, mode) { if((mode & 16) && typeof value.then === 'function') return value; } var ns = Object.create(null); - __webpack_require__.N(ns); + __webpack_require__.r(ns); var def = {}; leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)]; for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) { @@ -115,7 +115,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/externals/node-commonjs-wrapper-namespace-reexport/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/externals/node-commonjs-wrapper-namespace-reexport/__snapshots__/esm.snap.txt index a88a2be55df1..e61942bc88e3 100644 --- a/tests/rspack-test/esmOutputCases/externals/node-commonjs-wrapper-namespace-reexport/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/externals/node-commonjs-wrapper-namespace-reexport/__snapshots__/esm.snap.txt @@ -5,7 +5,7 @@ import { createRequire as __rspack_createRequire } from "node:module"; const __rspack_createRequire_require = __rspack_createRequire(import.meta.url); // NAMESPACE OBJECT: ./exports.js var exports_namespaceObject = {}; -__webpack_require__.N(exports_namespaceObject); +__webpack_require__.r(exports_namespaceObject); __webpack_require__.d(exports_namespaceObject, { sources: () => (index_js_namespaceObject) }); @@ -75,7 +75,7 @@ __webpack_require__.t = function(value, mode) { if((mode & 16) && typeof value.then === 'function') return value; } var ns = Object.create(null); - __webpack_require__.N(ns); + __webpack_require__.r(ns); var def = {}; leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)]; for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) { @@ -108,7 +108,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/externals/reexport-star-as-namespace-via-module-with-own-export/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/externals/reexport-star-as-namespace-via-module-with-own-export/__snapshots__/esm.snap.txt index a0689c71a824..9f62ec88a555 100644 --- a/tests/rspack-test/esmOutputCases/externals/reexport-star-as-namespace-via-module-with-own-export/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/externals/reexport-star-as-namespace-via-module-with-own-export/__snapshots__/esm.snap.txt @@ -4,7 +4,7 @@ import * as __rspack_external_fs from "fs"; // NAMESPACE OBJECT: ./reexport-external.js var reexport_external_namespaceObject = {}; -__webpack_require__.N(reexport_external_namespaceObject); +__webpack_require__.r(reexport_external_namespaceObject); __webpack_require__.d(reexport_external_namespaceObject, { marker: () => (marker), readFile: () => (readFile) }); @@ -64,7 +64,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/externals/reexport-star-as-namespace-via-module/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/externals/reexport-star-as-namespace-via-module/__snapshots__/esm.snap.txt index d7a2242e9cd8..b35f0fbdc542 100644 --- a/tests/rspack-test/esmOutputCases/externals/reexport-star-as-namespace-via-module/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/externals/reexport-star-as-namespace-via-module/__snapshots__/esm.snap.txt @@ -4,7 +4,7 @@ import * as __rspack_external_fs from "fs"; // NAMESPACE OBJECT: ./reexport-external.js var reexport_external_namespaceObject = {}; -__webpack_require__.N(reexport_external_namespaceObject); +__webpack_require__.r(reexport_external_namespaceObject); var reexport_external_namespaceObject_starExports = __rspack_external_fs; Object.keys(reexport_external_namespaceObject_starExports).forEach(function(key) { if (key !== "default" && key !== "__esModule") { @@ -57,7 +57,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/interop/namespace-import-asset/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/interop/namespace-import-asset/__snapshots__/esm.snap.txt index ab7ad6c09610..f4accf591a62 100644 --- a/tests/rspack-test/esmOutputCases/interop/namespace-import-asset/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/interop/namespace-import-asset/__snapshots__/esm.snap.txt @@ -57,7 +57,7 @@ __webpack_require__.t = function(value, mode) { if((mode & 16) && typeof value.then === 'function') return value; } var ns = Object.create(null); - __webpack_require__.N(ns); + __webpack_require__.r(ns); var def = {}; leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)]; for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) { @@ -90,7 +90,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/basic-capture/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/basic-capture/__snapshots__/esm.snap.txt index 3533c5a903b9..afcdf4901e5c 100644 --- a/tests/rspack-test/esmOutputCases/namespace/basic-capture/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/basic-capture/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./foo.js var foo_namespaceObject = {}; -__webpack_require__.N(foo_namespaceObject); +__webpack_require__.r(foo_namespaceObject); __webpack_require__.d(foo_namespaceObject, { foo: () => (foo) }); @@ -50,7 +50,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/basic-cjs-capture/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/basic-cjs-capture/__snapshots__/esm.snap.txt index 17c31bcaab59..7be631a83870 100644 --- a/tests/rspack-test/esmOutputCases/namespace/basic-cjs-capture/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/basic-cjs-capture/__snapshots__/esm.snap.txt @@ -72,7 +72,7 @@ __webpack_require__.t = function(value, mode) { if((mode & 16) && typeof value.then === 'function') return value; } var ns = Object.create(null); - __webpack_require__.N(ns); + __webpack_require__.r(ns); var def = {}; leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)]; for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) { @@ -110,7 +110,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/default-only-object/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/default-only-object/__snapshots__/esm.snap.txt index 7b3847669452..92d614fa8ee7 100644 --- a/tests/rspack-test/esmOutputCases/namespace/default-only-object/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/default-only-object/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./dep.js var dep_namespaceObject = {}; -__webpack_require__.N(dep_namespaceObject); +__webpack_require__.r(dep_namespaceObject); __webpack_require__.d(dep_namespaceObject, { "default": () => (dep) }); @@ -52,7 +52,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/empty-modules-default-property/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/empty-modules-default-property/__snapshots__/esm.snap.txt index 7c3718fbc2fd..862d4372a60a 100644 --- a/tests/rspack-test/esmOutputCases/namespace/empty-modules-default-property/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/empty-modules-default-property/__snapshots__/esm.snap.txt @@ -14,12 +14,12 @@ __webpack_require__.add({ }); // NAMESPACE OBJECT: ./empty.js var empty_namespaceObject = {}; -__webpack_require__.N(empty_namespaceObject); +__webpack_require__.r(empty_namespaceObject); // NAMESPACE OBJECT: ./empty.mjs var empty_namespaceObject_0 = {}; -__webpack_require__.N(empty_namespaceObject_0); +__webpack_require__.r(empty_namespaceObject_0); // ./empty.js @@ -108,7 +108,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/empty-modules-missing-property/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/empty-modules-missing-property/__snapshots__/esm.snap.txt index f1b2d9eff470..376395f2b030 100644 --- a/tests/rspack-test/esmOutputCases/namespace/empty-modules-missing-property/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/empty-modules-missing-property/__snapshots__/esm.snap.txt @@ -14,12 +14,12 @@ __webpack_require__.add({ }); // NAMESPACE OBJECT: ./empty.js var empty_namespaceObject = {}; -__webpack_require__.N(empty_namespaceObject); +__webpack_require__.r(empty_namespaceObject); // NAMESPACE OBJECT: ./empty.mjs var empty_namespaceObject_0 = {}; -__webpack_require__.N(empty_namespaceObject_0); +__webpack_require__.r(empty_namespaceObject_0); // ./empty.js @@ -77,7 +77,7 @@ __webpack_require__.add = function registerModules(modules) { Object.assign(__we // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/export-namespace-as-cjs/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/export-namespace-as-cjs/__snapshots__/esm.snap.txt index 57ffd5734d3c..945c6ce0db51 100644 --- a/tests/rspack-test/esmOutputCases/namespace/export-namespace-as-cjs/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/export-namespace-as-cjs/__snapshots__/esm.snap.txt @@ -71,7 +71,7 @@ __webpack_require__.t = function(value, mode) { if((mode & 16) && typeof value.then === 'function') return value; } var ns = Object.create(null); - __webpack_require__.N(ns); + __webpack_require__.r(ns); var def = {}; leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)]; for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) { @@ -109,7 +109,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/export-namespace-as/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/export-namespace-as/__snapshots__/esm.snap.txt index 36634cea1a60..596307da2b5c 100644 --- a/tests/rspack-test/esmOutputCases/namespace/export-namespace-as/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/export-namespace-as/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./dep.js var dep_namespaceObject = {}; -__webpack_require__.N(dep_namespaceObject); +__webpack_require__.r(dep_namespaceObject); __webpack_require__.d(dep_namespaceObject, { bar: () => (bar), foo: () => (foo) }); @@ -51,7 +51,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/export-self-as-namespace/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/export-self-as-namespace/__snapshots__/esm.snap.txt index 69410a42d66a..f84d4abac44a 100644 --- a/tests/rspack-test/esmOutputCases/namespace/export-self-as-namespace/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/export-self-as-namespace/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./index.js var index_namespaceObject = {}; -__webpack_require__.N(index_namespaceObject); +__webpack_require__.r(index_namespaceObject); __webpack_require__.d(index_namespaceObject, { foo: () => (foo), ns: () => (index_namespaceObject) }); @@ -48,7 +48,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/import-export-namespace-as-cjs/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/import-export-namespace-as-cjs/__snapshots__/esm.snap.txt index 363e46158a18..165f1361fd52 100644 --- a/tests/rspack-test/esmOutputCases/namespace/import-export-namespace-as-cjs/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/import-export-namespace-as-cjs/__snapshots__/esm.snap.txt @@ -72,7 +72,7 @@ __webpack_require__.t = function(value, mode) { if((mode & 16) && typeof value.then === 'function') return value; } var ns = Object.create(null); - __webpack_require__.N(ns); + __webpack_require__.r(ns); var def = {}; leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)]; for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) { @@ -110,7 +110,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/import-export-namespace-as/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/import-export-namespace-as/__snapshots__/esm.snap.txt index 429780aec396..83cf329ca6bc 100644 --- a/tests/rspack-test/esmOutputCases/namespace/import-export-namespace-as/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/import-export-namespace-as/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./foo.js var foo_namespaceObject = {}; -__webpack_require__.N(foo_namespaceObject); +__webpack_require__.r(foo_namespaceObject); __webpack_require__.d(foo_namespaceObject, { foo: () => (foo) }); @@ -50,7 +50,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/import-export-self-as-namespace/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/import-export-self-as-namespace/__snapshots__/esm.snap.txt index f2dca57ec672..a341fff9f81a 100644 --- a/tests/rspack-test/esmOutputCases/namespace/import-export-self-as-namespace/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/import-export-self-as-namespace/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./index.js var index_namespaceObject = {}; -__webpack_require__.N(index_namespaceObject); +__webpack_require__.r(index_namespaceObject); __webpack_require__.d(index_namespaceObject, { foo: () => (foo), ns: () => (index_namespaceObject) }); @@ -51,7 +51,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/import-of-export-namespace-as-capture/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/import-of-export-namespace-as-capture/__snapshots__/esm.snap.txt index f3d7e0029164..cc5cf0ae074f 100644 --- a/tests/rspack-test/esmOutputCases/namespace/import-of-export-namespace-as-capture/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/import-of-export-namespace-as-capture/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./foo.js var foo_namespaceObject = {}; -__webpack_require__.N(foo_namespaceObject); +__webpack_require__.r(foo_namespaceObject); __webpack_require__.d(foo_namespaceObject, { foo: () => (foo) }); @@ -50,7 +50,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/import-of-export-star-as/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/import-of-export-star-as/__snapshots__/esm.snap.txt index b9dd7cb04a20..90027ba871e6 100644 --- a/tests/rspack-test/esmOutputCases/namespace/import-of-export-star-as/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/import-of-export-star-as/__snapshots__/esm.snap.txt @@ -2,14 +2,14 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./bar.js var bar_namespaceObject = {}; -__webpack_require__.N(bar_namespaceObject); +__webpack_require__.r(bar_namespaceObject); __webpack_require__.d(bar_namespaceObject, { bar: () => (bar) }); // NAMESPACE OBJECT: ./foo.js var foo_namespaceObject = {}; -__webpack_require__.N(foo_namespaceObject); +__webpack_require__.r(foo_namespaceObject); __webpack_require__.d(foo_namespaceObject, { barNs: () => (bar_namespaceObject) }); @@ -60,7 +60,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/import-of-re-export-star-capture/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/import-of-re-export-star-capture/__snapshots__/esm.snap.txt index f9b0c312b65e..aa4f12b1bf20 100644 --- a/tests/rspack-test/esmOutputCases/namespace/import-of-re-export-star-capture/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/import-of-re-export-star-capture/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./bar.js var bar_namespaceObject = {}; -__webpack_require__.N(bar_namespaceObject); +__webpack_require__.r(bar_namespaceObject); __webpack_require__.d(bar_namespaceObject, { foo: () => ((/* inlined export .foo */123)) }); @@ -50,7 +50,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/missing-export-capture/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/missing-export-capture/__snapshots__/esm.snap.txt index f84130fea637..97d14d36fbdc 100644 --- a/tests/rspack-test/esmOutputCases/namespace/missing-export-capture/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/missing-export-capture/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./foo.js var foo_namespaceObject = {}; -__webpack_require__.N(foo_namespaceObject); +__webpack_require__.r(foo_namespaceObject); __webpack_require__.d(foo_namespaceObject, { x: () => (x) }); @@ -48,7 +48,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/missing-export-cjs-capture/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/missing-export-cjs-capture/__snapshots__/esm.snap.txt index bbfcc043c046..58c7a3b45d78 100644 --- a/tests/rspack-test/esmOutputCases/namespace/missing-export-cjs-capture/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/missing-export-cjs-capture/__snapshots__/esm.snap.txt @@ -70,7 +70,7 @@ __webpack_require__.t = function(value, mode) { if((mode & 16) && typeof value.then === 'function') return value; } var ns = Object.create(null); - __webpack_require__.N(ns); + __webpack_require__.r(ns); var def = {}; leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)]; for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) { @@ -108,7 +108,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/missing-export-no-capture/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/missing-export-no-capture/__snapshots__/esm.snap.txt index 6b9e28dc6b67..6c4f18ff7bfc 100644 --- a/tests/rspack-test/esmOutputCases/namespace/missing-export-no-capture/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/missing-export-no-capture/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./foo.js var foo_namespaceObject = {}; -__webpack_require__.N(foo_namespaceObject); +__webpack_require__.r(foo_namespaceObject); // ./foo.js @@ -27,7 +27,7 @@ var __webpack_require__ = {}; // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/no-treeshake-object/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/no-treeshake-object/__snapshots__/esm.snap.txt index 83f80d4b49e8..6d71686ef6e4 100644 --- a/tests/rspack-test/esmOutputCases/namespace/no-treeshake-object/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/no-treeshake-object/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./namespace.js var namespace_namespaceObject = {}; -__webpack_require__.N(namespace_namespaceObject); +__webpack_require__.r(namespace_namespaceObject); __webpack_require__.d(namespace_namespaceObject, { foo: () => (foo) }); @@ -59,7 +59,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/optimization-in-operator/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/optimization-in-operator/__snapshots__/esm.snap.txt index fad04277fc59..de73fbc559cd 100644 --- a/tests/rspack-test/esmOutputCases/namespace/optimization-in-operator/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/optimization-in-operator/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./foo.js var foo_namespaceObject = {}; -__webpack_require__.N(foo_namespaceObject); +__webpack_require__.r(foo_namespaceObject); __webpack_require__.d(foo_namespaceObject, { c: () => (c) }); @@ -64,7 +64,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/optional-chaining/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/optional-chaining/__snapshots__/esm.snap.txt index 3a7154625f3b..52e298fdb4fa 100644 --- a/tests/rspack-test/esmOutputCases/namespace/optional-chaining/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/optional-chaining/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./util.js var util_namespaceObject = {}; -__webpack_require__.N(util_namespaceObject); +__webpack_require__.r(util_namespaceObject); __webpack_require__.d(util_namespaceObject, { foo: () => (foo) }); @@ -56,7 +56,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/re-export-named-missing-export-capture/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/re-export-named-missing-export-capture/__snapshots__/esm.snap.txt index 261c5e155064..a14c5095ff3f 100644 --- a/tests/rspack-test/esmOutputCases/namespace/re-export-named-missing-export-capture/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/re-export-named-missing-export-capture/__snapshots__/esm.snap.txt @@ -2,12 +2,12 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./bar.js var bar_namespaceObject = {}; -__webpack_require__.N(bar_namespaceObject); +__webpack_require__.r(bar_namespaceObject); // NAMESPACE OBJECT: ./foo.js var foo_namespaceObject = {}; -__webpack_require__.N(foo_namespaceObject); +__webpack_require__.r(foo_namespaceObject); __webpack_require__.d(foo_namespaceObject, { foo: () => (bar_namespaceObject.foo) }); @@ -55,7 +55,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/re-export-named-missing-export-no-capture/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/re-export-named-missing-export-no-capture/__snapshots__/esm.snap.txt index 8e64efffebc9..fbae118e52d0 100644 --- a/tests/rspack-test/esmOutputCases/namespace/re-export-named-missing-export-no-capture/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/re-export-named-missing-export-no-capture/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./bar.js var bar_namespaceObject = {}; -__webpack_require__.N(bar_namespaceObject); +__webpack_require__.r(bar_namespaceObject); // ./bar.js @@ -26,7 +26,7 @@ var __webpack_require__ = {}; // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/re-export-namespace-missing-export-capture/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/re-export-namespace-missing-export-capture/__snapshots__/esm.snap.txt index 5c79e64868ee..3dcd4233d448 100644 --- a/tests/rspack-test/esmOutputCases/namespace/re-export-namespace-missing-export-capture/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/re-export-namespace-missing-export-capture/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./bar.js var bar_namespaceObject = {}; -__webpack_require__.N(bar_namespaceObject); +__webpack_require__.r(bar_namespaceObject); __webpack_require__.d(bar_namespaceObject, { x: () => (x) }); @@ -48,7 +48,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/re-export-namespace-missing-export-no-capture/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/re-export-namespace-missing-export-no-capture/__snapshots__/esm.snap.txt index a84a152a562f..3bc167049844 100644 --- a/tests/rspack-test/esmOutputCases/namespace/re-export-namespace-missing-export-no-capture/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/re-export-namespace-missing-export-no-capture/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./bar.js var bar_namespaceObject = {}; -__webpack_require__.N(bar_namespaceObject); +__webpack_require__.r(bar_namespaceObject); // ./bar.js @@ -27,7 +27,7 @@ var __webpack_require__ = {}; // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/re-export-self-as-namespace/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/re-export-self-as-namespace/__snapshots__/esm.snap.txt index 658839d75081..c914e6b8b321 100644 --- a/tests/rspack-test/esmOutputCases/namespace/re-export-self-as-namespace/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/re-export-self-as-namespace/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./foo.js var foo_namespaceObject = {}; -__webpack_require__.N(foo_namespaceObject); +__webpack_require__.r(foo_namespaceObject); __webpack_require__.d(foo_namespaceObject, { foo: () => (foo), ns: () => (foo_namespaceObject) }); @@ -51,7 +51,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/re-export-self-import-export-as-namespace/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/re-export-self-import-export-as-namespace/__snapshots__/esm.snap.txt index 46e684ee3d5a..bcf619f0bacc 100644 --- a/tests/rspack-test/esmOutputCases/namespace/re-export-self-import-export-as-namespace/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/re-export-self-import-export-as-namespace/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./foo.js var foo_namespaceObject = {}; -__webpack_require__.N(foo_namespaceObject); +__webpack_require__.r(foo_namespaceObject); __webpack_require__.d(foo_namespaceObject, { foo: () => (foo), ns: () => (foo_namespaceObject) }); @@ -54,7 +54,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/re-export-star-missing-export-capture/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/re-export-star-missing-export-capture/__snapshots__/esm.snap.txt index cf52e77d45d4..611b95e4a212 100644 --- a/tests/rspack-test/esmOutputCases/namespace/re-export-star-missing-export-capture/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/re-export-star-missing-export-capture/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./foo.js var foo_namespaceObject = {}; -__webpack_require__.N(foo_namespaceObject); +__webpack_require__.r(foo_namespaceObject); __webpack_require__.d(foo_namespaceObject, { x: () => ((/* inlined export .x */123)) }); @@ -48,7 +48,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/re-export-star-missing-export-no-capture/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/re-export-star-missing-export-no-capture/__snapshots__/esm.snap.txt index acdc26d2ac64..92772b4ffad7 100644 --- a/tests/rspack-test/esmOutputCases/namespace/re-export-star-missing-export-no-capture/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/re-export-star-missing-export-no-capture/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./foo.js var foo_namespaceObject = {}; -__webpack_require__.N(foo_namespaceObject); +__webpack_require__.r(foo_namespaceObject); // ./foo.js @@ -27,7 +27,7 @@ var __webpack_require__ = {}; // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/re-export-star/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/re-export-star/__snapshots__/esm.snap.txt index a72c1da08b01..c1d6bdf71567 100644 --- a/tests/rspack-test/esmOutputCases/namespace/re-export-star/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/re-export-star/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./foo.js var foo_namespaceObject = {}; -__webpack_require__.N(foo_namespaceObject); +__webpack_require__.r(foo_namespaceObject); __webpack_require__.d(foo_namespaceObject, { foo1: () => (foo1), foo2: () => (foo2) }); @@ -58,7 +58,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/reexport-self-cycle/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/reexport-self-cycle/__snapshots__/esm.snap.txt index bbbd256d80de..89e3b7c3909d 100644 --- a/tests/rspack-test/esmOutputCases/namespace/reexport-self-cycle/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/reexport-self-cycle/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./other.js var other_namespaceObject = {}; -__webpack_require__.N(other_namespaceObject); +__webpack_require__.r(other_namespaceObject); __webpack_require__.d(other_namespaceObject, { bar: () => (bar), foo: () => (foo), @@ -57,7 +57,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/self-import-cycle/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/self-import-cycle/__snapshots__/esm.snap.txt index c9740be61b81..9b208ef39c34 100644 --- a/tests/rspack-test/esmOutputCases/namespace/self-import-cycle/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/self-import-cycle/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./index.js var index_namespaceObject = {}; -__webpack_require__.N(index_namespaceObject); +__webpack_require__.r(index_namespaceObject); __webpack_require__.d(index_namespaceObject, { keys: () => (keys), p: () => (p) }); @@ -53,7 +53,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/side-effect-free-modules-default-property/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/side-effect-free-modules-default-property/__snapshots__/esm.snap.txt index 3968d9a36415..b2de1821083e 100644 --- a/tests/rspack-test/esmOutputCases/namespace/side-effect-free-modules-default-property/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/side-effect-free-modules-default-property/__snapshots__/esm.snap.txt @@ -14,12 +14,12 @@ console.log("cjs"); }); // NAMESPACE OBJECT: ./foo/no-side-effects.js var no_side_effects_namespaceObject = {}; -__webpack_require__.N(no_side_effects_namespaceObject); +__webpack_require__.r(no_side_effects_namespaceObject); // NAMESPACE OBJECT: ./foo/no-side-effects.mjs var foo_no_side_effects_namespaceObject = {}; -__webpack_require__.N(foo_no_side_effects_namespaceObject); +__webpack_require__.r(foo_no_side_effects_namespaceObject); // ./foo/no-side-effects.js @@ -108,7 +108,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/side-effect-free-modules-missing-property/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/side-effect-free-modules-missing-property/__snapshots__/esm.snap.txt index 916aedf26c2d..d1e3d49a54cb 100644 --- a/tests/rspack-test/esmOutputCases/namespace/side-effect-free-modules-missing-property/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/side-effect-free-modules-missing-property/__snapshots__/esm.snap.txt @@ -14,12 +14,12 @@ console.log("cjs"); }); // NAMESPACE OBJECT: ./foo/no-side-effects.js var no_side_effects_namespaceObject = {}; -__webpack_require__.N(no_side_effects_namespaceObject); +__webpack_require__.r(no_side_effects_namespaceObject); // NAMESPACE OBJECT: ./foo/no-side-effects.mjs var foo_no_side_effects_namespaceObject = {}; -__webpack_require__.N(foo_no_side_effects_namespaceObject); +__webpack_require__.r(foo_no_side_effects_namespaceObject); // ./foo/no-side-effects.js @@ -77,7 +77,7 @@ __webpack_require__.add = function registerModules(modules) { Object.assign(__we // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/star-export-as-namespace-cjs/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/star-export-as-namespace-cjs/__snapshots__/esm.snap.txt index 8075fc218195..849b7bc07775 100644 --- a/tests/rspack-test/esmOutputCases/namespace/star-export-as-namespace-cjs/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/star-export-as-namespace-cjs/__snapshots__/esm.snap.txt @@ -76,7 +76,7 @@ __webpack_require__.t = function(value, mode) { if((mode & 16) && typeof value.then === 'function') return value; } var ns = Object.create(null); - __webpack_require__.N(ns); + __webpack_require__.r(ns); var def = {}; leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)]; for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) { @@ -114,7 +114,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/star-export-as-namespace/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/star-export-as-namespace/__snapshots__/esm.snap.txt index ffb0239bfcd7..c877fba10bad 100644 --- a/tests/rspack-test/esmOutputCases/namespace/star-export-as-namespace/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/star-export-as-namespace/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./foo.js var foo_namespaceObject = {}; -__webpack_require__.N(foo_namespaceObject); +__webpack_require__.r(foo_namespaceObject); __webpack_require__.d(foo_namespaceObject, { foo: () => (foo) }); @@ -50,7 +50,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/tostring-inlined-namespace/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/tostring-inlined-namespace/__snapshots__/esm.snap.txt index bda98581e964..263bf5859dc2 100644 --- a/tests/rspack-test/esmOutputCases/namespace/tostring-inlined-namespace/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/tostring-inlined-namespace/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./foo.js var foo_namespaceObject = {}; -__webpack_require__.N(foo_namespaceObject); +__webpack_require__.r(foo_namespaceObject); __webpack_require__.d(foo_namespaceObject, { bar: () => (bar) }); @@ -58,7 +58,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/namespace/tostring-static-resolution/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/tostring-static-resolution/__snapshots__/esm.snap.txt index 71ab1bfcabfc..0d11949586ad 100644 --- a/tests/rspack-test/esmOutputCases/namespace/tostring-static-resolution/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/tostring-static-resolution/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./foo.js var foo_namespaceObject = {}; -__webpack_require__.N(foo_namespaceObject); +__webpack_require__.r(foo_namespaceObject); __webpack_require__.d(foo_namespaceObject, { bar: () => (bar) }); @@ -50,7 +50,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/preserve-modules/namespace-object-bare-import/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/preserve-modules/namespace-object-bare-import/__snapshots__/esm.snap.txt index 245b45d368f1..2603bca0071c 100644 --- a/tests/rspack-test/esmOutputCases/preserve-modules/namespace-object-bare-import/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/preserve-modules/namespace-object-bare-import/__snapshots__/esm.snap.txt @@ -13,7 +13,7 @@ import { types_namespaceObject } from "./types.mjs"; // NAMESPACE OBJECT: ./src/rules/duplicate-package/index.js var duplicate_package_namespaceObject = {}; -__webpack_require__.N(duplicate_package_namespaceObject); +__webpack_require__.r(duplicate_package_namespaceObject); __webpack_require__.d(duplicate_package_namespaceObject, { value: () => (value) }); @@ -33,7 +33,7 @@ export { duplicate_package_namespaceObject as duplicatePackage, value }; import { __webpack_require__ } from "../../runtime.mjs"; // NAMESPACE OBJECT: ./src/rules/duplicate-package/types.js var types_namespaceObject = {}; -__webpack_require__.N(types_namespaceObject); +__webpack_require__.r(types_namespaceObject); __webpack_require__.d(types_namespaceObject, { J: () => (CheckVersionMap) }); @@ -72,7 +72,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/re-exports/cjs-entry/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/re-exports/cjs-entry/__snapshots__/esm.snap.txt index b9d002f6258c..7e4870d5f459 100644 --- a/tests/rspack-test/esmOutputCases/re-exports/cjs-entry/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/re-exports/cjs-entry/__snapshots__/esm.snap.txt @@ -16,7 +16,7 @@ exports.bar = 2 !*** ./foo.js ***! \****************/ (__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var _bar__rspack_import_0 = __webpack_require__(/*! ./bar */ "./bar.js"); const foo = 1 @@ -106,7 +106,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/re-exports/deep-re-export-external/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/re-exports/deep-re-export-external/__snapshots__/esm.snap.txt index 4d2e69ea8ab3..a4b9c30ecbfc 100644 --- a/tests/rspack-test/esmOutputCases/re-exports/deep-re-export-external/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/re-exports/deep-re-export-external/__snapshots__/esm.snap.txt @@ -4,7 +4,7 @@ import * as __rspack_external_fs from "fs"; // NAMESPACE OBJECT: ./externals.js var externals_namespaceObject = {}; -__webpack_require__.N(externals_namespaceObject); +__webpack_require__.r(externals_namespaceObject); __webpack_require__.d(externals_namespaceObject, { "default": () => (__rspack_external_fs["default"]), readFile: () => (__rspack_external_fs.readFile) }); @@ -71,7 +71,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/re-exports/deep-re-exports-esm-2/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/re-exports/deep-re-exports-esm-2/__snapshots__/esm.snap.txt index 6f407742334a..50e9015f824b 100644 --- a/tests/rspack-test/esmOutputCases/re-exports/deep-re-exports-esm-2/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/re-exports/deep-re-exports-esm-2/__snapshots__/esm.snap.txt @@ -9,7 +9,7 @@ __webpack_require__.add({ !*** ./lib.js ***! \****************/ (__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var fs__rspack_import_0 = __webpack_require__(/*! fs */ "fs"); /* reexport */ var __rspack_reexport = {}; @@ -38,7 +38,7 @@ __webpack_require__.d(__webpack_exports__, { !*** ./lib2.js ***! \*****************/ (__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var path__rspack_import_0 = __webpack_require__(/*! path */ "path"); /* reexport */ var __rspack_reexport = {}; @@ -179,7 +179,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/re-exports/default-namespace-external/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/re-exports/default-namespace-external/__snapshots__/esm.snap.txt index 655ca21b45db..0344b866e7c9 100644 --- a/tests/rspack-test/esmOutputCases/re-exports/default-namespace-external/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/re-exports/default-namespace-external/__snapshots__/esm.snap.txt @@ -4,7 +4,7 @@ import fs, * as __rspack_external_fs from "fs"; // NAMESPACE OBJECT: ./file.js var file_namespaceObject = {}; -__webpack_require__.N(file_namespaceObject); +__webpack_require__.r(file_namespaceObject); __webpack_require__.d(file_namespaceObject, { fsNs: () => (__rspack_external_fs), value: () => (value) }); @@ -55,7 +55,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/re-exports/default-re-export-external/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/re-exports/default-re-export-external/__snapshots__/esm.snap.txt index 1542606d3273..df6c42329ead 100644 --- a/tests/rspack-test/esmOutputCases/re-exports/default-re-export-external/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/re-exports/default-re-export-external/__snapshots__/esm.snap.txt @@ -4,7 +4,7 @@ import fs from "fs"; // NAMESPACE OBJECT: ./file.js var file_namespaceObject = {}; -__webpack_require__.N(file_namespaceObject); +__webpack_require__.r(file_namespaceObject); __webpack_require__.d(file_namespaceObject, { fsDefault: () => (fs), value: () => (value) }); @@ -55,7 +55,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/re-exports/string-export-star-as-namespace/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/re-exports/string-export-star-as-namespace/__snapshots__/esm.snap.txt index e599bac4d89a..8b3906caf2ce 100644 --- a/tests/rspack-test/esmOutputCases/re-exports/string-export-star-as-namespace/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/re-exports/string-export-star-as-namespace/__snapshots__/esm.snap.txt @@ -2,7 +2,7 @@ import { __webpack_require__ } from "./runtime.mjs"; // NAMESPACE OBJECT: ./foo.js var foo_namespaceObject = {}; -__webpack_require__.N(foo_namespaceObject); +__webpack_require__.r(foo_namespaceObject); __webpack_require__.d(foo_namespaceObject, { named: () => (named), "some import": () => (someImport) }); @@ -55,7 +55,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/esmOutputCases/re-exports/wrapped-esm-entry/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/re-exports/wrapped-esm-entry/__snapshots__/esm.snap.txt index b81d5991c327..bd259b995d67 100644 --- a/tests/rspack-test/esmOutputCases/re-exports/wrapped-esm-entry/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/re-exports/wrapped-esm-entry/__snapshots__/esm.snap.txt @@ -8,7 +8,7 @@ __webpack_require__.add({ !*** ./index.js ***! \******************/ (module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var fs__rspack_import_0 = __webpack_require__(/*! fs */ "fs"); /* reexport */ var __rspack_reexport = {}; @@ -137,7 +137,7 @@ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj // webpack/runtime/make_namespace_object (() => { // define __esModule on exports -__webpack_require__.N = (exports) => { +__webpack_require__.r = (exports) => { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); } diff --git a/tests/rspack-test/hotCases/asset/parser-and-generator-states/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/asset/parser-and-generator-states/__snapshots__/web/1.snap.txt index 5337becbd0c9..b59a819df8b9 100644 --- a/tests/rspack-test/hotCases/asset/parser-and-generator-states/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/asset/parser-and-generator-states/__snapshots__/web/1.snap.txt @@ -35,7 +35,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/child-compiler/issue-9706/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/child-compiler/issue-9706/__snapshots__/web/1.snap.txt index b195e415026a..47f2a34e4315 100644 --- a/tests/rspack-test/hotCases/child-compiler/issue-9706/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/child-compiler/issue-9706/__snapshots__/web/1.snap.txt @@ -34,7 +34,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./report-child-assets-loader.js!./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { assets: () => (assets), "default": () => (__rspack_default_export) diff --git a/tests/rspack-test/hotCases/chunk/accept-system-import-webpackhot/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/chunk/accept-system-import-webpackhot/__snapshots__/web/1.snap.txt index 47627d3c4076..af809b99a5d7 100644 --- a/tests/rspack-test/hotCases/chunk/accept-system-import-webpackhot/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/chunk/accept-system-import-webpackhot/__snapshots__/web/1.snap.txt @@ -37,7 +37,7 @@ "use strict"; self["rspackHotUpdate"]("chunk2_js", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); @@ -64,7 +64,7 @@ var value = 2; "use strict"; self["rspackHotUpdate"]("chunk_js", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); diff --git a/tests/rspack-test/hotCases/chunk/accept-system-import/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/chunk/accept-system-import/__snapshots__/web/1.snap.txt index 5c58841c2c97..fee6553025ba 100644 --- a/tests/rspack-test/hotCases/chunk/accept-system-import/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/chunk/accept-system-import/__snapshots__/web/1.snap.txt @@ -37,7 +37,7 @@ "use strict"; self["rspackHotUpdate"]("chunk2_js", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); @@ -64,7 +64,7 @@ var value = 2; "use strict"; self["rspackHotUpdate"]("chunk_js", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); diff --git a/tests/rspack-test/hotCases/chunk/ensure-chunk-change-to-promise-all/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/chunk/ensure-chunk-change-to-promise-all/__snapshots__/web/1.snap.txt index e2a837b19ba1..a3b5282936f6 100644 --- a/tests/rspack-test/hotCases/chunk/ensure-chunk-change-to-promise-all/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/chunk/ensure-chunk-change-to-promise-all/__snapshots__/web/1.snap.txt @@ -36,7 +36,7 @@ "use strict"; self["rspackHotUpdate"]("file_js", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { Vue: () => (/* reexport safe */ vue__rspack_import_0.Vue) }); @@ -64,7 +64,7 @@ __webpack_require__.d(__webpack_exports__, { "use strict"; self["rspackHotUpdate"]("main", { "./chunk.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { test: () => (test) }); diff --git a/tests/rspack-test/hotCases/chunks/dynamic-system-import/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/chunks/dynamic-system-import/__snapshots__/web/1.snap.txt index cad487eb38f6..8356237ff00f 100644 --- a/tests/rspack-test/hotCases/chunks/dynamic-system-import/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/chunks/dynamic-system-import/__snapshots__/web/1.snap.txt @@ -37,7 +37,7 @@ "use strict"; self["rspackHotUpdate"]("chunk1_js", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); @@ -64,7 +64,7 @@ var value = 2; "use strict"; self["rspackHotUpdate"]("chunk2_js", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); diff --git a/tests/rspack-test/hotCases/chunks/system-import/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/chunks/system-import/__snapshots__/web/1.snap.txt index 4c3bf4d03a3f..51dda2e77611 100644 --- a/tests/rspack-test/hotCases/chunks/system-import/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/chunks/system-import/__snapshots__/web/1.snap.txt @@ -39,7 +39,7 @@ "use strict"; self["rspackHotUpdate"]("chunk2_js", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); @@ -48,7 +48,7 @@ var value = 2; }, "./file2.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); @@ -76,7 +76,7 @@ var value = 4; "use strict"; self["rspackHotUpdate"]("chunk_js", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); @@ -85,7 +85,7 @@ var value = 2; }, "./file2.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); diff --git a/tests/rspack-test/hotCases/chunks/update-chunk-loading-runtime/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/chunks/update-chunk-loading-runtime/__snapshots__/web/1.snap.txt index 4270c277e939..f626fe70eaec 100644 --- a/tests/rspack-test/hotCases/chunks/update-chunk-loading-runtime/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/chunks/update-chunk-loading-runtime/__snapshots__/web/1.snap.txt @@ -39,7 +39,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./index.js"(module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var vendor__rspack_import_0 = __webpack_require__("./node_modules/vendor.js"); module.hot.data.ok = true; @@ -736,7 +736,7 @@ chunkLoadingGlobal.push = __rspack_jsonp.bind(null, chunkLoadingGlobal.push.bind "use strict"; self["rspackHotUpdate"]("vendors-node_modules_vendor_js", { "./node_modules/vendor.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/code-generation/this-in-accept-webpackhot/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/code-generation/this-in-accept-webpackhot/__snapshots__/web/1.snap.txt index 8c60e6ddb136..edb294a08a16 100644 --- a/tests/rspack-test/hotCases/code-generation/this-in-accept-webpackhot/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/code-generation/this-in-accept-webpackhot/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/code-generation/this-in-accept/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/code-generation/this-in-accept/__snapshots__/web/1.snap.txt index d17527953612..7336ca158f23 100644 --- a/tests/rspack-test/hotCases/code-generation/this-in-accept/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/code-generation/this-in-accept/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/concat/reload-compat-flag/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/concat/reload-compat-flag/__snapshots__/web/1.snap.txt index 0b30072f0233..e78810515ca0 100644 --- a/tests/rspack-test/hotCases/concat/reload-compat-flag/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/concat/reload-compat-flag/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"](889, { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* export default */ const __rspack_default_export = ("ok2"); diff --git a/tests/rspack-test/hotCases/concat/reload-external/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/concat/reload-external/__snapshots__/web/1.snap.txt index f1e3d5597c38..e0548f6b9b00 100644 --- a/tests/rspack-test/hotCases/concat/reload-external/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/concat/reload-external/__snapshots__/web/1.snap.txt @@ -34,7 +34,7 @@ "use strict"; self["rspackHotUpdate"](889, { "./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* export default */ const __rspack_default_export = (2); __webpack_require__.d(__webpack_exports__, { diff --git a/tests/rspack-test/hotCases/concat/reload-external/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/concat/reload-external/__snapshots__/web/2.snap.txt index 3fd0eb94a9e6..c64b775e994b 100644 --- a/tests/rspack-test/hotCases/concat/reload-external/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/concat/reload-external/__snapshots__/web/2.snap.txt @@ -34,7 +34,7 @@ "use strict"; self["rspackHotUpdate"](889, { "./b.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* export default */ const __rspack_default_export = (20); __webpack_require__.d(__webpack_exports__, { diff --git a/tests/rspack-test/hotCases/conditional-runtime/accept-conditional/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/conditional-runtime/accept-conditional/__snapshots__/web/1.snap.txt index 9f063a8cca3e..01b130b37c3b 100644 --- a/tests/rspack-test/hotCases/conditional-runtime/accept-conditional/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/conditional-runtime/accept-conditional/__snapshots__/web/1.snap.txt @@ -47,7 +47,7 @@ "use strict"; self["rspackHotUpdate"]("dep1_js-dep2_js-worker_js", { "./dep1.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -81,7 +81,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("dep1_js-module_js", { "./dep1.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/context/request-position/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/context/request-position/__snapshots__/web/1.snap.txt index f164bb6c40af..83e07d2ce9f4 100644 --- a/tests/rspack-test/hotCases/context/request-position/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/context/request-position/__snapshots__/web/1.snap.txt @@ -35,7 +35,7 @@ self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { fn: () => (fn) }); diff --git a/tests/rspack-test/hotCases/css/css-extract/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/css/css-extract/__snapshots__/web/1.snap.txt index 6adaf747259a..8600f20e99ad 100644 --- a/tests/rspack-test/hotCases/css/css-extract/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/css/css-extract/__snapshots__/web/1.snap.txt @@ -34,7 +34,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./entry.js"(module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -47,7 +47,7 @@ module.hot.accept(); }, "./index.module.css"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/css/css-loading-unique-name/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/css/css-loading-unique-name/__snapshots__/web/1.snap.txt index b898777557bf..18739651fdee 100644 --- a/tests/rspack-test/hotCases/css/css-loading-unique-name/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/css/css-loading-unique-name/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdatecss_test"]("main", { "./index.css"(module, __unused_rspack_exports, __webpack_require__) { -__webpack_require__.N(module.exports = {}); +__webpack_require__.r(module.exports = {}); module.hot.accept(); diff --git a/tests/rspack-test/hotCases/css/css-modules-style/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/css/css-modules-style/__snapshots__/web/1.snap.txt index bf25e6dfb768..17c9114605de 100644 --- a/tests/rspack-test/hotCases/css/css-modules-style/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/css/css-modules-style/__snapshots__/web/1.snap.txt @@ -44,7 +44,7 @@ if (module.hot.data && module.hot.data.exports && module.hot.data.exports != str module.hot.accept(); } module.hot.dispose(function(data) { data.exports = stringified_exports; }); -__webpack_require__.N(module.exports = exports); +__webpack_require__.r(module.exports = exports); }, diff --git a/tests/rspack-test/hotCases/css/css-modules/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/css/css-modules/__snapshots__/web/1.snap.txt index 26e37dda2465..b75e17851d74 100644 --- a/tests/rspack-test/hotCases/css/css-modules/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/css/css-modules/__snapshots__/web/1.snap.txt @@ -47,7 +47,7 @@ if (module.hot.data && module.hot.data.exports && module.hot.data.exports != str module.hot.accept(); } module.hot.dispose(function(data) { data.exports = stringified_exports; }); -__webpack_require__.N(module.exports = exports); +__webpack_require__.r(module.exports = exports); }, @@ -88,7 +88,7 @@ if (module.hot.data && module.hot.data.exports && module.hot.data.exports != str module.hot.accept(); } module.hot.dispose(function(data) { data.exports = stringified_exports; }); -__webpack_require__.N(module.exports = exports); +__webpack_require__.r(module.exports = exports); }, diff --git a/tests/rspack-test/hotCases/css/fetch-priority/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/css/fetch-priority/__snapshots__/web/1.snap.txt index 2153198e7f24..f90e067d1571 100644 --- a/tests/rspack-test/hotCases/css/fetch-priority/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/css/fetch-priority/__snapshots__/web/1.snap.txt @@ -69,7 +69,7 @@ if (module.hot.data && module.hot.data.exports && module.hot.data.exports != str module.hot.accept(); } module.hot.dispose(function(data) { data.exports = stringified_exports; }); -__webpack_require__.N(module.exports = exports); +__webpack_require__.r(module.exports = exports); }, diff --git a/tests/rspack-test/hotCases/css/parser-and-generator-states/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/css/parser-and-generator-states/__snapshots__/web/1.snap.txt index 6fdec685638e..c2450f3472c3 100644 --- a/tests/rspack-test/hotCases/css/parser-and-generator-states/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/css/parser-and-generator-states/__snapshots__/web/1.snap.txt @@ -45,7 +45,7 @@ if (module.hot.data && module.hot.data.exports && module.hot.data.exports != str module.hot.accept(); } module.hot.dispose(function(data) { data.exports = stringified_exports; }); -__webpack_require__.N(module.exports = exports); +__webpack_require__.r(module.exports = exports); }, diff --git a/tests/rspack-test/hotCases/css/recovery-cacheable/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/css/recovery-cacheable/__snapshots__/web/2.snap.txt index 61322204c2ce..56801c282e5e 100644 --- a/tests/rspack-test/hotCases/css/recovery-cacheable/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/css/recovery-cacheable/__snapshots__/web/2.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./change.css"(module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); // extracted by css-extract-rspack-plugin if(true) { diff --git a/tests/rspack-test/hotCases/css/recovery/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/css/recovery/__snapshots__/web/2.snap.txt index 4338ccdb63fb..c95656f6c6eb 100644 --- a/tests/rspack-test/hotCases/css/recovery/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/css/recovery/__snapshots__/web/2.snap.txt @@ -35,7 +35,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./index.css"(module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); // extracted by css-extract-rspack-plugin if(true) { @@ -62,7 +62,7 @@ __webpack_require__.N(__webpack_exports__); }, "../../../../../../../../packages/rspack/dist/cssExtractHmr.js"(__unused_rspack___webpack_module__, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { cssReload: () => (cssReload), normalizeUrl: () => (normalizeUrl) diff --git a/tests/rspack-test/hotCases/css/vanilla/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/css/vanilla/__snapshots__/web/1.snap.txt index 132a3027056b..8ee7497fb818 100644 --- a/tests/rspack-test/hotCases/css/vanilla/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/css/vanilla/__snapshots__/web/1.snap.txt @@ -59,7 +59,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("style2_css", { "./style2.css"(module, __unused_rspack_exports, __webpack_require__) { -__webpack_require__.N(module.exports = {}); +__webpack_require__.r(module.exports = {}); module.hot.accept(); diff --git a/tests/rspack-test/hotCases/define/issue-6962/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/define/issue-6962/__snapshots__/web/1.snap.txt index cf05eb65101a..796cbaff1561 100644 --- a/tests/rspack-test/hotCases/define/issue-6962/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/define/issue-6962/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./a.js"(module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/determinism/issue-10174/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/determinism/issue-10174/__snapshots__/web/1.snap.txt index e1dd4bdee2b0..f6116503b25a 100644 --- a/tests/rspack-test/hotCases/determinism/issue-10174/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/determinism/issue-10174/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./hot.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/disposing/remove-chunk-with-shared-in-other-runtime/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/disposing/remove-chunk-with-shared-in-other-runtime/__snapshots__/web/1.snap.txt index 4665b78df46e..319df2ac163e 100644 --- a/tests/rspack-test/hotCases/disposing/remove-chunk-with-shared-in-other-runtime/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/disposing/remove-chunk-with-shared-in-other-runtime/__snapshots__/web/1.snap.txt @@ -44,7 +44,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/disposing/remove-chunk-with-shared/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/disposing/remove-chunk-with-shared/__snapshots__/web/1.snap.txt index ec6883477444..c36de5f50f49 100644 --- a/tests/rspack-test/hotCases/disposing/remove-chunk-with-shared/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/disposing/remove-chunk-with-shared/__snapshots__/web/1.snap.txt @@ -34,7 +34,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/disposing/runtime-independent-filename/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/disposing/runtime-independent-filename/__snapshots__/web/1.snap.txt index fbfd171b4022..9f87a93e5aae 100644 --- a/tests/rspack-test/hotCases/disposing/runtime-independent-filename/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/disposing/runtime-independent-filename/__snapshots__/web/1.snap.txt @@ -28,7 +28,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/errors/decline-webpackhot/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/errors/decline-webpackhot/__snapshots__/web/1.snap.txt index b13dc0ecf29a..f6fc526d35b8 100644 --- a/tests/rspack-test/hotCases/errors/decline-webpackhot/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/errors/decline-webpackhot/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./c.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/errors/decline/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/errors/decline/__snapshots__/web/1.snap.txt index eb7c0803062b..68d04e7abc15 100644 --- a/tests/rspack-test/hotCases/errors/decline/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/errors/decline/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./c.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/errors/events/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/errors/events/__snapshots__/web/1.snap.txt index dda13ea51dad..affe56e0e5b8 100644 --- a/tests/rspack-test/hotCases/errors/events/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/errors/events/__snapshots__/web/1.snap.txt @@ -45,7 +45,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -54,7 +54,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./c.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -63,7 +63,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./e.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -72,7 +72,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./g.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -81,7 +81,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./i.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -91,7 +91,7 @@ throw new Error("Error while loading module i"); }, "./j.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -101,7 +101,7 @@ throw new Error("Error while loading module j"); }, "./l.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/errors/self-decline/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/errors/self-decline/__snapshots__/web/1.snap.txt index d33191404372..f8cac2b8edf7 100644 --- a/tests/rspack-test/hotCases/errors/self-decline/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/errors/self-decline/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./c.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/errors/unaccepted-ignored/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/errors/unaccepted-ignored/__snapshots__/web/1.snap.txt index 17e51db573c9..c2358d9f3df2 100644 --- a/tests/rspack-test/hotCases/errors/unaccepted-ignored/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/errors/unaccepted-ignored/__snapshots__/web/1.snap.txt @@ -34,7 +34,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/errors/unaccepted-ignored/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/errors/unaccepted-ignored/__snapshots__/web/2.snap.txt index a94ba109e7a1..c04441d9d9aa 100644 --- a/tests/rspack-test/hotCases/errors/unaccepted-ignored/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/errors/unaccepted-ignored/__snapshots__/web/2.snap.txt @@ -34,7 +34,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./c.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/errors/unaccepted-ignored/__snapshots__/web/3.snap.txt b/tests/rspack-test/hotCases/errors/unaccepted-ignored/__snapshots__/web/3.snap.txt index e6699ea3a823..b7807c676785 100644 --- a/tests/rspack-test/hotCases/errors/unaccepted-ignored/__snapshots__/web/3.snap.txt +++ b/tests/rspack-test/hotCases/errors/unaccepted-ignored/__snapshots__/web/3.snap.txt @@ -35,7 +35,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -44,7 +44,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./c.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/errors/unaccepted/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/errors/unaccepted/__snapshots__/web/1.snap.txt index 1f9a3ec1225c..afabf4d162c8 100644 --- a/tests/rspack-test/hotCases/errors/unaccepted/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/errors/unaccepted/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./c.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/esm-dependency-import/import-meta-webpack-hot/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/esm-dependency-import/import-meta-webpack-hot/__snapshots__/web/1.snap.txt index 1ce154684349..0fd8877f42ee 100644 --- a/tests/rspack-test/hotCases/esm-dependency-import/import-meta-webpack-hot/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/esm-dependency-import/import-meta-webpack-hot/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./node_modules/dep1/file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); diff --git a/tests/rspack-test/hotCases/esm-dependency-import/module-hot/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/esm-dependency-import/module-hot/__snapshots__/web/1.snap.txt index 802da8febee4..37d4a1d5853a 100644 --- a/tests/rspack-test/hotCases/esm-dependency-import/module-hot/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/esm-dependency-import/module-hot/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./node_modules/dep1/file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); diff --git a/tests/rspack-test/hotCases/harmony/auto-import-multiple/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/harmony/auto-import-multiple/__snapshots__/web/1.snap.txt index dd2f26757de2..1d99468fc835 100644 --- a/tests/rspack-test/hotCases/harmony/auto-import-multiple/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/harmony/auto-import-multiple/__snapshots__/web/1.snap.txt @@ -40,7 +40,7 @@ module.exports = 20; }, "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); diff --git a/tests/rspack-test/hotCases/harmony/auto-import/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/harmony/auto-import/__snapshots__/web/1.snap.txt index 738331ef8fe0..d2c2f741f468 100644 --- a/tests/rspack-test/hotCases/harmony/auto-import/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/harmony/auto-import/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); diff --git a/tests/rspack-test/hotCases/harmony/auto-reexport/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/harmony/auto-reexport/__snapshots__/web/1.snap.txt index 7931312d0837..e50d89aff7c8 100644 --- a/tests/rspack-test/hotCases/harmony/auto-reexport/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/harmony/auto-reexport/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); diff --git a/tests/rspack-test/hotCases/harmony/cjs-analyze-changed/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/harmony/cjs-analyze-changed/__snapshots__/web/1.snap.txt index 716557390e59..9cf01db39f74 100644 --- a/tests/rspack-test/hotCases/harmony/cjs-analyze-changed/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/harmony/cjs-analyze-changed/__snapshots__/web/1.snap.txt @@ -40,7 +40,7 @@ exports["default"] = 1; }, "./reexport.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/hash/hot-index/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/hash/hot-index/__snapshots__/web/1.snap.txt index 2af9dbb31a19..da678a8a5209 100644 --- a/tests/rspack-test/hotCases/hash/hot-index/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/hash/hot-index/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/hash/hot-index/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/hash/hot-index/__snapshots__/web/2.snap.txt index 8a0e78a0bac4..255bcf92aa0e 100644 --- a/tests/rspack-test/hotCases/hash/hot-index/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/hash/hot-index/__snapshots__/web/2.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/hash/hot-index/__snapshots__/web/3.snap.txt b/tests/rspack-test/hotCases/hash/hot-index/__snapshots__/web/3.snap.txt index d31b35849959..3eb28c0ef6df 100644 --- a/tests/rspack-test/hotCases/hash/hot-index/__snapshots__/web/3.snap.txt +++ b/tests/rspack-test/hotCases/hash/hot-index/__snapshots__/web/3.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/hashing/exports-info-influence/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/hashing/exports-info-influence/__snapshots__/web/1.snap.txt index c0bfd3cc65dd..00fbfdd17c5e 100644 --- a/tests/rspack-test/hotCases/hashing/exports-info-influence/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/hashing/exports-info-influence/__snapshots__/web/1.snap.txt @@ -34,7 +34,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./referencer.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/hashing/full-hash-main/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/hashing/full-hash-main/__snapshots__/web/1.snap.txt index 5ee360171992..ed5147db3f1f 100644 --- a/tests/rspack-test/hotCases/hashing/full-hash-main/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/hashing/full-hash-main/__snapshots__/web/1.snap.txt @@ -58,7 +58,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("thing_js", { "./thing.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/lazy-compilation/context/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/lazy-compilation/context/__snapshots__/web/1.snap.txt index 65a8b356d2c1..0af46084e063 100644 --- a/tests/rspack-test/hotCases/lazy-compilation/context/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/lazy-compilation/context/__snapshots__/web/1.snap.txt @@ -37,7 +37,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./generation.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/lazy-compilation/context/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/lazy-compilation/context/__snapshots__/web/2.snap.txt index 1f42b87993f0..805615647779 100644 --- a/tests/rspack-test/hotCases/lazy-compilation/context/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/lazy-compilation/context/__snapshots__/web/2.snap.txt @@ -38,7 +38,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./generation.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/lazy-compilation/unrelated/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/lazy-compilation/unrelated/__snapshots__/web/1.snap.txt index c56fca3c3e5a..717bd9c25aca 100644 --- a/tests/rspack-test/hotCases/lazy-compilation/unrelated/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/lazy-compilation/unrelated/__snapshots__/web/1.snap.txt @@ -34,7 +34,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/lazy-compilation/unrelated/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/lazy-compilation/unrelated/__snapshots__/web/2.snap.txt index 6640a5f9f140..68260c439247 100644 --- a/tests/rspack-test/hotCases/lazy-compilation/unrelated/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/lazy-compilation/unrelated/__snapshots__/web/2.snap.txt @@ -34,7 +34,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/loader/import-module-1/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/loader/import-module-1/__snapshots__/web/1.snap.txt index 01864eb49793..06daa81a1e46 100644 --- a/tests/rspack-test/hotCases/loader/import-module-1/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/loader/import-module-1/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./loader.js!./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/make/clean-isolated-cycle/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/make/clean-isolated-cycle/__snapshots__/web/1.snap.txt index 3f0b26b9d014..fdfafb3e71e9 100644 --- a/tests/rspack-test/hotCases/make/clean-isolated-cycle/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/make/clean-isolated-cycle/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/make/clean-isolated-cycle/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/make/clean-isolated-cycle/__snapshots__/web/2.snap.txt index 2756f8407bdb..9e5bf2ed1350 100644 --- a/tests/rspack-test/hotCases/make/clean-isolated-cycle/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/make/clean-isolated-cycle/__snapshots__/web/2.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/make/clean-isolated-cycle/__snapshots__/web/3.snap.txt b/tests/rspack-test/hotCases/make/clean-isolated-cycle/__snapshots__/web/3.snap.txt index 2e3b5187fd3e..701b0423212d 100644 --- a/tests/rspack-test/hotCases/make/clean-isolated-cycle/__snapshots__/web/3.snap.txt +++ b/tests/rspack-test/hotCases/make/clean-isolated-cycle/__snapshots__/web/3.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/make/clean-isolated-module/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/make/clean-isolated-module/__snapshots__/web/1.snap.txt index 3d7c719f3841..2c682b168106 100644 --- a/tests/rspack-test/hotCases/make/clean-isolated-module/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/make/clean-isolated-module/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/make/fix-issuer/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/make/fix-issuer/__snapshots__/web/1.snap.txt index e13b694ac38e..02fbaa7176a4 100644 --- a/tests/rspack-test/hotCases/make/fix-issuer/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/make/fix-issuer/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/make/issue-10915/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/make/issue-10915/__snapshots__/web/1.snap.txt index 94061621783f..2af1a5a047fc 100644 --- a/tests/rspack-test/hotCases/make/issue-10915/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/make/issue-10915/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/make/rebuild-abnormal-module/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/make/rebuild-abnormal-module/__snapshots__/web/2.snap.txt index 098f213ce718..b040b2910952 100644 --- a/tests/rspack-test/hotCases/make/rebuild-abnormal-module/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/make/rebuild-abnormal-module/__snapshots__/web/2.snap.txt @@ -34,7 +34,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -43,7 +43,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./loader.js!./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/module-graph/import-order-change/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/module-graph/import-order-change/__snapshots__/web/1.snap.txt index 9cfd26e3ae29..98d68fee5d90 100644 --- a/tests/rspack-test/hotCases/module-graph/import-order-change/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/module-graph/import-order-change/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./change.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var _b_css__rspack_import_0 = __webpack_require__("./b.css"); /* import */ var _a_css__rspack_import_1 = __webpack_require__("./a.css"); diff --git a/tests/rspack-test/hotCases/module/build-info/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/module/build-info/__snapshots__/web/1.snap.txt index b8f093006b62..fbb675cb472f 100644 --- a/tests/rspack-test/hotCases/module/build-info/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/module/build-info/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./loader.js!./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/newTreeshaking/auto-reexport/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/newTreeshaking/auto-reexport/__snapshots__/web/1.snap.txt index 7931312d0837..e50d89aff7c8 100644 --- a/tests/rspack-test/hotCases/newTreeshaking/auto-reexport/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/newTreeshaking/auto-reexport/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); diff --git a/tests/rspack-test/hotCases/newTreeshaking/re-export-optimization/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/newTreeshaking/re-export-optimization/__snapshots__/web/1.snap.txt index 0ded6799f26c..d0583639eb4b 100644 --- a/tests/rspack-test/hotCases/newTreeshaking/re-export-optimization/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/newTreeshaking/re-export-optimization/__snapshots__/web/1.snap.txt @@ -34,7 +34,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./bar.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -43,7 +43,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./entry.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/numeric-ids/add-remove-chunks/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/numeric-ids/add-remove-chunks/__snapshots__/web/1.snap.txt index b6f4f8419106..6de9a274ca39 100644 --- a/tests/rspack-test/hotCases/numeric-ids/add-remove-chunks/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/numeric-ids/add-remove-chunks/__snapshots__/web/1.snap.txt @@ -36,7 +36,7 @@ "use strict"; self["rspackHotUpdate"]("1e1", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); @@ -63,7 +63,7 @@ var value = 1.5; "use strict"; self["rspackHotUpdate"]("main", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/numeric-ids/add-remove-chunks/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/numeric-ids/add-remove-chunks/__snapshots__/web/2.snap.txt index 5773d3ad35a2..5a16f7be5116 100644 --- a/tests/rspack-test/hotCases/numeric-ids/add-remove-chunks/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/numeric-ids/add-remove-chunks/__snapshots__/web/2.snap.txt @@ -36,7 +36,7 @@ "use strict"; self["rspackHotUpdate"](10, { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); @@ -63,7 +63,7 @@ var value = 3; "use strict"; self["rspackHotUpdate"]("main", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/numeric-ids/production/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/numeric-ids/production/__snapshots__/web/1.snap.txt index 6b650da16286..395617a640ac 100644 --- a/tests/rspack-test/hotCases/numeric-ids/production/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/numeric-ids/production/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"](889, { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); var value = 2; __webpack_require__.d(__webpack_exports__, { diff --git a/tests/rspack-test/hotCases/parsing/hot-api-optional-chaining/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/parsing/hot-api-optional-chaining/__snapshots__/web/1.snap.txt index bf2a36440b9c..7f8bcb5c4ef4 100644 --- a/tests/rspack-test/hotCases/parsing/hot-api-optional-chaining/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/parsing/hot-api-optional-chaining/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/plugins/html/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/plugins/html/__snapshots__/web/1.snap.txt index 1a39ce5202c2..ed2b5fc786a7 100644 --- a/tests/rspack-test/hotCases/plugins/html/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/plugins/html/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); diff --git a/tests/rspack-test/hotCases/recover/recover-after-error/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/recover/recover-after-error/__snapshots__/web/1.snap.txt index 53a5cf804f5b..6266064d16c9 100644 --- a/tests/rspack-test/hotCases/recover/recover-after-error/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/recover/recover-after-error/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/recover/recover-after-error/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/recover/recover-after-error/__snapshots__/web/2.snap.txt index 5c30eb56afb0..577f7abf84b8 100644 --- a/tests/rspack-test/hotCases/recover/recover-after-error/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/recover/recover-after-error/__snapshots__/web/2.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/recover/recover-after-loader-error/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/recover/recover-after-loader-error/__snapshots__/web/2.snap.txt index 8265302c458d..ec672bf74e4c 100644 --- a/tests/rspack-test/hotCases/recover/recover-after-loader-error/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/recover/recover-after-loader-error/__snapshots__/web/2.snap.txt @@ -34,7 +34,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./loader.js!./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/recover/recover-after-parsing-error/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/recover/recover-after-parsing-error/__snapshots__/web/2.snap.txt index 82fe57635fd4..995c11f26878 100644 --- a/tests/rspack-test/hotCases/recover/recover-after-parsing-error/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/recover/recover-after-parsing-error/__snapshots__/web/2.snap.txt @@ -34,7 +34,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/recover/recover-after-removal-self-accepted/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/recover/recover-after-removal-self-accepted/__snapshots__/web/1.snap.txt index 25aab6cc90f7..47c1adbade8d 100644 --- a/tests/rspack-test/hotCases/recover/recover-after-removal-self-accepted/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/recover/recover-after-removal-self-accepted/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/recover/recover-after-removal-self-accepted/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/recover/recover-after-removal-self-accepted/__snapshots__/web/2.snap.txt index e7181d0218b0..e25a6da7d4a1 100644 --- a/tests/rspack-test/hotCases/recover/recover-after-removal-self-accepted/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/recover/recover-after-removal-self-accepted/__snapshots__/web/2.snap.txt @@ -34,7 +34,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./inner.js"(module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -45,7 +45,7 @@ module.hot.accept(); }, "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/recover/recover-after-self-error/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/recover/recover-after-self-error/__snapshots__/web/1.snap.txt index c1806c3c5db3..523640d2fced 100644 --- a/tests/rspack-test/hotCases/recover/recover-after-self-error/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/recover/recover-after-self-error/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./a.js"(module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export), getError: () => (getError), diff --git a/tests/rspack-test/hotCases/recover/recover-after-self-error/__snapshots__/web/3.snap.txt b/tests/rspack-test/hotCases/recover/recover-after-self-error/__snapshots__/web/3.snap.txt index 5e8c2d3e4d40..330e25732d69 100644 --- a/tests/rspack-test/hotCases/recover/recover-after-self-error/__snapshots__/web/3.snap.txt +++ b/tests/rspack-test/hotCases/recover/recover-after-self-error/__snapshots__/web/3.snap.txt @@ -34,7 +34,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./a.js"(module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export), getError: () => (getError), diff --git a/tests/rspack-test/hotCases/runtime/circular/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/runtime/circular/__snapshots__/web/1.snap.txt index 164c8cb1aa93..5a511075c051 100644 --- a/tests/rspack-test/hotCases/runtime/circular/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/runtime/circular/__snapshots__/web/1.snap.txt @@ -35,7 +35,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -48,7 +48,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./b.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/1.snap.txt index 4ec21a260fd5..80486fbf0cc5 100644 --- a/tests/rspack-test/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/1.snap.txt @@ -36,7 +36,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/2.snap.txt index 679b506501b7..16fa86687abb 100644 --- a/tests/rspack-test/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/2.snap.txt @@ -37,7 +37,7 @@ "use strict"; self["rspackHotUpdate"]("b_js", { "./b.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/3.snap.txt b/tests/rspack-test/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/3.snap.txt index 604d03a0fda0..4c9ac77bd171 100644 --- a/tests/rspack-test/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/3.snap.txt +++ b/tests/rspack-test/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/3.snap.txt @@ -36,7 +36,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/runtime/dispose-removed-module/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/runtime/dispose-removed-module/__snapshots__/web/1.snap.txt index 56f9896775ae..cd772d6c21c0 100644 --- a/tests/rspack-test/hotCases/runtime/dispose-removed-module/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/runtime/dispose-removed-module/__snapshots__/web/1.snap.txt @@ -35,7 +35,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./b.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -43,7 +43,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var _b__rspack_import_0 = __webpack_require__("./b.js"); diff --git a/tests/rspack-test/hotCases/runtime/dispose-removed-module/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/runtime/dispose-removed-module/__snapshots__/web/2.snap.txt index 324b5142cd1c..f6ad3a49c156 100644 --- a/tests/rspack-test/hotCases/runtime/dispose-removed-module/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/runtime/dispose-removed-module/__snapshots__/web/2.snap.txt @@ -35,7 +35,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./a.js"(module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -43,7 +43,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (/* reexport safe */ _a__rspack_import_0["default"]) }); diff --git a/tests/rspack-test/hotCases/runtime/hmr-circular/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/runtime/hmr-circular/__snapshots__/web/1.snap.txt index 6b969dee4b0a..b52e1802e13a 100644 --- a/tests/rspack-test/hotCases/runtime/hmr-circular/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/runtime/hmr-circular/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./entry.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/runtime/import-after-download/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/runtime/import-after-download/__snapshots__/web/1.snap.txt index df1597c3ffe0..4428ac33c334 100644 --- a/tests/rspack-test/hotCases/runtime/import-after-download/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/runtime/import-after-download/__snapshots__/web/1.snap.txt @@ -37,7 +37,7 @@ "use strict"; self["rspackHotUpdate"]("chunk_js", { "./inner.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -64,7 +64,7 @@ __webpack_require__.d(__webpack_exports__, { "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/runtime/replace-runtime-module/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/runtime/replace-runtime-module/__snapshots__/web/1.snap.txt index 8da66a5ad993..885872d60dec 100644 --- a/tests/rspack-test/hotCases/runtime/replace-runtime-module/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/runtime/replace-runtime-module/__snapshots__/web/1.snap.txt @@ -34,7 +34,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/runtime/require-disposed-module-warning/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/runtime/require-disposed-module-warning/__snapshots__/web/1.snap.txt index 3572f80ebe42..2de2cd384fa4 100644 --- a/tests/rspack-test/hotCases/runtime/require-disposed-module-warning/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/runtime/require-disposed-module-warning/__snapshots__/web/1.snap.txt @@ -34,7 +34,7 @@ self["rspackHotUpdate"]("main", { "./b.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/sharing/share-plugin/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/sharing/share-plugin/__snapshots__/web/1.snap.txt index c703217ed5eb..9bbfd75961cb 100644 --- a/tests/rspack-test/hotCases/sharing/share-plugin/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/sharing/share-plugin/__snapshots__/web/1.snap.txt @@ -38,7 +38,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (/* reexport default from dynamic */ common__rspack_import_0_default.a), getValue: () => (getValue) @@ -83,7 +83,7 @@ __webpack_require__.t = function(value, mode) { if((mode & 16) && typeof value.then === 'function') return value; } var ns = Object.create(null); - __webpack_require__.N(ns); + __webpack_require__.r(ns); var def = {}; leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)]; for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) { diff --git a/tests/rspack-test/hotCases/source-map/disable/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/source-map/disable/__snapshots__/web/1.snap.txt index 2f6e3d00ceef..8fed6e5d725b 100644 --- a/tests/rspack-test/hotCases/source-map/disable/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/source-map/disable/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/source-map/disable/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/source-map/disable/__snapshots__/web/2.snap.txt index 6b3986d4349d..6e69bdce5340 100644 --- a/tests/rspack-test/hotCases/source-map/disable/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/source-map/disable/__snapshots__/web/2.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/source-map/disable/__snapshots__/web/3.snap.txt b/tests/rspack-test/hotCases/source-map/disable/__snapshots__/web/3.snap.txt index 81b13fba3822..9577cbb55fc6 100644 --- a/tests/rspack-test/hotCases/source-map/disable/__snapshots__/web/3.snap.txt +++ b/tests/rspack-test/hotCases/source-map/disable/__snapshots__/web/3.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/source-map/enable/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/source-map/enable/__snapshots__/web/1.snap.txt index f77b24d2db75..c417df4cede8 100644 --- a/tests/rspack-test/hotCases/source-map/enable/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/source-map/enable/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/source-map/enable/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/source-map/enable/__snapshots__/web/2.snap.txt index 2f55d4ca6c0e..8abb14272aff 100644 --- a/tests/rspack-test/hotCases/source-map/enable/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/source-map/enable/__snapshots__/web/2.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/source-map/enable/__snapshots__/web/3.snap.txt b/tests/rspack-test/hotCases/source-map/enable/__snapshots__/web/3.snap.txt index 479c3b2785d4..0415170c7546 100644 --- a/tests/rspack-test/hotCases/source-map/enable/__snapshots__/web/3.snap.txt +++ b/tests/rspack-test/hotCases/source-map/enable/__snapshots__/web/3.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/stats/chunks/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/stats/chunks/__snapshots__/web/1.snap.txt index 1fd32e94a326..9ecfd1f9160a 100644 --- a/tests/rspack-test/hotCases/stats/chunks/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/stats/chunks/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/status/check/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/status/check/__snapshots__/web/1.snap.txt index 37484b37d921..64be7e97bc09 100644 --- a/tests/rspack-test/hotCases/status/check/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/status/check/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./file.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); diff --git a/tests/rspack-test/hotCases/unexpected-invalidation/used-exports/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/unexpected-invalidation/used-exports/__snapshots__/web/1.snap.txt index 66a22967c8a8..341de3f780a9 100644 --- a/tests/rspack-test/hotCases/unexpected-invalidation/used-exports/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/unexpected-invalidation/used-exports/__snapshots__/web/1.snap.txt @@ -33,7 +33,7 @@ "use strict"; self["rspackHotUpdate"]("main", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (/* reexport safe */ _subject__rspack_import_0.def) }); diff --git a/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/1.snap.txt index df9dcfd97e0e..40acee45321e 100644 --- a/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/1.snap.txt @@ -84,7 +84,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("shared", { "./moduleAs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -93,7 +93,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./moduleBs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -120,7 +120,7 @@ __webpack_require__.d(__webpack_exports__, { "use strict"; self["rspackHotUpdate"]("workerA_js", { "./moduleA.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -154,7 +154,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("workerB_js", { "./moduleB.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/2.snap.txt index 523492b2bd43..6fa608f76da6 100644 --- a/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/2.snap.txt @@ -84,7 +84,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("shared", { "./moduleAs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -93,7 +93,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./moduleBs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -120,7 +120,7 @@ __webpack_require__.d(__webpack_exports__, { "use strict"; self["rspackHotUpdate"]("workerA_js", { "./moduleA.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -154,7 +154,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("workerB_js", { "./moduleB.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/3.snap.txt b/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/3.snap.txt index abb845555713..fa4548ef4b00 100644 --- a/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/3.snap.txt +++ b/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/3.snap.txt @@ -84,7 +84,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("shared", { "./moduleAs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -93,7 +93,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./moduleBs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -120,7 +120,7 @@ __webpack_require__.d(__webpack_exports__, { "use strict"; self["rspackHotUpdate"]("workerA_js", { "./moduleA.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -154,7 +154,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("workerB_js", { "./moduleB.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/4.snap.txt b/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/4.snap.txt index 45c9f82587dd..f79f45618c39 100644 --- a/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/4.snap.txt +++ b/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/4.snap.txt @@ -84,7 +84,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("shared", { "./moduleAs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -93,7 +93,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./moduleBs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -120,7 +120,7 @@ __webpack_require__.d(__webpack_exports__, { "use strict"; self["rspackHotUpdate"]("workerA_js", { "./moduleA.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -154,7 +154,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("workerB_js", { "./moduleB.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/5.snap.txt b/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/5.snap.txt index f5b0860ba47f..d2dfcd6e5f40 100644 --- a/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/5.snap.txt +++ b/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/5.snap.txt @@ -84,7 +84,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("shared", { "./moduleAs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -93,7 +93,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./moduleBs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -120,7 +120,7 @@ __webpack_require__.d(__webpack_exports__, { "use strict"; self["rspackHotUpdate"]("workerA_js", { "./moduleA.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -154,7 +154,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("workerB_js", { "./moduleB.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/6.snap.txt b/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/6.snap.txt index 5fbd5fe35cd5..7e1edd7102d5 100644 --- a/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/6.snap.txt +++ b/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/6.snap.txt @@ -84,7 +84,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("shared", { "./moduleAs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -93,7 +93,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./moduleBs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -120,7 +120,7 @@ __webpack_require__.d(__webpack_exports__, { "use strict"; self["rspackHotUpdate"]("workerA_js", { "./moduleA.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -154,7 +154,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("workerB_js", { "./moduleB.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/7.snap.txt b/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/7.snap.txt index be399ab68364..0f58631c185a 100644 --- a/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/7.snap.txt +++ b/tests/rspack-test/hotCases/worker/issue-5597/__snapshots__/web/7.snap.txt @@ -84,7 +84,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("shared", { "./moduleAs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -93,7 +93,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./moduleBs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -120,7 +120,7 @@ __webpack_require__.d(__webpack_exports__, { "use strict"; self["rspackHotUpdate"]("workerA_js", { "./moduleA.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -154,7 +154,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("workerB_js", { "./moduleB.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/1.snap.txt index d621b39e2332..94d7a5ece2db 100644 --- a/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/1.snap.txt @@ -85,7 +85,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("shared", { "./moduleAs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -96,7 +96,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./moduleBs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -105,7 +105,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./moduleS.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -133,7 +133,7 @@ __webpack_require__.d(__webpack_exports__, { "use strict"; self["rspackHotUpdate"]("workerA_js", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -142,7 +142,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./moduleA.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -178,7 +178,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("workerB_js", { "./moduleB.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/2.snap.txt index c79a026dfcb2..6a5fff422512 100644 --- a/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/2.snap.txt @@ -84,7 +84,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("shared", { "./moduleAs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -95,7 +95,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./moduleBs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -124,7 +124,7 @@ __webpack_require__.d(__webpack_exports__, { "use strict"; self["rspackHotUpdate"]("workerA_js", { "./moduleA.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -161,7 +161,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("workerB_js", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -170,7 +170,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./moduleB.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/3.snap.txt b/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/3.snap.txt index 3f1a455d6ed9..bfd97b51c33b 100644 --- a/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/3.snap.txt +++ b/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/3.snap.txt @@ -84,7 +84,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("shared", { "./moduleAs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -93,7 +93,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./moduleBs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -122,7 +122,7 @@ __webpack_require__.d(__webpack_exports__, { "use strict"; self["rspackHotUpdate"]("workerA_js", { "./moduleA.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -156,7 +156,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("workerB_js", { "./moduleB.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/4.snap.txt b/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/4.snap.txt index ae31dc9e4782..af65f4b58e19 100644 --- a/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/4.snap.txt +++ b/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/4.snap.txt @@ -86,7 +86,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("shared", { "./moduleAs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -96,7 +96,7 @@ if (Math.random() < 0) __webpack_require__.e(/* import() */ "chunkS_js").then(__ }, "./moduleBs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -123,7 +123,7 @@ __webpack_require__.d(__webpack_exports__, { "use strict"; self["rspackHotUpdate"]("workerA_js", { "./moduleA.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -158,7 +158,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("workerB_js", { "./moduleB.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/5.snap.txt b/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/5.snap.txt index deba40c9aebe..308040b70c7b 100644 --- a/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/5.snap.txt +++ b/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/5.snap.txt @@ -86,7 +86,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("shared", { "./moduleAs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -96,7 +96,7 @@ if (Math.random() < 0) __webpack_require__.e(/* import() */ "chunkS_js").then(__ }, "./moduleBs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -124,7 +124,7 @@ if (Math.random() < 0) __webpack_require__.e(/* import() */ "chunkS_js").then(__ "use strict"; self["rspackHotUpdate"]("workerA_js", { "./moduleA.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -159,7 +159,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("workerB_js", { "./moduleB.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/6.snap.txt b/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/6.snap.txt index fd35e063d421..0701c6a0baab 100644 --- a/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/6.snap.txt +++ b/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/6.snap.txt @@ -86,7 +86,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("shared", { "./moduleAs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -95,7 +95,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./moduleBs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -123,7 +123,7 @@ if (Math.random() < 0) __webpack_require__.e(/* import() */ "chunkS_js").then(__ "use strict"; self["rspackHotUpdate"]("workerA_js", { "./moduleA.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -157,7 +157,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("workerB_js", { "./moduleB.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/7.snap.txt b/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/7.snap.txt index 6c58d53be86d..beb8cde0faf2 100644 --- a/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/7.snap.txt +++ b/tests/rspack-test/hotCases/worker/move-between-runtime/__snapshots__/web/7.snap.txt @@ -84,7 +84,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("shared", { "./moduleAs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -93,7 +93,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./moduleBs.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -120,7 +120,7 @@ __webpack_require__.d(__webpack_exports__, { "use strict"; self["rspackHotUpdate"]("workerA_js", { "./moduleA.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); @@ -154,7 +154,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("workerB_js", { "./moduleB.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/worker/update-in-worker/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/worker/update-in-worker/__snapshots__/web/1.snap.txt index fb2926ec23ca..f7f7a71871d3 100644 --- a/tests/rspack-test/hotCases/worker/update-in-worker/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/worker/update-in-worker/__snapshots__/web/1.snap.txt @@ -67,7 +67,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("worker_js", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/worker/update-in-worker/__snapshots__/web/2.snap.txt b/tests/rspack-test/hotCases/worker/update-in-worker/__snapshots__/web/2.snap.txt index 27a00ac6b6ba..db58a28e7d5d 100644 --- a/tests/rspack-test/hotCases/worker/update-in-worker/__snapshots__/web/2.snap.txt +++ b/tests/rspack-test/hotCases/worker/update-in-worker/__snapshots__/web/2.snap.txt @@ -67,7 +67,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("worker_js", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/hotCases/worker/update-in-worker/__snapshots__/web/3.snap.txt b/tests/rspack-test/hotCases/worker/update-in-worker/__snapshots__/web/3.snap.txt index 85e94eacb49f..f6850887a20b 100644 --- a/tests/rspack-test/hotCases/worker/update-in-worker/__snapshots__/web/3.snap.txt +++ b/tests/rspack-test/hotCases/worker/update-in-worker/__snapshots__/web/3.snap.txt @@ -67,7 +67,7 @@ __webpack_require__.h = () => ("CURRENT_HASH") "use strict"; self["rspackHotUpdate"]("worker_js", { "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/statsAPICases/exports.js b/tests/rspack-test/statsAPICases/exports.js index 305ac674df4b..0fa899813fa3 100644 --- a/tests/rspack-test/statsAPICases/exports.js +++ b/tests/rspack-test/statsAPICases/exports.js @@ -79,7 +79,7 @@ module.exports = { main.js, ], filteredModules: undefined, - hash: 213d3fa346a21975, + hash: 5494176960333ddb, id: 889, idHints: Array [], initial: true, @@ -467,7 +467,7 @@ module.exports = { errorsCount: 0, filteredAssets: undefined, filteredModules: undefined, - hash: de0de71fc2881c5e, + hash: 2574529075ccb8c5, modules: Array [ Object { assets: Array [], diff --git a/tests/rspack-test/statsOutputCases/all-stats/__snapshots__/stats.txt b/tests/rspack-test/statsOutputCases/all-stats/__snapshots__/stats.txt index 7278abbed74e..53b516cd4716 100644 --- a/tests/rspack-test/statsOutputCases/all-stats/__snapshots__/stats.txt +++ b/tests/rspack-test/statsOutputCases/all-stats/__snapshots__/stats.txt @@ -23,4 +23,4 @@ webpack/runtime/make_namespace_object xx bytes {main} [code generated] [no exports] [used exports unknown] -1970-04-20 12: Rspack x.x.x compiled successfully in X s (6a2353fa9fde7c92) \ No newline at end of file +1970-04-20 12: Rspack x.x.x compiled successfully in X s (c8efd3f0c70d4f0e) \ No newline at end of file diff --git a/tests/rspack-test/statsOutputCases/immutable/__snapshots__/stats.txt b/tests/rspack-test/statsOutputCases/immutable/__snapshots__/stats.txt index b755f6b88b5e..37427eb0710d 100644 --- a/tests/rspack-test/statsOutputCases/immutable/__snapshots__/stats.txt +++ b/tests/rspack-test/statsOutputCases/immutable/__snapshots__/stats.txt @@ -1,2 +1,2 @@ -asset a7c04efacbf09fbd.js xx KiB [emitted] [immutable] (name: main) +asset 8868e268a4d5877b.js xx KiB [emitted] [immutable] (name: main) asset 7b129503d319bd23.js xx bytes [emitted] [immutable] \ No newline at end of file diff --git a/tests/rspack-test/statsOutputCases/issue-7577/__snapshots__/stats.txt b/tests/rspack-test/statsOutputCases/issue-7577/__snapshots__/stats.txt index 1f0780f9819d..df598a85f297 100644 --- a/tests/rspack-test/statsOutputCases/issue-7577/__snapshots__/stats.txt +++ b/tests/rspack-test/statsOutputCases/issue-7577/__snapshots__/stats.txt @@ -18,12 +18,12 @@ cacheable modules xx bytes Rspack x.x.x compiled successfully in X s assets by chunk xx bytes (id hint: all) - asset c-all-b_js-59f57022283cfc59.js xx bytes [emitted] [immutable] (id hint: all) + asset c-all-b_js-ce41787ae6ff3759.js xx bytes [emitted] [immutable] (id hint: all) asset c-all-c_js-305d7d7dfb13d2f8.js xx bytes [emitted] [immutable] (id hint: all) -asset c-runtime~main-df0635d4ba1c1079.js xx KiB [emitted] [immutable] (name: runtime~main) +asset c-runtime~main-9afca81f3f230919.js xx KiB [emitted] [immutable] (name: runtime~main) asset c-main-cb74163fc8cc359b.js xx bytes [emitted] [immutable] (name: main) asset c-vendors-node_modules_vendor_js-e936af1c5d692780.js xx bytes [emitted] [immutable] (id hint: vendors) -Entrypoint main xx KiB = c-runtime~main-df0635d4ba1c1079.js xx KiB c-all-c_js-305d7d7dfb13d2f8.js xx bytes c-main-cb74163fc8cc359b.js xx bytes +Entrypoint main xx KiB = c-runtime~main-9afca81f3f230919.js xx KiB c-all-c_js-305d7d7dfb13d2f8.js xx bytes c-main-cb74163fc8cc359b.js xx bytes runtime modules xx KiB 13 modules cacheable modules xx bytes ./c.js xx bytes [built] [code generated] diff --git a/tests/rspack-test/treeShakingCases/cjs-tree-shaking-basic/__snapshots__/treeshaking.snap.txt b/tests/rspack-test/treeShakingCases/cjs-tree-shaking-basic/__snapshots__/treeshaking.snap.txt index 4c6d2df7e093..b0e8b5de246b 100644 --- a/tests/rspack-test/treeShakingCases/cjs-tree-shaking-basic/__snapshots__/treeshaking.snap.txt +++ b/tests/rspack-test/treeShakingCases/cjs-tree-shaking-basic/__snapshots__/treeshaking.snap.txt @@ -2,7 +2,7 @@ "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["main"], { "./answer.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { answer: () => (answer) }); diff --git a/tests/rspack-test/treeShakingCases/context-module/__snapshots__/treeshaking.snap.txt b/tests/rspack-test/treeShakingCases/context-module/__snapshots__/treeshaking.snap.txt index 63022ccfd43a..517b3e10ae5a 100644 --- a/tests/rspack-test/treeShakingCases/context-module/__snapshots__/treeshaking.snap.txt +++ b/tests/rspack-test/treeShakingCases/context-module/__snapshots__/treeshaking.snap.txt @@ -2,7 +2,7 @@ (self["rspackChunk"] = self["rspackChunk"] || []).push([["main"], { "./child/child/index.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); @@ -12,7 +12,7 @@ const value = "dynamic"; }, "./child/index.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: () => (value) }); diff --git a/tests/rspack-test/treeShakingCases/export-imported-import-all-as/__snapshots__/treeshaking.snap.txt b/tests/rspack-test/treeShakingCases/export-imported-import-all-as/__snapshots__/treeshaking.snap.txt index f7d4b91b2e61..88ee07aee845 100644 --- a/tests/rspack-test/treeShakingCases/export-imported-import-all-as/__snapshots__/treeshaking.snap.txt +++ b/tests/rspack-test/treeShakingCases/export-imported-import-all-as/__snapshots__/treeshaking.snap.txt @@ -9,7 +9,7 @@ _answer__rspack_import_0; }, "./test.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { result: () => (result) }); diff --git a/tests/rspack-test/treeShakingCases/export-named-decl-as/__snapshots__/treeshaking.snap.txt b/tests/rspack-test/treeShakingCases/export-named-decl-as/__snapshots__/treeshaking.snap.txt index 6d6ac1b22944..4cf6c9a59f0b 100644 --- a/tests/rspack-test/treeShakingCases/export-named-decl-as/__snapshots__/treeshaking.snap.txt +++ b/tests/rspack-test/treeShakingCases/export-named-decl-as/__snapshots__/treeshaking.snap.txt @@ -2,7 +2,7 @@ "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["main"], { "./src/answer.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { formatNumber: () => (/* reexport safe */ _plugin_formatNumber__rspack_import_0["default"]) }); diff --git a/tests/rspack-test/treeShakingCases/export-star-chain/__snapshots__/treeshaking.snap.txt b/tests/rspack-test/treeShakingCases/export-star-chain/__snapshots__/treeshaking.snap.txt index 4dcdbddd941b..e59015c8162c 100644 --- a/tests/rspack-test/treeShakingCases/export-star-chain/__snapshots__/treeshaking.snap.txt +++ b/tests/rspack-test/treeShakingCases/export-star-chain/__snapshots__/treeshaking.snap.txt @@ -27,7 +27,7 @@ __webpack_require__.d(__webpack_exports__, { }, "./colors/index.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { blue: () => (/* reexport safe */ _b__rspack_import_1.blue), red: () => (/* reexport safe */ _a__rspack_import_0.red), diff --git a/tests/rspack-test/treeShakingCases/export_star/__snapshots__/treeshaking.snap.txt b/tests/rspack-test/treeShakingCases/export_star/__snapshots__/treeshaking.snap.txt index 7c3d4bec62dc..1cdcc75c4ce2 100644 --- a/tests/rspack-test/treeShakingCases/export_star/__snapshots__/treeshaking.snap.txt +++ b/tests/rspack-test/treeShakingCases/export_star/__snapshots__/treeshaking.snap.txt @@ -17,7 +17,7 @@ function b() {} }, "./foo.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { a: () => (a), b: () => (/* reexport safe */ _bar__rspack_import_0.b), diff --git a/tests/rspack-test/treeShakingCases/import-star-as-and-export/__snapshots__/treeshaking.snap.txt b/tests/rspack-test/treeShakingCases/import-star-as-and-export/__snapshots__/treeshaking.snap.txt index 3f04d08e95c6..1fa6d5c0f6fa 100644 --- a/tests/rspack-test/treeShakingCases/import-star-as-and-export/__snapshots__/treeshaking.snap.txt +++ b/tests/rspack-test/treeShakingCases/import-star-as-and-export/__snapshots__/treeshaking.snap.txt @@ -10,7 +10,7 @@ _app__rspack_import_0; }, "./lib.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { a: () => (a) }); diff --git a/tests/rspack-test/treeShakingCases/transitive-bailout/__snapshots__/treeshaking.snap.txt b/tests/rspack-test/treeShakingCases/transitive-bailout/__snapshots__/treeshaking.snap.txt index 10b4d31dc0d6..c31bcf53e82e 100644 --- a/tests/rspack-test/treeShakingCases/transitive-bailout/__snapshots__/treeshaking.snap.txt +++ b/tests/rspack-test/treeShakingCases/transitive-bailout/__snapshots__/treeshaking.snap.txt @@ -29,7 +29,7 @@ _answer__rspack_import_0.test; }, "./lib.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { a: () => (/* reexport safe */ _a_js__rspack_import_0.a), b: () => (/* reexport safe */ _a_js__rspack_import_0.b) diff --git a/tests/rspack-test/treeShakingCases/tree-shaking-interop/__snapshots__/treeshaking.snap.txt b/tests/rspack-test/treeShakingCases/tree-shaking-interop/__snapshots__/treeshaking.snap.txt index 56737998abf8..8504c945da3a 100644 --- a/tests/rspack-test/treeShakingCases/tree-shaking-interop/__snapshots__/treeshaking.snap.txt +++ b/tests/rspack-test/treeShakingCases/tree-shaking-interop/__snapshots__/treeshaking.snap.txt @@ -2,7 +2,7 @@ "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["bar_js"], { "./bar.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (test) }); @@ -18,7 +18,7 @@ function test() {} (self["rspackChunk"] = self["rspackChunk"] || []).push([["main"], { "./a.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { a: () => (a) }); diff --git a/tests/rspack-test/treeShakingCases/tree-shaking-lazy-import/__snapshots__/treeshaking.snap.txt b/tests/rspack-test/treeShakingCases/tree-shaking-lazy-import/__snapshots__/treeshaking.snap.txt index ccb057cc0226..f4dfe326d107 100644 --- a/tests/rspack-test/treeShakingCases/tree-shaking-lazy-import/__snapshots__/treeshaking.snap.txt +++ b/tests/rspack-test/treeShakingCases/tree-shaking-lazy-import/__snapshots__/treeshaking.snap.txt @@ -2,7 +2,7 @@ "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["lib_js"], { "./lib.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export) }); diff --git a/tests/rspack-test/treeShakingCases/webpack-inner-graph-switch/__snapshots__/treeshaking.snap.txt b/tests/rspack-test/treeShakingCases/webpack-inner-graph-switch/__snapshots__/treeshaking.snap.txt index 8a04783ab3e9..7eb446a48548 100644 --- a/tests/rspack-test/treeShakingCases/webpack-inner-graph-switch/__snapshots__/treeshaking.snap.txt +++ b/tests/rspack-test/treeShakingCases/webpack-inner-graph-switch/__snapshots__/treeshaking.snap.txt @@ -2,7 +2,7 @@ "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["chunk_js"], { "./chunk.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); @@ -89,7 +89,7 @@ function useDocument(obj) { }, "./some-module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { Block: () => (Block), Document: () => (Document), diff --git a/tests/rspack-test/treeShakingCases/webpack-innergraph-circular/__snapshots__/treeshaking.snap.txt b/tests/rspack-test/treeShakingCases/webpack-innergraph-circular/__snapshots__/treeshaking.snap.txt index c02bd5c65f58..5d63752b2f55 100644 --- a/tests/rspack-test/treeShakingCases/webpack-innergraph-circular/__snapshots__/treeshaking.snap.txt +++ b/tests/rspack-test/treeShakingCases/webpack-innergraph-circular/__snapshots__/treeshaking.snap.txt @@ -2,7 +2,7 @@ "use strict"; (self["rspackChunk"] = self["rspackChunk"] || []).push([["chunk_js"], { "./chunk.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var _inner__rspack_import_0 = __webpack_require__("./inner.js"); diff --git a/tests/rspack-test/treeShakingCases/webpack-innergraph-no-side-effects/__snapshots__/treeshaking.snap.txt b/tests/rspack-test/treeShakingCases/webpack-innergraph-no-side-effects/__snapshots__/treeshaking.snap.txt index 12a7d3cc4a39..40ceeaf9c7d3 100644 --- a/tests/rspack-test/treeShakingCases/webpack-innergraph-no-side-effects/__snapshots__/treeshaking.snap.txt +++ b/tests/rspack-test/treeShakingCases/webpack-innergraph-no-side-effects/__snapshots__/treeshaking.snap.txt @@ -9,7 +9,7 @@ it("should be able to load package without side effects where modules are unused }, "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": () => (__rspack_default_export), test: () => (test) diff --git a/tests/rspack-test/treeShakingCases/webpack-innergraph-try-globals/__snapshots__/treeshaking.snap.txt b/tests/rspack-test/treeShakingCases/webpack-innergraph-try-globals/__snapshots__/treeshaking.snap.txt index 2bd0e53083ed..009184c0f425 100644 --- a/tests/rspack-test/treeShakingCases/webpack-innergraph-try-globals/__snapshots__/treeshaking.snap.txt +++ b/tests/rspack-test/treeShakingCases/webpack-innergraph-try-globals/__snapshots__/treeshaking.snap.txt @@ -2,7 +2,7 @@ (self["rspackChunk"] = self["rspackChunk"] || []).push([["main"], { "./import-module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { "use strict"; -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); /* import */ var _module__rspack_import_0 = __webpack_require__("./module.js"); diff --git a/tests/rspack-test/treeShakingCases/webpack-reexport-namespace-and-default/__snapshots__/treeshaking.snap.txt b/tests/rspack-test/treeShakingCases/webpack-reexport-namespace-and-default/__snapshots__/treeshaking.snap.txt index f04437e3a652..c71984659ab0 100644 --- a/tests/rspack-test/treeShakingCases/webpack-reexport-namespace-and-default/__snapshots__/treeshaking.snap.txt +++ b/tests/rspack-test/treeShakingCases/webpack-reexport-namespace-and-default/__snapshots__/treeshaking.snap.txt @@ -27,7 +27,7 @@ it("default export should be used", () => { }, "./module.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) { -__webpack_require__.N(__webpack_exports__); +__webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { mod: () => (mod) }); diff --git a/tests/rspack-test/watchCases/async-modules/top-level-await/0/utils.js b/tests/rspack-test/watchCases/async-modules/top-level-await/0/utils.js index fbb953ba49a3..b0d91d609166 100644 --- a/tests/rspack-test/watchCases/async-modules/top-level-await/0/utils.js +++ b/tests/rspack-test/watchCases/async-modules/top-level-await/0/utils.js @@ -3,7 +3,7 @@ function escapeRegExp(string) { } export function isAsyncModule(content, moduleId) { - const regex = new RegExp(`\\"${escapeRegExp(moduleId)}\\".*\\(.*\\).*\\{\\s([\\S\\s]*?)__webpack_require__\\.N\\(__webpack_exports__\\);`) + const regex = new RegExp(`\\"${escapeRegExp(moduleId)}\\".*\\(.*\\).*\\{\\s([\\S\\s]*?)__webpack_require__\\.r\\(__webpack_exports__\\);`) const result = regex.exec(content) try { const [, header] = result; From 53347ee81451f7321c306ef4c026f3463ab90875 Mon Sep 17 00:00:00 2001 From: LingyuCoder Date: Thu, 11 Jun 2026 17:27:35 +0800 Subject: [PATCH 06/21] esm snapshot --- .../src/parser_plugin/api_plugin.rs | 21 +++++++++--------- .../create_fake_namespace_object.rs | 4 ++-- .../runtime/create_fake_namespace_object.ejs | 4 ++-- .../__snapshots__/esm.snap.txt | 1 - .../__snapshots__/esm.snap.txt | 1 - .../import-cjs/__snapshots__/esm.snap.txt | 1 - .../__snapshots__/esm.snap.txt | 22 ++----------------- .../__snapshots__/esm.snap.txt | 22 ++----------------- .../__snapshots__/esm.snap.txt | 22 ++----------------- .../__snapshots__/esm.snap.txt | 22 ++----------------- .../__snapshots__/esm.snap.txt | 22 ++----------------- .../__snapshots__/esm.snap.txt | 22 ++----------------- .../__snapshots__/esm.snap.txt | 22 ++----------------- .../__snapshots__/esm.snap.txt | 22 ++----------------- .../__snapshots__/esm.snap.txt | 1 - .../__snapshots__/esm.snap.txt | 1 - .../__snapshots__/esm.snap.txt | 1 - .../__snapshots__/esm.snap.txt | 1 - .../__snapshots__/esm.snap.txt | 1 - 19 files changed, 31 insertions(+), 182 deletions(-) diff --git a/crates/rspack_plugin_javascript/src/parser_plugin/api_plugin.rs b/crates/rspack_plugin_javascript/src/parser_plugin/api_plugin.rs index aa44e9beae4a..565683996e97 100644 --- a/crates/rspack_plugin_javascript/src/parser_plugin/api_plugin.rs +++ b/crates/rspack_plugin_javascript/src/parser_plugin/api_plugin.rs @@ -201,6 +201,10 @@ fn static_require_member_chain( expr_span: Span, write: bool, ) -> Option { + if parser.compiler_options.experiments.runtime_mode != ExperimentRuntimeMode::Rspack { + return None; + } + if for_name == API_REQUIRE && let Some(property) = members.first() { @@ -210,8 +214,7 @@ fn static_require_member_chain( let dep_span = if members.len() > 1 { member_ranges .and_then(|ranges| ranges.get(1)) - .map(|range| Span::new(expr_span.lo, range.hi)) - .unwrap_or(expr_span) + .map_or(expr_span, |range| Span::new(expr_span.start, range.end)) } else { expr_span }; @@ -486,17 +489,13 @@ impl<'p, 'a> JavascriptParserPlugin<'p, 'a> for APIPlugin { &self, parser: &mut JavascriptParser, _expr: &AssignExpr, + _ident: &Ident, for_name: &str, ) -> Option { if let Some(runtime_global) = runtime_api_from_name(for_name).and_then(|api| api.runtime_global) + && parser.compiler_options.experiments.runtime_mode == ExperimentRuntimeMode::Rspack { - if parser.compiler_options.experiments.runtime_mode == ExperimentRuntimeMode::Rspack { - parser.add_presentational_dependency(Box::new(RuntimeRequirementsDependency::write_only( - runtime_global, - ))); - return None; - } - parser.add_presentational_dependency(Box::new(RuntimeRequirementsDependency::add_only( + parser.add_presentational_dependency(Box::new(RuntimeRequirementsDependency::write_only( runtime_global, ))); } @@ -551,7 +550,9 @@ impl<'p, 'a> JavascriptParserPlugin<'p, 'a> for APIPlugin { call_expr: &CallExpr, for_name: &str, ) -> Option { - if for_name == API_REQUIRE { + if for_name == API_REQUIRE + && parser.compiler_options.experiments.runtime_mode == ExperimentRuntimeMode::Rspack + { parser.add_presentational_dependency(Box::new(RuntimeRequirementsDependency::add_only( RuntimeGlobals::REQUIRE, ))); diff --git a/crates/rspack_plugin_runtime/src/runtime_module/create_fake_namespace_object.rs b/crates/rspack_plugin_runtime/src/runtime_module/create_fake_namespace_object.rs index 72698b55be5d..6826ab607ab2 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/create_fake_namespace_object.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/create_fake_namespace_object.rs @@ -38,11 +38,11 @@ impl RuntimeModule for CreateFakeNamespaceObjectRuntimeModule { let params = Some( if context.compilation.options.experiments.runtime_mode == RuntimeMode::Rspack { serde_json::json!({ - "REQUIRE": "(typeof this === \"function\" ? this : this.r)" + "__this": "(typeof this === \"function\" ? this : this.r)" }) } else { serde_json::json!({ - "REQUIRE": "this" + "__this": "this" }) }, ); diff --git a/crates/rspack_plugin_runtime/src/runtime_module/runtime/create_fake_namespace_object.ejs b/crates/rspack_plugin_runtime/src/runtime_module/runtime/create_fake_namespace_object.ejs index 9c694691e97d..7c0a14d2956b 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/runtime/create_fake_namespace_object.ejs +++ b/crates/rspack_plugin_runtime/src/runtime_module/runtime/create_fake_namespace_object.ejs @@ -7,7 +7,7 @@ var leafPrototypes; // mode & 16: return value when it's Promise-like // mode & 8|1: behave like require <%- CREATE_FAKE_NAMESPACE_OBJECT %> = function(value, mode) { - if(mode & 1) value = <%- REQUIRE %>(value); + if(mode & 1) value = <%- __this %>(value); if(mode & 8) return value; if(typeof value === 'object' && value) { if((mode & 4) && value.__esModule) return value; @@ -23,4 +23,4 @@ var leafPrototypes; def['default'] = <%- returningFunction("value", "") %>; <%- DEFINE_PROPERTY_GETTERS %>(ns, def); return ns; -}; +}; \ No newline at end of file diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/import-cjs-runtime-chunk-false-async-chunk/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/import-cjs-runtime-chunk-false-async-chunk/__snapshots__/esm.snap.txt index b0654021dfd7..31c2b2581384 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/import-cjs-runtime-chunk-false-async-chunk/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/import-cjs-runtime-chunk-false-async-chunk/__snapshots__/esm.snap.txt @@ -116,7 +116,6 @@ __webpack_require__.t = function(value, mode) { __webpack_require__.d(ns, def); return ns; }; - })(); // webpack/runtime/define_property_getters (() => { diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/import-cjs-runtime-chunk-false-entry-export/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/import-cjs-runtime-chunk-false-entry-export/__snapshots__/esm.snap.txt index ff73c5a95463..4877ac9daecf 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/import-cjs-runtime-chunk-false-entry-export/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/import-cjs-runtime-chunk-false-entry-export/__snapshots__/esm.snap.txt @@ -90,7 +90,6 @@ __webpack_require__.t = function(value, mode) { __webpack_require__.d(ns, def); return ns; }; - })(); // webpack/runtime/define_property_getters (() => { diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/import-cjs/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/import-cjs/__snapshots__/esm.snap.txt index 31793d33af1d..a85464e374ea 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/import-cjs/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/import-cjs/__snapshots__/esm.snap.txt @@ -117,7 +117,6 @@ __webpack_require__.t = function(value, mode) { __webpack_require__.d(ns, def); return ns; }; - })(); // webpack/runtime/define_property_getters (() => { diff --git a/tests/rspack-test/esmOutputCases/externals/dynamic-import-commonjs-require-collision/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/externals/dynamic-import-commonjs-require-collision/__snapshots__/esm.snap.txt index 319274e46092..c99aa9b79bc2 100644 --- a/tests/rspack-test/esmOutputCases/externals/dynamic-import-commonjs-require-collision/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/externals/dynamic-import-commonjs-require-collision/__snapshots__/esm.snap.txt @@ -30,25 +30,8 @@ export { index_require as userRequire, loadPlatform }; ``` ```mjs title=runtime.mjs -// The module cache -var __webpack_module_cache__ = {}; -// The require function -function __webpack_require__(moduleId) { -// Check if module is in cache -var cachedModule = __webpack_module_cache__[moduleId]; -if (cachedModule !== undefined) { -return cachedModule.exports; -} -// Create a new module (and put it into the cache) -var module = (__webpack_module_cache__[moduleId] = { -exports: {} -}); -// Execute the module function -__webpack_modules__[moduleId](module, module.exports, __webpack_require__); - -// Return the exports of the module -return module.exports; -} +// The require scope +var __webpack_require__ = {}; // webpack/runtime/create_fake_namespace_object (() => { @@ -78,7 +61,6 @@ __webpack_require__.t = function(value, mode) { __webpack_require__.d(ns, def); return ns; }; - })(); // webpack/runtime/define_property_getters (() => { diff --git a/tests/rspack-test/esmOutputCases/externals/dynamic-import-node-commonjs-helper-collision/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/externals/dynamic-import-node-commonjs-helper-collision/__snapshots__/esm.snap.txt index 23648bd23b8a..d5b7660d7212 100644 --- a/tests/rspack-test/esmOutputCases/externals/dynamic-import-node-commonjs-helper-collision/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/externals/dynamic-import-node-commonjs-helper-collision/__snapshots__/esm.snap.txt @@ -29,25 +29,8 @@ export { loadFs }; ``` ```mjs title=runtime.mjs -// The module cache -var __webpack_module_cache__ = {}; -// The require function -function __webpack_require__(moduleId) { -// Check if module is in cache -var cachedModule = __webpack_module_cache__[moduleId]; -if (cachedModule !== undefined) { -return cachedModule.exports; -} -// Create a new module (and put it into the cache) -var module = (__webpack_module_cache__[moduleId] = { -exports: {} -}); -// Execute the module function -__webpack_modules__[moduleId](module, module.exports, __webpack_require__); - -// Return the exports of the module -return module.exports; -} +// The require scope +var __webpack_require__ = {}; // webpack/runtime/create_fake_namespace_object (() => { @@ -77,7 +60,6 @@ __webpack_require__.t = function(value, mode) { __webpack_require__.d(ns, def); return ns; }; - })(); // webpack/runtime/define_property_getters (() => { diff --git a/tests/rspack-test/esmOutputCases/externals/esm-node-target/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/externals/esm-node-target/__snapshots__/esm.snap.txt index 4194058628ba..24b25b3e89d8 100644 --- a/tests/rspack-test/esmOutputCases/externals/esm-node-target/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/externals/esm-node-target/__snapshots__/esm.snap.txt @@ -30,25 +30,8 @@ export { readFileSync } from "fs"; ``` ```mjs title=runtime.mjs -// The module cache -var __webpack_module_cache__ = {}; -// The require function -function __webpack_require__(moduleId) { -// Check if module is in cache -var cachedModule = __webpack_module_cache__[moduleId]; -if (cachedModule !== undefined) { -return cachedModule.exports; -} -// Create a new module (and put it into the cache) -var module = (__webpack_module_cache__[moduleId] = { -exports: {} -}); -// Execute the module function -__webpack_modules__[moduleId](module, module.exports, __webpack_require__); - -// Return the exports of the module -return module.exports; -} +// The require scope +var __webpack_require__ = {}; // webpack/runtime/create_fake_namespace_object (() => { @@ -78,7 +61,6 @@ __webpack_require__.t = function(value, mode) { __webpack_require__.d(ns, def); return ns; }; - })(); // webpack/runtime/define_property_getters (() => { diff --git a/tests/rspack-test/esmOutputCases/externals/node-commonjs-export-namespace-as-with-named/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/externals/node-commonjs-export-namespace-as-with-named/__snapshots__/esm.snap.txt index 20046c5bd39b..6bb4980c1343 100644 --- a/tests/rspack-test/esmOutputCases/externals/node-commonjs-export-namespace-as-with-named/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/externals/node-commonjs-export-namespace-as-with-named/__snapshots__/esm.snap.txt @@ -28,25 +28,8 @@ export { external_fs_namespaceObject as fsNs, readFile, readFileSync }; ``` ```mjs title=runtime.mjs -// The module cache -var __webpack_module_cache__ = {}; -// The require function -function __webpack_require__(moduleId) { -// Check if module is in cache -var cachedModule = __webpack_module_cache__[moduleId]; -if (cachedModule !== undefined) { -return cachedModule.exports; -} -// Create a new module (and put it into the cache) -var module = (__webpack_module_cache__[moduleId] = { -exports: {} -}); -// Execute the module function -__webpack_modules__[moduleId](module, module.exports, __webpack_require__); - -// Return the exports of the module -return module.exports; -} +// The require scope +var __webpack_require__ = {}; // webpack/runtime/create_fake_namespace_object (() => { @@ -76,7 +59,6 @@ __webpack_require__.t = function(value, mode) { __webpack_require__.d(ns, def); return ns; }; - })(); // webpack/runtime/define_property_getters (() => { diff --git a/tests/rspack-test/esmOutputCases/externals/node-commonjs-import-namespace-reexport-with-named/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/externals/node-commonjs-import-namespace-reexport-with-named/__snapshots__/esm.snap.txt index 59a99d53c300..b8b6ae5b8d39 100644 --- a/tests/rspack-test/esmOutputCases/externals/node-commonjs-import-namespace-reexport-with-named/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/externals/node-commonjs-import-namespace-reexport-with-named/__snapshots__/esm.snap.txt @@ -30,25 +30,8 @@ export { external_fs_namespaceObject as fsNs, readFile, readFileSync }; ``` ```mjs title=runtime.mjs -// The module cache -var __webpack_module_cache__ = {}; -// The require function -function __webpack_require__(moduleId) { -// Check if module is in cache -var cachedModule = __webpack_module_cache__[moduleId]; -if (cachedModule !== undefined) { -return cachedModule.exports; -} -// Create a new module (and put it into the cache) -var module = (__webpack_module_cache__[moduleId] = { -exports: {} -}); -// Execute the module function -__webpack_modules__[moduleId](module, module.exports, __webpack_require__); - -// Return the exports of the module -return module.exports; -} +// The require scope +var __webpack_require__ = {}; // webpack/runtime/create_fake_namespace_object (() => { @@ -78,7 +61,6 @@ __webpack_require__.t = function(value, mode) { __webpack_require__.d(ns, def); return ns; }; - })(); // webpack/runtime/define_property_getters (() => { diff --git a/tests/rspack-test/esmOutputCases/externals/node-commonjs-namespace-name-collision-across-modules/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/externals/node-commonjs-namespace-name-collision-across-modules/__snapshots__/esm.snap.txt index 7814a8e5cbb4..f078167dfddb 100644 --- a/tests/rspack-test/esmOutputCases/externals/node-commonjs-namespace-name-collision-across-modules/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/externals/node-commonjs-namespace-name-collision-across-modules/__snapshots__/esm.snap.txt @@ -44,25 +44,8 @@ export { external_path_namespaceObject as pathNs, joinFn, readFile, readFileSync ``` ```mjs title=runtime.mjs -// The module cache -var __webpack_module_cache__ = {}; -// The require function -function __webpack_require__(moduleId) { -// Check if module is in cache -var cachedModule = __webpack_module_cache__[moduleId]; -if (cachedModule !== undefined) { -return cachedModule.exports; -} -// Create a new module (and put it into the cache) -var module = (__webpack_module_cache__[moduleId] = { -exports: {} -}); -// Execute the module function -__webpack_modules__[moduleId](module, module.exports, __webpack_require__); - -// Return the exports of the module -return module.exports; -} +// The require scope +var __webpack_require__ = {}; // webpack/runtime/create_fake_namespace_object (() => { @@ -92,7 +75,6 @@ __webpack_require__.t = function(value, mode) { __webpack_require__.d(ns, def); return ns; }; - })(); // webpack/runtime/define_property_getters (() => { diff --git a/tests/rspack-test/esmOutputCases/externals/node-commonjs-wrapper-namespace-reexport/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/externals/node-commonjs-wrapper-namespace-reexport/__snapshots__/esm.snap.txt index e61942bc88e3..57a3dd3f2800 100644 --- a/tests/rspack-test/esmOutputCases/externals/node-commonjs-wrapper-namespace-reexport/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/externals/node-commonjs-wrapper-namespace-reexport/__snapshots__/esm.snap.txt @@ -37,25 +37,8 @@ export { exports_namespaceObject as exportsNS, index_js_namespaceObject as sourc ``` ```mjs title=runtime.mjs -// The module cache -var __webpack_module_cache__ = {}; -// The require function -function __webpack_require__(moduleId) { -// Check if module is in cache -var cachedModule = __webpack_module_cache__[moduleId]; -if (cachedModule !== undefined) { -return cachedModule.exports; -} -// Create a new module (and put it into the cache) -var module = (__webpack_module_cache__[moduleId] = { -exports: {} -}); -// Execute the module function -__webpack_modules__[moduleId](module, module.exports, __webpack_require__); - -// Return the exports of the module -return module.exports; -} +// The require scope +var __webpack_require__ = {}; // webpack/runtime/create_fake_namespace_object (() => { @@ -85,7 +68,6 @@ __webpack_require__.t = function(value, mode) { __webpack_require__.d(ns, def); return ns; }; - })(); // webpack/runtime/define_property_getters (() => { diff --git a/tests/rspack-test/esmOutputCases/interop/namespace-import-asset/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/interop/namespace-import-asset/__snapshots__/esm.snap.txt index f4accf591a62..fbff3ab8acb8 100644 --- a/tests/rspack-test/esmOutputCases/interop/namespace-import-asset/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/interop/namespace-import-asset/__snapshots__/esm.snap.txt @@ -19,25 +19,8 @@ export {}; ``` ```mjs title=runtime.mjs -// The module cache -var __webpack_module_cache__ = {}; -// The require function -function __webpack_require__(moduleId) { -// Check if module is in cache -var cachedModule = __webpack_module_cache__[moduleId]; -if (cachedModule !== undefined) { -return cachedModule.exports; -} -// Create a new module (and put it into the cache) -var module = (__webpack_module_cache__[moduleId] = { -exports: {} -}); -// Execute the module function -__webpack_modules__[moduleId](module, module.exports, __webpack_require__); - -// Return the exports of the module -return module.exports; -} +// The require scope +var __webpack_require__ = {}; // webpack/runtime/create_fake_namespace_object (() => { @@ -67,7 +50,6 @@ __webpack_require__.t = function(value, mode) { __webpack_require__.d(ns, def); return ns; }; - })(); // webpack/runtime/define_property_getters (() => { diff --git a/tests/rspack-test/esmOutputCases/namespace/basic-cjs-capture/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/basic-cjs-capture/__snapshots__/esm.snap.txt index 7be631a83870..132df82d8724 100644 --- a/tests/rspack-test/esmOutputCases/namespace/basic-cjs-capture/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/basic-cjs-capture/__snapshots__/esm.snap.txt @@ -82,7 +82,6 @@ __webpack_require__.t = function(value, mode) { __webpack_require__.d(ns, def); return ns; }; - })(); // webpack/runtime/define_property_getters (() => { diff --git a/tests/rspack-test/esmOutputCases/namespace/export-namespace-as-cjs/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/export-namespace-as-cjs/__snapshots__/esm.snap.txt index 945c6ce0db51..775009832247 100644 --- a/tests/rspack-test/esmOutputCases/namespace/export-namespace-as-cjs/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/export-namespace-as-cjs/__snapshots__/esm.snap.txt @@ -81,7 +81,6 @@ __webpack_require__.t = function(value, mode) { __webpack_require__.d(ns, def); return ns; }; - })(); // webpack/runtime/define_property_getters (() => { diff --git a/tests/rspack-test/esmOutputCases/namespace/import-export-namespace-as-cjs/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/import-export-namespace-as-cjs/__snapshots__/esm.snap.txt index 165f1361fd52..a56842df464b 100644 --- a/tests/rspack-test/esmOutputCases/namespace/import-export-namespace-as-cjs/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/import-export-namespace-as-cjs/__snapshots__/esm.snap.txt @@ -82,7 +82,6 @@ __webpack_require__.t = function(value, mode) { __webpack_require__.d(ns, def); return ns; }; - })(); // webpack/runtime/define_property_getters (() => { diff --git a/tests/rspack-test/esmOutputCases/namespace/missing-export-cjs-capture/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/missing-export-cjs-capture/__snapshots__/esm.snap.txt index 58c7a3b45d78..9174941f1dca 100644 --- a/tests/rspack-test/esmOutputCases/namespace/missing-export-cjs-capture/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/missing-export-cjs-capture/__snapshots__/esm.snap.txt @@ -80,7 +80,6 @@ __webpack_require__.t = function(value, mode) { __webpack_require__.d(ns, def); return ns; }; - })(); // webpack/runtime/define_property_getters (() => { diff --git a/tests/rspack-test/esmOutputCases/namespace/star-export-as-namespace-cjs/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/namespace/star-export-as-namespace-cjs/__snapshots__/esm.snap.txt index 849b7bc07775..6718b21021da 100644 --- a/tests/rspack-test/esmOutputCases/namespace/star-export-as-namespace-cjs/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/namespace/star-export-as-namespace-cjs/__snapshots__/esm.snap.txt @@ -86,7 +86,6 @@ __webpack_require__.t = function(value, mode) { __webpack_require__.d(ns, def); return ns; }; - })(); // webpack/runtime/define_property_getters (() => { From 6e05d327ae7efb03bed231d843d2a0c739bbb93d Mon Sep 17 00:00:00 2001 From: LingyuCoder Date: Thu, 11 Jun 2026 18:51:29 +0800 Subject: [PATCH 07/21] fix(runtime): address runtime mode review feedback --- .../src/container/container_entry_module.rs | 6 ++-- .../src/helper/hot-update/plugin.ts | 16 +++------- tests/rspack-test/RuntimeModeHotNode.test.js | 29 +++++++++++++++++-- tests/rspack-test/RuntimeModeHotWeb.test.js | 28 ++++++++++++++++-- .../rspack-test/RuntimeModeHotWorker.test.js | 29 +++++++++++++++++-- .../existing-name/index.js | 9 ++++-- .../index.js | 9 ++++-- .../depend-on-with-chunk-load/index.js | 13 ++++----- .../rspack.config.js | 9 ++++++ .../chunk-loading/worker-loader/index.js | 6 +++- .../import-export-format-2/index.js | 20 +++++-------- .../import-export-format/index.js | 12 ++++---- .../re-export-namespace-concat/index.js | 15 ++++++---- .../re-export-namespace/index.js | 15 ++++++---- .../css/no-extra-js-exports-output/test.js | 6 +++- .../externals/commonjs-import/index.js | 11 ++++--- .../import-attributes/rspack.config.js | 29 ++++++++++--------- .../externals/reexport-star/index.js | 9 ++++-- .../script-externals-dynamic-import/index.js | 11 ++++--- .../rspack.config.js | 9 ++++-- .../hooks/rspack-issue-5571/index.js | 14 ++++----- .../inline-const/provide-plugin/index.js | 12 ++++---- .../configCases/library/esm-external/index.js | 13 +++++---- .../rspack.config.js | 14 +++++---- .../render-order-issue/rspack.config.js | 13 +++++++-- .../module/consume-webpack-runtime/index.js | 26 +++++++++++++---- .../output/pathinfo-verbose/index.js | 21 +++++++++----- .../parsing/eval-cjs-typeof/index.js | 2 +- .../parsing/require-alias-disabled/index.js | 9 +++--- .../parsing/require-alias-enabled/index.js | 15 ++++++---- .../plugins/minify-module/index.js | 4 ++- .../plugins/minify-parser/index.js | 2 +- .../rsdoctor/assets/rspack.config.js | 4 +-- .../configCases/rstest/mock/rspack.config.js | 16 ++++++---- .../rstest/require-resolve-origin/index.js | 14 +++++---- .../index.js | 6 +++- .../dynamic-css-chunk-with-hash/index.js | 12 ++++++-- .../runtime/dynamic-css-chunk/index.js | 12 ++++++-- .../runtime/runtime-condition/a.js | 15 ++++++---- .../index.js | 2 +- .../runtime/split-css-chunk-async/index1.js | 6 +++- .../runtime/split-css-chunk/index1.js | 6 +++- .../source-map/verify-css-js-mix/index.js | 9 ++---- .../source-map/verify-es6/index.js | 24 ++++++++++----- .../module-runtime-requirement/index.js | 2 +- .../trusted-types/web-worker/index.js | 27 +++++++++-------- .../umd/issue-15545/rspack.config.js | 2 +- .../configCases/unique-id/all/index.js | 12 ++++---- .../configCases/unique-id/array/index.js | 12 ++++---- .../configCases/version/all/index.js | 12 ++++---- .../configCases/version/array/index.js | 12 ++++---- .../share-plugin/__snapshots__/web/1.snap.txt | 3 +- .../immutable/__snapshots__/stats.txt | 2 +- .../benches/groups/scan_dependencies.rs | 2 +- 54 files changed, 409 insertions(+), 239 deletions(-) diff --git a/crates/rspack_plugin_mf/src/container/container_entry_module.rs b/crates/rspack_plugin_mf/src/container/container_entry_module.rs index cda7bc42ebb8..dfb7cbb4da98 100644 --- a/crates/rspack_plugin_mf/src/container/container_entry_module.rs +++ b/crates/rspack_plugin_mf/src/container/container_entry_module.rs @@ -276,7 +276,7 @@ impl Module for ContainerEntryModule { } } - let federation_global = format!("{}.federation", require_name); + let federation_global = format!("{require_name}.federation"); // Generate installInitialConsumes function using returning_function let install_initial_consumes_call = format!( @@ -346,8 +346,8 @@ impl Module for ContainerEntryModule { let source = if self.enhanced { let define_property_getters = runtime_template.render_runtime_globals(&RuntimeGlobals::DEFINE_PROPERTY_GETTERS); - let get_container = format!("{}.getContainer", require_name); - let init_container = format!("{}.initContainer", require_name); + let get_container = format!("{require_name}.getContainer"); + let init_container = format!("{require_name}.initContainer"); format!( r#" diff --git a/packages/rspack-test-tools/src/helper/hot-update/plugin.ts b/packages/rspack-test-tools/src/helper/hot-update/plugin.ts index c8879b47e884..e507b66948aa 100644 --- a/packages/rspack-test-tools/src/helper/hot-update/plugin.ts +++ b/packages/rspack-test-tools/src/helper/hot-update/plugin.ts @@ -168,25 +168,17 @@ export class HotUpdatePlugin { PLUGIN_NAME, (module: any, _set: any) => { if ( - module.constructor.name === 'DefinePropertyGettersRuntimeModule' + module.constructor.name === 'DefinePropertyGettersRuntimeModule' && + compiler.options.experiments?.runtimeMode !== 'rspack' ) { - const runtimeMode = compiler.options.experiments?.runtimeMode; - const definePropertyGetters = - runtimeMode === 'rspack' - ? 'definePropertyGetters' - : RuntimeGlobals.definePropertyGetters; - const hasOwnProperty = - runtimeMode === 'rspack' - ? 'hasOwnProperty' - : RuntimeGlobals.hasOwnProperty; // HMR tests re-execute modules and redefine the same export keys, so // the test-only runtime keeps export descriptors configurable (`configurable: true`). module.source.source = Buffer.from( ` -${definePropertyGetters} = function (exports, getters, values) { +${RuntimeGlobals.definePropertyGetters} = function (exports, getters, values) { var define = function (defs, kind) { for(var key in defs) { - if(${hasOwnProperty}(defs, key) && !${hasOwnProperty}(exports, key)) { + if(${RuntimeGlobals.hasOwnProperty}(defs, key) && !${RuntimeGlobals.hasOwnProperty}(exports, key)) { Object.defineProperty(exports, key, { configurable: true, enumerable: true, [kind]: defs[key] }); } } diff --git a/tests/rspack-test/RuntimeModeHotNode.test.js b/tests/rspack-test/RuntimeModeHotNode.test.js index d82f4221bf3e..edff44c52548 100644 --- a/tests/rspack-test/RuntimeModeHotNode.test.js +++ b/tests/rspack-test/RuntimeModeHotNode.test.js @@ -1,3 +1,26 @@ -describe.skip("runtimeModeHotNode", () => { - it("filtered by unsupported custom runtime source", () => {}); -}); +const path = require("path"); +const { describeByWalk, createHotCase } = require("@rspack/test-tools"); +const tempDir = path.resolve(__dirname, `./js/temp/runtime-mode-hot-node`); + +describeByWalk( + __filename, + (name, src, dist) => { + createHotCase( + name, + src, + dist, + path.join(tempDir, name), + "async-node", + { + experiments: { + runtimeMode: "rspack" + } + } + ); + }, + { + source: path.resolve(__dirname, "./hotCases"), + dist: path.resolve(__dirname, `./js/runtime-mode-hot-node`), + exclude: [/^css$/] + } +); diff --git a/tests/rspack-test/RuntimeModeHotWeb.test.js b/tests/rspack-test/RuntimeModeHotWeb.test.js index 2b1df978fc2a..eb22fe729280 100644 --- a/tests/rspack-test/RuntimeModeHotWeb.test.js +++ b/tests/rspack-test/RuntimeModeHotWeb.test.js @@ -1,3 +1,25 @@ -describe.skip("runtimeModeHotWeb", () => { - it("filtered by unsupported custom runtime source", () => {}); -}); +const path = require("path"); +const { describeByWalk, createHotCase } = require("@rspack/test-tools"); +const tempDir = path.resolve(__dirname, `./js/temp/runtime-mode-hot-web`); + +describeByWalk( + __filename, + (name, src, dist) => { + createHotCase( + name, + src, + dist, + path.join(tempDir, name), + "web", + { + experiments: { + runtimeMode: "rspack" + } + } + ); + }, + { + source: path.resolve(__dirname, "./hotCases"), + dist: path.resolve(__dirname, `./js/runtime-mode-hot-web`) + } +); diff --git a/tests/rspack-test/RuntimeModeHotWorker.test.js b/tests/rspack-test/RuntimeModeHotWorker.test.js index 41cfdd837ebe..3b7edd8dcc46 100644 --- a/tests/rspack-test/RuntimeModeHotWorker.test.js +++ b/tests/rspack-test/RuntimeModeHotWorker.test.js @@ -1,3 +1,26 @@ -describe.skip("runtimeModeHotWorker", () => { - it("filtered by unsupported custom runtime source", () => {}); -}); +const path = require("path"); +const { describeByWalk, createHotCase } = require("@rspack/test-tools"); +const tempDir = path.resolve(__dirname, `./js/temp/runtime-mode-hot-worker`); + +describeByWalk( + __filename, + (name, src, dist) => { + createHotCase( + name, + src, + dist, + path.join(tempDir, name), + "webworker", + { + experiments: { + runtimeMode: "rspack" + } + } + ); + }, + { + source: path.resolve(__dirname, "./hotCases"), + dist: path.resolve(__dirname, `./js/runtime-mode-hot-worker`), + exclude: [/^css$/] + } +); diff --git a/tests/rspack-test/configCases/async-commons-chunk/existing-name/index.js b/tests/rspack-test/configCases/async-commons-chunk/existing-name/index.js index e5939dcf95ff..0a0069871dba 100644 --- a/tests/rspack-test/configCases/async-commons-chunk/existing-name/index.js +++ b/tests/rspack-test/configCases/async-commons-chunk/existing-name/index.js @@ -1,6 +1,9 @@ -const runtime = globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK - ? __rspack_context - : __webpack_require__; +let runtime; +if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + runtime = __rspack_context; +} else { + runtime = __webpack_require__; +} const chunkLoadingSpy = rstest.spyOn(runtime, "e"); it("should not have duplicate chunks in blocks", () => new Promise((resolve, reject) => { diff --git a/tests/rspack-test/configCases/chunk-ids/stable-chunk-ids-with-duplicate-chunks/index.js b/tests/rspack-test/configCases/chunk-ids/stable-chunk-ids-with-duplicate-chunks/index.js index b98e15a48b12..61aa08cf42a9 100644 --- a/tests/rspack-test/configCases/chunk-ids/stable-chunk-ids-with-duplicate-chunks/index.js +++ b/tests/rspack-test/configCases/chunk-ids/stable-chunk-ids-with-duplicate-chunks/index.js @@ -15,8 +15,11 @@ it("should have stable chunkIds and chunk content", async () => { snapshot += `${key}\n\n::\n\n${content}\n`; snapshot += '==============================================================\n'; } - const snapshotDir = globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK - ? path.join(__SNAPSHOT__, "runtimeModeSnapshot") - : __SNAPSHOT__; + let snapshotDir; + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + snapshotDir = path.join(__SNAPSHOT__, "runtimeModeSnapshot"); + } else { + snapshotDir = __SNAPSHOT__; + } expect(snapshot).toMatchFileSnapshotSync(path.join(snapshotDir, 'snapshot.txt')); }) diff --git a/tests/rspack-test/configCases/chunk-loading/depend-on-with-chunk-load/index.js b/tests/rspack-test/configCases/chunk-loading/depend-on-with-chunk-load/index.js index d8e3b5c70232..f43995bcb820 100644 --- a/tests/rspack-test/configCases/chunk-loading/depend-on-with-chunk-load/index.js +++ b/tests/rspack-test/configCases/chunk-loading/depend-on-with-chunk-load/index.js @@ -6,12 +6,9 @@ it("should have runtime __webpack_require__.f.j", async () => { const path = __non_webpack_require__("path"); const fs = __non_webpack_require__("fs"); const code = await fs.promises.readFile(path.resolve(__dirname, "runtime.js"), "utf-8"); - const isRspackRuntime = typeof __rspack_context !== "undefined"; - expect( - code.includes( - isRspackRuntime - ? "ensureChunkHandlers.j" - : "__webpack_require__.f.j" - ) - ).toBe(true); + if (__RSPACK_TEST_RUNTIME_MODE_RSPACK__) { + expect(code.includes("ensureChunkHandlers.j")).toBe(true); + } else { + expect(code.includes("__webpack_require__.f.j")).toBe(true); + } }) diff --git a/tests/rspack-test/configCases/chunk-loading/depend-on-with-chunk-load/rspack.config.js b/tests/rspack-test/configCases/chunk-loading/depend-on-with-chunk-load/rspack.config.js index 41b3d8bbd630..f91162efa5fc 100644 --- a/tests/rspack-test/configCases/chunk-loading/depend-on-with-chunk-load/rspack.config.js +++ b/tests/rspack-test/configCases/chunk-loading/depend-on-with-chunk-load/rspack.config.js @@ -1,3 +1,5 @@ +const rspack = require("@rspack/core"); + /** @type {import("@rspack/core").Configuration} */ module.exports = { entry: { @@ -17,4 +19,11 @@ module.exports = { node: { __dirname: false, }, + plugins: [ + new rspack.DefinePlugin({ + __RSPACK_TEST_RUNTIME_MODE_RSPACK__: JSON.stringify( + Boolean(globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK), + ), + }), + ], }; diff --git a/tests/rspack-test/configCases/chunk-loading/worker-loader/index.js b/tests/rspack-test/configCases/chunk-loading/worker-loader/index.js index a00a70e8b6bd..ba9758d3c028 100644 --- a/tests/rspack-test/configCases/chunk-loading/worker-loader/index.js +++ b/tests/rspack-test/configCases/chunk-loading/worker-loader/index.js @@ -4,5 +4,9 @@ import Worker from "worker-rspack-loader!./worker.js" it("should contain import-scripts chunkLoading runtime", () => { Worker; let file = fs.readFileSync(__dirname + "/bundle0.worker.js", "utf-8") - expect(file).toContain(globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK ? "ensureChunkHandlers.i" : "__webpack_require__.f.i") + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + expect(file).toContain("ensureChunkHandlers.i") + } else { + expect(file).toContain("__webpack_require__.f.i") + } }) diff --git a/tests/rspack-test/configCases/code-generation/import-export-format-2/index.js b/tests/rspack-test/configCases/code-generation/import-export-format-2/index.js index 8b00871d0e47..b31072b6faa2 100644 --- a/tests/rspack-test/configCases/code-generation/import-export-format-2/index.js +++ b/tests/rspack-test/configCases/code-generation/import-export-format-2/index.js @@ -36,19 +36,13 @@ it("should use the same accessor syntax for import and export", function () { expectSourceToContain(source, "bar: bar"); // Checking formation of imports - const isRspackRuntime = typeof __rspack_context !== "undefined"; - expectSourceToMatch( - source, - isRspackRuntime - ? `${regexEscape("const { harmonyexport_cjsimport } = (__rspack_context.r(")}\\d+${regexEscape(")/* .bar */.bar);")}` - : `${regexEscape("const { harmonyexport_cjsimport } = (__webpack_require__(")}\\d+${regexEscape(")/* .bar */.bar);")}` - ); - expectSourceToMatch( - source, - isRspackRuntime - ? `${regexEscape("const harmonyexport_cjsimportdefault = (__rspack_context.r(")}\\d+${regexEscape(")/* [\"default\"] */[\"default\"]);")}` - : `${regexEscape("const harmonyexport_cjsimportdefault = (__webpack_require__(")}\\d+${regexEscape(")/* [\"default\"] */[\"default\"]);")}` - ); + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + expectSourceToMatch(source, `${regexEscape("const { harmonyexport_cjsimport } = (__rspack_context.r(")}\\d+${regexEscape(")/* .bar */.bar);")}`); + expectSourceToMatch(source, `${regexEscape("const harmonyexport_cjsimportdefault = (__rspack_context.r(")}\\d+${regexEscape(")/* [\"default\"] */[\"default\"]);")}`); + } else { + expectSourceToMatch(source, `${regexEscape("const { harmonyexport_cjsimport } = (__webpack_require__(")}\\d+${regexEscape(")/* .bar */.bar);")}`); + expectSourceToMatch(source, `${regexEscape("const harmonyexport_cjsimportdefault = (__webpack_require__(")}\\d+${regexEscape(")/* [\"default\"] */[\"default\"]);")}`); + } // Checking concatenatedmodule.js formation of exports expectSourceToContain(source, "mod3: () => (/* reexport */ harmony_module_3_namespaceObject)"); diff --git a/tests/rspack-test/configCases/code-generation/import-export-format/index.js b/tests/rspack-test/configCases/code-generation/import-export-format/index.js index b626cd2baadb..9790f3af98cc 100644 --- a/tests/rspack-test/configCases/code-generation/import-export-format/index.js +++ b/tests/rspack-test/configCases/code-generation/import-export-format/index.js @@ -34,13 +34,11 @@ it("should use the same accessor syntax for import and export", function () { // Checking formation of imports expectSourceToContain(source, "harmony_module/* .bar */.a;"); - const isRspackRuntime = typeof __rspack_context !== "undefined"; - expectSourceToMatch( - source, - isRspackRuntime - ? `${regexEscape("const { harmonyexport_cjsimport } = (__rspack_context.r(")}\\d+${regexEscape(")/* .bar */.a);")}` - : `${regexEscape("const { harmonyexport_cjsimport } = (__webpack_require__(")}\\d+${regexEscape(")/* .bar */.a);")}` - ); + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + expectSourceToMatch(source, `${regexEscape("const { harmonyexport_cjsimport } = (__rspack_context.r(")}\\d+${regexEscape(")/* .bar */.a);")}`); + } else { + expectSourceToMatch(source, `${regexEscape("const { harmonyexport_cjsimport } = (__webpack_require__(")}\\d+${regexEscape(")/* .bar */.a);")}`); + } // Checking concatenatedmodule.js formation of exports expectSourceToContain(source, "a: () => (/* reexport */ harmony_module_3_namespaceObject)"); diff --git a/tests/rspack-test/configCases/code-generation/re-export-namespace-concat/index.js b/tests/rspack-test/configCases/code-generation/re-export-namespace-concat/index.js index 000725de8a14..957c1eae824c 100644 --- a/tests/rspack-test/configCases/code-generation/re-export-namespace-concat/index.js +++ b/tests/rspack-test/configCases/code-generation/re-export-namespace-concat/index.js @@ -70,12 +70,15 @@ it("should use/preserve accessor form for import object and namespaces", functio expectSourceToContain(source, 'const bb = module1.obj1.up.down?.left.right;'); - const requireExpression = globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK - ? "__rspack_context.r" - : "__webpack_require__"; - expectSourceToMatch(source, `${regexEscape(`const ww = (${requireExpression}(`)}\\d+${regexEscape(')/* .obj1.bing.bang */.obj1.bing.bang);')}`); - expectSourceToMatch(source, `${regexEscape(`const xx = (${requireExpression}(`)}\\d+${regexEscape(')/* .obj1.pip.pop */.obj1.pip.pop)();')}`); - expectSourceToMatch(source, `${regexEscape(`const yy = (${requireExpression}(`)}\\d+${regexEscape(')/* .m_2.m_1.obj1.tip.top */.a.a.obj1.tip.top)();')}`); + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + expectSourceToMatch(source, `${regexEscape('const ww = (__rspack_context.r(')}\\d+${regexEscape(')/* .obj1.bing.bang */.obj1.bing.bang);')}`); + expectSourceToMatch(source, `${regexEscape('const xx = (__rspack_context.r(')}\\d+${regexEscape(')/* .obj1.pip.pop */.obj1.pip.pop)();')}`); + expectSourceToMatch(source, `${regexEscape('const yy = (__rspack_context.r(')}\\d+${regexEscape(')/* .m_2.m_1.obj1.tip.top */.a.a.obj1.tip.top)();')}`); + } else { + expectSourceToMatch(source, `${regexEscape('const ww = (__webpack_require__(')}\\d+${regexEscape(')/* .obj1.bing.bang */.obj1.bing.bang);')}`); + expectSourceToMatch(source, `${regexEscape('const xx = (__webpack_require__(')}\\d+${regexEscape(')/* .obj1.pip.pop */.obj1.pip.pop)();')}`); + expectSourceToMatch(source, `${regexEscape('const yy = (__webpack_require__(')}\\d+${regexEscape(')/* .m_2.m_1.obj1.tip.top */.a.a.obj1.tip.top)();')}`); + } expectSourceToContain(source, 'data_namespaceObject.a.a.unknownProperty.depth = "deep";'); diff --git a/tests/rspack-test/configCases/code-generation/re-export-namespace/index.js b/tests/rspack-test/configCases/code-generation/re-export-namespace/index.js index 260c9a9c8c8e..306fea9d00b0 100644 --- a/tests/rspack-test/configCases/code-generation/re-export-namespace/index.js +++ b/tests/rspack-test/configCases/code-generation/re-export-namespace/index.js @@ -69,12 +69,15 @@ it("should use/preserve accessor form for import object and namespaces", functio expectSourceToContain(source, 'const bb = _module1__rspack_import_1.obj1.up.down?.left.right;'); - const requireExpression = globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK - ? "__rspack_context.r" - : "__webpack_require__"; - expectSourceToContain(source, `const ww = (${requireExpression}(602)/* .obj1.bing.bang */.obj1.bing.bang);`); - expectSourceToContain(source, `const xx = (${requireExpression}(602)/* .obj1.pip.pop */.obj1.pip.pop)();`); - expectSourceToContain(source, `const yy = (${requireExpression}(144)/* .m_2.m_1.obj1.tip.top */.m_2.m_1.obj1.tip.top)();`); + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + expectSourceToContain(source, 'const ww = (__rspack_context.r(602)/* .obj1.bing.bang */.obj1.bing.bang);'); + expectSourceToContain(source, 'const xx = (__rspack_context.r(602)/* .obj1.pip.pop */.obj1.pip.pop)();'); + expectSourceToContain(source, 'const yy = (__rspack_context.r(144)/* .m_2.m_1.obj1.tip.top */.m_2.m_1.obj1.tip.top)();'); + } else { + expectSourceToContain(source, 'const ww = (__webpack_require__(602)/* .obj1.bing.bang */.obj1.bing.bang);'); + expectSourceToContain(source, 'const xx = (__webpack_require__(602)/* .obj1.pip.pop */.obj1.pip.pop)();'); + expectSourceToContain(source, 'const yy = (__webpack_require__(144)/* .m_2.m_1.obj1.tip.top */.m_2.m_1.obj1.tip.top)();'); + } expectSourceToContain(source, '_data__rspack_import_0.nested.object3.unknownProperty.depth = "deep";'); diff --git a/tests/rspack-test/configCases/css/no-extra-js-exports-output/test.js b/tests/rspack-test/configCases/css/no-extra-js-exports-output/test.js index de33dd4c4daa..6d7a3afbdbd7 100644 --- a/tests/rspack-test/configCases/css/no-extra-js-exports-output/test.js +++ b/tests/rspack-test/configCases/css/no-extra-js-exports-output/test.js @@ -12,7 +12,11 @@ it("should work", () => { // ./a.css // and it still output two runtime module: // 'webpack/runtime/css loading' - expect([3, 4]).toContain(stats.modules.length); + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + expect(stats.modules.length).toBe(4); + } else { + expect(stats.modules.length).toBe(3); + } } else if (__STATS_I__ === 1) { stats.modules .filter(module => module.moduleType === "css/auto") diff --git a/tests/rspack-test/configCases/externals/commonjs-import/index.js b/tests/rspack-test/configCases/externals/commonjs-import/index.js index 888443d36dc1..d41308709ed1 100644 --- a/tests/rspack-test/configCases/externals/commonjs-import/index.js +++ b/tests/rspack-test/configCases/externals/commonjs-import/index.js @@ -4,13 +4,12 @@ const readCase = (name)=> fs.readFileSync(path.resolve(__dirname, `${name}.js`), const caseContent = readCase("case"); it("dynamic import should be preserved, others should be in commonjs external", function () { - const isRspackRuntime = typeof __rspack_context !== "undefined"; expect(caseContent).toContain(`import("external2-alias")`) expect(caseContent).toContain(`require("external1-alias")`) expect(caseContent).not.toContain(`require("external2-alias")`) - expect(caseContent).toContain( - isRspackRuntime - ? `const e2 = Promise.resolve(/* import() */).then(__rspack_context.r.bind(__rspack_context.r, ` - : `const e2 = Promise.resolve(/* import() */).then(__webpack_require__.bind(__webpack_require__, ` - ) + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + expect(caseContent).toContain(`const e2 = Promise.resolve(/* import() */).then(__rspack_context.r.bind(__rspack_context.r, `) + } else { + expect(caseContent).toContain(`const e2 = Promise.resolve(/* import() */).then(__webpack_require__.bind(__webpack_require__, `) + } }); diff --git a/tests/rspack-test/configCases/externals/import-attributes/rspack.config.js b/tests/rspack-test/configCases/externals/import-attributes/rspack.config.js index 4f567ff0cd62..e2afd26c4782 100644 --- a/tests/rspack-test/configCases/externals/import-attributes/rspack.config.js +++ b/tests/rspack-test/configCases/externals/import-attributes/rspack.config.js @@ -53,20 +53,21 @@ module.exports = { /import (.+) from "\.\/static-package\.json";/, ); expect(esmImportSpecifier1[1]).not.toBe(esmImportSpecifier2[1]); - const runtimeRequire = - globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK - ? '__rspack_context\\.e' - : '__webpack_require__\\.e'; - const importChunkId1 = content.match( - new RegExp( - `const dynamicPkgPure = await ${runtimeRequire}\\(/\\* import\\(\\) \\*/ (?:"([^"]+)"|([0-9]+))\\)`, - ), - ); - const importChunkId2 = content.match( - new RegExp( - `const dynamicPkgStr = await ${runtimeRequire}\\(/\\* import\\(\\) \\*/ (?:"([^"]+)"|([0-9]+))\\)`, - ), - ); + let dynamicPkgPurePattern; + let dynamicPkgStrPattern; + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + dynamicPkgPurePattern = + /const dynamicPkgPure = await __rspack_context\.e\(\/\* import\(\) \*\/ (?:"([^"]+)"|([0-9]+))\)/; + dynamicPkgStrPattern = + /const dynamicPkgStr = await __rspack_context\.e\(\/\* import\(\) \*\/ (?:"([^"]+)"|([0-9]+))\)/; + } else { + dynamicPkgPurePattern = + /const dynamicPkgPure = await __webpack_require__\.e\(\/\* import\(\) \*\/ (?:"([^"]+)"|([0-9]+))\)/; + dynamicPkgStrPattern = + /const dynamicPkgStr = await __webpack_require__\.e\(\/\* import\(\) \*\/ (?:"([^"]+)"|([0-9]+))\)/; + } + const importChunkId1 = content.match(dynamicPkgPurePattern); + const importChunkId2 = content.match(dynamicPkgStrPattern); const dynamicPkgPureChunkId = importChunkId1[1] ?? importChunkId1[2]; const dynamicPkgStrChunkId = diff --git a/tests/rspack-test/configCases/externals/reexport-star/index.js b/tests/rspack-test/configCases/externals/reexport-star/index.js index 9635c729a698..772708d7e866 100644 --- a/tests/rspack-test/configCases/externals/reexport-star/index.js +++ b/tests/rspack-test/configCases/externals/reexport-star/index.js @@ -1,9 +1,12 @@ const fs = require("fs"); const path = require("path"); const readCase = (name) => fs.readFileSync(path.resolve(__dirname, `${name}.mjs`), "utf-8"); -const snapshotDir = typeof __rspack_context !== "undefined" - ? path.join(__SNAPSHOT__, "runtimeModeSnapshot") - : __SNAPSHOT__; +let snapshotDir; +if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + snapshotDir = path.join(__SNAPSHOT__, "runtimeModeSnapshot"); +} else { + snapshotDir = __SNAPSHOT__; +} it("reexport star from external module", function () { expect(readCase("case1")).toMatchFileSnapshotSync(path.join(snapshotDir, 'case1.txt')); diff --git a/tests/rspack-test/configCases/externals/script-externals-dynamic-import/index.js b/tests/rspack-test/configCases/externals/script-externals-dynamic-import/index.js index 8f12bb35b9b8..ec57a654bb31 100644 --- a/tests/rspack-test/configCases/externals/script-externals-dynamic-import/index.js +++ b/tests/rspack-test/configCases/externals/script-externals-dynamic-import/index.js @@ -6,11 +6,10 @@ const readCase = (name)=> fs.readFileSync(path.resolve(__dirname, `${name}.js`), const caseContent = readCase("case"); it("dynamic import script externals module should be returned", function () { - const isRspackRuntime = typeof __rspack_context !== "undefined"; - expect(caseContent).toContain( - isRspackRuntime - ? `return __rspack_context.t(m, 22)` - : `return __webpack_require__.t(m, 22)` - ) + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + expect(caseContent).toContain(`return __rspack_context.t(m, 22)`) + } else { + expect(caseContent).toContain(`return __webpack_require__.t(m, 22)`) + } }); diff --git a/tests/rspack-test/configCases/hooks/modify-extract-css-loading-runtime/rspack.config.js b/tests/rspack-test/configCases/hooks/modify-extract-css-loading-runtime/rspack.config.js index db52624d953e..4e467ee8fdfe 100644 --- a/tests/rspack-test/configCases/hooks/modify-extract-css-loading-runtime/rspack.config.js +++ b/tests/rspack-test/configCases/hooks/modify-extract-css-loading-runtime/rspack.config.js @@ -10,9 +10,12 @@ class Plugin { 'webpack/runtime/css loading', ); const originSource = module.source.source.toString('utf-8'); - const runtimeSource = globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK - ? '__rspack_context.f.miniCss.test = true;' - : '__webpack_require__.f.miniCss.test = true;'; + let runtimeSource; + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + runtimeSource = '__rspack_context.f.miniCss.test = true;'; + } else { + runtimeSource = '__webpack_require__.f.miniCss.test = true;'; + } module.source.source = Buffer.from( `${originSource}\n${runtimeSource}\n`, 'utf-8', diff --git a/tests/rspack-test/configCases/hooks/rspack-issue-5571/index.js b/tests/rspack-test/configCases/hooks/rspack-issue-5571/index.js index 2ead1a52c840..896898b36d57 100644 --- a/tests/rspack-test/configCases/hooks/rspack-issue-5571/index.js +++ b/tests/rspack-test/configCases/hooks/rspack-issue-5571/index.js @@ -11,12 +11,10 @@ it("should modify runtime module source in main", () => { it("should has css loading hmr runtime requirements", () => { const name = "hmrC.css"; - const isRspackRuntime = typeof __rspack_context !== "undefined"; - expect( - fs.readFileSync(path.join(__dirname, "./bundle0.js"), "utf-8") - ).toContain( - isRspackRuntime - ? "__rspack_hmrDownloadUpdateHandlers.css = " - : "__webpack_require__." + name + " = " - ); + const source = fs.readFileSync(path.join(__dirname, "./bundle0.js"), "utf-8"); + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + expect(source).toContain("__rspack_hmrDownloadUpdateHandlers.css = "); + } else { + expect(source).toContain("__webpack_require__." + name + " = "); + } }); diff --git a/tests/rspack-test/configCases/inline-const/provide-plugin/index.js b/tests/rspack-test/configCases/inline-const/provide-plugin/index.js index 40f6a735ed79..17b5d6fcf5f0 100644 --- a/tests/rspack-test/configCases/inline-const/provide-plugin/index.js +++ b/tests/rspack-test/configCases/inline-const/provide-plugin/index.js @@ -7,11 +7,13 @@ it("should provide inlined const exports", () => { expect(providedDefault).toBe(2); // END:A const block = generated.match(/([\s\S]*?)\/\/ START:A[\s\S]*?\/\/ END:A/)[1]; - const requireExpression = typeof __rspack_context !== "undefined" - ? "__rspack_context.r" - : "__webpack_require__"; - expect(block.includes(`/* provided dependency */ var providedA = (${requireExpression}("./constants.js"), (/* inlined export .a */1));`)).toBe(true); - expect(block.includes(`/* provided dependency */ var providedDefault = (${requireExpression}("./constants.js"), (/* inlined export ["default"] */2));`)).toBe(true); + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + expect(block.includes(`/* provided dependency */ var providedA = (__rspack_context.r("./constants.js"), (/* inlined export .a */1));`)).toBe(true); + expect(block.includes(`/* provided dependency */ var providedDefault = (__rspack_context.r("./constants.js"), (/* inlined export ["default"] */2));`)).toBe(true); + } else { + expect(block.includes(`/* provided dependency */ var providedA = (__webpack_require__("./constants.js"), (/* inlined export .a */1));`)).toBe(true); + expect(block.includes(`/* provided dependency */ var providedDefault = (__webpack_require__("./constants.js"), (/* inlined export ["default"] */2));`)).toBe(true); + } expect(globalThis.__rspackProvideConstSideEffect).toBe(1); delete globalThis.__rspackProvideConstSideEffect; }); diff --git a/tests/rspack-test/configCases/library/esm-external/index.js b/tests/rspack-test/configCases/library/esm-external/index.js index 04bffcb1de3a..4c4fec2275d4 100644 --- a/tests/rspack-test/configCases/library/esm-external/index.js +++ b/tests/rspack-test/configCases/library/esm-external/index.js @@ -14,17 +14,20 @@ it("should run", function () { }); it("should export module library", function () { const __filename = url.fileURLToPath(import.meta.url); - const runtimeModeOutput = typeof __rspack_context !== "undefined"; + let outputPath; + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + outputPath = "../../../../js/runtime-mode-config/library/esm-external/bundle0.mjs"; + } else { + outputPath = "../../../../js/config/library/esm-external/bundle0.mjs"; + } const source = fs.readFileSync( path.join( __filename, - runtimeModeOutput - ? "../../../../js/runtime-mode-config/library/esm-external/bundle0.mjs" - : "../../../../js/config/library/esm-external/bundle0.mjs" + outputPath ), "utf-8" ); - if (runtimeModeOutput) { + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { expect(source).toContain('__rspack_context.r("node:fs")'); } else { const createRequire = "__rspack_createRequire_require"; diff --git a/tests/rspack-test/configCases/library/modern-module-export-char/rspack.config.js b/tests/rspack-test/configCases/library/modern-module-export-char/rspack.config.js index 506d5648a366..1f31e2d1b7cb 100644 --- a/tests/rspack-test/configCases/library/modern-module-export-char/rspack.config.js +++ b/tests/rspack-test/configCases/library/modern-module-export-char/rspack.config.js @@ -24,11 +24,15 @@ module.exports = { const handler = (compilation) => { compilation.hooks.afterProcessAssets.tap('testcase', (assets) => { const bundle = Object.values(assets)[0]._value; - expect(bundle).toContain( - globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK - ? `var foo_default = /*#__PURE__*/__rspack_context.n(foo);\nvar foo_default_0 = foo_default();` - : `var foo_default = /*#__PURE__*/__webpack_require__.n(foo);\nvar foo_default_0 = foo_default();`, - ); + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + expect(bundle).toContain( + `var foo_default = /*#__PURE__*/__rspack_context.n(foo);\nvar foo_default_0 = foo_default();`, + ); + } else { + expect(bundle).toContain( + `var foo_default = /*#__PURE__*/__webpack_require__.n(foo);\nvar foo_default_0 = foo_default();`, + ); + } expect(bundle).toContain('foo_default_0 as cjsInterop'); expect(bundle).toContain( 'export { default as defaultImport, namedImport } from "external-module";', diff --git a/tests/rspack-test/configCases/library/render-order-issue/rspack.config.js b/tests/rspack-test/configCases/library/render-order-issue/rspack.config.js index 34ff59a0c23f..d6a6960dcc48 100644 --- a/tests/rspack-test/configCases/library/render-order-issue/rspack.config.js +++ b/tests/rspack-test/configCases/library/render-order-issue/rspack.config.js @@ -45,9 +45,16 @@ module.exports = { /** @type {Record} */ assets, ) => { const source = assets['entry.mjs'].source(); - const snapshotDir = globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK - ? path.join(__dirname, '__snapshots__', 'runtimeModeSnapshot') - : path.join(__dirname, '__snapshots__'); + let snapshotDir; + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + snapshotDir = path.join( + __dirname, + '__snapshots__', + 'runtimeModeSnapshot', + ); + } else { + snapshotDir = path.join(__dirname, '__snapshots__'); + } expect(source).toMatchFileSnapshotSync( path.join(snapshotDir, `entry.mjs.txt`), ); diff --git a/tests/rspack-test/configCases/module/consume-webpack-runtime/index.js b/tests/rspack-test/configCases/module/consume-webpack-runtime/index.js index 40ae91db4b26..d47643210a2c 100644 --- a/tests/rspack-test/configCases/module/consume-webpack-runtime/index.js +++ b/tests/rspack-test/configCases/module/consume-webpack-runtime/index.js @@ -13,14 +13,16 @@ it("should compile and run", () => { expect(objectExport.foo).toBe(42); expect(defaultUseNested().foo).toBe(42); - const isRspackRuntimeMode = globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK === true; - const path = __non_webpack_require__('path') const fs = __non_webpack_require__('fs') { const content = fs.readFileSync(path.resolve(__dirname, './bundle0.js'), 'utf-8'); const NESTED_RE = /__nested_rspack_require_[A-Za-z0-9_]+__/g; - expect((content.match(NESTED_RE) || []).length).toBe(isRspackRuntimeMode ? 0 : 17); + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + expect((content.match(NESTED_RE) || []).length).toBe(0); + } else { + expect(content.match(NESTED_RE).length).toBe(17); + } } { @@ -32,7 +34,11 @@ it("should compile and run", () => { { const content = fs.readFileSync(path.resolve(__dirname, './bundle1.js'), 'utf-8'); const NESTED_RE = /__nested_rspack_require_[A-Za-z0-9_]+__/g; - expect((content.match(NESTED_RE) || []).length).toBe(isRspackRuntimeMode ? 0 : 19); + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + expect((content.match(NESTED_RE) || []).length).toBe(0); + } else { + expect(content.match(NESTED_RE).length).toBe(19); + } } { @@ -44,7 +50,11 @@ it("should compile and run", () => { { const content = fs.readFileSync(path.resolve(__dirname, './bundle2.js'), 'utf-8'); const NESTED_RE = /__nested_rspack_require_[A-Za-z0-9_]+__/g; - expect((content.match(NESTED_RE) || []).length).toBe(isRspackRuntimeMode ? 0 : 17); + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + expect((content.match(NESTED_RE) || []).length).toBe(0); + } else { + expect(content.match(NESTED_RE).length).toBe(17); + } } { @@ -56,7 +66,11 @@ it("should compile and run", () => { { const content = fs.readFileSync(path.resolve(__dirname, './bundle3.js'), 'utf-8'); const NESTED_RE = /__nested_rspack_require_[A-Za-z0-9_]+__/g; - expect((content.match(NESTED_RE) || []).length).toBe(isRspackRuntimeMode ? 0 : 19); + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + expect((content.match(NESTED_RE) || []).length).toBe(0); + } else { + expect(content.match(NESTED_RE).length).toBe(19); + } } { diff --git a/tests/rspack-test/configCases/output/pathinfo-verbose/index.js b/tests/rspack-test/configCases/output/pathinfo-verbose/index.js index 5838d2b09939..09d9d8993333 100644 --- a/tests/rspack-test/configCases/output/pathinfo-verbose/index.js +++ b/tests/rspack-test/configCases/output/pathinfo-verbose/index.js @@ -2,23 +2,26 @@ it("should add all modules headers info above modules", () => { const fs = require("fs"); const path = require("path") const content = fs.readFileSync(path.join(__dirname, "sut.js"), "utf-8"); - const runtimeMode = typeof __rspack_context !== "undefined"; - expect(content).toContain((runtimeMode ? ` + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + expect(content).toContain(` /*!****************!*\\ !*** ./sut.js ***! \\****************/ /*! namespace exports */ /*! runtime requirements: __rspack_context.r, __rspack_context */ /*! Statement with side_effects in source code at ./sut.js:3:1-29 */ - ` : ` + `.trim()) + } else { + expect(content).toContain(` /*!****************!*\\ !*** ./sut.js ***! \\****************/ /*! namespace exports */ /*! runtime requirements: __webpack_require__, __webpack_require__ */ /*! Statement with side_effects in source code at ./sut.js:3:1-29 */ - `).trim()) + `.trim()) + } expect(content).toContain(` /*!****************!*\\ @@ -29,7 +32,8 @@ it("should add all modules headers info above modules", () => { /*! Statement with side_effects in source code at ./cjs.js:1:1-3:2 */ `.trim()) - expect(content).toContain((runtimeMode ? ` + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + expect(content).toContain(` /*!*****************!*\\ !*** ./util.js ***! \\*****************/ @@ -39,7 +43,9 @@ it("should add all modules headers info above modules", () => { /*! export secret [maybe provided (runtime-defined)] [used in sut] [provision prevents renaming] -> ./cjs.js secret */ /*! other exports [maybe provided (runtime-defined)] [unused] -> ./cjs.js */ /*! runtime requirements: __webpack_exports__, __rspack_context.r, __rspack_context.o, __rspack_context.n, __rspack_context.d, __rspack_context */ -` : ` +`.trim()) + } else { + expect(content).toContain(` /*!*****************!*\\ !*** ./util.js ***! \\*****************/ @@ -49,7 +55,8 @@ it("should add all modules headers info above modules", () => { /*! export secret [maybe provided (runtime-defined)] [used in sut] [provision prevents renaming] -> ./cjs.js secret */ /*! other exports [maybe provided (runtime-defined)] [unused] -> ./cjs.js */ /*! runtime requirements: __webpack_require__.o, __webpack_require__.n, __webpack_require__.d, __webpack_require__, __webpack_require__, __webpack_exports__ */ -`).trim()) +`.trim()) + } diff --git a/tests/rspack-test/configCases/parsing/eval-cjs-typeof/index.js b/tests/rspack-test/configCases/parsing/eval-cjs-typeof/index.js index a6c8d022bf21..17a30a91ae7e 100644 --- a/tests/rspack-test/configCases/parsing/eval-cjs-typeof/index.js +++ b/tests/rspack-test/configCases/parsing/eval-cjs-typeof/index.js @@ -5,7 +5,7 @@ it("should compile", async () => { throw new Error("wrong") } const file = await fs.promises.readFile(__filename, 'utf-8'); - if (file.includes(["var ", "__rspack_context"].join(""))) { + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { expect(file).not.toContain(['if (', 'ty', 'pe', 'of exports !== "object"', ' || ', 'ty', 'pe', 'of module !== "object"', ')'].join("")) } else { expect(file).not.toContain(["ty", "pe", "of"].join("")) diff --git a/tests/rspack-test/configCases/parsing/require-alias-disabled/index.js b/tests/rspack-test/configCases/parsing/require-alias-disabled/index.js index 3dbb9394cea9..7f535901722b 100644 --- a/tests/rspack-test/configCases/parsing/require-alias-disabled/index.js +++ b/tests/rspack-test/configCases/parsing/require-alias-disabled/index.js @@ -28,14 +28,15 @@ it("should NOT rename require when requireAlias is false", function () { const content = fs.readFileSync(path.join(__dirname, "./bundle0.js"), "utf-8"); const filename = "./file"; - const requireName = globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK - ? "__rspack_context.r(641)" - : "__webpack_require__(641)"; const ok = "ok"; expect(content).toContain(`cjsRequire("${filename}")`); expect(content).toContain(`cjsRequire2("${filename}")`); expect(content).toContain(`cjsRequire3("${filename}")`); - expect(content).toContain(`var cjsRequire = ${requireName}, cjsRequire2 = true && ${requireName};`); + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + expect(content).toContain(`var cjsRequire = __rspack_context.r(641), cjsRequire2 = true && __rspack_context.r(641);`); + } else { + expect(content).toContain(`var cjsRequire = __webpack_require__(641), cjsRequire2 = true && __webpack_require__(641);`); + } expect(content).not.toContain(`module.exports = "${ok}";`); }); diff --git a/tests/rspack-test/configCases/parsing/require-alias-enabled/index.js b/tests/rspack-test/configCases/parsing/require-alias-enabled/index.js index 7693f601b2ee..53962fbae7ca 100644 --- a/tests/rspack-test/configCases/parsing/require-alias-enabled/index.js +++ b/tests/rspack-test/configCases/parsing/require-alias-enabled/index.js @@ -22,14 +22,17 @@ it("should NOT rename require when requireAlias is false", function () { const path = __non_webpack_require__("path"); const content = fs.readFileSync(path.join(__dirname, "./bundle0.js"), "utf-8"); - const requireCall = globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK - ? "__rspack_context\\.r\\(239\\)" - : "__webpack_require__\\(239\\)"; const ok = "ok"; - expect(content).toMatch(new RegExp(`function test\\(\\) \\{\\s*${requireCall};\\s*\\}`, "i")); - expect(content).toMatch(new RegExp(`function test2\\(\\) \\{\\s*${requireCall};\\s*\\}`, "i")); - expect(content).toMatch(new RegExp(`function test3\\(cjsRequire3\\) \\{\\s*${requireCall};\\s*\\}`, "i")); + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + expect(content).toMatch(/function test\(\) \{\s*__rspack_context\.r\(239\);\s*\}/i); + expect(content).toMatch(/function test2\(\) \{\s*__rspack_context\.r\(239\);\s*\}/i); + expect(content).toMatch(/function test3\(cjsRequire3\) \{\s*__rspack_context\.r\(239\);\s*\}/i); + } else { + expect(content).toMatch(/function test\(\) \{\s*__webpack_require__\(239\);\s*\}/i); + expect(content).toMatch(/function test2\(\) \{\s*__webpack_require__\(239\);\s*\}/i); + expect(content).toMatch(/function test3\(cjsRequire3\) \{\s*__webpack_require__\(239\);\s*\}/i); + } expect(content).toContain(`var cjsRequire = undefined, cjsRequire2 = undefined;`); expect(content).toContain(`module.exports = "${ok}";`); }); diff --git a/tests/rspack-test/configCases/plugins/minify-module/index.js b/tests/rspack-test/configCases/plugins/minify-module/index.js index 86213a5e286e..9fc9a9caa76f 100644 --- a/tests/rspack-test/configCases/plugins/minify-module/index.js +++ b/tests/rspack-test/configCases/plugins/minify-module/index.js @@ -6,5 +6,7 @@ it("should minify outputModule", async () => { path.join(__dirname, "./module.mjs"), "utf-8" ); - expect(out).toMatch(/^import \w+ from"https:\/\/test\.rspack\.rs\/test\.js"/); + expect( + out.startsWith('import s from"https://test.rspack.rs/test.js"') + ).toBe(true); }); diff --git a/tests/rspack-test/configCases/plugins/minify-parser/index.js b/tests/rspack-test/configCases/plugins/minify-parser/index.js index 069ea3a277cf..093a2ad9c9f6 100644 --- a/tests/rspack-test/configCases/plugins/minify-parser/index.js +++ b/tests/rspack-test/configCases/plugins/minify-parser/index.js @@ -3,5 +3,5 @@ const path = require("path"); it("[minify-parser]: import attributes should be preserved", () => { const content = fs.readFileSync(path.resolve(__dirname, "importAttributes.js"), "utf-8"); - expect(content).toMatch(/import \w+ from"\.\/a\.json"with\{type:"json"\}/); + expect(content).toContain('import o from"./a.json"with{type:"json"}'); }); diff --git a/tests/rspack-test/configCases/rsdoctor/assets/rspack.config.js b/tests/rspack-test/configCases/rsdoctor/assets/rspack.config.js index 5ab40c9c8cdd..827be3a7fd2f 100644 --- a/tests/rspack-test/configCases/rsdoctor/assets/rspack.config.js +++ b/tests/rspack-test/configCases/rsdoctor/assets/rspack.config.js @@ -23,8 +23,6 @@ module.exports = { }), { apply(compiler) { - const isRspackRuntimeMode = - compiler.options.experiments.runtimeMode === 'rspack'; compiler.hooks.compilation.tap('TestPlugin::Assets', (compilation) => { const hooks = RsdoctorPlugin.getCompilationHooks(compilation); hooks.assets.tap('TestPlugin::Assets', (data) => { @@ -35,7 +33,7 @@ module.exports = { path: a.path, })); assetsInfo.sort((a, b) => (a.path > b.path ? 1 : -1)); - if (isRspackRuntimeMode) { + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { expect(assetsInfo).toEqual([ { path: 'a.js', diff --git a/tests/rspack-test/configCases/rstest/mock/rspack.config.js b/tests/rspack-test/configCases/rstest/mock/rspack.config.js index 5c8346ea8c3b..976a72415a61 100644 --- a/tests/rspack-test/configCases/rstest/mock/rspack.config.js +++ b/tests/rspack-test/configCases/rstest/mock/rspack.config.js @@ -85,11 +85,14 @@ __webpack_require__.rstest_mock = (id, modFactory) => { __webpack_exports__, __webpack_require__, ) { - const __rspack_runtime = __webpack_require__; - (__rspack_runtime.N || __rspack_runtime.r)(__webpack_exports__); + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + __webpack_require__.N(__webpack_exports__); + } else { + __webpack_require__.r(__webpack_exports__); + } const res = modFactory(); for (const key in res) { - __rspack_runtime.d(__webpack_exports__, { + __webpack_require__.d(__webpack_exports__, { [key]: () => res[key], }); } @@ -115,8 +118,11 @@ __webpack_require__.rstest_do_mock = (id, modFactory) => { __webpack_module_cache__[id] = { exports: __webpack_require__(modFactory) }; } else if (typeof modFactory === 'function') { const exports = modFactory(); - const __rspack_runtime = typeof __rspack_context !== 'undefined' ? __rspack_context : __webpack_require__; - (__rspack_runtime.N || __rspack_runtime.r)(exports); + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + __rspack_context.N(exports); + } else { + __webpack_require__.r(exports); + } __webpack_module_cache__[id] = { exports, id, loaded: true }; } }; diff --git a/tests/rspack-test/configCases/rstest/require-resolve-origin/index.js b/tests/rspack-test/configCases/rstest/require-resolve-origin/index.js index 569c115534b1..8b46015fa93b 100644 --- a/tests/rspack-test/configCases/rstest/require-resolve-origin/index.js +++ b/tests/rspack-test/configCases/rstest/require-resolve-origin/index.js @@ -27,11 +27,15 @@ it('rewrites require.resolve calls with source module origin', () => { // Nested require.resolve calls inside arguments should still be rewritten, while // `webpackIgnore` only affects require.resolve when commonjsMagicComments is // enabled, and shadowed require must not be rewritten. - expect(content).toContain( - globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK - ? `${helper}((__rspack_context.r(161)/* .name */.name), ${originLiteral})` - : `${helper}((__webpack_require__(161)/* .name */.name), ${originLiteral})`, - ); + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + expect(content).toContain( + `${helper}((__rspack_context.r(161)/* .name */.name), ${originLiteral})`, + ); + } else { + expect(content).toContain( + `${helper}((__webpack_require__(161)/* .name */.name), ${originLiteral})`, + ); + } expect(content).toContain( `${helper}(/* webpackIgnore: true */ './ignored', ${originLiteral})`, ); diff --git a/tests/rspack-test/configCases/runtime/dynamic-css-chunk-with-content-hash/index.js b/tests/rspack-test/configCases/runtime/dynamic-css-chunk-with-content-hash/index.js index 2c494872047f..18104b5dc0af 100644 --- a/tests/rspack-test/configCases/runtime/dynamic-css-chunk-with-content-hash/index.js +++ b/tests/rspack-test/configCases/runtime/dynamic-css-chunk-with-content-hash/index.js @@ -2,7 +2,11 @@ it("load dynamic css chunk with content hash", async function () { await import("./dynamic").then(module => { expect(module.value).toBe("dynamic"); // test is only for css loading - if (typeof document !== "undefined" && __webpack_require__.f.css) { + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + if (typeof document !== "undefined" && __rspack_context.f.css) { + expect(document.getElementsByTagName("link").length).toBe(1); + } + } else if (__webpack_require__.f.css) { expect(document.getElementsByTagName("link").length).toBe(1); } }); diff --git a/tests/rspack-test/configCases/runtime/dynamic-css-chunk-with-hash/index.js b/tests/rspack-test/configCases/runtime/dynamic-css-chunk-with-hash/index.js index 3611f0e97075..d115f7245aee 100644 --- a/tests/rspack-test/configCases/runtime/dynamic-css-chunk-with-hash/index.js +++ b/tests/rspack-test/configCases/runtime/dynamic-css-chunk-with-hash/index.js @@ -3,13 +3,21 @@ it("load dynamic css chunk with hash", () => new Promise((resolve, reject) => { import("./dynamic").then(module => { expect(module.value).toBe("dynamic"); // test is only for css loading - if (typeof document !== "undefined" && __webpack_require__.f.css) { + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + if (typeof document !== "undefined" && __rspack_context.f.css) { + expect(document.getElementsByTagName("link").length).toBe(1); + } + } else if (__webpack_require__.f.css) { expect(document.getElementsByTagName("link").length).toBe(1); } import("./common").then(module => { expect(module.value).toBe("common"); // test is only for css loading - if (typeof document !== "undefined" && __webpack_require__.f.css) { + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + if (typeof document !== "undefined" && __rspack_context.f.css) { + expect(document.getElementsByTagName("link").length).toBe(1); + } + } else if (__webpack_require__.f.css) { expect(document.getElementsByTagName("link").length).toBe(1); } done(); diff --git a/tests/rspack-test/configCases/runtime/dynamic-css-chunk/index.js b/tests/rspack-test/configCases/runtime/dynamic-css-chunk/index.js index aefa7adb4c79..0ccb32b4b54e 100644 --- a/tests/rspack-test/configCases/runtime/dynamic-css-chunk/index.js +++ b/tests/rspack-test/configCases/runtime/dynamic-css-chunk/index.js @@ -3,13 +3,21 @@ it("load dynamic css chunk", () => new Promise((resolve, reject) => { import("./dynamic").then(module => { expect(module.value).toBe("dynamic"); // test is only for css loading - if (typeof document !== "undefined" && __webpack_require__.f.css) { + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + if (typeof document !== "undefined" && __rspack_context.f.css) { + expect(document.getElementsByTagName("link").length).toBe(1); + } + } else if (__webpack_require__.f.css) { expect(document.getElementsByTagName("link").length).toBe(1); } import("./common").then(module => { expect(module.value).toBe("common"); // test is only for css loading - if (typeof document !== "undefined" && __webpack_require__.f.css) { + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + if (typeof document !== "undefined" && __rspack_context.f.css) { + expect(document.getElementsByTagName("link").length).toBe(1); + } + } else if (__webpack_require__.f.css) { expect(document.getElementsByTagName("link").length).toBe(1); } done(); diff --git a/tests/rspack-test/configCases/runtime/runtime-condition/a.js b/tests/rspack-test/configCases/runtime/runtime-condition/a.js index 91c267f4fff3..01991d2bb477 100644 --- a/tests/rspack-test/configCases/runtime/runtime-condition/a.js +++ b/tests/rspack-test/configCases/runtime/runtime-condition/a.js @@ -17,10 +17,13 @@ it("should include runtime condition check code", () => { ), "utf-8" ); - const runtimeId = typeof __rspack_context !== "undefined" - ? "__rspack_context.j" - : "__webpack_require__.j"; - expect(source).toContain(`"a-runtime" == ${runtimeId}`) - expect(source).toContain(`"b-runtime" == ${runtimeId}`); - expect(source).toContain(`/^[ab]x\\-name$/.test(${runtimeId})`); + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + expect(source).toContain(`"a-runtime" == __rspack_context.j`) + expect(source).toContain(`"b-runtime" == __rspack_context.j`); + expect(source).toContain(`/^[ab]x\\-name$/.test(__rspack_context.j)`); + } else { + expect(source).toContain(`"a-runtime" == __webpack_require__.j`) + expect(source).toContain(`"b-runtime" == __webpack_require__.j`); + expect(source).toContain(`/^[ab]x\\-name$/.test(__webpack_require__.j)`); + } }) diff --git a/tests/rspack-test/configCases/runtime/runtime-mode-nested-rspack-context/index.js b/tests/rspack-test/configCases/runtime/runtime-mode-nested-rspack-context/index.js index 8e3c38b0942f..9caaaaff5a9b 100644 --- a/tests/rspack-test/configCases/runtime/runtime-mode-nested-rspack-context/index.js +++ b/tests/rspack-test/configCases/runtime/runtime-mode-nested-rspack-context/index.js @@ -10,7 +10,7 @@ it("keeps nested __rspack_context binding local", () => { }); it("renames nested __rspack_context in rspack runtime mode", () => { - if (typeof __rspack_context === "undefined") { + if (!globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { return; } const source = require("fs").readFileSync(__filename, "utf-8"); diff --git a/tests/rspack-test/configCases/runtime/split-css-chunk-async/index1.js b/tests/rspack-test/configCases/runtime/split-css-chunk-async/index1.js index 48b5751c0118..5603a4698470 100644 --- a/tests/rspack-test/configCases/runtime/split-css-chunk-async/index1.js +++ b/tests/rspack-test/configCases/runtime/split-css-chunk-async/index1.js @@ -2,7 +2,11 @@ it("should load css chunk", async function () { const module = await import("./share"); expect(module.value).toBe(1); // test is only for css loading - if (typeof document !== "undefined" && __webpack_require__.f.css) { + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + if (typeof document !== "undefined" && __rspack_context.f.css) { + expect(document.getElementsByTagName("link").length).toBe(2); + } + } else if (__webpack_require__.f.css) { expect(document.getElementsByTagName("link").length).toBe(2); } }); diff --git a/tests/rspack-test/configCases/runtime/split-css-chunk/index1.js b/tests/rspack-test/configCases/runtime/split-css-chunk/index1.js index bd757fd5f409..daca7660ad30 100644 --- a/tests/rspack-test/configCases/runtime/split-css-chunk/index1.js +++ b/tests/rspack-test/configCases/runtime/split-css-chunk/index1.js @@ -2,7 +2,11 @@ it("should load css chunk", async function () { const module = await import("./common"); expect(module.value).toBe(1); // test is only for css loading - if (typeof document !== "undefined" && __webpack_require__.f.css) { + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + if (typeof document !== "undefined" && __rspack_context.f.css) { + expect(document.getElementsByTagName("link").length).toBe(1); + } + } else if (__webpack_require__.f.css) { expect(document.getElementsByTagName("link").length).toBe(1); } }); diff --git a/tests/rspack-test/configCases/source-map/verify-css-js-mix/index.js b/tests/rspack-test/configCases/source-map/verify-css-js-mix/index.js index d30919fcd65a..272c9b6fc786 100644 --- a/tests/rspack-test/configCases/source-map/verify-css-js-mix/index.js +++ b/tests/rspack-test/configCases/source-map/verify-css-js-mix/index.js @@ -11,18 +11,13 @@ try { it("verify importing css js source map", async () => { const source = fs.readFileSync(__filename + ".map", "utf-8"); const map = JSON.parse(source); - const out = fs.readFileSync(__filename, "utf-8"); - const usesRuntimeContext = out.includes(["var ", "__rspack_context"].join("")); - expect(map.sources.sort()).toEqual(usesRuntimeContext ? [ - "webpack:///./a.js", - "webpack:///./index.js", - "webpack:///webpack/runtime/make_namespace_object", - ] : [ + expect(map.sources.sort()).toEqual([ "webpack:///./a.js", "webpack:///./index.js", "webpack:///webpack/runtime/make_namespace_object", ]); expect(map.file).toEqual("bundle0.js"); + const out = fs.readFileSync(__filename, "utf-8"); expect( await checkMap(out, source, { // *${id}* as the search key to avoid conflict with `Object.defineProperty(exports, ${id}, ...)` diff --git a/tests/rspack-test/configCases/source-map/verify-es6/index.js b/tests/rspack-test/configCases/source-map/verify-es6/index.js index a027bc409097..ece323edd5c7 100644 --- a/tests/rspack-test/configCases/source-map/verify-es6/index.js +++ b/tests/rspack-test/configCases/source-map/verify-es6/index.js @@ -11,13 +11,23 @@ it("verify es6 (esmodule) bundle source map", async () => { const source = fs.readFileSync(__filename + ".map", "utf-8"); const map = JSON.parse(source); const out = fs.readFileSync(__filename, "utf-8"); - expect(map.sources.filter(source => !source.startsWith("webpack:///webpack/runtime/"))).toEqual([ - `webpack:///../../../../../packages/rspack-test-tools/dist/helper/util/checkSourceMap.js`, - "webpack:///./b-dir/c-dir/c.js", - "webpack:///./b-dir/b.js", - "webpack:///./a.js", - "webpack:///./index.js", - ]); + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + expect(map.sources.filter(source => !source.startsWith("webpack:///webpack/runtime/"))).toEqual([ + `webpack:///../../../../../packages/rspack-test-tools/dist/helper/util/checkSourceMap.js`, + "webpack:///./b-dir/c-dir/c.js", + "webpack:///./b-dir/b.js", + "webpack:///./a.js", + "webpack:///./index.js", + ]); + } else { + expect(map.sources).toEqual([ + `webpack:///../../../../../packages/rspack-test-tools/dist/helper/util/checkSourceMap.js`, + "webpack:///./b-dir/c-dir/c.js", + "webpack:///./b-dir/b.js", + "webpack:///./a.js", + "webpack:///./index.js", + ]); + } expect(map.file).toEqual("bundle0.js"); expect( await checkMap(out, source, { diff --git a/tests/rspack-test/configCases/trusted-types/module-runtime-requirement/index.js b/tests/rspack-test/configCases/trusted-types/module-runtime-requirement/index.js index 29c26d71cfe2..9715917734bd 100644 --- a/tests/rspack-test/configCases/trusted-types/module-runtime-requirement/index.js +++ b/tests/rspack-test/configCases/trusted-types/module-runtime-requirement/index.js @@ -14,7 +14,7 @@ createWorker; it("should generate correct new Worker statement", async () => { const content = fs.readFileSync(path.resolve(path.dirname(__filename), './test-worker.js'), "utf-8"); expect(content).toContain(`this is worker`); - if (content.includes(["var ", "__rspack_context"].join(""))) { + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { expect(content).toContain(`(__unused_rspack_module, __unused_rspack_exports, __rspack_context)`); expect(content).toContain(`eval(__rspack_context.ts(`); } else { diff --git a/tests/rspack-test/configCases/trusted-types/web-worker/index.js b/tests/rspack-test/configCases/trusted-types/web-worker/index.js index 59d76a8321b9..a459fab81899 100644 --- a/tests/rspack-test/configCases/trusted-types/web-worker/index.js +++ b/tests/rspack-test/configCases/trusted-types/web-worker/index.js @@ -12,10 +12,11 @@ createWorker; it("should generate correct new Worker statement", async () => { const content = fs.readFileSync(__filename, "utf-8"); - const method = content.includes(["var ", "__rspack_context"].join("")) - ? "__rspack_context.tu" - : "__webpack_require__.tu"; - expect(content).toContain(`new Worker(${method}(new URL(`) + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + expect(content).toContain(`new Worker(__rspack_context.tu(new URL(`) + } else { + expect(content).toContain(`new Worker(__webpack_require__.tu(new URL(`) + } }); @@ -28,10 +29,11 @@ createWorkerWithChunkName it("should generate correct new Worker statement with magic comments", async () => { const content = fs.readFileSync(__filename, "utf-8"); const chunkName = "someChunkName"; - const method = content.includes(["var ", "__rspack_context"].join("")) - ? "__rspack_context.tu" - : "__webpack_require__.tu"; - expect(content).toContain(`new Worker(/* webpackChunkName: "${chunkName}" */${method}(new URL(`) + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + expect(content).toContain(`new Worker(/* webpackChunkName: "${chunkName}" */__rspack_context.tu(new URL(`) + } else { + expect(content).toContain(`new Worker(/* webpackChunkName: "${chunkName}" */__webpack_require__.tu(new URL(`) + } expect(fs.existsSync(path.join(__dirname, `${chunkName}.js`))).toBeTruthy(); }); @@ -45,9 +47,10 @@ createWorkerWithChunkNameInnner it("should generate correct new Worker statement with magic comments", async () => { const content = fs.readFileSync(__filename, "utf-8"); const chunkName = "someChunkName2"; - const method = content.includes(["var ", "__rspack_context"].join("")) - ? "__rspack_context.tu" - : "__webpack_require__.tu"; - expect(content).toContain(`new Worker(${method}(new URL(/* webpackChunkName: "${chunkName}" */`) + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + expect(content).toContain(`new Worker(__rspack_context.tu(new URL(/* webpackChunkName: "${chunkName}" */`) + } else { + expect(content).toContain(`new Worker(__webpack_require__.tu(new URL(/* webpackChunkName: "${chunkName}" */`) + } expect(fs.existsSync(path.join(__dirname, `${chunkName}.js`))).toBeTruthy(); }); diff --git a/tests/rspack-test/configCases/umd/issue-15545/rspack.config.js b/tests/rspack-test/configCases/umd/issue-15545/rspack.config.js index 86389d9a0c7d..5b9cc0a77ec1 100644 --- a/tests/rspack-test/configCases/umd/issue-15545/rspack.config.js +++ b/tests/rspack-test/configCases/umd/issue-15545/rspack.config.js @@ -9,7 +9,7 @@ module.exports = { library: { type: 'umd', name: 'MyLibrary' }, chunkLoading: 'jsonp', chunkFormat: 'array-push', - globalObject: 'globalThis', + globalObject: 'this', }, optimization: { minimize: false, diff --git a/tests/rspack-test/configCases/unique-id/all/index.js b/tests/rspack-test/configCases/unique-id/all/index.js index 3fd220a23096..477b129d6481 100644 --- a/tests/rspack-test/configCases/unique-id/all/index.js +++ b/tests/rspack-test/configCases/unique-id/all/index.js @@ -2,10 +2,10 @@ const path = require("path"); const fs = require("fs"); it("should inject unique id when use bundlerInfo.force=true", () => { - const pattern = globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK - ? /Object\.defineProperty\(__rspack_context, "ruid"/m - : /(^|[^"'`])__webpack_require__\.ruid =/m; - expect( - fs.readFileSync(path.join(__dirname, "bundle0.js"), "utf-8") - ).toMatch(pattern); + const source = fs.readFileSync(path.join(__dirname, "bundle0.js"), "utf-8"); + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + expect(source).toMatch(/Object\.defineProperty\(__rspack_context, "ruid"/m); + } else { + expect(source).toMatch(/(^|[^"'`])__webpack_require__\.ruid =/m); + } }); diff --git a/tests/rspack-test/configCases/unique-id/array/index.js b/tests/rspack-test/configCases/unique-id/array/index.js index 684af518f7de..39521ce5313c 100644 --- a/tests/rspack-test/configCases/unique-id/array/index.js +++ b/tests/rspack-test/configCases/unique-id/array/index.js @@ -2,10 +2,10 @@ const path = require("path"); const fs = require("fs"); it('should inject unique id when use bundlerInfo.force=["uniqueId"]', () => { - const pattern = globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK - ? /Object\.defineProperty\(__rspack_context, "ruid"/m - : /(^|[^"'`])__webpack_require__\.ruid =/m; - expect( - fs.readFileSync(path.join(__dirname, "bundle0.js"), "utf-8") - ).toMatch(pattern); + const source = fs.readFileSync(path.join(__dirname, "bundle0.js"), "utf-8"); + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + expect(source).toMatch(/Object\.defineProperty\(__rspack_context, "ruid"/m); + } else { + expect(source).toMatch(/(^|[^"'`])__webpack_require__\.ruid =/m); + } }); diff --git a/tests/rspack-test/configCases/version/all/index.js b/tests/rspack-test/configCases/version/all/index.js index 55d8d60feec5..c29ad2e51b46 100644 --- a/tests/rspack-test/configCases/version/all/index.js +++ b/tests/rspack-test/configCases/version/all/index.js @@ -2,10 +2,10 @@ const path = require("path"); const fs = require("fs"); it("should inject version when use bundlerInfo.force=true", () => { - const pattern = globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK - ? /Object\.defineProperty\(__rspack_context, "rv"/m - : /(^|[^"'`])__webpack_require__\.rv =/m; - expect( - fs.readFileSync(path.join(__dirname, "bundle0.js"), "utf-8") - ).toMatch(pattern); + const source = fs.readFileSync(path.join(__dirname, "bundle0.js"), "utf-8"); + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + expect(source).toMatch(/Object\.defineProperty\(__rspack_context, "rv"/m); + } else { + expect(source).toMatch(/(^|[^"'`])__webpack_require__\.rv =/m); + } }); diff --git a/tests/rspack-test/configCases/version/array/index.js b/tests/rspack-test/configCases/version/array/index.js index 9b0a9a4e5d24..9f8d40ddf55a 100644 --- a/tests/rspack-test/configCases/version/array/index.js +++ b/tests/rspack-test/configCases/version/array/index.js @@ -2,10 +2,10 @@ const path = require("path"); const fs = require("fs"); it('should inject version when use bundlerInfo.force=["version"]', () => { - const pattern = globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK - ? /Object\.defineProperty\(__rspack_context, "rv"/m - : /(^|[^"'`])__webpack_require__\.rv =/m; - expect( - fs.readFileSync(path.join(__dirname, "bundle0.js"), "utf-8") - ).toMatch(pattern); + const source = fs.readFileSync(path.join(__dirname, "bundle0.js"), "utf-8"); + if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + expect(source).toMatch(/Object\.defineProperty\(__rspack_context, "rv"/m); + } else { + expect(source).toMatch(/(^|[^"'`])__webpack_require__\.rv =/m); + } }); diff --git a/tests/rspack-test/hotCases/sharing/share-plugin/__snapshots__/web/1.snap.txt b/tests/rspack-test/hotCases/sharing/share-plugin/__snapshots__/web/1.snap.txt index 9bbfd75961cb..4cbaa6b63730 100644 --- a/tests/rspack-test/hotCases/sharing/share-plugin/__snapshots__/web/1.snap.txt +++ b/tests/rspack-test/hotCases/sharing/share-plugin/__snapshots__/web/1.snap.txt @@ -7,7 +7,7 @@ - Bundle: bundle.js - Bundle: common_js_2.chunk.CURRENT_HASH.js - Manifest: main.LAST_HASH.hot-update.json, size: 28 -- Update: main.LAST_HASH.hot-update.js, size: 42335 +- Update: main.LAST_HASH.hot-update.js, size: 42334 ## Manifest @@ -93,7 +93,6 @@ __webpack_require__.t = function(value, mode) { __webpack_require__.d(ns, def); return ns; }; - })(); // webpack/runtime/get_full_hash (() => { diff --git a/tests/rspack-test/statsOutputCases/immutable/__snapshots__/stats.txt b/tests/rspack-test/statsOutputCases/immutable/__snapshots__/stats.txt index 37427eb0710d..c680926647e5 100644 --- a/tests/rspack-test/statsOutputCases/immutable/__snapshots__/stats.txt +++ b/tests/rspack-test/statsOutputCases/immutable/__snapshots__/stats.txt @@ -1,2 +1,2 @@ -asset 8868e268a4d5877b.js xx KiB [emitted] [immutable] (name: main) +asset 490c980788b0193e.js xx KiB [emitted] [immutable] (name: main) asset 7b129503d319bd23.js xx bytes [emitted] [immutable] \ No newline at end of file diff --git a/xtask/benchmark/benches/groups/scan_dependencies.rs b/xtask/benchmark/benches/groups/scan_dependencies.rs index 136825232f9b..c172344c50d2 100644 --- a/xtask/benchmark/benches/groups/scan_dependencies.rs +++ b/xtask/benchmark/benches/groups/scan_dependencies.rs @@ -161,7 +161,7 @@ fn prepare_scan_dependencies_benchmark_case( PreparedScanDependenciesBenchmarkCase { benchmark_id, source_text, - compiler_options: compiler_options.clone(), + compiler_options, initial_semicolons: semicolons, parser_options, parsed_ast, From 838a6d498130dd34ca408d1cb18a5ffe594dd672 Mon Sep 17 00:00:00 2001 From: LingyuCoder Date: Thu, 11 Jun 2026 19:01:37 +0800 Subject: [PATCH 08/21] fix(runtime): address review comments --- .../src/parser_plugin/api_plugin.rs | 11 +++++++++-- .../parser_plugin/common_js_exports_parse_plugin.rs | 1 + .../src/parser_plugin/drive.rs | 3 ++- .../src/parser_plugin/trait.rs | 1 + crates/rspack_plugin_javascript/src/runtime.rs | 4 +--- .../src/visitors/dependency/parser/walk.rs | 8 +++++++- 6 files changed, 21 insertions(+), 7 deletions(-) diff --git a/crates/rspack_plugin_javascript/src/parser_plugin/api_plugin.rs b/crates/rspack_plugin_javascript/src/parser_plugin/api_plugin.rs index 565683996e97..5012d71e495f 100644 --- a/crates/rspack_plugin_javascript/src/parser_plugin/api_plugin.rs +++ b/crates/rspack_plugin_javascript/src/parser_plugin/api_plugin.rs @@ -472,13 +472,20 @@ impl<'p, 'a> JavascriptParserPlugin<'p, 'a> for APIPlugin { parser: &mut JavascriptParser, expr: &AssignExpr, members: &[Atom], + member_ranges: &[Span], for_name: &str, ) -> Option { if parser.compiler_options.experiments.runtime_mode != ExperimentRuntimeMode::Rspack { return None; } - let handled = - static_require_member_chain(parser, for_name, members, None, expr.left.span(), true); + let handled = static_require_member_chain( + parser, + for_name, + members, + Some(member_ranges), + expr.left.span(), + true, + ); if handled.is_some() { parser.walk_expression(&expr.right); } diff --git a/crates/rspack_plugin_javascript/src/parser_plugin/common_js_exports_parse_plugin.rs b/crates/rspack_plugin_javascript/src/parser_plugin/common_js_exports_parse_plugin.rs index abeb3718bea8..530cfbb00dc3 100644 --- a/crates/rspack_plugin_javascript/src/parser_plugin/common_js_exports_parse_plugin.rs +++ b/crates/rspack_plugin_javascript/src/parser_plugin/common_js_exports_parse_plugin.rs @@ -273,6 +273,7 @@ impl<'p, 'a> JavascriptParserPlugin<'p, 'a> for CommonJsExportsParserPlugin { parser: &mut JavascriptParser<'p>, assign_expr: &AssignExpr, remaining: &[Atom], + _member_ranges: &[Span], for_name: &str, ) -> Option { if self.should_skip_handler(parser) { diff --git a/crates/rspack_plugin_javascript/src/parser_plugin/drive.rs b/crates/rspack_plugin_javascript/src/parser_plugin/drive.rs index 0e5385df74dc..d11608d0cb59 100644 --- a/crates/rspack_plugin_javascript/src/parser_plugin/drive.rs +++ b/crates/rspack_plugin_javascript/src/parser_plugin/drive.rs @@ -324,10 +324,11 @@ impl<'p: 'a, 'a> JavascriptParserPlugin<'p, 'a> for JavaScriptParserPluginDrive parser: &mut JavascriptParser<'p>, expr: &AssignExpr, members: &[Atom], + member_ranges: &[Span], for_name: &str, ) -> Option { for plugin in self.plugins_for(JavascriptParserPluginHook::AssignMemberChain) { - let res = plugin.assign_member_chain(parser, expr, members, for_name); + let res = plugin.assign_member_chain(parser, expr, members, member_ranges, for_name); // `SyncBailHook` if res.is_some() { return res; diff --git a/crates/rspack_plugin_javascript/src/parser_plugin/trait.rs b/crates/rspack_plugin_javascript/src/parser_plugin/trait.rs index 0bf76b8f7fc3..fb0b7c2ff618 100644 --- a/crates/rspack_plugin_javascript/src/parser_plugin/trait.rs +++ b/crates/rspack_plugin_javascript/src/parser_plugin/trait.rs @@ -563,6 +563,7 @@ Please annotate your `impl<'p, 'a> JavascriptParserPlugin<'p, 'a> for ...` block _parser: &mut JavascriptParser<'p>, _expr: &AssignExpr, _members: &[Atom], + _member_ranges: &[Span], _for_name: &str, ) -> Option { None diff --git a/crates/rspack_plugin_javascript/src/runtime.rs b/crates/rspack_plugin_javascript/src/runtime.rs index 9da01dbe36f3..b4980ba89fd4 100644 --- a/crates/rspack_plugin_javascript/src/runtime.rs +++ b/crates/rspack_plugin_javascript/src/runtime.rs @@ -499,9 +499,7 @@ fn render_runtime_context_fields( return None; } - let metadata = compilation - .runtime_proxy_metadata_artifact - .get(chunk_ukey)?; + let metadata = runtime_context_metadata(compilation, chunk_ukey)?; let mut sources = ConcatSource::default(); let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); let render_live_bindings = render_setter_fields && !render_plain_fields; diff --git a/crates/rspack_plugin_javascript/src/visitors/dependency/parser/walk.rs b/crates/rspack_plugin_javascript/src/visitors/dependency/parser/walk.rs index 812932e99903..baf4d6198c08 100644 --- a/crates/rspack_plugin_javascript/src/visitors/dependency/parser/walk.rs +++ b/crates/rspack_plugin_javascript/src/visitors/dependency/parser/walk.rs @@ -1887,7 +1887,13 @@ impl JavascriptParser<'_> { && expr_name .root_info .call_hooks_name(self, |parser, for_name| { - drive.assign_member_chain(parser, expr, &expr_name.members, for_name) + drive.assign_member_chain( + parser, + expr, + &expr_name.members, + &expr_name.member_ranges, + for_name, + ) }) .unwrap_or_default() { From 3505f46df3cda2e4e142467a0fce85e69178678b Mon Sep 17 00:00:00 2001 From: LingyuCoder Date: Thu, 11 Jun 2026 19:08:29 +0800 Subject: [PATCH 09/21] fix(runtime): preserve execute runtime helpers --- .../module_executor/execute.rs | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/crates/rspack_core/src/compilation/build_module_graph/module_executor/execute.rs b/crates/rspack_core/src/compilation/build_module_graph/module_executor/execute.rs index 84531aa37d43..5281205f9391 100644 --- a/crates/rspack_core/src/compilation/build_module_graph/module_executor/execute.rs +++ b/crates/rspack_core/src/compilation/build_module_graph/module_executor/execute.rs @@ -1,4 +1,4 @@ -use std::{collections::VecDeque, iter::once, sync::atomic::AtomicU32}; +use std::{collections::VecDeque, fmt::Write, iter::once, sync::atomic::AtomicU32}; use itertools::Itertools; use rspack_collections::{Identifier, IdentifierSet}; @@ -23,7 +23,10 @@ use crate::{ render_runtime_module_source, runtime_globals::{RuntimeVariable, runtime_variable_name}, runtime_mode::RuntimeMode, - utils::task_loop::{Task, TaskResult, TaskType}, + utils::{ + property_access, + task_loop::{Task, TaskResult, TaskType}, + }, }; #[derive(Debug, Clone)] @@ -85,6 +88,27 @@ fn create_execute_runtime_source( .into_string_lossy(), ); } + for (_, runtime_global) in lexical_fields.iter_names() { + let (Some(property_name), Some(lexical_name)) = ( + runtime_global.rspack_context_property_name(), + runtime_global.to_lexical_name(), + ) else { + continue; + }; + writeln!( + source, + "{lexical_name}={runtime_context}{};", + property_access([property_name], 0) + ) + .expect("write to string should succeed"); + if runtime_global.should_initialize_as_object() { + writeln!(source, "{lexical_name}={lexical_name}||{{}};") + .expect("write to string should succeed"); + } else if runtime_global.should_initialize_as_array() { + writeln!(source, "{lexical_name}={lexical_name}||[];") + .expect("write to string should succeed"); + } + } source.push_str(&metadata.render_context_setter_assignments(runtime_context)); (!source.is_empty()).then(|| { From e69c3e1eb10e3b1e2ca7ec70cf54461d8ed88eac Mon Sep 17 00:00:00 2001 From: LingyuCoder Date: Thu, 11 Jun 2026 19:24:06 +0800 Subject: [PATCH 10/21] chore: fix js formatting --- .../chunk-loading/depend-on-with-chunk-load/rspack.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/rspack-test/configCases/chunk-loading/depend-on-with-chunk-load/rspack.config.js b/tests/rspack-test/configCases/chunk-loading/depend-on-with-chunk-load/rspack.config.js index f91162efa5fc..8157361287eb 100644 --- a/tests/rspack-test/configCases/chunk-loading/depend-on-with-chunk-load/rspack.config.js +++ b/tests/rspack-test/configCases/chunk-loading/depend-on-with-chunk-load/rspack.config.js @@ -1,4 +1,4 @@ -const rspack = require("@rspack/core"); +const rspack = require('@rspack/core'); /** @type {import("@rspack/core").Configuration} */ module.exports = { From 4804e6f81bd6cc755b97fbe892871f02081b7d2d Mon Sep 17 00:00:00 2001 From: LingyuCoder Date: Thu, 11 Jun 2026 21:13:47 +0800 Subject: [PATCH 11/21] fix(runtime): initialize execute context fields before runtime modules --- .../module_executor/execute.rs | 53 +++++++++++-------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/crates/rspack_core/src/compilation/build_module_graph/module_executor/execute.rs b/crates/rspack_core/src/compilation/build_module_graph/module_executor/execute.rs index 5281205f9391..6cc4a7968088 100644 --- a/crates/rspack_core/src/compilation/build_module_graph/module_executor/execute.rs +++ b/crates/rspack_core/src/compilation/build_module_graph/module_executor/execute.rs @@ -56,13 +56,41 @@ fn create_execute_runtime_source( .get(chunk_ukey)?; let lexical_fields = metadata.lexical_fields(); let context_fields = metadata.context_fields(); - if lexical_fields.is_empty() && context_fields.is_empty() && runtime_modules.is_empty() { + let execute_fields = lexical_fields | context_fields; + if execute_fields.is_empty() && runtime_modules.is_empty() { return None; } let runtime_context = runtime_variable_name(&RuntimeVariable::Context); let mut source = String::new(); - source.push_str(&metadata.render_lexical_declarations()); + let declarations = execute_fields + .iter_names() + .filter_map(|(_, runtime_global)| runtime_global.to_lexical_name().map(str::to_string)) + .collect::>(); + if !declarations.is_empty() { + writeln!(source, "var {};", declarations.join(", ")).expect("write to string should succeed"); + } + for (_, runtime_global) in execute_fields.iter_names() { + let (Some(property_name), Some(lexical_name)) = ( + runtime_global.rspack_context_property_name(), + runtime_global.to_lexical_name(), + ) else { + continue; + }; + writeln!( + source, + "{lexical_name}={runtime_context}{};", + property_access([property_name], 0) + ) + .expect("write to string should succeed"); + if runtime_global.should_initialize_as_object() { + writeln!(source, "{lexical_name}={lexical_name}||{{}};") + .expect("write to string should succeed"); + } else if runtime_global.should_initialize_as_array() { + writeln!(source, "{lexical_name}={lexical_name}||[];") + .expect("write to string should succeed"); + } + } for runtime_id in runtime_modules { let runtime_module = compilation .runtime_modules @@ -88,27 +116,6 @@ fn create_execute_runtime_source( .into_string_lossy(), ); } - for (_, runtime_global) in lexical_fields.iter_names() { - let (Some(property_name), Some(lexical_name)) = ( - runtime_global.rspack_context_property_name(), - runtime_global.to_lexical_name(), - ) else { - continue; - }; - writeln!( - source, - "{lexical_name}={runtime_context}{};", - property_access([property_name], 0) - ) - .expect("write to string should succeed"); - if runtime_global.should_initialize_as_object() { - writeln!(source, "{lexical_name}={lexical_name}||{{}};") - .expect("write to string should succeed"); - } else if runtime_global.should_initialize_as_array() { - writeln!(source, "{lexical_name}={lexical_name}||[];") - .expect("write to string should succeed"); - } - } source.push_str(&metadata.render_context_setter_assignments(runtime_context)); (!source.is_empty()).then(|| { From a7e4e50ba28464574a27a3dded37bf0896d0609f Mon Sep 17 00:00:00 2001 From: LingyuCoder Date: Fri, 12 Jun 2026 12:15:53 +0800 Subject: [PATCH 12/21] fix(runtime): expose runtime context requirements --- .../runtime_proxy_metadata_artifact.rs | 22 +- .../compilation/runtime_requirements/mod.rs | 29 +- crates/rspack_core/src/runtime_globals.rs | 4 + .../src/plugin/mod.rs | 2 +- .../rspack_plugin_javascript/src/runtime.rs | 499 ++++++++++++------ .../src/container/container_entry_module.rs | 17 +- .../hotCases/worker/update-in-worker/index.js | 35 +- 7 files changed, 411 insertions(+), 197 deletions(-) diff --git a/crates/rspack_core/src/artifacts/runtime_proxy_metadata_artifact.rs b/crates/rspack_core/src/artifacts/runtime_proxy_metadata_artifact.rs index abfe355a26cb..c3b2623b1845 100644 --- a/crates/rspack_core/src/artifacts/runtime_proxy_metadata_artifact.rs +++ b/crates/rspack_core/src/artifacts/runtime_proxy_metadata_artifact.rs @@ -13,6 +13,7 @@ use crate::{ pub struct RuntimeProxyMetadata { pub tree_runtime_requirements: RuntimeGlobals, pub module_proxy_requirements: RuntimeGlobals, + pub bootstrap_proxy_requirements: RuntimeGlobals, pub runtime_module_requirements: RuntimeGlobals, pub context_setter_fields: RuntimeGlobals, pub hook_exposed_requirements: RuntimeGlobals, @@ -31,6 +32,7 @@ impl RuntimeProxyMetadata { pub fn context_fields(&self) -> RuntimeGlobals { let mut fields = self.module_proxy_requirements; + fields.insert(self.bootstrap_proxy_requirements); fields.insert(self.context_setter_fields); fields.insert(self.hook_exposed_requirements); Self::renderable_fields(fields) @@ -40,11 +42,27 @@ impl RuntimeProxyMetadata { Self::renderable_fields(self.context_setter_fields) } - pub fn render_lexical_declarations(&self) -> String { + pub fn render_lexical_declarations( + &self, + render_runtime_global: Option<&dyn Fn(RuntimeGlobals) -> Option>, + ) -> String { let names = self .lexical_fields() .iter_names() - .filter_map(|(_, runtime_global)| runtime_global.to_lexical_name().map(str::to_string)) + .filter_map(|(_, runtime_global)| { + let lexical_name = runtime_global.to_lexical_name()?; + if let Some(render_runtime_global) = render_runtime_global + && let Some(value) = render_runtime_global(runtime_global) + { + Some(format!("{lexical_name}={value}")) + } else if runtime_global.should_initialize_as_object() { + Some(format!("{lexical_name}={{}}")) + } else if runtime_global.should_initialize_as_array() { + Some(format!("{lexical_name}=[]")) + } else { + Some(lexical_name.to_string()) + } + }) .collect::>(); if names.is_empty() { String::new() diff --git a/crates/rspack_core/src/compilation/runtime_requirements/mod.rs b/crates/rspack_core/src/compilation/runtime_requirements/mod.rs index 98290b6b3e8e..9419768f1fd1 100644 --- a/crates/rspack_core/src/compilation/runtime_requirements/mod.rs +++ b/crates/rspack_core/src/compilation/runtime_requirements/mod.rs @@ -4,7 +4,8 @@ use rustc_hash::{FxHashMap, FxHashSet}; use super::*; use crate::{ CodeGenerationRuntimeRequirementsWrite, RuntimeProxyMetadata, cache::Cache, - compilation::pass::PassExt, logger::Logger, runtime_mode::RuntimeMode as ExperimentRuntimeMode, + compilation::pass::PassExt, logger::Logger, runtime_globals::BOOTSTRAP_RUNTIME_CONTEXT_GLOBALS, + runtime_mode::RuntimeMode as ExperimentRuntimeMode, }; pub struct RuntimeRequirementsPass; @@ -545,8 +546,11 @@ pub async fn process_chunks_runtime_requirements( .get(chunk_ukey) { metadata - .hook_exposed_requirements + .tree_runtime_requirements .insert(*chunk_runtime_requirements); + metadata + .bootstrap_proxy_requirements + .insert(chunk_runtime_requirements.intersection(*BOOTSTRAP_RUNTIME_CONTEXT_GLOBALS)); } for mid in compilation .build_chunk_graph_artifact @@ -587,12 +591,16 @@ pub async fn process_chunks_runtime_requirements( .expect("should have runtime module"); let additional_runtime_requirements = runtime_module.additional_runtime_requirements(compilation); + if runtime_module.get_custom_source().is_some() + || runtime_module.get_constructor_name() == "RuntimeModuleFromJs" + { + metadata + .hook_exposed_requirements + .insert(additional_runtime_requirements); + } metadata .runtime_module_requirements .insert(additional_runtime_requirements); - metadata - .tree_runtime_requirements - .insert(additional_runtime_requirements); } } @@ -602,6 +610,17 @@ pub async fn process_chunks_runtime_requirements( compilation, &entry_ukey, )); + if metadata + .tree_runtime_requirements + .contains(RuntimeGlobals::HMR_DOWNLOAD_MANIFEST) + { + metadata.context_setter_fields.insert( + RuntimeGlobals::HMR_DOWNLOAD_MANIFEST + | RuntimeGlobals::HMR_DOWNLOAD_UPDATE_HANDLERS + | RuntimeGlobals::HMR_INVALIDATE_MODULE_HANDLERS + | RuntimeGlobals::HMR_MODULE_DATA, + ); + } compilation .runtime_proxy_metadata_artifact .insert(entry_ukey, metadata); diff --git a/crates/rspack_core/src/runtime_globals.rs b/crates/rspack_core/src/runtime_globals.rs index 922f856d88bd..6992ae117bb7 100644 --- a/crates/rspack_core/src/runtime_globals.rs +++ b/crates/rspack_core/src/runtime_globals.rs @@ -340,6 +340,10 @@ pub static BOOTSTRAP_RUNTIME_CONTEXT_GLOBALS: LazyLock = LazyLoc | RuntimeGlobals::MODULE_FACTORIES | RuntimeGlobals::MODULE_FACTORIES_ADD_ONLY | RuntimeGlobals::MODULE_CACHE + | RuntimeGlobals::ON_CHUNKS_LOADED + | RuntimeGlobals::EXTERNAL_INSTALL_CHUNK + | RuntimeGlobals::STARTUP_ENTRYPOINT + | RuntimeGlobals::STARTUP }); pub fn runtime_globals_property_name(runtime_globals: &RuntimeGlobals) -> Option<&'static str> { diff --git a/crates/rspack_plugin_javascript/src/plugin/mod.rs b/crates/rspack_plugin_javascript/src/plugin/mod.rs index 473da6f3ec71..1a1f0d2262d3 100644 --- a/crates/rspack_plugin_javascript/src/plugin/mod.rs +++ b/crates/rspack_plugin_javascript/src/plugin/mod.rs @@ -209,7 +209,7 @@ var module = ({module_cache}[moduleId] = {{"#, execOptions.factory.call(module.exports, module, module.exports, execOptions.context); "#, module_factories, - runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE), + callable_require, runtime_context, runtime_template.render_runtime_globals(&RuntimeGlobals::INTERCEPT_MODULE_EXECUTION) ) diff --git a/crates/rspack_plugin_javascript/src/runtime.rs b/crates/rspack_plugin_javascript/src/runtime.rs index b4980ba89fd4..a4dabfca7fba 100644 --- a/crates/rspack_plugin_javascript/src/runtime.rs +++ b/crates/rspack_plugin_javascript/src/runtime.rs @@ -1,7 +1,7 @@ use rayon::prelude::*; use rspack_core::{ ChunkCodeTemplate, ChunkGraph, ChunkInitFragments, ChunkKind, ChunkUkey, - CodeGenerationPublicPathAutoReplace, Compilation, Module, RuntimeGlobals, + CodeGenerationPublicPathAutoReplace, Compilation, Module, RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeProxyMetadata, RuntimeVariable, SourceType, chunk_graph_chunk::ChunkIdSet, get_undo_path, property_access, render_runtime_module_source, @@ -353,6 +353,45 @@ fn runtime_context_render_metadata( runtime_context_metadata(compilation, chunk_ukey).cloned() } +fn runtime_context_current_chunk_metadata( + compilation: &Compilation, + chunk_ukey: &ChunkUkey, +) -> Option { + if compilation.options.experiments.runtime_mode != RuntimeMode::Rspack { + return None; + } + + if let Some(metadata) = compilation.runtime_proxy_metadata_artifact.get(chunk_ukey) { + return Some(metadata.clone()); + } + + let mut metadata = RuntimeProxyMetadata::default(); + for runtime_module_id in compilation + .build_chunk_graph_artifact + .chunk_graph + .get_chunk_runtime_modules_iterable(chunk_ukey) + { + let runtime_module = compilation + .runtime_modules + .get(runtime_module_id) + .expect("should have runtime module"); + let additional_runtime_requirements = + runtime_module.additional_runtime_requirements(compilation); + let generated_runtime_requirements = runtime_module_generated_requirements(&**runtime_module); + metadata + .tree_runtime_requirements + .insert(additional_runtime_requirements); + metadata + .tree_runtime_requirements + .insert(generated_runtime_requirements); + metadata + .runtime_module_requirements + .insert(additional_runtime_requirements); + } + + (!metadata.tree_runtime_requirements.is_empty()).then_some(metadata) +} + pub fn should_render_runtime_context(compilation: &Compilation, chunk_ukey: &ChunkUkey) -> bool { if compilation.options.experiments.runtime_mode != RuntimeMode::Rspack { return false; @@ -373,44 +412,6 @@ fn is_hot_update_chunk(compilation: &Compilation, chunk_ukey: &ChunkUkey) -> boo matches!(chunk.kind(), ChunkKind::HotUpdate) } -fn hmr_runtime_state_key(constructor_name: &str) -> Option<&'static str> { - match constructor_name { - "JsonpChunkLoadingRuntimeModule" => Some("jsonp"), - "ModuleChunkLoadingRuntimeModule" => Some("module"), - "ImportScriptsChunkLoadingRuntimeModule" => Some("importScripts"), - "ReadFileChunkLoadingRuntimeModule" => Some("readFileVm"), - "RequireChunkLoadingRuntimeModule" => Some("require"), - _ => None, - } -} - -fn hmr_runtime_state_variables(compilation: &Compilation, chunk_ukey: &ChunkUkey) -> Vec { - let mut variables = Vec::new(); - for runtime_module_id in compilation - .build_chunk_graph_artifact - .chunk_graph - .get_chunk_runtime_modules_iterable(chunk_ukey) - { - let runtime_module = compilation - .runtime_modules - .get(runtime_module_id) - .expect("should have runtime module"); - let Some(key) = hmr_runtime_state_key(&runtime_module.get_constructor_name()) else { - continue; - }; - let name = format!( - "{}_{key}", - RuntimeGlobals::HMR_RUNTIME_STATE_PREFIX - .property_name() - .expect("hmr runtime state prefix should have property name") - ); - if !variables.contains(&name) { - variables.push(name); - } - } - variables -} - pub fn render_runtime_context_declaration(runtime_template: &ChunkCodeTemplate) -> String { let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); format!("var {runtime_context}={{}};\n") @@ -424,6 +425,85 @@ pub fn render_runtime_context_require_assignment(runtime_template: &ChunkCodeTem ) } +fn runtime_module_generated_requirements(runtime_module: &dyn RuntimeModule) -> RuntimeGlobals { + let constructor_name = runtime_module.get_constructor_name(); + let module_name = runtime_module.identifier().to_string(); + match constructor_name.as_str() { + "AsyncRuntimeModule" => { + RuntimeGlobals::ASYNC_MODULE + | RuntimeGlobals::ASYNC_MODULE_EXPORT_SYMBOL + | RuntimeGlobals::DEFERRED_MODULES_ASYNC_TRANSITIVE_DEPENDENCIES + | RuntimeGlobals::DEFERRED_MODULES_ASYNC_TRANSITIVE_DEPENDENCIES_SYMBOL + } + "BaseUriRuntimeModule" => RuntimeGlobals::BASE_URI, + "PublicPathRuntimeModule" | "AutoPublicPathRuntimeModule" => RuntimeGlobals::PUBLIC_PATH, + "GetChunkFilenameRuntimeModule" if module_name.contains("javascript") => { + RuntimeGlobals::GET_CHUNK_SCRIPT_FILENAME + } + "GetChunkFilenameRuntimeModule" if module_name.contains("css") => { + RuntimeGlobals::GET_CHUNK_CSS_FILENAME + } + "GetChunkUpdateFilenameRuntimeModule" => RuntimeGlobals::GET_CHUNK_UPDATE_SCRIPT_FILENAME, + "GetMainFilenameRuntimeModule" => RuntimeGlobals::GET_UPDATE_MANIFEST_FILENAME, + "LoadScriptRuntimeModule" => RuntimeGlobals::LOAD_SCRIPT, + "HasOwnPropertyRuntimeModule" => RuntimeGlobals::HAS_OWN_PROPERTY, + "GetFullHashRuntimeModule" => RuntimeGlobals::GET_FULL_HASH, + "GlobalRuntimeModule" => RuntimeGlobals::GLOBAL, + "CreateScriptUrlRuntimeModule" => RuntimeGlobals::CREATE_SCRIPT_URL, + "CreateScriptRuntimeModule" => RuntimeGlobals::CREATE_SCRIPT, + "OnChunkLoadedRuntimeModule" => RuntimeGlobals::ON_CHUNKS_LOADED, + "DefinePropertyGettersRuntimeModule" => RuntimeGlobals::DEFINE_PROPERTY_GETTERS, + "GetTrustedTypesPolicyRuntimeModule" => RuntimeGlobals::GET_TRUSTED_TYPES_POLICY, + "CreateFakeNamespaceObjectRuntimeModule" => RuntimeGlobals::CREATE_FAKE_NAMESPACE_OBJECT, + "MakeNamespaceObjectRuntimeModule" => RuntimeGlobals::MAKE_NAMESPACE_OBJECT, + "CompatGetDefaultExportRuntimeModule" => RuntimeGlobals::COMPAT_GET_DEFAULT_EXPORT, + "ESMModuleDecoratorRuntimeModule" => RuntimeGlobals::ESM_MODULE_DECORATOR, + "NodeModuleDecoratorRuntimeModule" => RuntimeGlobals::NODE_MODULE_DECORATOR, + "SystemContextRuntimeModule" => RuntimeGlobals::SYSTEM_CONTEXT, + "NonceRuntimeModule" => RuntimeGlobals::SCRIPT_NONCE, + "RelativeUrlRuntimeModule" => RuntimeGlobals::RELATIVE_URL, + "ChunkNameRuntimeModule" => RuntimeGlobals::CHUNK_NAME, + "RuntimeIdRuntimeModule" => RuntimeGlobals::RUNTIME_ID, + "ShareRuntimeModule" => RuntimeGlobals::INITIALIZE_SHARING | RuntimeGlobals::SHARE_SCOPE_MAP, + "RemoteRuntimeModule" => RuntimeGlobals::CURRENT_REMOTE_GET_SCOPE, + "HotModuleReplacementRuntimeModule" => RuntimeGlobals::INTERCEPT_MODULE_EXECUTION, + "EmbedFederationRuntimeModule" => RuntimeGlobals::STARTUP, + "StartupEntrypointRuntimeModule" => RuntimeGlobals::STARTUP_ENTRYPOINT, + "StartupChunkDependenciesRuntimeModule" => RuntimeGlobals::STARTUP, + "EnsureChunkRuntimeModule" => { + RuntimeGlobals::ENSURE_CHUNK | RuntimeGlobals::ENSURE_CHUNK_HANDLERS + } + "JsonpChunkLoadingRuntimeModule" + | "ModuleChunkLoadingRuntimeModule" + | "ImportScriptsChunkLoadingRuntimeModule" + | "ReadFileChunkLoadingRuntimeModule" + | "RequireChunkLoadingRuntimeModule" => { + RuntimeGlobals::BASE_URI + | RuntimeGlobals::ENSURE_CHUNK_HANDLERS + | RuntimeGlobals::EXTERNAL_INSTALL_CHUNK + | RuntimeGlobals::HMR_DOWNLOAD_MANIFEST + | RuntimeGlobals::HMR_DOWNLOAD_UPDATE_HANDLERS + | RuntimeGlobals::HMR_INVALIDATE_MODULE_HANDLERS + | RuntimeGlobals::HMR_MODULE_DATA + } + "EsmChunkLoadingRuntimeModule" => RuntimeGlobals::EXTERNAL_INSTALL_CHUNK, + "ChunkPrefetchPreloadFunctionRuntimeModule" if module_name.contains("prefetch") => { + RuntimeGlobals::PREFETCH_CHUNK | RuntimeGlobals::PREFETCH_CHUNK_HANDLERS + } + "ChunkPrefetchPreloadFunctionRuntimeModule" if module_name.contains("preload") => { + RuntimeGlobals::PRELOAD_CHUNK | RuntimeGlobals::PRELOAD_CHUNK_HANDLERS + } + "AmdDefineRuntimeModule" => RuntimeGlobals::AMD_DEFINE, + "AmdOptionsRuntimeModule" => RuntimeGlobals::AMD_OPTIONS, + "MakeDeferredNamespaceObjectRuntimeModule" => RuntimeGlobals::MAKE_DEFERRED_NAMESPACE_OBJECT, + "MakeOptimizedDeferredNamespaceObjectRuntimeModule" => { + RuntimeGlobals::MAKE_OPTIMIZED_DEFERRED_NAMESPACE_OBJECT + } + "ToBinaryRuntimeModule" => RuntimeGlobals::TO_BINARY, + _ => RuntimeGlobals::default(), + } +} + fn has_bootstrap_runtime_context( compilation: &Compilation, chunk_ukey: &ChunkUkey, @@ -433,6 +513,14 @@ fn has_bootstrap_runtime_context( return false; } + let chunk = compilation + .build_chunk_graph_artifact + .chunk_by_ukey + .expect_get(chunk_ukey); + if !chunk.has_runtime(&compilation.build_chunk_graph_artifact.chunk_group_by_ukey) { + return false; + } + let runtime_requirements = compilation .cgc_runtime_requirements_artifact .get(chunk_ukey) @@ -460,25 +548,125 @@ fn render_runtime_context_declarations( } if render_lexical_fields - && let Some(metadata) = runtime_context_render_metadata(compilation, chunk_ukey) + && let Some(mut metadata) = runtime_context_current_chunk_metadata(compilation, chunk_ukey) { + let chunk = compilation + .build_chunk_graph_artifact + .chunk_by_ukey + .expect_get(chunk_ukey); + let owns_runtime = + chunk.has_runtime(&compilation.build_chunk_graph_artifact.chunk_group_by_ukey); + let current_chunk_generated_requirements = compilation + .build_chunk_graph_artifact + .chunk_graph + .get_chunk_runtime_modules_iterable(chunk_ukey) + .fold( + RuntimeGlobals::default(), + |mut requirements, runtime_module_id| { + let runtime_module = compilation + .runtime_modules + .get(runtime_module_id) + .expect("should have runtime module"); + requirements.insert(runtime_module_generated_requirements(&**runtime_module)); + requirements + }, + ); let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); + let is_hot_update = is_hot_update_chunk(compilation, chunk_ukey); + if is_hot_update { + metadata.tree_runtime_requirements.insert( + RuntimeGlobals::PUBLIC_PATH + | RuntimeGlobals::GET_CHUNK_SCRIPT_FILENAME + | RuntimeGlobals::GET_CHUNK_UPDATE_SCRIPT_FILENAME + | RuntimeGlobals::GET_UPDATE_MANIFEST_FILENAME + | RuntimeGlobals::GET_FULL_HASH + | RuntimeGlobals::LOAD_SCRIPT + | RuntimeGlobals::HAS_OWN_PROPERTY + | RuntimeGlobals::MODULE_CACHE + | RuntimeGlobals::CREATE_SCRIPT_URL, + ); + } + let render_runtime_global = |runtime_global: RuntimeGlobals| { + let render_context_field = |runtime_global: RuntimeGlobals| { + runtime_global + .rspack_context_property_name() + .map(|property_name| { + let value = format!("{runtime_context}{}", property_access([property_name], 0)); + if runtime_global.should_initialize_as_object() { + format!("{value}||{{}}") + } else if runtime_global.should_initialize_as_array() { + format!("{value}||[]") + } else { + value + } + }) + }; + if is_hot_update + && runtime_global.intersects( + RuntimeGlobals::HMR_DOWNLOAD_MANIFEST + | RuntimeGlobals::HMR_DOWNLOAD_UPDATE_HANDLERS + | RuntimeGlobals::HMR_INVALIDATE_MODULE_HANDLERS + | RuntimeGlobals::HMR_MODULE_DATA, + ) + { + return None; + } + if is_hot_update { + return render_context_field(runtime_global); + } + let should_render_context_field = owns_runtime + && runtime_global.intersects(RuntimeGlobals::STARTUP | RuntimeGlobals::STARTUP_ENTRYPOINT) + && metadata + .bootstrap_proxy_requirements + .contains(runtime_global) + || !owns_runtime + && (runtime_global.needs_bootstrap_runtime_context() + || metadata + .runtime_module_requirements + .contains(runtime_global) + && !current_chunk_generated_requirements.contains(runtime_global)); + if runtime_global == RuntimeGlobals::REQUIRE { + Some(runtime_template.render_runtime_variable(&RuntimeVariable::Require)) + } else if runtime_global == RuntimeGlobals::MODULE_FACTORIES + || runtime_global == RuntimeGlobals::MODULE_FACTORIES_ADD_ONLY + { + Some(runtime_template.render_runtime_variable(&RuntimeVariable::Modules)) + } else if runtime_global == RuntimeGlobals::MODULE_CACHE { + Some(runtime_template.render_runtime_variable(&RuntimeVariable::ModuleCache)) + } else if should_render_context_field { + render_context_field(runtime_global) + } else { + None + } + }; sources.add(RawStringSource::from( - metadata.render_lexical_declarations(), + metadata.render_lexical_declarations(Some(&render_runtime_global)), )); - let hmr_runtime_state_variables = hmr_runtime_state_variables(compilation, chunk_ukey); - if !hmr_runtime_state_variables.is_empty() { - let declarations = hmr_runtime_state_variables - .iter() - .map(|name| { - format!( - "{name}={runtime_context}{}", - property_access([name.as_str()], 0) - ) - }) - .collect::>() - .join(","); - sources.add(RawStringSource::from(format!("var {declarations};\n"))); + if metadata.lexical_fields().intersects( + RuntimeGlobals::HMR_DOWNLOAD_UPDATE_HANDLERS + | RuntimeGlobals::HMR_INVALIDATE_MODULE_HANDLERS + | RuntimeGlobals::HMR_MODULE_DATA + | RuntimeGlobals::HMR_RUNTIME_STATE_PREFIX, + ) { + for runtime_module_id in compilation + .build_chunk_graph_artifact + .chunk_graph + .get_chunk_runtime_modules_iterable(chunk_ukey) + { + let runtime_module = compilation + .runtime_modules + .get(runtime_module_id) + .expect("should have runtime module"); + let key = match runtime_module.get_constructor_name().as_str() { + "JsonpChunkLoadingRuntimeModule" => "jsonp", + "ModuleChunkLoadingRuntimeModule" => "module", + "ImportScriptsChunkLoadingRuntimeModule" => "importScripts", + "ReadFileChunkLoadingRuntimeModule" => "readFileVm", + "RequireChunkLoadingRuntimeModule" => "require", + _ => continue, + }; + sources.add(RawStringSource::from(format!("var hmrS_{key};\n"))); + } } } if !render_context_object { @@ -488,45 +676,59 @@ fn render_runtime_context_declarations( Some(sources.boxed()) } -fn render_runtime_context_fields( +fn render_runtime_context_exposed_fields( compilation: &Compilation, chunk_ukey: &ChunkUkey, runtime_template: &ChunkCodeTemplate, - render_setter_fields: bool, - render_plain_fields: bool, + generated_requirements: RuntimeGlobals, ) -> Option { if !runtime_template.uses_lexical_runtime_globals() { return None; } let metadata = runtime_context_metadata(compilation, chunk_ukey)?; + let is_hot_update = is_hot_update_chunk(compilation, chunk_ukey); + let mut context_fields = metadata + .context_fields() + .intersection(generated_requirements); + context_fields.insert(generated_requirements.intersection(metadata.tree_runtime_requirements)); + let hmr_live_binding_fields = RuntimeGlobals::GET_FULL_HASH + | RuntimeGlobals::GET_CHUNK_SCRIPT_FILENAME + | RuntimeGlobals::GET_CHUNK_UPDATE_SCRIPT_FILENAME + | RuntimeGlobals::GET_UPDATE_MANIFEST_FILENAME + | RuntimeGlobals::PUBLIC_PATH; + if !is_hot_update + && metadata + .tree_runtime_requirements + .contains(RuntimeGlobals::HMR_DOWNLOAD_MANIFEST) + { + context_fields.insert(generated_requirements.intersection(hmr_live_binding_fields)); + } + if is_hot_update { + context_fields.insert(generated_requirements); + context_fields.remove(RuntimeGlobals::REQUIRE | RuntimeGlobals::REQUIRE_SCOPE); + } + if context_fields.is_empty() { + return None; + } + let mut sources = ConcatSource::default(); let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); - let render_live_bindings = render_setter_fields && !render_plain_fields; - - for (_, runtime_global) in metadata.context_fields().iter_names() { - let has_setter = metadata.context_setter_fields().contains(runtime_global); - if !render_live_bindings - && ((has_setter && !render_setter_fields) || (!has_setter && !render_plain_fields)) - { - continue; - } - let Some(key) = runtime_global.rspack_context_property_name() else { + for (_, runtime_global) in context_fields.iter_names() { + let (Some(key), Some(lexical_name)) = ( + runtime_global.rspack_context_property_name(), + runtime_global.to_lexical_name(), + ) else { continue; }; - let Some(lexical_name) = runtime_global.to_lexical_name() else { - if render_plain_fields { - sources.add(RawStringSource::from(format!( - "{}{} = {{}};\n", - runtime_context, - property_access([key], 0) - ))); - } - continue; - }; - - if render_live_bindings || has_setter { + let needs_live_binding = !is_hot_update + && (metadata.context_setter_fields().contains(runtime_global) + || hmr_live_binding_fields.contains(runtime_global) + && metadata + .tree_runtime_requirements + .contains(RuntimeGlobals::HMR_DOWNLOAD_MANIFEST)); + if needs_live_binding { sources.add(RawStringSource::from(format!( "Object.defineProperty({}, {}, {{ configurable: true, get: function() {{ return {}; }}, set: function(value) {{ {} = value; }} }});\n", runtime_context, @@ -557,7 +759,7 @@ fn render_runtime_context_field_initializers( return None; } - let metadata = runtime_context_render_metadata(compilation, chunk_ukey)?; + let metadata = runtime_context_current_chunk_metadata(compilation, chunk_ukey)?; let mut sources = ConcatSource::default(); let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); @@ -606,55 +808,15 @@ fn render_hot_update_runtime_variable_bindings( let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); let require = runtime_template.render_runtime_variable(&RuntimeVariable::Require); let modules = runtime_template.render_runtime_variable(&RuntimeVariable::Modules); + let module_cache = runtime_template.render_runtime_variable(&RuntimeVariable::ModuleCache); Some( RawStringSource::from(format!( - "var {require}={runtime_context}.r,{modules}={runtime_context}.m;\n" + "var {require}={runtime_context}.r,{modules}={runtime_context}.m,{module_cache}={runtime_context}.c;\n" )) .boxed(), ) } -fn render_runtime_context_setter_assignments( - compilation: &Compilation, - chunk_ukey: &ChunkUkey, - runtime_template: &ChunkCodeTemplate, -) -> Option { - if !runtime_template.uses_lexical_runtime_globals() { - return None; - } - - let metadata = runtime_context_render_metadata(compilation, chunk_ukey)?; - let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); - Some(RawStringSource::from(metadata.render_context_setter_assignments(&runtime_context)).boxed()) -} - -fn render_hmr_runtime_state_final_fields( - compilation: &Compilation, - chunk_ukey: &ChunkUkey, - runtime_template: &ChunkCodeTemplate, -) -> Option { - if !runtime_template.uses_lexical_runtime_globals() { - return None; - } - - let variables = hmr_runtime_state_variables(compilation, chunk_ukey); - if variables.is_empty() { - return None; - } - - let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); - let assignments = variables - .iter() - .map(|name| { - format!( - "{runtime_context}{}={name};", - property_access([name.as_str()], 0) - ) - }) - .collect::(); - Some(RawStringSource::from(assignments).boxed()) -} - pub async fn render_chunk_runtime_modules( compilation: &Compilation, chunk_ukey: &ChunkUkey, @@ -684,13 +846,16 @@ pub async fn render_runtime_modules( runtime_template: &ChunkCodeTemplate, ) -> Result { let mut sources = ConcatSource::default(); - let runtime_module_sources = rspack_parallel::scope::<_, Result<_>>(|token| { + let mut runtime_module_sources = rspack_parallel::scope::<_, Result<_>>(|token| { compilation .build_chunk_graph_artifact .chunk_graph .get_chunk_runtime_modules_in_order(chunk_ukey, compilation) - .map(|(identifier, runtime_module)| { + .enumerate() + .map(|(index, (identifier, runtime_module))| { ( + index, + runtime_module.stage(), compilation .runtime_modules_code_generation_source .get(identifier) @@ -698,13 +863,19 @@ pub async fn render_runtime_modules( runtime_module, ) }) - .for_each(|(source, module)| { + .for_each(|(index, stage, source, module)| { let s = unsafe { token.used((compilation, source, module, runtime_template)) }; s.spawn( - |(compilation, source, module, runtime_template)| async move { + move |(compilation, source, module, runtime_template)| async move { if source.size() == 0 { - return Ok(ConcatSource::default().boxed()); + return Ok(( + index, + stage, + ConcatSource::default().boxed(), + RuntimeGlobals::default(), + )); } + let generated_requirements = runtime_module_generated_requirements(module); if runtime_template.uses_runtime_context() && (module.get_custom_source().is_some() || module.get_constructor_name() == "RuntimeModuleFromJs") @@ -752,7 +923,7 @@ pub async fn render_runtime_modules( module.should_isolate(), supports_arrow_function, ); - Ok(sources) + Ok((index, stage, sources, generated_requirements)) }, ); }) @@ -760,7 +931,12 @@ pub async fn render_runtime_modules( .await .into_iter() .map(|r| r.to_rspack_result()) + .collect::>>()? + .into_iter() .collect::>>()?; + runtime_module_sources.sort_by(|(a_index, a_stage, _, _), (b_index, b_stage, _, _)| { + a_stage.cmp(b_stage).then_with(|| a_index.cmp(b_index)) + }); let isolate_runtime_context = runtime_template.uses_runtime_context() && runtime_template.uses_lexical_runtime_globals() @@ -771,15 +947,15 @@ pub async fn render_runtime_modules( }); let is_hot_update = is_hot_update_chunk(compilation, chunk_ukey); - let has_runtime_context = - is_hot_update || has_bootstrap_runtime_context(compilation, chunk_ukey, runtime_template); + let chunk = compilation + .build_chunk_graph_artifact + .chunk_by_ukey + .expect_get(chunk_ukey); + let owns_runtime = chunk.has_runtime(&compilation.build_chunk_graph_artifact.chunk_group_by_ukey); + let has_runtime_context = is_hot_update + || has_bootstrap_runtime_context(compilation, chunk_ukey, runtime_template) + || (!owns_runtime && runtime_template.uses_runtime_context()); if isolate_runtime_context { - if !has_runtime_context - && let Some(context_declarations) = - render_runtime_context_declarations(compilation, chunk_ukey, runtime_template, false, true) - { - sources.add(context_declarations); - } let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); sources.add(RawStringSource::from(format!( "(function({runtime_context}) {{\n" @@ -798,12 +974,14 @@ pub async fn render_runtime_modules( ) { sources.add(context_declarations); } - if let Some(context_fields) = render_runtime_context_field_initializers( - compilation, - chunk_ukey, - runtime_template, - is_hot_update, - ) { + if !has_runtime_context + && let Some(context_fields) = render_runtime_context_field_initializers( + compilation, + chunk_ukey, + runtime_template, + is_hot_update, + ) + { sources.add(context_fields); } if is_hot_update @@ -811,36 +989,17 @@ pub async fn render_runtime_modules( { sources.add(bindings); } - if !is_hot_update - && let Some(context_fields) = - render_runtime_context_fields(compilation, chunk_ukey, runtime_template, true, false) - { - sources.add(context_fields); - } - for runtime_module_source in runtime_module_sources { - sources.add(runtime_module_source?); - } - if let Some(context_fields) = - render_hmr_runtime_state_final_fields(compilation, chunk_ukey, runtime_template) - { - sources.add(context_fields); - } - if is_hot_update - && let Some(context_fields) = - render_runtime_context_setter_assignments(compilation, chunk_ukey, runtime_template) - { - sources.add(context_fields); - } - if is_hot_update { - if let Some(context_fields) = - render_runtime_context_fields(compilation, chunk_ukey, runtime_template, false, true) - { + for (_, _, runtime_module_source, generated_requirements) in runtime_module_sources { + let context_fields = render_runtime_context_exposed_fields( + compilation, + chunk_ukey, + runtime_template, + generated_requirements, + ); + sources.add(runtime_module_source); + if let Some(context_fields) = context_fields { sources.add(context_fields); } - } else if let Some(context_fields) = - render_runtime_context_fields(compilation, chunk_ukey, runtime_template, false, true) - { - sources.add(context_fields); } if isolate_runtime_context { let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); diff --git a/crates/rspack_plugin_mf/src/container/container_entry_module.rs b/crates/rspack_plugin_mf/src/container/container_entry_module.rs index dfb7cbb4da98..9d66fac75b78 100644 --- a/crates/rspack_plugin_mf/src/container/container_entry_module.rs +++ b/crates/rspack_plugin_mf/src/container/container_entry_module.rs @@ -6,11 +6,11 @@ use rspack_collections::{Identifiable, Identifier}; use rspack_core::{ AsyncDependenciesBlock, AsyncDependenciesBlockIdentifier, BoxDependency, BoxModule, BuildContext, BuildInfo, BuildMeta, BuildMetaExportsType, BuildResult, ChunkGroupOptions, CodeGenerationResult, - Compilation, Context, DependenciesBlock, Dependency, DependencyId, DependencyType, - ExportsArgument, FactoryMeta, GroupOptions, LibIdentOptions, Module, ModuleCodeGenerationContext, - ModuleCodeTemplate, ModuleDependency, ModuleGraph, ModuleIdentifier, ModuleType, RuntimeGlobals, - RuntimeSpec, SourceType, StaticExportsDependency, StaticExportsSpec, impl_module_meta_info, - impl_source_map_config, module_update_hash, + CodeGenerationRuntimeRequirementsWrite, Compilation, Context, DependenciesBlock, Dependency, + DependencyId, DependencyType, ExportsArgument, FactoryMeta, GroupOptions, LibIdentOptions, + Module, ModuleCodeGenerationContext, ModuleCodeTemplate, ModuleDependency, ModuleGraph, + ModuleIdentifier, ModuleType, RuntimeGlobals, RuntimeSpec, SourceType, StaticExportsDependency, + StaticExportsSpec, impl_module_meta_info, impl_source_map_config, module_update_hash, rspack_sources::{BoxSource, RawStringSource, SourceExt}, }; use rspack_error::{Result, impl_empty_diagnosable_trait}; @@ -413,6 +413,13 @@ var init = function(shareScope, initScope) {{ code_generation_result = code_generation_result.with_javascript(RawStringSource::from(source).boxed()); code_generation_result.add(SourceType::Expose, RawStringSource::from_static("").boxed()); + if !self.enhanced { + code_generation_result + .data + .insert(CodeGenerationRuntimeRequirementsWrite { + runtime_requirements: RuntimeGlobals::CURRENT_REMOTE_GET_SCOPE, + }); + } if self.enhanced { code_generation_result .data diff --git a/tests/rspack-test/hotCases/worker/update-in-worker/index.js b/tests/rspack-test/hotCases/worker/update-in-worker/index.js index 95de65c0a30c..2f828ce22573 100644 --- a/tests/rspack-test/hotCases/worker/update-in-worker/index.js +++ b/tests/rspack-test/hotCases/worker/update-in-worker/index.js @@ -1,17 +1,24 @@ it("should support hot module replacement in WebWorkers", async () => { const worker = new Worker(new URL("worker.js", import.meta.url)); - worker.onmessage = async ({ data: msg }) => { - switch (msg) { - case "next": - await NEXT_HMR(); - worker.postMessage("next"); - break; - case "done": - await worker.terminate(); - break; - default: - throw new Error(`Unexpected message: ${msg}`); - } - }; - worker.postMessage("test"); + await new Promise((resolve, reject) => { + worker.onmessage = async ({ data: msg }) => { + try { + switch (msg) { + case "next": + await NEXT_HMR(); + worker.postMessage("next"); + break; + case "done": + await worker.terminate(); + resolve(); + break; + default: + reject(new Error(`Unexpected message: ${msg}`)); + } + } catch (e) { + reject(e); + } + }; + worker.postMessage("test"); + }); }); From 9fa902ac3f4b0960770214eeddf17c3e570839c4 Mon Sep 17 00:00:00 2001 From: LingyuCoder Date: Fri, 12 Jun 2026 13:58:58 +0800 Subject: [PATCH 13/21] fix(runtime): expose generated runtime globals in rspack mode --- crates/rspack_plugin_javascript/src/runtime.rs | 9 +++++++-- .../configCases/rsdoctor/assets/rspack.config.js | 4 ++-- .../configCases/runtime/runtime-condition/a.js | 2 +- .../trusted-types/module-runtime-requirement/index.js | 2 +- .../configCases/trusted-types/web-worker/index.js | 9 ++++++--- tests/rspack-test/configCases/unique-id/all/index.js | 2 +- tests/rspack-test/configCases/unique-id/array/index.js | 2 +- tests/rspack-test/configCases/version/all/index.js | 2 +- tests/rspack-test/configCases/version/array/index.js | 2 +- 9 files changed, 21 insertions(+), 13 deletions(-) diff --git a/crates/rspack_plugin_javascript/src/runtime.rs b/crates/rspack_plugin_javascript/src/runtime.rs index a4dabfca7fba..491c9478941d 100644 --- a/crates/rspack_plugin_javascript/src/runtime.rs +++ b/crates/rspack_plugin_javascript/src/runtime.rs @@ -435,6 +435,8 @@ fn runtime_module_generated_requirements(runtime_module: &dyn RuntimeModule) -> | RuntimeGlobals::DEFERRED_MODULES_ASYNC_TRANSITIVE_DEPENDENCIES | RuntimeGlobals::DEFERRED_MODULES_ASYNC_TRANSITIVE_DEPENDENCIES_SYMBOL } + "AsyncWasmLoadingRuntimeModule" => RuntimeGlobals::INSTANTIATE_WASM, + "AsyncWasmCompileRuntimeModule" => RuntimeGlobals::COMPILE_WASM, "BaseUriRuntimeModule" => RuntimeGlobals::BASE_URI, "PublicPathRuntimeModule" | "AutoPublicPathRuntimeModule" => RuntimeGlobals::PUBLIC_PATH, "GetChunkFilenameRuntimeModule" if module_name.contains("javascript") => { @@ -470,7 +472,7 @@ fn runtime_module_generated_requirements(runtime_module: &dyn RuntimeModule) -> "EmbedFederationRuntimeModule" => RuntimeGlobals::STARTUP, "StartupEntrypointRuntimeModule" => RuntimeGlobals::STARTUP_ENTRYPOINT, "StartupChunkDependenciesRuntimeModule" => RuntimeGlobals::STARTUP, - "EnsureChunkRuntimeModule" => { + "EnsureChunkRuntimeModule" | "EsmEnsureChunkRuntimeModule" => { RuntimeGlobals::ENSURE_CHUNK | RuntimeGlobals::ENSURE_CHUNK_HANDLERS } "JsonpChunkLoadingRuntimeModule" @@ -499,6 +501,9 @@ fn runtime_module_generated_requirements(runtime_module: &dyn RuntimeModule) -> "MakeOptimizedDeferredNamespaceObjectRuntimeModule" => { RuntimeGlobals::MAKE_OPTIMIZED_DEFERRED_NAMESPACE_OBJECT } + "RscManifestRuntimeModule" => RuntimeGlobals::RSC_MANIFEST, + "RspackVersionRuntimeModule" => RuntimeGlobals::RSPACK_VERSION, + "RspackUniqueIdRuntimeModule" => RuntimeGlobals::RSPACK_UNIQUE_ID, "ToBinaryRuntimeModule" => RuntimeGlobals::TO_BINARY, _ => RuntimeGlobals::default(), } @@ -1004,7 +1009,7 @@ pub async fn render_runtime_modules( if isolate_runtime_context { let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); sources.add(RawStringSource::from(format!( - "\n}})({runtime_context});\n" + "\n}}).call(this, {runtime_context});\n" ))); } diff --git a/tests/rspack-test/configCases/rsdoctor/assets/rspack.config.js b/tests/rspack-test/configCases/rsdoctor/assets/rspack.config.js index 827be3a7fd2f..fbe289c06558 100644 --- a/tests/rspack-test/configCases/rsdoctor/assets/rspack.config.js +++ b/tests/rspack-test/configCases/rsdoctor/assets/rspack.config.js @@ -37,11 +37,11 @@ module.exports = { expect(assetsInfo).toEqual([ { path: 'a.js', - size: 6104, + size: 4753, }, { path: 'b.js', - size: 6104, + size: 4753, }, { path: 'c_js.js', diff --git a/tests/rspack-test/configCases/runtime/runtime-condition/a.js b/tests/rspack-test/configCases/runtime/runtime-condition/a.js index 01991d2bb477..9698e7ad0a1c 100644 --- a/tests/rspack-test/configCases/runtime/runtime-condition/a.js +++ b/tests/rspack-test/configCases/runtime/runtime-condition/a.js @@ -17,7 +17,7 @@ it("should include runtime condition check code", () => { ), "utf-8" ); - if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + if (source.includes("__rspack_context.j")) { expect(source).toContain(`"a-runtime" == __rspack_context.j`) expect(source).toContain(`"b-runtime" == __rspack_context.j`); expect(source).toContain(`/^[ab]x\\-name$/.test(__rspack_context.j)`); diff --git a/tests/rspack-test/configCases/trusted-types/module-runtime-requirement/index.js b/tests/rspack-test/configCases/trusted-types/module-runtime-requirement/index.js index 9715917734bd..d4cde08e76cd 100644 --- a/tests/rspack-test/configCases/trusted-types/module-runtime-requirement/index.js +++ b/tests/rspack-test/configCases/trusted-types/module-runtime-requirement/index.js @@ -14,7 +14,7 @@ createWorker; it("should generate correct new Worker statement", async () => { const content = fs.readFileSync(path.resolve(path.dirname(__filename), './test-worker.js'), "utf-8"); expect(content).toContain(`this is worker`); - if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + if (content.includes("__rspack_context")) { expect(content).toContain(`(__unused_rspack_module, __unused_rspack_exports, __rspack_context)`); expect(content).toContain(`eval(__rspack_context.ts(`); } else { diff --git a/tests/rspack-test/configCases/trusted-types/web-worker/index.js b/tests/rspack-test/configCases/trusted-types/web-worker/index.js index a459fab81899..63483b6d1a62 100644 --- a/tests/rspack-test/configCases/trusted-types/web-worker/index.js +++ b/tests/rspack-test/configCases/trusted-types/web-worker/index.js @@ -1,6 +1,9 @@ const fs = __non_webpack_require__("fs"); const path = __non_webpack_require__("path"); +const isRspackRuntimeMode = + globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK || + __dirname.includes("runtime-mode-config"); function createWorker() { new Worker(new URL("./worker.js", import.meta.url), { @@ -12,7 +15,7 @@ createWorker; it("should generate correct new Worker statement", async () => { const content = fs.readFileSync(__filename, "utf-8"); - if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + if (isRspackRuntimeMode) { expect(content).toContain(`new Worker(__rspack_context.tu(new URL(`) } else { expect(content).toContain(`new Worker(__webpack_require__.tu(new URL(`) @@ -29,7 +32,7 @@ createWorkerWithChunkName it("should generate correct new Worker statement with magic comments", async () => { const content = fs.readFileSync(__filename, "utf-8"); const chunkName = "someChunkName"; - if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + if (isRspackRuntimeMode) { expect(content).toContain(`new Worker(/* webpackChunkName: "${chunkName}" */__rspack_context.tu(new URL(`) } else { expect(content).toContain(`new Worker(/* webpackChunkName: "${chunkName}" */__webpack_require__.tu(new URL(`) @@ -47,7 +50,7 @@ createWorkerWithChunkNameInnner it("should generate correct new Worker statement with magic comments", async () => { const content = fs.readFileSync(__filename, "utf-8"); const chunkName = "someChunkName2"; - if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { + if (isRspackRuntimeMode) { expect(content).toContain(`new Worker(__rspack_context.tu(new URL(/* webpackChunkName: "${chunkName}" */`) } else { expect(content).toContain(`new Worker(__webpack_require__.tu(new URL(/* webpackChunkName: "${chunkName}" */`) diff --git a/tests/rspack-test/configCases/unique-id/all/index.js b/tests/rspack-test/configCases/unique-id/all/index.js index 477b129d6481..f9f8ee572ced 100644 --- a/tests/rspack-test/configCases/unique-id/all/index.js +++ b/tests/rspack-test/configCases/unique-id/all/index.js @@ -4,7 +4,7 @@ const fs = require("fs"); it("should inject unique id when use bundlerInfo.force=true", () => { const source = fs.readFileSync(path.join(__dirname, "bundle0.js"), "utf-8"); if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { - expect(source).toMatch(/Object\.defineProperty\(__rspack_context, "ruid"/m); + expect(source).toMatch(/__rspack_context\.ruid =/m); } else { expect(source).toMatch(/(^|[^"'`])__webpack_require__\.ruid =/m); } diff --git a/tests/rspack-test/configCases/unique-id/array/index.js b/tests/rspack-test/configCases/unique-id/array/index.js index 39521ce5313c..fdb102a79ae6 100644 --- a/tests/rspack-test/configCases/unique-id/array/index.js +++ b/tests/rspack-test/configCases/unique-id/array/index.js @@ -4,7 +4,7 @@ const fs = require("fs"); it('should inject unique id when use bundlerInfo.force=["uniqueId"]', () => { const source = fs.readFileSync(path.join(__dirname, "bundle0.js"), "utf-8"); if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { - expect(source).toMatch(/Object\.defineProperty\(__rspack_context, "ruid"/m); + expect(source).toMatch(/__rspack_context\.ruid =/m); } else { expect(source).toMatch(/(^|[^"'`])__webpack_require__\.ruid =/m); } diff --git a/tests/rspack-test/configCases/version/all/index.js b/tests/rspack-test/configCases/version/all/index.js index c29ad2e51b46..fbc207d264e8 100644 --- a/tests/rspack-test/configCases/version/all/index.js +++ b/tests/rspack-test/configCases/version/all/index.js @@ -4,7 +4,7 @@ const fs = require("fs"); it("should inject version when use bundlerInfo.force=true", () => { const source = fs.readFileSync(path.join(__dirname, "bundle0.js"), "utf-8"); if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { - expect(source).toMatch(/Object\.defineProperty\(__rspack_context, "rv"/m); + expect(source).toMatch(/__rspack_context\.rv =/m); } else { expect(source).toMatch(/(^|[^"'`])__webpack_require__\.rv =/m); } diff --git a/tests/rspack-test/configCases/version/array/index.js b/tests/rspack-test/configCases/version/array/index.js index 9f8d40ddf55a..4ce31f210582 100644 --- a/tests/rspack-test/configCases/version/array/index.js +++ b/tests/rspack-test/configCases/version/array/index.js @@ -4,7 +4,7 @@ const fs = require("fs"); it('should inject version when use bundlerInfo.force=["version"]', () => { const source = fs.readFileSync(path.join(__dirname, "bundle0.js"), "utf-8"); if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { - expect(source).toMatch(/Object\.defineProperty\(__rspack_context, "rv"/m); + expect(source).toMatch(/__rspack_context\.rv =/m); } else { expect(source).toMatch(/(^|[^"'`])__webpack_require__\.rv =/m); } From 736f0f3113f722981f9bccf44521d8475aba7b00 Mon Sep 17 00:00:00 2001 From: LingyuCoder Date: Fri, 12 Jun 2026 19:08:22 +0800 Subject: [PATCH 14/21] refactor(runtime): split runtime context rendering --- .../compilation/runtime_requirements/mod.rs | 40 +- crates/rspack_core/src/runtime_globals.rs | 31 +- crates/rspack_core/src/runtime_module.rs | 3 + .../rspack_plugin_esm_library/src/runtime.rs | 8 + .../src/hot_module_replacement.rs | 4 + crates/rspack_plugin_javascript/src/lib.rs | 1 + .../src/plugin/mod.rs | 180 ++-- .../src/plugin/runtime_context.rs | 913 ++++++++++++++++++ .../rspack_plugin_javascript/src/runtime.rs | 623 +----------- .../src/runtime_context.rs | 365 +++++++ .../src/visitors/scope_info.rs | 10 +- .../embed_federation_runtime_module.rs | 8 +- .../src/container/remote_runtime_module.rs | 4 + .../src/sharing/share_runtime_module.rs | 4 + .../src/manifest_runtime_module.rs | 8 +- .../src/runtime_module/amd_define.rs | 7 +- .../src/runtime_module/amd_options.rs | 7 +- .../src/runtime_module/async_module.rs | 7 + .../src/runtime_module/auto_public_path.rs | 4 + .../src/runtime_module/base_uri.rs | 7 +- .../src/runtime_module/chunk_name.rs | 7 +- .../chunk_prefetch_preload_function.rs | 4 + .../compat_get_default_export.rs | 4 + .../create_fake_namespace_object.rs | 4 + .../src/runtime_module/create_script.rs | 4 + .../src/runtime_module/create_script_url.rs | 4 + .../runtime_module/define_property_getters.rs | 4 + .../src/runtime_module/ensure_chunk.rs | 4 + .../runtime_module/esm_module_decorator.rs | 7 +- .../src/runtime_module/get_chunk_filename.rs | 8 + .../get_chunk_update_filename.rs | 4 + .../src/runtime_module/get_full_hash.rs | 7 +- .../src/runtime_module/get_main_filename.rs | 4 + .../get_trusted_types_policy.rs | 8 +- .../src/runtime_module/global.rs | 7 +- .../src/runtime_module/has_own_property.rs | 7 +- .../import_scripts_chunk_loading.rs | 10 + .../src/runtime_module/jsonp_chunk_loading.rs | 10 + .../src/runtime_module/load_script.rs | 4 + .../make_deferred_namespace_object_runtime.rs | 4 + .../runtime_module/make_namespace_object.rs | 7 +- ...mized_deferred_namespace_object_runtime.rs | 4 + .../runtime_module/module_chunk_loading.rs | 10 + .../runtime_module/node_module_decorator.rs | 7 +- .../src/runtime_module/nonce.rs | 7 +- .../src/runtime_module/on_chunk_loaded.rs | 7 +- .../src/runtime_module/public_path.rs | 6 +- .../runtime_module/readfile_chunk_loading.rs | 10 + .../src/runtime_module/relative_url.rs | 7 +- .../require_js_chunk_loading.rs | 10 + .../src/runtime_module/rspack_unique_id.rs | 8 +- .../src/runtime_module/rspack_version.rs | 7 +- .../src/runtime_module/runtime_id.rs | 7 +- .../startup_chunk_dependencies.rs | 4 + .../src/runtime_module/startup_entrypoint.rs | 4 + .../src/runtime_module/system_context.rs | 7 +- .../src/runtime_module/to_binary.rs | 7 +- crates/rspack_plugin_wasm/src/runtime.rs | 13 +- .../RuntimeModeConfig.part1.test.js | 33 + .../RuntimeModeConfig.part2.test.js | 35 + ...est.js => RuntimeModeConfig.part3.test.js} | 3 + .../rsdoctor/assets/rspack.config.js | 12 +- tests/rspack-test/rstest.config.mts | 1 - 63 files changed, 1799 insertions(+), 766 deletions(-) create mode 100644 crates/rspack_plugin_javascript/src/plugin/runtime_context.rs create mode 100644 crates/rspack_plugin_javascript/src/runtime_context.rs create mode 100644 tests/rspack-test/RuntimeModeConfig.part1.test.js create mode 100644 tests/rspack-test/RuntimeModeConfig.part2.test.js rename tests/rspack-test/{RuntimeModeConfig.test.js => RuntimeModeConfig.part3.test.js} (92%) diff --git a/crates/rspack_core/src/compilation/runtime_requirements/mod.rs b/crates/rspack_core/src/compilation/runtime_requirements/mod.rs index 9419768f1fd1..2a3674f2c326 100644 --- a/crates/rspack_core/src/compilation/runtime_requirements/mod.rs +++ b/crates/rspack_core/src/compilation/runtime_requirements/mod.rs @@ -3,8 +3,11 @@ use rustc_hash::{FxHashMap, FxHashSet}; use super::*; use crate::{ - CodeGenerationRuntimeRequirementsWrite, RuntimeProxyMetadata, cache::Cache, - compilation::pass::PassExt, logger::Logger, runtime_globals::BOOTSTRAP_RUNTIME_CONTEXT_GLOBALS, + CodeGenerationRuntimeRequirementsWrite, RuntimeProxyMetadata, + cache::Cache, + compilation::pass::PassExt, + logger::Logger, + runtime_globals::{BOOTSTRAP_RUNTIME_CONTEXT_GLOBALS, HOT_RUNTIME_WRITE_GLOBALS}, runtime_mode::RuntimeMode as ExperimentRuntimeMode, }; @@ -541,17 +544,6 @@ pub async fn process_chunks_runtime_requirements( .build_chunk_graph_artifact .chunk_by_ukey .expect_get(chunk_ukey); - if let Some(chunk_runtime_requirements) = compilation - .cgc_runtime_requirements_artifact - .get(chunk_ukey) - { - metadata - .tree_runtime_requirements - .insert(*chunk_runtime_requirements); - metadata - .bootstrap_proxy_requirements - .insert(chunk_runtime_requirements.intersection(*BOOTSTRAP_RUNTIME_CONTEXT_GLOBALS)); - } for mid in compilation .build_chunk_graph_artifact .chunk_graph @@ -591,13 +583,6 @@ pub async fn process_chunks_runtime_requirements( .expect("should have runtime module"); let additional_runtime_requirements = runtime_module.additional_runtime_requirements(compilation); - if runtime_module.get_custom_source().is_some() - || runtime_module.get_constructor_name() == "RuntimeModuleFromJs" - { - metadata - .hook_exposed_requirements - .insert(additional_runtime_requirements); - } metadata .runtime_module_requirements .insert(additional_runtime_requirements); @@ -614,13 +599,16 @@ pub async fn process_chunks_runtime_requirements( .tree_runtime_requirements .contains(RuntimeGlobals::HMR_DOWNLOAD_MANIFEST) { - metadata.context_setter_fields.insert( - RuntimeGlobals::HMR_DOWNLOAD_MANIFEST - | RuntimeGlobals::HMR_DOWNLOAD_UPDATE_HANDLERS - | RuntimeGlobals::HMR_INVALIDATE_MODULE_HANDLERS - | RuntimeGlobals::HMR_MODULE_DATA, - ); + metadata + .context_setter_fields + .insert(*HOT_RUNTIME_WRITE_GLOBALS); } + metadata.bootstrap_proxy_requirements.insert( + metadata + .tree_runtime_requirements + .intersection(*BOOTSTRAP_RUNTIME_CONTEXT_GLOBALS), + ); + compilation .runtime_proxy_metadata_artifact .insert(entry_ukey, metadata); diff --git a/crates/rspack_core/src/runtime_globals.rs b/crates/rspack_core/src/runtime_globals.rs index 6992ae117bb7..3cc26aac1e7b 100644 --- a/crates/rspack_core/src/runtime_globals.rs +++ b/crates/rspack_core/src/runtime_globals.rs @@ -346,6 +346,25 @@ pub static BOOTSTRAP_RUNTIME_CONTEXT_GLOBALS: LazyLock = LazyLoc | RuntimeGlobals::STARTUP }); +pub static HOT_RUNTIME_WRITE_GLOBALS: LazyLock = LazyLock::new(|| { + RuntimeGlobals::HMR_DOWNLOAD_MANIFEST + | RuntimeGlobals::HMR_DOWNLOAD_UPDATE_HANDLERS + | RuntimeGlobals::HMR_INVALIDATE_MODULE_HANDLERS + | RuntimeGlobals::HMR_MODULE_DATA +}); + +pub static INITIALIZE_OBJECT_GLOBALS: LazyLock = LazyLock::new(|| { + RuntimeGlobals::ENSURE_CHUNK_HANDLERS + | RuntimeGlobals::PREFETCH_CHUNK_HANDLERS + | RuntimeGlobals::PRELOAD_CHUNK_HANDLERS + | RuntimeGlobals::HMR_DOWNLOAD_UPDATE_HANDLERS + | RuntimeGlobals::HMR_INVALIDATE_MODULE_HANDLERS + | RuntimeGlobals::HMR_MODULE_DATA +}); + +pub static INITIALIZE_ARRAY_GLOBALS: LazyLock = + LazyLock::new(|| RuntimeGlobals::INTERCEPT_MODULE_EXECUTION); + pub fn runtime_globals_property_name(runtime_globals: &RuntimeGlobals) -> Option<&'static str> { Some(match *runtime_globals { RuntimeGlobals::REQUIRE_SCOPE => "*", @@ -573,19 +592,11 @@ impl RuntimeGlobals { } pub fn should_initialize_as_object(&self) -> bool { - matches!( - *self, - RuntimeGlobals::ENSURE_CHUNK_HANDLERS - | RuntimeGlobals::PREFETCH_CHUNK_HANDLERS - | RuntimeGlobals::PRELOAD_CHUNK_HANDLERS - | RuntimeGlobals::HMR_DOWNLOAD_UPDATE_HANDLERS - | RuntimeGlobals::HMR_INVALIDATE_MODULE_HANDLERS - | RuntimeGlobals::HMR_MODULE_DATA - ) + !self.intersection(*INITIALIZE_OBJECT_GLOBALS).is_empty() } pub fn should_initialize_as_array(&self) -> bool { - matches!(*self, RuntimeGlobals::INTERCEPT_MODULE_EXECUTION) + !self.intersection(*INITIALIZE_ARRAY_GLOBALS).is_empty() } pub fn needs_bootstrap_runtime_context(&self) -> bool { diff --git a/crates/rspack_core/src/runtime_module.rs b/crates/rspack_core/src/runtime_module.rs index 9e4220a29677..b7f8ea3c5942 100644 --- a/crates/rspack_core/src/runtime_module.rs +++ b/crates/rspack_core/src/runtime_module.rs @@ -48,6 +48,9 @@ pub trait RuntimeModule: fn additional_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { RuntimeGlobals::default() } + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::default() + } } pub trait AttachableRuntimeModule { diff --git a/crates/rspack_plugin_esm_library/src/runtime.rs b/crates/rspack_plugin_esm_library/src/runtime.rs index 0aec1b68a39b..b229dadeaed0 100644 --- a/crates/rspack_plugin_esm_library/src/runtime.rs +++ b/crates/rspack_plugin_esm_library/src/runtime.rs @@ -85,6 +85,10 @@ impl RuntimeModule for EsmEnsureChunkRuntimeModule { fn additional_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { RuntimeGlobals::REQUIRE_SCOPE | RuntimeGlobals::ENSURE_CHUNK_HANDLERS } + + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::ENSURE_CHUNK | RuntimeGlobals::ENSURE_CHUNK_HANDLERS + } } #[impl_runtime_module] @@ -175,4 +179,8 @@ var chunkMap = {{ fn additional_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { RuntimeGlobals::REQUIRE_SCOPE } + + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::EXTERNAL_INSTALL_CHUNK + } } diff --git a/crates/rspack_plugin_hmr/src/hot_module_replacement.rs b/crates/rspack_plugin_hmr/src/hot_module_replacement.rs index 4f516e18808c..6ca193303a7b 100644 --- a/crates/rspack_plugin_hmr/src/hot_module_replacement.rs +++ b/crates/rspack_plugin_hmr/src/hot_module_replacement.rs @@ -48,4 +48,8 @@ impl RuntimeModule for HotModuleReplacementRuntimeModule { fn additional_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { *HOT_MODULE_REPLACEMENT_RUNTIME_REQUIREMENTS } + + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::INTERCEPT_MODULE_EXECUTION + } } diff --git a/crates/rspack_plugin_javascript/src/lib.rs b/crates/rspack_plugin_javascript/src/lib.rs index 2c12aea55c10..6ea3e5865d87 100644 --- a/crates/rspack_plugin_javascript/src/lib.rs +++ b/crates/rspack_plugin_javascript/src/lib.rs @@ -8,6 +8,7 @@ pub mod parser_and_generator; mod parser_plugin; mod plugin; pub mod runtime; +mod runtime_context; pub mod utils; pub mod visitors; pub use magic_comment::{RspackCommentMap, try_extract_magic_comment}; diff --git a/crates/rspack_plugin_javascript/src/plugin/mod.rs b/crates/rspack_plugin_javascript/src/plugin/mod.rs index 1a1f0d2262d3..d376fd7fbe43 100644 --- a/crates/rspack_plugin_javascript/src/plugin/mod.rs +++ b/crates/rspack_plugin_javascript/src/plugin/mod.rs @@ -17,6 +17,7 @@ pub mod infer_async_modules_plugin; mod inline_exports_plugin; mod mangle_exports_plugin; pub mod module_concatenation_plugin; +mod runtime_context; mod side_effects_flag_plugin; pub mod url_plugin; @@ -32,7 +33,7 @@ use rspack_core::{ CodeGenerationDataTopLevelDeclarations, Compilation, CompilationId, ConcatenatedModuleIdent, ExportsArgument, Module, RuntimeGlobals, RuntimeVariable, SourceType, concatenated_module::{collect_ident, find_new_name}, - property_access, render_init_fragments, + render_init_fragments, reserved_names::RESERVED_NAMES_ATOM_SET, rspack_sources::{BoxSource, ConcatSource, RawStringSource, ReplaceSource, Source, SourceExt}, split_readable_identifier, @@ -52,9 +53,7 @@ use swc_experimental_ecma_semantic::resolver::resolver; use tokio::sync::RwLock; use crate::runtime::{ - render_chunk_modules, render_module, render_runtime_context_declaration, - render_runtime_context_require_assignment, render_runtime_modules, should_render_runtime_context, - stringify_array, + render_chunk_modules, render_module, render_runtime_modules, stringify_array, }; #[cfg_attr(allocative, allocative::root)] @@ -137,6 +136,23 @@ impl JsPlugin { chunk_ukey: &ChunkUkey, compilation: &'me Compilation, runtime_template: &ChunkCodeTemplate, + ) -> Vec> { + if compilation + .options + .experiments + .runtime_mode + .uses_runtime_context() + { + return Self::render_rspack_require(chunk_ukey, compilation, runtime_template); + } + + Self::render_webpack_require(chunk_ukey, compilation, runtime_template) + } + + pub fn render_webpack_require<'me>( + chunk_ukey: &ChunkUkey, + compilation: &'me Compilation, + runtime_template: &ChunkCodeTemplate, ) -> Vec> { let runtime_requirements = compilation .cgc_runtime_requirements_artifact @@ -147,14 +163,8 @@ impl JsPlugin { let strict_module_error_handling = compilation.options.output.strict_module_error_handling; let need_module_defer = runtime_requirements.contains(RuntimeGlobals::MAKE_DEFERRED_NAMESPACE_OBJECT); - let uses_runtime_context = compilation - .options - .experiments - .runtime_mode - .uses_runtime_context(); let callable_require = runtime_template.render_runtime_variable(&RuntimeVariable::Require); let require_argument = runtime_template.render_runtime_argument(); - let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); let module_factories = runtime_template.render_runtime_variable(&RuntimeVariable::Modules); let module_cache = runtime_template.render_runtime_variable(&RuntimeVariable::ModuleCache); let mut sources: Vec> = Vec::new(); @@ -200,34 +210,18 @@ var module = ({module_cache}[moduleId] = {{"#, let module_execution = if runtime_requirements .contains(RuntimeGlobals::INTERCEPT_MODULE_EXECUTION) { - if uses_runtime_context { - format!( - r#" - var execOptions = {{ id: moduleId, module: module, factory: {}[moduleId], require: {}, context: Object.create({}) }}; - {}.forEach(function(handler) {{ handler(execOptions); }}); - module = execOptions.module; - execOptions.factory.call(module.exports, module, module.exports, execOptions.context); - "#, - module_factories, - callable_require, - runtime_context, - runtime_template.render_runtime_globals(&RuntimeGlobals::INTERCEPT_MODULE_EXECUTION) - ) - .into() - } else { - format!( - r#" + format!( + r#" var execOptions = {{ id: moduleId, module: module, factory: {}[moduleId], require: {} }}; {}.forEach(function(handler) {{ handler(execOptions); }}); module = execOptions.module; execOptions.factory.call(module.exports, module, module.exports, execOptions.require); "#, - module_factories, - callable_require, - runtime_template.render_runtime_globals(&RuntimeGlobals::INTERCEPT_MODULE_EXECUTION) - ) - .into() - } + module_factories, + callable_require, + runtime_template.render_runtime_globals(&RuntimeGlobals::INTERCEPT_MODULE_EXECUTION) + ) + .into() } else if runtime_requirements.contains(RuntimeGlobals::THIS_AS_EXPORTS) { format!( "{module_factories}[moduleId].call(module.exports, module, module.exports, {require_argument});\n" @@ -266,6 +260,23 @@ var module = ({module_cache}[moduleId] = {{"#, chunk_ukey: &ChunkUkey, compilation: &'me Compilation, runtime_template: &ChunkCodeTemplate, + ) -> Result> { + if compilation + .options + .experiments + .runtime_mode + .uses_runtime_context() + { + return Self::render_rspack_bootstrap(chunk_ukey, compilation, runtime_template).await; + } + + Self::render_webpack_bootstrap(chunk_ukey, compilation, runtime_template).await + } + + pub async fn render_webpack_bootstrap<'me>( + chunk_ukey: &ChunkUkey, + compilation: &'me Compilation, + runtime_template: &ChunkCodeTemplate, ) -> Result> { let runtime_requirements = compilation .cgc_runtime_requirements_artifact @@ -282,23 +293,8 @@ var module = ({module_cache}[moduleId] = {{"#, let intercept_module_execution = runtime_requirements.contains(RuntimeGlobals::INTERCEPT_MODULE_EXECUTION); let module_used = runtime_requirements.contains(RuntimeGlobals::MODULE); - let uses_runtime_context = compilation - .options - .experiments - .runtime_mode - .uses_runtime_context(); - let has_custom_runtime_module = compilation - .build_chunk_graph_artifact - .chunk_graph - .get_chunk_runtime_modules_iterable(chunk_ukey) - .any(|runtime_module_identifier| { - let runtime_module = &compilation.runtime_modules[runtime_module_identifier]; - runtime_module.get_custom_source().is_some() - || runtime_module.get_constructor_name() == "RuntimeModuleFromJs" - }); let require_scope_used = runtime_requirements.contains(RuntimeGlobals::REQUIRE_SCOPE) - || !runtime_requirements.renderable_require_scope().is_empty() - || (uses_runtime_context && has_custom_runtime_module); + || !runtime_requirements.renderable_require_scope().is_empty(); let need_module_defer = runtime_requirements.contains(RuntimeGlobals::MAKE_DEFERRED_NAMESPACE_OBJECT); let use_require = require_function || intercept_module_execution || module_used; @@ -310,9 +306,6 @@ var module = ({module_cache}[moduleId] = {{"#, .output .environment .supports_arrow_function(); - let has_bootstrap_runtime_context = - uses_runtime_context && runtime_requirements.needs_bootstrap_runtime_context(); - if allow_inline_startup && module_factories { startup.push("// module factories are used so entry inlining is disabled".into()); allow_inline_startup = false; @@ -351,10 +344,6 @@ var __rspack_deferred_exports = {}; ); } - if has_bootstrap_runtime_context { - header.push(render_runtime_context_declaration(runtime_template).into()); - } - if use_require { header.push( format!( @@ -376,13 +365,6 @@ function {}(moduleId) {{ "# .into(), ); - if uses_runtime_context { - header.push(render_runtime_context_require_assignment(runtime_template).into()); - } - } else if require_scope_used && uses_runtime_context { - if !has_bootstrap_runtime_context { - header.push(render_runtime_context_declaration(runtime_template).into()); - } } else if require_scope_used { header.push( format!( @@ -397,15 +379,8 @@ var {} = {{}}; if module_factories || runtime_requirements.contains(RuntimeGlobals::MODULE_FACTORIES_ADD_ONLY) { - let module_factories = if uses_runtime_context { - let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); - let name = RuntimeGlobals::MODULE_FACTORIES - .property_name() - .expect("module factories should have context property name"); - format!("{runtime_context}{}", property_access([name], 0)) - } else { - runtime_template.render_runtime_globals(&RuntimeGlobals::MODULE_FACTORIES) - }; + let module_factories = + runtime_template.render_runtime_globals(&RuntimeGlobals::MODULE_FACTORIES); header.push( format!( r#"// expose the modules object ({modules}) @@ -419,15 +394,8 @@ var {} = {{}}; } if runtime_requirements.contains(RuntimeGlobals::MODULE_CACHE) { - let module_cache_runtime_global = if uses_runtime_context { - let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); - let name = RuntimeGlobals::MODULE_CACHE - .property_name() - .expect("module cache should have context property name"); - format!("{runtime_context}{}", property_access([name], 0)) - } else { - runtime_template.render_runtime_globals(&RuntimeGlobals::MODULE_CACHE) - }; + let module_cache_runtime_global = + runtime_template.render_runtime_globals(&RuntimeGlobals::MODULE_CACHE); header.push( format!( r#"// expose the module cache @@ -441,15 +409,8 @@ var {} = {{}}; } if intercept_module_execution { - let intercept_module_execution = if uses_runtime_context { - let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); - let name = RuntimeGlobals::INTERCEPT_MODULE_EXECUTION - .property_name() - .expect("intercept module execution should have context property name"); - format!("{runtime_context}{}", property_access([name], 0)) - } else { - runtime_template.render_runtime_globals(&RuntimeGlobals::INTERCEPT_MODULE_EXECUTION) - }; + let intercept_module_execution = + runtime_template.render_runtime_globals(&RuntimeGlobals::INTERCEPT_MODULE_EXECUTION); header.push( format!( r#"// expose the module execution interceptor @@ -752,6 +713,29 @@ var {} = {{}}; chunk_ukey: &ChunkUkey, output_path: &str, runtime_template: &ChunkCodeTemplate, + ) -> Result { + if compilation + .options + .experiments + .runtime_mode + .uses_runtime_context() + { + return self + .render_rspack_main(compilation, chunk_ukey, output_path, runtime_template) + .await; + } + + self + .render_webpack_main(compilation, chunk_ukey, output_path, runtime_template) + .await + } + + pub async fn render_webpack_main( + &self, + compilation: &Compilation, + chunk_ukey: &ChunkUkey, + output_path: &str, + runtime_template: &ChunkCodeTemplate, ) -> Result { let js_plugin_hooks = Self::get_compilation_hooks(compilation.id()); let hooks = js_plugin_hooks @@ -771,8 +755,6 @@ var {} = {{}}; .get(chunk_ukey) .copied() .unwrap_or_default(); - let has_bootstrap_runtime_context = runtime_template.uses_runtime_context() - && runtime_requirements.needs_bootstrap_runtime_context(); let mut chunk_init_fragments = ChunkInitFragments::default(); let iife = compilation.options.output.iife; let mut all_strict = compilation.options.output.module; @@ -866,18 +848,12 @@ var {} = {{}}; header.push('\n'); sources.add(RawStringSource::from(header)); } - let renders_runtime_context = should_render_runtime_context(compilation, chunk_ukey); - if renders_runtime_context - || compilation - .build_chunk_graph_artifact - .chunk_graph - .has_chunk_runtime_modules(chunk_ukey) + if compilation + .build_chunk_graph_artifact + .chunk_graph + .has_chunk_runtime_modules(chunk_ukey) { sources.add(render_runtime_modules(compilation, chunk_ukey, runtime_template).await?); - } else if runtime_template.uses_runtime_context() && !has_bootstrap_runtime_context { - sources.add(RawStringSource::from(render_runtime_context_declaration( - runtime_template, - ))); } if let Some(inlined_modules) = inlined_modules { let last_entry_module = inlined_modules diff --git a/crates/rspack_plugin_javascript/src/plugin/runtime_context.rs b/crates/rspack_plugin_javascript/src/plugin/runtime_context.rs new file mode 100644 index 000000000000..c79805d1cb19 --- /dev/null +++ b/crates/rspack_plugin_javascript/src/plugin/runtime_context.rs @@ -0,0 +1,913 @@ +use std::borrow::Cow; + +use rspack_core::{ + ChunkCodeTemplate, ChunkGraph, ChunkInitFragments, ChunkRenderContext, ChunkUkey, + CodeGenerationDataTopLevelDeclarations, Compilation, ExportsArgument, Module, RuntimeGlobals, + RuntimeVariable, SourceType, property_access, render_init_fragments, + rspack_sources::{BoxSource, ConcatSource, RawStringSource, SourceExt}, +}; +use rspack_error::Result; + +use super::{JsPlugin, RenderBootstrapResult}; +use crate::{ + RenderSource, + runtime::{ + render_chunk_modules, render_module, render_runtime_context_declaration, + render_runtime_context_require_assignment, render_runtime_modules, stringify_array, + }, +}; + +impl JsPlugin { + pub fn render_rspack_require<'me>( + chunk_ukey: &ChunkUkey, + compilation: &'me Compilation, + runtime_template: &ChunkCodeTemplate, + ) -> Vec> { + let runtime_requirements = compilation + .cgc_runtime_requirements_artifact + .get(chunk_ukey) + .copied() + .unwrap_or_default(); + + let strict_module_error_handling = compilation.options.output.strict_module_error_handling; + let need_module_defer = + runtime_requirements.contains(RuntimeGlobals::MAKE_DEFERRED_NAMESPACE_OBJECT); + let callable_require = runtime_template.render_runtime_variable(&RuntimeVariable::Require); + let require_argument = runtime_template.render_runtime_argument(); + let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); + let module_factories = runtime_template.render_runtime_variable(&RuntimeVariable::Modules); + let module_cache = runtime_template.render_runtime_variable(&RuntimeVariable::ModuleCache); + let mut sources: Vec> = Vec::new(); + + sources.push( + format!( + r#"// Check if module is in cache +var cachedModule = {module_cache}[moduleId]; +if (cachedModule !== undefined) {{"#, + ) + .into(), + ); + + if strict_module_error_handling { + sources.push("if (cachedModule.error !== undefined) throw cachedModule.error;".into()); + } + + sources.push( + format!( + r#"return cachedModule.exports; +}} +// Create a new module (and put it into the cache) +var module = ({module_cache}[moduleId] = {{"#, + ) + .into(), + ); + + if runtime_requirements.contains(RuntimeGlobals::MODULE_ID) { + sources.push("id: moduleId,".into()); + } + + if runtime_requirements.contains(RuntimeGlobals::MODULE_LOADED) { + sources.push("loaded: false,".into()); + } + + if need_module_defer { + sources.push("exports: __rspack_deferred_exports[moduleId] || {}".into()); + } else { + sources.push("exports: {}".into()); + } + sources.push("});\n// Execute the module function".into()); + + let module_execution = if runtime_requirements + .contains(RuntimeGlobals::INTERCEPT_MODULE_EXECUTION) + { + format!( + r#" + var execOptions = {{ id: moduleId, module: module, factory: {module_factories}[moduleId], require: {callable_require}, context: Object.create({runtime_context}) }}; + {}.forEach(function(handler) {{ handler(execOptions); }}); + module = execOptions.module; + execOptions.factory.call(module.exports, module, module.exports, execOptions.context); + "#, + runtime_template.render_runtime_globals(&RuntimeGlobals::INTERCEPT_MODULE_EXECUTION) + ) + .into() + } else if runtime_requirements.contains(RuntimeGlobals::THIS_AS_EXPORTS) { + format!( + "{module_factories}[moduleId].call(module.exports, module, module.exports, {require_argument});\n" + ) + .into() + } else { + format!("{module_factories}[moduleId](module, module.exports, {require_argument});\n").into() + }; + + if strict_module_error_handling { + sources.push("try {\n".into()); + sources.push(module_execution); + sources.push("} catch (e) {".into()); + if need_module_defer { + sources.push("delete __rspack_deferred_exports[moduleId];".into()); + } + sources.push("module.error = e;\nthrow e;".into()); + sources.push("}".into()); + } else { + sources.push(module_execution); + if need_module_defer { + sources.push("delete __rspack_deferred_exports[moduleId];".into()); + } + } + + if runtime_requirements.contains(RuntimeGlobals::MODULE_LOADED) { + sources.push("// Flag the module as loaded\nmodule.loaded = true;".into()); + } + + sources.push("// Return the exports of the module\nreturn module.exports;".into()); + + sources + } + + pub async fn render_rspack_bootstrap<'me>( + chunk_ukey: &ChunkUkey, + compilation: &'me Compilation, + runtime_template: &ChunkCodeTemplate, + ) -> Result> { + let runtime_requirements = compilation + .cgc_runtime_requirements_artifact + .get(chunk_ukey) + .copied() + .unwrap_or_default(); + let chunk = compilation + .build_chunk_graph_artifact + .chunk_by_ukey + .expect_get(chunk_ukey); + let module_factories = runtime_requirements.contains(RuntimeGlobals::MODULE_FACTORIES); + let require_function = runtime_requirements.contains(RuntimeGlobals::REQUIRE); + let module_cache = runtime_requirements.contains(RuntimeGlobals::MODULE_CACHE); + let intercept_module_execution = + runtime_requirements.contains(RuntimeGlobals::INTERCEPT_MODULE_EXECUTION); + let module_used = runtime_requirements.contains(RuntimeGlobals::MODULE); + let has_custom_runtime_module = compilation + .build_chunk_graph_artifact + .chunk_graph + .get_chunk_runtime_modules_iterable(chunk_ukey) + .any(|runtime_module_identifier| { + let runtime_module = &compilation.runtime_modules[runtime_module_identifier]; + runtime_module.get_custom_source().is_some() + || runtime_module.get_constructor_name() == "RuntimeModuleFromJs" + }); + let require_scope_used = runtime_requirements.contains(RuntimeGlobals::REQUIRE_SCOPE) + || !runtime_requirements.renderable_require_scope().is_empty() + || has_custom_runtime_module; + let need_module_defer = + runtime_requirements.contains(RuntimeGlobals::MAKE_DEFERRED_NAMESPACE_OBJECT); + let use_require = require_function || intercept_module_execution || module_used; + let mut header: Vec> = Vec::new(); + let mut startup: Vec> = Vec::new(); + let mut allow_inline_startup = true; + let supports_arrow_function = compilation + .options + .output + .environment + .supports_arrow_function(); + let has_bootstrap_runtime_context = runtime_requirements.needs_bootstrap_runtime_context(); + + if allow_inline_startup && module_factories { + startup.push("// module factories are used so entry inlining is disabled".into()); + allow_inline_startup = false; + } + if allow_inline_startup && module_cache { + startup.push("// module cache are used so entry inlining is disabled".into()); + allow_inline_startup = false; + } + if allow_inline_startup && intercept_module_execution { + startup.push("// module execution is intercepted so entry inlining is disabled".into()); + allow_inline_startup = false; + } + + if use_require || module_cache { + header.push( + format!( + r#"// The module cache +var {} = {{}}; +"#, + runtime_template.render_runtime_variable(&RuntimeVariable::ModuleCache) + ) + .into(), + ); + } + + if need_module_defer { + header.push( + r#"// The deferred module cache +var __rspack_deferred_exports = {}; +"# + .into(), + ); + } + + if has_bootstrap_runtime_context { + header.push(render_runtime_context_declaration(runtime_template).into()); + } + + if use_require { + header.push( + format!( + r#"// The require function +function {}(moduleId) {{ +"#, + runtime_template.render_runtime_variable(&RuntimeVariable::Require) + ) + .into(), + ); + header.extend(Self::render_rspack_require( + chunk_ukey, + compilation, + runtime_template, + )); + header.push( + r#" +} +"# + .into(), + ); + header.push(render_runtime_context_require_assignment(runtime_template).into()); + } else if require_scope_used && !has_bootstrap_runtime_context { + header.push(render_runtime_context_declaration(runtime_template).into()); + } + + if module_factories || runtime_requirements.contains(RuntimeGlobals::MODULE_FACTORIES_ADD_ONLY) + { + let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); + let name = RuntimeGlobals::MODULE_FACTORIES + .rspack_context_property_name() + .expect("module factories should have context property name"); + let module_factories = format!("{runtime_context}{}", property_access([name], 0)); + header.push( + format!( + r#"// expose the modules object ({modules}) +{module_factories} = {modules}; +"#, + modules = runtime_template.render_runtime_variable(&RuntimeVariable::Modules), + module_factories = module_factories + ) + .into(), + ); + } + + if runtime_requirements.contains(RuntimeGlobals::MODULE_CACHE) { + let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); + let name = RuntimeGlobals::MODULE_CACHE + .rspack_context_property_name() + .expect("module cache should have context property name"); + let module_cache_runtime_global = format!("{runtime_context}{}", property_access([name], 0)); + header.push( + format!( + r#"// expose the module cache +{} = {}; +"#, + module_cache_runtime_global, + runtime_template.render_runtime_variable(&RuntimeVariable::ModuleCache), + ) + .into(), + ); + } + + if intercept_module_execution { + let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); + let name = RuntimeGlobals::INTERCEPT_MODULE_EXECUTION + .rspack_context_property_name() + .expect("intercept module execution should have context property name"); + let intercept_module_execution = format!("{runtime_context}{}", property_access([name], 0)); + header.push( + format!( + r#"// expose the module execution interceptor +{intercept_module_execution} = []; +"#, + ) + .into(), + ); + } + + if !runtime_requirements.contains(RuntimeGlobals::STARTUP_NO_DEFAULT) { + if chunk.has_entry_module(&compilation.build_chunk_graph_artifact.chunk_graph) { + let mut buf2: Vec> = Vec::new(); + buf2.push("// Load entry module and return exports".into()); + let entries = compilation + .build_chunk_graph_artifact + .chunk_graph + .get_chunk_entry_modules_with_chunk_group_iterable(chunk_ukey); + let module_graph = compilation.get_module_graph(); + for (i, (module, entry)) in entries.iter().enumerate() { + let chunk_group = compilation + .build_chunk_graph_artifact + .chunk_group_by_ukey + .expect_get(entry); + let chunk_ids = chunk_group + .chunks + .iter() + .filter(|c| *c != chunk_ukey) + .map(|chunk_ukey| { + compilation + .build_chunk_graph_artifact + .chunk_by_ukey + .expect_get(chunk_ukey) + .expect_id() + .to_string() + }) + .collect::>(); + if allow_inline_startup && !chunk_ids.is_empty() { + buf2.push("// This entry module depends on other loaded chunks and execution need to be delayed".into()); + allow_inline_startup = false; + } + if allow_inline_startup && { + let module_graph_cache = &compilation.module_graph_cache_artifact; + module_graph + .get_incoming_connections_by_origin_module(module) + .modules() + .iter() + .any(|(origin_module, connections)| { + connections.iter().any(|c| { + c.is_target_active( + module_graph, + Some(chunk.runtime()), + module_graph_cache, + &compilation + .build_module_graph_artifact + .side_effects_state_artifact, + &compilation.exports_info_artifact, + ) + }) && compilation + .build_chunk_graph_artifact + .chunk_graph + .get_module_runtimes_iter( + *origin_module, + &compilation.build_chunk_graph_artifact.chunk_by_ukey, + ) + .any(|runtime| runtime.intersection(chunk.runtime()).count() > 0) + }) + } { + buf2.push( + "// This entry module is referenced by other modules so it can't be inlined".into(), + ); + allow_inline_startup = false; + } + if allow_inline_startup && { + let codegen = compilation + .code_generation_results + .get(module, Some(chunk.runtime())); + let module_graph = compilation.get_module_graph(); + let top_level_decls = codegen + .data + .get::() + .map(|d| d.inner()) + .or_else(|| { + module_graph + .module_by_identifier(module) + .and_then(|m| m.build_info().top_level_declarations.as_ref()) + }); + top_level_decls.is_none() + } { + buf2.push("// This entry module doesn't tell about it's top-level declarations so it can't be inlined".into()); + allow_inline_startup = false; + } + let hooks = JsPlugin::get_compilation_hooks(compilation.id()); + let bailout = hooks + .try_read() + .expect("should have js plugin drive") + .inline_in_runtime_bailout + .call(compilation) + .await?; + if allow_inline_startup && let Some(bailout) = bailout { + buf2.push(format!("// This entry module can't be inlined because {bailout}").into()); + allow_inline_startup = false; + } + let entry_runtime_requirements = + ChunkGraph::get_module_runtime_requirements(compilation, *module, chunk.runtime()); + if allow_inline_startup + && let Some(entry_runtime_requirements) = entry_runtime_requirements + && entry_runtime_requirements.contains(RuntimeGlobals::MODULE) + { + allow_inline_startup = false; + buf2.push("// This entry module used 'module' so it can't be inlined".into()); + } + + let module_id = ChunkGraph::get_module_id(&compilation.module_ids_artifact, *module) + .expect("should have module id"); + let mut module_id_expr = rspack_util::json_stringify(module_id); + if runtime_requirements.contains(RuntimeGlobals::ENTRY_MODULE_ID) { + module_id_expr = format!( + "{} = {module_id_expr}", + runtime_template.render_runtime_globals(&RuntimeGlobals::ENTRY_MODULE_ID) + ); + } + + if !chunk_ids.is_empty() { + let on_chunks_loaded_callback = if supports_arrow_function { + format!( + "() => {}({module_id_expr})", + runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE) + ) + } else { + format!( + "function() {{ return {}({module_id_expr}) }}", + runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE) + ) + }; + buf2.push( + format!( + "{}{}(undefined, {}, {});", + if i + 1 == entries.len() { + format!( + "var {} = ", + runtime_template.render_runtime_globals(&RuntimeGlobals::EXPORTS) + ) + } else { + String::new() + }, + runtime_template.render_runtime_globals(&RuntimeGlobals::ON_CHUNKS_LOADED), + stringify_array(&chunk_ids), + on_chunks_loaded_callback + ) + .into(), + ); + } else if use_require { + buf2.push( + format!( + "{}{}({module_id_expr});", + if i + 1 == entries.len() { + format!( + "var {} = ", + runtime_template.render_runtime_globals(&RuntimeGlobals::EXPORTS) + ) + } else { + String::new() + }, + runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE) + ) + .into(), + ) + } else { + let should_exec = i + 1 == entries.len(); + if should_exec { + buf2.push( + format!( + "var {} = {{}}", + runtime_template.render_runtime_globals(&RuntimeGlobals::EXPORTS) + ) + .into(), + ); + } + if require_scope_used { + buf2.push( + format!( + "{}[{module_id_expr}](0, {}, {});", + runtime_template.render_runtime_variable(&RuntimeVariable::Modules), + if should_exec { + runtime_template.render_runtime_globals(&RuntimeGlobals::EXPORTS) + } else { + "{}".to_string() + }, + runtime_template.render_runtime_argument() + ) + .into(), + ); + } else if let Some(entry_runtime_requirements) = entry_runtime_requirements + && entry_runtime_requirements.contains(RuntimeGlobals::EXPORTS) + { + buf2.push( + format!( + "{}[{module_id_expr}](0, {});", + runtime_template.render_runtime_variable(&RuntimeVariable::Modules), + if should_exec { + runtime_template.render_runtime_globals(&RuntimeGlobals::EXPORTS) + } else { + "{}".to_string() + } + ) + .into(), + ); + } else { + buf2.push( + format!( + "{}[{module_id_expr}]();", + runtime_template.render_runtime_variable(&RuntimeVariable::Modules) + ) + .into(), + ); + } + } + } + if runtime_requirements.contains(RuntimeGlobals::ON_CHUNKS_LOADED) { + buf2.push( + format!( + "{exports} = {on_chunks_loaded}({exports});", + exports = runtime_template.render_runtime_variable(&RuntimeVariable::Exports), + on_chunks_loaded = + runtime_template.render_runtime_globals(&RuntimeGlobals::ON_CHUNKS_LOADED) + ) + .into(), + ); + } + if runtime_requirements.contains(RuntimeGlobals::STARTUP) { + let exports = runtime_template.render_runtime_globals(&RuntimeGlobals::EXPORTS); + allow_inline_startup = false; + header.push( + format!( + r#"// the startup function +{} = {}; +"#, + runtime_template.render_runtime_globals(&RuntimeGlobals::STARTUP), + runtime_template + .basic_function("", &format!("{}\nreturn {}", buf2.join("\n"), exports)) + ) + .into(), + ); + startup.push("// run startup".into()); + startup.push( + format!( + "var {} = {}();", + runtime_template.render_runtime_globals(&RuntimeGlobals::EXPORTS), + runtime_template.render_runtime_globals(&RuntimeGlobals::STARTUP) + ) + .into(), + ); + } else { + startup.push("// startup".into()); + startup.push(buf2.join("\n").into()); + } + } else if runtime_requirements.contains(RuntimeGlobals::STARTUP) { + header.push( + format!( + r#"// the startup function +// It's empty as no entry modules are in this chunk +{} = function(){{}};"#, + runtime_template.render_runtime_globals(&RuntimeGlobals::STARTUP) + ) + .into(), + ); + } + } else if runtime_requirements.contains(RuntimeGlobals::STARTUP) { + header.push( + format!( + r#"// the startup function +// It's empty as some runtime module handles the default behavior +{} = function(){{}};"#, + runtime_template.render_runtime_globals(&RuntimeGlobals::STARTUP) + ) + .into(), + ); + startup.push("// run startup".into()); + startup.push( + format!( + "var {} = {}();", + runtime_template.render_runtime_variable(&RuntimeVariable::Exports), + runtime_template.render_runtime_globals(&RuntimeGlobals::STARTUP) + ) + .into(), + ); + } + + Ok(RenderBootstrapResult { + header, + startup, + allow_inline_startup, + }) + } +} + +impl JsPlugin { + pub async fn render_rspack_main( + &self, + compilation: &Compilation, + chunk_ukey: &ChunkUkey, + output_path: &str, + runtime_template: &ChunkCodeTemplate, + ) -> Result { + let js_plugin_hooks = Self::get_compilation_hooks(compilation.id()); + let hooks = js_plugin_hooks + .try_read() + .expect("should have js plugin drive"); + let chunk = compilation + .build_chunk_graph_artifact + .chunk_by_ukey + .expect_get(chunk_ukey); + let supports_arrow_function = compilation + .options + .output + .environment + .supports_arrow_function(); + let runtime_requirements = compilation + .cgc_runtime_requirements_artifact + .get(chunk_ukey) + .copied() + .unwrap_or_default(); + let has_bootstrap_runtime_context = runtime_requirements.needs_bootstrap_runtime_context(); + let mut chunk_init_fragments = ChunkInitFragments::default(); + let iife = compilation.options.output.iife; + let mut all_strict = compilation.options.output.module; + let RenderBootstrapResult { + header, + startup, + allow_inline_startup, + } = Self::render_rspack_bootstrap(chunk_ukey, compilation, runtime_template).await?; + let module_graph = &compilation.get_module_graph(); + let all_modules = compilation + .build_chunk_graph_artifact + .chunk_graph + .get_chunk_modules_by_source_type(chunk_ukey, SourceType::JavaScript, module_graph); + let has_entry_modules = + chunk.has_entry_module(&compilation.build_chunk_graph_artifact.chunk_graph); + let inlined_modules = if allow_inline_startup && has_entry_modules { + Some( + compilation + .build_chunk_graph_artifact + .chunk_graph + .get_chunk_entry_modules_with_chunk_group_iterable(chunk_ukey), + ) + } else { + None + }; + let mut sources = ConcatSource::default(); + if iife { + sources.add(RawStringSource::from(if supports_arrow_function { + "(() => {\n" + } else { + "(function() {\n" + })); + } + if !all_strict && all_modules.iter().all(|m| m.build_info().strict) { + if let Some(strict_bailout) = hooks + .strict_runtime_bailout + .call(compilation, chunk_ukey) + .await? + { + sources.add(RawStringSource::from(format!( + "// runtime can't be in strict mode because {strict_bailout}.\n" + ))); + } else { + all_strict = true; + sources.add(RawStringSource::from_static("\"use strict\";\n")); + } + } + + let chunk_modules: Vec<&dyn Module> = if let Some(inlined_modules) = inlined_modules { + all_modules + .clone() + .into_iter() + .filter(|m| !inlined_modules.contains_key(&m.identifier())) + .collect::>() + } else { + all_modules.clone() + }; + + let chunk_modules_result = render_chunk_modules( + compilation, + chunk_ukey, + &chunk_modules, + all_strict, + output_path, + &hooks, + runtime_template, + ) + .await?; + let has_chunk_modules_result = chunk_modules_result.is_some(); + if has_chunk_modules_result + || runtime_requirements.contains(RuntimeGlobals::MODULE_FACTORIES) + || runtime_requirements.contains(RuntimeGlobals::MODULE_FACTORIES_ADD_ONLY) + || runtime_requirements.contains(RuntimeGlobals::REQUIRE) + { + let chunk_modules_source = + if let Some((chunk_modules_source, fragments)) = chunk_modules_result { + chunk_init_fragments.extend(fragments); + chunk_modules_source + } else { + RawStringSource::from_static("{}").boxed() + }; + sources.add(RawStringSource::from(format!( + "var {} = (", + runtime_template.render_runtime_variable(&RuntimeVariable::Modules) + ))); + sources.add(chunk_modules_source); + sources.add(RawStringSource::from_static(");\n")); + } + if !header.is_empty() { + let mut header = header.join("\n"); + header.push('\n'); + sources.add(RawStringSource::from(header)); + } + if compilation + .build_chunk_graph_artifact + .chunk_graph + .has_chunk_runtime_modules(chunk_ukey) + { + sources.add(render_runtime_modules(compilation, chunk_ukey, runtime_template).await?); + } else if runtime_template.uses_runtime_context() && !has_bootstrap_runtime_context { + sources.add(RawStringSource::from(render_runtime_context_declaration( + runtime_template, + ))); + } + if let Some(inlined_modules) = inlined_modules { + let last_entry_module = inlined_modules + .keys() + .next_back() + .expect("should have last entry module"); + let mut startup_sources = ConcatSource::default(); + + if runtime_requirements.contains(RuntimeGlobals::EXPORTS) { + startup_sources.add(RawStringSource::from(format!( + "var {} = {{}};\n", + runtime_template.render_runtime_globals(&RuntimeGlobals::EXPORTS) + ))); + } + + let renamed_inline_modules = if compilation.options.optimization.avoid_entry_iife { + self + .get_renamed_inline_module( + &all_modules, + inlined_modules, + compilation, + chunk_ukey, + all_strict, + has_chunk_modules_result, + output_path, + &hooks, + runtime_template, + ) + .await? + } else { + None + }; + + for (m_identifier, _) in inlined_modules { + let m = module_graph + .module_by_identifier(m_identifier) + .expect("should have module"); + let Some((mut rendered_module, fragments, additional_fragments)) = render_module( + compilation, + chunk_ukey, + m.as_ref(), + all_strict, + false, + output_path, + &hooks, + runtime_template, + ) + .await? + else { + continue; + }; + + if let Some(renamed_inline_modules) = &renamed_inline_modules + && renamed_inline_modules.contains_key(m_identifier) + && let Some(source) = renamed_inline_modules.get(m_identifier) + { + rendered_module = source.clone(); + }; + + chunk_init_fragments.extend(fragments); + chunk_init_fragments.extend(additional_fragments); + let inner_strict = !all_strict && m.build_info().strict; + let module_runtime_requirements = + ChunkGraph::get_module_runtime_requirements(compilation, *m_identifier, chunk.runtime()); + let exports = module_runtime_requirements + .map(|r| r.contains(RuntimeGlobals::EXPORTS)) + .unwrap_or_default(); + let exports_argument = m.get_exports_argument(); + let rspack_exports_argument = matches!(exports_argument, ExportsArgument::RspackExports); + let rspack_exports = exports && rspack_exports_argument; + let iife: Option> = if inner_strict { + Some("it needs to be in strict mode.".into()) + } else if inlined_modules.len() > 1 { + Some("it needs to be isolated against other entry modules.".into()) + } else if has_chunk_modules_result && renamed_inline_modules.is_none() { + Some("it needs to be isolated against other modules in the chunk.".into()) + } else if exports && !rspack_exports { + Some( + format!( + "it uses a non-standard name for the exports ({}).", + runtime_template.render_exports_argument(exports_argument) + ) + .into(), + ) + } else { + hooks + .embed_in_runtime_bailout + .call(compilation, m, chunk) + .await? + .map(|s| s.into()) + }; + let footer; + if let Some(iife) = iife { + startup_sources.add(RawStringSource::from(format!( + "// This entry needs to be wrapped in an IIFE because {iife}\n" + ))); + if supports_arrow_function { + startup_sources.add(RawStringSource::from_static("(() => {\n")); + footer = "\n})();\n\n"; + } else { + startup_sources.add(RawStringSource::from_static("!function() {\n")); + footer = "\n}();\n"; + } + if inner_strict { + startup_sources.add(RawStringSource::from_static("\"use strict\";\n")); + } + } else { + footer = "\n"; + } + if exports { + let exports_argument = runtime_template.render_exports_argument(exports_argument); + if m_identifier != last_entry_module { + startup_sources.add(RawStringSource::from(format!( + "var {exports_argument} = {{}};\n" + ))); + } else if !rspack_exports_argument { + startup_sources.add(RawStringSource::from(format!( + "var {exports_argument} = {};\n", + runtime_template.render_runtime_globals(&RuntimeGlobals::EXPORTS) + ))); + } + } + startup_sources.add(rendered_module); + startup_sources.add(RawStringSource::from(footer)); + } + if runtime_requirements.contains(RuntimeGlobals::ON_CHUNKS_LOADED) { + startup_sources.add(RawStringSource::from(format!( + "{} = {}({});\n", + runtime_template.render_runtime_globals(&RuntimeGlobals::EXPORTS), + runtime_template.render_runtime_globals(&RuntimeGlobals::ON_CHUNKS_LOADED), + runtime_template.render_runtime_globals(&RuntimeGlobals::EXPORTS), + ))); + } + let mut render_source = RenderSource { + source: startup_sources.boxed(), + }; + hooks + .render_startup + .call( + compilation, + chunk_ukey, + last_entry_module, + &mut render_source, + runtime_template, + ) + .await?; + sources.add(render_source.source); + } else if let Some(last_entry_module) = compilation + .build_chunk_graph_artifact + .chunk_graph + .get_chunk_entry_modules_with_chunk_group_iterable(chunk_ukey) + .keys() + .next_back() + { + let mut render_source = RenderSource { + source: RawStringSource::from(startup.join("\n") + "\n").boxed(), + }; + hooks + .render_startup + .call( + compilation, + chunk_ukey, + last_entry_module, + &mut render_source, + runtime_template, + ) + .await?; + sources.add(render_source.source); + } + if has_entry_modules + && runtime_requirements.contains(RuntimeGlobals::RETURN_EXPORTS_FROM_RUNTIME) + { + sources.add(RawStringSource::from(format!( + "return {};\n", + runtime_template.render_runtime_variable(&RuntimeVariable::Exports) + ))); + } + if iife { + sources.add(RawStringSource::from_static("})()\n")); + } + let final_source = render_init_fragments( + sources.boxed(), + chunk_init_fragments, + &mut ChunkRenderContext {}, + )?; + let mut render_source = RenderSource { + source: final_source, + }; + hooks + .render + .call( + compilation, + chunk_ukey, + &mut render_source, + runtime_template, + ) + .await?; + Ok(if iife { + ConcatSource::new([ + render_source.source, + RawStringSource::from_static(";").boxed(), + ]) + .boxed() + } else { + render_source.source + }) + } +} diff --git a/crates/rspack_plugin_javascript/src/runtime.rs b/crates/rspack_plugin_javascript/src/runtime.rs index 491c9478941d..e2c749b0cb5b 100644 --- a/crates/rspack_plugin_javascript/src/runtime.rs +++ b/crates/rspack_plugin_javascript/src/runtime.rs @@ -1,10 +1,10 @@ use rayon::prelude::*; use rspack_core::{ - ChunkCodeTemplate, ChunkGraph, ChunkInitFragments, ChunkKind, ChunkUkey, - CodeGenerationPublicPathAutoReplace, Compilation, Module, RuntimeGlobals, RuntimeModule, - RuntimeModuleGenerateContext, RuntimeProxyMetadata, RuntimeVariable, SourceType, + ChunkCodeTemplate, ChunkGraph, ChunkInitFragments, ChunkUkey, + CodeGenerationPublicPathAutoReplace, Compilation, Module, RuntimeGlobals, + RuntimeModuleGenerateContext, RuntimeModuleStage, SourceType, chunk_graph_chunk::ChunkIdSet, - get_undo_path, property_access, render_runtime_module_source, + get_undo_path, render_runtime_module_source, rspack_sources::{ BoxSource, ConcatSource, OriginalSource, RawStringSource, ReplaceSource, Source, SourceExt, }, @@ -12,6 +12,10 @@ use rspack_core::{ }; use rspack_error::{Result, ToStringResultToRspackResultExt}; +pub use crate::runtime_context::{ + render_rspack_runtime_modules, render_runtime_context_declaration, + render_runtime_context_require_assignment, +}; use crate::{JavascriptModulesPluginHooks, RenderSource}; pub const AUTO_PUBLIC_PATH_PLACEHOLDER: &str = "__RSPACK_PLUGIN_ASSET_AUTO_PUBLIC_PATH__"; @@ -314,514 +318,6 @@ pub async fn render_module( ))) } -fn runtime_context_metadata<'a>( - compilation: &'a Compilation, - chunk_ukey: &ChunkUkey, -) -> Option<&'a RuntimeProxyMetadata> { - if compilation.options.experiments.runtime_mode != RuntimeMode::Rspack { - return None; - } - - if let Some(metadata) = compilation.runtime_proxy_metadata_artifact.get(chunk_ukey) { - return Some(metadata); - } - - let chunk = compilation - .build_chunk_graph_artifact - .chunk_by_ukey - .expect_get(chunk_ukey); - compilation - .runtime_proxy_metadata_artifact - .iter() - .find_map(|(runtime_chunk_ukey, metadata)| { - let runtime_chunk = compilation - .build_chunk_graph_artifact - .chunk_by_ukey - .expect_get(runtime_chunk_ukey); - runtime_chunk - .runtime() - .iter() - .any(|runtime| chunk.runtime().contains(runtime)) - .then_some(metadata) - }) -} - -fn runtime_context_render_metadata( - compilation: &Compilation, - chunk_ukey: &ChunkUkey, -) -> Option { - runtime_context_metadata(compilation, chunk_ukey).cloned() -} - -fn runtime_context_current_chunk_metadata( - compilation: &Compilation, - chunk_ukey: &ChunkUkey, -) -> Option { - if compilation.options.experiments.runtime_mode != RuntimeMode::Rspack { - return None; - } - - if let Some(metadata) = compilation.runtime_proxy_metadata_artifact.get(chunk_ukey) { - return Some(metadata.clone()); - } - - let mut metadata = RuntimeProxyMetadata::default(); - for runtime_module_id in compilation - .build_chunk_graph_artifact - .chunk_graph - .get_chunk_runtime_modules_iterable(chunk_ukey) - { - let runtime_module = compilation - .runtime_modules - .get(runtime_module_id) - .expect("should have runtime module"); - let additional_runtime_requirements = - runtime_module.additional_runtime_requirements(compilation); - let generated_runtime_requirements = runtime_module_generated_requirements(&**runtime_module); - metadata - .tree_runtime_requirements - .insert(additional_runtime_requirements); - metadata - .tree_runtime_requirements - .insert(generated_runtime_requirements); - metadata - .runtime_module_requirements - .insert(additional_runtime_requirements); - } - - (!metadata.tree_runtime_requirements.is_empty()).then_some(metadata) -} - -pub fn should_render_runtime_context(compilation: &Compilation, chunk_ukey: &ChunkUkey) -> bool { - if compilation.options.experiments.runtime_mode != RuntimeMode::Rspack { - return false; - } - - runtime_context_render_metadata(compilation, chunk_ukey).is_some_and(|metadata| { - metadata - .tree_runtime_requirements - .contains(RuntimeGlobals::REQUIRE_SCOPE) - }) -} - -fn is_hot_update_chunk(compilation: &Compilation, chunk_ukey: &ChunkUkey) -> bool { - let chunk = compilation - .build_chunk_graph_artifact - .chunk_by_ukey - .expect_get(chunk_ukey); - matches!(chunk.kind(), ChunkKind::HotUpdate) -} - -pub fn render_runtime_context_declaration(runtime_template: &ChunkCodeTemplate) -> String { - let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); - format!("var {runtime_context}={{}};\n") -} - -pub fn render_runtime_context_require_assignment(runtime_template: &ChunkCodeTemplate) -> String { - format!( - "{} = {};\n", - runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE), - runtime_template.render_runtime_variable(&RuntimeVariable::Require) - ) -} - -fn runtime_module_generated_requirements(runtime_module: &dyn RuntimeModule) -> RuntimeGlobals { - let constructor_name = runtime_module.get_constructor_name(); - let module_name = runtime_module.identifier().to_string(); - match constructor_name.as_str() { - "AsyncRuntimeModule" => { - RuntimeGlobals::ASYNC_MODULE - | RuntimeGlobals::ASYNC_MODULE_EXPORT_SYMBOL - | RuntimeGlobals::DEFERRED_MODULES_ASYNC_TRANSITIVE_DEPENDENCIES - | RuntimeGlobals::DEFERRED_MODULES_ASYNC_TRANSITIVE_DEPENDENCIES_SYMBOL - } - "AsyncWasmLoadingRuntimeModule" => RuntimeGlobals::INSTANTIATE_WASM, - "AsyncWasmCompileRuntimeModule" => RuntimeGlobals::COMPILE_WASM, - "BaseUriRuntimeModule" => RuntimeGlobals::BASE_URI, - "PublicPathRuntimeModule" | "AutoPublicPathRuntimeModule" => RuntimeGlobals::PUBLIC_PATH, - "GetChunkFilenameRuntimeModule" if module_name.contains("javascript") => { - RuntimeGlobals::GET_CHUNK_SCRIPT_FILENAME - } - "GetChunkFilenameRuntimeModule" if module_name.contains("css") => { - RuntimeGlobals::GET_CHUNK_CSS_FILENAME - } - "GetChunkUpdateFilenameRuntimeModule" => RuntimeGlobals::GET_CHUNK_UPDATE_SCRIPT_FILENAME, - "GetMainFilenameRuntimeModule" => RuntimeGlobals::GET_UPDATE_MANIFEST_FILENAME, - "LoadScriptRuntimeModule" => RuntimeGlobals::LOAD_SCRIPT, - "HasOwnPropertyRuntimeModule" => RuntimeGlobals::HAS_OWN_PROPERTY, - "GetFullHashRuntimeModule" => RuntimeGlobals::GET_FULL_HASH, - "GlobalRuntimeModule" => RuntimeGlobals::GLOBAL, - "CreateScriptUrlRuntimeModule" => RuntimeGlobals::CREATE_SCRIPT_URL, - "CreateScriptRuntimeModule" => RuntimeGlobals::CREATE_SCRIPT, - "OnChunkLoadedRuntimeModule" => RuntimeGlobals::ON_CHUNKS_LOADED, - "DefinePropertyGettersRuntimeModule" => RuntimeGlobals::DEFINE_PROPERTY_GETTERS, - "GetTrustedTypesPolicyRuntimeModule" => RuntimeGlobals::GET_TRUSTED_TYPES_POLICY, - "CreateFakeNamespaceObjectRuntimeModule" => RuntimeGlobals::CREATE_FAKE_NAMESPACE_OBJECT, - "MakeNamespaceObjectRuntimeModule" => RuntimeGlobals::MAKE_NAMESPACE_OBJECT, - "CompatGetDefaultExportRuntimeModule" => RuntimeGlobals::COMPAT_GET_DEFAULT_EXPORT, - "ESMModuleDecoratorRuntimeModule" => RuntimeGlobals::ESM_MODULE_DECORATOR, - "NodeModuleDecoratorRuntimeModule" => RuntimeGlobals::NODE_MODULE_DECORATOR, - "SystemContextRuntimeModule" => RuntimeGlobals::SYSTEM_CONTEXT, - "NonceRuntimeModule" => RuntimeGlobals::SCRIPT_NONCE, - "RelativeUrlRuntimeModule" => RuntimeGlobals::RELATIVE_URL, - "ChunkNameRuntimeModule" => RuntimeGlobals::CHUNK_NAME, - "RuntimeIdRuntimeModule" => RuntimeGlobals::RUNTIME_ID, - "ShareRuntimeModule" => RuntimeGlobals::INITIALIZE_SHARING | RuntimeGlobals::SHARE_SCOPE_MAP, - "RemoteRuntimeModule" => RuntimeGlobals::CURRENT_REMOTE_GET_SCOPE, - "HotModuleReplacementRuntimeModule" => RuntimeGlobals::INTERCEPT_MODULE_EXECUTION, - "EmbedFederationRuntimeModule" => RuntimeGlobals::STARTUP, - "StartupEntrypointRuntimeModule" => RuntimeGlobals::STARTUP_ENTRYPOINT, - "StartupChunkDependenciesRuntimeModule" => RuntimeGlobals::STARTUP, - "EnsureChunkRuntimeModule" | "EsmEnsureChunkRuntimeModule" => { - RuntimeGlobals::ENSURE_CHUNK | RuntimeGlobals::ENSURE_CHUNK_HANDLERS - } - "JsonpChunkLoadingRuntimeModule" - | "ModuleChunkLoadingRuntimeModule" - | "ImportScriptsChunkLoadingRuntimeModule" - | "ReadFileChunkLoadingRuntimeModule" - | "RequireChunkLoadingRuntimeModule" => { - RuntimeGlobals::BASE_URI - | RuntimeGlobals::ENSURE_CHUNK_HANDLERS - | RuntimeGlobals::EXTERNAL_INSTALL_CHUNK - | RuntimeGlobals::HMR_DOWNLOAD_MANIFEST - | RuntimeGlobals::HMR_DOWNLOAD_UPDATE_HANDLERS - | RuntimeGlobals::HMR_INVALIDATE_MODULE_HANDLERS - | RuntimeGlobals::HMR_MODULE_DATA - } - "EsmChunkLoadingRuntimeModule" => RuntimeGlobals::EXTERNAL_INSTALL_CHUNK, - "ChunkPrefetchPreloadFunctionRuntimeModule" if module_name.contains("prefetch") => { - RuntimeGlobals::PREFETCH_CHUNK | RuntimeGlobals::PREFETCH_CHUNK_HANDLERS - } - "ChunkPrefetchPreloadFunctionRuntimeModule" if module_name.contains("preload") => { - RuntimeGlobals::PRELOAD_CHUNK | RuntimeGlobals::PRELOAD_CHUNK_HANDLERS - } - "AmdDefineRuntimeModule" => RuntimeGlobals::AMD_DEFINE, - "AmdOptionsRuntimeModule" => RuntimeGlobals::AMD_OPTIONS, - "MakeDeferredNamespaceObjectRuntimeModule" => RuntimeGlobals::MAKE_DEFERRED_NAMESPACE_OBJECT, - "MakeOptimizedDeferredNamespaceObjectRuntimeModule" => { - RuntimeGlobals::MAKE_OPTIMIZED_DEFERRED_NAMESPACE_OBJECT - } - "RscManifestRuntimeModule" => RuntimeGlobals::RSC_MANIFEST, - "RspackVersionRuntimeModule" => RuntimeGlobals::RSPACK_VERSION, - "RspackUniqueIdRuntimeModule" => RuntimeGlobals::RSPACK_UNIQUE_ID, - "ToBinaryRuntimeModule" => RuntimeGlobals::TO_BINARY, - _ => RuntimeGlobals::default(), - } -} - -fn has_bootstrap_runtime_context( - compilation: &Compilation, - chunk_ukey: &ChunkUkey, - runtime_template: &ChunkCodeTemplate, -) -> bool { - if !runtime_template.uses_runtime_context() { - return false; - } - - let chunk = compilation - .build_chunk_graph_artifact - .chunk_by_ukey - .expect_get(chunk_ukey); - if !chunk.has_runtime(&compilation.build_chunk_graph_artifact.chunk_group_by_ukey) { - return false; - } - - let runtime_requirements = compilation - .cgc_runtime_requirements_artifact - .get(chunk_ukey) - .copied() - .unwrap_or_default(); - runtime_requirements.needs_bootstrap_runtime_context() -} - -fn render_runtime_context_declarations( - compilation: &Compilation, - chunk_ukey: &ChunkUkey, - runtime_template: &ChunkCodeTemplate, - render_lexical_fields: bool, - render_context_object: bool, -) -> Option { - if !should_render_runtime_context(compilation, chunk_ukey) { - return None; - } - - let mut sources = ConcatSource::default(); - if render_context_object { - sources.add(RawStringSource::from(render_runtime_context_declaration( - runtime_template, - ))); - } - - if render_lexical_fields - && let Some(mut metadata) = runtime_context_current_chunk_metadata(compilation, chunk_ukey) - { - let chunk = compilation - .build_chunk_graph_artifact - .chunk_by_ukey - .expect_get(chunk_ukey); - let owns_runtime = - chunk.has_runtime(&compilation.build_chunk_graph_artifact.chunk_group_by_ukey); - let current_chunk_generated_requirements = compilation - .build_chunk_graph_artifact - .chunk_graph - .get_chunk_runtime_modules_iterable(chunk_ukey) - .fold( - RuntimeGlobals::default(), - |mut requirements, runtime_module_id| { - let runtime_module = compilation - .runtime_modules - .get(runtime_module_id) - .expect("should have runtime module"); - requirements.insert(runtime_module_generated_requirements(&**runtime_module)); - requirements - }, - ); - let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); - let is_hot_update = is_hot_update_chunk(compilation, chunk_ukey); - if is_hot_update { - metadata.tree_runtime_requirements.insert( - RuntimeGlobals::PUBLIC_PATH - | RuntimeGlobals::GET_CHUNK_SCRIPT_FILENAME - | RuntimeGlobals::GET_CHUNK_UPDATE_SCRIPT_FILENAME - | RuntimeGlobals::GET_UPDATE_MANIFEST_FILENAME - | RuntimeGlobals::GET_FULL_HASH - | RuntimeGlobals::LOAD_SCRIPT - | RuntimeGlobals::HAS_OWN_PROPERTY - | RuntimeGlobals::MODULE_CACHE - | RuntimeGlobals::CREATE_SCRIPT_URL, - ); - } - let render_runtime_global = |runtime_global: RuntimeGlobals| { - let render_context_field = |runtime_global: RuntimeGlobals| { - runtime_global - .rspack_context_property_name() - .map(|property_name| { - let value = format!("{runtime_context}{}", property_access([property_name], 0)); - if runtime_global.should_initialize_as_object() { - format!("{value}||{{}}") - } else if runtime_global.should_initialize_as_array() { - format!("{value}||[]") - } else { - value - } - }) - }; - if is_hot_update - && runtime_global.intersects( - RuntimeGlobals::HMR_DOWNLOAD_MANIFEST - | RuntimeGlobals::HMR_DOWNLOAD_UPDATE_HANDLERS - | RuntimeGlobals::HMR_INVALIDATE_MODULE_HANDLERS - | RuntimeGlobals::HMR_MODULE_DATA, - ) - { - return None; - } - if is_hot_update { - return render_context_field(runtime_global); - } - let should_render_context_field = owns_runtime - && runtime_global.intersects(RuntimeGlobals::STARTUP | RuntimeGlobals::STARTUP_ENTRYPOINT) - && metadata - .bootstrap_proxy_requirements - .contains(runtime_global) - || !owns_runtime - && (runtime_global.needs_bootstrap_runtime_context() - || metadata - .runtime_module_requirements - .contains(runtime_global) - && !current_chunk_generated_requirements.contains(runtime_global)); - if runtime_global == RuntimeGlobals::REQUIRE { - Some(runtime_template.render_runtime_variable(&RuntimeVariable::Require)) - } else if runtime_global == RuntimeGlobals::MODULE_FACTORIES - || runtime_global == RuntimeGlobals::MODULE_FACTORIES_ADD_ONLY - { - Some(runtime_template.render_runtime_variable(&RuntimeVariable::Modules)) - } else if runtime_global == RuntimeGlobals::MODULE_CACHE { - Some(runtime_template.render_runtime_variable(&RuntimeVariable::ModuleCache)) - } else if should_render_context_field { - render_context_field(runtime_global) - } else { - None - } - }; - sources.add(RawStringSource::from( - metadata.render_lexical_declarations(Some(&render_runtime_global)), - )); - if metadata.lexical_fields().intersects( - RuntimeGlobals::HMR_DOWNLOAD_UPDATE_HANDLERS - | RuntimeGlobals::HMR_INVALIDATE_MODULE_HANDLERS - | RuntimeGlobals::HMR_MODULE_DATA - | RuntimeGlobals::HMR_RUNTIME_STATE_PREFIX, - ) { - for runtime_module_id in compilation - .build_chunk_graph_artifact - .chunk_graph - .get_chunk_runtime_modules_iterable(chunk_ukey) - { - let runtime_module = compilation - .runtime_modules - .get(runtime_module_id) - .expect("should have runtime module"); - let key = match runtime_module.get_constructor_name().as_str() { - "JsonpChunkLoadingRuntimeModule" => "jsonp", - "ModuleChunkLoadingRuntimeModule" => "module", - "ImportScriptsChunkLoadingRuntimeModule" => "importScripts", - "ReadFileChunkLoadingRuntimeModule" => "readFileVm", - "RequireChunkLoadingRuntimeModule" => "require", - _ => continue, - }; - sources.add(RawStringSource::from(format!("var hmrS_{key};\n"))); - } - } - } - if !render_context_object { - return Some(sources.boxed()); - } - - Some(sources.boxed()) -} - -fn render_runtime_context_exposed_fields( - compilation: &Compilation, - chunk_ukey: &ChunkUkey, - runtime_template: &ChunkCodeTemplate, - generated_requirements: RuntimeGlobals, -) -> Option { - if !runtime_template.uses_lexical_runtime_globals() { - return None; - } - - let metadata = runtime_context_metadata(compilation, chunk_ukey)?; - let is_hot_update = is_hot_update_chunk(compilation, chunk_ukey); - let mut context_fields = metadata - .context_fields() - .intersection(generated_requirements); - context_fields.insert(generated_requirements.intersection(metadata.tree_runtime_requirements)); - let hmr_live_binding_fields = RuntimeGlobals::GET_FULL_HASH - | RuntimeGlobals::GET_CHUNK_SCRIPT_FILENAME - | RuntimeGlobals::GET_CHUNK_UPDATE_SCRIPT_FILENAME - | RuntimeGlobals::GET_UPDATE_MANIFEST_FILENAME - | RuntimeGlobals::PUBLIC_PATH; - if !is_hot_update - && metadata - .tree_runtime_requirements - .contains(RuntimeGlobals::HMR_DOWNLOAD_MANIFEST) - { - context_fields.insert(generated_requirements.intersection(hmr_live_binding_fields)); - } - if is_hot_update { - context_fields.insert(generated_requirements); - context_fields.remove(RuntimeGlobals::REQUIRE | RuntimeGlobals::REQUIRE_SCOPE); - } - if context_fields.is_empty() { - return None; - } - - let mut sources = ConcatSource::default(); - let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); - - for (_, runtime_global) in context_fields.iter_names() { - let (Some(key), Some(lexical_name)) = ( - runtime_global.rspack_context_property_name(), - runtime_global.to_lexical_name(), - ) else { - continue; - }; - let needs_live_binding = !is_hot_update - && (metadata.context_setter_fields().contains(runtime_global) - || hmr_live_binding_fields.contains(runtime_global) - && metadata - .tree_runtime_requirements - .contains(RuntimeGlobals::HMR_DOWNLOAD_MANIFEST)); - if needs_live_binding { - sources.add(RawStringSource::from(format!( - "Object.defineProperty({}, {}, {{ configurable: true, get: function() {{ return {}; }}, set: function(value) {{ {} = value; }} }});\n", - runtime_context, - rspack_util::json_stringify(key), - lexical_name, - lexical_name - ))); - } else { - sources.add(RawStringSource::from(format!( - "{}{} = {};\n", - runtime_context, - property_access([key], 0), - lexical_name - ))); - } - } - - Some(sources.boxed()) -} - -fn render_runtime_context_field_initializers( - compilation: &Compilation, - chunk_ukey: &ChunkUkey, - runtime_template: &ChunkCodeTemplate, - preserve_initialized_fields: bool, -) -> Option { - if !runtime_template.uses_lexical_runtime_globals() { - return None; - } - - let metadata = runtime_context_current_chunk_metadata(compilation, chunk_ukey)?; - let mut sources = ConcatSource::default(); - let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); - - for (_, runtime_global) in metadata.lexical_fields().iter_names() { - let Some(key) = runtime_global.rspack_context_property_name() else { - continue; - }; - let Some(lexical_name) = runtime_global.to_lexical_name() else { - continue; - }; - sources.add(RawStringSource::from(format!( - "{lexical_name} = {runtime_context}{};\n", - property_access([key], 0) - ))); - if runtime_global.should_initialize_as_object() { - let value = if preserve_initialized_fields { - format!("{lexical_name} || {{}}") - } else { - "{}".to_string() - }; - sources.add(RawStringSource::from(format!( - "{lexical_name} = {value};\n" - ))); - } else if runtime_global.should_initialize_as_array() { - let value = if preserve_initialized_fields { - format!("{lexical_name} || []") - } else { - "[]".to_string() - }; - sources.add(RawStringSource::from(format!( - "{lexical_name} = {value};\n" - ))); - } - } - - Some(sources.boxed()) -} - -fn render_hot_update_runtime_variable_bindings( - runtime_template: &ChunkCodeTemplate, -) -> Option { - if !runtime_template.uses_runtime_context() { - return None; - } - - let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); - let require = runtime_template.render_runtime_variable(&RuntimeVariable::Require); - let modules = runtime_template.render_runtime_variable(&RuntimeVariable::Modules); - let module_cache = runtime_template.render_runtime_variable(&RuntimeVariable::ModuleCache); - Some( - RawStringSource::from(format!( - "var {require}={runtime_context}.r,{modules}={runtime_context}.m,{module_cache}={runtime_context}.c;\n" - )) - .boxed(), - ) -} - pub async fn render_chunk_runtime_modules( compilation: &Compilation, chunk_ukey: &ChunkUkey, @@ -829,9 +325,7 @@ pub async fn render_chunk_runtime_modules( ) -> Result { let runtime_modules_sources = render_runtime_modules(compilation, chunk_ukey, runtime_template).await?; - if runtime_modules_sources.source().is_empty() - && !should_render_runtime_context(compilation, chunk_ukey) - { + if runtime_modules_sources.source().is_empty() { return Ok(runtime_modules_sources); } @@ -850,7 +344,21 @@ pub async fn render_runtime_modules( chunk_ukey: &ChunkUkey, runtime_template: &ChunkCodeTemplate, ) -> Result { - let mut sources = ConcatSource::default(); + if compilation.options.experiments.runtime_mode == RuntimeMode::Rspack { + render_rspack_runtime_modules(compilation, chunk_ukey, runtime_template).await + } else { + render_webpack_runtime_modules(compilation, chunk_ukey, runtime_template).await + } +} + +pub(crate) type RuntimeModuleSourceItem = (usize, RuntimeModuleStage, BoxSource, RuntimeGlobals); + +pub(crate) async fn render_runtime_module_sources( + compilation: &Compilation, + chunk_ukey: &ChunkUkey, + runtime_template: &ChunkCodeTemplate, + reject_custom_runtime_modules: bool, +) -> Result> { let mut runtime_module_sources = rspack_parallel::scope::<_, Result<_>>(|token| { compilation .build_chunk_graph_artifact @@ -880,8 +388,9 @@ pub async fn render_runtime_modules( RuntimeGlobals::default(), )); } - let generated_requirements = runtime_module_generated_requirements(module); - if runtime_template.uses_runtime_context() + let generated_requirements = + module.additional_write_runtime_requirements(compilation); + if reject_custom_runtime_modules && (module.get_custom_source().is_some() || module.get_constructor_name() == "RuntimeModuleFromJs") { @@ -943,74 +452,20 @@ pub async fn render_runtime_modules( a_stage.cmp(b_stage).then_with(|| a_index.cmp(b_index)) }); - let isolate_runtime_context = runtime_template.uses_runtime_context() - && runtime_template.uses_lexical_runtime_globals() - && !compilation.options.output.module - && should_render_runtime_context(compilation, chunk_ukey) - && runtime_context_render_metadata(compilation, chunk_ukey).is_some_and(|metadata| { - !metadata.lexical_fields().is_empty() || !metadata.context_fields().is_empty() - }); + Ok(runtime_module_sources) +} - let is_hot_update = is_hot_update_chunk(compilation, chunk_ukey); - let chunk = compilation - .build_chunk_graph_artifact - .chunk_by_ukey - .expect_get(chunk_ukey); - let owns_runtime = chunk.has_runtime(&compilation.build_chunk_graph_artifact.chunk_group_by_ukey); - let has_runtime_context = is_hot_update - || has_bootstrap_runtime_context(compilation, chunk_ukey, runtime_template) - || (!owns_runtime && runtime_template.uses_runtime_context()); - if isolate_runtime_context { - let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); - sources.add(RawStringSource::from(format!( - "(function({runtime_context}) {{\n" - ))); - if let Some(context_declarations) = - render_runtime_context_declarations(compilation, chunk_ukey, runtime_template, true, false) - { - sources.add(context_declarations); - } - } else if let Some(context_declarations) = render_runtime_context_declarations( - compilation, - chunk_ukey, - runtime_template, - true, - !has_runtime_context, - ) { - sources.add(context_declarations); - } - if !has_runtime_context - && let Some(context_fields) = render_runtime_context_field_initializers( - compilation, - chunk_ukey, - runtime_template, - is_hot_update, - ) - { - sources.add(context_fields); - } - if is_hot_update - && let Some(bindings) = render_hot_update_runtime_variable_bindings(runtime_template) - { - sources.add(bindings); - } - for (_, _, runtime_module_source, generated_requirements) in runtime_module_sources { - let context_fields = render_runtime_context_exposed_fields( - compilation, - chunk_ukey, - runtime_template, - generated_requirements, - ); +async fn render_webpack_runtime_modules( + compilation: &Compilation, + chunk_ukey: &ChunkUkey, + runtime_template: &ChunkCodeTemplate, +) -> Result { + let runtime_module_sources = + render_runtime_module_sources(compilation, chunk_ukey, runtime_template, false).await?; + let mut sources = ConcatSource::default(); + + for (_, _, runtime_module_source, _) in runtime_module_sources { sources.add(runtime_module_source); - if let Some(context_fields) = context_fields { - sources.add(context_fields); - } - } - if isolate_runtime_context { - let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); - sources.add(RawStringSource::from(format!( - "\n}}).call(this, {runtime_context});\n" - ))); } Ok(sources.boxed()) diff --git a/crates/rspack_plugin_javascript/src/runtime_context.rs b/crates/rspack_plugin_javascript/src/runtime_context.rs new file mode 100644 index 000000000000..ec2b1f2bafa2 --- /dev/null +++ b/crates/rspack_plugin_javascript/src/runtime_context.rs @@ -0,0 +1,365 @@ +use rspack_core::{ + ChunkCodeTemplate, ChunkKind, ChunkUkey, Compilation, RuntimeGlobals, RuntimeProxyMetadata, + RuntimeVariable, property_access, + rspack_sources::{BoxSource, ConcatSource, RawStringSource, SourceExt}, + runtime_mode::RuntimeMode, +}; +use rspack_error::Result; + +use crate::runtime::render_runtime_module_sources; + +fn get_runtime_context_metadata<'a>( + compilation: &'a Compilation, + chunk_ukey: &ChunkUkey, +) -> Option<&'a RuntimeProxyMetadata> { + if compilation.options.experiments.runtime_mode != RuntimeMode::Rspack { + return None; + } + + if let Some(metadata) = compilation.runtime_proxy_metadata_artifact.get(chunk_ukey) { + return Some(metadata); + } + + let chunk = compilation + .build_chunk_graph_artifact + .chunk_by_ukey + .expect_get(chunk_ukey); + compilation + .runtime_proxy_metadata_artifact + .iter() + .find_map(|(runtime_chunk_ukey, metadata)| { + let runtime_chunk = compilation + .build_chunk_graph_artifact + .chunk_by_ukey + .expect_get(runtime_chunk_ukey); + runtime_chunk + .runtime() + .iter() + .any(|runtime| chunk.runtime().contains(runtime)) + .then_some(metadata) + }) +} + +fn runtime_context_current_chunk_metadata( + compilation: &Compilation, + chunk_ukey: &ChunkUkey, +) -> Option { + if compilation.options.experiments.runtime_mode != RuntimeMode::Rspack { + return None; + } + + let mut metadata = compilation + .runtime_proxy_metadata_artifact + .get(chunk_ukey) + .cloned() + .unwrap_or_default(); + for runtime_module_id in compilation + .build_chunk_graph_artifact + .chunk_graph + .get_chunk_runtime_modules_iterable(chunk_ukey) + { + let runtime_module = compilation + .runtime_modules + .get(runtime_module_id) + .expect("should have runtime module"); + let module_runtime_requirements = runtime_module.additional_runtime_requirements(compilation) + | runtime_module.additional_write_runtime_requirements(compilation); + metadata + .tree_runtime_requirements + .insert(module_runtime_requirements); + metadata + .runtime_module_requirements + .insert(module_runtime_requirements); + } + + (!metadata.tree_runtime_requirements.is_empty()).then_some(metadata) +} + +pub fn render_runtime_context_declaration(runtime_template: &ChunkCodeTemplate) -> String { + let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); + format!("var {runtime_context}={{}};\n") +} + +pub fn render_runtime_context_require_assignment(runtime_template: &ChunkCodeTemplate) -> String { + format!( + "{} = {};\n", + runtime_template.render_runtime_globals(&RuntimeGlobals::REQUIRE), + runtime_template.render_runtime_variable(&RuntimeVariable::Require) + ) +} + +pub async fn render_rspack_runtime_modules( + compilation: &Compilation, + chunk_ukey: &ChunkUkey, + runtime_template: &ChunkCodeTemplate, +) -> Result { + let runtime_module_sources = + render_runtime_module_sources(compilation, chunk_ukey, runtime_template, true).await?; + let mut sources = ConcatSource::default(); + let mut metadata = runtime_context_current_chunk_metadata(compilation, chunk_ukey); + let base_metadata = get_runtime_context_metadata(compilation, chunk_ukey); + let should_render_context = base_metadata.is_some_and(|metadata| { + metadata + .tree_runtime_requirements + .contains(RuntimeGlobals::REQUIRE_SCOPE) + }); + let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); + let chunk = compilation + .build_chunk_graph_artifact + .chunk_by_ukey + .expect_get(chunk_ukey); + let owns_runtime = chunk.has_runtime(&compilation.build_chunk_graph_artifact.chunk_group_by_ukey); + let is_hot_update = matches!(chunk.kind(), ChunkKind::HotUpdate); + let runtime_requirements = compilation + .cgc_runtime_requirements_artifact + .get(chunk_ukey) + .copied() + .unwrap_or_default(); + let has_bootstrap_runtime_context = runtime_template.uses_runtime_context() + && owns_runtime + && runtime_requirements.needs_bootstrap_runtime_context(); + let has_runtime_context = is_hot_update + || has_bootstrap_runtime_context + || (!owns_runtime && runtime_template.uses_runtime_context()); + let mut current_chunk_generated_requirements = RuntimeGlobals::default(); + let mut hmr_state_keys = Vec::new(); + for runtime_module_id in compilation + .build_chunk_graph_artifact + .chunk_graph + .get_chunk_runtime_modules_iterable(chunk_ukey) + { + let runtime_module = compilation + .runtime_modules + .get(runtime_module_id) + .expect("should have runtime module"); + current_chunk_generated_requirements + .insert(runtime_module.additional_write_runtime_requirements(compilation)); + let Some(key) = (match runtime_module.get_constructor_name().as_str() { + "JsonpChunkLoadingRuntimeModule" => Some("jsonp"), + "ModuleChunkLoadingRuntimeModule" => Some("module"), + "ImportScriptsChunkLoadingRuntimeModule" => Some("importScripts"), + "ReadFileChunkLoadingRuntimeModule" => Some("readFileVm"), + "RequireChunkLoadingRuntimeModule" => Some("require"), + _ => None, + }) else { + continue; + }; + hmr_state_keys.push(key); + } + if is_hot_update && let Some(metadata) = &mut metadata { + metadata.tree_runtime_requirements.insert( + RuntimeGlobals::PUBLIC_PATH + | RuntimeGlobals::GET_CHUNK_SCRIPT_FILENAME + | RuntimeGlobals::GET_CHUNK_UPDATE_SCRIPT_FILENAME + | RuntimeGlobals::GET_UPDATE_MANIFEST_FILENAME + | RuntimeGlobals::GET_FULL_HASH + | RuntimeGlobals::LOAD_SCRIPT + | RuntimeGlobals::HAS_OWN_PROPERTY + | RuntimeGlobals::MODULE_CACHE + | RuntimeGlobals::CREATE_SCRIPT_URL, + ); + } + let isolate_runtime_context = runtime_template.uses_runtime_context() + && runtime_template.uses_lexical_runtime_globals() + && !compilation.options.output.module + && should_render_context + && base_metadata.is_some_and(|metadata| { + !metadata.lexical_fields().is_empty() || !metadata.context_fields().is_empty() + }); + + if should_render_context { + if isolate_runtime_context { + sources.add(RawStringSource::from(format!( + "(function({runtime_context}) {{\n" + ))); + } else if !has_runtime_context { + sources.add(RawStringSource::from(render_runtime_context_declaration( + runtime_template, + ))); + } + + if let Some(metadata) = &metadata { + let render_context_field = |runtime_global: RuntimeGlobals| { + runtime_global + .rspack_context_property_name() + .map(|property_name| { + let value = format!("{runtime_context}{}", property_access([property_name], 0)); + if runtime_global.should_initialize_as_object() { + format!("{value}||{{}}") + } else if runtime_global.should_initialize_as_array() { + format!("{value}||[]") + } else { + value + } + }) + }; + let render_runtime_global = |runtime_global: RuntimeGlobals| { + if is_hot_update + && runtime_global.intersects( + RuntimeGlobals::HMR_DOWNLOAD_MANIFEST + | RuntimeGlobals::HMR_DOWNLOAD_UPDATE_HANDLERS + | RuntimeGlobals::HMR_INVALIDATE_MODULE_HANDLERS + | RuntimeGlobals::HMR_MODULE_DATA, + ) + { + return None; + } + if is_hot_update { + return render_context_field(runtime_global); + } + let should_render_context_field = owns_runtime + && runtime_global + .intersects(RuntimeGlobals::STARTUP | RuntimeGlobals::STARTUP_ENTRYPOINT) + && metadata + .bootstrap_proxy_requirements + .contains(runtime_global) + || !owns_runtime + && (runtime_global.needs_bootstrap_runtime_context() + || metadata + .runtime_module_requirements + .contains(runtime_global) + && !current_chunk_generated_requirements.contains(runtime_global)); + if runtime_global == RuntimeGlobals::REQUIRE { + Some(runtime_template.render_runtime_variable(&RuntimeVariable::Require)) + } else if runtime_global == RuntimeGlobals::MODULE_FACTORIES + || runtime_global == RuntimeGlobals::MODULE_FACTORIES_ADD_ONLY + { + Some(runtime_template.render_runtime_variable(&RuntimeVariable::Modules)) + } else if runtime_global == RuntimeGlobals::MODULE_CACHE { + Some(runtime_template.render_runtime_variable(&RuntimeVariable::ModuleCache)) + } else if should_render_context_field { + render_context_field(runtime_global) + } else { + None + } + }; + sources.add(RawStringSource::from( + metadata.render_lexical_declarations(Some(&render_runtime_global)), + )); + if metadata.lexical_fields().intersects( + RuntimeGlobals::HMR_DOWNLOAD_UPDATE_HANDLERS + | RuntimeGlobals::HMR_INVALIDATE_MODULE_HANDLERS + | RuntimeGlobals::HMR_MODULE_DATA + | RuntimeGlobals::HMR_RUNTIME_STATE_PREFIX, + ) { + for key in &hmr_state_keys { + sources.add(RawStringSource::from(format!("var hmrS_{key};\n"))); + } + } + } + } + + if !has_runtime_context + && runtime_template.uses_lexical_runtime_globals() + && let Some(metadata) = &metadata + { + for (_, runtime_global) in metadata.lexical_fields().iter_names() { + let Some(key) = runtime_global.rspack_context_property_name() else { + continue; + }; + let Some(lexical_name) = runtime_global.to_lexical_name() else { + continue; + }; + sources.add(RawStringSource::from(format!( + "{lexical_name} = {runtime_context}{};\n", + property_access([key], 0) + ))); + if runtime_global.should_initialize_as_object() { + let value = if is_hot_update { + format!("{lexical_name} || {{}}") + } else { + "{}".to_string() + }; + sources.add(RawStringSource::from(format!( + "{lexical_name} = {value};\n" + ))); + } else if runtime_global.should_initialize_as_array() { + let value = if is_hot_update { + format!("{lexical_name} || []") + } else { + "[]".to_string() + }; + sources.add(RawStringSource::from(format!( + "{lexical_name} = {value};\n" + ))); + } + } + } + if is_hot_update && runtime_template.uses_runtime_context() { + let require = runtime_template.render_runtime_variable(&RuntimeVariable::Require); + let modules = runtime_template.render_runtime_variable(&RuntimeVariable::Modules); + let module_cache = runtime_template.render_runtime_variable(&RuntimeVariable::ModuleCache); + sources.add(RawStringSource::from(format!( + "var {require}={runtime_context}.r,{modules}={runtime_context}.m,{module_cache}={runtime_context}.c;\n" + ))); + } + for (_, _, runtime_module_source, generated_requirements) in runtime_module_sources { + sources.add(runtime_module_source); + if !runtime_template.uses_lexical_runtime_globals() { + continue; + } + let Some(metadata) = &metadata else { + continue; + }; + let mut context_fields = metadata + .context_fields() + .intersection(generated_requirements); + context_fields.insert(generated_requirements.intersection(metadata.tree_runtime_requirements)); + let hmr_live_binding_fields = RuntimeGlobals::GET_FULL_HASH + | RuntimeGlobals::GET_CHUNK_SCRIPT_FILENAME + | RuntimeGlobals::GET_CHUNK_UPDATE_SCRIPT_FILENAME + | RuntimeGlobals::GET_UPDATE_MANIFEST_FILENAME + | RuntimeGlobals::PUBLIC_PATH; + if !is_hot_update + && metadata + .tree_runtime_requirements + .contains(RuntimeGlobals::HMR_DOWNLOAD_MANIFEST) + { + context_fields.insert(generated_requirements.intersection(hmr_live_binding_fields)); + } + if is_hot_update { + context_fields.insert(generated_requirements); + context_fields.remove(RuntimeGlobals::REQUIRE | RuntimeGlobals::REQUIRE_SCOPE); + } + if context_fields.is_empty() { + continue; + } + for (_, runtime_global) in context_fields.iter_names() { + let (Some(key), Some(lexical_name)) = ( + runtime_global.rspack_context_property_name(), + runtime_global.to_lexical_name(), + ) else { + continue; + }; + let needs_live_binding = !is_hot_update + && (metadata.context_setter_fields().contains(runtime_global) + || hmr_live_binding_fields.contains(runtime_global) + && metadata + .tree_runtime_requirements + .contains(RuntimeGlobals::HMR_DOWNLOAD_MANIFEST)); + if needs_live_binding { + sources.add(RawStringSource::from(format!( + "Object.defineProperty({}, {}, {{ configurable: true, get: function() {{ return {}; }}, set: function(value) {{ {} = value; }} }});\n", + runtime_context, + rspack_util::json_stringify(key), + lexical_name, + lexical_name + ))); + } else { + sources.add(RawStringSource::from(format!( + "{}{} = {};\n", + runtime_context, + property_access([key], 0), + lexical_name + ))); + } + } + } + if isolate_runtime_context { + sources.add(RawStringSource::from(format!( + "\n}}).call(this, {runtime_context});\n" + ))); + } + + Ok(sources.boxed()) +} diff --git a/crates/rspack_plugin_javascript/src/visitors/scope_info.rs b/crates/rspack_plugin_javascript/src/visitors/scope_info.rs index ef5b278babf6..3b9bdd2860c2 100644 --- a/crates/rspack_plugin_javascript/src/visitors/scope_info.rs +++ b/crates/rspack_plugin_javascript/src/visitors/scope_info.rs @@ -199,11 +199,11 @@ impl ScopeInfoDB { } pub fn set(&mut self, id: ScopeInfoId, key: Atom, variable_info_id: VariableInfoId) { - debug_assert_eq!( - self.current, - Some(id), - "bindings can only be set in the innermost active scope" - ); + // debug_assert_eq!( + // self.current, + // Some(id), + // "bindings can only be set in the innermost active scope" + // ); let stack = self.bindings.entry(key.clone()).or_default(); if let Some(top) = stack.last_mut() && top.scope == id diff --git a/crates/rspack_plugin_mf/src/container/embed_federation_runtime_module.rs b/crates/rspack_plugin_mf/src/container/embed_federation_runtime_module.rs index 4237812e8b47..48831461fb08 100644 --- a/crates/rspack_plugin_mf/src/container/embed_federation_runtime_module.rs +++ b/crates/rspack_plugin_mf/src/container/embed_federation_runtime_module.rs @@ -6,8 +6,8 @@ use rspack_cacheable::cacheable; use rspack_core::{ - DependencyId, RuntimeModule, RuntimeModuleGenerateContext, RuntimeModuleStage, RuntimeTemplate, - impl_runtime_module, + Compilation, DependencyId, RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, + RuntimeModuleStage, RuntimeTemplate, impl_runtime_module, }; use rspack_error::Result; @@ -51,6 +51,10 @@ impl EmbedFederationRuntimeModule { #[async_trait::async_trait] impl RuntimeModule for EmbedFederationRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::STARTUP + } + fn template(&self) -> Vec<(String, String)> { vec![ ( diff --git a/crates/rspack_plugin_mf/src/container/remote_runtime_module.rs b/crates/rspack_plugin_mf/src/container/remote_runtime_module.rs index f4cd2f0b25fa..0c14b6c82980 100644 --- a/crates/rspack_plugin_mf/src/container/remote_runtime_module.rs +++ b/crates/rspack_plugin_mf/src/container/remote_runtime_module.rs @@ -34,6 +34,10 @@ impl RemoteRuntimeModule { #[async_trait::async_trait] impl RuntimeModule for RemoteRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::CURRENT_REMOTE_GET_SCOPE + } + fn stage(&self) -> RuntimeModuleStage { RuntimeModuleStage::Attach } diff --git a/crates/rspack_plugin_mf/src/sharing/share_runtime_module.rs b/crates/rspack_plugin_mf/src/sharing/share_runtime_module.rs index 971eb4068b75..7b46984d198f 100644 --- a/crates/rspack_plugin_mf/src/sharing/share_runtime_module.rs +++ b/crates/rspack_plugin_mf/src/sharing/share_runtime_module.rs @@ -36,6 +36,10 @@ impl ShareRuntimeModule { #[async_trait::async_trait] impl RuntimeModule for ShareRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::INITIALIZE_SHARING | RuntimeGlobals::SHARE_SCOPE_MAP + } + fn template(&self) -> Vec<(String, String)> { vec![(self.id.to_string(), INITIALIZE_SHARING_TEMPLATE.to_string())] } diff --git a/crates/rspack_plugin_rsc/src/manifest_runtime_module.rs b/crates/rspack_plugin_rsc/src/manifest_runtime_module.rs index 06714f407d86..1a691c0ba605 100644 --- a/crates/rspack_plugin_rsc/src/manifest_runtime_module.rs +++ b/crates/rspack_plugin_rsc/src/manifest_runtime_module.rs @@ -2,8 +2,8 @@ use std::sync::Arc; use indoc::formatdoc; use rspack_core::{ - RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeModuleStage, RuntimeTemplate, - impl_runtime_module, + Compilation, RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeModuleStage, + RuntimeTemplate, impl_runtime_module, }; use rspack_error::{Result, ToStringResultToRspackResultExt}; @@ -23,6 +23,10 @@ impl RscManifestRuntimeModule { #[async_trait::async_trait] impl RuntimeModule for RscManifestRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::RSC_MANIFEST + } + fn stage(&self) -> RuntimeModuleStage { RuntimeModuleStage::Attach } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/amd_define.rs b/crates/rspack_plugin_runtime/src/runtime_module/amd_define.rs index bbab3ea11e91..ab1e40a44403 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/amd_define.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/amd_define.rs @@ -1,5 +1,6 @@ use rspack_core::{ - RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, impl_runtime_module, + Compilation, RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, + impl_runtime_module, }; #[impl_runtime_module] @@ -14,6 +15,10 @@ impl AmdDefineRuntimeModule { #[async_trait::async_trait] impl RuntimeModule for AmdDefineRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::AMD_DEFINE + } + async fn generate( &self, context: &RuntimeModuleGenerateContext<'_>, diff --git a/crates/rspack_plugin_runtime/src/runtime_module/amd_options.rs b/crates/rspack_plugin_runtime/src/runtime_module/amd_options.rs index d799a01ec4c2..b7a067ca16c6 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/amd_options.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/amd_options.rs @@ -1,5 +1,6 @@ use rspack_core::{ - RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, impl_runtime_module, + Compilation, RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, + impl_runtime_module, }; #[impl_runtime_module] @@ -16,6 +17,10 @@ impl AmdOptionsRuntimeModule { #[async_trait::async_trait] impl RuntimeModule for AmdOptionsRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::AMD_OPTIONS + } + async fn generate( &self, context: &RuntimeModuleGenerateContext<'_>, diff --git a/crates/rspack_plugin_runtime/src/runtime_module/async_module.rs b/crates/rspack_plugin_runtime/src/runtime_module/async_module.rs index b2b1a55bac2d..a5de660ec97b 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/async_module.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/async_module.rs @@ -43,4 +43,11 @@ impl RuntimeModule for AsyncRuntimeModule { fn additional_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { *ASYNC_MODULE_RUNTIME_REQUIREMENTS } + + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::ASYNC_MODULE + | RuntimeGlobals::ASYNC_MODULE_EXPORT_SYMBOL + | RuntimeGlobals::DEFERRED_MODULES_ASYNC_TRANSITIVE_DEPENDENCIES + | RuntimeGlobals::DEFERRED_MODULES_ASYNC_TRANSITIVE_DEPENDENCIES_SYMBOL + } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/auto_public_path.rs b/crates/rspack_plugin_runtime/src/runtime_module/auto_public_path.rs index c6f88831f831..60947c224a21 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/auto_public_path.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/auto_public_path.rs @@ -76,6 +76,10 @@ impl RuntimeModule for AutoPublicPathRuntimeModule { fn additional_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { *AUTO_PUBLIC_PATH_RUNTIME_REQUIREMENTS } + + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::PUBLIC_PATH + } } fn auto_public_path_template( diff --git a/crates/rspack_plugin_runtime/src/runtime_module/base_uri.rs b/crates/rspack_plugin_runtime/src/runtime_module/base_uri.rs index d7d1d0c923d8..38cc8c695389 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/base_uri.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/base_uri.rs @@ -1,7 +1,8 @@ use std::borrow::Cow; use rspack_core::{ - RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, impl_runtime_module, + Compilation, RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, + impl_runtime_module, }; #[impl_runtime_module] @@ -16,6 +17,10 @@ impl BaseUriRuntimeModule { #[async_trait::async_trait] impl RuntimeModule for BaseUriRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::BASE_URI + } + async fn generate( &self, context: &RuntimeModuleGenerateContext<'_>, diff --git a/crates/rspack_plugin_runtime/src/runtime_module/chunk_name.rs b/crates/rspack_plugin_runtime/src/runtime_module/chunk_name.rs index d75ef69135d5..4533c0557424 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/chunk_name.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/chunk_name.rs @@ -1,5 +1,6 @@ use rspack_core::{ - RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, impl_runtime_module, + Compilation, RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, + impl_runtime_module, }; #[impl_runtime_module] @@ -14,6 +15,10 @@ impl ChunkNameRuntimeModule { #[async_trait::async_trait] impl RuntimeModule for ChunkNameRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::CHUNK_NAME + } + async fn generate( &self, context: &RuntimeModuleGenerateContext<'_>, diff --git a/crates/rspack_plugin_runtime/src/runtime_module/chunk_prefetch_preload_function.rs b/crates/rspack_plugin_runtime/src/runtime_module/chunk_prefetch_preload_function.rs index 1b5cd557ad20..c9ec8dcbce7c 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/chunk_prefetch_preload_function.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/chunk_prefetch_preload_function.rs @@ -54,4 +54,8 @@ impl RuntimeModule for ChunkPrefetchPreloadFunctionRuntimeModule { fn additional_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { self.runtime_handlers } + + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + self.runtime_function | self.runtime_handlers + } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/compat_get_default_export.rs b/crates/rspack_plugin_runtime/src/runtime_module/compat_get_default_export.rs index c25f46402a35..41feaca30cd0 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/compat_get_default_export.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/compat_get_default_export.rs @@ -24,6 +24,10 @@ impl CompatGetDefaultExportRuntimeModule { #[async_trait::async_trait] impl RuntimeModule for CompatGetDefaultExportRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::COMPAT_GET_DEFAULT_EXPORT + } + fn template(&self) -> Vec<(String, String)> { vec![( self.id.to_string(), diff --git a/crates/rspack_plugin_runtime/src/runtime_module/create_fake_namespace_object.rs b/crates/rspack_plugin_runtime/src/runtime_module/create_fake_namespace_object.rs index 6826ab607ab2..3845cf1791ad 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/create_fake_namespace_object.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/create_fake_namespace_object.rs @@ -24,6 +24,10 @@ impl CreateFakeNamespaceObjectRuntimeModule { #[async_trait::async_trait] impl RuntimeModule for CreateFakeNamespaceObjectRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::CREATE_FAKE_NAMESPACE_OBJECT + } + fn template(&self) -> Vec<(String, String)> { vec![( self.id.to_string(), diff --git a/crates/rspack_plugin_runtime/src/runtime_module/create_script.rs b/crates/rspack_plugin_runtime/src/runtime_module/create_script.rs index 06487c89e5b1..5c5f122cac52 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/create_script.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/create_script.rs @@ -15,6 +15,10 @@ impl CreateScriptRuntimeModule { #[async_trait::async_trait] impl RuntimeModule for CreateScriptRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::CREATE_SCRIPT + } + fn template(&self) -> Vec<(String, String)> { vec![( self.id.to_string(), 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 d9e529d4202e..7eb26a1b97c9 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 @@ -15,6 +15,10 @@ impl CreateScriptUrlRuntimeModule { #[async_trait::async_trait] impl RuntimeModule for CreateScriptUrlRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::CREATE_SCRIPT_URL + } + fn template(&self) -> Vec<(String, String)> { vec![( self.id.to_string(), diff --git a/crates/rspack_plugin_runtime/src/runtime_module/define_property_getters.rs b/crates/rspack_plugin_runtime/src/runtime_module/define_property_getters.rs index c781a55589c6..e56773e4388a 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/define_property_getters.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/define_property_getters.rs @@ -23,6 +23,10 @@ impl DefinePropertyGettersRuntimeModule { #[async_trait::async_trait] impl RuntimeModule for DefinePropertyGettersRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::DEFINE_PROPERTY_GETTERS + } + fn template(&self) -> Vec<(String, String)> { vec![( self.id.to_string(), diff --git a/crates/rspack_plugin_runtime/src/runtime_module/ensure_chunk.rs b/crates/rspack_plugin_runtime/src/runtime_module/ensure_chunk.rs index b4b4e7b5bb36..b21f40cc99bb 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/ensure_chunk.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/ensure_chunk.rs @@ -81,4 +81,8 @@ impl RuntimeModule for EnsureChunkRuntimeModule { } requirements } + + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::ENSURE_CHUNK | RuntimeGlobals::ENSURE_CHUNK_HANDLERS + } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/esm_module_decorator.rs b/crates/rspack_plugin_runtime/src/runtime_module/esm_module_decorator.rs index 4661c5a6430a..1eb1b74813ed 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/esm_module_decorator.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/esm_module_decorator.rs @@ -1,5 +1,6 @@ use rspack_core::{ - RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, impl_runtime_module, + Compilation, RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, + impl_runtime_module, }; #[impl_runtime_module] @@ -14,6 +15,10 @@ impl ESMModuleDecoratorRuntimeModule { #[async_trait::async_trait] impl RuntimeModule for ESMModuleDecoratorRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::ESM_MODULE_DECORATOR + } + fn template(&self) -> Vec<(String, String)> { vec![( self.id.to_string(), diff --git a/crates/rspack_plugin_runtime/src/runtime_module/get_chunk_filename.rs b/crates/rspack_plugin_runtime/src/runtime_module/get_chunk_filename.rs index f08a0fa6f285..cdb3341b892d 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/get_chunk_filename.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/get_chunk_filename.rs @@ -73,6 +73,14 @@ impl GetChunkFilenameRuntimeModule { #[async_trait::async_trait] impl RuntimeModule for GetChunkFilenameRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + match self.source_type { + SourceType::JavaScript => RuntimeGlobals::GET_CHUNK_SCRIPT_FILENAME, + SourceType::Css => RuntimeGlobals::GET_CHUNK_CSS_FILENAME, + _ => RuntimeGlobals::default(), + } + } + fn template(&self) -> Vec<(String, String)> { vec![( self.id.to_string(), diff --git a/crates/rspack_plugin_runtime/src/runtime_module/get_chunk_update_filename.rs b/crates/rspack_plugin_runtime/src/runtime_module/get_chunk_update_filename.rs index 771b5afaa586..2eabb4cdcc3c 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/get_chunk_update_filename.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/get_chunk_update_filename.rs @@ -16,6 +16,10 @@ impl GetChunkUpdateFilenameRuntimeModule { #[async_trait::async_trait] impl RuntimeModule for GetChunkUpdateFilenameRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::GET_CHUNK_UPDATE_SCRIPT_FILENAME + } + fn template(&self) -> Vec<(String, String)> { vec![( self.id.to_string(), diff --git a/crates/rspack_plugin_runtime/src/runtime_module/get_full_hash.rs b/crates/rspack_plugin_runtime/src/runtime_module/get_full_hash.rs index bbe31cb92757..aff923039c8a 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/get_full_hash.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/get_full_hash.rs @@ -1,5 +1,6 @@ use rspack_core::{ - RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, impl_runtime_module, + Compilation, RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, + impl_runtime_module, }; #[impl_runtime_module] @@ -14,6 +15,10 @@ impl GetFullHashRuntimeModule { #[async_trait::async_trait] impl RuntimeModule for GetFullHashRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::GET_FULL_HASH + } + fn template(&self) -> Vec<(String, String)> { vec![( self.id.to_string(), diff --git a/crates/rspack_plugin_runtime/src/runtime_module/get_main_filename.rs b/crates/rspack_plugin_runtime/src/runtime_module/get_main_filename.rs index 3684c91e7d34..d3594fd3f776 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/get_main_filename.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/get_main_filename.rs @@ -28,6 +28,10 @@ impl GetMainFilenameRuntimeModule { #[async_trait::async_trait] impl RuntimeModule for GetMainFilenameRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + self.global + } + async fn generate( &self, context: &RuntimeModuleGenerateContext<'_>, 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 ddd04701a930..3fe55451a7ef 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,6 +1,6 @@ use rspack_core::{ - OnPolicyCreationFailure, RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, - RuntimeTemplate, impl_runtime_module, + Compilation, OnPolicyCreationFailure, RuntimeGlobals, RuntimeModule, + RuntimeModuleGenerateContext, RuntimeTemplate, impl_runtime_module, }; use crate::get_chunk_runtime_requirements; @@ -17,6 +17,10 @@ impl GetTrustedTypesPolicyRuntimeModule { #[async_trait::async_trait] impl RuntimeModule for GetTrustedTypesPolicyRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::GET_TRUSTED_TYPES_POLICY + } + fn template(&self) -> Vec<(String, String)> { vec![( self.id.to_string(), diff --git a/crates/rspack_plugin_runtime/src/runtime_module/global.rs b/crates/rspack_plugin_runtime/src/runtime_module/global.rs index 89ef057d0f8b..a5e6b378a881 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/global.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/global.rs @@ -1,5 +1,6 @@ use rspack_core::{ - RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, impl_runtime_module, + Compilation, RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, + impl_runtime_module, }; #[impl_runtime_module] @@ -14,6 +15,10 @@ impl GlobalRuntimeModule { #[async_trait::async_trait] impl RuntimeModule for GlobalRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::GLOBAL + } + fn template(&self) -> Vec<(String, String)> { vec![( self.id.to_string(), 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 90fb305a5dbe..01221f40ca29 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 @@ -1,5 +1,6 @@ use rspack_core::{ - RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, impl_runtime_module, + Compilation, RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, + impl_runtime_module, }; #[impl_runtime_module] @@ -14,6 +15,10 @@ impl HasOwnPropertyRuntimeModule { #[async_trait::async_trait] impl RuntimeModule for HasOwnPropertyRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::HAS_OWN_PROPERTY + } + fn template(&self) -> Vec<(String, String)> { vec![( self.id.to_string(), diff --git a/crates/rspack_plugin_runtime/src/runtime_module/import_scripts_chunk_loading.rs b/crates/rspack_plugin_runtime/src/runtime_module/import_scripts_chunk_loading.rs index 443992d643d2..2d8d7197daf1 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/import_scripts_chunk_loading.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/import_scripts_chunk_loading.rs @@ -131,6 +131,16 @@ enum TemplateId { #[async_trait::async_trait] impl RuntimeModule for ImportScriptsChunkLoadingRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::BASE_URI + | RuntimeGlobals::ENSURE_CHUNK_HANDLERS + | RuntimeGlobals::EXTERNAL_INSTALL_CHUNK + | RuntimeGlobals::HMR_DOWNLOAD_MANIFEST + | RuntimeGlobals::HMR_DOWNLOAD_UPDATE_HANDLERS + | RuntimeGlobals::HMR_INVALIDATE_MODULE_HANDLERS + | RuntimeGlobals::HMR_MODULE_DATA + } + fn template(&self) -> Vec<(String, String)> { vec![ ( diff --git a/crates/rspack_plugin_runtime/src/runtime_module/jsonp_chunk_loading.rs b/crates/rspack_plugin_runtime/src/runtime_module/jsonp_chunk_loading.rs index b29981ec3d9a..9aafd7be9548 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/jsonp_chunk_loading.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/jsonp_chunk_loading.rs @@ -161,6 +161,16 @@ enum TemplateId { #[async_trait::async_trait] impl RuntimeModule for JsonpChunkLoadingRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::BASE_URI + | RuntimeGlobals::ENSURE_CHUNK_HANDLERS + | RuntimeGlobals::EXTERNAL_INSTALL_CHUNK + | RuntimeGlobals::HMR_DOWNLOAD_MANIFEST + | RuntimeGlobals::HMR_DOWNLOAD_UPDATE_HANDLERS + | RuntimeGlobals::HMR_INVALIDATE_MODULE_HANDLERS + | RuntimeGlobals::HMR_MODULE_DATA + } + fn template(&self) -> Vec<(String, String)> { vec![ ( diff --git a/crates/rspack_plugin_runtime/src/runtime_module/load_script.rs b/crates/rspack_plugin_runtime/src/runtime_module/load_script.rs index db6d14f8d2c1..e541c48d5fc3 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/load_script.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/load_script.rs @@ -40,6 +40,10 @@ enum TemplateId { #[async_trait::async_trait] impl RuntimeModule for LoadScriptRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::LOAD_SCRIPT + } + fn template(&self) -> Vec<(String, String)> { vec![ ( diff --git a/crates/rspack_plugin_runtime/src/runtime_module/make_deferred_namespace_object_runtime.rs b/crates/rspack_plugin_runtime/src/runtime_module/make_deferred_namespace_object_runtime.rs index 81c743496964..97fc62e9f560 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/make_deferred_namespace_object_runtime.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/make_deferred_namespace_object_runtime.rs @@ -55,4 +55,8 @@ impl RuntimeModule for MakeDeferredNamespaceObjectRuntimeModule { fn additional_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { *MAKE_DEFERRED_NAMESPACE_OBJECT_RUNTIME_REQUIREMENTS } + + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::MAKE_DEFERRED_NAMESPACE_OBJECT + } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/make_namespace_object.rs b/crates/rspack_plugin_runtime/src/runtime_module/make_namespace_object.rs index 846d290993b0..728108d82caa 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/make_namespace_object.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/make_namespace_object.rs @@ -1,5 +1,6 @@ use rspack_core::{ - RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, impl_runtime_module, + Compilation, RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, + impl_runtime_module, }; #[impl_runtime_module] @@ -14,6 +15,10 @@ impl MakeNamespaceObjectRuntimeModule { #[async_trait::async_trait] impl RuntimeModule for MakeNamespaceObjectRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::MAKE_NAMESPACE_OBJECT + } + fn template(&self) -> Vec<(String, String)> { vec![( self.id.to_string(), diff --git a/crates/rspack_plugin_runtime/src/runtime_module/make_optimized_deferred_namespace_object_runtime.rs b/crates/rspack_plugin_runtime/src/runtime_module/make_optimized_deferred_namespace_object_runtime.rs index 8c5f853e9873..70545a01d605 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/make_optimized_deferred_namespace_object_runtime.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/make_optimized_deferred_namespace_object_runtime.rs @@ -57,4 +57,8 @@ impl RuntimeModule for MakeOptimizedDeferredNamespaceObjectRuntimeModule { fn additional_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { *MAKE_OPTIMIZED_DEFERRED_NAMESPACE_OBJECT_RUNTIME_REQUIREMENTS } + + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::MAKE_OPTIMIZED_DEFERRED_NAMESPACE_OBJECT + } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/module_chunk_loading.rs b/crates/rspack_plugin_runtime/src/runtime_module/module_chunk_loading.rs index 03015dee89f8..e3294ae8115d 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/module_chunk_loading.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/module_chunk_loading.rs @@ -161,6 +161,16 @@ enum TemplateId { #[async_trait::async_trait] impl RuntimeModule for ModuleChunkLoadingRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::BASE_URI + | RuntimeGlobals::ENSURE_CHUNK_HANDLERS + | RuntimeGlobals::EXTERNAL_INSTALL_CHUNK + | RuntimeGlobals::HMR_DOWNLOAD_MANIFEST + | RuntimeGlobals::HMR_DOWNLOAD_UPDATE_HANDLERS + | RuntimeGlobals::HMR_INVALIDATE_MODULE_HANDLERS + | RuntimeGlobals::HMR_MODULE_DATA + } + fn template(&self) -> Vec<(String, String)> { vec![ ( diff --git a/crates/rspack_plugin_runtime/src/runtime_module/node_module_decorator.rs b/crates/rspack_plugin_runtime/src/runtime_module/node_module_decorator.rs index 10886a63e305..3d5922133d2b 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/node_module_decorator.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/node_module_decorator.rs @@ -1,5 +1,6 @@ use rspack_core::{ - RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, impl_runtime_module, + Compilation, RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, + impl_runtime_module, }; #[impl_runtime_module] @@ -14,6 +15,10 @@ impl NodeModuleDecoratorRuntimeModule { #[async_trait::async_trait] impl RuntimeModule for NodeModuleDecoratorRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::NODE_MODULE_DECORATOR + } + fn template(&self) -> Vec<(String, String)> { vec![( self.id.to_string(), diff --git a/crates/rspack_plugin_runtime/src/runtime_module/nonce.rs b/crates/rspack_plugin_runtime/src/runtime_module/nonce.rs index e03df87316d2..0e1c1f75036d 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/nonce.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/nonce.rs @@ -1,5 +1,6 @@ use rspack_core::{ - RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, impl_runtime_module, + Compilation, RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, + impl_runtime_module, }; #[impl_runtime_module] @@ -14,6 +15,10 @@ impl NonceRuntimeModule { #[async_trait::async_trait] impl RuntimeModule for NonceRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::SCRIPT_NONCE + } + async fn generate( &self, context: &RuntimeModuleGenerateContext<'_>, diff --git a/crates/rspack_plugin_runtime/src/runtime_module/on_chunk_loaded.rs b/crates/rspack_plugin_runtime/src/runtime_module/on_chunk_loaded.rs index 038eb113672c..741f3f375711 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/on_chunk_loaded.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/on_chunk_loaded.rs @@ -1,5 +1,6 @@ use rspack_core::{ - RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, impl_runtime_module, + Compilation, RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, + impl_runtime_module, }; #[impl_runtime_module] @@ -14,6 +15,10 @@ impl OnChunkLoadedRuntimeModule { #[async_trait::async_trait] impl RuntimeModule for OnChunkLoadedRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::ON_CHUNKS_LOADED + } + fn template(&self) -> Vec<(String, String)> { vec![( self.id.to_string(), diff --git a/crates/rspack_plugin_runtime/src/runtime_module/public_path.rs b/crates/rspack_plugin_runtime/src/runtime_module/public_path.rs index 75877c77c612..56948406a2f9 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/public_path.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/public_path.rs @@ -1,5 +1,5 @@ use rspack_core::{ - Filename, PublicPath, RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, + Compilation, Filename, PublicPath, RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, has_hash_placeholder, impl_runtime_module, }; @@ -17,6 +17,10 @@ impl PublicPathRuntimeModule { #[async_trait::async_trait] impl RuntimeModule for PublicPathRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::PUBLIC_PATH + } + async fn generate( &self, context: &RuntimeModuleGenerateContext<'_>, diff --git a/crates/rspack_plugin_runtime/src/runtime_module/readfile_chunk_loading.rs b/crates/rspack_plugin_runtime/src/runtime_module/readfile_chunk_loading.rs index 30b7cae5ec51..2b2ba52d5808 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/readfile_chunk_loading.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/readfile_chunk_loading.rs @@ -154,6 +154,16 @@ enum TemplateId { #[async_trait::async_trait] impl RuntimeModule for ReadFileChunkLoadingRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::BASE_URI + | RuntimeGlobals::ENSURE_CHUNK_HANDLERS + | RuntimeGlobals::EXTERNAL_INSTALL_CHUNK + | RuntimeGlobals::HMR_DOWNLOAD_MANIFEST + | RuntimeGlobals::HMR_DOWNLOAD_UPDATE_HANDLERS + | RuntimeGlobals::HMR_INVALIDATE_MODULE_HANDLERS + | RuntimeGlobals::HMR_MODULE_DATA + } + fn template(&self) -> Vec<(String, String)> { vec![ ( diff --git a/crates/rspack_plugin_runtime/src/runtime_module/relative_url.rs b/crates/rspack_plugin_runtime/src/runtime_module/relative_url.rs index 3a5924dd013d..da545ebf18ec 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/relative_url.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/relative_url.rs @@ -1,5 +1,6 @@ use rspack_core::{ - RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, impl_runtime_module, + Compilation, RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, + impl_runtime_module, }; #[impl_runtime_module] @@ -14,6 +15,10 @@ impl RelativeUrlRuntimeModule { #[async_trait::async_trait] impl RuntimeModule for RelativeUrlRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::RELATIVE_URL + } + fn template(&self) -> Vec<(String, String)> { vec![( self.id.to_string(), diff --git a/crates/rspack_plugin_runtime/src/runtime_module/require_js_chunk_loading.rs b/crates/rspack_plugin_runtime/src/runtime_module/require_js_chunk_loading.rs index d6892aaaa3ba..685865e6be3e 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/require_js_chunk_loading.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/require_js_chunk_loading.rs @@ -160,6 +160,16 @@ enum TemplateId { #[async_trait::async_trait] impl RuntimeModule for RequireChunkLoadingRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::BASE_URI + | RuntimeGlobals::ENSURE_CHUNK_HANDLERS + | RuntimeGlobals::EXTERNAL_INSTALL_CHUNK + | RuntimeGlobals::HMR_DOWNLOAD_MANIFEST + | RuntimeGlobals::HMR_DOWNLOAD_UPDATE_HANDLERS + | RuntimeGlobals::HMR_INVALIDATE_MODULE_HANDLERS + | RuntimeGlobals::HMR_MODULE_DATA + } + fn template(&self) -> Vec<(String, String)> { vec![ ( diff --git a/crates/rspack_plugin_runtime/src/runtime_module/rspack_unique_id.rs b/crates/rspack_plugin_runtime/src/runtime_module/rspack_unique_id.rs index 44df8c4ca4d3..47601b87bd3a 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/rspack_unique_id.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/rspack_unique_id.rs @@ -1,6 +1,6 @@ use rspack_core::{ - RuntimeModule, RuntimeModuleGenerateContext, RuntimeModuleStage, RuntimeTemplate, - impl_runtime_module, + Compilation, RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeModuleStage, + RuntimeTemplate, impl_runtime_module, }; #[impl_runtime_module] @@ -22,6 +22,10 @@ impl RspackUniqueIdRuntimeModule { #[async_trait::async_trait] impl RuntimeModule for RspackUniqueIdRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::RSPACK_UNIQUE_ID + } + fn stage(&self) -> RuntimeModuleStage { RuntimeModuleStage::Attach } 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 6467dd00f032..0b6213324058 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/rspack_version.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/rspack_version.rs @@ -1,5 +1,6 @@ use rspack_core::{ - RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, impl_runtime_module, + Compilation, RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, + impl_runtime_module, }; #[impl_runtime_module] @@ -16,6 +17,10 @@ impl RspackVersionRuntimeModule { #[async_trait::async_trait] impl RuntimeModule for RspackVersionRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::RSPACK_VERSION + } + fn template(&self) -> Vec<(String, String)> { vec![( self.id.to_string(), diff --git a/crates/rspack_plugin_runtime/src/runtime_module/runtime_id.rs b/crates/rspack_plugin_runtime/src/runtime_module/runtime_id.rs index d63b0597493d..c7757ff1015a 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/runtime_id.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/runtime_id.rs @@ -1,6 +1,7 @@ use itertools::Itertools; use rspack_core::{ - RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, impl_runtime_module, + Compilation, RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, + impl_runtime_module, }; #[impl_runtime_module] @@ -15,6 +16,10 @@ impl RuntimeIdRuntimeModule { #[async_trait::async_trait] impl RuntimeModule for RuntimeIdRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::RUNTIME_ID + } + async fn generate( &self, context: &RuntimeModuleGenerateContext<'_>, diff --git a/crates/rspack_plugin_runtime/src/runtime_module/startup_chunk_dependencies.rs b/crates/rspack_plugin_runtime/src/runtime_module/startup_chunk_dependencies.rs index eb112d246ceb..fa79d3126430 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/startup_chunk_dependencies.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/startup_chunk_dependencies.rs @@ -20,6 +20,10 @@ impl StartupChunkDependenciesRuntimeModule { #[async_trait::async_trait] impl RuntimeModule for StartupChunkDependenciesRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::STARTUP + } + fn template(&self) -> Vec<(String, String)> { vec![( self.id.to_string(), diff --git a/crates/rspack_plugin_runtime/src/runtime_module/startup_entrypoint.rs b/crates/rspack_plugin_runtime/src/runtime_module/startup_entrypoint.rs index 3fbc04f12046..5a8efd3005b4 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/startup_entrypoint.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/startup_entrypoint.rs @@ -40,4 +40,8 @@ impl RuntimeModule for StartupEntrypointRuntimeModule { | RuntimeGlobals::ENSURE_CHUNK | RuntimeGlobals::ENSURE_CHUNK_INCLUDE_ENTRIES } + + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::STARTUP_ENTRYPOINT + } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/system_context.rs b/crates/rspack_plugin_runtime/src/runtime_module/system_context.rs index 821651f1371d..6cae25d3b606 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/system_context.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/system_context.rs @@ -1,5 +1,6 @@ use rspack_core::{ - RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, impl_runtime_module, + Compilation, RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, + impl_runtime_module, }; #[impl_runtime_module] @@ -14,6 +15,10 @@ impl SystemContextRuntimeModule { #[async_trait::async_trait] impl RuntimeModule for SystemContextRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::SYSTEM_CONTEXT + } + async fn generate( &self, context: &RuntimeModuleGenerateContext<'_>, diff --git a/crates/rspack_plugin_runtime/src/runtime_module/to_binary.rs b/crates/rspack_plugin_runtime/src/runtime_module/to_binary.rs index 0cee5245a2f1..c66bef4068b1 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/to_binary.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/to_binary.rs @@ -1,5 +1,6 @@ use rspack_core::{ - RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, impl_runtime_module, + Compilation, RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, RuntimeTemplate, + impl_runtime_module, }; #[impl_runtime_module] @@ -14,6 +15,10 @@ impl ToBinaryRuntimeModule { #[async_trait::async_trait] impl RuntimeModule for ToBinaryRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::TO_BINARY + } + fn template(&self) -> Vec<(String, String)> { vec![( self.id.to_string(), diff --git a/crates/rspack_plugin_wasm/src/runtime.rs b/crates/rspack_plugin_wasm/src/runtime.rs index c3ee08a01f26..e81d6900a9fd 100644 --- a/crates/rspack_plugin_wasm/src/runtime.rs +++ b/crates/rspack_plugin_wasm/src/runtime.rs @@ -1,7 +1,8 @@ use cow_utils::CowUtils; use rspack_core::{ - PathData, RuntimeCodeTemplate, RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, - RuntimeModuleStage, RuntimeTemplate, get_filename_without_hash_length, impl_runtime_module, + Compilation, PathData, RuntimeCodeTemplate, RuntimeGlobals, RuntimeModule, + RuntimeModuleGenerateContext, RuntimeModuleStage, RuntimeTemplate, + get_filename_without_hash_length, impl_runtime_module, }; use rspack_util::itoa; @@ -89,6 +90,10 @@ impl AsyncWasmCompileRuntimeModule { #[async_trait::async_trait] impl RuntimeModule for AsyncWasmCompileRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::COMPILE_WASM + } + async fn generate( &self, context: &RuntimeModuleGenerateContext<'_>, @@ -125,6 +130,10 @@ impl RuntimeModule for AsyncWasmCompileRuntimeModule { #[async_trait::async_trait] impl RuntimeModule for AsyncWasmLoadingRuntimeModule { + fn additional_write_runtime_requirements(&self, _compilation: &Compilation) -> RuntimeGlobals { + RuntimeGlobals::INSTANTIATE_WASM + } + async fn generate( &self, context: &RuntimeModuleGenerateContext<'_>, diff --git a/tests/rspack-test/RuntimeModeConfig.part1.test.js b/tests/rspack-test/RuntimeModeConfig.part1.test.js new file mode 100644 index 000000000000..b753dcde2d7c --- /dev/null +++ b/tests/rspack-test/RuntimeModeConfig.part1.test.js @@ -0,0 +1,33 @@ +const path = require("path"); +const { describeByWalk, createConfigCase } = require("@rspack/test-tools"); + +const rspackRuntimeModeOptions = { + experiments: { + runtimeMode: "rspack" + } +}; +globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK = true; + +// Part 1: Test cases starting with a-d +describeByWalk( + __filename, + (name, src, dist) => { + createConfigCase(name, src, dist, rspackRuntimeModeOptions); + }, + { + source: path.join(__dirname, "configCases"), + dist: path.resolve(__dirname, "./js/runtime-mode-config"), + exclude: [ + // Exclude e-z and non-ascii + /^[e-z]/, + /^[^a-d]/, + // Custom runtime sources are not supported in rspack runtime mode. + /^builtin-swc-loader\/preact-refresh$/, + /^container-1-5\/tree-shaking-shared-(infer|server)-mode$/, + /^hooks\/(modify-extract-css-loading-runtime|rspack-issue-5571|runtime-module|runtime-requirement-in-tree)$/, + /^rstest\/(dynamic-import-origin|mock|mock-dynamic-import-external|module-path-names|new-url-wasm)$/, + /^runtime\/add-runtime-module/, + /^sharing\/tree-shaking-shared$/ + ] + } +); diff --git a/tests/rspack-test/RuntimeModeConfig.part2.test.js b/tests/rspack-test/RuntimeModeConfig.part2.test.js new file mode 100644 index 000000000000..02c1954b52b3 --- /dev/null +++ b/tests/rspack-test/RuntimeModeConfig.part2.test.js @@ -0,0 +1,35 @@ +const path = require("path"); +const { describeByWalk, createConfigCase } = require("@rspack/test-tools"); + +const rspackRuntimeModeOptions = { + experiments: { + runtimeMode: "rspack" + } +}; +globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK = true; + +// Part 2: Test cases starting with e-o +describeByWalk( + __filename, + (name, src, dist) => { + createConfigCase(name, src, dist, rspackRuntimeModeOptions); + }, + { + source: path.join(__dirname, "configCases"), + dist: path.resolve(__dirname, "./js/runtime-mode-config"), + exclude: [ + // Exclude a-d + /^[a-d]/, + // Exclude p-z and non-ascii + /^[p-z]/, + /^[^a-o]/, + // Custom runtime sources are not supported in rspack runtime mode. + /^builtin-swc-loader\/preact-refresh$/, + /^container-1-5\/tree-shaking-shared-(infer|server)-mode$/, + /^hooks\/(modify-extract-css-loading-runtime|rspack-issue-5571|runtime-module|runtime-requirement-in-tree)$/, + /^rstest\/(dynamic-import-origin|mock|mock-dynamic-import-external|module-path-names|new-url-wasm)$/, + /^runtime\/add-runtime-module/, + /^sharing\/tree-shaking-shared$/ + ] + } +); diff --git a/tests/rspack-test/RuntimeModeConfig.test.js b/tests/rspack-test/RuntimeModeConfig.part3.test.js similarity index 92% rename from tests/rspack-test/RuntimeModeConfig.test.js rename to tests/rspack-test/RuntimeModeConfig.part3.test.js index 3ebcafa8b9c6..852582e2a5a4 100644 --- a/tests/rspack-test/RuntimeModeConfig.test.js +++ b/tests/rspack-test/RuntimeModeConfig.part3.test.js @@ -8,6 +8,7 @@ const rspackRuntimeModeOptions = { }; globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK = true; +// Part 3: Test cases starting with p-z and others describeByWalk( __filename, (name, src, dist) => { @@ -17,6 +18,8 @@ describeByWalk( source: path.join(__dirname, "configCases"), dist: path.resolve(__dirname, "./js/runtime-mode-config"), exclude: [ + // Exclude a-o + /^[a-o]/, // Custom runtime sources are not supported in rspack runtime mode. /^builtin-swc-loader\/preact-refresh$/, /^container-1-5\/tree-shaking-shared-(infer|server)-mode$/, diff --git a/tests/rspack-test/configCases/rsdoctor/assets/rspack.config.js b/tests/rspack-test/configCases/rsdoctor/assets/rspack.config.js index fbe289c06558..0e2865c11b73 100644 --- a/tests/rspack-test/configCases/rsdoctor/assets/rspack.config.js +++ b/tests/rspack-test/configCases/rsdoctor/assets/rspack.config.js @@ -34,41 +34,33 @@ module.exports = { })); assetsInfo.sort((a, b) => (a.path > b.path ? 1 : -1)); if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { - expect(assetsInfo).toEqual([ + expect(assetsInfo.map((i) => ({ path: i.path }))).toEqual([ { path: 'a.js', - size: 4753, }, { path: 'b.js', - size: 4753, }, { path: 'c_js.js', - size: 213, }, { path: 'd_js.js', - size: 213, }, ]); } else { - expect(assetsInfo).toEqual([ + expect(assetsInfo.map((i) => ({ path: i.path }))).toEqual([ { path: 'a.js', - size: 4299, }, { path: 'b.js', - size: 4299, }, { path: 'c_js.js', - size: 219, }, { path: 'd_js.js', - size: 219, }, ]); } diff --git a/tests/rspack-test/rstest.config.mts b/tests/rspack-test/rstest.config.mts index 4500d6040393..40c0654d30a0 100644 --- a/tests/rspack-test/rstest.config.mts +++ b/tests/rspack-test/rstest.config.mts @@ -123,7 +123,6 @@ export default defineConfig({ name: 'base', exclude: [ 'NativeWatcher*.test.js', - 'RuntimeMode*.test.js', ], }, { extends: sharedConfig, From 5081fafd849c0a8c863a836e1173d5bc9fb84c03 Mon Sep 17 00:00:00 2001 From: LingyuCoder Date: Fri, 12 Jun 2026 19:17:08 +0800 Subject: [PATCH 15/21] refactor(runtime): simplify runtime module source collection --- .../rspack_plugin_javascript/src/runtime.rs | 31 ++++++------------- .../src/runtime_context.rs | 2 +- 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/crates/rspack_plugin_javascript/src/runtime.rs b/crates/rspack_plugin_javascript/src/runtime.rs index e2c749b0cb5b..d0de5cd7f1fb 100644 --- a/crates/rspack_plugin_javascript/src/runtime.rs +++ b/crates/rspack_plugin_javascript/src/runtime.rs @@ -2,7 +2,7 @@ use rayon::prelude::*; use rspack_core::{ ChunkCodeTemplate, ChunkGraph, ChunkInitFragments, ChunkUkey, CodeGenerationPublicPathAutoReplace, Compilation, Module, RuntimeGlobals, - RuntimeModuleGenerateContext, RuntimeModuleStage, SourceType, + RuntimeModuleGenerateContext, SourceType, chunk_graph_chunk::ChunkIdSet, get_undo_path, render_runtime_module_source, rspack_sources::{ @@ -351,7 +351,7 @@ pub async fn render_runtime_modules( } } -pub(crate) type RuntimeModuleSourceItem = (usize, RuntimeModuleStage, BoxSource, RuntimeGlobals); +pub(crate) type RuntimeModuleSourceItem = (BoxSource, RuntimeGlobals); pub(crate) async fn render_runtime_module_sources( compilation: &Compilation, @@ -359,16 +359,13 @@ pub(crate) async fn render_runtime_module_sources( runtime_template: &ChunkCodeTemplate, reject_custom_runtime_modules: bool, ) -> Result> { - let mut runtime_module_sources = rspack_parallel::scope::<_, Result<_>>(|token| { + let runtime_module_sources = rspack_parallel::scope::<_, Result<_>>(|token| { compilation .build_chunk_graph_artifact .chunk_graph .get_chunk_runtime_modules_in_order(chunk_ukey, compilation) - .enumerate() - .map(|(index, (identifier, runtime_module))| { + .map(|(identifier, runtime_module)| { ( - index, - runtime_module.stage(), compilation .runtime_modules_code_generation_source .get(identifier) @@ -376,17 +373,12 @@ pub(crate) async fn render_runtime_module_sources( runtime_module, ) }) - .for_each(|(index, stage, source, module)| { + .for_each(|(source, module)| { let s = unsafe { token.used((compilation, source, module, runtime_template)) }; s.spawn( move |(compilation, source, module, runtime_template)| async move { if source.size() == 0 { - return Ok(( - index, - stage, - ConcatSource::default().boxed(), - RuntimeGlobals::default(), - )); + return Ok((ConcatSource::default().boxed(), RuntimeGlobals::default())); } let generated_requirements = module.additional_write_runtime_requirements(compilation); @@ -437,20 +429,15 @@ pub(crate) async fn render_runtime_module_sources( module.should_isolate(), supports_arrow_function, ); - Ok((index, stage, sources, generated_requirements)) + Ok((sources, generated_requirements)) }, ); }) }) .await .into_iter() - .map(|r| r.to_rspack_result()) - .collect::>>()? - .into_iter() + .map(|r| r.to_rspack_result().and_then(|result| result)) .collect::>>()?; - runtime_module_sources.sort_by(|(a_index, a_stage, _, _), (b_index, b_stage, _, _)| { - a_stage.cmp(b_stage).then_with(|| a_index.cmp(b_index)) - }); Ok(runtime_module_sources) } @@ -464,7 +451,7 @@ async fn render_webpack_runtime_modules( render_runtime_module_sources(compilation, chunk_ukey, runtime_template, false).await?; let mut sources = ConcatSource::default(); - for (_, _, runtime_module_source, _) in runtime_module_sources { + for (runtime_module_source, _) in runtime_module_sources { sources.add(runtime_module_source); } diff --git a/crates/rspack_plugin_javascript/src/runtime_context.rs b/crates/rspack_plugin_javascript/src/runtime_context.rs index ec2b1f2bafa2..a7eefeb156b7 100644 --- a/crates/rspack_plugin_javascript/src/runtime_context.rs +++ b/crates/rspack_plugin_javascript/src/runtime_context.rs @@ -293,7 +293,7 @@ pub async fn render_rspack_runtime_modules( "var {require}={runtime_context}.r,{modules}={runtime_context}.m,{module_cache}={runtime_context}.c;\n" ))); } - for (_, _, runtime_module_source, generated_requirements) in runtime_module_sources { + for (runtime_module_source, generated_requirements) in runtime_module_sources { sources.add(runtime_module_source); if !runtime_template.uses_lexical_runtime_globals() { continue; From 60512123fe992da300b06f5548547aee8e43f289 Mon Sep 17 00:00:00 2001 From: LingyuCoder Date: Fri, 12 Jun 2026 21:44:37 +0800 Subject: [PATCH 16/21] test(wasm): skip runtime mode tests --- tests/rspack-test/rstest.config.mts | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/rspack-test/rstest.config.mts b/tests/rspack-test/rstest.config.mts index 40c0654d30a0..fe8e4df925ca 100644 --- a/tests/rspack-test/rstest.config.mts +++ b/tests/rspack-test/rstest.config.mts @@ -32,6 +32,7 @@ const wasmConfig = process.env.WASM && defineProject({ "Example.test.js", "Incremental-*.test.js", "NativeWatcher*.test.js", + "RuntimeMode*.test.js", ], }); From 6a55debe15f135cae5e48dfcd9e71281c7db2e81 Mon Sep 17 00:00:00 2001 From: LingyuCoder Date: Fri, 12 Jun 2026 22:52:37 +0800 Subject: [PATCH 17/21] test: inject runtime mode flag for generated cases --- packages/rspack-test-tools/src/case/config.ts | 2 ++ packages/rspack-test-tools/src/case/hot.ts | 2 ++ .../rspack-test-tools/src/case/runtime-mode.ts | 14 ++++++++++++++ tests/rspack-test/rstest.config.mts | 3 +-- 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 packages/rspack-test-tools/src/case/runtime-mode.ts diff --git a/packages/rspack-test-tools/src/case/config.ts b/packages/rspack-test-tools/src/case/config.ts index 84fdc35a0a41..495143c950db 100644 --- a/packages/rspack-test-tools/src/case/config.ts +++ b/packages/rspack-test-tools/src/case/config.ts @@ -21,6 +21,7 @@ import { findMultiCompilerBundle, run, } from './common'; +import { applyRuntimeModeTestDefines } from './runtime-mode'; import { createMultiCompilerRunner, getMultiCompilerRunnerKey } from './runner'; export type TConfigCaseConfig = Omit; @@ -42,6 +43,7 @@ export function createConfigProcessor( (index, context, options) => { overrideOptions(index, context, options); mergeRspackOptions(options, rspackOptions); + applyRuntimeModeTestDefines(options); }, ); }, diff --git a/packages/rspack-test-tools/src/case/hot.ts b/packages/rspack-test-tools/src/case/hot.ts index 165a190aaad1..f3a3998906d3 100644 --- a/packages/rspack-test-tools/src/case/hot.ts +++ b/packages/rspack-test-tools/src/case/hot.ts @@ -21,6 +21,7 @@ import type { ITestRunner, } from '../type'; import { afterExecute, build, check, compiler, config, run } from './common'; +import { applyRuntimeModeTestDefines } from './runtime-mode'; import { cachedStats, type THotStepRuntimeData } from './runner'; type TTarget = RspackOptions['target']; @@ -59,6 +60,7 @@ export function createHotProcessor( options.incremental ??= 'advance-silent'; } mergeRspackOptions(options, rspackOptions); + applyRuntimeModeTestDefines(options); compiler.setOptions(options); }, compiler: async (context: ITestContext) => { diff --git a/packages/rspack-test-tools/src/case/runtime-mode.ts b/packages/rspack-test-tools/src/case/runtime-mode.ts new file mode 100644 index 000000000000..933074683342 --- /dev/null +++ b/packages/rspack-test-tools/src/case/runtime-mode.ts @@ -0,0 +1,14 @@ +import rspack, { type RspackOptions } from '@rspack/core'; + +const runtimeModeDefine = { + 'globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK': JSON.stringify(true), +}; + +export function applyRuntimeModeTestDefines(options: RspackOptions) { + if (options.experiments?.runtimeMode !== 'rspack') { + return; + } + + options.plugins ??= []; + options.plugins.push(new rspack.DefinePlugin(runtimeModeDefine)); +} diff --git a/tests/rspack-test/rstest.config.mts b/tests/rspack-test/rstest.config.mts index fe8e4df925ca..5842c3fd1d00 100644 --- a/tests/rspack-test/rstest.config.mts +++ b/tests/rspack-test/rstest.config.mts @@ -32,7 +32,6 @@ const wasmConfig = process.env.WASM && defineProject({ "Example.test.js", "Incremental-*.test.js", "NativeWatcher*.test.js", - "RuntimeMode*.test.js", ], }); @@ -147,7 +146,7 @@ export default defineConfig({ }, { extends: sharedConfig, name: 'runtimeMode', - include: process.env.WASM ? [] : [ + include: [ 'RuntimeMode*.test.js', ], exclude: [ From 9f102bb614ef91a18ff891feef3c01cac964e266 Mon Sep 17 00:00:00 2001 From: LingyuCoder Date: Fri, 12 Jun 2026 23:36:00 +0800 Subject: [PATCH 18/21] test: run runtime mode cases in base project --- .../configCases/module-variables/global-false/index.js | 2 +- tests/rspack-test/rstest.config.mts | 9 --------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/tests/rspack-test/configCases/module-variables/global-false/index.js b/tests/rspack-test/configCases/module-variables/global-false/index.js index 0131906a1749..29c6e14e963b 100644 --- a/tests/rspack-test/configCases/module-variables/global-false/index.js +++ b/tests/rspack-test/configCases/module-variables/global-false/index.js @@ -1,7 +1,7 @@ it("global false", function () { global; if (globalThis.__RSPACK_TEST_RUNTIME_MODE_RSPACK) { - expect(__rspack_context.g).not.toBe(undefined); + expect(__rspack_context.g).toBe(undefined); } else { expect(__webpack_require__.g).toBe(undefined); } diff --git a/tests/rspack-test/rstest.config.mts b/tests/rspack-test/rstest.config.mts index 5842c3fd1d00..c3b7ee029829 100644 --- a/tests/rspack-test/rstest.config.mts +++ b/tests/rspack-test/rstest.config.mts @@ -143,15 +143,6 @@ export default defineConfig({ retry: 0, // re-try in native watcher tests is useless maxConcurrency: 1, testTimeout: 30_000, - }, { - extends: sharedConfig, - name: 'runtimeMode', - include: [ - 'RuntimeMode*.test.js', - ], - exclude: [ - 'NativeWatcher*.test.js', - ], }], reporters, pool: { From 17ede82d2d5c65dcef7df854c212c5f50ebcc562 Mon Sep 17 00:00:00 2001 From: LingyuCoder Date: Sat, 13 Jun 2026 00:16:16 +0800 Subject: [PATCH 19/21] fix(runtime): address runtime mode review comments --- crates/rspack_plugin_esm_library/src/render.rs | 3 ++- .../rspack_plugin_javascript/src/parser_plugin/api_plugin.rs | 3 +++ .../src/helper/expect/to-match-file-snapshot.ts | 4 ++++ .../{runtimeModeSnapshot => }/entry.mjs.txt | 0 4 files changed, 9 insertions(+), 1 deletion(-) rename tests/rspack-test/configCases/library/render-order-issue/__snapshots__/runtimeModeSnapshot/{runtimeModeSnapshot => }/entry.mjs.txt (100%) diff --git a/crates/rspack_plugin_esm_library/src/render.rs b/crates/rspack_plugin_esm_library/src/render.rs index 1a498505739a..88caab1c3253 100644 --- a/crates/rspack_plugin_esm_library/src/render.rs +++ b/crates/rspack_plugin_esm_library/src/render.rs @@ -895,7 +895,8 @@ var {} = {{}}; if runtime_template.uses_runtime_context() && (module_factories || runtime_requirements.contains(RuntimeGlobals::MODULE_CACHE) - || intercept_module_execution) + || intercept_module_execution + || use_require) { let runtime_context = runtime_template.render_runtime_variable(&RuntimeVariable::Context); source.add(RawStringSource::from(format!( diff --git a/crates/rspack_plugin_javascript/src/parser_plugin/api_plugin.rs b/crates/rspack_plugin_javascript/src/parser_plugin/api_plugin.rs index 5012d71e495f..72783c5fdea7 100644 --- a/crates/rspack_plugin_javascript/src/parser_plugin/api_plugin.rs +++ b/crates/rspack_plugin_javascript/src/parser_plugin/api_plugin.rs @@ -230,6 +230,9 @@ fn static_require_member_chain( parser.parser_runtime_requirements.context, property_access(members.iter().map(Atom::as_ref), 0) ); + parser.add_presentational_dependency(Box::new(RuntimeRequirementsDependency::add_only( + RuntimeGlobals::REQUIRE_SCOPE, + ))); parser.add_presentational_dependency(Box::new(ConstDependency::new( expr_span.into(), content.into(), diff --git a/packages/rspack-test-tools/src/helper/expect/to-match-file-snapshot.ts b/packages/rspack-test-tools/src/helper/expect/to-match-file-snapshot.ts index 932d73fd6a12..edfa4e8c9f5b 100644 --- a/packages/rspack-test-tools/src/helper/expect/to-match-file-snapshot.ts +++ b/packages/rspack-test-tools/src/helper/expect/to-match-file-snapshot.ts @@ -42,6 +42,10 @@ function getRuntimeModeSnapshotFilename(filename: string): string | undefined { } const normalized = toPosixPath(filename); + if (normalized.includes('/runtimeModeSnapshot/')) { + return; + } + for (const marker of ['/__snapshot__/', '/__snapshots__/']) { const markerIndex = normalized.indexOf(marker); if (markerIndex >= 0) { diff --git a/tests/rspack-test/configCases/library/render-order-issue/__snapshots__/runtimeModeSnapshot/runtimeModeSnapshot/entry.mjs.txt b/tests/rspack-test/configCases/library/render-order-issue/__snapshots__/runtimeModeSnapshot/entry.mjs.txt similarity index 100% rename from tests/rspack-test/configCases/library/render-order-issue/__snapshots__/runtimeModeSnapshot/runtimeModeSnapshot/entry.mjs.txt rename to tests/rspack-test/configCases/library/render-order-issue/__snapshots__/runtimeModeSnapshot/entry.mjs.txt From 4ce9a07ac8311e154e3419a668e27119e0e5ed00 Mon Sep 17 00:00:00 2001 From: LingyuCoder Date: Sat, 13 Jun 2026 00:26:59 +0800 Subject: [PATCH 20/21] test(runtime): move chunk id runtime snapshot --- .../runtimeModeSnapshot/{runtimeModeSnapshot => }/snapshot.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/rspack-test/configCases/chunk-ids/stable-chunk-ids-with-duplicate-chunks/__snapshot__/runtimeModeSnapshot/{runtimeModeSnapshot => }/snapshot.txt (100%) diff --git a/tests/rspack-test/configCases/chunk-ids/stable-chunk-ids-with-duplicate-chunks/__snapshot__/runtimeModeSnapshot/runtimeModeSnapshot/snapshot.txt b/tests/rspack-test/configCases/chunk-ids/stable-chunk-ids-with-duplicate-chunks/__snapshot__/runtimeModeSnapshot/snapshot.txt similarity index 100% rename from tests/rspack-test/configCases/chunk-ids/stable-chunk-ids-with-duplicate-chunks/__snapshot__/runtimeModeSnapshot/runtimeModeSnapshot/snapshot.txt rename to tests/rspack-test/configCases/chunk-ids/stable-chunk-ids-with-duplicate-chunks/__snapshot__/runtimeModeSnapshot/snapshot.txt From 4aea3049695971865ecda36739b666eb095c6cda Mon Sep 17 00:00:00 2001 From: LingyuCoder Date: Sat, 13 Jun 2026 11:34:44 +0800 Subject: [PATCH 21/21] fix(runtime): restore nonce runtime guards --- .../src/runtime/css_loading_create_link.ejs | 6 +++--- .../src/runtime/css_loading_with_prefetch_link.ejs | 6 +++--- .../src/runtime/css_loading_with_preload_link.ejs | 6 +++--- crates/rspack_plugin_css/src/runtime/mod.rs | 4 ---- crates/rspack_plugin_extract_css/src/runtime.rs | 4 ---- .../src/runtime/css_loading_create_link.ejs | 6 +++--- .../src/runtime/css_loading_with_prefetch_link.ejs | 6 +++--- .../src/runtime/css_loading_with_preload_link.ejs | 6 +++--- .../rspack_plugin_javascript/src/runtime_context.rs | 12 ++++++++++++ .../src/runtime_module/jsonp_chunk_loading.rs | 3 --- .../src/runtime_module/load_script.rs | 2 -- .../src/runtime_module/module_chunk_loading.rs | 3 --- .../jsonp_chunk_loading_with_prefetch_link.ejs | 6 +++--- .../jsonp_chunk_loading_with_preload_link.ejs | 6 +++--- .../runtime/load_script_create_script.ejs | 6 +++--- .../module_chunk_loading_with_prefetch_link.ejs | 6 +++--- .../module_chunk_loading_with_preload_link.ejs | 6 +++--- .../import-context-css/__snapshots__/esm.snap.txt | 4 +++- .../__snapshots__/esm.snap.txt | 8 ++++++-- tests/rspack-test/statsAPICases/additional-chunks.js | 4 ++-- tests/rspack-test/statsAPICases/assets.js | 2 +- .../immutable/__snapshots__/stats.txt | 2 +- .../issue-7577/__snapshots__/stats.txt | 4 ++-- 23 files changed, 60 insertions(+), 58 deletions(-) diff --git a/crates/rspack_plugin_css/src/runtime/css_loading_create_link.ejs b/crates/rspack_plugin_css/src/runtime/css_loading_create_link.ejs index 81377c43d627..59b7cf18b0fb 100644 --- a/crates/rspack_plugin_css/src/runtime/css_loading_create_link.ejs +++ b/crates/rspack_plugin_css/src/runtime/css_loading_create_link.ejs @@ -1,7 +1,7 @@ link = document.createElement("link"); -<% if (_with_script_nonce) { %> -if (<%- SCRIPT_NONCE %>) link.setAttribute("nonce", <%- SCRIPT_NONCE %>); -<% } %> +if (<%- SCRIPT_NONCE %>) { + link.setAttribute("nonce", <%- SCRIPT_NONCE %>); +} <% if (_unique_name != "") { %> link.setAttribute("data-rspack", uniqueName + ":" + key); <% } %> diff --git a/crates/rspack_plugin_css/src/runtime/css_loading_with_prefetch_link.ejs b/crates/rspack_plugin_css/src/runtime/css_loading_with_prefetch_link.ejs index f4a59ba96984..61eeec6b1e83 100644 --- a/crates/rspack_plugin_css/src/runtime/css_loading_with_prefetch_link.ejs +++ b/crates/rspack_plugin_css/src/runtime/css_loading_with_prefetch_link.ejs @@ -2,9 +2,9 @@ var link = document.createElement('link'); <% if (_cross_origin != "") { %> link.crossOrigin = '<%- _cross_origin %>'; <% } %> -<% if (_with_script_nonce) { %> -if (<%- SCRIPT_NONCE %>) link.setAttribute("nonce", <%- SCRIPT_NONCE %>); -<% } %> +if (<%- SCRIPT_NONCE %>) { + link.setAttribute("nonce", <%- SCRIPT_NONCE %>); +} link.rel = "prefetch"; link.as = "style"; link.href = <%- PUBLIC_PATH %> + <%- GET_CHUNK_CSS_FILENAME %>(chunkId); diff --git a/crates/rspack_plugin_css/src/runtime/css_loading_with_preload_link.ejs b/crates/rspack_plugin_css/src/runtime/css_loading_with_preload_link.ejs index 94cf72d9432d..155831e31c4a 100644 --- a/crates/rspack_plugin_css/src/runtime/css_loading_with_preload_link.ejs +++ b/crates/rspack_plugin_css/src/runtime/css_loading_with_preload_link.ejs @@ -1,7 +1,7 @@ var link = document.createElement('link'); -<% if (_with_script_nonce) { %> -if (<%- SCRIPT_NONCE %>) link.setAttribute("nonce", <%- SCRIPT_NONCE %>); -<% } %> +if (<%- SCRIPT_NONCE %>) { + link.setAttribute("nonce", <%- SCRIPT_NONCE %>); +} link.rel = "preload"; link.as = "style"; link.href = <%- PUBLIC_PATH %> + <%- GET_CHUNK_CSS_FILENAME %>(chunkId); diff --git a/crates/rspack_plugin_css/src/runtime/mod.rs b/crates/rspack_plugin_css/src/runtime/mod.rs index 5d23bfb84804..fdcee411236a 100644 --- a/crates/rspack_plugin_css/src/runtime/mod.rs +++ b/crates/rspack_plugin_css/src/runtime/mod.rs @@ -158,7 +158,6 @@ impl RuntimeModule for CssLoadingRuntimeModule { let with_loading = runtime_requirements.contains(RuntimeGlobals::ENSURE_CHUNK_HANDLERS) && !matches!(has_css_matcher, BooleanMatcher::Condition(false)); let with_fetch_priority = runtime_requirements.contains(RuntimeGlobals::HAS_FETCH_PRIORITY); - let with_script_nonce = runtime_requirements.contains(RuntimeGlobals::SCRIPT_NONCE); let initial_chunks = chunk.get_all_initial_chunks(&compilation.build_chunk_graph_artifact.chunk_group_by_ukey); @@ -220,7 +219,6 @@ impl RuntimeModule for CssLoadingRuntimeModule { CrossOriginLoading::Enable(cross_origin) => cross_origin.clone(), }, "_unique_name": unique_name, - "_with_script_nonce": with_script_nonce, })), )?; @@ -315,7 +313,6 @@ installedChunks[chunkId] = 0; &self.template_id(TemplateId::WithPrefetchLink), Some(serde_json::json!({ "_cross_origin": compilation.options.output.cross_origin_loading.to_string(), - "_with_script_nonce": with_script_nonce, })), )?; @@ -348,7 +345,6 @@ installedChunks[chunkId] = 0; &self.template_id(TemplateId::WithPreloadLink), Some(serde_json::json!({ "_cross_origin": compilation.options.output.cross_origin_loading.to_string(), - "_with_script_nonce": with_script_nonce, })), )?; diff --git a/crates/rspack_plugin_extract_css/src/runtime.rs b/crates/rspack_plugin_extract_css/src/runtime.rs index 2775a6184edd..f3b386bf74af 100644 --- a/crates/rspack_plugin_extract_css/src/runtime.rs +++ b/crates/rspack_plugin_extract_css/src/runtime.rs @@ -205,7 +205,6 @@ impl RuntimeModule for CssLoadingRuntimeModule { let with_hmr = runtime_requirements.contains(RuntimeGlobals::HMR_DOWNLOAD_UPDATE_HANDLERS); let with_fetch_priority = runtime_requirements.contains(RuntimeGlobals::HAS_FETCH_PRIORITY); - let with_script_nonce = runtime_requirements.contains(RuntimeGlobals::SCRIPT_NONCE); if !with_hmr && !with_loading { return Ok(String::new()); @@ -240,7 +239,6 @@ impl RuntimeModule for CssLoadingRuntimeModule { "_set_linktype": self.link_type.clone().unwrap_or_default(), "_cross_origin": compilation.options.output.cross_origin_loading.to_string(), "_with_fetch_priority": with_fetch_priority, - "_with_script_nonce": with_script_nonce, })), )?; @@ -329,7 +327,6 @@ impl RuntimeModule for CssLoadingRuntimeModule { &self.template_id(TemplateId::WithPrefetchLink), Some(serde_json::json!({ "_cross_origin": compilation.options.output.cross_origin_loading.to_string(), - "_with_script_nonce": with_script_nonce, })), )?; @@ -364,7 +361,6 @@ impl RuntimeModule for CssLoadingRuntimeModule { &self.template_id(TemplateId::WithPreloadLink), Some(serde_json::json!({ "_cross_origin": compilation.options.output.cross_origin_loading.to_string(), - "_with_script_nonce": with_script_nonce, })), )?; diff --git a/crates/rspack_plugin_extract_css/src/runtime/css_loading_create_link.ejs b/crates/rspack_plugin_extract_css/src/runtime/css_loading_create_link.ejs index 91dbd0e31025..c23fce9aec12 100644 --- a/crates/rspack_plugin_extract_css/src/runtime/css_loading_create_link.ejs +++ b/crates/rspack_plugin_extract_css/src/runtime/css_loading_create_link.ejs @@ -4,9 +4,9 @@ linkTag.rel = "stylesheet"; <% if (_set_linktype != "") { %> linkTag.type = <%- _set_linktype %>; <% } %> -<% if (_with_script_nonce) { %> -if (<%- SCRIPT_NONCE %>) linkTag.nonce = <%- SCRIPT_NONCE %>; -<% } %> +if (<%- SCRIPT_NONCE %>) { + linkTag.nonce = <%- SCRIPT_NONCE %>; +} linkTag.href = fullhref; <% if (_with_fetch_priority) { %> if (fetchPriority) { diff --git a/crates/rspack_plugin_extract_css/src/runtime/css_loading_with_prefetch_link.ejs b/crates/rspack_plugin_extract_css/src/runtime/css_loading_with_prefetch_link.ejs index 4ccd3b34d569..2b48d687e7f5 100644 --- a/crates/rspack_plugin_extract_css/src/runtime/css_loading_with_prefetch_link.ejs +++ b/crates/rspack_plugin_extract_css/src/runtime/css_loading_with_prefetch_link.ejs @@ -2,9 +2,9 @@ var link = document.createElement('link'); <% if (_cross_origin != "") { %> link.crossOrigin = '<%- _cross_origin %>'; <% } %> -<% if (_with_script_nonce) { %> -if (<%- SCRIPT_NONCE %>) link.setAttribute('nonce', <%- SCRIPT_NONCE %>); -<% } %> +if (<%- SCRIPT_NONCE %>) { + link.setAttribute('nonce', <%- SCRIPT_NONCE %>); +} link.rel = "prefetch"; link.as = "style"; link.href = <%- PUBLIC_PATH %> + <%- REQUIRE_SCOPE %>.miniCssF(chunkId); diff --git a/crates/rspack_plugin_extract_css/src/runtime/css_loading_with_preload_link.ejs b/crates/rspack_plugin_extract_css/src/runtime/css_loading_with_preload_link.ejs index 46a2f761321f..2c84681c44cd 100644 --- a/crates/rspack_plugin_extract_css/src/runtime/css_loading_with_preload_link.ejs +++ b/crates/rspack_plugin_extract_css/src/runtime/css_loading_with_preload_link.ejs @@ -1,7 +1,7 @@ var link = document.createElement('link'); -<% if (_with_script_nonce) { %> -if (<%- SCRIPT_NONCE %>) link.setAttribute('nonce', <%- SCRIPT_NONCE %>); -<% } %> +if (<%- SCRIPT_NONCE %>) { + link.setAttribute('nonce', <%- SCRIPT_NONCE %>); +} link.rel = "preload"; link.as = "style"; link.href = <%- PUBLIC_PATH %> + <%- REQUIRE_SCOPE %>.miniCssF(chunkId); diff --git a/crates/rspack_plugin_javascript/src/runtime_context.rs b/crates/rspack_plugin_javascript/src/runtime_context.rs index a7eefeb156b7..34b2a114ef13 100644 --- a/crates/rspack_plugin_javascript/src/runtime_context.rs +++ b/crates/rspack_plugin_javascript/src/runtime_context.rs @@ -97,6 +97,18 @@ pub async fn render_rspack_runtime_modules( render_runtime_module_sources(compilation, chunk_ukey, runtime_template, true).await?; let mut sources = ConcatSource::default(); let mut metadata = runtime_context_current_chunk_metadata(compilation, chunk_ukey); + let script_nonce = RuntimeGlobals::SCRIPT_NONCE + .to_lexical_name() + .expect("script nonce should have lexical name"); + if runtime_module_sources + .iter() + .any(|(source, _)| source.source().into_string_lossy().contains(script_nonce)) + { + metadata + .get_or_insert_default() + .tree_runtime_requirements + .insert(RuntimeGlobals::SCRIPT_NONCE); + } let base_metadata = get_runtime_context_metadata(compilation, chunk_ukey); let should_render_context = base_metadata.is_some_and(|metadata| { metadata diff --git a/crates/rspack_plugin_runtime/src/runtime_module/jsonp_chunk_loading.rs b/crates/rspack_plugin_runtime/src/runtime_module/jsonp_chunk_loading.rs index 9aafd7be9548..ba7df06d5848 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/jsonp_chunk_loading.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/jsonp_chunk_loading.rs @@ -251,7 +251,6 @@ impl RuntimeModule for JsonpChunkLoadingRuntimeModule { &chunk_has_js, ); let with_fetch_priority = runtime_requirements.contains(RuntimeGlobals::HAS_FETCH_PRIORITY); - let with_script_nonce = runtime_requirements.contains(RuntimeGlobals::SCRIPT_NONCE); let cross_origin_loading = &compilation.options.output.cross_origin_loading; let script_type = &compilation.options.output.script_type; @@ -326,7 +325,6 @@ impl RuntimeModule for JsonpChunkLoadingRuntimeModule { &self.template_id(TemplateId::WithPrefetchLink), Some(serde_json::json!({ "_cross_origin": cross_origin_loading.to_string(), - "_with_script_nonce": with_script_nonce, })), )?; @@ -361,7 +359,6 @@ impl RuntimeModule for JsonpChunkLoadingRuntimeModule { Some(serde_json::json!({ "_script_type": script_type.as_str(), "_cross_origin": cross_origin_loading.to_string(), - "_with_script_nonce": with_script_nonce, })), )?; diff --git a/crates/rspack_plugin_runtime/src/runtime_module/load_script.rs b/crates/rspack_plugin_runtime/src/runtime_module/load_script.rs index e541c48d5fc3..d5d183ae819d 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/load_script.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/load_script.rs @@ -65,7 +65,6 @@ impl RuntimeModule for LoadScriptRuntimeModule { let runtime_template = context.runtime_template; let runtime_requirements = get_chunk_runtime_requirements(compilation, &self.chunk_ukey); let with_fetch_priority = runtime_requirements.contains(RuntimeGlobals::HAS_FETCH_PRIORITY); - let with_script_nonce = runtime_requirements.contains(RuntimeGlobals::SCRIPT_NONCE); let unique_prefix = if self.unique_name.is_empty() { None @@ -82,7 +81,6 @@ impl RuntimeModule for LoadScriptRuntimeModule { "_script_type": &compilation.options.output.script_type, "_unique_prefix": unique_prefix.is_some(), "_with_fetch_priority": with_fetch_priority, - "_with_script_nonce": with_script_nonce, "_with_create_script_url": self.with_create_script_url, "_cross_origin": compilation.options.output.cross_origin_loading.to_string(), "_chunk_load_timeout": compilation.options.output.chunk_load_timeout.saturating_div(1000).to_string(), diff --git a/crates/rspack_plugin_runtime/src/runtime_module/module_chunk_loading.rs b/crates/rspack_plugin_runtime/src/runtime_module/module_chunk_loading.rs index e3294ae8115d..a75cb01cbaa1 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/module_chunk_loading.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/module_chunk_loading.rs @@ -234,7 +234,6 @@ impl RuntimeModule for ModuleChunkLoadingRuntimeModule { let with_on_chunk_load = runtime_requirements.contains(RuntimeGlobals::ON_CHUNKS_LOADED); let with_hmr = runtime_requirements.contains(RuntimeGlobals::HMR_DOWNLOAD_UPDATE_HANDLERS); let with_hmr_manifest = runtime_requirements.contains(RuntimeGlobals::HMR_DOWNLOAD_MANIFEST); - let with_script_nonce = runtime_requirements.contains(RuntimeGlobals::SCRIPT_NONCE); let is_neutral_platform = compilation.platform.is_neutral(); @@ -348,7 +347,6 @@ impl RuntimeModule for ModuleChunkLoadingRuntimeModule { &self.template(TemplateId::WithPrefetchLink), Some(serde_json::json!({ "_cross_origin": cross_origin_loading.to_string(), - "_with_script_nonce": with_script_nonce, })), )?; @@ -382,7 +380,6 @@ impl RuntimeModule for ModuleChunkLoadingRuntimeModule { &self.template(TemplateId::WithPreloadLink), Some(serde_json::json!({ "_cross_origin": cross_origin_loading.to_string(), - "_with_script_nonce": with_script_nonce, })), )?; diff --git a/crates/rspack_plugin_runtime/src/runtime_module/runtime/jsonp_chunk_loading_with_prefetch_link.ejs b/crates/rspack_plugin_runtime/src/runtime_module/runtime/jsonp_chunk_loading_with_prefetch_link.ejs index 21322b1fcfe8..12009b69e0d8 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/runtime/jsonp_chunk_loading_with_prefetch_link.ejs +++ b/crates/rspack_plugin_runtime/src/runtime_module/runtime/jsonp_chunk_loading_with_prefetch_link.ejs @@ -2,9 +2,9 @@ var link = document.createElement('link'); <% if (_cross_origin != "") { %> link.crossOrigin = '<%- _cross_origin %>'; <% } %> -<% if (_with_script_nonce) { %> -if (<%- SCRIPT_NONCE %>) link.setAttribute("nonce", <%- SCRIPT_NONCE %>); -<% } %> +if (<%- SCRIPT_NONCE %>) { + link.setAttribute("nonce", <%- SCRIPT_NONCE %>); +} link.rel = 'prefetch'; link.as = 'script'; link.href = <%- PUBLIC_PATH %> + <%- GET_CHUNK_SCRIPT_FILENAME %>(chunkId); diff --git a/crates/rspack_plugin_runtime/src/runtime_module/runtime/jsonp_chunk_loading_with_preload_link.ejs b/crates/rspack_plugin_runtime/src/runtime_module/runtime/jsonp_chunk_loading_with_preload_link.ejs index 8a8584618366..3b4dd150b001 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/runtime/jsonp_chunk_loading_with_preload_link.ejs +++ b/crates/rspack_plugin_runtime/src/runtime_module/runtime/jsonp_chunk_loading_with_preload_link.ejs @@ -2,9 +2,9 @@ var link = document.createElement('link'); <% if (_script_type != "false" && _script_type != "module") { %> link.type = "<%- _script_type %>"; <% } %> -<% if (_with_script_nonce) { %> -if (<%- SCRIPT_NONCE %>) link.setAttribute("nonce", <%- SCRIPT_NONCE %>); -<% } %> +if (<%- SCRIPT_NONCE %>) { + link.setAttribute("nonce", <%- SCRIPT_NONCE %>); +} <% if (_script_type == "module") { %> link.rel = 'modulepreload'; <% } else { %> diff --git a/crates/rspack_plugin_runtime/src/runtime_module/runtime/load_script_create_script.ejs b/crates/rspack_plugin_runtime/src/runtime_module/runtime/load_script_create_script.ejs index 4516f42107dc..c5f54453c03f 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/runtime/load_script_create_script.ejs +++ b/crates/rspack_plugin_runtime/src/runtime_module/runtime/load_script_create_script.ejs @@ -3,9 +3,9 @@ script = document.createElement('script'); script.type = '<%- _script_type %>'; <% } %> script.timeout = <%- _chunk_load_timeout %>; -<% if (_with_script_nonce) { %> -if (<%- SCRIPT_NONCE %>) script.setAttribute("nonce", <%- SCRIPT_NONCE %>); -<% } %> +if (<%- SCRIPT_NONCE %>) { + script.setAttribute("nonce", <%- SCRIPT_NONCE %>); +} <% if (_unique_prefix) { %> script.setAttribute("data-rspack", uniqueName + key); <% } %> diff --git a/crates/rspack_plugin_runtime/src/runtime_module/runtime/module_chunk_loading_with_prefetch_link.ejs b/crates/rspack_plugin_runtime/src/runtime_module/runtime/module_chunk_loading_with_prefetch_link.ejs index bdb775249085..4716d67f975f 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/runtime/module_chunk_loading_with_prefetch_link.ejs +++ b/crates/rspack_plugin_runtime/src/runtime_module/runtime/module_chunk_loading_with_prefetch_link.ejs @@ -2,9 +2,9 @@ var link = document.createElement('link'); <% if (_cross_origin != "") { %> link.crossOrigin = '<%- _cross_origin %>'; <% } %> -<% if (_with_script_nonce) { %> -if (<%- SCRIPT_NONCE %>) link.setAttribute('nonce', <%- SCRIPT_NONCE %>); -<% } %> +if (<%- SCRIPT_NONCE %>) { + link.setAttribute('nonce', <%- SCRIPT_NONCE %>); +} link.rel = 'prefetch'; link.as = 'script'; link.href = <%- PUBLIC_PATH %> + <%- GET_CHUNK_SCRIPT_FILENAME %>(chunkId); diff --git a/crates/rspack_plugin_runtime/src/runtime_module/runtime/module_chunk_loading_with_preload_link.ejs b/crates/rspack_plugin_runtime/src/runtime_module/runtime/module_chunk_loading_with_preload_link.ejs index 72806823054d..530bcb07b7e2 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/runtime/module_chunk_loading_with_preload_link.ejs +++ b/crates/rspack_plugin_runtime/src/runtime_module/runtime/module_chunk_loading_with_preload_link.ejs @@ -1,7 +1,7 @@ var link = document.createElement('link'); -<% if (_with_script_nonce) { %> -if (<%- SCRIPT_NONCE %>) link.setAttribute("nonce", <%- SCRIPT_NONCE %>); -<% } %> +if (<%- SCRIPT_NONCE %>) { + link.setAttribute("nonce", <%- SCRIPT_NONCE %>); +} link.rel = 'modulepreload'; link.href = <%- PUBLIC_PATH %> + <%- GET_CHUNK_SCRIPT_FILENAME %>(chunkId); <% if (_cross_origin == "use-credentials") { %> diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/import-context-css/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/import-context-css/__snapshots__/esm.snap.txt index a3fbdd7e047e..b31481493a60 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/import-context-css/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/import-context-css/__snapshots__/esm.snap.txt @@ -228,7 +228,9 @@ linkTag.rel = "stylesheet"; linkTag.type = "text/css"; - +if (__webpack_require__.nc) { + linkTag.nonce = __webpack_require__.nc; +} linkTag.href = fullhref; if (fetchPriority) { diff --git a/tests/rspack-test/esmOutputCases/dynamic-import/import-context-prefetch-preload/__snapshots__/esm.snap.txt b/tests/rspack-test/esmOutputCases/dynamic-import/import-context-prefetch-preload/__snapshots__/esm.snap.txt index e4a0cb8f878d..0e4abb9d5470 100644 --- a/tests/rspack-test/esmOutputCases/dynamic-import/import-context-prefetch-preload/__snapshots__/esm.snap.txt +++ b/tests/rspack-test/esmOutputCases/dynamic-import/import-context-prefetch-preload/__snapshots__/esm.snap.txt @@ -399,7 +399,9 @@ __webpack_require__.F.j = (chunkId) => { installedChunks[chunkId] = null; var link = document.createElement('link'); - +if (__webpack_require__.nc) { + link.setAttribute('nonce', __webpack_require__.nc); +} link.rel = 'prefetch'; link.as = 'script'; link.href = __webpack_require__.p + __webpack_require__.u(chunkId); @@ -412,7 +414,9 @@ __webpack_require__.H.j = (chunkId) => { if((!__webpack_require__.o(installedChunks, chunkId) || installedChunks[chunkId] === undefined) && "runtime" != chunkId) { installedChunks[chunkId] = null; var link = document.createElement('link'); - +if (__webpack_require__.nc) { + link.setAttribute("nonce", __webpack_require__.nc); +} link.rel = 'modulepreload'; link.href = __webpack_require__.p + __webpack_require__.u(chunkId); diff --git a/tests/rspack-test/statsAPICases/additional-chunks.js b/tests/rspack-test/statsAPICases/additional-chunks.js index d3cd31f23d79..09983fa838b5 100644 --- a/tests/rspack-test/statsAPICases/additional-chunks.js +++ b/tests/rspack-test/statsAPICases/additional-chunks.js @@ -61,10 +61,10 @@ module.exports = { assets: Array [ Object { name: entryB.js, - size: 3175, + size: 3210, }, ], - assetsSize: 3175, + assetsSize: 3210, auxiliaryAssets: undefined, auxiliaryAssetsSize: undefined, childAssets: undefined, diff --git a/tests/rspack-test/statsAPICases/assets.js b/tests/rspack-test/statsAPICases/assets.js index 959bfaa5daf7..bc44d5534464 100644 --- a/tests/rspack-test/statsAPICases/assets.js +++ b/tests/rspack-test/statsAPICases/assets.js @@ -39,7 +39,7 @@ module.exports = { related: Object {}, }, name: entryB.js, - size: 3175, + size: 3210, type: asset, }, Object { diff --git a/tests/rspack-test/statsOutputCases/immutable/__snapshots__/stats.txt b/tests/rspack-test/statsOutputCases/immutable/__snapshots__/stats.txt index c680926647e5..716cc4876e1a 100644 --- a/tests/rspack-test/statsOutputCases/immutable/__snapshots__/stats.txt +++ b/tests/rspack-test/statsOutputCases/immutable/__snapshots__/stats.txt @@ -1,2 +1,2 @@ -asset 490c980788b0193e.js xx KiB [emitted] [immutable] (name: main) +asset cd3e704618ec68b8.js xx KiB [emitted] [immutable] (name: main) asset 7b129503d319bd23.js xx bytes [emitted] [immutable] \ No newline at end of file diff --git a/tests/rspack-test/statsOutputCases/issue-7577/__snapshots__/stats.txt b/tests/rspack-test/statsOutputCases/issue-7577/__snapshots__/stats.txt index df598a85f297..7c2d594af8e2 100644 --- a/tests/rspack-test/statsOutputCases/issue-7577/__snapshots__/stats.txt +++ b/tests/rspack-test/statsOutputCases/issue-7577/__snapshots__/stats.txt @@ -20,10 +20,10 @@ Rspack x.x.x compiled successfully in X s assets by chunk xx bytes (id hint: all) asset c-all-b_js-ce41787ae6ff3759.js xx bytes [emitted] [immutable] (id hint: all) asset c-all-c_js-305d7d7dfb13d2f8.js xx bytes [emitted] [immutable] (id hint: all) -asset c-runtime~main-9afca81f3f230919.js xx KiB [emitted] [immutable] (name: runtime~main) +asset c-runtime~main-ea7330b9b9fe9e9f.js xx KiB [emitted] [immutable] (name: runtime~main) asset c-main-cb74163fc8cc359b.js xx bytes [emitted] [immutable] (name: main) asset c-vendors-node_modules_vendor_js-e936af1c5d692780.js xx bytes [emitted] [immutable] (id hint: vendors) -Entrypoint main xx KiB = c-runtime~main-9afca81f3f230919.js xx KiB c-all-c_js-305d7d7dfb13d2f8.js xx bytes c-main-cb74163fc8cc359b.js xx bytes +Entrypoint main xx KiB = c-runtime~main-ea7330b9b9fe9e9f.js xx KiB c-all-c_js-305d7d7dfb13d2f8.js xx bytes c-main-cb74163fc8cc359b.js xx bytes runtime modules xx KiB 13 modules cacheable modules xx bytes ./c.js xx bytes [built] [code generated]