Skip to content

Commit 98a29c3

Browse files
feat(enhanced): add include/exclude filtering support for shared modules (#3949)
Co-authored-by: Claude <[email protected]>
1 parent 05d5f9b commit 98a29c3

File tree

72 files changed

+3777
-715
lines changed

Some content is hidden

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

72 files changed

+3777
-715
lines changed

.changeset/README.md

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"@module-federation/enhanced": minor
3+
---
4+
5+
feat(enhanced): add include/exclude filtering for shared modules
6+
7+
- Add include/exclude filtering for both ConsumeSharedPlugin and ProvideSharedPlugin
8+
- Support version-based filtering using semantic version ranges (e.g., `include: { version: '^18.0.0' }`)
9+
- Support request pattern filtering with string and RegExp (e.g., `include: { request: /^Button/ }`)
10+
- Add singleton warnings when filters are used to prevent multiple shared instances
11+
- Enhanced type definitions and JSON schema validation for filtering options

CLAUDE.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,4 +253,45 @@ pattern: "const $COMPONENT = () => { $$$ }"
253253
pattern: "getUserData($$$)"
254254
```
255255

256-
This system ensures Claude always leverages parallel task execution, modern tools, and efficient search methods for maximum speed and efficiency across any codebase or request type.
256+
Avaliable pnpm commands in workspace, can run with pnpm [script] -w
257+
258+
```
259+
"nx": "nx",
260+
"commit": "cz",
261+
"docs": "typedoc",
262+
"f": "nx format:write",
263+
"enhanced:jest": "pnpm build && cd packages/enhanced && NODE_OPTIONS=--experimental-vm-modules npx jest test/ConfigTestCases.basictest.js test/unit",
264+
"lint": "nx run-many --target=lint",
265+
"test": "nx run-many --target=test",
266+
"build": "NX_TUI=false nx run-many --target=build --parallel=5 --projects=tag:type:pkg",
267+
"build:pkg": "NX_TUI=false nx run-many --targets=build --projects=tag:type:pkg --skip-nx-cache",
268+
"test:pkg": "NX_TUI=false nx run-many --targets=test --projects=tag:type:pkg --skip-nx-cache",
269+
"lint-fix": "nx format:write --uncommitted",
270+
"trigger-release": "node -e 'import(\"open\").then(open => open.default(\"https://github.com/module-federation/core/actions/workflows/trigger-release.yml\"))'",
271+
"serve:next": "nx run-many --target=serve --all --parallel=3 -exclude='*,!tag:nextjs'",
272+
"app:router:dev": "nx run-many --target=serve --parallel=10 --projects='router-*'",
273+
"app:next-router:dev": "nx run-many --target=serve --projects=next-app-router-4000,next-app-router-4001 --parallel",
274+
"serve:website": "nx run website-new:serve",
275+
"build:website": "nx run website-new:build",
276+
"extract-i18n:website": "nx run website:extract-i18n",
277+
"sync:pullMFTypes": "concurrently \"node ./packages/enhanced/pullts.js\"",
278+
"app:next:dev": "nx run-many --target=serve --configuration=development -p 3000-home,3001-shop,3002-checkout",
279+
"app:next:build": "nx run-many --target=build --parallel=2 --configuration=production -p 3000-home,3001-shop,3002-checkout",
280+
"app:next:prod": "nx run-many --target=serve --configuration=production -p 3000-home,3001-shop,3002-checkout",
281+
"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",
282+
"app:runtime:dev": "nx run-many --target=serve -p 3005-runtime-host,3006-runtime-remote,3007-runtime-remote",
283+
"app:manifest:dev": "NX_TUI=false 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",
284+
"app:manifest:prod": "NX_TUI=false 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",
285+
"app:ts:dev": "nx run-many --target=serve -p react_ts_host,react_ts_nested_remote,react_ts_remote",
286+
"app:component-data-fetch:dev": "NX_TUI=false nx run-many --target=serve --parallel=3 --configuration=development -p modernjs-ssr-data-fetch-provider,modernjs-ssr-data-fetch-provider-csr,modernjs-ssr-data-fetch-host",
287+
"app:modern:dev": "NX_TUI=false nx run-many --target=serve --parallel=10 --configuration=development -p modernjs-ssr-dynamic-nested-remote,modernjs-ssr-dynamic-remote,modernjs-ssr-dynamic-remote-new-version,modernjs-ssr-host,modernjs-ssr-nested-remote,modernjs-ssr-remote,modernjs-ssr-remote-new-version",
288+
"commitlint": "commitlint --edit",
289+
"prepare": "husky install",
290+
"changeset": "changeset",
291+
"build:packages": "npx nx affected -t build --parallel=10 --exclude='*,!tag:type:pkg'",
292+
"changegen": "./changeset-gen.js --path ./packages/runtime && ./changeset-gen.js --path ./packages/runtime-core && ./changeset-gen.js --path ./packages/sdk &&./changeset-gen.js --path ./packages/cli --staged && ./changeset-gen.js --path ./packages/enhanced && ./changeset-gen.js --path ./packages/node && ./changeset-gen.js --path ./packages/data-prefetch && ./changeset-gen.js --path ./packages/nextjs-mf && ./changeset-gen.js --path ./packages/dts-plugin",
293+
"commitgen:staged": "./commit-gen.js --path ./packages --staged",
294+
"commitgen:main": "./commit-gen.js --path ./packages",
295+
"changeset:status": "changeset status",
296+
"generate:schema": "nx run enhanced:generate:schema && nx format:write"
297+
```

INCREMENTAL_PR_PLAN_REVISED.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ compiler.hooks.addRemoteDependency = new SyncHook([...]);
7373
**Size**: Medium (~12 files)
7474
**Risk**: Low
7575
**Type**: Feature
76-
**Feature**: Filter shared modules by version constraints
76+
**Feature**: Filter shared modules by version constraints (FIXED: Now correctly reads actual module versions from package.json instead of comparing version ranges)
7777

7878
**Files to include**:
7979
- `src/lib/sharing/utils.ts` (add `testRequestFilters`, `addSingletonFilterWarning`)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# CI re-trigger: Sun Jul 13 15:45:00 PDT 2025

packages/enhanced/src/declarations/plugins/sharing/ConsumeSharedModule.d.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,30 @@ export type ConsumeOptions = {
5050
* Issuer layer in which the module should be resolved
5151
*/
5252
issuerLayer?: string | null;
53+
/**
54+
* Include filters for consuming shared modules
55+
*/
56+
include?: {
57+
/**
58+
* Version requirement that must be satisfied for the shared module to be included
59+
*/
60+
version?: string;
61+
/**
62+
* Request pattern that must match for the shared module to be included
63+
*/
64+
request?: string | RegExp;
65+
};
66+
/**
67+
* Exclude filters for consuming shared modules
68+
*/
69+
exclude?: {
70+
/**
71+
* Version requirement that if satisfied will exclude the shared module
72+
*/
73+
version?: string;
74+
/**
75+
* Request pattern that if matched will exclude the shared module
76+
*/
77+
request?: string | RegExp;
78+
};
5379
};

packages/enhanced/src/declarations/plugins/sharing/ConsumeSharedPlugin.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ export interface ConsumesObject {
3535
*/
3636
[k: string]: ConsumesConfig | ConsumesItem;
3737
}
38+
39+
export interface IncludeExcludeOptions {
40+
request?: string | RegExp;
41+
version?: string;
42+
fallbackVersion?: string;
43+
}
3844
/**
3945
* Advanced configuration for modules that should be consumed from share scope.
4046
*/
@@ -83,4 +89,7 @@ export interface ConsumesConfig {
8389
* The actual request to use for importing the module. If not specified, the property name/key will be used.
8490
*/
8591
request?: string;
92+
exclude?: IncludeExcludeOptions;
93+
include?: IncludeExcludeOptions;
94+
nodeModulesReconstructedLookup?: boolean;
8695
}

packages/enhanced/src/declarations/plugins/sharing/ProvideSharedPlugin.d.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,30 @@ export interface ProvidesConfig {
7272
* The actual request to use for importing the module. If not specified, the property name/key will be used.
7373
*/
7474
request?: string;
75+
/**
76+
* Include filters for providing shared modules.
77+
*/
78+
include?: {
79+
/**
80+
* Version requirement that must be satisfied for the module to be provided.
81+
*/
82+
version?: string;
83+
/**
84+
* Request pattern that must match for the module to be provided.
85+
*/
86+
request?: string | RegExp;
87+
};
88+
/**
89+
* Exclude filters for providing shared modules.
90+
*/
91+
exclude?: {
92+
/**
93+
* Version requirement that if satisfied will exclude the module from being provided.
94+
*/
95+
version?: string;
96+
/**
97+
* Request pattern that if matched will exclude the module from being provided.
98+
*/
99+
request?: string | RegExp;
100+
};
75101
}

packages/enhanced/src/declarations/plugins/sharing/SharePlugin.d.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,22 @@ export interface SharedConfig {
8787
* The actual request to use for importing the module. Defaults to the property name.
8888
*/
8989
request?: string;
90+
/**
91+
* Filter for the shared module.
92+
*/
93+
exclude?: IncludeExcludeOptions;
94+
/**
95+
* Filter for the shared module.
96+
*/
97+
include?: IncludeExcludeOptions;
98+
/**
99+
* Node modules reconstructed lookup.
100+
*/
101+
nodeModulesReconstructedLookup?: boolean;
102+
}
103+
104+
export interface IncludeExcludeOptions {
105+
request?: string | RegExp;
106+
version?: string;
107+
fallbackVersion?: string;
90108
}

0 commit comments

Comments
 (0)