@module-federation/modern-js 0.0.0-next-20250926024003 → 0.0.0-refactor-manifest-20251013103938
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.
- package/dist/cjs/cli/configPlugin.js +8 -2
- package/dist/cjs/cli/index.js +1 -0
- package/dist/cjs/cli/ssrPlugin.js +85 -5
- package/dist/esm/cli/configPlugin.js +8 -2
- package/dist/esm/cli/index.js +1 -0
- package/dist/esm/cli/ssrPlugin.js +92 -6
- package/dist/esm-node/cli/configPlugin.js +8 -2
- package/dist/esm-node/cli/index.js +1 -0
- package/dist/esm-node/cli/ssrPlugin.js +85 -5
- package/dist/types/types/index.d.ts +5 -0
- package/package.json +9 -9
|
@@ -51,7 +51,6 @@ var import_utils3 = require("./utils");
|
|
|
51
51
|
const defaultPath = import_path.default.resolve(process.cwd(), "module-federation.config.ts");
|
|
52
52
|
function setEnv(enableSSR) {
|
|
53
53
|
if (enableSSR) {
|
|
54
|
-
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
55
54
|
process.env["MF_SSR_PRJ"] = "true";
|
|
56
55
|
}
|
|
57
56
|
}
|
|
@@ -66,7 +65,14 @@ const getMFConfig = async (userConfig) => {
|
|
|
66
65
|
return mfConfig;
|
|
67
66
|
};
|
|
68
67
|
const injectRuntimePlugins = (runtimePlugin, runtimePlugins) => {
|
|
69
|
-
|
|
68
|
+
const pluginName = typeof runtimePlugin === "string" ? runtimePlugin : runtimePlugin[0];
|
|
69
|
+
const hasPlugin = runtimePlugins.some((existingPlugin) => {
|
|
70
|
+
if (typeof existingPlugin === "string") {
|
|
71
|
+
return existingPlugin === pluginName;
|
|
72
|
+
}
|
|
73
|
+
return existingPlugin[0] === pluginName;
|
|
74
|
+
});
|
|
75
|
+
if (!hasPlugin) {
|
|
70
76
|
runtimePlugins.push(runtimePlugin);
|
|
71
77
|
}
|
|
72
78
|
};
|
package/dist/cjs/cli/index.js
CHANGED
|
@@ -36,6 +36,7 @@ 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,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_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 = getManifestAssetFileNames((_pluginOptions_csrConfig = pluginOptions.csrConfig) === null || _pluginOptions_csrConfig === void 0 ? void 0 : _pluginOptions_csrConfig.manifest);
|
|
86
|
+
const nodeAssetFileNames = 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
|
-
|
|
222
|
-
(0, import_utils2.updateStatsAndManifest)(nodePlugin, browserPlugin, distOutputDir);
|
|
303
|
+
writeMergedManifest();
|
|
223
304
|
});
|
|
224
305
|
api.onDevCompileDone(() => {
|
|
225
|
-
|
|
226
|
-
(0, import_utils2.updateStatsAndManifest)(nodePlugin, browserPlugin, distOutputDir);
|
|
306
|
+
writeMergedManifest();
|
|
227
307
|
});
|
|
228
308
|
}
|
|
229
309
|
});
|
|
@@ -16,7 +16,6 @@ import { isDev } from "./utils";
|
|
|
16
16
|
var defaultPath = path.resolve(process.cwd(), "module-federation.config.ts");
|
|
17
17
|
function setEnv(enableSSR) {
|
|
18
18
|
if (enableSSR) {
|
|
19
|
-
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
20
19
|
process.env["MF_SSR_PRJ"] = "true";
|
|
21
20
|
}
|
|
22
21
|
}
|
|
@@ -58,7 +57,14 @@ var getMFConfig = function() {
|
|
|
58
57
|
};
|
|
59
58
|
}();
|
|
60
59
|
var injectRuntimePlugins = function(runtimePlugin, runtimePlugins) {
|
|
61
|
-
|
|
60
|
+
var pluginName = typeof runtimePlugin === "string" ? runtimePlugin : runtimePlugin[0];
|
|
61
|
+
var hasPlugin = runtimePlugins.some(function(existingPlugin) {
|
|
62
|
+
if (typeof existingPlugin === "string") {
|
|
63
|
+
return existingPlugin === pluginName;
|
|
64
|
+
}
|
|
65
|
+
return existingPlugin[0] === pluginName;
|
|
66
|
+
});
|
|
67
|
+
if (!hasPlugin) {
|
|
62
68
|
runtimePlugins.push(runtimePlugin);
|
|
63
69
|
}
|
|
64
70
|
};
|
package/dist/esm/cli/index.js
CHANGED
|
@@ -14,6 +14,7 @@ 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,
|
|
@@ -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_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 = getManifestAssetFileNames((_pluginOptions_csrConfig = pluginOptions.csrConfig) === null || _pluginOptions_csrConfig === void 0 ? void 0 : _pluginOptions_csrConfig.manifest);
|
|
58
|
+
var nodeAssetFileNames = 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
|
-
|
|
196
|
-
updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir);
|
|
283
|
+
writeMergedManifest();
|
|
197
284
|
});
|
|
198
285
|
api.onDevCompileDone(function() {
|
|
199
|
-
|
|
200
|
-
updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir);
|
|
286
|
+
writeMergedManifest();
|
|
201
287
|
});
|
|
202
288
|
return [
|
|
203
289
|
2
|
|
@@ -10,7 +10,6 @@ import { isDev } from "./utils";
|
|
|
10
10
|
const defaultPath = path.resolve(process.cwd(), "module-federation.config.ts");
|
|
11
11
|
function setEnv(enableSSR) {
|
|
12
12
|
if (enableSSR) {
|
|
13
|
-
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
14
13
|
process.env["MF_SSR_PRJ"] = "true";
|
|
15
14
|
}
|
|
16
15
|
}
|
|
@@ -25,7 +24,14 @@ const getMFConfig = async (userConfig) => {
|
|
|
25
24
|
return mfConfig;
|
|
26
25
|
};
|
|
27
26
|
const injectRuntimePlugins = (runtimePlugin, runtimePlugins) => {
|
|
28
|
-
|
|
27
|
+
const pluginName = typeof runtimePlugin === "string" ? runtimePlugin : runtimePlugin[0];
|
|
28
|
+
const hasPlugin = runtimePlugins.some((existingPlugin) => {
|
|
29
|
+
if (typeof existingPlugin === "string") {
|
|
30
|
+
return existingPlugin === pluginName;
|
|
31
|
+
}
|
|
32
|
+
return existingPlugin[0] === pluginName;
|
|
33
|
+
});
|
|
34
|
+
if (!hasPlugin) {
|
|
29
35
|
runtimePlugins.push(runtimePlugin);
|
|
30
36
|
}
|
|
31
37
|
};
|
|
@@ -10,6 +10,7 @@ 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,
|
|
@@ -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_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 = getManifestAssetFileNames((_pluginOptions_csrConfig = pluginOptions.csrConfig) === null || _pluginOptions_csrConfig === void 0 ? void 0 : _pluginOptions_csrConfig.manifest);
|
|
50
|
+
const nodeAssetFileNames = 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
|
-
|
|
186
|
-
updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir);
|
|
267
|
+
writeMergedManifest();
|
|
187
268
|
});
|
|
188
269
|
api.onDevCompileDone(() => {
|
|
189
|
-
|
|
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;
|
|
@@ -15,6 +16,10 @@ export interface InternalModernPluginOptions {
|
|
|
15
16
|
originPluginOptions: PluginOptions;
|
|
16
17
|
browserPlugin?: BundlerPlugin;
|
|
17
18
|
nodePlugin?: BundlerPlugin;
|
|
19
|
+
assetResources: {
|
|
20
|
+
browser?: StatsAssetResource;
|
|
21
|
+
node?: StatsAssetResource;
|
|
22
|
+
};
|
|
18
23
|
remoteIpStrategy?: 'ipv4' | 'inherit';
|
|
19
24
|
userConfig?: PluginOptions;
|
|
20
25
|
fetchServerQuery?: Record<string, unknown>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/modern-js",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-refactor-manifest-20251013103938",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist/",
|
|
6
6
|
"types.d.ts",
|
|
@@ -119,13 +119,13 @@
|
|
|
119
119
|
"@swc/helpers": "^0.5.17",
|
|
120
120
|
"node-fetch": "~3.3.0",
|
|
121
121
|
"react-error-boundary": "4.1.2",
|
|
122
|
-
"@module-federation/
|
|
123
|
-
"@module-federation/
|
|
124
|
-
"@module-federation/
|
|
125
|
-
"@module-federation/
|
|
126
|
-
"@module-federation/
|
|
127
|
-
"@module-federation/cli": "0.0.0-
|
|
128
|
-
"@module-federation/
|
|
122
|
+
"@module-federation/enhanced": "0.0.0-refactor-manifest-20251013103938",
|
|
123
|
+
"@module-federation/rsbuild-plugin": "0.0.0-refactor-manifest-20251013103938",
|
|
124
|
+
"@module-federation/node": "0.0.0-refactor-manifest-20251013103938",
|
|
125
|
+
"@module-federation/bridge-react": "0.0.0-refactor-manifest-20251013103938",
|
|
126
|
+
"@module-federation/runtime": "0.0.0-refactor-manifest-20251013103938",
|
|
127
|
+
"@module-federation/cli": "0.0.0-refactor-manifest-20251013103938",
|
|
128
|
+
"@module-federation/sdk": "0.0.0-refactor-manifest-20251013103938"
|
|
129
129
|
},
|
|
130
130
|
"devDependencies": {
|
|
131
131
|
"@modern-js/core": "2.68.2",
|
|
@@ -137,7 +137,7 @@
|
|
|
137
137
|
"@modern-js/tsconfig": "2.68.2",
|
|
138
138
|
"@types/react": "^18.3.11",
|
|
139
139
|
"@types/react-dom": "^18.3.0",
|
|
140
|
-
"@module-federation/manifest": "0.0.0-
|
|
140
|
+
"@module-federation/manifest": "0.0.0-refactor-manifest-20251013103938"
|
|
141
141
|
},
|
|
142
142
|
"peerDependencies": {
|
|
143
143
|
"react": ">=17",
|