@module-federation/modern-js-v3 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 (102) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +5 -0
  3. package/dist/cjs/cli/configPlugin.js +351 -0
  4. package/dist/cjs/cli/index.js +102 -0
  5. package/dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js +58 -0
  6. package/dist/cjs/cli/mfRuntimePlugins/shared-strategy.js +57 -0
  7. package/dist/cjs/cli/server/data-fetch-server-plugin.js +63 -0
  8. package/dist/cjs/cli/ssrPlugin.js +308 -0
  9. package/dist/cjs/cli/utils.js +97 -0
  10. package/dist/cjs/constant.js +44 -0
  11. package/dist/cjs/interfaces/bundler.js +18 -0
  12. package/dist/cjs/logger.js +43 -0
  13. package/dist/cjs/react/data-fetch.js +62 -0
  14. package/dist/cjs/react/index.js +62 -0
  15. package/dist/cjs/react/plugin.js +69 -0
  16. package/dist/cjs/react/v18.js +62 -0
  17. package/dist/cjs/react/v19.js +62 -0
  18. package/dist/cjs/runtime/index.js +62 -0
  19. package/dist/cjs/server/fileCache.js +86 -0
  20. package/dist/cjs/server/index.js +75 -0
  21. package/dist/cjs/server/staticMiddleware.js +101 -0
  22. package/dist/cjs/ssr-runtime/SSRLiveReload.js +54 -0
  23. package/dist/cjs/ssr-runtime/devPlugin.js +71 -0
  24. package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +51 -0
  25. package/dist/cjs/types/index.js +18 -0
  26. package/dist/esm/cli/configPlugin.mjs +314 -0
  27. package/dist/esm/cli/index.mjs +69 -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 +290 -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 +1 -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 +2 -0
  39. package/dist/esm/react/v18.mjs +1 -0
  40. package/dist/esm/react/v19.mjs +1 -0
  41. package/dist/esm/rslib-runtime.mjs +18 -0
  42. package/dist/esm/runtime/index.mjs +1 -0
  43. package/dist/esm/server/fileCache.mjs +125 -0
  44. package/dist/esm/server/index.mjs +37 -0
  45. package/dist/esm/server/staticMiddleware.mjs +122 -0
  46. package/dist/esm/ssr-runtime/SSRLiveReload.mjs +23 -0
  47. package/dist/esm/ssr-runtime/devPlugin.mjs +70 -0
  48. package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.mjs +33 -0
  49. package/dist/esm/types/index.mjs +1 -0
  50. package/dist/esm-node/cli/configPlugin.mjs +269 -0
  51. package/dist/esm-node/cli/index.mjs +59 -0
  52. package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.mjs +10 -0
  53. package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.mjs +19 -0
  54. package/dist/esm-node/cli/server/data-fetch-server-plugin.mjs +15 -0
  55. package/dist/esm-node/cli/ssrPlugin.mjs +249 -0
  56. package/dist/esm-node/cli/utils.mjs +40 -0
  57. package/dist/esm-node/constant.mjs +3 -0
  58. package/dist/esm-node/interfaces/bundler.mjs +1 -0
  59. package/dist/esm-node/logger.mjs +5 -0
  60. package/dist/esm-node/react/data-fetch.mjs +1 -0
  61. package/dist/esm-node/react/index.mjs +1 -0
  62. package/dist/esm-node/react/plugin.mjs +2 -0
  63. package/dist/esm-node/react/v18.mjs +1 -0
  64. package/dist/esm-node/react/v19.mjs +1 -0
  65. package/dist/esm-node/rslib-runtime.mjs +18 -0
  66. package/dist/esm-node/runtime/index.mjs +1 -0
  67. package/dist/esm-node/server/fileCache.mjs +45 -0
  68. package/dist/esm-node/server/index.mjs +35 -0
  69. package/dist/esm-node/server/staticMiddleware.mjs +50 -0
  70. package/dist/esm-node/ssr-runtime/SSRLiveReload.mjs +16 -0
  71. package/dist/esm-node/ssr-runtime/devPlugin.mjs +33 -0
  72. package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.mjs +13 -0
  73. package/dist/esm-node/types/index.mjs +1 -0
  74. package/dist/types/cli/configPlugin.d.ts +21 -0
  75. package/dist/types/cli/configPlugin.spec.d.ts +1 -0
  76. package/dist/types/cli/index.d.ts +6 -0
  77. package/dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts +3 -0
  78. package/dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts +3 -0
  79. package/dist/types/cli/server/data-fetch-server-plugin.d.ts +3 -0
  80. package/dist/types/cli/ssrPlugin.d.ts +6 -0
  81. package/dist/types/cli/ssrPlugin.spec.d.ts +1 -0
  82. package/dist/types/cli/utils.d.ts +6 -0
  83. package/dist/types/constant.d.ts +2 -0
  84. package/dist/types/interfaces/bundler.d.ts +14 -0
  85. package/dist/types/logger.d.ts +2 -0
  86. package/dist/types/react/data-fetch.d.ts +1 -0
  87. package/dist/types/react/index.d.ts +1 -0
  88. package/dist/types/react/plugin.d.ts +2 -0
  89. package/dist/types/react/v18.d.ts +1 -0
  90. package/dist/types/react/v19.d.ts +1 -0
  91. package/dist/types/runtime/index.d.ts +1 -0
  92. package/dist/types/server/fileCache.d.ts +14 -0
  93. package/dist/types/server/fileCache.spec.d.ts +1 -0
  94. package/dist/types/server/index.d.ts +4 -0
  95. package/dist/types/server/staticMiddleware.d.ts +7 -0
  96. package/dist/types/server/staticMiddleware.spec.d.ts +1 -0
  97. package/dist/types/ssr-runtime/SSRLiveReload.d.ts +2 -0
  98. package/dist/types/ssr-runtime/devPlugin.d.ts +2 -0
  99. package/dist/types/ssr-runtime/injectDataFetchFunctionPlugin.d.ts +4 -0
  100. package/dist/types/types/index.d.ts +35 -0
  101. package/package.json +194 -0
  102. package/types.d.ts +6 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-present zhanghang(2heal1)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # @module-federation/modern-js-v3
