-
Notifications
You must be signed in to change notification settings - Fork 153
refactor: split federation runtime plugin into separate plugins #803
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
Merged
Merged
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
fa787dc
refactor: split federation runtinme plugin into separate plugins:
jbroma 6a0755c
chore: cjs exports
jbroma 7f9614a
chore: package exports
jbroma 0d08fce
feat: add option to disable injecting runtime plugins
jbroma 3cb567c
feat: make resolver plugin configurable
jbroma 802f2e8
chore: use named exports
jbroma da366bf
test: update tests
jbroma 7d59df9
fix: plugin import naming
jbroma 3a5a119
chore: add changeset
jbroma d79d046
fix: reconfigure package exports
jbroma 21bad2b
chore: remove empty RN condition
jbroma 6d9da6f
fix: add d.ts files with typings
jbroma 73498cb
Merge remote-tracking branch 'origin/main' into refactor/separate-run…
jbroma 86d236a
chore: update tester apps configs
jbroma a59e4d5
fix: use default export
jbroma 1889155
refactor: change to list of default runtime plugins
jbroma 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 @@ | ||
| --- | ||
| "@callstack/repack": minor | ||
| --- | ||
|
|
||
| Refactor FederationRuntimePlugin into two separate plugins for more granular control over the MF2 runtime behaviour (CorePlugin & ResolverPlugin) |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 * from '../dist/modules/ScriptManager'; |
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 * from '../dist/modules/ScriptManager'; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 { default } from '../dist/modules/FederationRuntimePlugins/CorePlugin'; |
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,2 @@ | ||
| import RepackCorePlugin from '../dist/modules/FederationRuntimePlugins/CorePlugin'; | ||
| export default RepackCorePlugin; |
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 { default } from '../dist/modules/FederationRuntimePlugins/ResolverPlugin'; |
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,2 @@ | ||
| import RepackResolverPlugin from '../dist/modules/FederationRuntimePlugins/ResolverPlugin'; | ||
| export default RepackResolverPlugin; |
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 was deleted.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
packages/repack/src/modules/FederationRuntimePlugins/CorePlugin.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,32 @@ | ||
| import type { FederationRuntimePlugin } from '@module-federation/enhanced/runtime'; | ||
| import type * as RepackClient from '../ScriptManager'; | ||
|
|
||
| const RepackCorePlugin: () => FederationRuntimePlugin = () => ({ | ||
| name: 'repack-core-plugin', | ||
| loadEntry: async ({ remoteInfo }) => { | ||
| const client = require('../ScriptManager') as typeof RepackClient; | ||
| const { ScriptManager, getWebpackContext } = client; | ||
| const { entry, entryGlobalName } = remoteInfo; | ||
|
|
||
| try { | ||
| await ScriptManager.shared.loadScript( | ||
| entryGlobalName, | ||
| undefined, | ||
| getWebpackContext(), | ||
| entry | ||
| ); | ||
|
|
||
| // @ts-ignore | ||
| if (!globalThis[entryGlobalName]) { | ||
| throw new Error(); | ||
| } | ||
|
|
||
| // @ts-ignore | ||
| return globalThis[entryGlobalName]; | ||
| } catch { | ||
| console.error(`Failed to load remote entry: ${entryGlobalName}`); | ||
| } | ||
| }, | ||
| }); | ||
|
|
||
| export default RepackCorePlugin; |
55 changes: 55 additions & 0 deletions
55
packages/repack/src/modules/FederationRuntimePlugins/ResolverPlugin.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,55 @@ | ||
| import type { FederationRuntimePlugin } from '@module-federation/enhanced/runtime'; | ||
| import type * as RepackClient from '../ScriptManager'; | ||
|
|
||
| export type RepackResolverPluginConfiguration = | ||
| | Omit<RepackClient.ScriptLocator, 'url'> | ||
| | ((url: string) => Promise<RepackClient.ScriptLocator>); | ||
|
|
||
| const createScriptLocator = async ( | ||
| entryUrl: string, | ||
| config?: RepackResolverPluginConfiguration | ||
| ) => { | ||
| if (typeof config === 'function') { | ||
| const locator = await config(entryUrl); | ||
| return locator; | ||
| } | ||
| if (typeof config === 'object') { | ||
| return { url: entryUrl, ...config }; | ||
| } | ||
| return { url: entryUrl }; | ||
| }; | ||
|
|
||
| const RepackResolverPlugin: ( | ||
| config?: RepackResolverPluginConfiguration | ||
| ) => FederationRuntimePlugin = (config) => ({ | ||
| name: 'repack-resolver-plugin', | ||
| afterResolve(args) { | ||
| const { ScriptManager } = | ||
| require('../ScriptManager') as typeof RepackClient; | ||
| const { remoteInfo } = args; | ||
|
|
||
| ScriptManager.shared.addResolver( | ||
| async (scriptId, caller, referenceUrl) => { | ||
| // entry container | ||
| if (scriptId === remoteInfo.entryGlobalName) { | ||
| const locator = await createScriptLocator(remoteInfo.entry, config); | ||
| return locator; | ||
| } | ||
| // entry chunks | ||
| if (referenceUrl && caller === remoteInfo.entryGlobalName) { | ||
| const publicPath = remoteInfo.entry.split('/').slice(0, -1).join('/'); | ||
| const bundlePath = scriptId + referenceUrl.split(scriptId)[1]; | ||
| const url = publicPath + '/' + bundlePath; | ||
|
|
||
| const locator = await createScriptLocator(url, config); | ||
| return locator; | ||
| } | ||
| }, | ||
| { key: remoteInfo.entryGlobalName } | ||
| ); | ||
|
|
||
| return args; | ||
| }, | ||
| }); | ||
|
|
||
| export default RepackResolverPlugin; |
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
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.