feat(rspack): redirect the native bundler runtime to a composed entry - #5141
ScriptedAlchemy wants to merge 22 commits into
Conversation
# Conflicts: # pnpm-lock.yaml
🦋 Changeset detectedLatest commit: 84cee41 The changes in this PR will be included in the next version bump. This PR includes changesets to release 48 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
@module-federation/devtools
@module-federation/cli
create-module-federation
@module-federation/dts-plugin
@module-federation/enhanced
@module-federation/error-codes
@module-federation/esbuild
@module-federation/managers
@module-federation/manifest
@module-federation/metro
@module-federation/metro-plugin-rnc-cli
@module-federation/metro-plugin-rnef
@module-federation/metro-plugin-rock
@module-federation/modern-js
@module-federation/modern-js-v3
@module-federation/native-federation-tests
@module-federation/native-federation-typescript
@module-federation/nextjs-mf
@module-federation/node
@module-federation/observability-plugin
@module-federation/playground
@module-federation/retry-plugin
@module-federation/rsbuild-plugin
@module-federation/rspack
@module-federation/rspress-plugin
@module-federation/rstest
@module-federation/runtime
@module-federation/runtime-core
@module-federation/runtime-tools
@module-federation/sdk
@module-federation/storybook-addon
@module-federation/third-party-dts-extractor
@module-federation/treeshake-frontend
@module-federation/treeshake-server
@module-federation/typescript
@module-federation/utilities
@module-federation/webpack-bundler-runtime
@module-federation/bridge-react
@module-federation/bridge-react-webpack-plugin
@module-federation/bridge-shared
@module-federation/bridge-vue3
@module-federation/inject-external-runtime-core-plugin
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2dddaa6de7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| }, | ||
| "devDependencies": { | ||
| "@rspack/core": "^1.0.2", | ||
| "@rspack/core": "2.1.10", |
There was a problem hiding this comment.
Implement the composed-runtime wiring
When a consumer enables experiments.composedRuntime, this commit only upgrades @rspack/core and never changes the Rspack plugin implementation. ModuleFederationPlugin.apply() still unconditionally passes the original options to the native plugin and aliases @module-federation/runtime$ through resolveRspackRuntimeAlias() (packages/rspack/src/ModuleFederationPlugin.ts, lines 235-253), with no composition planning or virtual-module branch, so the new flag has no effect and output continues using the existing runtime entry.
Useful? React with 👍 / 👎.
…to rfc5128/06-rspack-composed
…to rfc5128/06-rspack-composed
…to rfc5128/06-rspack-composed
rspack's async startup runtime installs its consumes chunk handler without shared modules and calls bundlerRuntime.consumes, so a composed plan without the adapter crashed at startup. (cherry picked from commit 52ce340)
The rspack wrapper aliases the native plugin's absolute webpack-bundler-runtime path to a virtual composed module. Rstest externalized that path, so Node tried to import the virtual file from disk. The bypass applies only with experiments.composedRuntime, so builds without it keep today's externals. (cherry picked from commit 00109f5)
…to rfc5128/06-rspack-composed
…to rfc5128/06-rspack-composed
In composed mode the wrapper now summarizes the compilation's modules and external requests, runs the managers graph check, and reports its findings. A plugin-applied external on a runtime package, or a remote module with no remotes adapter in the bootstrap, is now a build error instead of a runtime failure.
…to rfc5128/06-rspack-composed
…to rfc5128/06-rspack-composed
…to rfc5128/06-rspack-composed
Part of RFC #5128 (alternate proposal to #5036).
Stack: 6 of 7. Base: #5140 (
rfc5128/05-enhanced-composed). Next: #5142.Landing order: #5135 → #5137 → #5139 → #5134 → #5140 → #5141 → #5142.
Companions on main: #5143 (disabled remote loadEntry), #5144 (enhanced duplicate serializer keys). #5126 (@rspack/core 2) is on main. PR 6 and 7 include it.
What changes
With
experiments.composedRuntimeset,@module-federation/rspackbuilds a composed federation bootstrap and points rspack's native Module Federation plugin at it. The build then imports only the runtime parts the plan needs, in ESM, instead ofwebpack-bundler-runtime/dist/index.cjsand the whole runtime. Rspack itself does not change. The composed build runs on@rspack/core1.5.8, 1.7.9, and 2.1.10.The wrapper plans from its own options, registers the bootstrap as a virtual module at
node_modules/.federation/rspack/<name>.<hash>.mjs, and aliases the bundler runtime path rspack computes to it. A virtual module does not go stale under rspack's persistent cache, which a real file at a hashed path does. The hash covers the rendered source, including the build id and resolved paths. In composed mode the wrapper runs the managers graph check infinishModules. An externalized runtime package, or a federation module whose adapter is not in the bootstrap, is a build error.The build keeps the full runtime, as today, in three cases. The flag is off, the
@rspack/corehas noexperiments.VirtualModulesPlugin, or a user alias points at a runtime package. The build warns when the flag was set. An@rspack/corewithoutcompiler.rspack(0.7) also falls back instead of throwing, because the plugins come fromcompiler.webpack.beforeRunandwatchRun, once per compiler.selectModemay await function externals, and rspack readsresolve.aliasand builtin plugins only when it creates its native compiler. The capability defines are applied after that decision for the same reason.federation.runtime.init, which the composed shim from refactor(webpack-bundler-runtime): compose the bundler runtime from adapters #5137 provides.@module-federation/runtime$alias is removed. Rspack's native plugin writes a@module-federation/runtimealias first, which already matches.This branch includes #5126 (the move to
@rspack/core2, now on main) through an earlier merge of its branch. The repo's previous pin,@rspack/core1.3.9, has noVirtualModulesPlugin. The rootpackage.json,pnpm-lock.yaml, and app config changes in this diff come from #5126.Verification
@rspack/core1.5.8 and 1.7.9 failed withTypeError: __webpack_require__.federation.runtime.init is not a function(11 passed, 2 failed) before the refactor(webpack-bundler-runtime): compose the bundler runtime from adapters #5137 shim reached this branch. They pass after it.@rspack/corerun in Node. The spec asserts the remote module's value and one shared singleton (evaluations1).webpack-bundler-runtime/dist/index.cjsis not, and excluded capability modules are absent in remotes-only and exposes-only builds.VirtualModulesPluginis missing, when a user alias points at the bundler runtime path, and when one points at a runtime package. Mutating either user-alias branch turns its spec red. Without the flag the build keeps the full runtime and no warning.ExternalsPluginon^@module-federation/runtime-core, and a composed build where a standaloneContainerReferencePluginadds a remote module with noremotesadapter, both built with no error before (Received: []). They now fail with the managers messages.packages/rspackpasses 22/22 atcfd395d69, with typecheck and lint clean. The rstest unit tests pass.cfd395d69passes with 0 failed and 0 skipped.--composed --bundler rspackruns 16 checks on each of@rspack/core1.7.9 and 1.5.8.--composed --bundler bothon 2.1.10 runs 32. Flag off against feat(enhanced): compose the runtime bootstrap behind experiments.composedRuntime #5140 at232dbe30eplus chore(deps): move the repo to @rspack/core 2 #5126 runs 34, and the emitted files are byte-identical on webpack and rspack.cfd395d69. Its own composed host and remote loaded the remote and one singleton on 1.5.8, 1.7.9, and 2.1.10, with the virtual module and noindex.cjs. The live head84cee419chas the same patch over its parent.84cee419cwith 19 checks.Deviations from the RFC
.cjsand.js. Rspack's resolve data has nodescriptionFileRoot, so the summary carries no package roots. The adapter, external, and bootstrap-count checks run as the RFC specifies.resolveRspackRuntimeAliasstays exported and deprecated, because@module-federation/rspack/pluginre-exports it and a minor cannot remove it.Overlaps with open PRs
This branch contains the #5144 fix through #5140 and #5126 through a merge of its branch. This PR carries no code from other open PRs. The PRs below change files this PR also changes. This PR does not include their changes.
packages/rspack/src/ModuleFederationPlugin.ts. feat(rspack): support eager exposes #5023 touchesresolveRspackRuntimeAlias. Neither changes the composed path.packages/rspack/src/ModuleFederationPlugin.ts.rspack.config.jsof the three manifest-demo rspack providers.package.json.