@module-federation/modern-js 0.21.6 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/dist/cjs/cli/configPlugin.js +301 -357
  2. package/dist/cjs/cli/index.js +103 -93
  3. package/dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js +51 -41
  4. package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +73 -75
  5. package/dist/cjs/cli/mfRuntimePlugins/shared-strategy.js +50 -40
  6. package/dist/cjs/cli/server/data-fetch-server-plugin.js +55 -44
  7. package/dist/cjs/cli/ssrPlugin.js +266 -298
  8. package/dist/cjs/cli/utils.js +84 -81
  9. package/dist/cjs/constant.js +37 -28
  10. package/dist/cjs/interfaces/bundler.js +17 -15
  11. package/dist/cjs/logger.js +37 -25
  12. package/dist/cjs/react/index.js +55 -19
  13. package/dist/cjs/react/plugin.js +62 -37
  14. package/dist/cjs/react/v18.js +55 -19
  15. package/dist/cjs/react/v19.js +55 -19
  16. package/dist/cjs/runtime/index.js +55 -19
  17. package/dist/cjs/server/fileCache.js +76 -76
  18. package/dist/cjs/server/index.js +65 -57
  19. package/dist/cjs/server/staticMiddleware.js +84 -84
  20. package/dist/cjs/ssr-runtime/SSRLiveReload.js +40 -34
  21. package/dist/cjs/ssr-runtime/devPlugin.js +63 -67
  22. package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +44 -36
  23. package/dist/cjs/types/index.js +17 -15
  24. package/dist/esm/cli/configPlugin.mjs +305 -0
  25. package/dist/esm/cli/index.mjs +83 -0
  26. package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.mjs +12 -0
  27. package/dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.mjs +58 -0
  28. package/dist/esm/cli/mfRuntimePlugins/shared-strategy.mjs +21 -0
  29. package/dist/esm/cli/server/data-fetch-server-plugin.mjs +17 -0
  30. package/dist/esm/cli/ssrPlugin.mjs +254 -0
  31. package/dist/esm/cli/utils.mjs +40 -0
  32. package/dist/esm/constant.mjs +3 -0
  33. package/dist/esm/logger.mjs +5 -0
  34. package/dist/esm/react/plugin.mjs +3 -0
  35. package/dist/esm/server/fileCache.mjs +90 -0
  36. package/dist/esm/server/index.mjs +36 -0
  37. package/dist/esm/server/staticMiddleware.mjs +87 -0
  38. package/dist/esm/ssr-runtime/SSRLiveReload.mjs +22 -0
  39. package/dist/esm/ssr-runtime/devPlugin.mjs +70 -0
  40. package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.mjs +34 -0
  41. package/dist/esm-node/cli/configPlugin.mjs +263 -0
  42. package/dist/esm-node/cli/index.mjs +67 -0
  43. package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.mjs +10 -0
  44. package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.mjs +46 -0
  45. package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.mjs +19 -0
  46. package/dist/esm-node/cli/server/data-fetch-server-plugin.mjs +15 -0
  47. package/dist/esm-node/cli/ssrPlugin.mjs +228 -0
  48. package/dist/esm-node/cli/utils.mjs +40 -0
  49. package/dist/esm-node/constant.mjs +3 -0
  50. package/dist/esm-node/logger.mjs +5 -0
  51. package/dist/esm-node/react/plugin.mjs +3 -0
  52. package/dist/esm-node/server/fileCache.mjs +37 -0
  53. package/dist/esm-node/server/index.mjs +34 -0
  54. package/dist/esm-node/server/staticMiddleware.mjs +42 -0
  55. package/dist/esm-node/ssr-runtime/SSRLiveReload.mjs +15 -0
  56. package/dist/esm-node/ssr-runtime/devPlugin.mjs +33 -0
  57. package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.mjs +14 -0
  58. package/package.json +32 -31
  59. package/dist/cjs/cli/configPlugin.spec.js +0 -112
  60. package/dist/cjs/server/fileCache.spec.js +0 -28
  61. package/dist/cjs/server/staticMiddleware.spec.js +0 -185
  62. package/dist/esm/cli/configPlugin.js +0 -395
  63. package/dist/esm/cli/configPlugin.spec.js +0 -108
  64. package/dist/esm/cli/index.js +0 -92
  65. package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.js +0 -16
  66. package/dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -74
  67. package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +0 -25
  68. package/dist/esm/cli/server/data-fetch-server-plugin.js +0 -20
  69. package/dist/esm/cli/ssrPlugin.js +0 -305
  70. package/dist/esm/cli/utils.js +0 -53
  71. package/dist/esm/constant.js +0 -6
  72. package/dist/esm/logger.js +0 -7
  73. package/dist/esm/react/plugin.js +0 -5
  74. package/dist/esm/server/fileCache.js +0 -98
  75. package/dist/esm/server/fileCache.spec.js +0 -50
  76. package/dist/esm/server/index.js +0 -41
  77. package/dist/esm/server/staticMiddleware.js +0 -104
  78. package/dist/esm/server/staticMiddleware.spec.js +0 -328
  79. package/dist/esm/ssr-runtime/SSRLiveReload.js +0 -26
  80. package/dist/esm/ssr-runtime/devPlugin.js +0 -73
  81. package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -34
  82. package/dist/esm-node/cli/configPlugin.js +0 -347
  83. package/dist/esm-node/cli/configPlugin.spec.js +0 -89
  84. package/dist/esm-node/cli/index.js +0 -72
  85. package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.js +0 -14
  86. package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -62
  87. package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +0 -23
  88. package/dist/esm-node/cli/server/data-fetch-server-plugin.js +0 -18
  89. package/dist/esm-node/cli/ssrPlugin.js +0 -280
  90. package/dist/esm-node/cli/utils.js +0 -53
  91. package/dist/esm-node/constant.js +0 -6
  92. package/dist/esm-node/logger.js +0 -7
  93. package/dist/esm-node/react/plugin.js +0 -5
  94. package/dist/esm-node/server/fileCache.js +0 -49
  95. package/dist/esm-node/server/fileCache.spec.js +0 -27
  96. package/dist/esm-node/server/index.js +0 -39
  97. package/dist/esm-node/server/staticMiddleware.js +0 -55
  98. package/dist/esm-node/server/staticMiddleware.spec.js +0 -162
  99. package/dist/esm-node/ssr-runtime/SSRLiveReload.js +0 -19
  100. package/dist/esm-node/ssr-runtime/devPlugin.js +0 -37
  101. package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -16
  102. /package/dist/esm/interfaces/{bundler.js → bundler.mjs} +0 -0
  103. /package/dist/esm/react/{index.js → index.mjs} +0 -0
  104. /package/dist/esm/react/{v18.js → v18.mjs} +0 -0
  105. /package/dist/esm/react/{v19.js → v19.mjs} +0 -0
  106. /package/dist/esm/runtime/{index.js → index.mjs} +0 -0
  107. /package/dist/esm/types/{index.js → index.mjs} +0 -0
  108. /package/dist/esm-node/interfaces/{bundler.js → bundler.mjs} +0 -0
  109. /package/dist/esm-node/react/{index.js → index.mjs} +0 -0
  110. /package/dist/esm-node/react/{v18.js → v18.mjs} +0 -0
  111. /package/dist/esm-node/react/{v19.js → v19.mjs} +0 -0
  112. /package/dist/esm-node/runtime/{index.js → index.mjs} +0 -0
  113. /package/dist/esm-node/types/{index.js → index.mjs} +0 -0
