-
-
Notifications
You must be signed in to change notification settings - Fork 392
feat(runtime): add webpack require and bundler-ignore accessors #4457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+651
−93
Closed
Changes from 10 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
e22f492
feat(runtime): add shared webpack require accessor helpers
cursoragent dce6b4d
fix(utils): update remote container typing for helper import
cursoragent 76c2216
refactor(runtime-core): decouple bundler ignore helper from sdk exports
cursoragent adff9b6
fix(utils): keep remote container type surface unchanged
cursoragent 707aab5
fix(webpack-bundler-runtime): keep internal direct webpack require usage
cursoragent aa47578
refactor(utils): simplify esm remote initialization typing
cursoragent 14d1b76
fix(webpack-bundler-runtime): use module-level webpack require accessor
cursoragent 04ba1b4
feat(runtime-core): prefer bundler runtime import ignore helper
cursoragent 7b274f1
refactor(webpack-bundler-runtime): keep ignore helper as standalone e…
cursoragent e3de5a3
Merge branch 'main' into cursor/bundler-runtime-require-access-725d
ScriptedAlchemy e0c0704
refactor(node): migrate runtime webpack require access to bundler acc…
cursoragent f953e6e
refactor: keep webpack require helpers on accessor entrypoint
cursoragent 4c257d8
test(webpack-bundler-runtime): avoid global webpack require mutation
cursoragent 92b7ec0
refactor(runtime-core): source bundler-ignore helper from sdk
cursoragent 2e41604
refactor(sdk): expose bundler helper via standalone entrypoint
cursoragent 49d79a6
refactor: route webpack runtime helpers through sdk bundler entry
cursoragent 385f226
fix(utils): avoid esm namespace mutation and defer webpack require
cursoragent 0211f52
refactor(webpack-bundler-runtime): remove accessor entrypoint leftovers
cursoragent ac23c9a
fix(webpack-bundler-runtime): use sdk bundler webpack require
cursoragent c911bb6
fix: add regression coverage and align release metadata
cursoragent ce7453a
fix(node): inline webpack require in runtime chunk strategies
cursoragent f2ba7eb
feat(sdk): expose webpack sharing accessors in bundler entry
cursoragent ca9fea3
fix(node): use sdk bundler accessor in strategies
cursoragent dd14287
fix(node): remove any cast in hot-reload webpack accessor
cursoragent 6e56bd7
refactor(utils): remove async wrappers in sharing scope setup
cursoragent 55fa8f6
test(core): add bundler and esm validation coverage
cursoragent bcff4b2
Merge branch 'main' into cursor/bundler-runtime-require-access-725d
ScriptedAlchemy e278fde
Merge remote-tracking branch 'origin/main' into cursor/bundler-runtim…
ScriptedAlchemy 539aef8
fix(dts-plugin): align workspace entrypoints and RawSource typing
ScriptedAlchemy 2fabca3
Merge branch 'main' into cursor/bundler-runtime-require-access-725d
ScriptedAlchemy fa6339f
fix(sdk): align package entrypoints with emitted artifacts
ScriptedAlchemy e85e0f4
Merge branch 'main' into cursor/bundler-runtime-require-access-725d
ScriptedAlchemy d550fd4
Merge branch 'main' into cursor/bundler-runtime-require-access-725d
ScriptedAlchemy cb38d95
Merge branch 'main' into cursor/bundler-runtime-require-access-725d
ScriptedAlchemy 724a9b4
Merge branch 'main' into cursor/bundler-runtime-require-access-725d
ScriptedAlchemy 9f163a2
Merge branch 'main' into cursor/bundler-runtime-require-access-725d
ScriptedAlchemy acbd6d6
Merge branch 'main' into cursor/bundler-runtime-require-access-725d
ScriptedAlchemy 443d2df
chore: merge main into cursor/bundler-runtime-require-access-725d
ScriptedAlchemy 535729c
Merge branch 'main' into cursor/bundler-runtime-require-access-725d
ScriptedAlchemy 0b299ab
Merge branch 'main' into cursor/bundler-runtime-require-access-725d
ScriptedAlchemy 949cfb7
Merge remote-tracking branch 'origin/main' into cursor/bundler-runtim…
ScriptedAlchemy c1fea4a
Merge branch 'main' into cursor/bundler-runtime-require-access-725d
ScriptedAlchemy c885b33
Merge remote-tracking branch 'origin/main' into cursor/bundler-runtim…
ScriptedAlchemy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| '@module-federation/webpack-bundler-runtime': patch | ||
| '@module-federation/runtime-core': patch | ||
| '@module-federation/utilities': patch | ||
| --- | ||
|
|
||
| Add runtime-safe access helpers for webpack require and ignored dynamic imports, and migrate core runtime loaders to use these helpers so intermediate bundling steps are less likely to rewrite runtime globals. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
packages/webpack-bundler-runtime/__tests__/accessor.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import { | ||
| getWebpackRequire, | ||
| getWebpackRequireOrThrow, | ||
| importWithBundlerIgnore, | ||
| } from '../src/accessor'; | ||
|
|
||
| describe('webpack require accessor', () => { | ||
| afterEach(() => { | ||
| delete (globalThis as { __webpack_require__?: unknown }) | ||
| .__webpack_require__; | ||
| }); | ||
|
|
||
| test('returns undefined when webpack runtime is unavailable', () => { | ||
| expect(getWebpackRequire()).toBeUndefined(); | ||
| }); | ||
|
|
||
| test('returns the webpack require function when present', () => { | ||
| const webpackRequire = Object.assign(jest.fn(), { | ||
| federation: { bundlerRuntime: {} }, | ||
| }); | ||
| (globalThis as { __webpack_require__?: unknown }).__webpack_require__ = | ||
| webpackRequire; | ||
|
|
||
| expect(getWebpackRequire()).toBe(webpackRequire); | ||
| }); | ||
|
|
||
| test('throws with clear message when webpack runtime is unavailable', () => { | ||
| expect(() => getWebpackRequireOrThrow()).toThrow( | ||
| 'Unable to access __webpack_require__.', | ||
| ); | ||
| }); | ||
|
|
||
| test('re-exports dynamic import helper', () => { | ||
| expect(typeof importWithBundlerIgnore).toBe('function'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import type { WebpackRequire } from './types'; | ||
|
|
||
| declare const __webpack_require__: unknown; | ||
|
|
||
| export function getWebpackRequire(): WebpackRequire | undefined { | ||
| if (typeof __webpack_require__ !== 'function') { | ||
| return undefined; | ||
| } | ||
|
|
||
| return __webpack_require__ as WebpackRequire; | ||
| } | ||
|
|
||
| export function getWebpackRequireOrThrow(): WebpackRequire { | ||
| const webpackRequire = getWebpackRequire(); | ||
|
|
||
| if (!webpackRequire) { | ||
| throw new Error( | ||
| 'Unable to access __webpack_require__. Ensure this code runs inside a webpack-compatible runtime.', | ||
| ); | ||
| } | ||
|
|
||
| return webpackRequire; | ||
| } | ||
|
|
||
| export function importWithBundlerIgnore<T = unknown>( | ||
| modulePath: string, | ||
| ): Promise<T> { | ||
| return import( | ||
| /* webpackIgnore: true */ | ||
| /* @vite-ignore */ | ||
| modulePath | ||
| ) as Promise<T>; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.