Skip to content

feat(enhanced): add include/exclude filtering support for shared modules #3949

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 15 commits into from
Jul 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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: 0 additions & 8 deletions .changeset/README.md

This file was deleted.

11 changes: 11 additions & 0 deletions .changeset/fix-version-filtering-bug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@module-federation/enhanced": minor
---

feat(enhanced): add include/exclude filtering for shared modules

- Add include/exclude filtering for both ConsumeSharedPlugin and ProvideSharedPlugin
- Support version-based filtering using semantic version ranges (e.g., `include: { version: '^18.0.0' }`)
- Support request pattern filtering with string and RegExp (e.g., `include: { request: /^Button/ }`)
- Add singleton warnings when filters are used to prevent multiple shared instances
- Enhanced type definitions and JSON schema validation for filtering options
43 changes: 42 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,45 @@ pattern: "const $COMPONENT = () => { $$$ }"
pattern: "getUserData($$$)"
```

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.
Avaliable pnpm commands in workspace, can run with pnpm [script] -w

```
"nx": "nx",
"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_TUI=false nx run-many --target=build --parallel=5 --projects=tag:type:pkg",
"build:pkg": "NX_TUI=false nx run-many --targets=build --projects=tag:type:pkg --skip-nx-cache",
"test:pkg": "NX_TUI=false nx run-many --targets=test --projects=tag:type:pkg --skip-nx-cache",
"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",
"sync:pullMFTypes": "concurrently \"node ./packages/enhanced/pullts.js\"",
"app:next:dev": "nx run-many --target=serve --configuration=development -p 3000-home,3001-shop,3002-checkout",
"app:next:build": "nx run-many --target=build --parallel=2 --configuration=production -p 3000-home,3001-shop,3002-checkout",
"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: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",
"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",
"app:ts:dev": "nx run-many --target=serve -p react_ts_host,react_ts_nested_remote,react_ts_remote",
"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",
"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",
"commitlint": "commitlint --edit",
"prepare": "husky install",
"changeset": "changeset",
"build:packages": "npx nx affected -t build --parallel=10 --exclude='*,!tag:type:pkg'",
"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",
"commitgen:staged": "./commit-gen.js --path ./packages --staged",
"commitgen:main": "./commit-gen.js --path ./packages",
"changeset:status": "changeset status",
"generate:schema": "nx run enhanced:generate:schema && nx format:write"
```
2 changes: 1 addition & 1 deletion INCREMENTAL_PR_PLAN_REVISED.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ compiler.hooks.addRemoteDependency = new SyncHook([...]);
**Size**: Medium (~12 files)
**Risk**: Low
**Type**: Feature
**Feature**: Filter shared modules by version constraints
**Feature**: Filter shared modules by version constraints (FIXED: Now correctly reads actual module versions from package.json instead of comparing version ranges)

**Files to include**:
- `src/lib/sharing/utils.ts` (add `testRequestFilters`, `addSingletonFilterWarning`)
Expand Down
1 change: 1 addition & 0 deletions packages/enhanced/.github-ci-retrigger
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# CI re-trigger: Sun Jul 13 15:45:00 PDT 2025
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,30 @@ export type ConsumeOptions = {
* Issuer layer in which the module should be resolved
*/
issuerLayer?: string | null;
/**
* Include filters for consuming shared modules
*/
include?: {
/**
* Version requirement that must be satisfied for the shared module to be included
*/
version?: string;
/**
* Request pattern that must match for the shared module to be included
*/
request?: string | RegExp;
};
/**
* Exclude filters for consuming shared modules
*/
exclude?: {
/**
* Version requirement that if satisfied will exclude the shared module
*/
version?: string;
/**
* Request pattern that if matched will exclude the shared module
*/
request?: string | RegExp;
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ export interface ConsumesObject {
*/
[k: string]: ConsumesConfig | ConsumesItem;
}

export interface IncludeExcludeOptions {
request?: string | RegExp;
version?: string;
fallbackVersion?: string;
}
/**
* Advanced configuration for modules that should be consumed from share scope.
*/
Expand Down Expand Up @@ -83,4 +89,7 @@ export interface ConsumesConfig {
* The actual request to use for importing the module. If not specified, the property name/key will be used.
*/
request?: string;
exclude?: IncludeExcludeOptions;
include?: IncludeExcludeOptions;
nodeModulesReconstructedLookup?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,30 @@ export interface ProvidesConfig {
* The actual request to use for importing the module. If not specified, the property name/key will be used.
*/
request?: string;
/**
* Include filters for providing shared modules.
*/
include?: {
/**
* Version requirement that must be satisfied for the module to be provided.
*/
version?: string;
/**
* Request pattern that must match for the module to be provided.
*/
request?: string | RegExp;
};
/**
* Exclude filters for providing shared modules.
*/
exclude?: {
/**
* Version requirement that if satisfied will exclude the module from being provided.
*/
version?: string;
/**
* Request pattern that if matched will exclude the module from being provided.
*/
request?: string | RegExp;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,22 @@ export interface SharedConfig {
* The actual request to use for importing the module. Defaults to the property name.
*/
request?: string;
/**
* Filter for the shared module.
*/
exclude?: IncludeExcludeOptions;
/**
* Filter for the shared module.
*/
include?: IncludeExcludeOptions;
/**
* Node modules reconstructed lookup.
*/
nodeModulesReconstructedLookup?: boolean;
}

export interface IncludeExcludeOptions {
request?: string | RegExp;
version?: string;
fallbackVersion?: string;
}
Loading