Skip to content

Commit 70a1708

Browse files
fix(enhanced): skip ensure file when virtualEntry (#3037)
1 parent 564f378 commit 70a1708

File tree

9 files changed

+111
-0
lines changed

9 files changed

+111
-0
lines changed

.changeset/ai-calm-bear.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@module-federation/enhanced": patch
3+
---
4+
5+
Added a check to skip processing when virtualRuntimeEntry is present.
6+
7+
- Added an early return in `FederationRuntimePlugin` to skip processing if `options.virtualRuntimeEntry` is defined.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ class FederationRuntimePlugin {
198198
if (!this.options) {
199199
return;
200200
}
201+
// skip virtual entry
202+
if (this.options?.virtualRuntimeEntry) {
203+
return;
204+
}
201205
const filePath = this.getFilePath(compiler);
202206
try {
203207
fs.readFileSync(filePath);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import React from 'react';
2+
import ComponentA from 'containerA/ComponentA';
3+
4+
export default () => {
5+
return `App rendered with [${React()}] and [${ComponentA()}]`;
6+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from 'react';
2+
3+
export default () => {
4+
return `ComponentA rendered with [${React()}]`;
5+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
it('should load the component from container', () => {
2+
return import('./App').then(({ default: App }) => {
3+
const rendered = App();
4+
expect(rendered).toBe(
5+
'App rendered with [This is react 0.1.2] and [ComponentA rendered with [This is react 0.1.2]]',
6+
);
7+
return import('./upgrade-react').then(({ default: upgrade }) => {
8+
upgrade();
9+
const rendered = App();
10+
expect(rendered).toBe(
11+
'App rendered with [This is react 1.2.3] and [ComponentA rendered with [This is react 1.2.3]]',
12+
);
13+
});
14+
});
15+
});

packages/enhanced/test/configCases/container/virtual-entry/node_modules/react.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
findBundle: function (i, options) {
3+
return i === 0 ? './main.js' : './module/main.mjs';
4+
},
5+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { setVersion } from 'react';
2+
3+
export default function upgrade() {
4+
setVersion('1.2.3');
5+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
const { ModuleFederationPlugin } = require('../../../../dist/src');
2+
3+
const common = {
4+
name: 've',
5+
exposes: {
6+
'./ComponentA': {
7+
import: './ComponentA',
8+
},
9+
},
10+
shared: {
11+
react: {
12+
version: false,
13+
requiredVersion: false,
14+
},
15+
},
16+
};
17+
18+
module.exports = [
19+
{
20+
output: {
21+
filename: '[name].js',
22+
uniqueName: '0-ve-full',
23+
},
24+
plugins: [
25+
new ModuleFederationPlugin({
26+
library: { type: 'commonjs-module' },
27+
virtualRuntimeEntry: true,
28+
filename: 'container.js',
29+
remotes: {
30+
containerA: {
31+
external: './container.js',
32+
},
33+
},
34+
...common,
35+
}),
36+
],
37+
},
38+
{
39+
experiments: {
40+
outputModule: true,
41+
},
42+
output: {
43+
filename: 'module/[name].mjs',
44+
uniqueName: '0-ve-full-mjs',
45+
},
46+
plugins: [
47+
new ModuleFederationPlugin({
48+
library: { type: 'module' },
49+
virtualRuntimeEntry: true,
50+
filename: 'module/container.mjs',
51+
remotes: {
52+
containerA: {
53+
external: './container.mjs',
54+
},
55+
},
56+
...common,
57+
}),
58+
],
59+
target: 'node14',
60+
},
61+
];

0 commit comments

Comments
 (0)