Skip to content

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

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

Open
wants to merge 19 commits into
base: feat/enhanced-hoist-container-refs
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
378c980
feat(enhanced): add include/exclude filtering support for shared modules
ScriptedAlchemy Jul 12, 2025
c84ddbe
ci: retrigger CI workflow
ScriptedAlchemy Jul 12, 2025
8184a92
fix(modernjs): add explicit return type to SSRLiveReload function
ScriptedAlchemy Jul 12, 2025
ebb4268
chore: retrigger CI for infrastructure failure
ScriptedAlchemy Jul 13, 2025
2840932
fix(rsbuild-plugin): correct build configuration
ScriptedAlchemy Jul 14, 2025
14b9c25
feat(enhanced): add include/exclude filtering support to share plugin
ScriptedAlchemy Jul 14, 2025
bd1f99c
feat(enhanced): implement version-based filtering for ProvideSharedPl…
ScriptedAlchemy Jul 14, 2025
d525d7a
chore: remove consume-filters test directory that doesn't belong to s…
ScriptedAlchemy Jul 14, 2025
9bab6fb
chore: remove utils
ScriptedAlchemy Jul 14, 2025
440216b
fix: resolve merge conflicts with feat/enhanced-hoist-container-refs
ScriptedAlchemy Jul 16, 2025
cad05e6
fix: prevent infinite recursion in importNodeModule functions
ScriptedAlchemy Jul 16, 2025
79db581
refactor: use importNodeModule directly with caching protection
ScriptedAlchemy Jul 16, 2025
c3824be
refactor: simplify importModuleDynamically to use cached importNodeMo…
ScriptedAlchemy Jul 16, 2025
f69e51d
fix: restore preferred use of vm.constants.USE_MAIN_CONTEXT_DEFAULT_L…
ScriptedAlchemy Jul 16, 2025
6dadff8
fix: clear nodeRuntimeImportCache between tests to prevent interference
ScriptedAlchemy Jul 16, 2025
e06609a
refactor: normalize export pattern for nodeRuntimeImportCache
ScriptedAlchemy Jul 16, 2025
a1e7b2c
Merge branch 'feat/enhanced-hoist-container-refs' into feat/basic-sha…
ScriptedAlchemy Jul 16, 2025
a7cf276
feat: upgrade NX to 21.2.3, Storybook to 9.0.9, and TypeScript to 5.8…
ScriptedAlchemy Jul 16, 2025
186fbd6
chore: merge main branch and resolve conflicts
ScriptedAlchemy Jul 16, 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
13 changes: 13 additions & 0 deletions .changeset/feat-share-filtering.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"@module-federation/enhanced": minor
---

feat: add include/exclude filtering support for shared modules

- Add testRequestFilters and addSingletonFilterWarning utilities
- Update ConsumeSharedPlugin with version and request filtering
- Update ProvideSharedPlugin with version and request filtering
- Update schemas to include include/exclude filter properties
- Add comprehensive unit tests for filtering functionality
- Add config test cases for consume and provide filtering

36 changes: 36 additions & 0 deletions .changeset/nx-upgrade-21-2-3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
"@module-federation/runtime": patch
"@module-federation/enhanced": patch
"@module-federation/rspack": patch
"@module-federation/webpack-bundler-runtime": patch
"@module-federation/sdk": patch
"@module-federation/runtime-tools": patch
"@module-federation/managers": patch
"@module-federation/manifest": patch
"@module-federation/dts-plugin": patch
"@module-federation/third-party-dts-extractor": patch
"@module-federation/devtools": patch
"@module-federation/bridge-react": patch
"@module-federation/bridge-vue3": patch
"@module-federation/bridge-shared": patch
"@module-federation/bridge-react-webpack-plugin": patch
"@module-federation/modern-js": patch
"@module-federation/retry-plugin": patch
"@module-federation/data-prefetch": patch
"@module-federation/rsbuild-plugin": patch
"@module-federation/error-codes": patch
"@module-federation/inject-external-runtime-core-plugin": patch
"@module-federation/runtime-core": patch
"create-module-federation": patch
"@module-federation/cli": patch
"@module-federation/rspress-plugin": patch
---

