@module-federation/modern-js 0.21.6 → 0.22.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.
Files changed (113) hide show
  1. package/dist/cjs/cli/configPlugin.js +301 -357
  2. package/dist/cjs/cli/index.js +103 -93
  3. package/dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js +51 -41
  4. package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +73 -75
  5. package/dist/cjs/cli/mfRuntimePlugins/shared-strategy.js +50 -40
  6. package/dist/cjs/cli/server/data-fetch-server-plugin.js +55 -44
  7. package/dist/cjs/cli/ssrPlugin.js +266 -298
  8. package/dist/cjs/cli/utils.js +84 -81
  9. package/dist/cjs/constant.js +37 -28
  10. package/dist/cjs/interfaces/bundler.js +17 -15
  11. package/dist/cjs/logger.js +37 -25
  12. package/dist/cjs/react/index.js +55 -19
  13. package/dist/cjs/react/plugin.js +62 -37
  14. package/dist/cjs/react/v18.js +55 -19
  15. package/dist/cjs/react/v19.js +55 -19
  16. package/dist/cjs/runtime/index.js +55 -19
  17. package/dist/cjs/server/fileCache.js +76 -76
  18. package/dist/cjs/server/index.js +65 -57
  19. package/dist/cjs/server/staticMiddleware.js +84 -84
  20. package/dist/cjs/ssr-runtime/SSRLiveReload.js +40 -34
  21. package/dist/cjs/ssr-runtime/devPlugin.js +63 -67
  22. package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +44 -36
  23. package/dist/cjs/types/index.js +17 -15
  24. package/dist/esm/cli/configPlugin.mjs +305 -0
  25. package/dist/esm/cli/index.mjs +83 -0
  26. package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.mjs +12 -0
  27. package/dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.mjs +58 -0
  28. package/dist/esm/cli/mfRuntimePlugins/shared-strategy.mjs +21 -0
  29. package/dist/esm/cli/server/data-fetch-server-plugin.mjs +17 -0
  30. package/dist/esm/cli/ssrPlugin.mjs +254 -0
  31. package/dist/esm/cli/utils.mjs +40 -0
  32. package/dist/esm/constant.mjs +3 -0
  33. package/dist/esm/logger.mjs +5 -0
  34. package/dist/esm/react/plugin.mjs +3 -0
  35. package/dist/esm/server/fileCache.mjs +90 -0
  36. package/dist/esm/server/index.mjs +36 -0
  37. package/dist/esm/server/staticMiddleware.mjs +87 -0
  38. package/dist/esm/ssr-runtime/SSRLiveReload.mjs +22 -0
  39. package/dist/esm/ssr-runtime/devPlugin.mjs +70 -0
  40. package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.mjs +34 -0
  41. package/dist/esm-node/cli/configPlugin.mjs +263 -0
  42. package/dist/esm-node/cli/index.mjs +67 -0
  43. package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.mjs +10 -0
  44. package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.mjs +46 -0
  45. package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.mjs +19 -0
  46. package/dist/esm-node/cli/server/data-fetch-server-plugin.mjs +15 -0
  47. package/dist/esm-node/cli/ssrPlugin.mjs +228 -0
  48. package/dist/esm-node/cli/utils.mjs +40 -0
  49. package/dist/esm-node/constant.mjs +3 -0
  50. package/dist/esm-node/logger.mjs +5 -0
  51. package/dist/esm-node/react/plugin.mjs +3 -0
  52. package/dist/esm-node/server/fileCache.mjs +37 -0
  53. package/dist/esm-node/server/index.mjs +34 -0
  54. package/dist/esm-node/server/staticMiddleware.mjs +42 -0
  55. package/dist/esm-node/ssr-runtime/SSRLiveReload.mjs +15 -0
  56. package/dist/esm-node/ssr-runtime/devPlugin.mjs +33 -0
  57. package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.mjs +14 -0
  58. package/package.json +32 -31
  59. package/dist/cjs/cli/configPlugin.spec.js +0 -112
  60. package/dist/cjs/server/fileCache.spec.js +0 -28
  61. package/dist/cjs/server/staticMiddleware.spec.js +0 -185
  62. package/dist/esm/cli/configPlugin.js +0 -395
  63. package/dist/esm/cli/configPlugin.spec.js +0 -108
  64. package/dist/esm/cli/index.js +0 -92
  65. package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.js +0 -16
  66. package/dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -74
  67. package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +0 -25
  68. package/dist/esm/cli/server/data-fetch-server-plugin.js +0 -20
  69. package/dist/esm/cli/ssrPlugin.js +0 -305
  70. package/dist/esm/cli/utils.js +0 -53
  71. package/dist/esm/constant.js +0 -6
  72. package/dist/esm/logger.js +0 -7
  73. package/dist/esm/react/plugin.js +0 -5
  74. package/dist/esm/server/fileCache.js +0 -98
  75. package/dist/esm/server/fileCache.spec.js +0 -50
  76. package/dist/esm/server/index.js +0 -41
  77. package/dist/esm/server/staticMiddleware.js +0 -104
  78. package/dist/esm/server/staticMiddleware.spec.js +0 -328
  79. package/dist/esm/ssr-runtime/SSRLiveReload.js +0 -26
  80. package/dist/esm/ssr-runtime/devPlugin.js +0 -73
  81. package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -34
  82. package/dist/esm-node/cli/configPlugin.js +0 -347
  83. package/dist/esm-node/cli/configPlugin.spec.js +0 -89
  84. package/dist/esm-node/cli/index.js +0 -72
  85. package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.js +0 -14
  86. package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -62
  87. package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +0 -23
  88. package/dist/esm-node/cli/server/data-fetch-server-plugin.js +0 -18
  89. package/dist/esm-node/cli/ssrPlugin.js +0 -280
  90. package/dist/esm-node/cli/utils.js +0 -53
  91. package/dist/esm-node/constant.js +0 -6
  92. package/dist/esm-node/logger.js +0 -7
  93. package/dist/esm-node/react/plugin.js +0 -5
  94. package/dist/esm-node/server/fileCache.js +0 -49
  95. package/dist/esm-node/server/fileCache.spec.js +0 -27
  96. package/dist/esm-node/server/index.js +0 -39
  97. package/dist/esm-node/server/staticMiddleware.js +0 -55
  98. package/dist/esm-node/server/staticMiddleware.spec.js +0 -162
  99. package/dist/esm-node/ssr-runtime/SSRLiveReload.js +0 -19
  100. package/dist/esm-node/ssr-runtime/devPlugin.js +0 -37
  101. package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -16
  102. /package/dist/esm/interfaces/{bundler.js → bundler.mjs} +0 -0
  103. /package/dist/esm/react/{index.js → index.mjs} +0 -0
  104. /package/dist/esm/react/{v18.js → v18.mjs} +0 -0
  105. /package/dist/esm/react/{v19.js → v19.mjs} +0 -0
  106. /package/dist/esm/runtime/{index.js → index.mjs} +0 -0
  107. /package/dist/esm/types/{index.js → index.mjs} +0 -0
  108. /package/dist/esm-node/interfaces/{bundler.js → bundler.mjs} +0 -0
  109. /package/dist/esm-node/react/{index.js → index.mjs} +0 -0
  110. /package/dist/esm-node/react/{v18.js → v18.mjs} +0 -0
  111. /package/dist/esm-node/react/{v19.js → v19.mjs} +0 -0
  112. /package/dist/esm-node/runtime/{index.js → index.mjs} +0 -0
  113. /package/dist/esm-node/types/{index.js → index.mjs} +0 -0
