Skip to content

Commit 20c19d7

Browse files
chore: create patch
1 parent a0ca93f commit 20c19d7

31 files changed

+1717
-949
lines changed

.vscode/launch.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": []
4+
}

apps/3000-home/next-env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
/// <reference types="next/image-types/global" />
33

44
// NOTE: This file should not be edited
5-
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
5+
// see https://nextjs.org/docs/pages/api-reference/config/typescript for more information.

apps/3000-home/next.config.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
1-
const { withNx } = require('@nx/next/plugins/with-nx');
21
const NextFederationPlugin = require('@module-federation/nextjs-mf');
32

4-
/**
5-
* @type {import('@nx/next/plugins/with-nx').WithNxOptions}
6-
**/
73
const nextConfig = {
8-
nx: {
9-
// Set this to true if you would like to to use SVGR
10-
// See: https://github.com/gregberge/svgr
11-
svgr: false,
12-
},
134
webpack(config, options) {
145
const { isServer } = options;
156
config.watchOptions = {
@@ -68,4 +59,4 @@ const nextConfig = {
6859
},
6960
};
7061

71-
module.exports = withNx(nextConfig);
62+
module.exports = nextConfig;

apps/3000-home/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77
"antd": "5.19.1",
88
"lodash": "4.17.21",
99
"next": "15.4.0",
10-
"react": "19.1.0"
10+
"react": "19.1.0",
11+
"react-dom": "19.1.0",
12+
"webpack": "5.99.9"
1113
},
1214
"devDependencies": {
1315
"@module-federation/nextjs-mf": "workspace:*",
14-
"@module-federation/runtime": "workspace:*",
15-
"@module-federation/utilities": "workspace:*"
16+
"@module-federation/runtime": "latest"
1617
},
1718
"scripts": {
1819
"start": "next start",
20+
"dev": "NEXT_PRIVATE_LOCAL_WEBPACK=true next dev",
1921
"build": "pnpm exec next telemetry disable && NEXT_PRIVATE_LOCAL_WEBPACK=true next build"
2022
}
2123
}

