Skip to content

feat(enhanced): support shared module layers #3276

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 91 commits into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
5b107fa
feat(enhanced): support layers
ScriptedAlchemy Nov 17, 2024
062706f
feat(enhanced): support layers
ScriptedAlchemy Nov 17, 2024
cfd9d01
feat(enhanced): layers for consume shared module
ScriptedAlchemy Nov 21, 2024
3e59c55
Merge branch 'main' into layers-support
ScriptedAlchemy Nov 21, 2024
536b110
Merge branch 'main' into layers-support
ScriptedAlchemy Nov 21, 2024
aed08e9
feat(enhanced): add issuerLayer support to consume shared
ScriptedAlchemy Nov 22, 2024
9fb164b
chore(enhanced): update test
ScriptedAlchemy Nov 25, 2024
a9d899c
chore(enhanced): update test
ScriptedAlchemy Nov 25, 2024
33a36d1
feat(enhanced): ConsumeSharedPlugin issuerLayer support
ScriptedAlchemy Nov 25, 2024
f0c5c50
chore: update tests for layer combos
ScriptedAlchemy Nov 25, 2024
578adbb
chore: update tests for layer combos
ScriptedAlchemy Nov 25, 2024
31f08d0
chore: update tests for layer combos
ScriptedAlchemy Nov 25, 2024
066ffa6
feat(enhanced): support direct layer
ScriptedAlchemy Nov 25, 2024
b70eb8d
Merge branch 'main' into layers-support
ScriptedAlchemy Nov 25, 2024
358ba00
fix(enhanced): update share options of share plugin
ScriptedAlchemy Nov 25, 2024
94d72ed
fix(enhanced): update share options of share plugin
ScriptedAlchemy Nov 25, 2024
91dbb12
chore(enhanced): refactor layers tests
ScriptedAlchemy Nov 25, 2024
514cf03
chore(enhanced): remove layer options from provider
ScriptedAlchemy Nov 25, 2024
359b0ca
Merge branch 'main' into consume-share-layers
ScriptedAlchemy Nov 25, 2024
24ef6d0
Delete .cursorrules
ScriptedAlchemy Nov 25, 2024
9d9bff2
feat(enhanced): support layers in consume share
ScriptedAlchemy Nov 26, 2024
40ae817
Merge branch 'main' into consume-share-layers
ScriptedAlchemy Nov 26, 2024
d1c68b3
fix(enhanced): rename requiredLayer to layer
ScriptedAlchemy Dec 2, 2024
22964f8
Merge remote-tracking branch 'origin/consume-share-layers' into consu…
ScriptedAlchemy Dec 2, 2024
9884030
Merge branch 'main' into consume-share-layers
ScriptedAlchemy Dec 2, 2024
3d8fa21
refactor(enhanced): pr review of consume share layering
ScriptedAlchemy Dec 3, 2024
69a2a52
Merge branch 'main' into consume-share-layers
ScriptedAlchemy Dec 3, 2024
04b8ffd
chore: locks
ScriptedAlchemy Dec 3, 2024
7852878
feat(enhanced): add request to consume share (#3307)
ScriptedAlchemy Dec 5, 2024
f35b1b1
Merge branch 'main' into consume-share-layers
ScriptedAlchemy Dec 5, 2024
b8df73e
chore: remove tt
ScriptedAlchemy Dec 9, 2024
b4b5a7b
chore: remove unused share
ScriptedAlchemy Dec 9, 2024
6f8f45e
refactor(enhanced): refactor type locations
ScriptedAlchemy Dec 10, 2024
875f516
feat(enhanced): ProvideSharedPlugin loader layer support (#3334)
ScriptedAlchemy Dec 12, 2024
673f6ca
Merge branch 'main' into consume-share-layers
ScriptedAlchemy Dec 12, 2024
20bae5b
chore: locks
ScriptedAlchemy Dec 12, 2024
a5774c8
chore(enhanced): add share plugin test
ScriptedAlchemy Dec 13, 2024
d44acbd
chore(enhanced): add share plugin test
ScriptedAlchemy Dec 13, 2024
1a33ac7
chore(enhanced): add share plugin test
ScriptedAlchemy Dec 13, 2024
1fc2b05
thing
ScriptedAlchemy Dec 13, 2024
29f6d73
thing
ScriptedAlchemy Dec 13, 2024
22127ee
chore(node): lint
ScriptedAlchemy Dec 13, 2024
8f9fb99
chore(node): lint
ScriptedAlchemy Dec 13, 2024
243f1bc
Merge branch 'main' into consume-share-layers
ScriptedAlchemy Dec 13, 2024
0c665be
feat(enhanced): layers support in module code generation (#3371)
ScriptedAlchemy Dec 29, 2024
ffdaf0b
chore: changeset
ScriptedAlchemy Dec 31, 2024
687365f
feat(enhanced): Layer via composite shareKey (#3415)
ScriptedAlchemy Dec 31, 2024
4ef6efb
Merge branch 'main' into consume-share-layers
ScriptedAlchemy Dec 31, 2024
81d2365
chore: locks
ScriptedAlchemy Dec 31, 2024
6f952fd
Merge branch 'main' into consume-share-layers
ScriptedAlchemy Jan 1, 2025
5fce760
chore: locks
ScriptedAlchemy Jan 1, 2025
1fba24f
fix(enhanced): cache consume module layer
ScriptedAlchemy Jan 2, 2025
7af571f
fix(nextjs-mf): enable app router shares and disable hard fail
ScriptedAlchemy Jan 2, 2025
7a178c0
chore: add host remote app router
ScriptedAlchemy Jan 2, 2025
10f2b73
feat(nextjs-mf): update module share for rsc
ScriptedAlchemy Jan 3, 2025
e122bf4
feat(nextjs-mf): update module share for rsc
ScriptedAlchemy Jan 21, 2025
c3729a7
Merge branch 'main' into consume-share-layers
ScriptedAlchemy Feb 18, 2025
e6a109d
chore: fix schema validation eror
ScriptedAlchemy Feb 18, 2025
ee0726d
chore: fix schema validation errors
ScriptedAlchemy Feb 18, 2025
2fc6497
fix(enhanced): schema validation
ScriptedAlchemy Feb 18, 2025
baaeb27
Merge branch 'main' into consume-share-layers
ScriptedAlchemy Feb 19, 2025
55abb84
chore: locks
ScriptedAlchemy Feb 19, 2025
cfca731
chore: update schema
ScriptedAlchemy Feb 19, 2025
6e6ef06
Merge branch 'main' into consume-share-layers
ScriptedAlchemy Feb 25, 2025
41e1a84
Merge branch 'main' into consume-share-layers
ScriptedAlchemy Mar 12, 2025
aef1bb2
chore: locks
ScriptedAlchemy Mar 12, 2025
fb936d3
chore: fix json schema
ScriptedAlchemy Mar 12, 2025
0ff2e2c
chore: fix json schema
ScriptedAlchemy Mar 12, 2025
42bf94c
chore: fix json schema
ScriptedAlchemy Mar 12, 2025
2c52030
feat(enhanced): implement multiple share scope support (#3524)
ScriptedAlchemy Mar 14, 2025
83261cc
chore: add next with app router
ScriptedAlchemy Mar 14, 2025
fc201b9
Merge branch 'main' into consume-share-layers
ScriptedAlchemy Mar 14, 2025
a3899fc
chore: add next with app router
ScriptedAlchemy Mar 14, 2025
25277fc
chore: update deps
ScriptedAlchemy Mar 14, 2025
b23bb46
Merge branch 'main' into consume-share-layers
ScriptedAlchemy Mar 14, 2025
f0b2404
chore: update deps
ScriptedAlchemy Mar 14, 2025
01b6767
chore: update deps
ScriptedAlchemy Mar 14, 2025
cc658b9
Merge branch 'main' into consume-share-layers
ScriptedAlchemy Mar 14, 2025
6835348
chore: update deps
ScriptedAlchemy Mar 14, 2025
a8b5055
fix: add next apps to workspace
ScriptedAlchemy Mar 14, 2025
dc6d0c0
Merge branch 'main' into consume-share-layers
ScriptedAlchemy Mar 15, 2025
9277303
Merge branch 'main' into consume-share-layers
ScriptedAlchemy Mar 28, 2025
e5f46ab
chore: locks
ScriptedAlchemy Mar 28, 2025
5871f1f
chore: add names to app router apps
ScriptedAlchemy Mar 28, 2025
76903ff
chore: disable AppRouter in nextjs-mf
ScriptedAlchemy Mar 28, 2025
daa8d98
chore: changeset
ScriptedAlchemy Mar 28, 2025
009c1c8
chore: fix schema (#3642)
2heal1 Apr 1, 2025
4907ed0
Merge branch 'main' into consume-share-layers
ScriptedAlchemy Apr 9, 2025
27f5ffe
chore: update locks
ScriptedAlchemy Apr 9, 2025
65cc74f
chore: fix dependson
ScriptedAlchemy Apr 9, 2025
6905c82
chore: fix depend on in nx
ScriptedAlchemy Apr 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/ai-hungry-bear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@module-federation/enhanced": minor
---

Enhancements to layer handling in module federation tests and configuration.

- Introduced new layer configurations to support more nuanced federation scenarios that consider multiple layers of dependency.

9 changes: 9 additions & 0 deletions .changeset/ai-sleepy-fox.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@module-federation/enhanced": patch
---

Refactored module sharing configuration handling.

- Simplified plugin schema for better maintainability
- Improved layer-based module sharing test coverage
- Removed redundant plugin exports
5 changes: 5 additions & 0 deletions .changeset/ai-sleepy-tiger.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@module-federation/runtime": minor
---

- Added a new property 'layer' of type string or null to SharedConfig.
5 changes: 5 additions & 0 deletions .changeset/brown-badgers-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/enhanced': minor
---

support request option on ConsumeSharePlugin. Allows matching requests like the object key of shared does
10 changes: 10 additions & 0 deletions .changeset/rotten-bears-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@module-federation/webpack-bundler-runtime': minor
'@module-federation/runtime-core': minor
'@module-federation/enhanced': minor
'@module-federation/managers': minor
'@module-federation/sdk': minor
'@module-federation/nextjs-mf': patch
---

Support share layers and multiple share scopes
5 changes: 5 additions & 0 deletions .changeset/shy-snails-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/enhanced': minor
---

Layer support for Provide Share Plugin
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# dependencies
node_modules
./webpack-lib
next.js
# IDEs and editors
/.idea
.project
Expand Down Expand Up @@ -71,4 +72,6 @@ packages/enhanced/test/js
!apps/rslib-module/@mf-types/**

**/vite.config.{js,ts,mjs,mts,cjs,cts}.timestamp*
/webpack-lib/

# Federation
**/.federation
1 change: 1 addition & 0 deletions apps/next-app-router/next-app-router-4000/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"name": "app-router-4000",
"private": true,
"scripts": {
"build": "next build",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ module.exports = {
singleQuote: true,
// pnpm doesn't support plugin autoloading
// https://github.com/tailwindlabs/prettier-plugin-tailwindcss#installation
// plugins: ['prettier-plugin-tailwindcss'],
plugins: ['prettier-plugin-tailwindcss'],
};
1 change: 1 addition & 0 deletions apps/next-app-router/next-app-router-4001/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"private": true,
"name": "app-router-4001",
"scripts": {
"build": "next build",
"dev": "NEXT_PRIVATE_LOCAL_WEBPACK=true next dev -p 4001",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ module.exports = {
singleQuote: true,
// pnpm doesn't support plugin autoloading
// https://github.com/tailwindlabs/prettier-plugin-tailwindcss#installation
// plugins: ['prettier-plugin-tailwindcss'],
plugins: ['prettier-plugin-tailwindcss'],
};
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"commit": "cz",
"docs": "typedoc",
"f": "nx format:write",
"enhanced:jest": "pnpm build && cd packages/enhanced && NODE_OPTIONS=--experimental-vm-modules npx jest test/ConfigTestCases.basictest.js test/unit",
"lint": "nx run-many --target=lint",
"test": "nx run-many --target=test",
"build": "nx run-many --target=build --parallel=5 --projects=tag:type:pkg",
Expand All @@ -31,6 +32,8 @@
"lint-fix": "nx format:write --uncommitted",
"trigger-release": "node -e 'import(\"open\").then(open => open.default(\"https://github.com/module-federation/core/actions/workflows/trigger-release.yml\"))'",
"serve:next": "nx run-many --target=serve --all --parallel=3 -exclude='*,!tag:nextjs'",
"app:router:dev": "nx run-many --target=serve --parallel=10 --projects='router-*'",
"app:next-router:dev": "nx run-many --target=serve --projects=next-app-router-4000,next-app-router-4001 --parallel",
"serve:website": "nx run website-new:serve",
"build:website": "nx run website-new:build",
"extract-i18n:website": "nx run website:extract-i18n",
Expand All @@ -40,7 +43,6 @@
"app:next:prod": "nx run-many --target=serve --configuration=production -p 3000-home,3001-shop,3002-checkout",
"app:node:dev": "nx run-many --target=serve --parallel=10 --configuration=development -p node-host,node-local-remote,node-remote,node-dynamic-remote-new-version,node-dynamic-remote",
"app:runtime:dev": "nx run-many --target=serve -p 3005-runtime-host,3006-runtime-remote,3007-runtime-remote",
"app:router:dev": "nx run-many --target=serve --parallel=10 --projects='router-*'",
"app:manifest:dev": "nx run-many --target=serve --configuration=development --parallel=100 -p modernjs,manifest-webpack-host,3009-webpack-provider,3010-rspack-provider,3011-rspack-manifest-provider,3012-rspack-js-entry-provider",
"app:manifest:prod": "nx run-many --target=serve --configuration=production --parallel=100 -p modernjs,manifest-webpack-host,3009-webpack-provider,3010-rspack-provider,3011-rspack-manifest-provider,3012-rspack-js-entry-provider",
"app:ts:dev": "nx run-many --target=serve -p react_ts_host,react_ts_nested_remote,react_ts_remote",
Expand Down Expand Up @@ -90,7 +92,6 @@
"sharp": "^0.33.4",
"storybook": "8.3.5",
"tapable": "2.2.1",
"tsup": "7.2.0",
"typedoc": "0.25.8",
"undici": "5.28.5",
"unplugin": "1.9.0"
Expand Down Expand Up @@ -219,7 +220,7 @@
"terser-webpack-plugin": "^5.3.10",
"ts-jest": "29.1.5",
"tslib": "2.8.1",
"tsup": "7.2.0",
"tsup": "7.3.0",
"typescript": "5.5.2",
"url-loader": "4.1.1",
"verdaccio": "5.29.2",
Expand All @@ -229,7 +230,8 @@
"vitest-fetch-mock": "^0.2.2",
"vue-tsc": "^2.0.26",
"wait-on": "^7.2.0",
"webpack": "5.93.0",
"webpack": "5.94.0",
"webpack-cli": "^5.1.4",
"webpack-virtual-modules": "0.6.2",
"whatwg-fetch": "^3.6.20",
"yargs": "^17.7.2"
Expand Down
30 changes: 18 additions & 12 deletions packages/create-module-federation/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
"targets": {
"build": {
"executor": "nx:run-commands",
"dependsOn": [
{
"target": "build",
"dependencies": true
}
],
"options": {
"parallel": false,
"dependsOn": [
{
"target": "build",
"dependencies": true
}
],
"commands": [
"cd packages/create-module-federation; pnpm run build",
"cp packages/create-module-federation/LICENSE packages/create-module-federation/dist"
Expand All @@ -33,19 +33,25 @@
},
"test": {
"executor": "nx:run-commands",
"dependsOn": [
{
"target": "build",
"dependencies": true
}
],
"options": {
"parallel": false,
"dependsOn": [
{
"target": "build",
"dependencies": true
}
],
"commands": ["echo 'no test'"]
}
},
"pre-release": {
"executor": "nx:run-commands",
"dependsOn": [
{
"target": "build",
"dependencies": true
}
],
"options": {
"parallel": false,
"commands": [
Expand Down
5 changes: 4 additions & 1 deletion packages/enhanced/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export default {
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/packages/enhanced',
rootDir: __dirname,
testMatch: ['<rootDir>/test/*.basictest.js'],
testMatch: [
'<rootDir>/test/*.basictest.js',
'<rootDir>/test/unit/**/*.test.ts',
],

testEnvironment: path.resolve(__dirname, './test/patch-node-env.js'),
setupFilesAfterEnv: ['<rootDir>/test/setupTestFramework.js'],
Expand Down
3 changes: 2 additions & 1 deletion packages/enhanced/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"@module-federation/sdk": "workspace:*",
"@module-federation/cli": "workspace:*",
"btoa": "^1.2.1",
"upath": "2.0.1"
"upath": "2.0.1",
"schema-utils": "^4.3.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
export type ConsumeOptions = {
/**
* fallback request
*/
import?: string | undefined;
/**
* resolved fallback request
*/
importResolved?: string | undefined;
/**
* The actual request to use for importing the module. If not specified, the property name/key will be used.
*/
request?: string;
/**
* global share key
*/
shareKey: string;
/**
* share scope
*/
shareScope: string | string[];
/**
* version requirement
*/
requiredVersion:
| import('webpack/lib/util/semver').SemVerRange
| false
| undefined;
/**
* package name to determine required version automatically
*/
packageName: string;
/**
* don't use shared version even if version isn't valid
*/
strictVersion: boolean;
/**
* use single global version
*/
singleton: boolean;
/**
* include the fallback module in a sync way
*/
eager: boolean;
/**
* Share a specific layer of the module, if the module supports layers
*/
layer?: string | null;
/**
* Issuer layer in which the module should be resolved
*/
issuerLayer?: string | null;
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface ConsumeSharedPluginOptions {
/**
* Share scope name used for all consumed modules (defaults to 'default').
*/
shareScope?: string;
shareScope?: string | string[];
}
/**
* Modules that should be consumed from share scope. Property names are used to match requested modules in this compilation. Relative requests are resolved, module requests are matched unresolved, absolute paths will match resolved requests. A trailing slash will match all requests with this prefix. In this case shareKey must also have a trailing slash.
Expand Down Expand Up @@ -62,7 +62,7 @@ export interface ConsumesConfig {
/**
* Share scope name.
*/
shareScope?: string;
shareScope?: string | string[];
/**
* Allow only a single version of the shared module in share scope (disabled by default).
*/
Expand All @@ -71,4 +71,16 @@ export interface ConsumesConfig {
* Do not accept shared module if version is not valid (defaults to yes, if local fallback module is available and shared module is not a singleton, otherwise no, has no effect if there is no required version specified).
*/
strictVersion?: boolean;
/**
* Issuer layer in which the module should be resolved.
*/
issuerLayer?: string;
/**
* Layer for the shared module.
*/
layer?: string;
/**
* The actual request to use for importing the module. If not specified, the property name/key will be used.
*/
request?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface ProvideSharedPluginOptions {
/**
* Share scope name used for all provided modules (defaults to 'default').
*/
shareScope?: string;
shareScope?: string | string[];
}
/**
* Modules that should be provided as shared modules to the share scope. Property names are used as share keys.
Expand All @@ -47,7 +47,7 @@ export interface ProvidesConfig {
/**
* Share scope name.
*/
shareScope?: string;
shareScope?: string | string[];
/**
* Version of the provided module. Will replace lower matching versions, but not higher.
*/
Expand All @@ -64,4 +64,12 @@ export interface ProvidesConfig {
* Do not accept shared module if version is not valid (defaults to yes, if local fallback module is available and shared module is not a singleton, otherwise no, has no effect if there is no required version specified).
*/
strictVersion?: boolean;
/**
* Layer for the shared module.
*/
layer?: string;
/**
* The actual request to use for importing the module. If not specified, the property name/key will be used.
*/
request?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface SharePluginOptions {
/**
* Share scope name used for all shared modules (defaults to 'default').
*/
shareScope?: string;
shareScope?: string | string[];
/**
* Modules that should be shared in the share scope. When provided, property names are used to match requested modules in this compilation.
*/
Expand Down Expand Up @@ -62,7 +62,7 @@ export interface SharedConfig {
/**
* Share scope name.
*/
shareScope?: string;
shareScope?: string | string[];
/**
* Allow only a single version of the shared module in share scope (disabled by default).
*/
Expand All @@ -75,4 +75,16 @@ export interface SharedConfig {
* Version of the provided module. Will replace lower matching versions, but not higher.
*/
version?: false | string;
/**
* Issuer layer in which the module should be resolved.
*/
issuerLayer?: string;
/**
* Layer for the shared module.
*/
layer?: string;
/**
* The actual request to use for importing the module. Defaults to the property name.
*/
request?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ const { Dependency } = require(
class ContainerEntryDependency extends Dependency {
public name: string;
public exposes: [string, ExposeOptions][];
public shareScope: string;
public shareScope: string | string[];
public injectRuntimeEntry: string;
public dataPrefetch: containerPlugin.ContainerPluginOptions['dataPrefetch'];

/**
* @param {string} name entry name
* @param {[string, ExposeOptions][]} exposes list of exposed modules
* @param {string} shareScope name of the share scope
* @param {string|string[]} shareScope name of the share scope
* @param {string[]} injectRuntimeEntry the path of injectRuntime file.
* @param {containerPlugin.ContainerPluginOptions['dataPrefetch']} dataPrefetch whether enable dataPrefetch
*/
constructor(
name: string,
exposes: [string, ExposeOptions][],
shareScope: string,
shareScope: string | string[],
injectRuntimeEntry: string,
dataPrefetch: containerPlugin.ContainerPluginOptions['dataPrefetch'],
) {
Expand Down
Loading