@module-federation/modern-js 0.21.3 → 0.21.5

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.
@@ -50,7 +50,6 @@ var import_utils3 = require("./utils");
50
50
  const defaultPath = import_path.default.resolve(process.cwd(), "module-federation.config.ts");
51
51
  function setEnv(enableSSR) {
52
52
  if (enableSSR) {
53
- process.env["MF_DISABLE_EMIT_STATS"] = "true";
54
53
  process.env["MF_SSR_PRJ"] = "true";
55
54
  }
56
55
  }
@@ -36,10 +36,12 @@ const moduleFederationPlugin = (userConfig = {}) => {
36
36
  ssrConfig: void 0,
37
37
  browserPlugin: void 0,
38
38
  nodePlugin: void 0,
39
+ assetResources: {},
39
40
  distOutputDir: "",
40
41
  originPluginOptions: userConfig,
41
42
  remoteIpStrategy: userConfig === null || userConfig === void 0 ? void 0 : userConfig.remoteIpStrategy,
42
43
  userConfig: userConfig || {},
44
+ assetFileNames: {},
43
45
  fetchServerQuery: (_userConfig_fetchServerQuery = userConfig.fetchServerQuery) !== null && _userConfig_fetchServerQuery !== void 0 ? _userConfig_fetchServerQuery : void 0
44
46
  };
45
47
  return {
@@ -42,12 +42,31 @@ var import_universe_entry_chunk_tracker_plugin = __toESM(require("@module-federa
42
42
  var import_logger = __toESM(require("../logger"));
43
43
  var import_utils = require("./utils");
44
44
  var import_utils2 = require("@module-federation/rsbuild-plugin/utils");
45
+ var import_sdk = require("@module-federation/sdk");
45
46
  var import_utils3 = require("./utils");
46
47
  function setEnv() {
47
- process.env["MF_DISABLE_EMIT_STATS"] = "true";
48
48
  process.env["MF_SSR_PRJ"] = "true";
49
49
  }
50
50
  const CHAIN_MF_PLUGIN_ID = "plugin-module-federation-server";
51
+ function getManifestAssetFileNames(manifestOption) {
52
+ if (!manifestOption) {
53
+ return {
54
+ statsFileName: import_sdk.StatsFileName,
55
+ manifestFileName: import_sdk.ManifestFileName
56
+ };
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
+ }
51
70
  const mfSSRRsbuildPlugin = (pluginOptions) => {
52
71
  return {
53
72
  name: "@modern-js/plugin-mf-post-config",
@@ -55,12 +74,43 @@ const mfSSRRsbuildPlugin = (pluginOptions) => {
55
74
  "@modern-js/builder-plugin-ssr"
56
75
  ],
57
76
  setup(api) {
77
+ var _pluginOptions_csrConfig, _pluginOptions_assetFileNames, _pluginOptions_ssrConfig;
58
78
  if (pluginOptions.csrConfig.getPublicPath) {
59
79
  return;
60
80
  }
61
81
  let csrOutputPath = "";
62
82
  let ssrOutputPath = "";
63
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
+ };
64
114
  api.modifyEnvironmentConfig((config, { name }) => {
65
115
  const target = config.output.target;
66
116
  if ((0, import_utils3.skipByTarget)(target)) {
@@ -68,6 +118,7 @@ const mfSSRRsbuildPlugin = (pluginOptions) => {
68
118
  }
69
119
  if ((0, import_utils3.isWebTarget)(target)) {
70
120
  csrOutputPath = config.output.distPath.root;
121
+ csrEnv = name;
71
122
  } else {
72
123
  ssrOutputPath = config.output.distPath.root;
73
124
  ssrEnv = name;
@@ -93,6 +144,24 @@ const mfSSRRsbuildPlugin = (pluginOptions) => {
93
144
  modifySSRPublicPath(config, utils);
94
145
  return config;
95
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
+ });
96
165
  }
97
166
  };
98
167
  };
@@ -217,13 +286,24 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
217
286
  }
218
287
  };
219
288
  });
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
+ };
220
302
  api.onAfterBuild(() => {
221
- const { nodePlugin, browserPlugin, distOutputDir } = pluginOptions;
222
- (0, import_utils2.updateStatsAndManifest)(nodePlugin, browserPlugin, distOutputDir);
303
+ writeMergedManifest();
223
304
  });
224
305
  api.onDevCompileDone(() => {
225
- const { nodePlugin, browserPlugin, distOutputDir } = pluginOptions;
226
- (0, import_utils2.updateStatsAndManifest)(nodePlugin, browserPlugin, distOutputDir);
306
+ writeMergedManifest();
227
307
  });
228
308
  }