apps/3000-home/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": "../../tsconfig.base.json",
2+
"extends": "../../../tsconfig.base.json",
33
"compilerOptions": {
44
"target": "es2017",
55
"jsx": "preserve",

apps/3001-shop/next-env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
/// <reference types="next/image-types/global" />
33

44
// NOTE: This file should not be edited
5-
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
5+
// see https://nextjs.org/docs/pages/api-reference/config/typescript for more information.

apps/3001-shop/next.config.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
const { withNx } = require('@nx/next/plugins/with-nx');
21
const NextFederationPlugin = require('@module-federation/nextjs-mf');
3-
/**
4-
* @type {import('@nx/next/plugins/with-nx').WithNxOptions}
5-
**/
2+
63
const nextConfig = {
7-
nx: {
8-
// Set this to true if you would like to to use SVGR
9-
// See: https://github.com/gregberge/svgr
10-
svgr: false,
11-
},
124
webpack(config, options) {
135
const { isServer } = options;
146
config.watchOptions = {
@@ -54,4 +46,4 @@ const nextConfig = {
5446
},
5547
};
5648

57-
module.exports = withNx(nextConfig);
49+
module.exports = nextConfig;

apps/3001-shop/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
"antd": "5.19.1",
88
"lodash": "4.17.21",
99
"next": "15.4.0",
10-
"react": "19.1.0"
10+
"react": "19.1.0",
11+
"react-dom": "19.1.0"
1112
},
1213
"devDependencies": {
1314
"@module-federation/nextjs-mf": "workspace:*",
1415
"@module-federation/runtime": "workspace:*",
15-
"@module-federation/sdk": "workspace:*",
16-
"@module-federation/utilities": "workspace:*"
16+
"@module-federation/sdk": "workspace:*"
1717
},
1818
"scripts": {
19+
"dev": "NEXT_PRIVATE_LOCAL_WEBPACK=true next dev",
1920
"start": "next start",
2021
"build": "NEXT_PRIVATE_LOCAL_WEBPACK=true next build"
2122
}

apps/3001-shop/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": "../../tsconfig.base.json",
2+
"extends": "../../../tsconfig.base.json",
33
"compilerOptions": {
44
"target": "es2017",
55
"jsx": "preserve",

apps/3002-checkout/next-env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
/// <reference types="next/image-types/global" />
33

44
// NOTE: This file should not be edited
5-
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
5+
// see https://nextjs.org/docs/pages/api-reference/config/typescript for more information.

apps/3002-checkout/next.config.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
1-
const { withNx } = require('@nx/next/plugins/with-nx');
21
const NextFederationPlugin = require('@module-federation/nextjs-mf');
32

4-
/**
5-
* @type {import('@nx/next/plugins/with-nx').WithNxOptions}
6-
**/
73
const nextConfig = {
8-
nx: {
9-
// Set this to true if you would like to to use SVGR
10-
// See: https://github.com/gregberge/svgr
11-
svgr: false,
12-
},
134
webpack(config, options) {
145
const { isServer } = options;
156
config.watchOptions = {
@@ -54,4 +45,4 @@ const nextConfig = {
5445
},
5546
};
5647

57-
module.exports = withNx(nextConfig);
48+
module.exports = nextConfig;

apps/3002-checkout/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
"antd": "5.19.1",
88
"lodash": "4.17.21",
99
"next": "15.4.0",
10-
"react": "19.1.0"
10+
"react": "19.1.0",
11+
"react-dom": "19.1.0"
1112
},
1213
"devDependencies": {
1314
"@module-federation/nextjs-mf": "workspace:*",
1415
"@module-federation/runtime": "workspace:*",
15-
"@module-federation/sdk": "workspace:*",
16-
"@module-federation/utilities": "workspace:*"
16+
"@module-federation/sdk": "workspace:*"
1717
},
1818
"scripts": {
19+
"dev": "NEXT_PRIVATE_LOCAL_WEBPACK=true next dev",
1920
"start": "next start",
2021
"build": "NEXT_PRIVATE_LOCAL_WEBPACK=true next build"
2122
}

apps/3002-checkout/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": "../../tsconfig.base.json",
2+
"extends": "../../../tsconfig.base.json",
33
"compilerOptions": {
44
"target": "es2017",
55
"jsx": "preserve",

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"build:website": "nx run website-new:build",
3939
"extract-i18n:website": "nx run website:extract-i18n",
4040
"sync:pullMFTypes": "concurrently \"node ./packages/enhanced/pullts.js\"",
41-
"app:next:dev": "nx run-many --target=serve --configuration=development -p 3000-home,3001-shop,3002-checkout",
41+
"app:next:dev": "NX_TUI=false nx run-many --target=serve --configuration=development -p 3000-home,3001-shop,3002-checkout",
4242
"app:next:build": "nx run-many --target=build --parallel=2 --configuration=production -p 3000-home,3001-shop,3002-checkout",
4343
"app:next:prod": "nx run-many --target=serve --configuration=production -p 3000-home,3001-shop,3002-checkout",
4444
"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",
@@ -84,8 +84,6 @@
8484
"lodash.get": "4.4.2",
8585
"openai": "^4.72.0",
8686
"rambda": "7.5.0",
87-
"react": "18.3.1",
88-
"react-dom": "18.3.1",
8987
"react-router-dom": "6.26.2",
9088
"regenerator-runtime": "0.14.1",
9189
"sharp": "^0.33.4",

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

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import FederationRuntimePlugin from '../container/runtime/FederationRuntimePlugi
2929
import ShareRuntimeModule from './ShareRuntimeModule';
3030
import type { SemVerRange } from 'webpack/lib/util/semver';
3131
import type { ResolveData } from 'webpack/lib/NormalModuleFactory';
32-
import type { ModuleFactoryCreateDataContextInfo } from 'webpack/lib/ModuleFactory';
3332
import type { ConsumeOptions } from '../../declarations/plugins/sharing/ConsumeSharedModule';
3433
import { createSchemaValidation } from '../../utils';
3534

@@ -61,14 +60,23 @@ const RESOLVE_OPTIONS: ResolveOptionsWithDependencyType = {
6160
};
6261
const PLUGIN_NAME = 'ConsumeSharedPlugin';
6362

64-
// Helper function to create composite key
65-
function createLookupKey(
66-
request: string,
67-
contextInfo: ModuleFactoryCreateDataContextInfo,
68-
): string {
69-
return contextInfo.issuerLayer
70-
? `(${contextInfo.issuerLayer})${request}`
71-
: request;
63+
// Helper function to try layered lookup first, then unlayered fallback
64+
function tryLookupWithFallback<T>(
65+
map: Map<string, T>,
66+
key: string,
67+
issuerLayer?: string | null,
68+
): T | undefined {
69+
// First try layered lookup if request has an issuer layer
70+
if (issuerLayer) {
71+
const layeredKey = `(${issuerLayer})${key}`;
72+
const layeredResult = map.get(layeredKey);
73+
if (layeredResult !== undefined) {
74+
return layeredResult;
75+
}
76+
}
77+
78+
// Fallback to unlayered lookup
79+
return map.get(key);
7280
}
7381

7482
class ConsumeSharedPlugin {
@@ -322,27 +330,57 @@ class ConsumeSharedPlugin {
322330
) {
323331
return;
324332
}
325-
const match = unresolvedConsumes.get(
326-
createLookupKey(request, contextInfo),
333+
334+
// Check exact request matches (with layer fallback)
335+
const match = tryLookupWithFallback(
336+
unresolvedConsumes,
337+
request,
338+
contextInfo.issuerLayer,
327339
);
328340

329341
if (match !== undefined) {
330342
return createConsumeSharedModule(context, request, match);
331343
}
344+
345+
// Check prefix matches with layer fallback
346+
// First try to find a prefix that matches both request and layer
347+
if (contextInfo.issuerLayer) {
348+
for (const [prefix, options] of prefixedConsumes) {
349+
if (
350+
request.startsWith(prefix) &&
351+
options.layer === contextInfo.issuerLayer
352+
) {
353+
const remainder = request.slice(prefix.length);
354+
return createConsumeSharedModule(context, request, {
355+
...options,
356+
import: options.import
357+
? options.import + remainder
358+
: undefined,
359+
shareKey: options.shareKey + remainder,
360+
layer: options.layer,
361+
});
362+
}
363+
}
364+
}
365+
366+
// Fallback to unlayered prefix matches
332367
for (const [prefix, options] of prefixedConsumes) {
333-
const lookup = options.request || prefix;
334-
if (request.startsWith(lookup)) {
335-
const remainder = request.slice(lookup.length);
368+
if (
369+
request.startsWith(prefix) &&
370+
(!options.layer || options.layer === 'undefined')
371+
) {
372+
const remainder = request.slice(prefix.length);
336373
return createConsumeSharedModule(context, request, {
337374
...options,
338375
import: options.import
339376
? options.import + remainder
340377
: undefined,
341378
shareKey: options.shareKey + remainder,
342-
layer: options.layer || contextInfo.issuerLayer,
379+
layer: options.layer,
343380
});
344381
}
345382
}
383+
346384
return;
347385
});
348386
},

0 commit comments

Comments
 (0)