chore: upgrade NX to 21.2.3, Storybook to 9.0.9, and TypeScript to 5.8.3

- Upgraded NX from 21.0.3 to 21.2.3 with workspace configuration updates
- Migrated Storybook from 8.3.5 to 9.0.9 with updated configurations and automigrations
- Upgraded TypeScript from 5.7.3 to 5.8.3 with compatibility fixes
- Fixed package exports and type declaration paths across all packages
- Resolved module resolution issues and TypeScript compatibility problems
- Updated build configurations and dependencies to support latest versions
6 changes: 3 additions & 3 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ jobs:
- name: Print Number of CPU Cores
run: nproc

- name: Build SDK with skip cache to ensure workspace deps available
run: npx nx build sdk --skip-nx-cache

- name: Run Build for All
run: npx nx run-many --targets=build --projects=tag:type:pkg --parallel=4

Expand All @@ -76,6 +73,9 @@ jobs:
fi
done

- name: Warm Nx Cache
run: npx nx run-many --targets=build --projects=tag:type:pkg --parallel=4

- name: Run Affected Test
uses: nick-fields/retry@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion apps/esbuild/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"build:remote": "node build/build-mfe1.js",
"build:host": "node build/build-shell.js",
"build": "rm -rf ./node_modules/.cache && npm run build:remote && npm run build:host",
"build": "npm run build:remote && npm run build:host",
"watch": "concurrently \"npm run build:remote -- --watch\" \"npm run build:host -- --watch\"",
"start:remote": "live-server dist/mfe1 --port=3001 --cors",
"start:host": "live-server dist/shell --port=3000",
Expand Down
6 changes: 5 additions & 1 deletion apps/reactStorybook/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"extends": ["plugin:@nx/react", "../../.eslintrc.json"],
"extends": [
"plugin:@nx/react",
"../../.eslintrc.json",
"plugin:storybook/recommended"
],
"ignorePatterns": ["!**/*"],
"overrides": [
{
Expand Down
16 changes: 11 additions & 5 deletions apps/reactStorybook/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
const { dirname, join } = require('node:path');

const nxModuleFederationConfig = require('../module-federation.config');

module.exports = {
stories: ['../src/app/**/*.mdx', '../src/app/**/*.stories.@(js|jsx|ts|tsx)'],

addons: [
'@storybook/addon-essentials',
'@nx/react/plugins/storybook',
getAbsolutePath('@nx/react/plugins/storybook'),
{
name: '@module-federation/storybook-addon',
name: getAbsolutePath('@module-federation/storybook-addon'),
options: {
nxModuleFederationConfig: { ...nxModuleFederationConfig },
},
},
'@chromatic-com/storybook',
getAbsolutePath('@chromatic-com/storybook'),
getAbsolutePath('@storybook/addon-docs'),
],

framework: {
name: '@storybook/nextjs',
name: getAbsolutePath('@storybook/nextjs'),
options: {},
},

Expand All @@ -30,3 +32,7 @@ module.exports = {
// To customize your webpack configuration you can use the webpackFinal field.
// Check https://storybook.js.org/docs/react/builders/webpack#extending-storybooks-webpack-config
// and https://nx.dev/packages/storybook/documents/custom-builder-configs

function getAbsolutePath(value) {
return dirname(require.resolve(join(value, 'package.json')));
}
2 changes: 1 addition & 1 deletion apps/reactStorybook/src/app/RemoteButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Suspense } from 'react';
import { Meta, Story } from '@storybook/react';
import { Meta, Story } from '@storybook/nextjs';

// @ts-ignore
const LazyButton = React.lazy(() => import('reactRemoteUI/Button'));
Expand Down
2 changes: 1 addition & 1 deletion apps/rslib-module/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const config: StorybookConfig = {
},
},
{
name: '@module-federation/storybook-addon/preset',
name: getAbsolutePath('@module-federation/storybook-addon/preset'),
options: {
remotes: {
'rslib-module':
Expand Down
54 changes: 25 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
}
},
"dependencies": {
"@storybook/addon-interactions": "8.6.12",
"adm-zip": "0.5.16",
"ansi-colors": "4.1.3",
"antd": "5.19.1",
Expand All @@ -89,7 +88,7 @@
"react-router-dom": "6.26.2",
"regenerator-runtime": "0.14.1",
"sharp": "^0.33.4",
"storybook": "8.3.5",
"storybook": "9.0.9",
"tapable": "2.2.1",
"typedoc": "0.25.8",
"undici": "5.28.5",
Expand All @@ -107,24 +106,24 @@
"@commitlint/cz-commitlint": "19.5.0",
"@fontsource/roboto": "5.1.0",
"@fontsource/roboto-mono": "5.1.0",
"@nx/cypress": "21.0.3",
"@nx/devkit": "21.0.3",
"@nx/esbuild": "21.0.3",
"@nx/eslint": "21.0.3",
"@nx/eslint-plugin": "21.0.3",
"@nx/express": "21.0.3",
"@nx/jest": "21.0.3",
"@nx/js": "21.0.3",
"@nx/module-federation": "21.0.3",
"@nx/next": "21.0.3",
"@nx/node": "21.0.3",
"@nx/react": "21.0.3",
"@nx/rollup": "21.0.3",
"@nx/rspack": "21.0.3",
"@nx/storybook": "21.0.3",
"@nx/vite": "21.0.3",
"@nx/web": "21.0.3",
"@nx/webpack": "21.0.3",
"@nx/cypress": "21.2.3",
"@nx/devkit": "21.2.3",
"@nx/esbuild": "21.2.3",
"@nx/eslint": "21.2.3",
"@nx/eslint-plugin": "21.2.3",
"@nx/express": "21.2.3",
"@nx/jest": "21.2.3",
"@nx/js": "21.2.3",
"@nx/module-federation": "21.2.3",
"@nx/next": "21.2.3",
"@nx/node": "21.2.3",
"@nx/react": "21.2.3",
"@nx/rollup": "21.2.3",
"@nx/rspack": "21.2.3",
"@nx/storybook": "21.2.3",
"@nx/vite": "21.2.3",
"@nx/web": "21.2.3",
"@nx/webpack": "21.2.3",
"@pmmmwh/react-refresh-webpack-plugin": "0.5.15",
"@rollup/plugin-alias": "5.1.1",
"@rollup/plugin-replace": "6.0.1",
Expand All @@ -135,12 +134,7 @@
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^11.0.1",
"@semantic-release/npm": "^11.0.0",
"@storybook/addon-essentials": "8.6.12",
"@storybook/core-common": "8.6.12",
"@storybook/core-server": "8.6.12",
"@storybook/nextjs": "8.6.12",
"@storybook/node-logger": "8.1.11",
"@storybook/react": "8.6.12",
"@storybook/nextjs": "9.0.9",
"@svgr/webpack": "8.1.0",
"@swc-node/register": "1.10.10",
"@swc/cli": "0.6.0",
Expand Down Expand Up @@ -203,7 +197,7 @@
"mime-types": "2.1.35",
"msw": "^1.2.1",
"node-fetch": "~3.3.2",
"nx": "21.0.3",
"nx": "21.2.3",
"open": "^10.1.0",
"postcss-calc": "9.0.1",
"postcss-custom-properties": "13.3.12",
Expand All @@ -223,7 +217,7 @@
"ts-jest": "29.1.5",
"tslib": "2.8.1",
"tsup": "7.3.0",
"typescript": "5.7.3",
"typescript": "5.8.3",
"url-loader": "4.1.1",
"verdaccio": "6.1.2",
"vite": "6.3.5",
Expand All @@ -236,7 +230,9 @@
"webpack-cli": "^5.1.4",
"webpack-virtual-modules": "0.6.2",
"whatwg-fetch": "^3.6.20",
"yargs": "^17.7.2"
"yargs": "^17.7.2",
"eslint-plugin-storybook": "9.0.9",
"@storybook/addon-docs": "9.0.17"
},
"config": {
"commitizen": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ import {
} from '../constant';

import type { MF_DATA_FETCH_MAP_VALUE } from '../types';
import type { FederationRuntimePlugin } from '@module-federation/runtime';
import type { ModuleFederationRuntimePlugin } from '@module-federation/runtime';

const autoFetchData: () => FederationRuntimePlugin = () => {
const autoFetchData: () => ModuleFederationRuntimePlugin = () => {
initDataFetchMap();
injectDataFetch();
return {
name: 'auto-fetch-data-plugin',
afterLoadSnapshot(args) {
afterLoadSnapshot(args: any) {
const { id, moduleInfo, remoteSnapshot, host } = args;
if (typeof id === 'string' && isDataLoaderExpose(id)) {
return args;
Expand Down Expand Up @@ -68,7 +68,7 @@ const autoFetchData: () => FederationRuntimePlugin = () => {
const hasSSRAsset = Boolean(remoteSnapshot.ssrRemoteEntry);
const hasDataFetchClient = Boolean(
remoteSnapshot.modules.find(
(module) =>
(module: any) =>
module.moduleName === `${dataFetchName}${DATA_FETCH_CLIENT_SUFFIX}`,
),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {
ModuleFederation,
FederationRuntimePlugin,
ModuleFederationRuntimePlugin,
} from '@module-federation/runtime';
import {
createLazyComponent,
Expand All @@ -24,7 +24,7 @@ declare module '@module-federation/runtime-core' {
}
}

export function lazyLoadComponentPlugin(): FederationRuntimePlugin {
export function lazyLoadComponentPlugin(): ModuleFederationRuntimePlugin {
return {
name: 'lazy-load-component-plugin',
apply(instance: ModuleFederation) {
Expand Down
2 changes: 1 addition & 1 deletion packages/bridge/bridge-react/src/remote/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
RemoteModule,
} from '../types';

type LazyRemoteComponentInfo<T, E extends keyof T> = RemoteComponentParams<T>;
type LazyRemoteComponentInfo<T, _E extends keyof T> = RemoteComponentParams<T>;

function createLazyRemoteComponent<
T = Record<string, unknown>,
Expand Down
19 changes: 13 additions & 6 deletions packages/chrome-devtools/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
import { createRequire } from 'node:module';
import { dirname, join } from 'node:path';
import type { StorybookConfig } from '@modern-js/storybook';

const require = createRequire(import.meta.url);

const config: StorybookConfig = {
stories: ['../stories/**/*.stories.@(js|jsx|ts|tsx)'],
addons: ['@storybook/addon-essentials', '@chromatic-com/storybook'],
addons: [
getAbsolutePath('@chromatic-com/storybook'),
getAbsolutePath('@storybook/addon-docs'),
],

framework: {
name: '@modern-js/storybook',
name: getAbsolutePath('@modern-js/storybook'),
options: {
bundler: 'webpack',
},
},

docs: {
autodocs: true,
},
};

export default config;

function getAbsolutePath(value: string): any {
return dirname(require.resolve(join(value, 'package.json')));
}
1 change: 0 additions & 1 deletion packages/chrome-devtools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
"@modern-js/tsconfig": "2.68.2",
"@module-federation/runtime": "workspace:*",
"@playwright/test": "1.49.1",
"@storybook/addon-essentials": "^8",
"@types/chrome": "^0.0.272",
"@types/dagre": "^0.7.52",
"@types/jest": "~29.2.4",
Expand Down
Loading