@@ -1,316 +1,284 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var ssrPlugin_exports = {};
30
- __export(ssrPlugin_exports, {
31
- CHAIN_MF_PLUGIN_ID: () => CHAIN_MF_PLUGIN_ID,
32
- default: () => ssrPlugin_default,
33
- moduleFederationSSRPlugin: () => moduleFederationSSRPlugin,
34
- setEnv: () => setEnv
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, definition)=>{
14
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
+ enumerable: true,
16
+ get: definition[key]
17
+ });
18
+ };
19
+ })();
20
+ (()=>{
21
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
22
+ })();
23
+ (()=>{
24
+ __webpack_require__.r = (exports1)=>{
25
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
26
+ value: 'Module'
27
+ });
28
+ Object.defineProperty(exports1, '__esModule', {
29
+ value: true
30
+ });
31
+ };
32
+ })();
33
+ var __webpack_exports__ = {};
34
+ __webpack_require__.r(__webpack_exports__);
35
+ __webpack_require__.d(__webpack_exports__, {
36
+ default: ()=>ssrPlugin,
37
+ moduleFederationSSRPlugin: ()=>moduleFederationSSRPlugin,
38
+ setEnv: ()=>setEnv,
39
+ CHAIN_MF_PLUGIN_ID: ()=>CHAIN_MF_PLUGIN_ID
35
40
  });