@@ -1,395 +0,0 @@
1
- import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
3
- import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
4
- import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
5
- import { _ as _type_of } from "@swc/helpers/_/_type_of";
6
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
7
- import path from "path";
8
- import { getIPV4, isWebTarget, skipByTarget } from "./utils";
9
- import { encodeName } from "@module-federation/sdk";
10
- import { bundle } from "@modern-js/node-bundle-require";
11
- import { LOCALHOST, PLUGIN_IDENTIFIER } from "../constant";
12
- import { autoDeleteSplitChunkCacheGroups, addDataFetchExposes } from "@module-federation/rsbuild-plugin/utils";
13
- import logger from "../logger";
14
- import { isDev } from "./utils";
15
- var defaultPath = path.resolve(process.cwd(), "module-federation.config.ts");
16
- function setEnv(enableSSR) {
17
- if (enableSSR) {
18
- process.env["MF_SSR_PRJ"] = "true";
19
- }
20
- }
21
- var getMFConfig = function() {
22
- var _ref = _async_to_generator(function(userConfig) {
23
- var config, configPath, mfConfigPath, preBundlePath, mfConfig;
24
- return _ts_generator(this, function(_state) {
25
- switch (_state.label) {
26
- case 0:
27
- config = userConfig.config, configPath = userConfig.configPath;
28
- if (config) {
29
- return [
30
- 2,
31
- config
32
- ];
33
- }
34
- mfConfigPath = configPath ? configPath : defaultPath;
35
- return [
36
- 4,
37
- bundle(mfConfigPath)
38
- ];
39
- case 1:
40
- preBundlePath = _state.sent();
41
- return [
42
- 4,
43
- import(preBundlePath)
44
- ];
45
- case 2:
46
- mfConfig = _state.sent().default;
47
- return [
48
- 2,
49
- mfConfig
50
- ];
51
- }
52
- });
53
- });
54
- return function getMFConfig2(userConfig) {
55
- return _ref.apply(this, arguments);
56
- };
57
- }();
58
- var injectRuntimePlugins = function(runtimePlugin, runtimePlugins) {
59
- var pluginName = typeof runtimePlugin === "string" ? runtimePlugin : runtimePlugin[0];
60
- var hasPlugin = runtimePlugins.some(function(existingPlugin) {
61
- if (typeof existingPlugin === "string") {
62
- return existingPlugin === pluginName;
63
- }
64
- return existingPlugin[0] === pluginName;
65
- });
66
- if (!hasPlugin) {
67
- runtimePlugins.push(runtimePlugin);
68
- }
69
- };
70
- var replaceRemoteUrl = function(mfConfig, remoteIpStrategy) {
71
- if (remoteIpStrategy && remoteIpStrategy === "inherit") {
72
- return;
73
- }
74
- if (!mfConfig.remotes) {
75
- return;
76
- }
77
- var ipv4 = getIPV4();
78
- var handleRemoteObject = function(remoteObject) {
79
- Object.keys(remoteObject).forEach(function(remoteKey) {
80
- var remote = remoteObject[remoteKey];
81
- if (Array.isArray(remote)) {
82
- return;
83
- }
84
- if (typeof remote === "string" && remote.includes(LOCALHOST)) {
85
- remoteObject[remoteKey] = remote.replace(LOCALHOST, ipv4);
86
- }
87
- if ((typeof remote === "undefined" ? "undefined" : _type_of(remote)) === "object" && !Array.isArray(remote.external) && remote.external.includes(LOCALHOST)) {
88
- remote.external = remote.external.replace(LOCALHOST, ipv4);
89
- }
90
- });
91
- };
92
- if (Array.isArray(mfConfig.remotes)) {
93
- mfConfig.remotes.forEach(function(remoteObject) {
94
- if (typeof remoteObject === "string") {
95
- return;
96
- }
97
- handleRemoteObject(remoteObject);
98
- });
99
- } else if (typeof mfConfig.remotes !== "string") {
100
- handleRemoteObject(mfConfig.remotes);
101
- }
102
- };
103
- var patchDTSConfig = function(mfConfig, isServer) {
104
- if (isServer) {
105
- return;
106
- }
107
- var ModernJSRuntime = "@module-federation/modern-js/runtime";
108
- if (mfConfig.dts !== false) {
109
- var _mfConfig_dts, _mfConfig_dts1;
110
- if (typeof mfConfig.dts === "boolean" || mfConfig.dts === void 0) {
111
- mfConfig.dts = {
112
- consumeTypes: {
113
- runtimePkgs: [
114
- ModernJSRuntime
115
- ]
116
- }
117
- };
118
- } else if (((_mfConfig_dts = mfConfig.dts) === null || _mfConfig_dts === void 0 ? void 0 : _mfConfig_dts.consumeTypes) || ((_mfConfig_dts1 = mfConfig.dts) === null || _mfConfig_dts1 === void 0 ? void 0 : _mfConfig_dts1.consumeTypes) === void 0) {
119
- var _mfConfig_dts2;
120
- if (typeof mfConfig.dts.consumeTypes === "boolean" || ((_mfConfig_dts2 = mfConfig.dts) === null || _mfConfig_dts2 === void 0 ? void 0 : _mfConfig_dts2.consumeTypes) === void 0) {
121
- mfConfig.dts.consumeTypes = {
122
- runtimePkgs: [
123
- ModernJSRuntime
124
- ]
125
- };
126
- } else {
127
- mfConfig.dts.consumeTypes.runtimePkgs = mfConfig.dts.consumeTypes.runtimePkgs || [];
128
- if (!mfConfig.dts.consumeTypes.runtimePkgs.includes(ModernJSRuntime)) {
129
- mfConfig.dts.consumeTypes.runtimePkgs.push(ModernJSRuntime);
130
- }
131
- }
132
- }
133
- }
134
- };
135
- var patchMFConfig = function(mfConfig, isServer, remoteIpStrategy, enableSSR) {
136
- replaceRemoteUrl(mfConfig, remoteIpStrategy);
137
- addDataFetchExposes(mfConfig.exposes, isServer);
138
- if (mfConfig.remoteType === void 0) {
139
- mfConfig.remoteType = "script";
140
- }
141
- if (!mfConfig.name) {
142
- throw new Error("".concat(PLUGIN_IDENTIFIER, " mfConfig.name can not be empty!"));
143
- }
144
- var runtimePlugins = _to_consumable_array(mfConfig.runtimePlugins || []);
145
- patchDTSConfig(mfConfig, isServer);
146
- injectRuntimePlugins(require.resolve("@module-federation/modern-js/shared-strategy"), runtimePlugins);
147
- if (enableSSR && isDev()) {
148
- injectRuntimePlugins(require.resolve("@module-federation/modern-js/resolve-entry-ipv4"), runtimePlugins);
149
- }
150
- if (isServer) {
151
- injectRuntimePlugins(require.resolve("@module-federation/node/runtimePlugin"), runtimePlugins);
152
- if (isDev()) {
153
- injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
154
- }
155
- injectRuntimePlugins(require.resolve("@module-federation/modern-js/inject-node-fetch"), runtimePlugins);
156
- if (!mfConfig.library) {
157
- mfConfig.library = {
158
- type: "commonjs-module",
159
- name: mfConfig.name
160
- };
161
- } else {
162
- if (!mfConfig.library.type) {
163
- mfConfig.library.type = "commonjs-module";
164
- }
165
- if (!mfConfig.library.name) {
166
- mfConfig.library.name = mfConfig.name;
167
- }
168
- }
169
- }
170
- mfConfig.runtimePlugins = runtimePlugins;
171
- if (!isServer) {
172
- var _mfConfig_library;
173
- if (((_mfConfig_library = mfConfig.library) === null || _mfConfig_library === void 0 ? void 0 : _mfConfig_library.type) === "commonjs-module") {
174
- mfConfig.library.type = "global";
175
- }
176
- return mfConfig;
177
- }
178
- mfConfig.dts = false;
179
- mfConfig.dev = false;
180
- return mfConfig;
181
- };
182
- function patchIgnoreWarning(chain) {
183
- var ignoreWarnings = chain.get("ignoreWarnings") || [];
184
- var ignoredMsgs = [
185
- "external script",
186
- "process.env.WS_NO_BUFFER_UTIL",
187
- "Can't resolve 'utf-8-validate"
188
- ];
189
- ignoreWarnings.push(function(warning) {
190
- if (ignoredMsgs.some(function(msg) {
191
- return warning.message.includes(msg);
192
- })) {
193
- return true;
194
- }
195
- return false;
196
- });
197
- chain.ignoreWarnings(ignoreWarnings);
198
- }
199
- function addMyTypes2Ignored(chain, mfConfig) {
200
- var watchOptions = chain.get("watchOptions");
201
- if (!watchOptions || !watchOptions.ignored) {
202
- chain.watchOptions({
203
- ignored: /[\\/](?:\.git|node_modules|@mf-types)[\\/]/
204
- });
205
- return;
206
- }
207
- var ignored = watchOptions.ignored;
208
- var DEFAULT_IGNORED_GLOB = "**/@mf-types/**";
209
- if (Array.isArray(ignored)) {
210
- if (mfConfig.dts !== false && _type_of(mfConfig.dts) === "object" && _type_of(mfConfig.dts.consumeTypes) === "object" && mfConfig.dts.consumeTypes.remoteTypesFolder) {
211
- chain.watchOptions(_object_spread_props(_object_spread({}, watchOptions), {
212
- ignored: ignored.concat("**/".concat(mfConfig.dts.consumeTypes.remoteTypesFolder, "/**"))
213
- }));
214
- } else {
215
- chain.watchOptions(_object_spread_props(_object_spread({}, watchOptions), {
216
- ignored: ignored.concat(DEFAULT_IGNORED_GLOB)
217
- }));
218
- }
219
- return;
220
- }
221
- if (typeof ignored !== "string") {
222
- chain.watchOptions(_object_spread_props(_object_spread({}, watchOptions), {
223
- ignored: /[\\/](?:\.git|node_modules|@mf-types)[\\/]/
224
- }));
225
- return;
226
- }
227
- chain.watchOptions(_object_spread_props(_object_spread({}, watchOptions), {
228
- ignored: ignored.concat(DEFAULT_IGNORED_GLOB)
229
- }));
230
- }
231
- function patchBundlerConfig(options) {
232
- var _modernjsConfig_deploy;
233
- var chain = options.chain, modernjsConfig = options.modernjsConfig, isServer = options.isServer, mfConfig = options.mfConfig, enableSSR = options.enableSSR;
234
- chain.optimization.delete("runtimeChunk");
235
- patchIgnoreWarning(chain);
236
- if (!chain.output.get("chunkLoadingGlobal")) {
237
- chain.output.chunkLoadingGlobal("chunk_".concat(mfConfig.name));
238
- }
239
- if (!chain.output.get("uniqueName")) {
240
- chain.output.uniqueName(mfConfig.name);
241
- }
242
- var splitChunkConfig = chain.optimization.splitChunks.entries();
243
- if (!isServer) {
244
- autoDeleteSplitChunkCacheGroups(mfConfig, splitChunkConfig);
245
- }
246
- if (!isServer && enableSSR && splitChunkConfig && (typeof splitChunkConfig === "undefined" ? "undefined" : _type_of(splitChunkConfig)) === "object" && splitChunkConfig.cacheGroups) {
247
- splitChunkConfig.chunks = "async";
248
- logger.warn('splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"');
249
- }
250
- if (isDev() && chain.output.get("publicPath") === "auto") {
251
- var _modernjsConfig_dev, _modernjsConfig_server;
252
- var port = ((_modernjsConfig_dev = modernjsConfig.dev) === null || _modernjsConfig_dev === void 0 ? void 0 : _modernjsConfig_dev.port) || ((_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.port) || 8080;
253
- var publicPath = "http://localhost:".concat(port, "/");
254
- chain.output.publicPath(publicPath);
255
- }
256
- if (isServer && enableSSR) {
257
- var uniqueName = mfConfig.name || chain.output.get("uniqueName");
258
- var chunkFileName = chain.output.get("chunkFilename");
259
- if (typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
260
- var suffix = "".concat(encodeName(uniqueName), "-[contenthash].js");
261
- chain.output.chunkFilename(chunkFileName.replace(".js", suffix));
262
- }
263
- }
264
- if (isDev() && enableSSR && !isServer) {
265
- chain.resolve.fallback.set("crypto", false).set("stream", false).set("vm", false);
266
- }
267
- if (((_modernjsConfig_deploy = modernjsConfig.deploy) === null || _modernjsConfig_deploy === void 0 ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) {
268
- chain.optimization.usedExports(false);
269
- }
270
- }
271
- var moduleFederationConfigPlugin = function(userConfig) {
272
- return {
273
- name: "@modern-js/plugin-module-federation-config",
274
- pre: [
275
- "@modern-js/plugin-initialize"
276
- ],
277
- post: [
278
- "@modern-js/plugin-module-federation"
279
- ],
280
- setup: function() {
281
- var _ref = _async_to_generator(function(api) {
282
- var _userConfig_userConfig, _modernjsConfig_server, modernjsConfig, mfConfig, csrConfig, ssrConfig, _userConfig_userConfig_ssr, enableSSR;
283
- return _ts_generator(this, function(_state) {
284
- switch (_state.label) {
285
- case 0:
286
- modernjsConfig = api.getConfig();
287
- return [
288
- 4,
289
- getMFConfig(userConfig.originPluginOptions)
290
- ];
291
- case 1:
292
- mfConfig = _state.sent();
293
- csrConfig = userConfig.csrConfig || JSON.parse(JSON.stringify(mfConfig));
294
- ssrConfig = userConfig.ssrConfig || JSON.parse(JSON.stringify(mfConfig));
295
- userConfig.ssrConfig = ssrConfig;
296
- userConfig.csrConfig = csrConfig;
297
- enableSSR = Boolean((_userConfig_userConfig_ssr = (_userConfig_userConfig = userConfig.userConfig) === null || _userConfig_userConfig === void 0 ? void 0 : _userConfig_userConfig.ssr) !== null && _userConfig_userConfig_ssr !== void 0 ? _userConfig_userConfig_ssr : Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr));
298
- api.modifyBundlerChain(function(chain) {
299
- var target = chain.get("target");
300
- if (skipByTarget(target)) {
301
- return;
302
- }
303
- var isWeb = isWebTarget(target);
304
- addMyTypes2Ignored(chain, !isWeb ? ssrConfig : csrConfig);
305
- var targetMFConfig = !isWeb ? ssrConfig : csrConfig;
306
- patchMFConfig(targetMFConfig, !isWeb, userConfig.remoteIpStrategy || "ipv4", enableSSR);
307
- patchBundlerConfig({
308
- chain,
309
- isServer: !isWeb,
310
- modernjsConfig,
311
- mfConfig,
312
- enableSSR
313
- });
314
- userConfig.distOutputDir = chain.output.get("path") || path.resolve(process.cwd(), "dist");
315
- });
316
- api.config(function() {
317
- var _modernjsConfig_tools, _userConfig_csrConfig, _modernjsConfig_source, _modernjsConfig_source1, _modernjsConfig_dev;
318
- var bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
319
- var ipv4 = getIPV4();
320
- if (userConfig.remoteIpStrategy === void 0) {
321
- if (!enableSSR) {
322
- userConfig.remoteIpStrategy = "inherit";
323
- } else {
324
- userConfig.remoteIpStrategy = "ipv4";
325
- }
326
- }
327
- var devServerConfig = (_modernjsConfig_tools = modernjsConfig.tools) === null || _modernjsConfig_tools === void 0 ? void 0 : _modernjsConfig_tools.devServer;
328
- var corsWarnMsgs = [
329
- "View https://module-federation.io/guide/troubleshooting/other.html#cors-warn for more details."
330
- ];
331
- if ((typeof devServerConfig === "undefined" ? "undefined" : _type_of(devServerConfig)) !== "object" || !("headers" in devServerConfig)) {
332
- corsWarnMsgs.unshift('Detect devServer.headers is empty, mf modern plugin will add default cors header: devServer.headers["Access-Control-Allow-Headers"] = "*". It is recommended to specify an allowlist of trusted origins instead.');
333
- }
334
- var exposes = (_userConfig_csrConfig = userConfig.csrConfig) === null || _userConfig_csrConfig === void 0 ? void 0 : _userConfig_csrConfig.exposes;
335
- var hasExposes = exposes && Array.isArray(exposes) ? exposes.length : Object.keys(exposes !== null && exposes !== void 0 ? exposes : {}).length;
336
- if (corsWarnMsgs.length > 1 && hasExposes) {
337
- logger.warn(corsWarnMsgs.join("\n"));
338
- }
339
- var corsHeaders = hasExposes ? {
340
- "Access-Control-Allow-Origin": "*",
341
- "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
342
- "Access-Control-Allow-Headers": "*"
343
- } : void 0;
344
- var defineConfig = {
345
- REMOTE_IP_STRATEGY: JSON.stringify(userConfig.remoteIpStrategy)
346
- };
347
- if (enableSSR && isDev()) {
348
- defineConfig["FEDERATION_IPV4"] = JSON.stringify(ipv4);
349
- }
350
- var _modernjsConfig_source_enableAsyncEntry;
351
- return {
352
- tools: {
353
- devServer: {
354
- headers: corsHeaders
355
- }
356
- },
357
- resolve: {
358
- alias: {
359
- // TODO: deprecated
360
- "@modern-js/runtime/mf": require.resolve("@module-federation/modern-js/runtime")
361
- }
362
- },
363
- source: {
364
- define: defineConfig,
365
- enableAsyncEntry: bundlerType === "rspack" ? (_modernjsConfig_source_enableAsyncEntry = (_modernjsConfig_source = modernjsConfig.source) === null || _modernjsConfig_source === void 0 ? void 0 : _modernjsConfig_source.enableAsyncEntry) !== null && _modernjsConfig_source_enableAsyncEntry !== void 0 ? _modernjsConfig_source_enableAsyncEntry : true : (_modernjsConfig_source1 = modernjsConfig.source) === null || _modernjsConfig_source1 === void 0 ? void 0 : _modernjsConfig_source1.enableAsyncEntry
366
- },
367
- dev: {
368
- assetPrefix: (modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_dev = modernjsConfig.dev) === null || _modernjsConfig_dev === void 0 ? void 0 : _modernjsConfig_dev.assetPrefix) ? modernjsConfig.dev.assetPrefix : true
369
- }
370
- };
371
- });
372
- return [
373
- 2
374
- ];
375
- }
376
- });
377
- });
378
- return function(api) {
379
- return _ref.apply(this, arguments);
380
- };
381
- }()
382
- };
383
- };
384
- var configPlugin_default = moduleFederationConfigPlugin;
385
- export {
386
- addMyTypes2Ignored,
387
- configPlugin_default as default,
388
- getMFConfig,
389
- isWebTarget,
390
- moduleFederationConfigPlugin,
391
- patchBundlerConfig,
392
- patchMFConfig,
393
- setEnv,
394
- skipByTarget
395
- };
@@ -1,108 +0,0 @@
1
- import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
- import { it, expect, describe } from "vitest";
4
- import { patchMFConfig } from "./configPlugin";
5
- import { getIPV4 } from "./utils";
6
- var mfConfig = {
7
- name: "host",
8
- filename: "remoteEntry.js",
9
- remotes: {
10
- remote: "http://localhost:3000/remoteEntry.js"
11
- },
12
- shared: {
13
- react: {
14
- singleton: true,
15
- eager: true
16
- },
17
- "react-dom": {
18
- singleton: true,
19
- eager: true
20
- }
21
- }
22
- };
23
- describe("patchMFConfig", /* @__PURE__ */ _async_to_generator(function() {
24
- return _ts_generator(this, function(_state) {
25
- it("patchMFConfig: server", /* @__PURE__ */ _async_to_generator(function() {
26
- var patchedConfig, ipv4;
27
- return _ts_generator(this, function(_state2) {
28
- patchedConfig = JSON.parse(JSON.stringify(mfConfig));
29
- patchMFConfig(patchedConfig, true);
30
- ipv4 = getIPV4();
31
- expect(patchedConfig).toStrictEqual({
32
- dev: false,
33
- dts: false,
34
- filename: "remoteEntry.js",
35
- library: {
36
- name: "host",
37
- type: "commonjs-module"
38
- },
39
- name: "host",
40
- remotes: {
41
- remote: "http://".concat(ipv4, ":3000/remoteEntry.js")
42
- },
43
- remoteType: "script",
44
- runtimePlugins: [
45
- require.resolve("@module-federation/modern-js/shared-strategy"),
46
- require.resolve("@module-federation/node/runtimePlugin"),
47
- require.resolve("@module-federation/modern-js/inject-node-fetch")
48
- ],
49
- shared: {
50
- react: {
51
- eager: true,
52
- singleton: true
53
- },
54
- "react-dom": {
55
- eager: true,
56
- singleton: true
57
- }
58
- }
59
- });
60
- return [
61
- 2
62
- ];
63
- });
64
- }));
65
- it("patchMFConfig: client", /* @__PURE__ */ _async_to_generator(function() {
66
- var patchedConfig, ipv4;
67
- return _ts_generator(this, function(_state2) {
68
- patchedConfig = JSON.parse(JSON.stringify(mfConfig));
69
- patchMFConfig(patchedConfig, false);
70
- ipv4 = getIPV4();
71
- expect(patchedConfig).toStrictEqual({
72
- filename: "remoteEntry.js",
73
- name: "host",
74
- remotes: {
75
- remote: "http://".concat(ipv4, ":3000/remoteEntry.js")
76
- },
77
- remoteType: "script",
78
- runtimePlugins: [
79
- require.resolve("@module-federation/modern-js/shared-strategy")
80
- ],
81
- shared: {
82
- react: {
83
- eager: true,
84
- singleton: true
85
- },
86
- "react-dom": {
87
- eager: true,
88
- singleton: true
89
- }
90
- },
91
- dts: {
92
- consumeTypes: {
93
- runtimePkgs: [
94
- "@module-federation/modern-js/runtime"
95
- ]
96
- }
97
- }
98
- });
99
- return [
100
- 2
101
- ];
102
- });
103
- }));
104
- return [
105
- 2
106
- ];
107
- });
108
- }));
@@ -1,92 +0,0 @@
1
- import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _type_of } from "@swc/helpers/_/_type_of";
3
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
- import { ModuleFederationPlugin as WebpackModuleFederationPlugin, AsyncBoundaryPlugin } from "@module-federation/enhanced";
5
- import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
6
- import { moduleFederationConfigPlugin } from "./configPlugin";
7
- import { moduleFederationSSRPlugin } from "./ssrPlugin";
8
- import { isWebTarget } from "./utils";
9
- var moduleFederationPlugin = function() {
10
- var userConfig = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
11
- var _userConfig_fetchServerQuery;
12
- var internalModernPluginOptions = {
13
- csrConfig: void 0,
14
- ssrConfig: void 0,
15
- browserPlugin: void 0,
16
- nodePlugin: void 0,
17
- assetResources: {},
18
- distOutputDir: "",
19
- originPluginOptions: userConfig,
20
- remoteIpStrategy: userConfig === null || userConfig === void 0 ? void 0 : userConfig.remoteIpStrategy,
21
- userConfig: userConfig || {},
22
- assetFileNames: {},
23
- fetchServerQuery: (_userConfig_fetchServerQuery = userConfig.fetchServerQuery) !== null && _userConfig_fetchServerQuery !== void 0 ? _userConfig_fetchServerQuery : void 0
24
- };
25
- return {
26
- name: "@modern-js/plugin-module-federation",
27
- setup: function() {
28
- var _ref = _async_to_generator(function(api) {
29
- var modernjsConfig;
30
- return _ts_generator(this, function(_state) {
31
- modernjsConfig = api.getConfig();
32
- api.modifyBundlerChain(function(chain) {
33
- var bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
34
- var browserPluginOptions = internalModernPluginOptions.csrConfig;
35
- var MFPlugin = bundlerType === "webpack" ? WebpackModuleFederationPlugin : RspackModuleFederationPlugin;
36
- if (isWebTarget(chain.get("target"))) {
37
- chain.plugin("plugin-module-federation").use(MFPlugin, [
38
- browserPluginOptions
39
- ]).init(function(Plugin, args) {
40
- internalModernPluginOptions.browserPlugin = new Plugin(args[0]);
41
- return internalModernPluginOptions.browserPlugin;
42
- });
43
- }
44
- if (bundlerType === "webpack") {
45
- var _modernjsConfig_source;
46
- var enableAsyncEntry = (_modernjsConfig_source = modernjsConfig.source) === null || _modernjsConfig_source === void 0 ? void 0 : _modernjsConfig_source.enableAsyncEntry;
47
- if (!enableAsyncEntry && browserPluginOptions.async !== false) {
48
- var asyncBoundaryPluginOptions = _type_of(browserPluginOptions.async) === "object" ? browserPluginOptions.async : {
49
- eager: function(module) {
50
- return module && /\.federation/.test((module === null || module === void 0 ? void 0 : module.request) || "");
51
- },
52
- excludeChunk: function(chunk) {
53
- return chunk.name === browserPluginOptions.name;
54
- }
55
- };
56
- chain.plugin("async-boundary-plugin").use(AsyncBoundaryPlugin, [
57
- asyncBoundaryPluginOptions
58
- ]);
59
- }
60
- }
61
- });
62
- api._internalServerPlugins(function(param) {
63
- var plugins = param.plugins;
64
- plugins.push({
65
- name: "@module-federation/modern-js/server"
66
- });
67
- return {
68
- plugins
69
- };
70
- });
71
- return [
72
- 2
73
- ];
74
- });
75
- });
76
- return function(api) {
77
- return _ref.apply(this, arguments);
78
- };
79
- }(),
80
- usePlugins: [
81
- moduleFederationConfigPlugin(internalModernPluginOptions),
82
- moduleFederationSSRPlugin(internalModernPluginOptions)
83
- ]
84
- };
85
- };
86
- var cli_default = moduleFederationPlugin;
87
- import { createModuleFederationConfig } from "@module-federation/enhanced";
88
- export {
89
- createModuleFederationConfig,
90
- cli_default as default,
91
- moduleFederationPlugin
92
- };
@@ -1,16 +0,0 @@
1
- import nodeFetch from "node-fetch";
2
- var injectNodeFetchPlugin = function() {
3
- return {
4
- name: "inject-node-fetch-plugin",
5
- beforeInit: function beforeInit(args) {
6
- if (!globalThis.fetch) {
7
- globalThis.fetch = nodeFetch;
8
- }
9
- return args;
10
- }
11
- };
12
- };
13
- var inject_node_fetch_default = injectNodeFetchPlugin;
14
- export {
15
- inject_node_fetch_default as default
16
- };
@@ -1,74 +0,0 @@
1
- import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
- import { LOCALHOST } from "../../constant";
4
- var ipv4 = typeof FEDERATION_IPV4 !== "undefined" ? FEDERATION_IPV4 : "127.0.0.1";
5
- var remoteIpStrategy = typeof REMOTE_IP_STRATEGY !== "undefined" ? REMOTE_IP_STRATEGY : "inherit";
6
- function replaceObjectLocalhost(key, obj) {
7
- if (remoteIpStrategy !== "ipv4") {
8
- return;
9
- }
10
- if (!(key in obj)) {
11
- return;
12
- }
13
- var remote = obj[key];
14
- if (remote && typeof remote === "string" && remote.includes(LOCALHOST)) {
15
- obj[key] = replaceLocalhost(remote);
16
- }
17
- }
18
- function replaceLocalhost(url) {
19
- return url.replace(LOCALHOST, ipv4);
20
- }
21
- var resolveEntryIpv4Plugin = function() {
22
- return {
23
- name: "resolve-entry-ipv4",
24
- beforeRegisterRemote: function beforeRegisterRemote(args) {
25
- var remote = args.remote;
26
- replaceObjectLocalhost("entry", remote);
27
- return args;
28
- },
29
- afterResolve: function afterResolve(args) {
30
- return _async_to_generator(function() {
31
- var remoteInfo;
32
- return _ts_generator(this, function(_state) {
33
- remoteInfo = args.remoteInfo;
34
- replaceObjectLocalhost("entry", remoteInfo);
35
- return [
36
- 2,
37
- args
38
- ];
39
- });
40
- })();
41
- },
42
- beforeLoadRemoteSnapshot: function beforeLoadRemoteSnapshot(args) {
43
- var moduleInfo = args.moduleInfo;
44
- if ("entry" in moduleInfo) {
45
- replaceObjectLocalhost("entry", moduleInfo);
46
- return args;
47
- }
48
- if ("version" in moduleInfo) {
49
- replaceObjectLocalhost("version", moduleInfo);
50
- }
51
- return args;
52
- },
53
- loadRemoteSnapshot: function loadRemoteSnapshot(args) {
54
- var remoteSnapshot = args.remoteSnapshot;
55
- if ("publicPath" in remoteSnapshot) {
56
- replaceObjectLocalhost("publicPath", remoteSnapshot);
57
- }
58
- if ("getPublicPath" in remoteSnapshot) {
59
- replaceObjectLocalhost("getPublicPath", remoteSnapshot);
60
- }
61
- if (remoteSnapshot.remotesInfo) {
62
- Object.keys(remoteSnapshot.remotesInfo).forEach(function(key) {
63
- var remoteInfo = remoteSnapshot.remotesInfo[key];
64
- replaceObjectLocalhost("matchedVersion", remoteInfo);
65
- });
66
- }
67
- return args;
68
- }
69
- };
70
- };
71
- var resolve_entry_ipv4_default = resolveEntryIpv4Plugin;
72
- export {
73
- resolve_entry_ipv4_default as default
74
- };