@module-federation/modern-js 0.0.0-chore-bump-node-22-20260710161714

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 (100) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +5 -0
  3. package/dist/cjs/cli/configPlugin.js +346 -0
  4. package/dist/cjs/cli/index.js +115 -0
  5. package/dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js +54 -0
  6. package/dist/cjs/cli/mfRuntimePlugins/shared-strategy.js +53 -0
  7. package/dist/cjs/cli/server/data-fetch-server-plugin.js +59 -0
  8. package/dist/cjs/cli/ssrPlugin.js +314 -0
  9. package/dist/cjs/cli/utils.js +93 -0
  10. package/dist/cjs/constant.js +40 -0
  11. package/dist/cjs/interfaces/bundler.js +18 -0
  12. package/dist/cjs/logger.js +39 -0
  13. package/dist/cjs/react/data-fetch.js +58 -0
  14. package/dist/cjs/react/index.js +58 -0
  15. package/dist/cjs/react/plugin.js +65 -0
  16. package/dist/cjs/react/v18.js +58 -0
  17. package/dist/cjs/react/v19.js +58 -0
  18. package/dist/cjs/runtime/index.js +58 -0
  19. package/dist/cjs/server/fileCache.js +82 -0
  20. package/dist/cjs/server/index.js +71 -0
  21. package/dist/cjs/server/staticMiddleware.js +97 -0
  22. package/dist/cjs/ssr-runtime/SSRLiveReload.js +50 -0
  23. package/dist/cjs/ssr-runtime/devPlugin.js +67 -0
  24. package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +47 -0
  25. package/dist/cjs/types/index.js +18 -0
  26. package/dist/esm/cli/configPlugin.mjs +321 -0
  27. package/dist/esm/cli/index.mjs +91 -0
  28. package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.mjs +12 -0
  29. package/dist/esm/cli/mfRuntimePlugins/shared-strategy.mjs +21 -0
  30. package/dist/esm/cli/server/data-fetch-server-plugin.mjs +17 -0
  31. package/dist/esm/cli/ssrPlugin.mjs +297 -0
  32. package/dist/esm/cli/utils.mjs +40 -0
  33. package/dist/esm/constant.mjs +3 -0
  34. package/dist/esm/interfaces/bundler.mjs +0 -0
  35. package/dist/esm/logger.mjs +5 -0
  36. package/dist/esm/react/data-fetch.mjs +1 -0
  37. package/dist/esm/react/index.mjs +1 -0
  38. package/dist/esm/react/plugin.mjs +3 -0
  39. package/dist/esm/react/v18.mjs +1 -0
  40. package/dist/esm/react/v19.mjs +1 -0
  41. package/dist/esm/runtime/index.mjs +1 -0
  42. package/dist/esm/server/fileCache.mjs +125 -0
  43. package/dist/esm/server/index.mjs +36 -0
  44. package/dist/esm/server/staticMiddleware.mjs +122 -0
  45. package/dist/esm/ssr-runtime/SSRLiveReload.mjs +23 -0
  46. package/dist/esm/ssr-runtime/devPlugin.mjs +70 -0
  47. package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.mjs +33 -0
  48. package/dist/esm/types/index.mjs +0 -0
  49. package/dist/esm-node/cli/configPlugin.mjs +276 -0
  50. package/dist/esm-node/cli/index.mjs +75 -0
  51. package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.mjs +10 -0
  52. package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.mjs +19 -0
  53. package/dist/esm-node/cli/server/data-fetch-server-plugin.mjs +15 -0
  54. package/dist/esm-node/cli/ssrPlugin.mjs +258 -0
  55. package/dist/esm-node/cli/utils.mjs +40 -0
  56. package/dist/esm-node/constant.mjs +3 -0
  57. package/dist/esm-node/interfaces/bundler.mjs +0 -0
  58. package/dist/esm-node/logger.mjs +5 -0
  59. package/dist/esm-node/react/data-fetch.mjs +1 -0
  60. package/dist/esm-node/react/index.mjs +1 -0
  61. package/dist/esm-node/react/plugin.mjs +3 -0
  62. package/dist/esm-node/react/v18.mjs +1 -0
  63. package/dist/esm-node/react/v19.mjs +1 -0
  64. package/dist/esm-node/runtime/index.mjs +1 -0
  65. package/dist/esm-node/server/fileCache.mjs +45 -0
  66. package/dist/esm-node/server/index.mjs +34 -0
  67. package/dist/esm-node/server/staticMiddleware.mjs +50 -0
  68. package/dist/esm-node/ssr-runtime/SSRLiveReload.mjs +16 -0
  69. package/dist/esm-node/ssr-runtime/devPlugin.mjs +33 -0
  70. package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.mjs +13 -0
  71. package/dist/esm-node/types/index.mjs +0 -0
  72. package/dist/types/cli/configPlugin.d.ts +21 -0
  73. package/dist/types/cli/configPlugin.spec.d.ts +1 -0
  74. package/dist/types/cli/index.d.ts +6 -0
  75. package/dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts +3 -0
  76. package/dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts +3 -0
  77. package/dist/types/cli/server/data-fetch-server-plugin.d.ts +3 -0
  78. package/dist/types/cli/ssrPlugin.d.ts +6 -0
  79. package/dist/types/cli/ssrPlugin.spec.d.ts +1 -0
  80. package/dist/types/cli/utils.d.ts +6 -0
  81. package/dist/types/constant.d.ts +2 -0
  82. package/dist/types/interfaces/bundler.d.ts +18 -0
  83. package/dist/types/logger.d.ts +2 -0
  84. package/dist/types/react/data-fetch.d.ts +1 -0
  85. package/dist/types/react/index.d.ts +1 -0
  86. package/dist/types/react/plugin.d.ts +2 -0
  87. package/dist/types/react/v18.d.ts +1 -0
  88. package/dist/types/react/v19.d.ts +1 -0
  89. package/dist/types/runtime/index.d.ts +1 -0
  90. package/dist/types/server/fileCache.d.ts +14 -0
  91. package/dist/types/server/fileCache.spec.d.ts +1 -0
  92. package/dist/types/server/index.d.ts +4 -0
  93. package/dist/types/server/staticMiddleware.d.ts +7 -0
  94. package/dist/types/server/staticMiddleware.spec.d.ts +1 -0
  95. package/dist/types/ssr-runtime/SSRLiveReload.d.ts +2 -0
  96. package/dist/types/ssr-runtime/devPlugin.d.ts +2 -0
  97. package/dist/types/ssr-runtime/injectDataFetchFunctionPlugin.d.ts +4 -0
  98. package/dist/types/types/index.d.ts +35 -0
  99. package/package.json +192 -0
  100. package/types.d.ts +6 -0