229
309
  });
@@ -15,7 +15,6 @@ import { isDev } from "./utils";
15
15
  var defaultPath = path.resolve(process.cwd(), "module-federation.config.ts");
16
16
  function setEnv(enableSSR) {
17
17
  if (enableSSR) {
18
- process.env["MF_DISABLE_EMIT_STATS"] = "true";
19
18
  process.env["MF_SSR_PRJ"] = "true";
20
19
  }
21
20
  }
@@ -14,10 +14,12 @@ var moduleFederationPlugin = function() {
14
14
  ssrConfig: void 0,
15
15
  browserPlugin: void 0,
16
16
  nodePlugin: void 0,
17
+ assetResources: {},
17
18
  distOutputDir: "",
18
19
  originPluginOptions: userConfig,
19
20
  remoteIpStrategy: userConfig === null || userConfig === void 0 ? void 0 : userConfig.remoteIpStrategy,
20
21
  userConfig: userConfig || {},
22
+ assetFileNames: {},
21
23
  fetchServerQuery: (_userConfig_fetchServerQuery = userConfig.fetchServerQuery) !== null && _userConfig_fetchServerQuery !== void 0 ? _userConfig_fetchServerQuery : void 0
22
24
  };
23
25
  return {
@@ -1,4 +1,5 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
2
3
  import { _ as _type_of } from "@swc/helpers/_/_type_of";
3
4
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
5
  import path from "path";
@@ -9,12 +10,35 @@ import UniverseEntryChunkTrackerPlugin from "@module-federation/node/universe-en
9
10
  import logger from "../logger";
10
11
  import { isDev } from "./utils";
11
12
  import { updateStatsAndManifest } from "@module-federation/rsbuild-plugin/utils";
13
+ import { ManifestFileName, StatsFileName, simpleJoinRemoteEntry } from "@module-federation/sdk";
12
14
  import { isWebTarget, skipByTarget } from "./utils";
13
15
  function setEnv() {
14
- process.env["MF_DISABLE_EMIT_STATS"] = "true";
15
16
  process.env["MF_SSR_PRJ"] = "true";
16
17
  }
17
18
  var CHAIN_MF_PLUGIN_ID = "plugin-module-federation-server";
19
+ function getManifestAssetFileNames(manifestOption) {
20
+ if (!manifestOption) {
21
+ return {
22
+ statsFileName: StatsFileName,
23
+ manifestFileName: ManifestFileName
24
+ };
25
+ }
26
+ var JSON_EXT = ".json";
27
+ var filePath = typeof manifestOption === "boolean" ? "" : manifestOption.filePath || "";
28
+ var baseFileName = typeof manifestOption === "boolean" ? "" : manifestOption.fileName || "";
29
+ var ensureExt = function(name) {
30
+ return name.endsWith(JSON_EXT) ? name : "".concat(name).concat(JSON_EXT);
31
+ };
32
+ var withSuffix = function(name, suffix) {
33
+ return name.replace(JSON_EXT, "".concat(suffix).concat(JSON_EXT));
34
+ };
35
+ var manifestFileName = baseFileName ? ensureExt(baseFileName) : ManifestFileName;
36
+ var statsFileName = baseFileName ? withSuffix(manifestFileName, "-stats") : StatsFileName;
37
+ return {
38
+ statsFileName: simpleJoinRemoteEntry(filePath, statsFileName),
39
+ manifestFileName: simpleJoinRemoteEntry(filePath, manifestFileName)
40
+ };
41
+ }
18
42
  var mfSSRRsbuildPlugin = function(pluginOptions) {
19
43
  return {
20
44
  name: "@modern-js/plugin-mf-post-config",
@@ -22,12 +46,43 @@ var mfSSRRsbuildPlugin = function(pluginOptions) {
22
46
  "@modern-js/builder-plugin-ssr"
23
47
  ],
24
48
  setup: function setup(api) {
49
+ var _pluginOptions_csrConfig, _pluginOptions_assetFileNames, _pluginOptions_ssrConfig;
25
50
  if (pluginOptions.csrConfig.getPublicPath) {
26
51
  return;
27
52
  }
28
53
  var csrOutputPath = "";
29
54
  var ssrOutputPath = "";
30
55
  var ssrEnv = "";
56
+ var csrEnv = "";
57
+ var browserAssetFileNames = pluginOptions.assetFileNames.browser || getManifestAssetFileNames((_pluginOptions_csrConfig = pluginOptions.csrConfig) === null || _pluginOptions_csrConfig === void 0 ? void 0 : _pluginOptions_csrConfig.manifest);
58
+ var 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);
59
+ var collectAssets = function(assets, fileNames, tag) {
60
+ var statsAsset = assets[fileNames.statsFileName];
61
+ var manifestAsset = assets[fileNames.manifestFileName];
62
+ if (!statsAsset || !manifestAsset) {
63
+ return void 0;
64
+ }
65
+ try {
66
+ var statsRaw = statsAsset.source();
67
+ var manifestRaw = manifestAsset.source();
68
+ var statsContent = typeof statsRaw === "string" ? statsRaw : statsRaw.toString();
69
+ var manifestContent = typeof manifestRaw === "string" ? manifestRaw : manifestRaw.toString();
70
+ return {
71
+ stats: {
72
+ data: JSON.parse(statsContent),
73
+ filename: fileNames.statsFileName
74
+ },
75
+ manifest: {
76
+ data: JSON.parse(manifestContent),
77
+ filename: fileNames.manifestFileName
78
+ }
79
+ };
80
+ } catch (err) {
81
+ var message = _instanceof(err, Error) ? err.message : String(err);
82
+ logger.error("Failed to parse ".concat(tag, " manifest assets: ").concat(message));
83
+ return void 0;
84
+ }
85
+ };
31
86
  api.modifyEnvironmentConfig(function(config, param) {
32
87
  var name = param.name;
33
88
  var target = config.output.target;
@@ -36,6 +91,7 @@ var mfSSRRsbuildPlugin = function(pluginOptions) {
36
91
  }
37
92
  if (isWebTarget(target)) {
38
93
  csrOutputPath = config.output.distPath.root;
94
+ csrEnv = name;
39
95
  } else {
40
96
  ssrOutputPath = config.output.distPath.root;
41
97
  ssrEnv = name;
@@ -61,6 +117,25 @@ var mfSSRRsbuildPlugin = function(pluginOptions) {
61
117
  modifySSRPublicPath(config, utils);
62
118
  return config;
63
119
  });
120
+ api.processAssets({
121
+ stage: "report"
122
+ }, function(param) {
123
+ var assets = param.assets, envContext = param.environment;
124
+ var _pluginOptions_csrConfig2, _pluginOptions_ssrConfig2;
125
+ var envName = envContext.name;
126
+ if (((_pluginOptions_csrConfig2 = pluginOptions.csrConfig) === null || _pluginOptions_csrConfig2 === void 0 ? void 0 : _pluginOptions_csrConfig2.manifest) !== false && csrEnv && envName === csrEnv) {
127
+ var browserAssets = collectAssets(assets, browserAssetFileNames, "browser");
128
+ if (browserAssets) {
129
+ pluginOptions.assetResources.browser = browserAssets;
130
+ }
131
+ }
132
+ if (((_pluginOptions_ssrConfig2 = pluginOptions.ssrConfig) === null || _pluginOptions_ssrConfig2 === void 0 ? void 0 : _pluginOptions_ssrConfig2.manifest) !== false && ssrEnv && envName === ssrEnv) {
133
+ var nodeAssets = collectAssets(assets, nodeAssetFileNames, "node");
134
+ if (nodeAssets) {
135
+ pluginOptions.assetResources.node = nodeAssets;
136
+ }
137
+ }
138
+ });
64
139
  }
65
140
  };
66
141
  };
@@ -73,7 +148,7 @@ var moduleFederationSSRPlugin = function(pluginOptions) {
73
148
  ],
74
149
  setup: function() {
75
150
  var _ref = _async_to_generator(function(api) {
76
- var _pluginOptions_userConfig, _modernjsConfig_server, modernjsConfig, _pluginOptions_userConfig_ssr, enableSSR;
151
+ var _pluginOptions_userConfig, _modernjsConfig_server, modernjsConfig, _pluginOptions_userConfig_ssr, enableSSR, writeMergedManifest;
77
152
  return _ts_generator(this, function(_state) {
78
153
  modernjsConfig = api.getConfig();
79
154
  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);
@@ -191,13 +266,24 @@ var moduleFederationSSRPlugin = function(pluginOptions) {
191
266
  }
192
267
  };
193
268
  });
269
+ writeMergedManifest = function() {
270
+ var distOutputDir = pluginOptions.distOutputDir, assetResources = pluginOptions.assetResources;
271
+ var browserAssets = assetResources.browser;
272
+ var nodeAssets = assetResources.node;
273
+ if (!distOutputDir || !browserAssets || !nodeAssets) {
274
+ return;
275
+ }
276
+ try {
277
+ updateStatsAndManifest(nodeAssets, browserAssets, distOutputDir);
278
+ } catch (err) {
279
+ logger.error(err);
280
+ }
281
+ };
194
282
  api.onAfterBuild(function() {
195
- var nodePlugin = pluginOptions.nodePlugin, browserPlugin = pluginOptions.browserPlugin, distOutputDir = pluginOptions.distOutputDir;
196
- updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir);
283
+ writeMergedManifest();
197
284
  });
198
285
  api.onDevCompileDone(function() {
199
- var nodePlugin = pluginOptions.nodePlugin, browserPlugin = pluginOptions.browserPlugin, distOutputDir = pluginOptions.distOutputDir;
200
- updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir);
286
+ writeMergedManifest();
201
287
  });
202
288
  return [
203
289
  2
@@ -9,7 +9,6 @@ import { isDev } from "./utils";
9
9
  const defaultPath = path.resolve(process.cwd(), "module-federation.config.ts");
10
10
  function setEnv(enableSSR) {
11
11
  if (enableSSR) {
12
- process.env["MF_DISABLE_EMIT_STATS"] = "true";
13
12
  process.env["MF_SSR_PRJ"] = "true";
14
13
  }
15
14
  }
@@ -10,10 +10,12 @@ const moduleFederationPlugin = (userConfig = {}) => {
10
10
  ssrConfig: void 0,
11
11
  browserPlugin: void 0,
12
12
  nodePlugin: void 0,
13
+ assetResources: {},
13
14
  distOutputDir: "",
14
15
  originPluginOptions: userConfig,
15
16
  remoteIpStrategy: userConfig === null || userConfig === void 0 ? void 0 : userConfig.remoteIpStrategy,
16
17
  userConfig: userConfig || {},
18
+ assetFileNames: {},
17
19
  fetchServerQuery: (_userConfig_fetchServerQuery = userConfig.fetchServerQuery) !== null && _userConfig_fetchServerQuery !== void 0 ? _userConfig_fetchServerQuery : void 0
18
20
  };
19
21
  return {
@@ -6,12 +6,31 @@ import UniverseEntryChunkTrackerPlugin from "@module-federation/node/universe-en
6
6
  import logger from "../logger";
7
7
  import { isDev } from "./utils";
8
8
  import { updateStatsAndManifest } from "@module-federation/rsbuild-plugin/utils";
9
+ import { ManifestFileName, StatsFileName, simpleJoinRemoteEntry } from "@module-federation/sdk";
9
10
  import { isWebTarget, skipByTarget } from "./utils";
10
11
  function setEnv() {
11
- process.env["MF_DISABLE_EMIT_STATS"] = "true";
12
12
  process.env["MF_SSR_PRJ"] = "true";
13
13
  }
14
14
  const CHAIN_MF_PLUGIN_ID = "plugin-module-federation-server";
15
+ function getManifestAssetFileNames(manifestOption) {
16
+ if (!manifestOption) {
17
+ return {
18
+ statsFileName: StatsFileName,
19
+ manifestFileName: ManifestFileName
20
+ };
21
+ }
22
+ const JSON_EXT = ".json";
23
+ const filePath = typeof manifestOption === "boolean" ? "" : manifestOption.filePath || "";
24
+ const baseFileName = typeof manifestOption === "boolean" ? "" : manifestOption.fileName || "";
25
+ const ensureExt = (name) => name.endsWith(JSON_EXT) ? name : `${name}${JSON_EXT}`;
26
+ const withSuffix = (name, suffix) => name.replace(JSON_EXT, `${suffix}${JSON_EXT}`);
27
+ const manifestFileName = baseFileName ? ensureExt(baseFileName) : ManifestFileName;
28
+ const statsFileName = baseFileName ? withSuffix(manifestFileName, "-stats") : StatsFileName;
29
+ return {
30
+ statsFileName: simpleJoinRemoteEntry(filePath, statsFileName),
31
+ manifestFileName: simpleJoinRemoteEntry(filePath, manifestFileName)
32
+ };
33
+ }
15
34
  const mfSSRRsbuildPlugin = (pluginOptions) => {
16
35
  return {
17
36
  name: "@modern-js/plugin-mf-post-config",
@@ -19,12 +38,43 @@ const mfSSRRsbuildPlugin = (pluginOptions) => {
19
38
  "@modern-js/builder-plugin-ssr"
20
39
  ],
21
40
  setup(api) {
41
+ var _pluginOptions_csrConfig, _pluginOptions_assetFileNames, _pluginOptions_ssrConfig;
22
42
  if (pluginOptions.csrConfig.getPublicPath) {
23
43
  return;
24
44
  }
25
45
  let csrOutputPath = "";
26
46
  let ssrOutputPath = "";
27
47
  let ssrEnv = "";
48
+ let csrEnv = "";
49
+ const browserAssetFileNames = pluginOptions.assetFileNames.browser || getManifestAssetFileNames((_pluginOptions_csrConfig = pluginOptions.csrConfig) === null || _pluginOptions_csrConfig === void 0 ? void 0 : _pluginOptions_csrConfig.manifest);
50
+ 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);
51
+ const collectAssets = (assets, fileNames, tag) => {
52
+ const statsAsset = assets[fileNames.statsFileName];
53
+ const manifestAsset = assets[fileNames.manifestFileName];
54
+ if (!statsAsset || !manifestAsset) {
55
+ return void 0;
56
+ }
57
+ try {
58
+ const statsRaw = statsAsset.source();
59
+ const manifestRaw = manifestAsset.source();
60
+ const statsContent = typeof statsRaw === "string" ? statsRaw : statsRaw.toString();
61
+ const manifestContent = typeof manifestRaw === "string" ? manifestRaw : manifestRaw.toString();
62
+ return {
63
+ stats: {
64
+ data: JSON.parse(statsContent),
65
+ filename: fileNames.statsFileName
66
+ },
67
+ manifest: {
68
+ data: JSON.parse(manifestContent),
69
+ filename: fileNames.manifestFileName
70
+ }
71
+ };
72
+ } catch (err) {
73
+ const message = err instanceof Error ? err.message : String(err);
74
+ logger.error(`Failed to parse ${tag} manifest assets: ${message}`);
75
+ return void 0;
76
+ }
77
+ };
28
78
  api.modifyEnvironmentConfig((config, { name }) => {
29
79
  const target = config.output.target;
30
80
  if (skipByTarget(target)) {
@@ -32,6 +82,7 @@ const mfSSRRsbuildPlugin = (pluginOptions) => {
32
82
  }
33
83
  if (isWebTarget(target)) {
34
84
  csrOutputPath = config.output.distPath.root;
85
+ csrEnv = name;
35
86
  } else {
36
87
  ssrOutputPath = config.output.distPath.root;
37
88
  ssrEnv = name;
@@ -57,6 +108,24 @@ const mfSSRRsbuildPlugin = (pluginOptions) => {
57
108
  modifySSRPublicPath(config, utils);
58
109
  return config;
59
110
  });
111
+ api.processAssets({
112
+ stage: "report"
113
+ }, ({ assets, environment: envContext }) => {
114
+ var _pluginOptions_csrConfig2, _pluginOptions_ssrConfig2;
115
+ const envName = envContext.name;
116
+ if (((_pluginOptions_csrConfig2 = pluginOptions.csrConfig) === null || _pluginOptions_csrConfig2 === void 0 ? void 0 : _pluginOptions_csrConfig2.manifest) !== false && csrEnv && envName === csrEnv) {
117
+ const browserAssets = collectAssets(assets, browserAssetFileNames, "browser");
118
+ if (browserAssets) {
119
+ pluginOptions.assetResources.browser = browserAssets;
120
+ }
121
+ }
122
+ if (((_pluginOptions_ssrConfig2 = pluginOptions.ssrConfig) === null || _pluginOptions_ssrConfig2 === void 0 ? void 0 : _pluginOptions_ssrConfig2.manifest) !== false && ssrEnv && envName === ssrEnv) {
123
+ const nodeAssets = collectAssets(assets, nodeAssetFileNames, "node");
124
+ if (nodeAssets) {
125
+ pluginOptions.assetResources.node = nodeAssets;
126
+ }
127
+ }
128
+ });
60
129
  }
61
130
  };
62
131
  };
@@ -181,13 +250,24 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
181
250
  }
182
251
  };
183
252
  });
253
+ const writeMergedManifest = () => {
254
+ const { distOutputDir, assetResources } = pluginOptions;
255
+ const browserAssets = assetResources.browser;
256
+ const nodeAssets = assetResources.node;
257
+ if (!distOutputDir || !browserAssets || !nodeAssets) {
258
+ return;
259
+ }
260
+ try {
261
+ updateStatsAndManifest(nodeAssets, browserAssets, distOutputDir);
262
+ } catch (err) {
263
+ logger.error(err);
264
+ }
265
+ };
184
266
  api.onAfterBuild(() => {
185
- const { nodePlugin, browserPlugin, distOutputDir } = pluginOptions;
186
- updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir);
267
+ writeMergedManifest();
187
268
  });
