@module-federation/modern-js 0.24.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -58,6 +58,8 @@ var __webpack_exports__ = {};
58
58
  setEnv: ()=>setEnv,
59
59
  patchBundlerConfig: ()=>patchBundlerConfig
60
60
  });
61
+ const external_fs_namespaceObject = require("fs");
62
+ var external_fs_default = /*#__PURE__*/ __webpack_require__.n(external_fs_namespaceObject);
61
63
  const external_path_namespaceObject = require("path");
62
64
  var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
63
65
  const external_utils_js_namespaceObject = require("./utils.js");
@@ -67,6 +69,20 @@ var __webpack_exports__ = {};
67
69
  const external_logger_js_namespaceObject = require("../logger.js");
68
70
  var external_logger_js_default = /*#__PURE__*/ __webpack_require__.n(external_logger_js_namespaceObject);
69
71
  const defaultPath = external_path_default().resolve(process.cwd(), 'module-federation.config.ts');
72
+ const resolvePackageFile = (packageName, esmRelativePath, cjsRelativePath)=>{
73
+ const packageEntry = require.resolve(packageName);
74
+ let packageRoot = external_path_default().dirname(packageEntry);
75
+ while(!external_fs_default().existsSync(external_path_default().join(packageRoot, 'package.json'))){
76
+ const parentDir = external_path_default().dirname(packageRoot);
77
+ if (parentDir === packageRoot) throw new Error(`Unable to resolve package root for ${packageName} from ${packageEntry}`);
78
+ packageRoot = parentDir;
79
+ }
80
+ return require.resolve(external_path_default().join(packageRoot, 'true' === process.env.IS_ESM_BUILD ? esmRelativePath : cjsRelativePath));
81
+ };
82
+ const resolveSharedStrategyPlugin = ()=>resolvePackageFile('@module-federation/modern-js', 'dist/esm/cli/mfRuntimePlugins/shared-strategy.mjs', 'dist/cjs/cli/mfRuntimePlugins/shared-strategy.js');
83
+ const resolveInjectNodeFetchPlugin = ()=>resolvePackageFile('@module-federation/modern-js', 'dist/esm/cli/mfRuntimePlugins/inject-node-fetch.mjs', 'dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js');
84
+ const resolveNodeRuntimePlugin = ()=>resolvePackageFile('@module-federation/node', 'dist/src/runtimePlugin.mjs', 'dist/src/runtimePlugin.js');
85
+ const resolveNodeRecordRemoteHashPlugin = ()=>resolvePackageFile('@module-federation/node', 'dist/src/recordDynamicRemoteEntryHashPlugin.mjs', 'dist/src/recordDynamicRemoteEntryHashPlugin.js');
70
86
  function setEnv(enableSSR) {
71
87
  if (enableSSR) process.env['MF_SSR_PRJ'] = 'true';
72
88
  }
@@ -76,8 +92,7 @@ var __webpack_exports__ = {};
76
92
  const mfConfigPath = configPath ? configPath : defaultPath;
77
93
  const { createJiti } = __webpack_require__("jiti");
78
94
  const jit = createJiti(__filename, {
79
- interopDefault: true,
80
- esmResolve: true
95
+ interopDefault: true
81
96
  });
82
97
  const configModule = await jit(mfConfigPath);
83
98
  const resolvedConfig = configModule && 'object' == typeof configModule && 'default' in configModule ? configModule.default : configModule;
@@ -91,24 +106,6 @@ var __webpack_exports__ = {};
91
106
  });
92
107
  if (!hasPlugin) runtimePlugins.push(runtimePlugin);
93
108
  };
94
- const replaceRemoteUrl = (mfConfig, remoteIpStrategy)=>{
95
- if (remoteIpStrategy && 'inherit' === remoteIpStrategy) return;
96
- if (!mfConfig.remotes) return;
97
- const ipv4 = (0, external_utils_js_namespaceObject.getIPV4)();
98
- const handleRemoteObject = (remoteObject)=>{
99
- Object.keys(remoteObject).forEach((remoteKey)=>{
100
- const remote = remoteObject[remoteKey];
101
- if (Array.isArray(remote)) return;
102
- if ('string' == typeof remote && remote.includes(external_constant_js_namespaceObject.LOCALHOST)) remoteObject[remoteKey] = remote.replace(external_constant_js_namespaceObject.LOCALHOST, ipv4);
103
- if ('object' == typeof remote && !Array.isArray(remote.external) && remote.external.includes(external_constant_js_namespaceObject.LOCALHOST)) remote.external = remote.external.replace(external_constant_js_namespaceObject.LOCALHOST, ipv4);
104
- });
105
- };
106
- if (Array.isArray(mfConfig.remotes)) mfConfig.remotes.forEach((remoteObject)=>{
107
- if ('string' == typeof remoteObject) return;
108
- handleRemoteObject(remoteObject);
109
- });
110
- else if ('string' != typeof mfConfig.remotes) handleRemoteObject(mfConfig.remotes);
111
- };
112
109
  const patchDTSConfig = (mfConfig, isServer)=>{
113
110
  if (isServer) return;
114
111
  const ModernJSRuntime = '@module-federation/modern-js/runtime';
@@ -135,8 +132,7 @@ var __webpack_exports__ = {};
135
132
  }
136
133
  }
137
134
  };
