Skip to content

Commit 09d6bc1

Browse files
authoredMar 18, 2025··
fix(enhanced): use default runtime export (#3601)
1 parent c01715a commit 09d6bc1

File tree

8 files changed

+26
-1132
lines changed

8 files changed

+26
-1132
lines changed
 

‎.changeset/chatty-months-share.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/enhanced': patch
3+
---
4+
5+
fix(enhanced): use default runtime export

‎packages/enhanced/src/lib/container/runtime/FederationRuntimePlugin.ts

+20-14
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@ const BundlerRuntimePath = require.resolve(
4747
const RuntimePath = require.resolve('@module-federation/runtime', {
4848
paths: [RuntimeToolsPath],
4949
});
50-
const EmbeddedRuntimePath = require.resolve(
51-
'@module-federation/runtime/embedded',
52-
{
53-
paths: [RuntimeToolsPath],
54-
},
55-
);
5650

5751
const federationGlobal = getFederationGlobalScope(RuntimeGlobals);
5852

@@ -330,17 +324,28 @@ class FederationRuntimePlugin {
330324
);
331325
}
332326

333-
setRuntimeAlias(compiler: Compiler) {
334-
const { experiments, implementation } = this.options || {};
335-
let runtimePath = EmbeddedRuntimePath;
327+
getRuntimeAlias(compiler: Compiler) {
328+
const { implementation } = this.options || {};
329+
let runtimePath = RuntimePath;
330+
const alias: any = compiler.options.resolve.alias || {};
336331

337-
if (implementation) {
338-
runtimePath = require.resolve(`@module-federation/runtime/embedded`, {
339-
paths: [implementation],
340-
});
332+
if (alias['@module-federation/runtime$']) {
333+
runtimePath = alias['@module-federation/runtime$'];
334+
} else {
335+
if (implementation) {
336+
runtimePath = require.resolve(`@module-federation/runtime`, {
337+
paths: [implementation],
338+
});
339+
}
341340
}
342341

342+
return runtimePath;
343+
}
344+
345+
setRuntimeAlias(compiler: Compiler) {
346+
const { implementation } = this.options || {};
343347
const alias: any = compiler.options.resolve.alias || {};
348+
const runtimePath = this.getRuntimeAlias(compiler);
344349
alias['@module-federation/runtime$'] =
345350
alias['@module-federation/runtime$'] || runtimePath;
346351
alias['@module-federation/runtime-tools$'] =
@@ -408,11 +413,12 @@ class FederationRuntimePlugin {
408413

409414
new HoistContainerReferences().apply(compiler);
410415

416+
const runtimePath = this.getRuntimeAlias(compiler);
411417
new compiler.webpack.NormalModuleReplacementPlugin(
412418
/@module-federation\/runtime/,
413419
(resolveData) => {
414420
if (/webpack-bundler-runtime/.test(resolveData.contextInfo.issuer)) {
415-
resolveData.request = RuntimePath;
421+
resolveData.request = runtimePath;
416422

417423
if (resolveData.createData) {
418424
resolveData.createData.request = resolveData.request;

‎packages/nextjs-mf/src/plugins/NextFederationPlugin/index.ts

-7
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,6 @@ export class NextFederationPlugin {
100100
(message) => /your target environment does not appear/.test(message),
101101
];
102102
}
103-
compiler.hooks.afterPlugins.tap('PatchAliasWebpackPlugin', () => {
104-
compiler.options.resolve.alias = {
105-
...compiler.options.resolve.alias,
106-
//useing embedded runtime
107-
// '@module-federation/runtime$': runtimeESMPath,
108-
};
109-
});
110103
}
111104

112105
private validateOptions(compiler: Compiler): boolean {

‎packages/runtime/__tests__/sync.spec.ts

-737
This file was deleted.

‎packages/runtime/package.json

-5
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@
3939
"import": "./dist/core.esm.mjs",
4040
"require": "./dist/core.cjs.js"
4141
},
42-
"./embedded": {
43-
"types": "./dist/embedded.cjs.d.ts",
44-
"import": "./dist/embedded.esm.mjs",
45-
"require": "./dist/embedded.cjs.js"
46-
},
4742
"./*": "./*"
4843
},
4944
"typesVersions": {

‎packages/runtime/project.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
"main": "packages/runtime/src/index.ts",
1515
"additionalEntryPoints": [
1616
"packages/runtime/src/types.ts",
17-
"packages/runtime/src/helpers.ts",
18-
"packages/runtime/src/embedded.ts"
17+
"packages/runtime/src/helpers.ts"
1918
],
2019
"tsConfig": "packages/runtime/tsconfig.lib.json",
2120
"assets": [],

‎packages/runtime/rollup.config.js

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ module.exports = (rollupConfig, projectOptions) => {
88
index: 'packages/runtime/src/index.ts',
99
types: 'packages/runtime/src/types.ts',
1010
helpers: 'packages/runtime/src/helpers.ts',
11-
embedded: 'packages/runtime/src/embedded.ts',
1211
core: 'packages/runtime/src/core.ts',
1312
};
1413

‎packages/runtime/src/embedded.ts

-366
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.