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