feat(enhanced): compose the runtime bootstrap behind experiments.composedRuntime - #5140
ScriptedAlchemy wants to merge 24 commits into
Conversation
🦋 Changeset detectedLatest commit: f2eb03c 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 |
@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: a3c075c1d1
ℹ️ 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".
| const composition = renderComposition( | ||
| plan, | ||
| resolveImports(plan, family), | ||
| this._buildId(compiler), |
There was a problem hiding this comment.
Fall back when composed imports cannot resolve
When a custom implementation declares the required export keys but exposes them only under conditions such as require, selectMode accepts the runtime family, but resolveImports uses only import/module/default conditions and throws here. This makes beforeCompile reject and the build fail, even though the legacy bootstrap can resolve that implementation and the new option promises to fall back when composition is unavailable. Catch composition import/render failures and return a legacy outcome with a warning instead.
Useful? React with 👍 / 👎.
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. |
…ants, and legacy selection
The planner already skips SharedContainerPlugin compilers, so a participant registered there is never read. Drop the stale fourth getTemplate argument from the runtime-guard unit test.
… into rfc5128/05-enhanced-composed
…enhanced's own runtime aliases A user alias on @module-federation/runtime$ now selects the legacy bootstrap. The graph check realpaths only runtime package roots and tolerates roots outside the real disk.
… into rfc5128/05-enhanced-composed
0a88a0b committed node_modules that the tree-shaking config case writes at test time. Ignore that path so they stay out.
…ph check ExternalModule.request is the external target, such as a global name, so an externalized runtime package passed the check. Use userRequest.
…from the planner FederationRuntimePlugin.apply returns for SharedContainerPlugin compilers before it creates the planner.
… into rfc5128/05-enhanced-composed
Two installed copies of enhanced in one process both registered their classes under the same 'enhanced/lib/...' key, and webpack's global serializer registry throws on the second registration. (cherry picked from commit 8b63693)
…izer registrations
… into rfc5128/05-enhanced-composed
… into rfc5128/05-enhanced-composed
… into rfc5128/05-enhanced-composed
… into rfc5128/05-enhanced-composed
… into rfc5128/05-enhanced-composed
… into rfc5128/05-enhanced-composed
Part of RFC #5128 (alternate proposal to #5036).
Stack: 5 of 7. Base: #5134 (
rfc5128/04-managers-composition). Next: #5141.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
ModuleFederationPluginin@module-federation/enhancedgetsexperiments.composedRuntime. With the flag on, enhanced generates a federation bootstrap that imports only the runtime-core capabilities and bundler-runtime adapters the build uses, so the excluded parts are not in the module graph. Builds without the flag are unchanged.Every federation plugin registers a participant on a compiler slot that all installed copies of enhanced share.
ModuleFederationPluginregisters one participant for its options, and a standaloneContainerPlugin,ContainerReferencePlugin,ConsumeSharedPlugin, orProvideSharedPluginregisters what it needs. The plan is sealed inafterResolvers. An older runtime, an externalized runtime, or a user alias on a runtime package selects today's bootstrap and defines, with a warning that names the reason. AfinishModulesgraph check reports federation modules whose adapter is missing.Two installed copies of enhanced could not share one webpack, because both registered serializers under the same
enhanced/lib/...key. This PR carries the fix from #5144 so the two-copies test loads a real second copy.Verification
configCases/composed-runtime/*has 7 cases (default, remotes-only, exposes-only, shared-only, all-off, after-plugins, standalone-share-plugin). Each runs the bundle, loads a remote module or a shared singleton, and asserts the planned parts are bundled and the excluded runtime-core modules are not. All 7 fail on the parent branch. All-off fails withexpected false to be true, and the other 6 fail withexpected [ 'compose', false ] to deeply equal [ 'compose', true ].compiler-unit/container/FederationCompositionPlugin.test.tscovers the fallbacks and errors. An older runtime family, a function external on runtime-core, and a user alias each select legacy with a warning. A plan that never ran warns. An external runtime package and a remote module without its adapter are build errors. Legacy output with the flag on is byte-identical to the flag off. Composed builds keepENV_TARGETand drop the capability and build-id defines. Two copies of enhanced plan once. A participant registered after sealing is refused. The shared tree-shaking compiler builds.--composed. Flag-off output is byte-identical to the parent branch.pnpm --filter @module-federation/enhanced run testpasses locally with 479 + 6 tests (unit, config cases, and the serial tree-shaking run). CI has no enhanced unit-test job, so this local run is the only run of that suite.c2aea32c3. The full gates review ran at884586498and found watch, multicompiler, and filesystem-cache profile flips correct. Its audit found that the graph check usedExternalModule.requestinstead ofuserRequest, and that 10 straynode_modulesfiles were committed. The verifier reproduced both fixes as fixed, and checked the fix(enhanced): key cache serializers by install directory #5144 port with its test workaround removed. The patch is unchanged through232dbe30eand the live headf2eb03cee.f2eb03ceewith 18 checks. e2e-treeshake was skipped because the affected-suite selector did not pick it.Deviations from the RFC
beforeCompile, once per compiler, not inafterResolvers.selectModeis async because function externals can be, andafterResolversis synchronous.beforeCompilestill runs beforemake, whereContainerPluginreads the entry path. The RFC now describes this timing.Overlaps with open PRs
This PR carries the #5144 serializer-key fix (the same
makeSerializablehelper and call sites). It carries no code from other open PRs. The PRs below change files this PR also changes. This PR does not include their changes.enhanced/src/lib/container/ModuleFederationPlugin.ts,runtime/FederationRuntimePlugin.ts, and its unit test. Only one of the two RFCs lands.enhanced/src/lib/container/runtime/FederationRuntimePlugin.ts. fix(enhanced): make the generated runtime entry deterministic and valid #5123 and fix(enhanced): resolve package names in runtimePlugins #4954 also change its unit test.enhanced/src/lib/sharing/ProvideSharedPlugin.ts.enhanced/src/lib/sharing/ConsumeSharedModule.ts.enhanced/src/lib/sharing/ConsumeSharedPlugin.ts.enhanced/src/lib/container/ModuleFederationPlugin.ts.ModuleFederationPluginschema files andsdk/src/types/plugins/ModuleFederationPlugin.ts.ContainerEntryModule.ts,ContainerExposedDependency.ts,ContainerPlugin.ts,ConsumeSharedPlugin.ts, theModuleFederationPluginschema files, andsdk/src/types/plugins/ModuleFederationPlugin.ts..gitignore.