Skip to content

Commit 6caee05

Browse files
authored
refactor: remove remote ip strategy feature (module-federation#4476)
1 parent befc21c commit 6caee05

13 files changed

Lines changed: 14 additions & 324 deletions

File tree

.changeset/clever-shirts-poke.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@module-federation/modern-js-v3': patch
3+
'@module-federation/modern-js': patch
4+
---
5+
6+
refactor: remove remote ip strategy feature

packages/modernjs-v3/package.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@
6666
"import": "./dist/esm/cli/mfRuntimePlugins/shared-strategy.mjs",
6767
"require": "./dist/cjs/cli/mfRuntimePlugins/shared-strategy.js"
6868
},
69-
"./resolve-entry-ipv4": {
70-
"types": "./dist/types/cli/mfRuntimePlugins/resolve-entry-ipv4.d.ts",
71-
"import": "./dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.mjs",
72-
"require": "./dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js"
73-
},
7469
"./inject-node-fetch": {
7570
"types": "./dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts",
7671
"import": "./dist/esm/cli/mfRuntimePlugins/inject-node-fetch.mjs",
@@ -114,9 +109,6 @@
114109
"shared-strategy": [
115110
"./dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts"
116111
],
117-
"resolve-entry-ipv4": [
118-
"./dist/types/cli/mfRuntimePlugins/resolve-entry-ipv4.d.ts"
119-
],
120112
"inject-node-fetch": [
121113
"./dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts"
122114
],

packages/modernjs-v3/src/cli/configPlugin.spec.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ describe('patchMFConfig', async () => {
1717
it('patchMFConfig: server', async () => {
1818
const patchedConfig = JSON.parse(JSON.stringify(mfConfig));
1919
patchMFConfig(patchedConfig, true);
20-
const ipv4 = getIPV4();
2120

2221
expect(patchedConfig).toStrictEqual({
2322
dev: false,
@@ -29,7 +28,7 @@ describe('patchMFConfig', async () => {
2928
},
3029
name: 'host',
3130
remotes: {
32-
remote: `http://${ipv4}:3000/remoteEntry.js`,
31+
remote: `http://localhost:3000/remoteEntry.js`,
3332
},
3433
remoteType: 'script',
3534
runtimePlugins: [
@@ -53,13 +52,12 @@ describe('patchMFConfig', async () => {
5352
it('patchMFConfig: client', async () => {
5453
const patchedConfig = JSON.parse(JSON.stringify(mfConfig));
5554
patchMFConfig(patchedConfig, false);
56-
const ipv4 = getIPV4();
5755

5856
expect(patchedConfig).toStrictEqual({
5957
filename: 'remoteEntry.js',
6058
name: 'host',
6159
remotes: {
62-
remote: `http://${ipv4}:3000/remoteEntry.js`,
60+
remote: `http://localhost:3000/remoteEntry.js`,
6361
},
6462
remoteType: 'script',
6563
runtimePlugins: [

packages/modernjs-v3/src/cli/configPlugin.ts

Lines changed: 2 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -79,50 +79,6 @@ const injectRuntimePlugins = (
7979
}
8080
};
8181

82-
const replaceRemoteUrl = (
83-
mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions,
84-
remoteIpStrategy?: 'ipv4' | 'inherit',
85-
) => {
86-
if (remoteIpStrategy && remoteIpStrategy === 'inherit') {
87-
return;
88-
}
89-
if (!mfConfig.remotes) {
90-
return;
91-
}
92-
const ipv4 = getIPV4();
93-
const handleRemoteObject = (
94-
remoteObject: moduleFederationPlugin.RemotesObject,
95-
) => {
96-
Object.keys(remoteObject).forEach((remoteKey) => {
97-
const remote = remoteObject[remoteKey];
98-
// no support array items yet
99-
if (Array.isArray(remote)) {
100-
return;
101-
}
102-
if (typeof remote === 'string' && remote.includes(LOCALHOST)) {
103-
remoteObject[remoteKey] = remote.replace(LOCALHOST, ipv4);
104-
}
105-
if (
106-
typeof remote === 'object' &&
107-
!Array.isArray(remote.external) &&
108-
remote.external.includes(LOCALHOST)
109-
) {
110-
remote.external = remote.external.replace(LOCALHOST, ipv4);
111-
}
112-
});
113-
};
114-
if (Array.isArray(mfConfig.remotes)) {
115-
mfConfig.remotes.forEach((remoteObject) => {
116-
if (typeof remoteObject === 'string') {
117-
return;
118-
}
119-
handleRemoteObject(remoteObject);
120-
});
121-
} else if (typeof mfConfig.remotes !== 'string') {
122-
handleRemoteObject(mfConfig.remotes);
123-
}
124-
};
125-
12682
const patchDTSConfig = (
12783
mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions,
12884
isServer: boolean,
@@ -163,10 +119,7 @@ const patchDTSConfig = (
163119
export const patchMFConfig = (
164120
mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions,
165121
isServer: boolean,
166-
remoteIpStrategy?: 'ipv4' | 'inherit',
167-
enableSSR?: boolean,
168122
) => {
169-
replaceRemoteUrl(mfConfig, remoteIpStrategy);
170123
addDataFetchExposes(mfConfig.exposes, isServer);
171124

172125
if (mfConfig.remoteType === undefined) {
@@ -188,13 +141,6 @@ export const patchMFConfig = (
188141
runtimePlugins,
189142
);
190143

191-
if (enableSSR && isDev()) {
192-
injectRuntimePlugins(
193-
require.resolve('@module-federation/modern-js-v3/resolve-entry-ipv4'),
194-
runtimePlugins,
195-
);
196-
}
197-
198144
if (isServer) {
199145
injectRuntimePlugins(
200146
require.resolve('@module-federation/node/runtimePlugin'),
@@ -414,12 +360,7 @@ export const moduleFederationConfigPlugin = (
414360
addMyTypes2Ignored(chain, !isWeb ? ssrConfig : csrConfig);
415361

416362
const targetMFConfig = !isWeb ? ssrConfig : csrConfig;
417-
patchMFConfig(
418-
targetMFConfig,
419-
!isWeb,
420-
userConfig.remoteIpStrategy || 'ipv4',
421-
enableSSR,
422-
);
363+
patchMFConfig(targetMFConfig, !isWeb);
423364

424365
patchBundlerConfig({
425366
chain,
@@ -444,16 +385,6 @@ export const moduleFederationConfigPlugin = (
444385
}
445386
});
446387
api.config(() => {
447-
const ipv4 = getIPV4();
448-
449-
if (userConfig.remoteIpStrategy === undefined) {
450-
if (!enableSSR) {
451-
userConfig.remoteIpStrategy = 'inherit';
452-
} else {
453-
userConfig.remoteIpStrategy = 'ipv4';
454-
}
455-
}
456-
457388
const devServerConfig = modernjsConfig.tools?.devServer;
458389
const corsWarnMsgs = [
459390
'View https://module-federation.io/guide/troubleshooting/other.html#cors-warn for more details.',
@@ -485,12 +416,7 @@ export const moduleFederationConfigPlugin = (
485416
'Access-Control-Allow-Headers': '*',
486417
}
487418
: undefined;
488-
const defineConfig = {
489-
REMOTE_IP_STRATEGY: JSON.stringify(userConfig.remoteIpStrategy),
490-
};
491-
if (enableSSR && isDev()) {
492-
defineConfig['FEDERATION_IPV4'] = JSON.stringify(ipv4);
493-
}
419+
494420
return {
495421
tools: {
496422
devServer: {
@@ -506,7 +432,6 @@ export const moduleFederationConfigPlugin = (
506432
},
507433
},
508434
source: {
509-
define: defineConfig,
510435
enableAsyncEntry: modernjsConfig.source?.enableAsyncEntry ?? true,
511436
},
512437
dev: {

packages/modernjs-v3/src/cli/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export const moduleFederationPlugin = (
2020
assetResources: {},
2121
distOutputDir: '',
2222
originPluginOptions: { ...userConfig },
23-
remoteIpStrategy: userConfig?.remoteIpStrategy,
2423
userConfig: userConfig || {},
2524
assetFileNames: {},
2625
fetchServerQuery: userConfig.fetchServerQuery ?? undefined,

packages/modernjs-v3/src/cli/mfRuntimePlugins/resolve-entry-ipv4.ts

Lines changed: 0 additions & 70 deletions
This file was deleted.

packages/modernjs-v3/src/types/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export interface PluginOptions {
99
distOutputDir?: string;
1010
}
1111
| boolean;
12-
remoteIpStrategy?: 'ipv4' | 'inherit';
1312
fetchServerQuery?: Record<string, unknown>;
1413
secondarySharedTreeShaking?: boolean;
1514
}
@@ -33,7 +32,6 @@ export interface InternalModernPluginOptions {
3332
browser?: StatsAssetResource;
3433
node?: StatsAssetResource;
3534
};
36-
remoteIpStrategy?: 'ipv4' | 'inherit';
3735
userConfig?: PluginOptions;
3836
fetchServerQuery?: Record<string, unknown>;
3937
secondarySharedTreeShaking?: boolean;

packages/modernjs/package.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@
6666
"import": "./dist/esm/cli/mfRuntimePlugins/shared-strategy.mjs",
6767
"require": "./dist/cjs/cli/mfRuntimePlugins/shared-strategy.js"
6868
},
69-
"./resolve-entry-ipv4": {
70-
"types": "./dist/types/cli/mfRuntimePlugins/resolve-entry-ipv4.d.ts",
71-
"import": "./dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.mjs",
72-
"require": "./dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js"
73-
},
7469
"./inject-node-fetch": {
7570
"types": "./dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts",
7671
"import": "./dist/esm/cli/mfRuntimePlugins/inject-node-fetch.mjs",
@@ -114,9 +109,6 @@
114109
"shared-strategy": [
115110
"./dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts"
116111
],
117-
"resolve-entry-ipv4": [
118-
"./dist/types/cli/mfRuntimePlugins/resolve-entry-ipv4.d.ts"
119-
],
120112
"inject-node-fetch": [
121113
"./dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts"
122114
],

packages/modernjs/src/cli/configPlugin.spec.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ describe('patchMFConfig', async () => {
1717
it('patchMFConfig: server', async () => {
1818
const patchedConfig = JSON.parse(JSON.stringify(mfConfig));
1919
patchMFConfig(patchedConfig, true);
20-
const ipv4 = getIPV4();
21-
2220
expect(patchedConfig).toStrictEqual({
2321
dev: false,
2422
dts: false,
@@ -29,7 +27,7 @@ describe('patchMFConfig', async () => {
2927
},
3028
name: 'host',
3129
remotes: {
32-
remote: `http://${ipv4}:3000/remoteEntry.js`,
30+
remote: `http://localhost:3000/remoteEntry.js`,
3331
},
3432
remoteType: 'script',
3533
runtimePlugins: [
@@ -53,13 +51,12 @@ describe('patchMFConfig', async () => {
5351
it('patchMFConfig: client', async () => {
5452
const patchedConfig = JSON.parse(JSON.stringify(mfConfig));
5553
patchMFConfig(patchedConfig, false);
56-
const ipv4 = getIPV4();
5754

5855
expect(patchedConfig).toStrictEqual({
5956
filename: 'remoteEntry.js',
6057
name: 'host',
6158
remotes: {
62-
remote: `http://${ipv4}:3000/remoteEntry.js`,
59+
remote: `http://localhost:3000/remoteEntry.js`,
6360
},
6461
remoteType: 'script',
6562
runtimePlugins: [

0 commit comments

Comments
 (0)