188
269
  api.onDevCompileDone(() => {
189
- const { nodePlugin, browserPlugin, distOutputDir } = pluginOptions;
190
- updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir);
270
+ writeMergedManifest();
191
271
  });
192
272
  }
193
273
  });
@@ -1,4 +1,5 @@
1
1
  import { moduleFederationPlugin } from '@module-federation/sdk';
2
+ import type { StatsAssetResource } from '@module-federation/rsbuild-plugin/utils';
2
3
  export interface PluginOptions {
3
4
  config?: moduleFederationPlugin.ModuleFederationPluginOptions;
4
5
  configPath?: string;
@@ -8,6 +9,10 @@ export interface PluginOptions {
8
9
  remoteIpStrategy?: 'ipv4' | 'inherit';
9
10
  fetchServerQuery?: Record<string, unknown>;
10
11
  }
12
+ export type AssetFileNames = {
13
+ statsFileName: string;
14
+ manifestFileName: string;
15
+ };
11
16
  export interface InternalModernPluginOptions {
12
17
  csrConfig?: moduleFederationPlugin.ModuleFederationPluginOptions;
13
18
  ssrConfig?: moduleFederationPlugin.ModuleFederationPluginOptions;
@@ -15,6 +20,14 @@ export interface InternalModernPluginOptions {
15
20
  originPluginOptions: PluginOptions;
16
21
  browserPlugin?: BundlerPlugin;
17
22
  nodePlugin?: BundlerPlugin;
23
+ assetFileNames: {
24
+ node?: AssetFileNames;
25
+ browser?: AssetFileNames;
26
+ };
27
+ assetResources: {
28
+ browser?: StatsAssetResource;
29
+ node?: StatsAssetResource;
30
+ };
18
31
  remoteIpStrategy?: 'ipv4' | 'inherit';
19
32
  userConfig?: PluginOptions;
20
33
  fetchServerQuery?: Record<string, unknown>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/modern-js",
3
- "version": "0.21.3",
3
+ "version": "0.21.5",
4
4
  "files": [
5
5
  "dist/",
6
6
  "types.d.ts",
@@ -140,13 +140,13 @@
140
140
  "@swc/helpers": "^0.5.17",
141
141
  "node-fetch": "~3.3.0",
142
142
  "react-error-boundary": "4.1.2",
143
- "@module-federation/rsbuild-plugin": "0.21.3",
144
- "@module-federation/bridge-react": "0.21.3",
145
- "@module-federation/enhanced": "0.21.3",
146
- "@module-federation/runtime": "0.21.3",
147
- "@module-federation/node": "2.7.22",
148
- "@module-federation/sdk": "0.21.3",
149
- "@module-federation/cli": "0.21.3"
143
+ "@module-federation/rsbuild-plugin": "0.21.5",
144
+ "@module-federation/enhanced": "0.21.5",
145
+ "@module-federation/bridge-react": "0.21.5",
146
+ "@module-federation/sdk": "0.21.5",
147
+ "@module-federation/node": "2.7.24",
148
+ "@module-federation/cli": "0.21.5",
149
+ "@module-federation/runtime": "0.21.5"
150
150
  },
151
151
  "devDependencies": {
152
152
  "@modern-js/core": "2.68.2",
@@ -158,7 +158,7 @@
158
158
  "@modern-js/tsconfig": "2.68.2",
159
159
  "@types/react": "^18.3.11",
160
160
  "@types/react-dom": "^18.3.0",
161
- "@module-federation/manifest": "0.21.3"
161
+ "@module-federation/manifest": "0.21.5"
162
162
  },
163
163
  "peerDependencies": {
164
164
  "react": ">=17",