36
- module.exports = __toCommonJS(ssrPlugin_exports);
37
- var import_path = __toESM(require("path"));
38
- var import_fs_extra = __toESM(require("fs-extra"));
39
- var import_webpack = require("@module-federation/enhanced/webpack");
40
- var import_rspack = require("@module-federation/enhanced/rspack");
41
- var import_universe_entry_chunk_tracker_plugin = __toESM(require("@module-federation/node/universe-entry-chunk-tracker-plugin"));
42
- var import_logger = __toESM(require("../logger"));
43
- var import_utils = require("./utils");
44
- var import_utils2 = require("@module-federation/rsbuild-plugin/utils");
45
- var import_sdk = require("@module-federation/sdk");
46
- var import_utils3 = require("./utils");
41
+ const external_path_namespaceObject = require("path");
42
+ var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
43
+ const external_fs_extra_namespaceObject = require("fs-extra");
44
+ var external_fs_extra_default = /*#__PURE__*/ __webpack_require__.n(external_fs_extra_namespaceObject);
45
+ const webpack_namespaceObject = require("@module-federation/enhanced/webpack");
46
+ const rspack_namespaceObject = require("@module-federation/enhanced/rspack");
47
+ const universe_entry_chunk_tracker_plugin_namespaceObject = require("@module-federation/node/universe-entry-chunk-tracker-plugin");
48
+ var universe_entry_chunk_tracker_plugin_default = /*#__PURE__*/ __webpack_require__.n(universe_entry_chunk_tracker_plugin_namespaceObject);
49
+ const external_logger_js_namespaceObject = require("../logger.js");
50
+ var external_logger_js_default = /*#__PURE__*/ __webpack_require__.n(external_logger_js_namespaceObject);
51
+ const external_utils_js_namespaceObject = require("./utils.js");
52
+ const utils_namespaceObject = require("@module-federation/rsbuild-plugin/utils");
53
+ const sdk_namespaceObject = require("@module-federation/sdk");
47
54
  function setEnv() {
48
- process.env["MF_SSR_PRJ"] = "true";
55
+ process.env['MF_SSR_PRJ'] = 'true';
49
56
  }
50
- const CHAIN_MF_PLUGIN_ID = "plugin-module-federation-server";
57
+ const CHAIN_MF_PLUGIN_ID = 'plugin-module-federation-server';
51
58
  function getManifestAssetFileNames(manifestOption) {
52
- if (!manifestOption) {
59
+ if (!manifestOption) return {
60
+ statsFileName: sdk_namespaceObject.StatsFileName,
61
+ manifestFileName: sdk_namespaceObject.ManifestFileName
62
+ };
63
+ const JSON_EXT = '.json';
64
+ const filePath = 'boolean' == typeof manifestOption ? '' : manifestOption.filePath || '';
65
+ const baseFileName = 'boolean' == typeof manifestOption ? '' : manifestOption.fileName || '';
66
+ const ensureExt = (name)=>name.endsWith(JSON_EXT) ? name : `${name}${JSON_EXT}`;
67
+ const withSuffix = (name, suffix)=>name.replace(JSON_EXT, `${suffix}${JSON_EXT}`);
68
+ const manifestFileName = baseFileName ? ensureExt(baseFileName) : sdk_namespaceObject.ManifestFileName;
69
+ const statsFileName = baseFileName ? withSuffix(manifestFileName, '-stats') : sdk_namespaceObject.StatsFileName;
53
70
  return {
54
- statsFileName: import_sdk.StatsFileName,
55
- manifestFileName: import_sdk.ManifestFileName
71
+ statsFileName: (0, sdk_namespaceObject.simpleJoinRemoteEntry)(filePath, statsFileName),
72
+ manifestFileName: (0, sdk_namespaceObject.simpleJoinRemoteEntry)(filePath, manifestFileName)
56
73
  };
57
- }
58
- const JSON_EXT = ".json";
59
- const filePath = typeof manifestOption === "boolean" ? "" : manifestOption.filePath || "";
60
- const baseFileName = typeof manifestOption === "boolean" ? "" : manifestOption.fileName || "";
61
- const ensureExt = (name) => name.endsWith(JSON_EXT) ? name : `${name}${JSON_EXT}`;
62
- const withSuffix = (name, suffix) => name.replace(JSON_EXT, `${suffix}${JSON_EXT}`);
63
- const manifestFileName = baseFileName ? ensureExt(baseFileName) : import_sdk.ManifestFileName;
64
- const statsFileName = baseFileName ? withSuffix(manifestFileName, "-stats") : import_sdk.StatsFileName;
65
- return {
66
- statsFileName: (0, import_sdk.simpleJoinRemoteEntry)(filePath, statsFileName),
67
- manifestFileName: (0, import_sdk.simpleJoinRemoteEntry)(filePath, manifestFileName)
68
- };
69
74
  }
