Repository navigation
fix(enhanced): give worker entrypoints the federation runtime entry #5125
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
Open
ScriptedAlchemy
wants to merge
4
commits into
main
Choose a base branch
from
fix/worker-federation-runtime
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ac147b3
test(enhanced): cover federation runtime placement for worker chunks
ScriptedAlchemy 9d310d2
fix(enhanced): give worker entrypoints the federation runtime entry
ScriptedAlchemy 68059ae
fix(enhanced): make AsyncEntrypointRuntimeDependency serializable
ScriptedAlchemy afcbfc3
Merge branch 'main' into fix/worker-federation-runtime
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
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,5 @@ | ||
| --- | ||
| '@module-federation/enhanced': patch | ||
| --- | ||
|
|
||
| Workers created with `new Worker(new URL(...))` and other async entrypoints now get the federation runtime entry in their own runtime chunk, so a remote or shared module loaded from a worker no longer throws on `bundlerRuntime`. Modules hoisted into runtime chunks are only removed from other chunks when every runtime of that chunk received them. |
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
26 changes: 26 additions & 0 deletions
26
packages/enhanced/src/lib/container/runtime/AsyncEntrypointRuntimeDependency.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,26 @@ | ||
| import { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path'; | ||
|
|
||
| const ModuleDependency = require( | ||
| normalizeWebpackPath('webpack/lib/dependencies/ModuleDependency'), | ||
| ) as typeof import('webpack/lib/dependencies/ModuleDependency'); | ||
| const NullDependency = require( | ||
| normalizeWebpackPath('webpack/lib/dependencies/NullDependency'), | ||
| ) as typeof import('webpack/lib/dependencies/NullDependency'); | ||
| const makeSerializable = require( | ||
| normalizeWebpackPath('webpack/lib/util/makeSerializable'), | ||
| ) as typeof import('webpack/lib/util/makeSerializable'); | ||
|
|
||
| class AsyncEntrypointRuntimeDependency extends ModuleDependency { | ||
| static override Template = NullDependency.Template; | ||
|
|
||
| override get type() { | ||
| return 'federation runtime async entrypoint dependency'; | ||
| } | ||
| } | ||
|
|
||
| makeSerializable( | ||
| AsyncEntrypointRuntimeDependency, | ||
| 'enhanced/lib/container/runtime/AsyncEntrypointRuntimeDependency', | ||
| ); | ||
|
|
||
| export default AsyncEntrypointRuntimeDependency; | ||
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
7 changes: 7 additions & 0 deletions
7
packages/enhanced/test/configCases/container/worker-runtime/container.js
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 @@ | ||
| import { label } from './helper.js'; | ||
|
|
||
| export function init() {} | ||
|
|
||
| export function get(request) { | ||
| return Promise.resolve(() => `${label} ${request}`); | ||
| } |
1 change: 1 addition & 0 deletions
1
packages/enhanced/test/configCases/container/worker-runtime/helper.js
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 @@ | ||
| export const label = 'remote'; |
13 changes: 13 additions & 0 deletions
13
packages/enhanced/test/configCases/container/worker-runtime/index.js
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,13 @@ | ||
| const { fileURLToPath } = __non_webpack_require__('url'); | ||
| const { basename } = __non_webpack_require__('path'); | ||
|
|
||
| it('should initialize the federation runtime in a worker chunk', async () => { | ||
| const worker = new Worker(new URL('./worker.js', import.meta.url)); | ||
| __non_webpack_require__(`./${basename(fileURLToPath(worker.url))}`); | ||
| expect(await globalThis.workerRemote).toBe('remote ./x'); | ||
| }); | ||
|
|
||
| it('should keep a hoisted module in a chunk whose runtime did not receive it', async () => { | ||
| __non_webpack_require__('./other.js'); | ||
| expect(await globalThis.otherHelper).toBe('remote'); | ||
| }); |
1 change: 1 addition & 0 deletions
1
packages/enhanced/test/configCases/container/worker-runtime/other.js
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 @@ | ||
| globalThis.otherHelper = import('./helper.js').then((m) => m.label); |
12 changes: 12 additions & 0 deletions
12
packages/enhanced/test/configCases/container/worker-runtime/test.config.js
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,12 @@ | ||
| module.exports = { | ||
| findBundle() { | ||
| return './main.js'; | ||
| }, | ||
| moduleScope(scope) { | ||
| scope.Worker = class Worker { | ||
| constructor(url) { | ||
| this.url = url; | ||
| } | ||
| }; | ||
| }, | ||
| }; |
20 changes: 20 additions & 0 deletions
20
packages/enhanced/test/configCases/container/worker-runtime/webpack.config.js
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,20 @@ | ||
| const { ModuleFederationPlugin } = require('../../../../dist/src'); | ||
|
|
||
| /** @type {import("../../../../").Configuration} */ | ||
| module.exports = { | ||
| entry: { | ||
| main: './index.js', | ||
| other: './other.js', | ||
| }, | ||
| output: { | ||
| filename: '[name].js', | ||
| }, | ||
| plugins: [ | ||
| new ModuleFederationPlugin({ | ||
| name: 'host', | ||
| remotes: { | ||
| remote: 'internal ./container.js', | ||
| }, | ||
| }), | ||
| ], | ||
| }; |
1 change: 1 addition & 0 deletions
1
packages/enhanced/test/configCases/container/worker-runtime/worker.js
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 @@ | ||
| globalThis.workerRemote = import('remote/x').then((m) => m.default); |
22 changes: 22 additions & 0 deletions
22
packages/enhanced/test/unit/container/runtime/AsyncEntrypointRuntimeDependency.test.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,22 @@ | ||
| import { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path'; | ||
| import AsyncEntrypointRuntimeDependency from '../../../../src/lib/container/runtime/AsyncEntrypointRuntimeDependency'; | ||
|
|
||
| const { buffersSerializer } = require( | ||
| normalizeWebpackPath('webpack/lib/util/serialization'), | ||
| ) as typeof import('webpack/lib/util/serialization'); | ||
|
|
||
| describe('AsyncEntrypointRuntimeDependency', () => { | ||
| it('round-trips through the webpack object serializer', async () => { | ||
| const dep = new AsyncEntrypointRuntimeDependency('./federation-entry.js'); | ||
| dep.loc = { name: 'worker' }; | ||
|
|
||
| const data = await buffersSerializer.serialize(dep, {}); | ||
| const restored = await buffersSerializer.deserialize(data, {}); | ||
|
|
||
| expect(restored).toBeInstanceOf(AsyncEntrypointRuntimeDependency); | ||
| expect(restored.request).toBe('./federation-entry.js'); | ||
| expect(restored.type).toBe( | ||
| 'federation runtime async entrypoint dependency', | ||
| ); | ||
| }); | ||
| }); |
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.