Skip to content

Commit

Permalink
chore: update webpack 5.97.1 (#9340)
Browse files Browse the repository at this point in the history
* chore: bump webpack 5.97.1

* fix: use rspack ignore plugin

* chore: ⬆️ update pnpm-lock

* feat: align async node with webpack

* fix: walkaround tsc error

* fix: option builder error

* feat:  align webpack module chunk loader

* chore: ⬆️ update pnpm-lock

* feat: add wrong wasm loading type error message

* test: update plugin-test snapshot

* fix: style unstable

* refactor: remove dead code

* refactor: todo -> unreachable

Co-authored-by: JSerFeng
  • Loading branch information
stormslowly authored Feb 18, 2025
1 parent 4df2004 commit 6f7a16d
Show file tree
Hide file tree
Showing 55 changed files with 686 additions and 528 deletions.
6 changes: 1 addition & 5 deletions crates/rspack/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2926,11 +2926,7 @@ impl OutputOptionsBuilder {
if tp.fetch_wasm() {
WasmLoading::Enable(WasmLoadingType::Fetch)
} else if tp.node_builtins() {
if output_module {
WasmLoading::Enable(WasmLoadingType::AsyncNodeModule)
} else {
WasmLoading::Enable(WasmLoadingType::AsyncNode)
}
WasmLoading::Enable(WasmLoadingType::AsyncNode)
} else {
WasmLoading::Disable
}
Expand Down
8 changes: 4 additions & 4 deletions crates/rspack_core/src/build_chunk_graph/code_splitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -869,16 +869,16 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on

let mut visited = IdentifierIndexSet::default();

let mut ctx = (0, 0, Default::default());
for root in roots {
let mut ctx = (0, 0, Default::default());
self.calculate_order_index(root, &runtime, &mut visited, &mut ctx, compilation);

let chunk_group = compilation
.chunk_group_by_ukey
.expect_get_mut(&chunk_group_ukey);
for (id, (pre, post)) in ctx.2 {
chunk_group.module_pre_order_indices.insert(id, pre);
chunk_group.module_post_order_indices.insert(id, post);
for (id, (pre, post)) in &ctx.2 {
chunk_group.module_pre_order_indices.insert(*id, *pre);
chunk_group.module_post_order_indices.insert(*id, *post);
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions crates/rspack_core/src/options/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,14 @@ impl From<&str> for WasmLoading {
pub enum WasmLoadingType {
Fetch,
AsyncNode,
AsyncNodeModule,
}

impl From<&str> for WasmLoadingType {
fn from(value: &str) -> Self {
match value {
"fetch" => Self::Fetch,
"async-node" => Self::AsyncNode,
"async-node-module" => Self::AsyncNodeModule,
_ => todo!(),
_ => unreachable!("invalid wasm loading type: {value}, expect one of [fetch, async-node]",),
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions crates/rspack_plugin_runtime/src/module_chunk_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,22 @@ fn render_chunk(

let mut sources = ConcatSource::default();
sources.add(RawStringSource::from(format!(
"export const ids = ['{}'];\n",
"export const __webpack_ids__ = ['{}'];\n",
&chunk.expect_id(&compilation.chunk_ids_artifact)
)));
sources.add(RawStringSource::from_static("export const modules = "));
sources.add(RawStringSource::from_static(
"export const __webpack_modules__ = ",
));
sources.add(render_source.source.clone());
sources.add(RawStringSource::from_static(";\n"));

if compilation
.chunk_graph
.has_chunk_runtime_modules(chunk_ukey)
{
sources.add(RawStringSource::from_static("export const runtime = "));
sources.add(RawStringSource::from_static(
"export const __webpack_runtime__ = ",
));
sources.add(render_chunk_runtime_modules(compilation, chunk_ukey)?);
sources.add(RawStringSource::from_static(";\n"));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
var installChunk = function (data) {
var ids = data.ids;
var modules = data.modules;
var runtime = data.runtime;
var __webpack_ids__ = data.__webpack_ids__;
var __webpack_modules__ = data.__webpack_modules__;
var __webpack_runtime__ = data.__webpack_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 (__webpack_require__.o(modules, moduleId)) {
__webpack_require__.m[moduleId] = modules[moduleId];
for (moduleId in __webpack_modules__) {
if (__webpack_require__.o(__webpack_modules__, moduleId)) {
__webpack_require__.m[moduleId] = __webpack_modules__[moduleId];
}
}
if (runtime) runtime(__webpack_require__);
for (; i < ids.length; i++) {
chunkId = ids[i];
if (__webpack_runtime__) __webpack_runtime__(__webpack_require__);
for (; i < __webpack_ids__.length; i++) {
chunkId = __webpack_ids__[i];
if (__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) {
installedChunks[chunkId][0]();
}
installedChunks[ids[i]] = 0;
installedChunks[__webpack_ids__[i]] = 0;
}
$WITH_ON_CHUNK_LOAD$
};
22 changes: 14 additions & 8 deletions crates/rspack_plugin_wasm/src/loading_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use crate::AsyncWasmLoadingRuntimeModule;
pub fn enable_wasm_loading_plugin(wasm_loading_type: WasmLoadingType) -> BoxPlugin {
match wasm_loading_type {
WasmLoadingType::Fetch => FetchCompileAsyncWasmPlugin::default().boxed(),
WasmLoadingType::AsyncNode => ReadFileCompileAsyncWasmPlugin::new(false).boxed(),
WasmLoadingType::AsyncNodeModule => ReadFileCompileAsyncWasmPlugin::new(true).boxed(),
WasmLoadingType::AsyncNode => ReadFileCompileAsyncWasmPlugin::new().boxed(),
}
}

Expand Down Expand Up @@ -65,13 +64,11 @@ impl Plugin for FetchCompileAsyncWasmPlugin {

#[plugin]
#[derive(Debug)]
pub struct ReadFileCompileAsyncWasmPlugin {
import: bool,
}
pub struct ReadFileCompileAsyncWasmPlugin {}

impl ReadFileCompileAsyncWasmPlugin {
fn new(import: bool) -> Self {
Self::new_inner(import)
fn new() -> Self {
Self::new_inner()
}
}

Expand All @@ -86,10 +83,19 @@ fn read_file_compile_async_wasm_plugin_runtime_requirements_in_tree(
) -> Result<Option<()>> {
if runtime_requirements.contains(RuntimeGlobals::INSTANTIATE_WASM) {
runtime_requirements_mut.insert(RuntimeGlobals::PUBLIC_PATH);

let import_enabled = compilation.options.output.module
&& compilation
.options
.output
.environment
.dynamic_import
.unwrap_or_default();

compilation.add_runtime_module(
chunk_ukey,
AsyncWasmLoadingRuntimeModule::new(
if self.import {
if import_enabled {
include_str!("runtime/read_file_compile_async_wasm_with_import.js").to_string()
} else {
include_str!("runtime/read_file_compile_async_wasm.js").to_string()
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"rimraf": "^5.0.10",
"ts-jest": "29.2.5",
"typescript": "^5.7.3",
"webpack": "^5.95.0",
"webpack": "5.97.1",
"webpack-cli": "5.1.4",
"zx": "8.3.0"
},
Expand All @@ -88,4 +88,4 @@
"rollup-plugin-dts": "patches/rollup-plugin-dts.patch"
}
}
}
}
4 changes: 2 additions & 2 deletions packages/rspack-test-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"rimraf": "^5.0.10",
"source-map": "^0.7.4",
"terser-webpack-plugin": "^5.3.10",
"webpack": "^5.95.0",
"webpack": "5.97.1",
"webpack-merge": "5.9.0",
"webpack-sources": "3.2.3"
},
Expand Down Expand Up @@ -126,4 +126,4 @@
"peerDependencies": {
"@rspack/core": ">=1.0.0"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class WebpackDiffConfigPlugin {
options.optimization.mangleExports ??= false;
options.optimization.concatenateModules ??= false;

options.output ??= {};
options.output ??= {} as any;
options.output.pathinfo ??= false;

options.output.environment ??= {};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
/** @type {import("@rspack/core").Configuration} */
module.exports = {
output: {
wasmLoading: "async-node-module"
wasmLoading: "async-node",
module: true,
environment: {
dynamicImport: true,
module: true
}
},
module: {
rules: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
/** @type {import("webpack").Configuration} */
module.exports = {
output: {
wasmLoading: "async-node-module"
wasmLoading: "async-node",
module: true,
environment: {
dynamicImport: true,
module: true
}
},
module: {
rules: [
Expand All @@ -13,6 +18,7 @@ module.exports = {
]
},
experiments: {
asyncWebAssembly: true
asyncWebAssembly: true,
outputModule: true
}
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const webpack = require("webpack");
const rspack = require("@rspack/core");

/** @type {import('@rspack/core').Configuration} */
module.exports = {
Expand All @@ -8,7 +8,7 @@ module.exports = {
modules: true
},
plugins: [
new webpack.IgnorePlugin({
new rspack.IgnorePlugin({
checkResource: (resource, request) => {
if (resource.includes("zh") || resource.includes("globalIndex")) {
return true;
Expand Down
3 changes: 1 addition & 2 deletions packages/rspack/src/config/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -708,8 +708,7 @@ const applyOutputDefaults = (
F(output, "wasmLoading", () => {
if (tp) {
if (tp.fetchWasm) return "fetch";
if (tp.nodeBuiltins)
return output.module ? "async-node-module" : "async-node";
if (tp.nodeBuiltins) return "async-node";
if (tp.nodeBuiltins === null || tp.fetchWasm === null) {
return "universal";
}
Expand Down
Loading

2 comments on commit 6f7a16d

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented on 6f7a16d Feb 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Benchmark detail: Open

Name Base (2025-02-18 92ddee2) Current Change
10000_big_production-mode_disable-minimize + exec 37.1 s ± 794 ms 38.1 s ± 641 ms +2.55 %
10000_development-mode + exec 1.78 s ± 19 ms 1.75 s ± 32 ms -1.97 %
10000_development-mode_hmr + exec 680 ms ± 6.9 ms 673 ms ± 4.5 ms -0.93 %
10000_production-mode + exec 2.22 s ± 94 ms 2.21 s ± 132 ms -0.78 %
10000_production-mode_persistent-cold + exec 2.38 s ± 127 ms 2.34 s ± 64 ms -2.00 %
10000_production-mode_persistent-hot + exec 1.64 s ± 92 ms 1.62 s ± 56 ms -1.41 %
arco-pro_development-mode + exec 1.76 s ± 83 ms 1.76 s ± 114 ms +0.10 %
arco-pro_development-mode_hmr + exec 387 ms ± 6.5 ms 385 ms ± 0.81 ms -0.58 %
arco-pro_production-mode + exec 3.6 s ± 148 ms 3.62 s ± 247 ms +0.52 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.65 s ± 190 ms 3.63 s ± 176 ms -0.64 %
arco-pro_production-mode_persistent-cold + exec 3.7 s ± 80 ms 3.72 s ± 141 ms +0.31 %
arco-pro_production-mode_persistent-hot + exec 2.3 s ± 162 ms 2.34 s ± 116 ms +2.00 %
arco-pro_production-mode_traverse-chunk-modules + exec 3.6 s ± 133 ms 3.65 s ± 244 ms +1.27 %
large-dyn-imports_development-mode + exec 2.04 s ± 70 ms 2.02 s ± 64 ms -0.71 %
large-dyn-imports_production-mode + exec 2.05 s ± 46 ms 2.04 s ± 47 ms -0.44 %
threejs_development-mode_10x + exec 1.53 s ± 35 ms 1.52 s ± 33 ms -0.72 %
threejs_development-mode_10x_hmr + exec 791 ms ± 23 ms 773 ms ± 14 ms -2.20 %
threejs_production-mode_10x + exec 5.2 s ± 215 ms 5.2 s ± 317 ms 0.00 %
threejs_production-mode_10x_persistent-cold + exec 5.26 s ± 303 ms 5.19 s ± 70 ms -1.29 %
threejs_production-mode_10x_persistent-hot + exec 4.42 s ± 39 ms 4.42 s ± 87 ms +0.03 %
10000_big_production-mode_disable-minimize + rss memory 8713 MiB ± 138 MiB 8675 MiB ± 113 MiB -0.44 %
10000_development-mode + rss memory 644 MiB ± 12.5 MiB 637 MiB ± 15.1 MiB -1.04 %
10000_development-mode_hmr + rss memory 1259 MiB ± 209 MiB 1292 MiB ± 211 MiB +2.60 %
10000_production-mode + rss memory 618 MiB ± 12.9 MiB 614 MiB ± 25.7 MiB -0.61 %
10000_production-mode_persistent-cold + rss memory 719 MiB ± 31.4 MiB 716 MiB ± 30.3 MiB -0.50 %
10000_production-mode_persistent-hot + rss memory 690 MiB ± 11.9 MiB 679 MiB ± 10.8 MiB -1.60 %
arco-pro_development-mode + rss memory 581 MiB ± 28.2 MiB 560 MiB ± 29.6 MiB -3.65 %
arco-pro_development-mode_hmr + rss memory 644 MiB ± 61.1 MiB 646 MiB ± 73.5 MiB +0.37 %
arco-pro_production-mode + rss memory 718 MiB ± 26.1 MiB 696 MiB ± 33.4 MiB -3.01 %
arco-pro_production-mode_generate-package-json-webpack-plugin + rss memory 727 MiB ± 18.9 MiB 722 MiB ± 15.4 MiB -0.79 %
arco-pro_production-mode_persistent-cold + rss memory 802 MiB ± 25.1 MiB 785 MiB ± 17 MiB -2.08 %
arco-pro_production-mode_persistent-hot + rss memory 639 MiB ± 29.8 MiB 634 MiB ± 13.7 MiB -0.66 %
arco-pro_production-mode_traverse-chunk-modules + rss memory 733 MiB ± 12.2 MiB 700 MiB ± 47.1 MiB -4.48 %
large-dyn-imports_development-mode + rss memory 636 MiB ± 6.13 MiB 631 MiB ± 3.51 MiB -0.81 %
large-dyn-imports_production-mode + rss memory 519 MiB ± 10.7 MiB 517 MiB ± 4.87 MiB -0.32 %
threejs_development-mode_10x + rss memory 545 MiB ± 27.8 MiB 548 MiB ± 8.02 MiB +0.59 %
threejs_development-mode_10x_hmr + rss memory 1165 MiB ± 55.2 MiB 1155 MiB ± 88 MiB -0.85 %
threejs_production-mode_10x + rss memory 833 MiB ± 23.7 MiB 830 MiB ± 35.9 MiB -0.34 %
threejs_production-mode_10x_persistent-cold + rss memory 930 MiB ± 69.3 MiB 907 MiB ± 32.2 MiB -2.44 %
threejs_production-mode_10x_persistent-hot + rss memory 796 MiB ± 32.9 MiB 782 MiB ± 32.5 MiB -1.79 %

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented on 6f7a16d Feb 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ecosystem CI detail: Open

suite result
modernjs ✅ success
rspress ✅ success
rslib ✅ success
rsbuild ❌ failure
rsdoctor ❌ failure
examples ✅ success
devserver ✅ success
nuxt ✅ success

Please sign in to comment.