70
- const mfSSRRsbuildPlugin = (pluginOptions) => {
71
- return {
72
- name: "@modern-js/plugin-mf-post-config",
73
- pre: [
74
- "@modern-js/builder-plugin-ssr"
75
- ],
76
- setup(api) {
77
- var _pluginOptions_csrConfig, _pluginOptions_assetFileNames, _pluginOptions_ssrConfig;
78
- if (pluginOptions.csrConfig.getPublicPath) {
79
- return;
80
- }
81
- let csrOutputPath = "";
82
- let ssrOutputPath = "";
83
- let ssrEnv = "";
84
- let csrEnv = "";
85
- const browserAssetFileNames = pluginOptions.assetFileNames.browser || getManifestAssetFileNames((_pluginOptions_csrConfig = pluginOptions.csrConfig) === null || _pluginOptions_csrConfig === void 0 ? void 0 : _pluginOptions_csrConfig.manifest);
86
- const nodeAssetFileNames = ((_pluginOptions_assetFileNames = pluginOptions.assetFileNames) === null || _pluginOptions_assetFileNames === void 0 ? void 0 : _pluginOptions_assetFileNames.node) || getManifestAssetFileNames((_pluginOptions_ssrConfig = pluginOptions.ssrConfig) === null || _pluginOptions_ssrConfig === void 0 ? void 0 : _pluginOptions_ssrConfig.manifest);
87
- const collectAssets = (assets, fileNames, tag) => {
88
- const statsAsset = assets[fileNames.statsFileName];
89
- const manifestAsset = assets[fileNames.manifestFileName];
90
- if (!statsAsset || !manifestAsset) {
91
- return void 0;
92
- }
93
- try {
94
- const statsRaw = statsAsset.source();
95
- const manifestRaw = manifestAsset.source();
96
- const statsContent = typeof statsRaw === "string" ? statsRaw : statsRaw.toString();
97
- const manifestContent = typeof manifestRaw === "string" ? manifestRaw : manifestRaw.toString();
98
- return {
99
- stats: {
100
- data: JSON.parse(statsContent),
101
- filename: fileNames.statsFileName
102
- },
103
- manifest: {
104
- data: JSON.parse(manifestContent),
105
- filename: fileNames.manifestFileName
106
- }
107
- };
108
- } catch (err) {
109
- const message = err instanceof Error ? err.message : String(err);
110
- import_logger.default.error(`Failed to parse ${tag} manifest assets: ${message}`);
111
- return void 0;
112
- }
113
- };
114
- api.modifyEnvironmentConfig((config, { name }) => {
115
- const target = config.output.target;
116
- if ((0, import_utils3.skipByTarget)(target)) {
117
- return config;
118
- }
119
- if ((0, import_utils3.isWebTarget)(target)) {
120
- csrOutputPath = config.output.distPath.root;
121
- csrEnv = name;
122
- } else {
123
- ssrOutputPath = config.output.distPath.root;
124
- ssrEnv = name;
125
- }
126
- return config;
127
- });
128
- const modifySSRPublicPath = (config, utils) => {
129
- if (ssrEnv !== utils.environment.name) {
130
- return config;
131
- }
132
- const userSSRConfig = pluginOptions.userConfig.ssr ? typeof pluginOptions.userConfig.ssr === "object" ? pluginOptions.userConfig.ssr : {} : {};
133
- if (userSSRConfig.distOutputDir) {
134
- return;
135
- }
136
- config.output.publicPath = `${config.output.publicPath}${import_path.default.relative(csrOutputPath, ssrOutputPath)}/`;
137
- return config;
138
- };
139
- api.modifyWebpackConfig((config, utils) => {
140
- modifySSRPublicPath(config, utils);
141
- return config;
142
- });
143
- api.modifyRspackConfig((config, utils) => {
144
- modifySSRPublicPath(config, utils);
145
- return config;
146
- });
147
- api.processAssets({
148
- stage: "report"
149
- }, ({ assets, environment: envContext }) => {
150
- var _pluginOptions_csrConfig2, _pluginOptions_ssrConfig2;
151
- const envName = envContext.name;
152
- if (((_pluginOptions_csrConfig2 = pluginOptions.csrConfig) === null || _pluginOptions_csrConfig2 === void 0 ? void 0 : _pluginOptions_csrConfig2.manifest) !== false && csrEnv && envName === csrEnv) {
153
- const browserAssets = collectAssets(assets, browserAssetFileNames, "browser");
154
- if (browserAssets) {
155
- pluginOptions.assetResources.browser = browserAssets;
156
- }
157
- }
158
- if (((_pluginOptions_ssrConfig2 = pluginOptions.ssrConfig) === null || _pluginOptions_ssrConfig2 === void 0 ? void 0 : _pluginOptions_ssrConfig2.manifest) !== false && ssrEnv && envName === ssrEnv) {
159
- const nodeAssets = collectAssets(assets, nodeAssetFileNames, "node");
160
- if (nodeAssets) {
161
- pluginOptions.assetResources.node = nodeAssets;
162
- }
163
- }
164
- });
165
- }
166
- };
167
- };
168
- const moduleFederationSSRPlugin = (pluginOptions) => ({
169
- name: "@modern-js/plugin-module-federation-ssr",
170
- pre: [
171
- "@modern-js/plugin-module-federation-config",
172
- "@modern-js/plugin-module-federation"
173
- ],
174
- setup: async (api) => {
175
- var _pluginOptions_userConfig, _modernjsConfig_server;
176
- const modernjsConfig = api.getConfig();
177
- var _pluginOptions_userConfig_ssr;
178
- const enableSSR = (_pluginOptions_userConfig_ssr = (_pluginOptions_userConfig = pluginOptions.userConfig) === null || _pluginOptions_userConfig === void 0 ? void 0 : _pluginOptions_userConfig.ssr) !== null && _pluginOptions_userConfig_ssr !== void 0 ? _pluginOptions_userConfig_ssr : Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
179
- if (!enableSSR) {
180
- return;
181
- }
182
- setEnv();
183
- api._internalRuntimePlugins(({ entrypoint, plugins }) => {
184
- const { fetchServerQuery } = pluginOptions;
185
- plugins.push({
186
- name: "injectDataFetchFunction",
187
- path: "@module-federation/modern-js/ssr-inject-data-fetch-function-plugin",
188
- config: {
189
- fetchServerQuery
190
- }
191
- });
192
- if (!(0, import_utils.isDev)()) {
193
- return {
194
- entrypoint,
195
- plugins
196
- };
197
- }
198
- plugins.push({
199
- name: "mfSSRDev",
200
- path: "@module-federation/modern-js/ssr-dev-plugin",
201
- config: {}
202
- });
203
- return {
204
- entrypoint,
205
- plugins
206
- };
207
- });
208
- if (pluginOptions.ssrConfig.remotes) {
209
- api._internalServerPlugins(({ plugins }) => {
210
- plugins.push({
211
- name: "@module-federation/modern-js/data-fetch-server-plugin",
212
- options: {}
213
- });
214
- return {
215
- plugins
216
- };
217
- });
218
- }
219
- api.modifyBundlerChain((chain) => {
220
- const target = chain.get("target");
221
- if ((0, import_utils3.skipByTarget)(target)) {
222
- return;
223
- }
224
- const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
225
- const MFPlugin = bundlerType === "webpack" ? import_webpack.ModuleFederationPlugin : import_rspack.ModuleFederationPlugin;
226
- const isWeb = (0, import_utils3.isWebTarget)(target);
227
- if (!isWeb) {
228
- if (!chain.plugins.has(CHAIN_MF_PLUGIN_ID)) {
229
- chain.plugin(CHAIN_MF_PLUGIN_ID).use(MFPlugin, [
230
- pluginOptions.ssrConfig
231
- ]).init((Plugin, args) => {
232
- pluginOptions.nodePlugin = new Plugin(args[0]);
233
- return pluginOptions.nodePlugin;
234
- });
235
- }
236
- }
237
- if (!isWeb) {
238
- chain.target("async-node");
239
- if ((0, import_utils.isDev)()) {
240
- chain.plugin("UniverseEntryChunkTrackerPlugin").use(import_universe_entry_chunk_tracker_plugin.default);
241
- }
242
- const userSSRConfig = pluginOptions.userConfig.ssr ? typeof pluginOptions.userConfig.ssr === "object" ? pluginOptions.userConfig.ssr : {} : {};
243
- const publicPath = chain.output.get("publicPath");
244
- if (userSSRConfig.distOutputDir && publicPath) {
245
- chain.output.publicPath(`${publicPath}${userSSRConfig.distOutputDir}/`);
75
+ const mfSSRRsbuildPlugin = (pluginOptions)=>({
76
+ name: '@modern-js/plugin-mf-post-config',
77
+ pre: [
78
+ '@modern-js/builder-plugin-ssr'
79
+ ],
80
+ setup (api) {
81
+ var _pluginOptions_csrConfig, _pluginOptions_assetFileNames, _pluginOptions_ssrConfig;
82
+ if (pluginOptions.csrConfig.getPublicPath) return;
83
+ let csrOutputPath = '';
84
+ let ssrOutputPath = '';
85
+ let ssrEnv = '';
86
+ let csrEnv = '';
87
+ const browserAssetFileNames = pluginOptions.assetFileNames.browser || getManifestAssetFileNames(null == (_pluginOptions_csrConfig = pluginOptions.csrConfig) ? void 0 : _pluginOptions_csrConfig.manifest);
88
+ const nodeAssetFileNames = (null == (_pluginOptions_assetFileNames = pluginOptions.assetFileNames) ? void 0 : _pluginOptions_assetFileNames.node) || getManifestAssetFileNames(null == (_pluginOptions_ssrConfig = pluginOptions.ssrConfig) ? void 0 : _pluginOptions_ssrConfig.manifest);
89
+ const collectAssets = (assets, fileNames, tag)=>{
90
+ const statsAsset = assets[fileNames.statsFileName];
91
+ const manifestAsset = assets[fileNames.manifestFileName];
92
+ if (!statsAsset || !manifestAsset) return;
93
+ try {
94
+ const statsRaw = statsAsset.source();
95
+ const manifestRaw = manifestAsset.source();
96
+ const statsContent = 'string' == typeof statsRaw ? statsRaw : statsRaw.toString();
97
+ const manifestContent = 'string' == typeof manifestRaw ? manifestRaw : manifestRaw.toString();
98
+ return {
99
+ stats: {
100
+ data: JSON.parse(statsContent),
101
+ filename: fileNames.statsFileName
102
+ },
103
+ manifest: {
104
+ data: JSON.parse(manifestContent),
105
+ filename: fileNames.manifestFileName
106
+ }
107
+ };
108
+ } catch (err) {
109
+ const message = err instanceof Error ? err.message : String(err);
110
+ external_logger_js_default().error(`Failed to parse ${tag} manifest assets: ${message}`);
111
+ return;
112
+ }
113
+ };
114
+ api.modifyEnvironmentConfig((config, { name })=>{
115
+ const target = config.output.target;
116
+ if ((0, external_utils_js_namespaceObject.skipByTarget)(target)) return config;
117
+ if ((0, external_utils_js_namespaceObject.isWebTarget)(target)) {
118
+ csrOutputPath = config.output.distPath.root;
119
+ csrEnv = name;
120
+ } else {
121
+ ssrOutputPath = config.output.distPath.root;
122
+ ssrEnv = name;
123
+ }
124
+ return config;
125
+ });
126
+ const modifySSRPublicPath = (config, utils)=>{
127
+ if (ssrEnv !== utils.environment.name) return config;
128
+ const userSSRConfig = pluginOptions.userConfig.ssr ? 'object' == typeof pluginOptions.userConfig.ssr ? pluginOptions.userConfig.ssr : {} : {};
129
+ if (!userSSRConfig.distOutputDir) return;
130
+ config.output.publicPath = `${config.output.publicPath}${external_path_default().relative(csrOutputPath, ssrOutputPath)}/`;
131
+ return config;
132
+ };
133
+ api.modifyWebpackConfig((config, utils)=>{
134
+ modifySSRPublicPath(config, utils);
135
+ return config;
136
+ });
137
+ api.modifyRspackConfig((config, utils)=>{
138
+ modifySSRPublicPath(config, utils);
139
+ return config;
140
+ });
141
+ api.processAssets({
142
+ stage: 'report'
143
+ }, ({ assets, environment: envContext })=>{
144
+ var _pluginOptions_csrConfig, _pluginOptions_ssrConfig;
145
+ const envName = envContext.name;
146
+ if ((null == (_pluginOptions_csrConfig = pluginOptions.csrConfig) ? void 0 : _pluginOptions_csrConfig.manifest) !== false && csrEnv && envName === csrEnv) {
147
+ const browserAssets = collectAssets(assets, browserAssetFileNames, 'browser');
148
+ if (browserAssets) pluginOptions.assetResources.browser = browserAssets;
149
+ }
150
+ if ((null == (_pluginOptions_ssrConfig = pluginOptions.ssrConfig) ? void 0 : _pluginOptions_ssrConfig.manifest) !== false && ssrEnv && envName === ssrEnv) {
151
+ const nodeAssets = collectAssets(assets, nodeAssetFileNames, 'node');
152
+ if (nodeAssets) pluginOptions.assetResources.node = nodeAssets;
153
+ }
154
+ });
246
155
  }
247
- }
248
- if ((0, import_utils.isDev)() && isWeb) {
249
- chain.externals({
250
- "@module-federation/node/utils": "NOT_USED_IN_BROWSER"
251
- });
252
- }
253
156
  });
254
- api.config(() => {
255
- return {
256
- builderPlugins: [
257
- mfSSRRsbuildPlugin(pluginOptions)
157
+ const moduleFederationSSRPlugin = (pluginOptions)=>({
158
+ name: '@modern-js/plugin-module-federation-ssr',
159
+ pre: [
160
+ '@modern-js/plugin-module-federation-config',
161
+ '@modern-js/plugin-module-federation'
258
162
  ],
259
- tools: {
260
- devServer: {
261
- before: [
262
- (req, res, next) => {
263
- if (!enableSSR) {
264
- next();
265
- return;
163
+ setup: async (api)=>{
164
+ var _pluginOptions_userConfig, _modernjsConfig_server;
165
+ const modernjsConfig = api.getConfig();
166
+ var _ref;
167
+ const enableSSR = null != (_ref = null == (_pluginOptions_userConfig = pluginOptions.userConfig) ? void 0 : _pluginOptions_userConfig.ssr) ? _ref : Boolean(null == modernjsConfig ? void 0 : null == (_modernjsConfig_server = modernjsConfig.server) ? void 0 : _modernjsConfig_server.ssr);
168
+ if (!enableSSR) return;
169
+ setEnv();
170
+ api._internalRuntimePlugins(({ entrypoint, plugins })=>{
171
+ const { fetchServerQuery } = pluginOptions;
172
+ plugins.push({
173
+ name: 'injectDataFetchFunction',
174
+ path: '@module-federation/modern-js/ssr-inject-data-fetch-function-plugin',
175
+ config: {
176
+ fetchServerQuery
177
+ }
178
+ });
179
+ if (!(0, external_utils_js_namespaceObject.isDev)()) return {
180
+ entrypoint,
181
+ plugins
182
+ };
183
+ plugins.push({
184
+ name: 'mfSSRDev',
185
+ path: '@module-federation/modern-js/ssr-dev-plugin',
186
+ config: {}
187
+ });
188
+ return {
189
+ entrypoint,
190
+ plugins
191
+ };
192
+ });
193
+ if (pluginOptions.ssrConfig.remotes) api._internalServerPlugins(({ plugins })=>{
194
+ plugins.push({
195
+ name: '@module-federation/modern-js/data-fetch-server-plugin',
196
+ options: {}
197
+ });
198
+ return {
199
+ plugins
200
+ };
201
+ });
202
+ api.modifyBundlerChain((chain)=>{
203
+ const target = chain.get('target');
204
+ if ((0, external_utils_js_namespaceObject.skipByTarget)(target)) return;
205
+ const bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
206
+ const MFPlugin = 'webpack' === bundlerType ? webpack_namespaceObject.ModuleFederationPlugin : rspack_namespaceObject.ModuleFederationPlugin;
207
+ const isWeb = (0, external_utils_js_namespaceObject.isWebTarget)(target);
208
+ if (!isWeb) {
209
+ if (!chain.plugins.has(CHAIN_MF_PLUGIN_ID)) chain.plugin(CHAIN_MF_PLUGIN_ID).use(MFPlugin, [
210
+ pluginOptions.ssrConfig
211
+ ]).init((Plugin, args)=>{
212
+ pluginOptions.nodePlugin = new Plugin(args[0]);
213
+ return pluginOptions.nodePlugin;
214
+ });
215
+ }
216
+ if (!isWeb) {
217
+ chain.target('async-node');
218
+ if ((0, external_utils_js_namespaceObject.isDev)()) chain.plugin('UniverseEntryChunkTrackerPlugin').use(universe_entry_chunk_tracker_plugin_default());
266
219
  }
220
+ if ((0, external_utils_js_namespaceObject.isDev)() && isWeb) chain.externals({
221
+ '@module-federation/node/utils': 'NOT_USED_IN_BROWSER'
222
+ });
223
+ });
224
+ api.config(()=>({
225
+ builderPlugins: [
226
+ mfSSRRsbuildPlugin(pluginOptions)
227
+ ],
228
+ tools: {
229
+ devServer: {
230
+ before: [
231
+ (req, res, next)=>{
232
+ if (!enableSSR) return void next();
233
+ try {
234
+ var _req_url, _req_url1;
235
+ if ((null == (_req_url = req.url) ? void 0 : _req_url.includes('.json')) && !(null == (_req_url1 = req.url) ? void 0 : _req_url1.includes('hot-update'))) {
236
+ const filepath = external_path_default().join(process.cwd(), `dist${req.url}`);
237
+ external_fs_extra_default().statSync(filepath);
238
+ res.setHeader('Access-Control-Allow-Origin', '*');
239
+ res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');
240
+ res.setHeader('Access-Control-Allow-Headers', '*');
241
+ external_fs_extra_default().createReadStream(filepath).pipe(res);
242
+ } else next();
243
+ } catch (err) {
244
+ external_logger_js_default().debug(err);
245
+ next();
246
+ }
247
+ }
248
+ ]
249
+ }
250
+ }
251
+ }));
252
+ const writeMergedManifest = ()=>{
253
+ const { distOutputDir, assetResources } = pluginOptions;
254
+ const browserAssets = assetResources.browser;
255
+ const nodeAssets = assetResources.node;
256
+ if (!distOutputDir || !browserAssets || !nodeAssets) return;
267
257
  try {
268
- var _req_url, _req_url1;
269
- if (((_req_url = req.url) === null || _req_url === void 0 ? void 0 : _req_url.includes(".json")) && !((_req_url1 = req.url) === null || _req_url1 === void 0 ? void 0 : _req_url1.includes("hot-update"))) {
270
- const filepath = import_path.default.join(process.cwd(), `dist${req.url}`);
271
- import_fs_extra.default.statSync(filepath);
272
- res.setHeader("Access-Control-Allow-Origin", "*");
273
- res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH, OPTIONS");
274
- res.setHeader("Access-Control-Allow-Headers", "*");
275
- import_fs_extra.default.createReadStream(filepath).pipe(res);
276
- } else {
277
- next();
278
- }
258
+ (0, utils_namespaceObject.updateStatsAndManifest)(nodeAssets, browserAssets, distOutputDir);
279
259
  } catch (err) {
280
- import_logger.default.debug(err);
281
- next();
260
+ external_logger_js_default().error(err);
282
261
  }
283
- }
284
- ]
285
- }
262
+ };
263
+ api.onAfterBuild(()=>{
264
+ writeMergedManifest();
265
+ });
266
+ api.onDevCompileDone(()=>{
267
+ writeMergedManifest();
268
+ });
286
269
  }
287
- };
288
270
  });
289
- const writeMergedManifest = () => {
290
- const { distOutputDir, assetResources } = pluginOptions;
291
- const browserAssets = assetResources.browser;
292
- const nodeAssets = assetResources.node;
293
- if (!distOutputDir || !browserAssets || !nodeAssets) {
294
- return;
295
- }
296
- try {
297
- (0, import_utils2.updateStatsAndManifest)(nodeAssets, browserAssets, distOutputDir);
298
- } catch (err) {
299
- import_logger.default.error(err);
300
- }
301
- };
302
- api.onAfterBuild(() => {
303
- writeMergedManifest();
304
- });
305
- api.onDevCompileDone(() => {
306
- writeMergedManifest();
307
- });
308
- }
309
- });
310
- var ssrPlugin_default = moduleFederationSSRPlugin;
311
- // Annotate the CommonJS export names for ESM import in node:
312
- 0 && (module.exports = {
313
- CHAIN_MF_PLUGIN_ID,
314
- moduleFederationSSRPlugin,
315
- setEnv
271
+ const ssrPlugin = moduleFederationSSRPlugin;
272
+ exports.CHAIN_MF_PLUGIN_ID = __webpack_exports__.CHAIN_MF_PLUGIN_ID;
273
+ exports["default"] = __webpack_exports__["default"];
274
+ exports.moduleFederationSSRPlugin = __webpack_exports__.moduleFederationSSRPlugin;
275
+ exports.setEnv = __webpack_exports__.setEnv;
276
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
277
+ "CHAIN_MF_PLUGIN_ID",
278
+ "default",
279
+ "moduleFederationSSRPlugin",
280
+ "setEnv"
281
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
282
+ Object.defineProperty(exports, '__esModule', {
283
+ value: true
316
284
  });