Skip to content

Commit 687365f

Browse files
feat(enhanced): Layer via composite shareKey (#3415)
1 parent ffdaf0b commit 687365f

File tree

87 files changed

+994
-281
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+994
-281
lines changed

.changeset/ai-hungry-bear.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"@module-federation/enhanced": minor
2+
---
3+
4+
Enhancements to layer handling in module federation tests and configuration.
5+
6+
- Improved handling of `shareKey` for layers within `ConsumeSharedPlugin` and `ProvideSharedPlugin`.
7+
- Conditionally prepend the `shareKey` with the `layer` if applicable.
8+
- Introduced new layer configurations to support more nuanced federation scenarios that consider multiple layers of dependency.
9+
```

.changeset/ai-sleepy-tiger.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@module-federation/runtime": minor
3+
---
4+
5+
- Added a new property 'layer' of type string or null to SharedConfig.
6+
```

.cursorignore

Lines changed: 76 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,78 @@
1-
# Add directories or file patterns to ignore during indexing (e.g. foo/ or *.csv)
2-
./tmp
3-
./scripts
4-
./.git
5-
packages/storybook-addon
6-
packages/core
7-
packages/utilities
8-
packages/typescript
1+
**/.cache/
2+
**/.temp/
3+
**/coverage/
4+
**/*.md
5+
**/*.yaml
6+
**/*/stats.json
7+
**/*.yml
8+
**/.eslintrc*
9+
**/.prettierrc*
10+
**/.swcrc
11+
**/jest.config.*
12+
**/tsconfig.*
13+
apps/
14+
15+
!packages/webpack-bundler-runtime/
16+
!packages/webpack-bundler-runtime/**/*
17+
!packages/sdk/
18+
!packages/sdk/**/*
19+
!packages/enhanced/
20+
!packages/enhanced/**/*
21+
!package.json
22+
!packages/*/package.json
23+
!**/package.json
24+
25+
packages/dts-plugin/
26+
packages/typescript/
927
packages/native-*
10-
apps
11-
**/configCases
12-
**/dist
13-
apps/**
14-
*.snap
15-
*.js
28+
packages/core/
29+
packages/assemble-release-plan/
30+
packages/native-federation-typescript/
31+
packages/esbuild/
32+
**/dist/
1633

34+
webpack/tooling
35+
webpack/setup
36+
webpack/test
37+
webpack/benchmark
38+
.cursorignore
39+
jest.preset.js
40+
babel.config.json
41+
.husky
42+
.husky/_
43+
.husky/commit-msg
44+
.husky/pre-commit
45+
nx.json
46+
tools
47+
tools/scripts
48+
tools/scripts/ci-is-affected.mjs
49+
tools/scripts/publish.mjs
50+
tools/generators
51+
tools/generators/.gitkeep
52+
LICENSE
53+
.nxignore
54+
netlify.toml
55+
renovate.json
56+
.changeset
57+
.changeset/config.json
58+
.npmrc
59+
.cursorrules
60+
.prettierignore
61+
.editorconfig
62+
ai-lint-fix.js
63+
.github
64+
.github/workflows
65+
.github/.github
66+
.github/ISSUE_TEMPLATE
67+
manifest.json
68+
typedoc.json
69+
typedoc.base.json
70+
commitlint.config.js
71+
.eslintignore
72+
commit-gen.js
73+
.vscode
74+
.vscode/settings.json
75+
.vscode/launch.json
76+
main.py
77+
.verdaccio
78+
.verdaccio/htpasswd

.cursorrules

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- when running tests, ALWAYS run "pnpm enhanced:jest" command
2+
- issuerLayer is webpack specific and not used in the runtime code

packages/enhanced/src/lib/sharing/ConsumeSharedPlugin.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ class ConsumeSharedPlugin {
125125
return {
126126
import: item.import === false ? undefined : item.import || request,
127127
shareScope: item.shareScope || options.shareScope || 'default',
128-
shareKey: item.shareKey || request,
128+
shareKey: item.layer
129+
? `(${item.layer})${item.shareKey || request}`
130+
: item.shareKey || request,
129131
requiredVersion:
130132
item.requiredVersion === false
131133
? false

packages/enhanced/src/lib/sharing/ProvideSharedModule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class ProvideSharedModule extends Module {
212212
requiredVersion: this._requiredVersion,
213213
strictVersion: this._strictVersion,
214214
singleton: this._singleton,
215-
layer: this.layer
215+
layer: this.layer,
216216
},
217217
});
218218
return { sources, data, runtimeRequirements };

packages/enhanced/src/lib/sharing/ProvideSharedModuleFactory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class ProvideSharedModuleFactory extends ModuleFactory {
3939
dep.requiredVersion,
4040
dep.strictVersion,
4141
dep.singleton,
42-
dep.layer
42+
dep.layer,
4343
),
4444
});
4545
}

packages/enhanced/src/lib/sharing/ProvideSharedPlugin.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,22 @@ class ProvideSharedPlugin {
9595
};
9696
return result;
9797
},
98-
(item, key) => ({
99-
shareKey: item.shareKey || key,
100-
version: item.version,
101-
shareScope: item.shareScope || options.shareScope || 'default',
102-
eager: !!item.eager,
103-
requiredVersion: item.requiredVersion || false,
104-
strictVersion: item.strictVersion || false,
105-
singleton: item.singleton || false,
106-
layer: item.layer,
107-
request: item.request || key,
108-
}),
98+
(item, key) => {
99+
const request = item.request || key;
100+
return {
101+
shareScope: item.shareScope || options.shareScope || 'default',
102+
shareKey: item.layer
103+
? `(${item.layer})${item.shareKey || request}`
104+
: item.shareKey || request,
105+
version: item.version,
106+
eager: !!item.eager,
107+
requiredVersion: item.requiredVersion,
108+
strictVersion: item.strictVersion,
109+
singleton: !!item.singleton,
110+
layer: item.layer,
111+
request,
112+
};
113+
},
109114
);
110115
this._provides.sort(([a], [b]) => {
111116
if (a < b) return -1;
@@ -265,7 +270,7 @@ class ProvideSharedPlugin {
265270
config.requiredVersion!,
266271
config.strictVersion!,
267272
config.singleton!,
268-
config.layer
273+
config.layer,
269274
),
270275
{
271276
name: undefined,

packages/enhanced/test/ConfigTestCases.template.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const describeCases = (config) => {
6262
for (const category of categories) {
6363
// eslint-disable-next-line no-loop-func
6464
describe(category.name, () => {
65+
// category.tests = [category.tests[1]];
6566
for (const testName of category.tests) {
6667
// eslint-disable-next-line no-loop-func
6768
describe(testName, function () {

packages/enhanced/test/configCases/container/3-layers-full/App.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)