@@ -0,0 +1,321 @@
1
+ import * as __rspack_external_jiti from "jiti";
2
+ import { _ } from "@swc/helpers/_/_async_to_generator";
3
+ import { _ as _object_spread__ } from "@swc/helpers/_/_object_spread";
4
+ import { _ as _object_spread_props__ } from "@swc/helpers/_/_object_spread_props";
5
+ import { _ as _to_consumable_array__ } from "@swc/helpers/_/_to_consumable_array";
6
+ import { _ as _type_of__ } from "@swc/helpers/_/_type_of";
7
+ import { _ as _ts_generator__ } from "@swc/helpers/_/_ts_generator";
8
+ import fs from "fs";
9
+ import path from "path";
10
+ import { isDev, isWebTarget, skipByTarget } from "./utils.mjs";
11
+ import { encodeName } from "@module-federation/sdk";
12
+ import { PLUGIN_IDENTIFIER } from "../constant.mjs";
13
+ import { addDataFetchExposes, autoDeleteSplitChunkCacheGroups } from "@module-federation/rsbuild-plugin/utils";
14
+ import logger from "../logger.mjs";
15
+ var __webpack_modules__ = {
16
+ jiti: function(module) {
17
+ module.exports = __rspack_external_jiti;
18
+ }
19
+ };
20
+ var __webpack_module_cache__ = {};
21
+ function __webpack_require__(moduleId) {
22
+ var cachedModule = __webpack_module_cache__[moduleId];
23
+ if (void 0 !== cachedModule) return cachedModule.exports;
24
+ var module = __webpack_module_cache__[moduleId] = {
25
+ exports: {}
26
+ };
27
+ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
28
+ return module.exports;
29
+ }
30
+ var defaultPath = path.resolve(process.cwd(), 'module-federation.config.ts');
31
+ var configPlugin_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 configPlugin_resolveSharedStrategyPlugin = function() {
42
+ return configPlugin_resolvePackageFile('@module-federation/modern-js', 'dist/esm/cli/mfRuntimePlugins/shared-strategy.mjs', 'dist/cjs/cli/mfRuntimePlugins/shared-strategy.js');
43
+ };
44
+ var configPlugin_resolveInjectNodeFetchPlugin = function() {
45
+ return configPlugin_resolvePackageFile('@module-federation/modern-js', 'dist/esm/cli/mfRuntimePlugins/inject-node-fetch.mjs', 'dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js');
46
+ };
47
+ var configPlugin_resolveNodeRuntimePlugin = function() {
48
+ return configPlugin_resolvePackageFile('@module-federation/node', 'dist/src/runtimePlugin.mjs', 'dist/src/runtimePlugin.js');
49
+ };
50
+ var configPlugin_resolveNodeRecordRemoteHashPlugin = function() {
51
+ return configPlugin_resolvePackageFile('@module-federation/node', 'dist/src/recordDynamicRemoteEntryHashPlugin.mjs', 'dist/src/recordDynamicRemoteEntryHashPlugin.js');
52
+ };
53
+ function setEnv(enableSSR) {
54
+ if (enableSSR) process.env['MF_SSR_PRJ'] = 'true';
55
+ }
56
+ var configPlugin_getMFConfig = function(userConfig) {
57
+ return _(function() {
58
+ var config, configPath, mfConfigPath, createJiti, jit, configModule, resolvedConfig;
59
+ return _ts_generator__(this, function(_state) {
60
+ switch(_state.label){
61
+ case 0:
62
+ config = userConfig.config, configPath = userConfig.configPath;
63
+ if (config) return [
64
+ 2,
65
+ config
66
+ ];
67
+ mfConfigPath = configPath ? configPath : defaultPath;
68
+ createJiti = __webpack_require__("jiti").createJiti;
69
+ jit = createJiti(__filename, {
70
+ interopDefault: true
71
+ });
72
+ return [
73
+ 4,
74
+ jit(mfConfigPath)
75
+ ];
76
+ case 1:
77
+ configModule = _state.sent();
78
+ resolvedConfig = configModule && (void 0 === configModule ? "undefined" : _type_of__(configModule)) === 'object' && 'default' in configModule ? configModule.default : configModule;
79
+ return [
80
+ 2,
81
+ resolvedConfig
82
+ ];
83
+ }
84
+ });
85
+ })();
86
+ };
87
+ var configPlugin_injectRuntimePlugins = function(runtimePlugin, runtimePlugins) {
88
+ var pluginName = 'string' == typeof runtimePlugin ? runtimePlugin : runtimePlugin[0];
89
+ var hasPlugin = runtimePlugins.some(function(existingPlugin) {
90
+ if ('string' == typeof existingPlugin) return existingPlugin === pluginName;
91
+ return existingPlugin[0] === pluginName;
92
+ });
93
+ if (!hasPlugin) runtimePlugins.push(runtimePlugin);
94
+ };
95
+ var configPlugin_patchDTSConfig = function(mfConfig, isServer) {
96
+ if (isServer) return;
97
+ var ModernJSRuntime = '@module-federation/modern-js/runtime';
98
+ if (false !== mfConfig.dts) {
99
+ var _mfConfig_dts, _mfConfig_dts1;
100
+ if ('boolean' == typeof mfConfig.dts || void 0 === mfConfig.dts) mfConfig.dts = {
101
+ consumeTypes: {
102
+ runtimePkgs: [
103
+ ModernJSRuntime
104
+ ]
105
+ }
106
+ };
107
+ else if ((null == (_mfConfig_dts = mfConfig.dts) ? void 0 : _mfConfig_dts.consumeTypes) || (null == (_mfConfig_dts1 = mfConfig.dts) ? void 0 : _mfConfig_dts1.consumeTypes) === void 0) {
108
+ var _mfConfig_dts2;
109
+ if ('boolean' == typeof mfConfig.dts.consumeTypes || (null == (_mfConfig_dts2 = mfConfig.dts) ? void 0 : _mfConfig_dts2.consumeTypes) === void 0) mfConfig.dts.consumeTypes = {
110
+ runtimePkgs: [
111
+ ModernJSRuntime
112
+ ]
113
+ };
114
+ else {
115
+ mfConfig.dts.consumeTypes.runtimePkgs = mfConfig.dts.consumeTypes.runtimePkgs || [];
116
+ if (!mfConfig.dts.consumeTypes.runtimePkgs.includes(ModernJSRuntime)) mfConfig.dts.consumeTypes.runtimePkgs.push(ModernJSRuntime);
117
+ }
118
+ }
119
+ }
120
+ };
121
+ var configPlugin_patchMFConfig = function(mfConfig, isServer) {
122
+ addDataFetchExposes(mfConfig.exposes, isServer);
123
+ if (void 0 === mfConfig.remoteType) mfConfig.remoteType = "script";
124
+ if (!mfConfig.name) throw new Error("".concat(PLUGIN_IDENTIFIER, " mfConfig.name can not be empty!"));
125
+ var runtimePlugins = _to_consumable_array__(mfConfig.runtimePlugins || []);
126
+ configPlugin_patchDTSConfig(mfConfig, isServer);
127
+ configPlugin_injectRuntimePlugins(configPlugin_resolveSharedStrategyPlugin(), runtimePlugins);
128
+ if (isServer) {
129
+ configPlugin_injectRuntimePlugins(configPlugin_resolveNodeRuntimePlugin(), runtimePlugins);
130
+ if (isDev()) configPlugin_injectRuntimePlugins(configPlugin_resolveNodeRecordRemoteHashPlugin(), runtimePlugins);
131
+ configPlugin_injectRuntimePlugins(configPlugin_resolveInjectNodeFetchPlugin(), runtimePlugins);
132
+ if (mfConfig.library) {
133
+ if (!mfConfig.library.type) mfConfig.library.type = 'commonjs-module';
134
+ if (!mfConfig.library.name) mfConfig.library.name = mfConfig.name;
135
+ } else mfConfig.library = {
136
+ type: 'commonjs-module',
137
+ name: mfConfig.name
138
+ };
139
+ }
140
+ mfConfig.runtimePlugins = runtimePlugins;
141
+ if (!isServer) {
142
+ var _mfConfig_library;
143
+ if ((null == (_mfConfig_library = mfConfig.library) ? void 0 : _mfConfig_library.type) === 'commonjs-module') mfConfig.library.type = 'global';
144
+ return mfConfig;
145
+ }
146
+ mfConfig.dts = false;
147
+ mfConfig.dev = false;
148
+ return mfConfig;
149
+ };
150
+ function patchIgnoreWarning(chain) {
151
+ var ignoreWarnings = chain.get('ignoreWarnings') || [];
152
+ var ignoredMsgs = [
153
+ "external script",
154
+ 'process.env.WS_NO_BUFFER_UTIL',
155
+ "Can't resolve 'utf-8-validate"
156
+ ];
157
+ ignoreWarnings.push(function(warning) {
158
+ if (ignoredMsgs.some(function(msg) {
159
+ return warning.message.includes(msg);
160
+ })) return true;
161
+ return false;
162
+ });
163
+ chain.ignoreWarnings(ignoreWarnings);
164
+ }
165
+ function addMyTypes2Ignored(chain, mfConfig) {
166
+ var watchOptions = chain.get('watchOptions');
167
+ if (!watchOptions || !watchOptions.ignored) return void chain.watchOptions({
168
+ ignored: /[\\/](?:\.git|node_modules|@mf-types)[\\/]/
169
+ });
170
+ var ignored = watchOptions.ignored;
171
+ var DEFAULT_IGNORED_GLOB = '**/@mf-types/**';
172
+ if (Array.isArray(ignored)) {
173
+ if (false !== mfConfig.dts && 'object' === _type_of__(mfConfig.dts) && 'object' === _type_of__(mfConfig.dts.consumeTypes) && mfConfig.dts.consumeTypes.remoteTypesFolder) chain.watchOptions(_object_spread_props__(_object_spread__({}, watchOptions), {
174
+ ignored: ignored.concat("**/".concat(mfConfig.dts.consumeTypes.remoteTypesFolder, "/**"))
175
+ }));
176
+ else chain.watchOptions(_object_spread_props__(_object_spread__({}, watchOptions), {
177
+ ignored: ignored.concat(DEFAULT_IGNORED_GLOB)
178
+ }));
179
+ return;
180
+ }
181
+ if ('string' != typeof ignored) return void chain.watchOptions(_object_spread_props__(_object_spread__({}, watchOptions), {
182
+ ignored: /[\\/](?:\.git|node_modules|@mf-types)[\\/]/
183
+ }));
184
+ chain.watchOptions(_object_spread_props__(_object_spread__({}, watchOptions), {
185
+ ignored: ignored.concat(DEFAULT_IGNORED_GLOB)
186
+ }));
187
+ }
188
+ function patchBundlerConfig(options) {
189
+ var _modernjsConfig_deploy;
190
+ var chain = options.chain, modernjsConfig = options.modernjsConfig, isServer = options.isServer, mfConfig = options.mfConfig, enableSSR = options.enableSSR;
191
+ chain.optimization.delete('runtimeChunk');
192
+ patchIgnoreWarning(chain);
193
+ if (!chain.output.get('chunkLoadingGlobal')) chain.output.chunkLoadingGlobal("chunk_".concat(mfConfig.name));
194
+ if (!chain.output.get('uniqueName')) chain.output.uniqueName(mfConfig.name);
195
+ var splitChunkConfig = chain.optimization.splitChunks.entries();
196
+ if (!isServer) autoDeleteSplitChunkCacheGroups(mfConfig, splitChunkConfig);
197
+ if (!isServer && enableSSR && splitChunkConfig && (void 0 === splitChunkConfig ? "undefined" : _type_of__(splitChunkConfig)) === 'object' && splitChunkConfig.cacheGroups) {
198
+ splitChunkConfig.chunks = 'async';
199
+ logger.warn('splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"');
200
+ }
201
+ if (isDev() && 'auto' === chain.output.get('publicPath')) {
202
+ var _modernjsConfig_dev, _modernjsConfig_server;
203
+ var port = (null == (_modernjsConfig_dev = modernjsConfig.dev) ? void 0 : _modernjsConfig_dev.port) || (null == (_modernjsConfig_server = modernjsConfig.server) ? void 0 : _modernjsConfig_server.port) || 8080;
204
+ var publicPath = "http://localhost:".concat(port, "/");
205
+ chain.output.publicPath(publicPath);
206
+ }
207
+ if (isServer && enableSSR) {
208
+ var uniqueName = mfConfig.name || chain.output.get('uniqueName');
209
+ var chunkFileName = chain.output.get('chunkFilename');
210
+ if ('string' == typeof chunkFileName && uniqueName && !chunkFileName.includes(uniqueName)) {
211
+ var suffix = "".concat(encodeName(uniqueName), "-[contenthash].js");
212
+ chain.output.chunkFilename(chunkFileName.replace('.js', suffix));
213
+ }
214
+ }
215
+ if (isDev() && enableSSR && !isServer) chain.resolve.fallback.set('crypto', false).set('stream', false).set('vm', false);
216
+ if ((null == (_modernjsConfig_deploy = modernjsConfig.deploy) ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) chain.optimization.usedExports(false);
217
+ }
218
+ var configPlugin_moduleFederationConfigPlugin = function(userConfig) {
219
+ return {
220
+ name: '@modern-js/plugin-module-federation-config',
221
+ pre: [
222
+ '@modern-js/plugin-initialize'
223
+ ],
224
+ post: [
225
+ '@modern-js/plugin-module-federation'
226
+ ],
227
+ setup: function(api) {
228
+ return _(function() {
229
+ var _ref, _userConfig_userConfig, _modernjsConfig_server, modernjsConfig, mfConfig, csrConfig, ssrConfig, enableSSR;
230
+ return _ts_generator__(this, function(_state) {
231
+ switch(_state.label){
232
+ case 0:
233
+ modernjsConfig = api.getConfig();
234
+ return [
235
+ 4,
236
+ configPlugin_getMFConfig(userConfig.originPluginOptions)
237
+ ];
238
+ case 1:
239
+ mfConfig = _state.sent();
240
+ csrConfig = userConfig.csrConfig || JSON.parse(JSON.stringify(mfConfig));
241
+ ssrConfig = userConfig.ssrConfig || JSON.parse(JSON.stringify(mfConfig));
242
+ userConfig.ssrConfig = ssrConfig;
243
+ userConfig.csrConfig = csrConfig;
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));
245
+ api.modifyBundlerChain(function(chain) {
246
+ var _modernjsConfig_source, _targetMFConfig_experiments;
247
+ var bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
248
+ var target = chain.get('target');
249
+ if (skipByTarget(target)) return;
250
+ var isWeb = isWebTarget(target);
251
+ addMyTypes2Ignored(chain, isWeb ? csrConfig : ssrConfig);
252
+ var targetMFConfig = isWeb ? csrConfig : ssrConfig;
253
+ configPlugin_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
+ }
259
+ patchBundlerConfig({
260
+ chain: chain,
261
+ isServer: !isWeb,
262
+ modernjsConfig: modernjsConfig,
263
+ mfConfig: mfConfig,
264
+ enableSSR: enableSSR
265
+ });
266
+ if (isWeb) userConfig.distOutputDir = chain.output.get('path') || path.resolve(process.cwd(), 'dist');
267
+ else if (enableSSR) {
268
+ var _userConfig, _userConfig_userConfig;
269
+ (_userConfig = userConfig).userConfig || (_userConfig.userConfig = {});
270
+ (_userConfig_userConfig = userConfig.userConfig).ssr || (_userConfig_userConfig.ssr = {});
271
+ if (true === userConfig.userConfig.ssr) userConfig.userConfig.ssr = {};
272
+ userConfig.userConfig.ssr.distOutputDir = chain.output.get('path') || path.resolve(process.cwd(), 'dist/bundles');
273
+ }
274
+ });
275
+ api.config(function() {
276
+ var _ref;
277
+ var _modernjsConfig_tools, _userConfig_csrConfig, _modernjsConfig_source, _modernjsConfig_source1, _modernjsConfig_dev;
278
+ var bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
279
+ var devServerConfig = null == (_modernjsConfig_tools = modernjsConfig.tools) ? void 0 : _modernjsConfig_tools.devServer;
280
+ var corsWarnMsgs = [
281
+ 'View https://module-federation.io/guide/troubleshooting/other.html#cors-warn for more details.'
282
+ ];
283
+ if ((void 0 === devServerConfig ? "undefined" : _type_of__(devServerConfig)) !== 'object' || !('headers' in devServerConfig)) 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.');
284
+ var exposes = null == (_userConfig_csrConfig = userConfig.csrConfig) ? void 0 : _userConfig_csrConfig.exposes;
285
+ var hasExposes = exposes && Array.isArray(exposes) ? exposes.length : Object.keys(null != exposes ? exposes : {}).length;
286
+ if (corsWarnMsgs.length > 1 && hasExposes) logger.warn(corsWarnMsgs.join('\n'));
287
+ var corsHeaders = hasExposes ? {
288
+ 'Access-Control-Allow-Origin': '*',
289
+ 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
290
+ 'Access-Control-Allow-Headers': '*'
291
+ } : void 0;
292
+ return {
293
+ tools: {
294
+ devServer: {
295
+ headers: corsHeaders
296
+ }
297
+ },
298
+ resolve: {
299
+ alias: {
300
+ '@modern-js/runtime/mf': require.resolve('@module-federation/modern-js/runtime')
301
+ }
302
+ },
303
+ source: {
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
305
+ },
306
+ dev: {
307
+ assetPrefix: (null == modernjsConfig ? void 0 : null == (_modernjsConfig_dev = modernjsConfig.dev) ? void 0 : _modernjsConfig_dev.assetPrefix) ? modernjsConfig.dev.assetPrefix : true
308
+ }
309
+ };
310
+ });
311
+ return [
312
+ 2
313
+ ];
314
+ }
315
+ });
316
+ })();
317
+ }
318
+ };
319
+ };
320
+ var configPlugin = configPlugin_moduleFederationConfigPlugin;
321
+ export { addMyTypes2Ignored, configPlugin as default, configPlugin_getMFConfig as getMFConfig, isWebTarget, configPlugin_moduleFederationConfigPlugin as moduleFederationConfigPlugin, patchBundlerConfig, configPlugin_patchMFConfig as patchMFConfig, setEnv, skipByTarget };
@@ -0,0 +1,91 @@
1
+ import { _ } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _object_spread__ } from "@swc/helpers/_/_object_spread";
3
+ import { _ as _type_of__ } from "@swc/helpers/_/_type_of";
4
+ import { _ as _ts_generator__ } from "@swc/helpers/_/_ts_generator";
5
+ import { AsyncBoundaryPlugin, ModuleFederationPlugin, TreeShakingSharedPlugin as enhanced_TreeShakingSharedPlugin, createModuleFederationConfig } from "@module-federation/enhanced";
6
+ import { ModuleFederationPlugin as rspack_ModuleFederationPlugin, TreeShakingSharedPlugin as rspack_TreeShakingSharedPlugin } from "@module-federation/enhanced/rspack";
7
+ import { moduleFederationConfigPlugin } from "./configPlugin.mjs";
8
+ import { moduleFederationSSRPlugin } from "./ssrPlugin.mjs";
9
+ import { isWebTarget } from "./utils.mjs";
10
+ var cli_moduleFederationPlugin = function() {
11
+ var userConfig = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
12
+ var _userConfig_fetchServerQuery, _userConfig_secondarySharedTreeShaking;
13
+ var internalModernPluginOptions = {
14
+ csrConfig: void 0,
15
+ ssrConfig: void 0,
16
+ browserPlugin: void 0,
17
+ nodePlugin: void 0,
18
+ assetResources: {},
19
+ distOutputDir: '',
20
+ originPluginOptions: _object_spread__({}, userConfig),
21
+ userConfig: userConfig || {},
22
+ assetFileNames: {},
23
+ fetchServerQuery: null != (_userConfig_fetchServerQuery = userConfig.fetchServerQuery) ? _userConfig_fetchServerQuery : void 0,
24
+ secondarySharedTreeShaking: null != (_userConfig_secondarySharedTreeShaking = userConfig.secondarySharedTreeShaking) ? _userConfig_secondarySharedTreeShaking : false
25
+ };
26
+ return {
27
+ name: '@modern-js/plugin-module-federation',
28
+ setup: function(api) {
29
+ return _(function() {
30
+ var modernjsConfig;
31
+ return _ts_generator__(this, function(_state) {
32
+ modernjsConfig = api.getConfig();
33
+ api.modifyBundlerChain(function(chain) {
34
+ var bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
35
+ var browserPluginOptions = internalModernPluginOptions.csrConfig;
36
+ var secondarySharedTreeShaking = internalModernPluginOptions.secondarySharedTreeShaking;
37
+ var MFPlugin = 'webpack' === bundlerType ? ModuleFederationPlugin : rspack_ModuleFederationPlugin;
38
+ var TreeShakingSharedPlugin = 'webpack' === bundlerType ? enhanced_TreeShakingSharedPlugin : rspack_TreeShakingSharedPlugin;
39
+ if (isWebTarget(chain.get('target'))) if (secondarySharedTreeShaking) chain.plugin('plugin-module-federation').use(TreeShakingSharedPlugin, [
40
+ {
41
+ mfConfig: browserPluginOptions,
42
+ secondary: true
43
+ }
44
+ ]);
45
+ else chain.plugin('plugin-module-federation').use(MFPlugin, [
46
+ browserPluginOptions
47
+ ]).init(function(Plugin, args) {
48
+ internalModernPluginOptions.browserPlugin = new Plugin(args[0]);
49
+ return internalModernPluginOptions.browserPlugin;
50
+ });
51
+ if ('webpack' === bundlerType && !secondarySharedTreeShaking) {
52
+ var _modernjsConfig_source;
53
+ var enableAsyncEntry = null == (_modernjsConfig_source = modernjsConfig.source) ? void 0 : _modernjsConfig_source.enableAsyncEntry;
54
+ if (!enableAsyncEntry && false !== browserPluginOptions.async) {
55
+ var asyncBoundaryPluginOptions = 'object' === _type_of__(browserPluginOptions.async) ? browserPluginOptions.async : {
56
+ eager: function(module) {
57
+ return module && /\.federation/.test((null == module ? void 0 : module.request) || '');
58
+ },
59
+ excludeChunk: function(chunk) {
60
+ return chunk.name === browserPluginOptions.name;
61
+ }
62
+ };
63
+ chain.plugin('async-boundary-plugin').use(AsyncBoundaryPlugin, [
64
+ asyncBoundaryPluginOptions
65
+ ]);
66
+ }
67
+ }
68
+ });
69
+ api._internalServerPlugins(function(param) {
70
+ var plugins = param.plugins;
71
+ plugins.push({
72
+ name: '@module-federation/modern-js/server'
73
+ });
74
+ return {
75
+ plugins: plugins
76
+ };
77
+ });
78
+ return [
79
+ 2
80
+ ];
81
+ });
82
+ })();
83
+ },
84
+ usePlugins: [
85
+ moduleFederationConfigPlugin(internalModernPluginOptions),
86
+ moduleFederationSSRPlugin(internalModernPluginOptions)
87
+ ]
88
+ };
89
+ };
90
+ var cli = cli_moduleFederationPlugin;
91
+ export { createModuleFederationConfig, cli as default, cli_moduleFederationPlugin as moduleFederationPlugin };
@@ -0,0 +1,12 @@
1
+ import node_fetch from "node-fetch";
2
+ var inject_node_fetch_injectNodeFetchPlugin = function() {
3
+ return {
4
+ name: 'inject-node-fetch-plugin',
5
+ beforeInit: function(args) {
6
+ if (!globalThis.fetch) globalThis.fetch = node_fetch;
7
+ return args;
8
+ }
9
+ };
10
+ };
11
+ var inject_node_fetch = inject_node_fetch_injectNodeFetchPlugin;
12
+ export { inject_node_fetch as default };
@@ -0,0 +1,21 @@
1
+ var shared_strategy_sharedStrategy = function() {
2
+ return {
3
+ name: 'shared-strategy-plugin',
4
+ beforeInit: function(args) {
5
+ var userOptions = args.userOptions;
6
+ var shared = userOptions.shared;
7
+ if (shared) Object.keys(shared).forEach(function(sharedKey) {
8
+ var sharedConfigs = shared[sharedKey];
9
+ var arraySharedConfigs = Array.isArray(sharedConfigs) ? sharedConfigs : [
10
+ sharedConfigs
11
+ ];
12
+ arraySharedConfigs.forEach(function(s) {
13
+ s.strategy = 'loaded-first';
14
+ });
15
+ });
16
+ return args;
17
+ }
18
+ };
19
+ };
20
+ var shared_strategy = shared_strategy_sharedStrategy;
21
+ export { shared_strategy as default };
@@ -0,0 +1,17 @@
1
+ import data_fetch_server_middleware from "@module-federation/bridge-react/data-fetch-server-middleware";
2
+ var data_fetch_server_plugin_dataFetchServePlugin = function() {
3
+ return {
4
+ name: 'mf-data-fetch-server-plugin',
5
+ setup: function(api) {
6
+ api.onPrepare(function() {
7
+ var middlewares = api.getServerContext().middlewares;
8
+ middlewares.push({
9
+ name: 'module-federation-serve-manifest',
10
+ handler: data_fetch_server_middleware
11
+ });
12
+ });
13
+ }
14
+ };
15
+ };
16
+ var data_fetch_server_plugin = data_fetch_server_plugin_dataFetchServePlugin;
17
+ export { data_fetch_server_plugin as default };