Repository navigation
feat(managers): plan the runtime composition and resolve one runtime family #5134
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
18
commits into
rfc5128/03-node-esbuild-runtime
Choose a base branch
from
rfc5128/04-managers-composition
base: rfc5128/03-node-esbuild-runtime
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 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
95cc87e
feat(managers): plan the runtime composition from federation particip…
ScriptedAlchemy bf3f50d
feat(managers): resolve the runtime family, select the mode, render a…
ScriptedAlchemy 25d911e
refactor(managers): name the composition helpers after what they resolve
ScriptedAlchemy bf6f74b
Merge remote-tracking branch 'origin/rfc5128/03-node-esbuild-runtime'…
ScriptedAlchemy 74ef4dd
Merge remote-tracking branch 'origin/rfc5128/03-node-esbuild-runtime'…
ScriptedAlchemy d2ebade
feat(managers): map ModuleFederationPlugin options to a composition p…
ScriptedAlchemy 1d75f2f
Merge remote-tracking branch 'origin/rfc5128/03-node-esbuild-runtime'…
ScriptedAlchemy 4e0a393
fix(managers): check byLayer externals when selecting the runtime mode
ScriptedAlchemy edc79c4
fix(managers): give function externals contextInfo and a failing getR…
ScriptedAlchemy 4a4b4af
fix(managers): wait for the callback of externals that return undefined
ScriptedAlchemy ed9df3e
fix(managers): match graph externals by their import name
ScriptedAlchemy 0568c38
test(managers): type-check the __tests__ directory
ScriptedAlchemy cf7e8b0
Merge remote-tracking branch 'origin/rfc5128/03-node-esbuild-runtime'…
ScriptedAlchemy 63874f3
Merge remote-tracking branch 'origin/rfc5128/03-node-esbuild-runtime'…
ScriptedAlchemy 92392fc
Merge remote-tracking branch 'origin/rfc5128/03-node-esbuild-runtime'…
ScriptedAlchemy 0576af6
Merge remote-tracking branch 'origin/rfc5128/03-node-esbuild-runtime'…
ScriptedAlchemy fb8c199
Merge remote-tracking branch 'origin/rfc5128/03-node-esbuild-runtime'…
ScriptedAlchemy a3a65b4
Merge remote-tracking branch 'origin/rfc5128/03-node-esbuild-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/managers': minor | ||
| --- | ||
|
|
||
| Add pure helpers that plan a composed federation runtime: `planComposition`, `resolveRuntimeFamily`, `selectMode`, `resolveImports`, `renderComposition`, and `checkFederationGraph`. | ||
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,68 @@ | ||
| import { planComposition } from '../src/composition/plan'; | ||
|
|
||
| describe('planComposition', () => { | ||
| it('keeps every handler on when no participant carries options', () => { | ||
| expect( | ||
| planComposition([{ kind: 'needs', needs: ['remotes'] }], 'universal'), | ||
| ).toEqual({ | ||
| shared: true, | ||
| remote: true, | ||
| snapshot: true, | ||
| adapters: ['remotes', 'share-scope'], | ||
| platform: 'universal', | ||
| }); | ||
| }); | ||
|
|
||
| it('turns a handler off only when every options participant disables it', () => { | ||
| const plan = planComposition( | ||
| [ | ||
| { | ||
| kind: 'options', | ||
| disable: { shared: true, snapshot: true }, | ||
| needs: [], | ||
| }, | ||
| { kind: 'options', disable: { shared: true }, needs: [] }, | ||
| { kind: 'needs', needs: [] }, | ||
| ], | ||
| 'web', | ||
| ); | ||
| expect(plan.shared).toBe(false); | ||
| expect(plan.remote).toBe(true); | ||
| expect(plan.snapshot).toBe(true); | ||
| }); | ||
|
|
||
| it('ignores needs participants when voting', () => { | ||
| const plan = planComposition( | ||
| [ | ||
| { kind: 'options', disable: { remote: true }, needs: ['container'] }, | ||
| { kind: 'needs', needs: ['remotes'] }, | ||
| ], | ||
| 'node', | ||
| ); | ||
| expect(plan.remote).toBe(false); | ||
| expect(plan.adapters).toEqual(['remotes', 'container', 'share-scope']); | ||
| }); | ||
|
|
||
| it('drops snapshot when remote is off', () => { | ||
| const plan = planComposition( | ||
| [{ kind: 'options', disable: { remote: true }, needs: [] }], | ||
| 'web', | ||
| ); | ||
| expect(plan.snapshot).toBe(false); | ||
| }); | ||
|
|
||
| it('closes remotes, consumes and container over share-scope in table order', () => { | ||
| expect( | ||
| planComposition( | ||
| [ | ||
| { | ||
| kind: 'needs', | ||
| needs: ['container', 'consumes', 'remotes', 'consumes'], | ||
| }, | ||
| ], | ||
| 'web', | ||
| ).adapters, | ||
| ).toEqual(['remotes', 'consumes', 'container', 'share-scope']); | ||
| expect(planComposition([], 'web').adapters).toEqual([]); | ||
| }); | ||
| }); |
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,59 @@ | ||
| export const ADAPTERS = [ | ||
| 'remotes', | ||
| 'consumes', | ||
| 'container', | ||
| 'share-scope', | ||
| ] as const; | ||
| export type AdapterName = (typeof ADAPTERS)[number]; | ||
|
|
||
| const ADAPTER_REQUIRES: Record<AdapterName, readonly AdapterName[]> = { | ||
| remotes: ['share-scope'], | ||
| consumes: ['share-scope'], | ||
| container: ['share-scope'], | ||
| 'share-scope': [], | ||
| }; | ||
|
|
||
| export type CompositionPlatform = 'web' | 'node' | 'universal'; | ||
|
|
||
| type Handler = 'shared' | 'remote' | 'snapshot'; | ||
|
|
||
| export type Participant = | ||
| | { | ||
| kind: 'options'; | ||
| disable: { [K in Handler]?: true }; | ||
| needs: readonly AdapterName[]; | ||
| } | ||
| | { kind: 'needs'; needs: readonly AdapterName[] }; | ||
|
|
||
| export interface CompositionPlan { | ||
| shared: boolean; | ||
| remote: boolean; | ||
| snapshot: boolean; | ||
| adapters: AdapterName[]; | ||
| platform: CompositionPlatform; | ||
| } | ||
|
|
||
| export function planComposition( | ||
| participants: readonly Participant[], | ||
| platform: CompositionPlatform, | ||
| ): CompositionPlan { | ||
| const voters = participants.filter((p) => p.kind === 'options'); | ||
| const off = (handler: Handler) => | ||
| voters.length > 0 && voters.every((p) => p.disable[handler]); | ||
|
|
||
| const needed = new Set<AdapterName>(); | ||
| const add = (name: AdapterName) => { | ||
| if (needed.has(name)) return; | ||
| needed.add(name); | ||
| ADAPTER_REQUIRES[name].forEach(add); | ||
| }; | ||
| participants.forEach((p) => p.needs.forEach(add)); | ||
|
|
||
| return { | ||
| shared: !off('shared'), | ||
| remote: !off('remote'), | ||
| snapshot: !off('remote') && !off('snapshot'), | ||
| adapters: ADAPTERS.filter((name) => needed.has(name)), | ||
| platform, | ||
| }; | ||
| } |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When this changeset is consumed during a release, the generated changelog will advertise five APIs that users cannot import: a repository-wide search finds no implementations of
resolveRuntimeFamily,selectMode,resolveImports,renderComposition, orcheckFederationGraph, andpackages/managers/src/index.tsexports onlyplanCompositionandADAPTERSfrom this change. Either include and export those helpers or limit the release note to the API actually added.Useful? React with 👍 / 👎.