2
+
3
+ This plugin provides Module Federation supporting functions for Modern.js
4
+
5
+ See [documentation](https://module-federation.io/guide/framework/modernjs.html) for more details .
@@ -0,0 +1,351 @@
1
+ "use strict";
2
+ var __webpack_modules__ = {
3
+ jiti (module) {
4
+ module.exports = require("jiti");
5
+ }
6
+ };
7
+ var __webpack_module_cache__ = {};
8
+ function __webpack_require__(moduleId) {
9
+ var cachedModule = __webpack_module_cache__[moduleId];
10
+ if (void 0 !== cachedModule) return cachedModule.exports;
11
+ var module = __webpack_module_cache__[moduleId] = {
12
+ exports: {}
13
+ };
14
+ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
15
+ return module.exports;
16
+ }
17
+ (()=>{
18
+ __webpack_require__.n = (module)=>{
19
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
20
+ __webpack_require__.d(getter, {
21
+ a: getter
22
+ });
23
+ return getter;
24
+ };
25
+ })();
26
+ (()=>{
27
+ __webpack_require__.d = (exports1, getters, values)=>{
28
+ var define = (defs, kind)=>{
29
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
30
+ enumerable: true,
31
+ [kind]: defs[key]
32
+ });
33
+ };
34
+ define(getters, "get");
35
+ define(values, "value");
36
+ };
37
+ })();
38
+ (()=>{
39
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
40
+ })();
41
+ (()=>{
42
+ __webpack_require__.r = (exports1)=>{
43
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
44
+ value: 'Module'
45
+ });
46
+ Object.defineProperty(exports1, '__esModule', {
47
+ value: true
48
+ });
49
+ };
50
+ })();
51
+ var __webpack_exports__ = {};
52
+ (()=>{
53
+ __webpack_require__.r(__webpack_exports__);
54
+ __webpack_require__.d(__webpack_exports__, {
55
+ addMyTypes2Ignored: ()=>addMyTypes2Ignored,
56
+ default: ()=>configPlugin,
57
+ getMFConfig: ()=>getMFConfig,
58
+ isWebTarget: ()=>external_utils_js_namespaceObject.isWebTarget,
59
+ moduleFederationConfigPlugin: ()=>moduleFederationConfigPlugin,
60
+ patchBundlerConfig: ()=>patchBundlerConfig,
61
+ patchMFConfig: ()=>patchMFConfig,
62
+ setEnv: ()=>setEnv,
63
+ skipByTarget: ()=>external_utils_js_namespaceObject.skipByTarget
64
+ });
65
+ const external_fs_namespaceObject = require("fs");
66
+ var external_fs_default = /*#__PURE__*/ __webpack_require__.n(external_fs_namespaceObject);
67
+ const external_path_namespaceObject = require("path");
68
+ var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
69
+ const external_utils_js_namespaceObject = require("./utils.js");
70
+ const sdk_namespaceObject = require("@module-federation/sdk");
71
+ const external_constant_js_namespaceObject = require("../constant.js");
72
+ const utils_namespaceObject = require("@module-federation/rsbuild-plugin/utils");
73
+ const external_logger_js_namespaceObject = require("../logger.js");
74
+ var external_logger_js_default = /*#__PURE__*/ __webpack_require__.n(external_logger_js_namespaceObject);
75
+ const defaultPath = external_path_default().resolve(process.cwd(), 'module-federation.config.ts');
76
+ const resolvePackageFile = (packageName, esmRelativePath, cjsRelativePath)=>{
77
+ const packageEntry = require.resolve(packageName);
78
+ let packageRoot = external_path_default().dirname(packageEntry);
79
+ while(!external_fs_default().existsSync(external_path_default().join(packageRoot, 'package.json'))){
80
+ const parentDir = external_path_default().dirname(packageRoot);
81
+ if (parentDir === packageRoot) throw new Error(`Unable to resolve package root for ${packageName} from ${packageEntry}`);
82
+ packageRoot = parentDir;
83
+ }
84
+ return require.resolve(external_path_default().join(packageRoot, 'true' === process.env['IS_ESM_BUILD'] ? esmRelativePath : cjsRelativePath));
85
+ };
86
+ const resolveSharedStrategyPlugin = ()=>resolvePackageFile('@module-federation/modern-js-v3', 'dist/esm/cli/mfRuntimePlugins/shared-strategy.mjs', 'dist/cjs/cli/mfRuntimePlugins/shared-strategy.js');
87
+ const resolveInjectNodeFetchPlugin = ()=>resolvePackageFile('@module-federation/modern-js-v3', 'dist/esm/cli/mfRuntimePlugins/inject-node-fetch.mjs', 'dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js');
88
+ const resolveNodeRuntimePlugin = ()=>resolvePackageFile('@module-federation/node', 'dist/src/runtimePlugin.mjs', 'dist/src/runtimePlugin.js');
89
+ const resolveNodeRecordRemoteHashPlugin = ()=>resolvePackageFile('@module-federation/node', 'dist/src/recordDynamicRemoteEntryHashPlugin.mjs', 'dist/src/recordDynamicRemoteEntryHashPlugin.js');
90
+ function setEnv(enableSSR) {
91
+ if (enableSSR) process.env['MF_SSR_PRJ'] = 'true';
92
+ }
93
+ const getMFConfig = async (userConfig)=>{
94
+ const { config, configPath } = userConfig;
95
+ if (config) return config;
96
+ const mfConfigPath = external_path_default().resolve(configPath || defaultPath);
97
+ const { createJiti } = __webpack_require__("jiti");
98
+ const jit = createJiti(mfConfigPath, {
99
+ interopDefault: true
100
+ });
101
+ const configModule = await jit(mfConfigPath);
102
+ const resolvedConfig = configModule && 'object' == typeof configModule && 'default' in configModule ? configModule.default : configModule;
103
+ return resolvedConfig;
104
+ };
105
+ const injectRuntimePlugins = (runtimePlugin, runtimePlugins)=>{
106
+ const pluginName = 'string' == typeof runtimePlugin ? runtimePlugin : runtimePlugin[0];
107
+ const hasPlugin = runtimePlugins.some((existingPlugin)=>{
108
+ if ('string' == typeof existingPlugin) return existingPlugin === pluginName;
109
+ return existingPlugin[0] === pluginName;
110
+ });
111
+ if (!hasPlugin) runtimePlugins.push(runtimePlugin);
112
+ };
113
+ const patchDTSConfig = (mfConfig, isServer)=>{
114
+ if (isServer) return;
115
+ const ModernJSRuntime = '@module-federation/modern-js-v3/runtime';
116
+ if (false !== mfConfig.dts) {
117
+ var _mfConfig_dts, _mfConfig_dts1;
118
+ if ('boolean' == typeof mfConfig.dts || void 0 === mfConfig.dts) mfConfig.dts = {
119
+ consumeTypes: {
120
+ runtimePkgs: [
121
+ ModernJSRuntime
122
+ ]
123
+ }
124
+ };
125
+ else if ((null == (_mfConfig_dts = mfConfig.dts) ? void 0 : _mfConfig_dts.consumeTypes) || (null == (_mfConfig_dts1 = mfConfig.dts) ? void 0 : _mfConfig_dts1.consumeTypes) === void 0) {
126
+ var _mfConfig_dts2;
127
+ if ('boolean' == typeof mfConfig.dts.consumeTypes || (null == (_mfConfig_dts2 = mfConfig.dts) ? void 0 : _mfConfig_dts2.consumeTypes) === void 0) mfConfig.dts.consumeTypes = {
128
+ runtimePkgs: [
129
+ ModernJSRuntime
130
+ ]
131
+ };
132
+ else {
133
+ mfConfig.dts.consumeTypes.runtimePkgs = mfConfig.dts.consumeTypes.runtimePkgs || [];
134
+ if (!mfConfig.dts.consumeTypes.runtimePkgs.includes(ModernJSRuntime)) mfConfig.dts.consumeTypes.runtimePkgs.push(ModernJSRuntime);
135
+ }
136
+ }
137
+ }
138
+ };
139
+ const patchMFConfig = (mfConfig, isServer)=>{
140
+ (0, utils_namespaceObject.addDataFetchExposes)(mfConfig.exposes, isServer);
141
+ if (void 0 === mfConfig.remoteType) mfConfig.remoteType = "script";
142
+ if (!mfConfig.name) throw new Error(`${external_constant_js_namespaceObject.PLUGIN_IDENTIFIER} mfConfig.name can not be empty!`);
143
+ const runtimePlugins = [
144
+ ...mfConfig.runtimePlugins || []
145
+ ];
146
+ patchDTSConfig(mfConfig, isServer);
147
+ injectRuntimePlugins(resolveSharedStrategyPlugin(), runtimePlugins);
148
+ if (isServer) {
149
+ injectRuntimePlugins(resolveNodeRuntimePlugin(), runtimePlugins);
150
+ if ((0, external_utils_js_namespaceObject.isDev)()) injectRuntimePlugins(resolveNodeRecordRemoteHashPlugin(), runtimePlugins);
151
+ injectRuntimePlugins(resolveInjectNodeFetchPlugin(), runtimePlugins);
152
+ if (mfConfig.library) {
153
+ if (!mfConfig.library.type) mfConfig.library.type = 'commonjs-module';
154
+ if (!mfConfig.library.name) mfConfig.library.name = mfConfig.name;
155
+ } else mfConfig.library = {
156
+ type: 'commonjs-module',
157
+ name: mfConfig.name
158
+ };
159
+ }
160
+ mfConfig.runtimePlugins = runtimePlugins;
161
+ if (!isServer) {
162
+ var _mfConfig_library;
163
+ if ((null == (_mfConfig_library = mfConfig.library) ? void 0 : _mfConfig_library.type) === 'commonjs-module') mfConfig.library.type = 'global';
164
+ return mfConfig;
165
+ }
166
+ mfConfig.dts = false;
167
+ mfConfig.dev = false;
168
+ return mfConfig;
169
+ };
170
+ function patchIgnoreWarning(chain) {
171
+ const ignoreWarnings = chain.get('ignoreWarnings') || [];
172
+ const ignoredMsgs = [
173
+ "external script",
174
+ 'process.env.WS_NO_BUFFER_UTIL',
175
+ "Can't resolve 'utf-8-validate"
176
+ ];
177
+ ignoreWarnings.push((warning)=>{
178
+ if (ignoredMsgs.some((msg)=>warning.message.includes(msg))) return true;
179
+ return false;
180
+ });
181
+ chain.ignoreWarnings(ignoreWarnings);
182
+ }
183
+ function addMyTypes2Ignored(chain, mfConfig) {
184
+ const watchOptions = chain.get('watchOptions');
185
+ if (!watchOptions || !watchOptions.ignored) return void chain.watchOptions({
186
+ ignored: /[\\/](?:\.git|node_modules|@mf-types)[\\/]/
187
+ });
188
+ const ignored = watchOptions.ignored;
189
+ const DEFAULT_IGNORED_GLOB = '**/@mf-types/**';
190
+ if (Array.isArray(ignored)) {
191
+ if (false !== mfConfig.dts && 'object' == typeof mfConfig.dts && 'object' == typeof mfConfig.dts.consumeTypes && mfConfig.dts.consumeTypes.remoteTypesFolder) chain.watchOptions({
192
+ ...watchOptions,
193
+ ignored: ignored.concat(`**/${mfConfig.dts.consumeTypes.remoteTypesFolder}/**`)
194
+ });
195
+ else chain.watchOptions({
196
+ ...watchOptions,
197
+ ignored: ignored.concat(DEFAULT_IGNORED_GLOB)
198
+ });
199
+ return;
200
+ }
201
+ if ('string' != typeof ignored) return void chain.watchOptions({
202
+ ...watchOptions,
203
+ ignored: /[\\/](?:\.git|node_modules|@mf-types)[\\/]/
204
+ });
205
+ chain.watchOptions({
206
+ ...watchOptions,
207
+ ignored: ignored.concat(DEFAULT_IGNORED_GLOB)
208
+ });
209
+ }
210
+ function patchBundlerConfig(options) {
211
+ var _modernjsConfig_deploy;
212
+ const { chain, modernjsConfig, isServer, mfConfig, enableSSR } = options;
213
+ chain.optimization.delete('runtimeChunk');
214
+ patchIgnoreWarning(chain);
215
+ if (!chain.output.get('chunkLoadingGlobal')) chain.output.chunkLoadingGlobal(`chunk_${mfConfig.name}`);
216
+ if (!chain.output.get('uniqueName')) chain.output.uniqueName(mfConfig.name);
217
+ const splitChunkConfig = chain.optimization.splitChunks.entries();
218
+ if (!isServer) (0, utils_namespaceObject.autoDeleteSplitChunkCacheGroups)(mfConfig, splitChunkConfig);
219
+ if (!isServer && enableSSR && splitChunkConfig && 'object' == typeof splitChunkConfig && splitChunkConfig.cacheGroups) {
220
+ splitChunkConfig.chunks = 'async';
221
+ external_logger_js_default().warn('splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"');
222
+ }
223
+ if ((0, external_utils_js_namespaceObject.isDev)() && 'auto' === chain.output.get('publicPath')) {
224
+ var _modernjsConfig_server;
225
+ const port = (null == (_modernjsConfig_server = modernjsConfig.server) ? void 0 : _modernjsConfig_server.port) || 8080;
226
+ const publicPath = `http://localhost:${port}/`;
227
+ chain.output.publicPath(publicPath);
228
+ }
229
+ if (isServer && enableSSR) {
230
+ const uniqueName = mfConfig.name || chain.output.get('uniqueName');
231
+ const chunkFileName = chain.output.get('chunkFilename');
232
+ if ('string' == typeof chunkFileName && uniqueName && !chunkFileName.includes(uniqueName)) {
233
+ const suffix = `${(0, sdk_namespaceObject.encodeName)(uniqueName)}-[contenthash].js`;
234
+ chain.output.chunkFilename(chunkFileName.replace('.js', suffix));
235
+ }
236
+ }
237
+ if ((0, external_utils_js_namespaceObject.isDev)() && enableSSR && !isServer) chain.resolve.fallback.set('crypto', false).set('stream', false).set('vm', false);
238
+ if ((null == (_modernjsConfig_deploy = modernjsConfig.deploy) ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) chain.optimization.usedExports(false);
239
+ }
240
+ const moduleFederationConfigPlugin = (userConfig)=>({
241
+ name: '@modern-js/plugin-module-federation-config',
242
+ pre: [
243
+ '@modern-js/plugin-initialize'
244
+ ],
245
+ post: [
246
+ '@modern-js/plugin-module-federation'
247
+ ],
248
+ setup: async (api)=>{
249
+ var _ref;
250
+ var _userConfig_userConfig, _modernjsConfig_server;
251
+ const modernjsConfig = api.getConfig();
252
+ const mfConfig = await getMFConfig(userConfig.originPluginOptions);
253
+ const csrConfig = userConfig.csrConfig || JSON.parse(JSON.stringify(mfConfig));
254
+ const ssrConfig = userConfig.ssrConfig || JSON.parse(JSON.stringify(mfConfig));
255
+ userConfig.ssrConfig = ssrConfig;
256
+ userConfig.csrConfig = csrConfig;
257
+ const enableSSR = Boolean(null != (_ref = null == (_userConfig_userConfig = userConfig.userConfig) ? void 0 : _userConfig_userConfig.ssr) ? _ref : Boolean(null == modernjsConfig ? void 0 : null == (_modernjsConfig_server = modernjsConfig.server) ? void 0 : _modernjsConfig_server.ssr));
258
+ api.modifyBundlerChain((chain)=>{
259
+ var _modernjsConfig_source, _targetMFConfig_experiments;
260
+ const target = chain.get('target');
261
+ if ((0, external_utils_js_namespaceObject.skipByTarget)(target)) return;
262
+ const isWeb = (0, external_utils_js_namespaceObject.isWebTarget)(target);
263
+ addMyTypes2Ignored(chain, isWeb ? csrConfig : ssrConfig);
264
+ const targetMFConfig = isWeb ? csrConfig : ssrConfig;
265
+ patchMFConfig(targetMFConfig, !isWeb);
266
+ if ((null == (_modernjsConfig_source = modernjsConfig.source) ? void 0 : _modernjsConfig_source.enableAsyncEntry) !== true && (null == (_targetMFConfig_experiments = targetMFConfig.experiments) ? void 0 : _targetMFConfig_experiments.asyncStartup) !== false) {
267
+ var _targetMFConfig;
268
+ (_targetMFConfig = targetMFConfig).experiments || (_targetMFConfig.experiments = {});
269
+ targetMFConfig.experiments.asyncStartup = true;
270
+ }
271
+ patchBundlerConfig({
272
+ chain,
273
+ isServer: !isWeb,
274
+ modernjsConfig,
275
+ mfConfig,
276
+ enableSSR
277
+ });
278
+ if (isWeb) userConfig.distOutputDir = chain.output.get('path') || external_path_default().resolve(process.cwd(), 'dist');
279
+ else if (enableSSR) {
280
+ var _userConfig, _userConfig_userConfig;
281
+ (_userConfig = userConfig).userConfig || (_userConfig.userConfig = {});
282
+ (_userConfig_userConfig = userConfig.userConfig).ssr || (_userConfig_userConfig.ssr = {});
283
+ if (true === userConfig.userConfig.ssr) userConfig.userConfig.ssr = {};
284
+ userConfig.userConfig.ssr.distOutputDir = chain.output.get('path') || external_path_default().resolve(process.cwd(), 'dist/bundles');
285
+ }
286
+ });
287
+ api.config(()=>{
288
+ var _ref;
289
+ var _modernjsConfig_tools, _userConfig_csrConfig, _modernjsConfig_dev, _modernjsConfig_source, _modernjsConfig_dev1, _modernjsConfig_dev2;
290
+ const devServerConfig = null == (_modernjsConfig_tools = modernjsConfig.tools) ? void 0 : _modernjsConfig_tools.devServer;
291
+ const corsWarnMsgs = [
292
+ 'View https://module-federation.io/guide/troubleshooting/other.html#cors-warn for more details.'
293
+ ];
294
+ if ('object' != typeof devServerConfig || !('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.');
295
+ const exposes = null == (_userConfig_csrConfig = userConfig.csrConfig) ? void 0 : _userConfig_csrConfig.exposes;
296
+ const hasExposes = exposes && Array.isArray(exposes) ? exposes.length > 0 : Object.keys(null != exposes ? exposes : {}).length > 0;
297
+ const lazyCompilationDisabledByPlugin = hasExposes && (null == modernjsConfig ? void 0 : null == (_modernjsConfig_dev = modernjsConfig.dev) ? void 0 : _modernjsConfig_dev.lazyCompilation) !== false;
298
+ if (corsWarnMsgs.length > 1 && hasExposes) external_logger_js_default().warn(corsWarnMsgs.join('\n'));
299
+ if (lazyCompilationDisabledByPlugin) external_logger_js_default().warn('Detected exposes in the Module Federation config. The Modern.js v3 Module Federation plugin will set dev.lazyCompilation to false for producer apps.');
300
+ const corsHeaders = hasExposes ? {
301
+ 'Access-Control-Allow-Origin': '*',
302
+ 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
303
+ 'Access-Control-Allow-Headers': '*'
304
+ } : void 0;
305
+ return {
306
+ tools: {
307
+ devServer: {
308
+ headers: corsHeaders
309
+ }
310
+ },
311
+ resolve: {
312
+ alias: {
313
+ '@modern-js/runtime/mf': require.resolve('@module-federation/modern-js-v3/runtime')
314
+ }
315
+ },
316
+ source: {
317
+ enableAsyncEntry: null != (_ref = null == (_modernjsConfig_source = modernjsConfig.source) ? void 0 : _modernjsConfig_source.enableAsyncEntry) ? _ref : true
318
+ },
319
+ dev: {
320
+ assetPrefix: (null == modernjsConfig ? void 0 : null == (_modernjsConfig_dev1 = modernjsConfig.dev) ? void 0 : _modernjsConfig_dev1.assetPrefix) ? modernjsConfig.dev.assetPrefix : 'auto',
321
+ lazyCompilation: hasExposes ? false : null == modernjsConfig ? void 0 : null == (_modernjsConfig_dev2 = modernjsConfig.dev) ? void 0 : _modernjsConfig_dev2.lazyCompilation
322
+ }
323
+ };
324
+ });
325
+ }
326
+ });
327
+ const configPlugin = moduleFederationConfigPlugin;
328
+ })();
329
+ exports.addMyTypes2Ignored = __webpack_exports__.addMyTypes2Ignored;
330
+ exports["default"] = __webpack_exports__["default"];
331
+ exports.getMFConfig = __webpack_exports__.getMFConfig;
332
+ exports.isWebTarget = __webpack_exports__.isWebTarget;
333
+ exports.moduleFederationConfigPlugin = __webpack_exports__.moduleFederationConfigPlugin;
334
+ exports.patchBundlerConfig = __webpack_exports__.patchBundlerConfig;
335
+ exports.patchMFConfig = __webpack_exports__.patchMFConfig;
336
+ exports.setEnv = __webpack_exports__.setEnv;
337
+ exports.skipByTarget = __webpack_exports__.skipByTarget;
338
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
339
+ "addMyTypes2Ignored",
340
+ "default",
341
+ "getMFConfig",
342
+ "isWebTarget",
343
+ "moduleFederationConfigPlugin",
344
+ "patchBundlerConfig",
345
+ "patchMFConfig",
346
+ "setEnv",
347
+ "skipByTarget"
348
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
349
+ Object.defineProperty(exports, '__esModule', {
350
+ value: true
351
+ });
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ __webpack_require__.d(__webpack_exports__, {
31
+ createModuleFederationConfig: ()=>enhanced_namespaceObject.createModuleFederationConfig,
32
+ default: ()=>cli,
33
+ moduleFederationPlugin: ()=>moduleFederationPlugin
34
+ });
35
+ const rspack_namespaceObject = require("@module-federation/enhanced/rspack");
36
+ const external_configPlugin_js_namespaceObject = require("./configPlugin.js");
37
+ const external_ssrPlugin_js_namespaceObject = require("./ssrPlugin.js");
38
+ const external_utils_js_namespaceObject = require("./utils.js");
39
+ const enhanced_namespaceObject = require("@module-federation/enhanced");
40
+ const moduleFederationPlugin = (userConfig = {})=>{
41
+ var _userConfig_fetchServerQuery, _userConfig_secondarySharedTreeShaking;
42
+ const internalModernPluginOptions = {
43
+ csrConfig: void 0,
44
+ ssrConfig: void 0,
45
+ browserPlugin: void 0,
46
+ nodePlugin: void 0,
47
+ assetResources: {},
48
+ distOutputDir: '',
49
+ originPluginOptions: {
50
+ ...userConfig
51
+ },
52
+ userConfig: userConfig || {},
53
+ assetFileNames: {},
54
+ fetchServerQuery: null != (_userConfig_fetchServerQuery = userConfig.fetchServerQuery) ? _userConfig_fetchServerQuery : void 0,
55
+ secondarySharedTreeShaking: null != (_userConfig_secondarySharedTreeShaking = userConfig.secondarySharedTreeShaking) ? _userConfig_secondarySharedTreeShaking : false
56
+ };
57
+ return {
58
+ name: '@modern-js/plugin-module-federation',
59
+ setup: async (api)=>{
60
+ api.modifyBundlerChain((chain)=>{
61
+ const browserPluginOptions = internalModernPluginOptions.csrConfig;
62
+ const { secondarySharedTreeShaking } = internalModernPluginOptions;
63
+ if ((0, external_utils_js_namespaceObject.isWebTarget)(chain.get('target'))) if (secondarySharedTreeShaking) chain.plugin('plugin-module-federation').use(rspack_namespaceObject.TreeShakingSharedPlugin, [
64
+ {
65
+ mfConfig: browserPluginOptions,
66
+ secondary: true
67
+ }
68
+ ]);
69
+ else chain.plugin('plugin-module-federation').use(rspack_namespaceObject.ModuleFederationPlugin, [
70
+ browserPluginOptions
71
+ ]).init((Plugin, args)=>{
72
+ internalModernPluginOptions.browserPlugin = new Plugin(args[0]);
73
+ return internalModernPluginOptions.browserPlugin;
74
+ });
75
+ });
76
+ api._internalServerPlugins(({ plugins })=>{
77
+ plugins.push({
78
+ name: '@module-federation/modern-js-v3/server'
79
+ });
80
+ return {
81
+ plugins
82
+ };
83
+ });
84
+ },
85
+ usePlugins: [
86
+ (0, external_configPlugin_js_namespaceObject.moduleFederationConfigPlugin)(internalModernPluginOptions),
87
+ (0, external_ssrPlugin_js_namespaceObject.moduleFederationSSRPlugin)(internalModernPluginOptions)
88
+ ]
89
+ };
90
+ };
91
+ const cli = moduleFederationPlugin;
92
+ exports.createModuleFederationConfig = __webpack_exports__.createModuleFederationConfig;
93
+ exports["default"] = __webpack_exports__["default"];
94
+ exports.moduleFederationPlugin = __webpack_exports__.moduleFederationPlugin;
95
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
96
+ "createModuleFederationConfig",
97
+ "default",
98
+ "moduleFederationPlugin"
99
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
100
+ Object.defineProperty(exports, '__esModule', {
101
+ value: true
102
+ });
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = (module)=>{
5
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
+ __webpack_require__.d(getter, {
7
+ a: getter
8
+ });
9
+ return getter;
10
+ };
11
+ })();
12
+ (()=>{
13
+ __webpack_require__.d = (exports1, getters, values)=>{
14
+ var define = (defs, kind)=>{
15
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
16
+ enumerable: true,
17
+ [kind]: defs[key]
18
+ });
19
+ };
20
+ define(getters, "get");
21
+ define(values, "value");
22
+ };
23
+ })();
24
+ (()=>{
25
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
26
+ })();
27
+ (()=>{
28
+ __webpack_require__.r = (exports1)=>{
29
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
30
+ value: 'Module'
31
+ });
32
+ Object.defineProperty(exports1, '__esModule', {
33
+ value: true
34
+ });
35
+ };
36
+ })();
37
+ var __webpack_exports__ = {};
38
+ __webpack_require__.r(__webpack_exports__);
39
+ __webpack_require__.d(__webpack_exports__, {
40
+ default: ()=>inject_node_fetch
41
+ });
42
+ const external_node_fetch_namespaceObject = require("node-fetch");
43
+ var external_node_fetch_default = /*#__PURE__*/ __webpack_require__.n(external_node_fetch_namespaceObject);
44
+ const injectNodeFetchPlugin = ()=>({
45
+ name: 'inject-node-fetch-plugin',
46
+ beforeInit (args) {
47
+ if (!globalThis.fetch) globalThis.fetch = external_node_fetch_default();
48
+ return args;
49
+ }
50
+ });
51
+ const inject_node_fetch = injectNodeFetchPlugin;
52
+ exports["default"] = __webpack_exports__["default"];
53
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
54
+ "default"
55
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
56
+ Object.defineProperty(exports, '__esModule', {
57
+ value: true
58
+ });
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ const sharedStrategy = ()=>({
31
+ name: 'shared-strategy-plugin',
32
+ beforeInit (args) {
33
+ const { userOptions } = args;
34
+ const shared = userOptions.shared;
35
+ if (shared) Object.keys(shared).forEach((sharedKey)=>{
36
+ const sharedConfigs = shared[sharedKey];
37
+ const arraySharedConfigs = Array.isArray(sharedConfigs) ? sharedConfigs : [
38
+ sharedConfigs
39
+ ];
40
+ arraySharedConfigs.forEach((s)=>{
41
+ s.strategy = 'loaded-first';
42
+ });
43
+ });
44
+ return args;
45
+ }
46
+ });
47
+ const __rspack_default_export = sharedStrategy;
48
+ __webpack_require__.d(__webpack_exports__, {}, {
49
+ default: __rspack_default_export
50
+ });
51
+ exports["default"] = __webpack_exports__["default"];
52
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
53
+ "default"
54
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
55
+ Object.defineProperty(exports, '__esModule', {
56
+ value: true
57
+ });
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = (module)=>{
5
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
+ __webpack_require__.d(getter, {
7
+ a: getter
8
+ });
9
+ return getter;
10
+ };
11
+ })();
12
+ (()=>{
13
+ __webpack_require__.d = (exports1, getters, values)=>{
14
+ var define = (defs, kind)=>{
15
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
16
+ enumerable: true,
17
+ [kind]: defs[key]
18
+ });
19
+ };
20
+ define(getters, "get");
21
+ define(values, "value");
22
+ };
23
+ })();
24
+ (()=>{
25
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
26
+ })();
27
+ (()=>{
28
+ __webpack_require__.r = (exports1)=>{
29
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
30
+ value: 'Module'
31
+ });
32
+ Object.defineProperty(exports1, '__esModule', {
33
+ value: true
34
+ });
35
+ };
36
+ })();
37
+ var __webpack_exports__ = {};
38
+ __webpack_require__.r(__webpack_exports__);
39
+ __webpack_require__.d(__webpack_exports__, {
40
+ default: ()=>data_fetch_server_plugin
41
+ });
42
+ const data_fetch_server_middleware_namespaceObject = require("@module-federation/bridge-react/data-fetch-server-middleware");
43
+ var data_fetch_server_middleware_default = /*#__PURE__*/ __webpack_require__.n(data_fetch_server_middleware_namespaceObject);
44
+ const dataFetchServePlugin = ()=>({
45
+ name: 'mf-data-fetch-server-plugin',
46
+ setup: (api)=>{
47
+ api.onPrepare(()=>{
48
+ const { middlewares } = api.getServerContext();
49
+ middlewares.push({
50
+ name: 'module-federation-serve-manifest',
51
+ handler: data_fetch_server_middleware_default()
52
+ });
53
+ });
54
+ }
55
+ });
56
+ const data_fetch_server_plugin = dataFetchServePlugin;
57
+ exports["default"] = __webpack_exports__["default"];
58
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
59
+ "default"
60
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
61
+ Object.defineProperty(exports, '__esModule', {
62
+ value: true
63
+ });