feat(runtime): add webpack require and bundler-ignore accessors#4457
feat(runtime): add webpack require and bundler-ignore accessors#4457ScriptedAlchemy wants to merge 27 commits intomainfrom
Conversation
Co-authored-by: zackary.l.jackson <zackary.l.jackson@gmail.com>
|
Cursor Agent can help with this pull request. Just |
🦋 Changeset detectedLatest commit: bcff4b2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 43 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 |
✅ Deploy Preview for module-federation-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
@module-federation/devtools
@module-federation/cli
create-module-federation
@module-federation/data-prefetch
@module-federation/dts-plugin
@module-federation/enhanced
@module-federation/error-codes
@module-federation/managers
@module-federation/manifest
@module-federation/metro
@module-federation/metro-plugin-rnc-cli
@module-federation/metro-plugin-rnef
@module-federation/modern-js-v3
@module-federation/retry-plugin
@module-federation/rsbuild-plugin
@module-federation/rspack
@module-federation/rspress-plugin
@module-federation/runtime
@module-federation/runtime-core
@module-federation/runtime-tools
@module-federation/sdk
@module-federation/third-party-dts-extractor
@module-federation/treeshake-frontend
@module-federation/treeshake-server
@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: |
Bundle Size Report7 package(s) changed, 34 unchanged.
Total dist: 6.91 MB (+19.7 kB (+0.3%)) |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e3de5a394f
ℹ️ 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".
There was a problem hiding this comment.
Pull request overview
This PR introduces a dedicated SDK subpath entrypoint for bundler/runtime-sensitive helpers, then migrates multiple runtime loaders to use those helpers instead of directly referencing __webpack_require__ or embedding bundler-specific magic comments in dynamic imports.
Changes:
- Added
@module-federation/sdk/bundlerhelpers:getWebpackRequire(),getWebpackRequireOrThrow(), andimportWithBundlerIgnore(). - Replaced direct
__webpack_require__usage andwebpackIgnore/@vite-ignoreinline imports across runtime-core, node, utilities, and webpack-bundler-runtime. - Added/updated Jest coverage to validate new fallbacks and ESM remote namespace wrapping behavior.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/webpack-bundler-runtime/src/init.ts | Uses SDK accessor to safely retrieve federation bundlerRuntime instead of direct __webpack_require__ access. |
| packages/webpack-bundler-runtime/tests/init.spec.ts | Adds a test ensuring the init path falls back to the provided webpackRequire when the SDK accessor returns undefined. |
| packages/utilities/src/utils/pure.ts | Switches script loader path from direct __webpack_require__.l to getWebpackRequireOrThrow().l. |
| packages/utilities/src/utils/pure.test.ts | Adds tests ensuring loadScript doesn’t resolve webpack require when asyncContainer is already a promise or a factory. |
| packages/utilities/src/utils/importRemote.ts | Centralizes ignored dynamic import usage and adds validation/wrapping for immutable ESM namespace containers. |
| packages/utilities/src/utils/importRemote.test.ts | Adds a test verifying immutable namespace objects are wrapped before runtime flags are attached. |
| packages/sdk/src/bundler.ts | Introduces new accessor + bundler-ignore dynamic import helper functions. |
| packages/sdk/project.json | Adds bundler.ts as an additional Rollup entrypoint so it’s built as a standalone subpath export. |
| packages/sdk/package.json | Exposes the new ./bundler export and typesVersions mapping. |
| packages/runtime-core/src/utils/load.ts | Replaces inline ignored dynamic import with importWithBundlerIgnore. |
| packages/node/src/utils/hot-reload.ts | Avoids direct global access by using getWebpackRequire() before clearing federation module cache. |
| packages/node/src/runtimePlugin.ts | Replaces direct __webpack_require__ usage with an accessor-backed helper throughout runtime plugin logic. |
| packages/node/src/filesystem/stratagies.ts | Uses accessor-backed webpack require for chunk url/base path resolution. |
| packages/node/src/tests/runtimePlugin.test.ts | Updates test fixtures so mocked __webpack_require__ matches webpack’s callable function shape. |
| .changeset/twelve-forks-whisper.md | Adds changeset for patch releases across affected packages and describes the new subpath export. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ScriptedAlchemy
left a comment
There was a problem hiding this comment.
I found one regression in packages/utilities/src/utils/pure.ts: loadScript now resolves getWebpackRequireOrThrow() before checking whether the remote container is already present on globalScope. In non-webpack hosts with preloaded globals, this throws early (__webpack_require__ missing) instead of returning the existing container. Consider resolving webpack require only in the branch that actually calls webpackRequire.l(...).
|
Re-reviewed latest head
|
|
@codex review the pr |
|
Re-review on head |
|
Codex Review: Didn't find any major issues. Nice work! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description
Centralizes access to
__webpack_require__and dynamicwebpackIgnore/vite-ignoreimports into dedicated helpers. This prevents direct global references from being inlined or patched during bundling, allowing downstream packages to import these functionalities externally.Specifically:
getWebpackRequire()andgetWebpackRequireOrThrow()in@module-federation/webpack-bundler-runtime/accessorfor safe__webpack_require__access.importWithBundlerIgnore()in@module-federation/sdkto encapsulate/* webpackIgnore: true */ /* @vite-ignore */dynamic imports, avoiding dependency cycles.__webpack_require__and magic-comment dynamic import usages inruntime-coreandutilitiesto use these new helpers.__webpack_require__reference withinwebpack-bundler-runtimeitself.Related Issue
Addresses the need to provide stable, importable accessors for webpack runtime globals and magic-comment-driven dynamic imports, as discussed in the conversation.
Types of changes
Checklist