138
- const patchMFConfig = (mfConfig, isServer, remoteIpStrategy, enableSSR)=>{
139
- replaceRemoteUrl(mfConfig, remoteIpStrategy);
135
+ const patchMFConfig = (mfConfig, isServer)=>{
140
136
  (0, utils_namespaceObject.addDataFetchExposes)(mfConfig.exposes, isServer);
141
137
  if (void 0 === mfConfig.remoteType) mfConfig.remoteType = "script";
142
138
  if (!mfConfig.name) throw new Error(`${external_constant_js_namespaceObject.PLUGIN_IDENTIFIER} mfConfig.name can not be empty!`);
@@ -144,12 +140,11 @@ var __webpack_exports__ = {};
144
140
  ...mfConfig.runtimePlugins || []
145
141
  ];
146
142
  patchDTSConfig(mfConfig, isServer);
147
- injectRuntimePlugins(require.resolve('@module-federation/modern-js/shared-strategy'), runtimePlugins);
148
- if (enableSSR && (0, external_utils_js_namespaceObject.isDev)()) injectRuntimePlugins(require.resolve('@module-federation/modern-js/resolve-entry-ipv4'), runtimePlugins);
143
+ injectRuntimePlugins(resolveSharedStrategyPlugin(), runtimePlugins);
149
144
  if (isServer) {
150
- injectRuntimePlugins(require.resolve('@module-federation/node/runtimePlugin'), runtimePlugins);
151
- if ((0, external_utils_js_namespaceObject.isDev)()) injectRuntimePlugins(require.resolve('@module-federation/node/record-dynamic-remote-entry-hash-plugin'), runtimePlugins);
152
- injectRuntimePlugins(require.resolve('@module-federation/modern-js/inject-node-fetch'), runtimePlugins);
145
+ injectRuntimePlugins(resolveNodeRuntimePlugin(), runtimePlugins);
146
+ if ((0, external_utils_js_namespaceObject.isDev)()) injectRuntimePlugins(resolveNodeRecordRemoteHashPlugin(), runtimePlugins);
147
+ injectRuntimePlugins(resolveInjectNodeFetchPlugin(), runtimePlugins);
153
148
  if (mfConfig.library) {
154
149
  if (!mfConfig.library.type) mfConfig.library.type = 'commonjs-module';
155
150
  if (!mfConfig.library.name) mfConfig.library.name = mfConfig.name;
@@ -257,12 +252,19 @@ var __webpack_exports__ = {};
257
252
  userConfig.csrConfig = csrConfig;
258
253
  const enableSSR = Boolean(null != (_ref = null == (_userConfig_userConfig = userConfig.userConfig) ? void 0 : _userConfig_userConfig.ssr) ? _ref : Boolean(null == modernjsConfig ? void 0 : null == (_modernjsConfig_server = modernjsConfig.server) ? void 0 : _modernjsConfig_server.ssr));
259
254
  api.modifyBundlerChain((chain)=>{
255
+ var _modernjsConfig_source, _targetMFConfig_experiments;
256
+ const bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
260
257
  const target = chain.get('target');
261
258
  if ((0, external_utils_js_namespaceObject.skipByTarget)(target)) return;
262
259
  const isWeb = (0, external_utils_js_namespaceObject.isWebTarget)(target);
263
260
  addMyTypes2Ignored(chain, isWeb ? csrConfig : ssrConfig);
264
261
  const targetMFConfig = isWeb ? csrConfig : ssrConfig;
265
- patchMFConfig(targetMFConfig, !isWeb, userConfig.remoteIpStrategy || 'ipv4', enableSSR);
262
+ patchMFConfig(targetMFConfig, !isWeb);
263
+ if ('rspack' === bundlerType && (null == (_modernjsConfig_source = modernjsConfig.source) ? void 0 : _modernjsConfig_source.enableAsyncEntry) !== true && (null == (_targetMFConfig_experiments = targetMFConfig.experiments) ? void 0 : _targetMFConfig_experiments.asyncStartup) !== false) {
264
+ var _targetMFConfig;
265
+ (_targetMFConfig = targetMFConfig).experiments || (_targetMFConfig.experiments = {});
266
+ targetMFConfig.experiments.asyncStartup = true;
267
+ }
266
268
  patchBundlerConfig({
267
269
  chain,
268
270
  isServer: !isWeb,
@@ -283,9 +285,6 @@ var __webpack_exports__ = {};
283
285
  var _ref;
284
286
  var _modernjsConfig_tools, _userConfig_csrConfig, _modernjsConfig_source, _modernjsConfig_source1, _modernjsConfig_dev;
285
287
  const bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
286
- const ipv4 = (0, external_utils_js_namespaceObject.getIPV4)();
287
- if (void 0 === userConfig.remoteIpStrategy) if (enableSSR) userConfig.remoteIpStrategy = 'ipv4';
288
- else userConfig.remoteIpStrategy = 'inherit';
289
288
  const devServerConfig = null == (_modernjsConfig_tools = modernjsConfig.tools) ? void 0 : _modernjsConfig_tools.devServer;
290
289
  const corsWarnMsgs = [
291
290
  'View https://module-federation.io/guide/troubleshooting/other.html#cors-warn for more details.'
@@ -299,10 +298,6 @@ var __webpack_exports__ = {};
299
298
  'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
300
299
  'Access-Control-Allow-Headers': '*'
301
300
  } : void 0;
302
- const defineConfig = {
303
- REMOTE_IP_STRATEGY: JSON.stringify(userConfig.remoteIpStrategy)
304
- };
305
- if (enableSSR && (0, external_utils_js_namespaceObject.isDev)()) defineConfig['FEDERATION_IPV4'] = JSON.stringify(ipv4);
306
301
  return {
307
302
  tools: {
308
303
  devServer: {
@@ -315,7 +310,6 @@ var __webpack_exports__ = {};
315
310
  }
316
311
  },
317
312
  source: {
318
- define: defineConfig,
319
313
  enableAsyncEntry: 'rspack' === bundlerType ? null != (_ref = null == (_modernjsConfig_source = modernjsConfig.source) ? void 0 : _modernjsConfig_source.enableAsyncEntry) ? _ref : true : null == (_modernjsConfig_source1 = modernjsConfig.source) ? void 0 : _modernjsConfig_source1.enableAsyncEntry
320
314
  },
321
315
  dev: {
@@ -45,7 +45,6 @@ const moduleFederationPlugin = (userConfig = {})=>{
45
45
  originPluginOptions: {
46
46
  ...userConfig
47
47
  },
48
- remoteIpStrategy: null == userConfig ? void 0 : userConfig.remoteIpStrategy,
49
48
  userConfig: userConfig || {},
50
49
  assetFileNames: {},
51
50
  fetchServerQuery: null != (_userConfig_fetchServerQuery = userConfig.fetchServerQuery) ? _userConfig_fetchServerQuery : void 0,
@@ -5,10 +5,11 @@ import { _ as _object_spread_props__ } from "@swc/helpers/_/_object_spread_props
5
5
  import { _ as _to_consumable_array__ } from "@swc/helpers/_/_to_consumable_array";
6
6
  import { _ as _type_of__ } from "@swc/helpers/_/_type_of";
7
7
  import { _ as _ts_generator__ } from "@swc/helpers/_/_ts_generator";
8
+ import fs from "fs";
8
9
  import path from "path";
9
- import { getIPV4, isDev, isWebTarget, skipByTarget } from "./utils.mjs";
10
+ import { isDev, isWebTarget, skipByTarget } from "./utils.mjs";
10
11
  import { encodeName } from "@module-federation/sdk";
11
- import { LOCALHOST, PLUGIN_IDENTIFIER } from "../constant.mjs";
12
+ import { PLUGIN_IDENTIFIER } from "../constant.mjs";
12
13
  import { addDataFetchExposes, autoDeleteSplitChunkCacheGroups } from "@module-federation/rsbuild-plugin/utils";
13
14
  import logger from "../logger.mjs";
14
15
  var __webpack_modules__ = {
@@ -27,6 +28,28 @@ function __webpack_require__(moduleId) {
27
28
  return module.exports;
28
29
  }
29
30
  var defaultPath = path.resolve(process.cwd(), 'module-federation.config.ts');
31
+ var resolvePackageFile = function(packageName, esmRelativePath, cjsRelativePath) {
32
+ var packageEntry = require.resolve(packageName);
33
+ var packageRoot = path.dirname(packageEntry);
34
+ while(!fs.existsSync(path.join(packageRoot, 'package.json'))){
35
+ var parentDir = path.dirname(packageRoot);
36
+ if (parentDir === packageRoot) throw new Error("Unable to resolve package root for ".concat(packageName, " from ").concat(packageEntry));
37
+ packageRoot = parentDir;
38
+ }
39
+ return require.resolve(path.join(packageRoot, 'true' === process.env.IS_ESM_BUILD ? esmRelativePath : cjsRelativePath));
40
+ };
41
+ var resolveSharedStrategyPlugin = function() {
42
+ return resolvePackageFile('@module-federation/modern-js', 'dist/esm/cli/mfRuntimePlugins/shared-strategy.mjs', 'dist/cjs/cli/mfRuntimePlugins/shared-strategy.js');
43
+ };
44
+ var resolveInjectNodeFetchPlugin = function() {
45
+ return resolvePackageFile('@module-federation/modern-js', 'dist/esm/cli/mfRuntimePlugins/inject-node-fetch.mjs', 'dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js');
46
+ };
47
+ var resolveNodeRuntimePlugin = function() {
48
+ return resolvePackageFile('@module-federation/node', 'dist/src/runtimePlugin.mjs', 'dist/src/runtimePlugin.js');
49
+ };
50
+ var resolveNodeRecordRemoteHashPlugin = function() {
51
+ return resolvePackageFile('@module-federation/node', 'dist/src/recordDynamicRemoteEntryHashPlugin.mjs', 'dist/src/recordDynamicRemoteEntryHashPlugin.js');
52
+ };
30
53
  function setEnv(enableSSR) {
31
54
  if (enableSSR) process.env['MF_SSR_PRJ'] = 'true';
32
55
  }
@@ -44,8 +67,7 @@ var getMFConfig = function(userConfig) {
44
67
  mfConfigPath = configPath ? configPath : defaultPath;
45
68
  createJiti = __webpack_require__("jiti").createJiti;
46
69
  jit = createJiti(__filename, {
47
- interopDefault: true,
48
- esmResolve: true
70
+ interopDefault: true
49
71
  });
50
72
  return [
51
73
  4,
@@ -70,24 +92,6 @@ var injectRuntimePlugins = function(runtimePlugin, runtimePlugins) {
70
92
  });
71
93
  if (!hasPlugin) runtimePlugins.push(runtimePlugin);
72
94
  };
73
- var replaceRemoteUrl = function(mfConfig, remoteIpStrategy) {
74
- if (remoteIpStrategy && 'inherit' === remoteIpStrategy) return;
75
- if (!mfConfig.remotes) return;
76
- var ipv4 = getIPV4();
77
- var handleRemoteObject = function(remoteObject) {
78
- Object.keys(remoteObject).forEach(function(remoteKey) {
79
- var remote = remoteObject[remoteKey];
80
- if (Array.isArray(remote)) return;
81
- if ('string' == typeof remote && remote.includes(LOCALHOST)) remoteObject[remoteKey] = remote.replace(LOCALHOST, ipv4);
82
- if ((void 0 === remote ? "undefined" : _type_of__(remote)) === 'object' && !Array.isArray(remote.external) && remote.external.includes(LOCALHOST)) remote.external = remote.external.replace(LOCALHOST, ipv4);
83
- });
84
- };
85
- if (Array.isArray(mfConfig.remotes)) mfConfig.remotes.forEach(function(remoteObject) {
86
- if ('string' == typeof remoteObject) return;
87
- handleRemoteObject(remoteObject);
88
- });
89
- else if ('string' != typeof mfConfig.remotes) handleRemoteObject(mfConfig.remotes);
90
- };
91
95
  var patchDTSConfig = function(mfConfig, isServer) {
92
96
  if (isServer) return;
93
97
  var ModernJSRuntime = '@module-federation/modern-js/runtime';
@@ -114,19 +118,17 @@ var patchDTSConfig = function(mfConfig, isServer) {
114
118
  }
115
119
  }
116
120
  };
117
- var patchMFConfig = function(mfConfig, isServer, remoteIpStrategy, enableSSR) {
118
- replaceRemoteUrl(mfConfig, remoteIpStrategy);
121
+ var patchMFConfig = function(mfConfig, isServer) {
119
122
  addDataFetchExposes(mfConfig.exposes, isServer);
120
123
  if (void 0 === mfConfig.remoteType) mfConfig.remoteType = "script";
121
124
  if (!mfConfig.name) throw new Error("".concat(PLUGIN_IDENTIFIER, " mfConfig.name can not be empty!"));
122
125
  var runtimePlugins = _to_consumable_array__(mfConfig.runtimePlugins || []);
123
126
  patchDTSConfig(mfConfig, isServer);
124
- injectRuntimePlugins(require.resolve('@module-federation/modern-js/shared-strategy'), runtimePlugins);
125
- if (enableSSR && isDev()) injectRuntimePlugins(require.resolve('@module-federation/modern-js/resolve-entry-ipv4'), runtimePlugins);
127
+ injectRuntimePlugins(resolveSharedStrategyPlugin(), runtimePlugins);
126
128
  if (isServer) {
127
- injectRuntimePlugins(require.resolve('@module-federation/node/runtimePlugin'), runtimePlugins);
128
- if (isDev()) injectRuntimePlugins(require.resolve('@module-federation/node/record-dynamic-remote-entry-hash-plugin'), runtimePlugins);
129
- injectRuntimePlugins(require.resolve('@module-federation/modern-js/inject-node-fetch'), runtimePlugins);
129
+ injectRuntimePlugins(resolveNodeRuntimePlugin(), runtimePlugins);
130
+ if (isDev()) injectRuntimePlugins(resolveNodeRecordRemoteHashPlugin(), runtimePlugins);
131
+ injectRuntimePlugins(resolveInjectNodeFetchPlugin(), runtimePlugins);
130
132
  if (mfConfig.library) {
131
133
  if (!mfConfig.library.type) mfConfig.library.type = 'commonjs-module';
132
134
  if (!mfConfig.library.name) mfConfig.library.name = mfConfig.name;
@@ -241,12 +243,19 @@ var moduleFederationConfigPlugin = function(userConfig) {
241
243
  userConfig.csrConfig = csrConfig;
242
244
  enableSSR = Boolean(null != (_ref = null == (_userConfig_userConfig = userConfig.userConfig) ? void 0 : _userConfig_userConfig.ssr) ? _ref : Boolean(null == modernjsConfig ? void 0 : null == (_modernjsConfig_server = modernjsConfig.server) ? void 0 : _modernjsConfig_server.ssr));
243
245
  api.modifyBundlerChain(function(chain) {
246
+ var _modernjsConfig_source, _targetMFConfig_experiments;
247
+ var bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
244
248
  var target = chain.get('target');
245
249
  if (skipByTarget(target)) return;
246
250
  var isWeb = isWebTarget(target);
247
251
  addMyTypes2Ignored(chain, isWeb ? csrConfig : ssrConfig);
248
252
  var targetMFConfig = isWeb ? csrConfig : ssrConfig;
249
- patchMFConfig(targetMFConfig, !isWeb, userConfig.remoteIpStrategy || 'ipv4', enableSSR);
253
+ patchMFConfig(targetMFConfig, !isWeb);
254
+ if ('rspack' === bundlerType && (null == (_modernjsConfig_source = modernjsConfig.source) ? void 0 : _modernjsConfig_source.enableAsyncEntry) !== true && (null == (_targetMFConfig_experiments = targetMFConfig.experiments) ? void 0 : _targetMFConfig_experiments.asyncStartup) !== false) {
255
+ var _targetMFConfig;
256
+ (_targetMFConfig = targetMFConfig).experiments || (_targetMFConfig.experiments = {});
257
+ targetMFConfig.experiments.asyncStartup = true;
258
+ }
250
259
  patchBundlerConfig({
251
260
  chain: chain,
252
261
  isServer: !isWeb,
@@ -267,9 +276,6 @@ var moduleFederationConfigPlugin = function(userConfig) {
267
276
  var _ref;
268
277
  var _modernjsConfig_tools, _userConfig_csrConfig, _modernjsConfig_source, _modernjsConfig_source1, _modernjsConfig_dev;
269
278
  var bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
270
- var ipv4 = getIPV4();
271
- if (void 0 === userConfig.remoteIpStrategy) if (enableSSR) userConfig.remoteIpStrategy = 'ipv4';
272
- else userConfig.remoteIpStrategy = 'inherit';
273
279
  var devServerConfig = null == (_modernjsConfig_tools = modernjsConfig.tools) ? void 0 : _modernjsConfig_tools.devServer;
274
280
  var corsWarnMsgs = [
275
281
  'View https://module-federation.io/guide/troubleshooting/other.html#cors-warn for more details.'
@@ -283,10 +289,6 @@ var moduleFederationConfigPlugin = function(userConfig) {
283
289
  'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
284
290
  'Access-Control-Allow-Headers': '*'
285
291
  } : void 0;
286
- var defineConfig = {
287
- REMOTE_IP_STRATEGY: JSON.stringify(userConfig.remoteIpStrategy)
288
- };
289
- if (enableSSR && isDev()) defineConfig['FEDERATION_IPV4'] = JSON.stringify(ipv4);
290
292
  return {
291
293
  tools: {
292
294
  devServer: {
@@ -299,7 +301,6 @@ var moduleFederationConfigPlugin = function(userConfig) {
299
301
  }
300
302
  },
301
303
  source: {
302
- define: defineConfig,
303
304
  enableAsyncEntry: 'rspack' === bundlerType ? null != (_ref = null == (_modernjsConfig_source = modernjsConfig.source) ? void 0 : _modernjsConfig_source.enableAsyncEntry) ? _ref : true : null == (_modernjsConfig_source1 = modernjsConfig.source) ? void 0 : _modernjsConfig_source1.enableAsyncEntry
304
305
  },
305
306
  dev: {
@@ -18,7 +18,6 @@ var moduleFederationPlugin = function() {
18
18
  assetResources: {},
19
19
  distOutputDir: '',
20
20
  originPluginOptions: _object_spread__({}, userConfig),
21
- remoteIpStrategy: null == userConfig ? void 0 : userConfig.remoteIpStrategy,
22
21
  userConfig: userConfig || {},
23
22
  assetFileNames: {},
24
23
  fetchServerQuery: null != (_userConfig_fetchServerQuery = userConfig.fetchServerQuery) ? _userConfig_fetchServerQuery : void 0,
@@ -1,8 +1,9 @@
1
1
  import * as __rspack_external_jiti from "jiti";
2
+ import fs from "fs";
2
3
  import path from "path";
3
- import { getIPV4, isDev, isWebTarget, skipByTarget } from "./utils.mjs";
4
+ import { isDev, isWebTarget, skipByTarget } from "./utils.mjs";
4
5
  import { encodeName } from "@module-federation/sdk";
5
- import { LOCALHOST, PLUGIN_IDENTIFIER } from "../constant.mjs";
6
+ import { PLUGIN_IDENTIFIER } from "../constant.mjs";
6
7
  import { addDataFetchExposes, autoDeleteSplitChunkCacheGroups } from "@module-federation/rsbuild-plugin/utils";
7
8
  import logger from "../logger.mjs";
8
9
  var __webpack_modules__ = {
@@ -21,6 +22,20 @@ function __webpack_require__(moduleId) {
21
22
  return module.exports;
22
23
  }
23
24
  const defaultPath = path.resolve(process.cwd(), 'module-federation.config.ts');
25
+ const resolvePackageFile = (packageName, esmRelativePath, cjsRelativePath)=>{
26
+ const packageEntry = require.resolve(packageName);
27
+ let packageRoot = path.dirname(packageEntry);
28
+ while(!fs.existsSync(path.join(packageRoot, 'package.json'))){
29
+ const parentDir = path.dirname(packageRoot);
30
+ if (parentDir === packageRoot) throw new Error(`Unable to resolve package root for ${packageName} from ${packageEntry}`);
31
+ packageRoot = parentDir;
32
+ }
33
+ return require.resolve(path.join(packageRoot, 'true' === process.env.IS_ESM_BUILD ? esmRelativePath : cjsRelativePath));
34
+ };
35
+ const resolveSharedStrategyPlugin = ()=>resolvePackageFile('@module-federation/modern-js', 'dist/esm/cli/mfRuntimePlugins/shared-strategy.mjs', 'dist/cjs/cli/mfRuntimePlugins/shared-strategy.js');
36
+ const resolveInjectNodeFetchPlugin = ()=>resolvePackageFile('@module-federation/modern-js', 'dist/esm/cli/mfRuntimePlugins/inject-node-fetch.mjs', 'dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js');
37
+ const resolveNodeRuntimePlugin = ()=>resolvePackageFile('@module-federation/node', 'dist/src/runtimePlugin.mjs', 'dist/src/runtimePlugin.js');
38
+ const resolveNodeRecordRemoteHashPlugin = ()=>resolvePackageFile('@module-federation/node', 'dist/src/recordDynamicRemoteEntryHashPlugin.mjs', 'dist/src/recordDynamicRemoteEntryHashPlugin.js');
24
39
  function setEnv(enableSSR) {
25
40
  if (enableSSR) process.env['MF_SSR_PRJ'] = 'true';
26
41
  }
@@ -30,8 +45,7 @@ const getMFConfig = async (userConfig)=>{
30
45
  const mfConfigPath = configPath ? configPath : defaultPath;
31
46
  const { createJiti } = __webpack_require__("jiti");
32
47
  const jit = createJiti(__filename, {
33
- interopDefault: true,
34
- esmResolve: true
48
+ interopDefault: true
35
49
  });
36
50
  const configModule = await jit(mfConfigPath);
37
51
  const resolvedConfig = configModule && 'object' == typeof configModule && 'default' in configModule ? configModule.default : configModule;
@@ -45,24 +59,6 @@ const injectRuntimePlugins = (runtimePlugin, runtimePlugins)=>{
45
59
  });
46
60
  if (!hasPlugin) runtimePlugins.push(runtimePlugin);
47
61
  };
48
- const replaceRemoteUrl = (mfConfig, remoteIpStrategy)=>{
49
- if (remoteIpStrategy && 'inherit' === remoteIpStrategy) return;
50
- if (!mfConfig.remotes) return;
51
- const ipv4 = getIPV4();
52
- const handleRemoteObject = (remoteObject)=>{
53
- Object.keys(remoteObject).forEach((remoteKey)=>{
54
- const remote = remoteObject[remoteKey];
55
- if (Array.isArray(remote)) return;
56
- if ('string' == typeof remote && remote.includes(LOCALHOST)) remoteObject[remoteKey] = remote.replace(LOCALHOST, ipv4);
57
- if ('object' == typeof remote && !Array.isArray(remote.external) && remote.external.includes(LOCALHOST)) remote.external = remote.external.replace(LOCALHOST, ipv4);
58
- });
59
- };
60
- if (Array.isArray(mfConfig.remotes)) mfConfig.remotes.forEach((remoteObject)=>{
61
- if ('string' == typeof remoteObject) return;
62
- handleRemoteObject(remoteObject);
63
- });
64
- else if ('string' != typeof mfConfig.remotes) handleRemoteObject(mfConfig.remotes);
65
- };
66
62
  const patchDTSConfig = (mfConfig, isServer)=>{
67
63
  if (isServer) return;
68
64
  const ModernJSRuntime = '@module-federation/modern-js/runtime';
@@ -89,8 +85,7 @@ const patchDTSConfig = (mfConfig, isServer)=>{
89
85
  }
90
86
  }
91
87
  };
92
- const patchMFConfig = (mfConfig, isServer, remoteIpStrategy, enableSSR)=>{
93
- replaceRemoteUrl(mfConfig, remoteIpStrategy);
88
+ const patchMFConfig = (mfConfig, isServer)=>{
94
89
  addDataFetchExposes(mfConfig.exposes, isServer);
95
90
  if (void 0 === mfConfig.remoteType) mfConfig.remoteType = "script";
96
91
  if (!mfConfig.name) throw new Error(`${PLUGIN_IDENTIFIER} mfConfig.name can not be empty!`);
@@ -98,12 +93,11 @@ const patchMFConfig = (mfConfig, isServer, remoteIpStrategy, enableSSR)=>{
98
93
  ...mfConfig.runtimePlugins || []
99
94
  ];
100
95
  patchDTSConfig(mfConfig, isServer);
101
- injectRuntimePlugins(require.resolve('@module-federation/modern-js/shared-strategy'), runtimePlugins);
102
- if (enableSSR && isDev()) injectRuntimePlugins(require.resolve('@module-federation/modern-js/resolve-entry-ipv4'), runtimePlugins);
96
+ injectRuntimePlugins(resolveSharedStrategyPlugin(), runtimePlugins);
103
97
  if (isServer) {
104
- injectRuntimePlugins(require.resolve('@module-federation/node/runtimePlugin'), runtimePlugins);
105
- if (isDev()) injectRuntimePlugins(require.resolve('@module-federation/node/record-dynamic-remote-entry-hash-plugin'), runtimePlugins);
106
- injectRuntimePlugins(require.resolve('@module-federation/modern-js/inject-node-fetch'), runtimePlugins);
98
+ injectRuntimePlugins(resolveNodeRuntimePlugin(), runtimePlugins);
99
+ if (isDev()) injectRuntimePlugins(resolveNodeRecordRemoteHashPlugin(), runtimePlugins);
100
+ injectRuntimePlugins(resolveInjectNodeFetchPlugin(), runtimePlugins);
107
101
  if (mfConfig.library) {
108
102
  if (!mfConfig.library.type) mfConfig.library.type = 'commonjs-module';
109
103
  if (!mfConfig.library.name) mfConfig.library.name = mfConfig.name;
@@ -211,12 +205,19 @@ const moduleFederationConfigPlugin = (userConfig)=>({
211
205
  userConfig.csrConfig = csrConfig;
212
206
  const enableSSR = Boolean(null != (_ref = null == (_userConfig_userConfig = userConfig.userConfig) ? void 0 : _userConfig_userConfig.ssr) ? _ref : Boolean(null == modernjsConfig ? void 0 : null == (_modernjsConfig_server = modernjsConfig.server) ? void 0 : _modernjsConfig_server.ssr));
213
207
  api.modifyBundlerChain((chain)=>{
208
+ var _modernjsConfig_source, _targetMFConfig_experiments;
209
+ const bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
214
210
  const target = chain.get('target');
215
211
  if (skipByTarget(target)) return;
216
212
  const isWeb = isWebTarget(target);
217
213
  addMyTypes2Ignored(chain, isWeb ? csrConfig : ssrConfig);
218
214
  const targetMFConfig = isWeb ? csrConfig : ssrConfig;
219
- patchMFConfig(targetMFConfig, !isWeb, userConfig.remoteIpStrategy || 'ipv4', enableSSR);
215
+ patchMFConfig(targetMFConfig, !isWeb);
216
+ if ('rspack' === bundlerType && (null == (_modernjsConfig_source = modernjsConfig.source) ? void 0 : _modernjsConfig_source.enableAsyncEntry) !== true && (null == (_targetMFConfig_experiments = targetMFConfig.experiments) ? void 0 : _targetMFConfig_experiments.asyncStartup) !== false) {
217
+ var _targetMFConfig;
218
+ (_targetMFConfig = targetMFConfig).experiments || (_targetMFConfig.experiments = {});
219
+ targetMFConfig.experiments.asyncStartup = true;
220
+ }
220
221
  patchBundlerConfig({
221
222
  chain,
222
223
  isServer: !isWeb,
@@ -237,9 +238,6 @@ const moduleFederationConfigPlugin = (userConfig)=>({
237
238
  var _ref;
238
239
  var _modernjsConfig_tools, _userConfig_csrConfig, _modernjsConfig_source, _modernjsConfig_source1, _modernjsConfig_dev;
239
240
  const bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
240
- const ipv4 = getIPV4();
241
- if (void 0 === userConfig.remoteIpStrategy) if (enableSSR) userConfig.remoteIpStrategy = 'ipv4';
242
- else userConfig.remoteIpStrategy = 'inherit';
243
241
  const devServerConfig = null == (_modernjsConfig_tools = modernjsConfig.tools) ? void 0 : _modernjsConfig_tools.devServer;
244
242
  const corsWarnMsgs = [
245
243
  'View https://module-federation.io/guide/troubleshooting/other.html#cors-warn for more details.'
@@ -253,10 +251,6 @@ const moduleFederationConfigPlugin = (userConfig)=>({
253
251
  'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
254
252
  'Access-Control-Allow-Headers': '*'
255
253
  } : void 0;
256
- const defineConfig = {
257
- REMOTE_IP_STRATEGY: JSON.stringify(userConfig.remoteIpStrategy)
258
- };
259
- if (enableSSR && isDev()) defineConfig['FEDERATION_IPV4'] = JSON.stringify(ipv4);
260
254
  return {
261
255
  tools: {
262
256
  devServer: {
@@ -269,7 +263,6 @@ const moduleFederationConfigPlugin = (userConfig)=>({
269
263
  }
270
264
  },
271
265
  source: {
272
- define: defineConfig,
273
266
  enableAsyncEntry: 'rspack' === bundlerType ? null != (_ref = null == (_modernjsConfig_source = modernjsConfig.source) ? void 0 : _modernjsConfig_source.enableAsyncEntry) ? _ref : true : null == (_modernjsConfig_source1 = modernjsConfig.source) ? void 0 : _modernjsConfig_source1.enableAsyncEntry
274
267
  },
275
268
  dev: {
@@ -15,7 +15,6 @@ const moduleFederationPlugin = (userConfig = {})=>{
15
15
  originPluginOptions: {
16
16
  ...userConfig
17
17
  },
18
- remoteIpStrategy: null == userConfig ? void 0 : userConfig.remoteIpStrategy,
19
18
  userConfig: userConfig || {},
20
19
  assetFileNames: {},
21
20
  fetchServerQuery: null != (_userConfig_fetchServerQuery = userConfig.fetchServerQuery) ? _userConfig_fetchServerQuery : void 0,
@@ -4,10 +4,17 @@ import { PluginOptions } from '../types';
4
4
  import type { InternalModernPluginOptions } from '../types';
5
5
  import type { AppTools, webpack, UserConfig, Rspack, CliPluginFuture } from '@modern-js/app-tools';
6
6
  import type { BundlerChainConfig } from '../interfaces/bundler';
7
+ declare global {
8
+ namespace NodeJS {
9
+ interface ProcessEnv {
10
+ IS_ESM_BUILD?: string;
11
+ }
12
+ }
13
+ }
7
14
  export type ConfigType<T> = T extends 'webpack' ? webpack.Configuration : T extends 'rspack' ? Rspack.Configuration : never;
8
15
  export declare function setEnv(enableSSR: boolean): void;
9
16
  export declare const getMFConfig: (userConfig: PluginOptions) => Promise<moduleFederationPlugin.ModuleFederationPluginOptions>;
10
- export declare const patchMFConfig: (mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions, isServer: boolean, remoteIpStrategy?: "ipv4" | "inherit", enableSSR?: boolean) => moduleFederationPlugin.ModuleFederationPluginOptions;
17
+ export declare const patchMFConfig: (mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions, isServer: boolean) => moduleFederationPlugin.ModuleFederationPluginOptions;
11
18
  export declare function addMyTypes2Ignored(chain: BundlerChainConfig, mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions): void;
12
19
  export declare function patchBundlerConfig(options: {
13
20
  chain: BundlerChainConfig;
@@ -6,7 +6,6 @@ export interface PluginOptions {
6
6
  ssr?: {
7
7
  distOutputDir?: string;
8
8
  } | boolean;
9
- remoteIpStrategy?: 'ipv4' | 'inherit';
10
9
  fetchServerQuery?: Record<string, unknown>;
11
10
  secondarySharedTreeShaking?: boolean;
12
11
  }
@@ -29,7 +28,6 @@ export interface InternalModernPluginOptions {
29
28
  browser?: StatsAssetResource;
30
29
  node?: StatsAssetResource;
31
30
  };
32
- remoteIpStrategy?: 'ipv4' | 'inherit';
33
31
  userConfig?: PluginOptions;
34
32
  fetchServerQuery?: Record<string, unknown>;
35
33
  secondarySharedTreeShaking?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/modern-js",
3
- "version": "0.24.1",
3
+ "version": "2.2.0",
4
4
  "files": [
5
5
  "dist/",
6
6
  "types.d.ts",
@@ -63,11 +63,6 @@
63
63
  "import": "./dist/esm/cli/mfRuntimePlugins/shared-strategy.mjs",
64
64
  "require": "./dist/cjs/cli/mfRuntimePlugins/shared-strategy.js"
65
65
  },
66
- "./resolve-entry-ipv4": {
67
- "types": "./dist/types/cli/mfRuntimePlugins/resolve-entry-ipv4.d.ts",
68
- "import": "./dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.mjs",
69
- "require": "./dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js"
70
- },
71
66
  "./inject-node-fetch": {
72
67
  "types": "./dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts",
73
68
  "import": "./dist/esm/cli/mfRuntimePlugins/inject-node-fetch.mjs",
@@ -111,9 +106,6 @@
111
106
  "shared-strategy": [
112
107
  "./dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts"
113
108
  ],
114
- "resolve-entry-ipv4": [
115
- "./dist/types/cli/mfRuntimePlugins/resolve-entry-ipv4.d.ts"
116
- ],
117
109
  "inject-node-fetch": [
118
110
  "./dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts"
119
111
  ],
@@ -133,33 +125,33 @@
133
125
  "author": "hanric <hanric.zhang@gmail.com>",
134
126
  "license": "MIT",
135
127
  "dependencies": {
136
- "@modern-js/utils": "2.70.2",
128
+ "@modern-js/utils": "2.70.5",
137
129
  "fs-extra": "11.3.0",
138
130
  "lru-cache": "10.4.3",
139
131
  "@swc/helpers": "^0.5.17",
140
132
  "node-fetch": "~3.3.0",
141
133
  "jiti": "2.4.2",
142
134
  "react-error-boundary": "4.1.2",
143
- "@module-federation/rsbuild-plugin": "0.24.1",
144
- "@module-federation/bridge-react": "0.24.1",
145
- "@module-federation/enhanced": "0.24.1",
146
- "@module-federation/runtime": "0.24.1",
147
- "@module-federation/node": "2.7.30",
148
- "@module-federation/sdk": "0.24.1",
149
- "@module-federation/cli": "0.24.1"
135
+ "@module-federation/rsbuild-plugin": "2.2.0",
136
+ "@module-federation/bridge-react": "2.2.0",
137
+ "@module-federation/enhanced": "2.2.0",
138
+ "@module-federation/node": "2.7.34",
139
+ "@module-federation/sdk": "2.2.0",
140
+ "@module-federation/cli": "2.2.0",
141
+ "@module-federation/runtime": "2.2.0"
150
142
  },
151
143
  "devDependencies": {
152
- "@rsbuild/plugin-react": "1.4.2",
144
+ "@rsbuild/plugin-react": "1.4.5",
153
145
  "@rslib/core": "0.18.5",
154
146
  "@rsbuild/core": "1.3.21",
155
- "@modern-js/app-tools": "2.70.2",
156
- "@modern-js/server-runtime": "2.70.2",
157
- "@modern-js/module-tools": "2.70.2",
158
- "@modern-js/runtime": "2.70.2",
159
- "@modern-js/tsconfig": "2.70.2",
147
+ "@modern-js/app-tools": "2.70.5",
148
+ "@modern-js/server-runtime": "2.70.5",
149
+ "@modern-js/module-tools": "2.70.5",
150
+ "@modern-js/runtime": "2.70.5",
151
+ "@modern-js/tsconfig": "2.70.5",
160
152
  "@types/react": "^18.3.11",
161
153
  "@types/react-dom": "^18.3.0",
162
- "@module-federation/manifest": "0.24.1"
154
+ "@module-federation/manifest": "2.2.0"
163
155
  },
164
156
  "peerDependencies": {
165
157
  "react": ">=17",
@@ -184,6 +176,9 @@
184
176
  }
185
177
  },
186
178
  "scripts": {
187
- "build": "rslib build"
179
+ "build": "rslib build",
180
+ "lint": "ESLINT_USE_FLAT_CONFIG=false pnpm exec eslint --ignore-pattern node_modules \"**/*.ts\"",
181
+ "test": "pnpm exec vitest run --passWithNoTests --config vite.config.mts",
182
+ "pre-release": "pnpm run test && pnpm run build"
188
183
  }
189
184
  }
package/dist/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2024-present zhanghang(2heal1)
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,80 +0,0 @@
1
- "use strict";
2
- var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.d = (exports1, definition)=>{
5
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
- enumerable: true,
7
- get: definition[key]
8
- });
9
- };
10
- })();
11
- (()=>{
12
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
- })();
14
- (()=>{
15
- __webpack_require__.r = (exports1)=>{
16
- if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
- value: 'Module'
18
- });
19
- Object.defineProperty(exports1, '__esModule', {
20
- value: true
21
- });
22
- };
23
- })();
24
- var __webpack_exports__ = {};
25
- __webpack_require__.r(__webpack_exports__);
26
- __webpack_require__.d(__webpack_exports__, {
27
- default: ()=>resolve_entry_ipv4
28
- });
29
- const external_constant_js_namespaceObject = require("../../constant.js");
30
- const ipv4 = "u" > typeof FEDERATION_IPV4 ? FEDERATION_IPV4 : '127.0.0.1';
31
- const remoteIpStrategy = "u" > typeof REMOTE_IP_STRATEGY ? REMOTE_IP_STRATEGY : 'inherit';
32
- function replaceObjectLocalhost(key, obj) {
33
- if ('ipv4' !== remoteIpStrategy) return;
34
- if (!(key in obj)) return;
35
- const remote = obj[key];
36
- if (remote && 'string' == typeof remote && remote.includes(external_constant_js_namespaceObject.LOCALHOST)) obj[key] = replaceLocalhost(remote);
37
- }
38
- function replaceLocalhost(url) {
39
- return url.replace(external_constant_js_namespaceObject.LOCALHOST, ipv4);
40
- }
41
- const resolveEntryIpv4Plugin = ()=>({
42
- name: 'resolve-entry-ipv4',
43
- beforeRegisterRemote (args) {
44
- const { remote } = args;
45
- replaceObjectLocalhost('entry', remote);
46
- return args;
47
- },
48
- async afterResolve (args) {
49
- const { remoteInfo } = args;
50
- replaceObjectLocalhost('entry', remoteInfo);
51
- return args;
52
- },
53
- beforeLoadRemoteSnapshot (args) {
54
- const { moduleInfo } = args;
55
- if ('entry' in moduleInfo) {
56
- replaceObjectLocalhost('entry', moduleInfo);
57
- return args;
58
- }
59
- if ('version' in moduleInfo) replaceObjectLocalhost('version', moduleInfo);
60
- return args;
61
- },
62
- loadRemoteSnapshot (args) {
63
- const { remoteSnapshot } = args;
64
- if ('publicPath' in remoteSnapshot) replaceObjectLocalhost('publicPath', remoteSnapshot);
65
- if ('getPublicPath' in remoteSnapshot) replaceObjectLocalhost('getPublicPath', remoteSnapshot);
66
- if (remoteSnapshot.remotesInfo) Object.keys(remoteSnapshot.remotesInfo).forEach((key)=>{
67
- const remoteInfo = remoteSnapshot.remotesInfo[key];
68
- replaceObjectLocalhost('matchedVersion', remoteInfo);
69
- });
70
- return args;
71
- }
72
- });
73
- const resolve_entry_ipv4 = resolveEntryIpv4Plugin;
74
- exports["default"] = __webpack_exports__["default"];
75
- for(var __rspack_i in __webpack_exports__)if (-1 === [
76
- "default"
77
- ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
78
- Object.defineProperty(exports, '__esModule', {
79
- value: true
80
- });
@@ -1,58 +0,0 @@
1
- import { _ } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _ts_generator__ } from "@swc/helpers/_/_ts_generator";
3
- import { LOCALHOST } from "../../constant.mjs";
4
- var ipv4 = "u" > typeof FEDERATION_IPV4 ? FEDERATION_IPV4 : '127.0.0.1';
5
- var remoteIpStrategy = "u" > typeof REMOTE_IP_STRATEGY ? REMOTE_IP_STRATEGY : 'inherit';
6
- function replaceObjectLocalhost(key, obj) {
7
- if ('ipv4' !== remoteIpStrategy) return;
8
- if (!(key in obj)) return;
9
- var remote = obj[key];
10
- if (remote && 'string' == typeof remote && remote.includes(LOCALHOST)) obj[key] = replaceLocalhost(remote);
11
- }
12
- function replaceLocalhost(url) {
13
- return url.replace(LOCALHOST, ipv4);
14
- }
15
- var resolveEntryIpv4Plugin = function() {
16
- return {
17
- name: 'resolve-entry-ipv4',
18
- beforeRegisterRemote: function(args) {
19
- var remote = args.remote;
20
- replaceObjectLocalhost('entry', remote);
21
- return args;
22
- },
23
- afterResolve: function(args) {
24
- return _(function() {
25
- var remoteInfo;
26
- return _ts_generator__(this, function(_state) {
27
- remoteInfo = args.remoteInfo;
28
- replaceObjectLocalhost('entry', remoteInfo);
29
- return [
30
- 2,
31
- args
32
- ];
33
- });
34
- })();
35
- },
36
- beforeLoadRemoteSnapshot: function(args) {
37
- var moduleInfo = args.moduleInfo;
38
- if ('entry' in moduleInfo) {
39
- replaceObjectLocalhost('entry', moduleInfo);
40
- return args;
41
- }
42
- if ('version' in moduleInfo) replaceObjectLocalhost('version', moduleInfo);
43
- return args;
44
- },
45
- loadRemoteSnapshot: function(args) {
46
- var remoteSnapshot = args.remoteSnapshot;
47
- if ('publicPath' in remoteSnapshot) replaceObjectLocalhost('publicPath', remoteSnapshot);
48
- if ('getPublicPath' in remoteSnapshot) replaceObjectLocalhost('getPublicPath', remoteSnapshot);
49
- if (remoteSnapshot.remotesInfo) Object.keys(remoteSnapshot.remotesInfo).forEach(function(key) {
50
- var remoteInfo = remoteSnapshot.remotesInfo[key];
51
- replaceObjectLocalhost('matchedVersion', remoteInfo);
52
- });
53
- return args;
54
- }
55
- };
56
- };
57
- var resolve_entry_ipv4 = resolveEntryIpv4Plugin;
58
- export { resolve_entry_ipv4 as default };
@@ -1,46 +0,0 @@
1
- import { LOCALHOST } from "../../constant.mjs";
2
- const ipv4 = "u" > typeof FEDERATION_IPV4 ? FEDERATION_IPV4 : '127.0.0.1';
3
- const remoteIpStrategy = "u" > typeof REMOTE_IP_STRATEGY ? REMOTE_IP_STRATEGY : 'inherit';
4
- function replaceObjectLocalhost(key, obj) {
5
- if ('ipv4' !== remoteIpStrategy) return;
6
- if (!(key in obj)) return;
7
- const remote = obj[key];
8
- if (remote && 'string' == typeof remote && remote.includes(LOCALHOST)) obj[key] = replaceLocalhost(remote);
9
- }
10
- function replaceLocalhost(url) {
11
- return url.replace(LOCALHOST, ipv4);
12
- }
13
- const resolveEntryIpv4Plugin = ()=>({
14
- name: 'resolve-entry-ipv4',
15
- beforeRegisterRemote (args) {
16
- const { remote } = args;
17
- replaceObjectLocalhost('entry', remote);
18
- return args;
19
- },
20
- async afterResolve (args) {
21
- const { remoteInfo } = args;
22
- replaceObjectLocalhost('entry', remoteInfo);
23
- return args;
24
- },
25
- beforeLoadRemoteSnapshot (args) {
26
- const { moduleInfo } = args;
27
- if ('entry' in moduleInfo) {
28
- replaceObjectLocalhost('entry', moduleInfo);
29
- return args;
30
- }
31
- if ('version' in moduleInfo) replaceObjectLocalhost('version', moduleInfo);
32
- return args;
33
- },
34
- loadRemoteSnapshot (args) {
35
- const { remoteSnapshot } = args;
36
- if ('publicPath' in remoteSnapshot) replaceObjectLocalhost('publicPath', remoteSnapshot);
37
- if ('getPublicPath' in remoteSnapshot) replaceObjectLocalhost('getPublicPath', remoteSnapshot);
38
- if (remoteSnapshot.remotesInfo) Object.keys(remoteSnapshot.remotesInfo).forEach((key)=>{
39
- const remoteInfo = remoteSnapshot.remotesInfo[key];
40
- replaceObjectLocalhost('matchedVersion', remoteInfo);
41
- });
42
- return args;
43
- }
44
- });
45
- const resolve_entry_ipv4 = resolveEntryIpv4Plugin;
46
- export { resolve_entry_ipv4 as default };
@@ -1,3 +0,0 @@
1
- import type { ModuleFederationRuntimePlugin } from '@module-federation/enhanced/runtime';
2
- declare const resolveEntryIpv4Plugin: () => ModuleFederationRuntimePlugin;
3
- export default resolveEntryIpv4Plugin;