@module-federation/modern-js 0.0.0-refactor-manifest-20251016072532 → 0.0.0-research-issue-4085-20251016232757
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 +1 -12
- package/dist/cjs/cli/index.js +0 -1
- package/dist/cjs/cli/ssrPlugin.js +5 -85
- package/dist/esm/cli/configPlugin.js +1 -12
- package/dist/esm/cli/index.js +0 -1
- package/dist/esm/cli/ssrPlugin.js +6 -92
- package/dist/esm-node/cli/configPlugin.js +1 -12
- package/dist/esm-node/cli/index.js +0 -1
- package/dist/esm-node/cli/ssrPlugin.js +5 -85
- package/dist/types/types/index.d.ts +0 -5
- package/package.json +9 -9
|
@@ -40,7 +40,6 @@ __export(configPlugin_exports, {
|
|
|
40
40
|
});
|
|
41
41
|
module.exports = __toCommonJS(configPlugin_exports);
|
|
42
42
|
var import_path = __toESM(require("path"));
|
|
43
|
-
var import_fs = __toESM(require("fs"));
|
|
44
43
|
var import_utils = require("./utils");
|
|
45
44
|
var import_sdk = require("@module-federation/sdk");
|
|
46
45
|
var import_node_bundle_require = require("@modern-js/node-bundle-require");
|
|
@@ -51,6 +50,7 @@ var import_utils3 = require("./utils");
|
|
|
51
50
|
const defaultPath = import_path.default.resolve(process.cwd(), "module-federation.config.ts");
|
|
52
51
|
function setEnv(enableSSR) {
|
|
53
52
|
if (enableSSR) {
|
|
53
|
+
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
54
54
|
process.env["MF_SSR_PRJ"] = "true";
|
|
55
55
|
}
|
|
56
56
|
}
|
|
@@ -153,17 +153,6 @@ const patchMFConfig = (mfConfig, isServer, remoteIpStrategy, enableSSR) => {
|
|
|
153
153
|
const runtimePlugins = [
|
|
154
154
|
...mfConfig.runtimePlugins || []
|
|
155
155
|
];
|
|
156
|
-
try {
|
|
157
|
-
const nodeModulesPath = import_path.default.resolve(process.cwd(), "node_modules");
|
|
158
|
-
const bridgeReactPath = import_path.default.join(nodeModulesPath, "@module-federation/bridge-react");
|
|
159
|
-
if (import_fs.default.existsSync(bridgeReactPath) && (!(mfConfig === null || mfConfig === void 0 ? void 0 : mfConfig.bridge) || !mfConfig.bridge.disableAlias)) {
|
|
160
|
-
mfConfig.bridge = {
|
|
161
|
-
disableAlias: true
|
|
162
|
-
};
|
|
163
|
-
import_logger.default.debug(`${import_constant.PLUGIN_IDENTIFIER} use "@module-federation/modern-js/react" instead of "@module-federation/bridge-react" !`);
|
|
164
|
-
}
|
|
165
|
-
} catch (e) {
|
|
166
|
-
}
|
|
167
156
|
patchDTSConfig(mfConfig, isServer);
|
|
168
157
|
injectRuntimePlugins(require.resolve("@module-federation/modern-js/shared-strategy"), runtimePlugins);
|
|
169
158
|
if (enableSSR && (0, import_utils3.isDev)()) {
|
package/dist/cjs/cli/index.js
CHANGED
|
@@ -36,7 +36,6 @@ const moduleFederationPlugin = (userConfig = {}) => {
|
|
|
36
36
|
ssrConfig: void 0,
|
|
37
37
|
browserPlugin: void 0,
|
|
38
38
|
nodePlugin: void 0,
|
|
39
|
-
assetResources: {},
|
|
40
39
|
distOutputDir: "",
|
|
41
40
|
originPluginOptions: userConfig,
|
|
42
41
|
remoteIpStrategy: userConfig === null || userConfig === void 0 ? void 0 : userConfig.remoteIpStrategy,
|
|
@@ -42,31 +42,12 @@ 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");
|
|
46
45
|
var import_utils3 = require("./utils");
|
|
47
46
|
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
|
-
}
|
|
70
51
|
const mfSSRRsbuildPlugin = (pluginOptions) => {
|
|
71
52
|
return {
|
|
72
53
|
name: "@modern-js/plugin-mf-post-config",
|
|
@@ -74,43 +55,12 @@ const mfSSRRsbuildPlugin = (pluginOptions) => {
|
|
|
74
55
|
"@modern-js/builder-plugin-ssr"
|
|
75
56
|
],
|
|
76
57
|
setup(api) {
|
|
77
|
-
var _pluginOptions_csrConfig, _pluginOptions_ssrConfig;
|
|
78
58
|
if (pluginOptions.csrConfig.getPublicPath) {
|
|
79
59
|
return;
|
|
80
60
|
}
|
|
81
61
|
let csrOutputPath = "";
|
|
82
62
|
let ssrOutputPath = "";
|
|
83
63
|
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
|
-
};
|
|
114
64
|
api.modifyEnvironmentConfig((config, { name }) => {
|
|
115
65
|
const target = config.output.target;
|
|
116
66
|
if ((0, import_utils3.skipByTarget)(target)) {
|
|
@@ -118,7 +68,6 @@ const mfSSRRsbuildPlugin = (pluginOptions) => {
|
|
|
118
68
|
}
|
|
119
69
|
if ((0, import_utils3.isWebTarget)(target)) {
|
|
120
70
|
csrOutputPath = config.output.distPath.root;
|
|
121
|
-
csrEnv = name;
|
|
122
71
|
} else {
|
|
123
72
|
ssrOutputPath = config.output.distPath.root;
|
|
124
73
|
ssrEnv = name;
|
|
@@ -144,24 +93,6 @@ const mfSSRRsbuildPlugin = (pluginOptions) => {
|
|
|
144
93
|
modifySSRPublicPath(config, utils);
|
|
145
94
|
return config;
|
|
146
95
|
});
|
|
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
96
|
}
|
|
166
97
|
};
|
|
167
98
|
};
|
|
@@ -286,24 +217,13 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
|
|
|
286
217
|
}
|
|
287
218
|
};
|
|
288
219
|
});
|
|
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
220
|
api.onAfterBuild(() => {
|
|
303
|
-
|
|
221
|
+
const { nodePlugin, browserPlugin, distOutputDir } = pluginOptions;
|
|
222
|
+
(0, import_utils2.updateStatsAndManifest)(nodePlugin, browserPlugin, distOutputDir);
|
|
304
223
|
});
|
|
305
224
|
api.onDevCompileDone(() => {
|
|
306
|
-
|
|
225
|
+
const { nodePlugin, browserPlugin, distOutputDir } = pluginOptions;
|
|
226
|
+
(0, import_utils2.updateStatsAndManifest)(nodePlugin, browserPlugin, distOutputDir);
|
|
307
227
|
});
|
|
308
228
|
}
|
|
309
229
|
});
|
|
@@ -5,7 +5,6 @@ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
|
5
5
|
import { _ as _type_of } from "@swc/helpers/_/_type_of";
|
|
6
6
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
7
7
|
import path from "path";
|
|
8
|
-
import fs from "fs";
|
|
9
8
|
import { getIPV4, isWebTarget, skipByTarget } from "./utils";
|
|
10
9
|
import { encodeName } from "@module-federation/sdk";
|
|
11
10
|
import { bundle } from "@modern-js/node-bundle-require";
|
|
@@ -16,6 +15,7 @@ import { isDev } from "./utils";
|
|
|
16
15
|
var defaultPath = path.resolve(process.cwd(), "module-federation.config.ts");
|
|
17
16
|
function setEnv(enableSSR) {
|
|
18
17
|
if (enableSSR) {
|
|
18
|
+
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
19
19
|
process.env["MF_SSR_PRJ"] = "true";
|
|
20
20
|
}
|
|
21
21
|
}
|
|
@@ -143,17 +143,6 @@ var patchMFConfig = function(mfConfig, isServer, remoteIpStrategy, enableSSR) {
|
|
|
143
143
|
throw new Error("".concat(PLUGIN_IDENTIFIER, " mfConfig.name can not be empty!"));
|
|
144
144
|
}
|
|
145
145
|
var runtimePlugins = _to_consumable_array(mfConfig.runtimePlugins || []);
|
|
146
|
-
try {
|
|
147
|
-
var nodeModulesPath = path.resolve(process.cwd(), "node_modules");
|
|
148
|
-
var bridgeReactPath = path.join(nodeModulesPath, "@module-federation/bridge-react");
|
|
149
|
-
if (fs.existsSync(bridgeReactPath) && (!(mfConfig === null || mfConfig === void 0 ? void 0 : mfConfig.bridge) || !mfConfig.bridge.disableAlias)) {
|
|
150
|
-
mfConfig.bridge = {
|
|
151
|
-
disableAlias: true
|
|
152
|
-
};
|
|
153
|
-
logger.debug("".concat(PLUGIN_IDENTIFIER, ' use "@module-federation/modern-js/react" instead of "@module-federation/bridge-react" !'));
|
|
154
|
-
}
|
|
155
|
-
} catch (e) {
|
|
156
|
-
}
|
|
157
146
|
patchDTSConfig(mfConfig, isServer);
|
|
158
147
|
injectRuntimePlugins(require.resolve("@module-federation/modern-js/shared-strategy"), runtimePlugins);
|
|
159
148
|
if (enableSSR && isDev()) {
|
package/dist/esm/cli/index.js
CHANGED
|
@@ -14,7 +14,6 @@ var moduleFederationPlugin = function() {
|
|
|
14
14
|
ssrConfig: void 0,
|
|
15
15
|
browserPlugin: void 0,
|
|
16
16
|
nodePlugin: void 0,
|
|
17
|
-
assetResources: {},
|
|
18
17
|
distOutputDir: "",
|
|
19
18
|
originPluginOptions: userConfig,
|
|
20
19
|
remoteIpStrategy: userConfig === null || userConfig === void 0 ? void 0 : userConfig.remoteIpStrategy,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
-
import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
|
|
3
2
|
import { _ as _type_of } from "@swc/helpers/_/_type_of";
|
|
4
3
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
5
4
|
import path from "path";
|
|
@@ -10,35 +9,12 @@ import UniverseEntryChunkTrackerPlugin from "@module-federation/node/universe-en
|
|
|
10
9
|
import logger from "../logger";
|
|
11
10
|
import { isDev } from "./utils";
|
|
12
11
|
import { updateStatsAndManifest } from "@module-federation/rsbuild-plugin/utils";
|
|
13
|
-
import { ManifestFileName, StatsFileName, simpleJoinRemoteEntry } from "@module-federation/sdk";
|
|
14
12
|
import { isWebTarget, skipByTarget } from "./utils";
|
|
15
13
|
function setEnv() {
|
|
14
|
+
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
16
15
|
process.env["MF_SSR_PRJ"] = "true";
|
|
17
16
|
}
|
|
18
17
|
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
|
-
}
|
|
42
18
|
var mfSSRRsbuildPlugin = function(pluginOptions) {
|
|
43
19
|
return {
|
|
44
20
|
name: "@modern-js/plugin-mf-post-config",
|
|
@@ -46,43 +22,12 @@ var mfSSRRsbuildPlugin = function(pluginOptions) {
|
|
|
46
22
|
"@modern-js/builder-plugin-ssr"
|
|
47
23
|
],
|
|
48
24
|
setup: function setup(api) {
|
|
49
|
-
var _pluginOptions_csrConfig, _pluginOptions_ssrConfig;
|
|
50
25
|
if (pluginOptions.csrConfig.getPublicPath) {
|
|
51
26
|
return;
|
|
52
27
|
}
|
|
53
28
|
var csrOutputPath = "";
|
|
54
29
|
var ssrOutputPath = "";
|
|
55
30
|
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
|
-
};
|
|
86
31
|
api.modifyEnvironmentConfig(function(config, param) {
|
|
87
32
|
var name = param.name;
|
|
88
33
|
var target = config.output.target;
|
|
@@ -91,7 +36,6 @@ var mfSSRRsbuildPlugin = function(pluginOptions) {
|
|
|
91
36
|
}
|
|
92
37
|
if (isWebTarget(target)) {
|
|
93
38
|
csrOutputPath = config.output.distPath.root;
|
|
94
|
-
csrEnv = name;
|
|
95
39
|
} else {
|
|
96
40
|
ssrOutputPath = config.output.distPath.root;
|
|
97
41
|
ssrEnv = name;
|
|
@@ -117,25 +61,6 @@ var mfSSRRsbuildPlugin = function(pluginOptions) {
|
|
|
117
61
|
modifySSRPublicPath(config, utils);
|
|
118
62
|
return config;
|
|
119
63
|
});
|
|
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
|
-
});
|
|
139
64
|
}
|
|
140
65
|
};
|
|
141
66
|
};
|
|
@@ -148,7 +73,7 @@ var moduleFederationSSRPlugin = function(pluginOptions) {
|
|
|
148
73
|
],
|
|
149
74
|
setup: function() {
|
|
150
75
|
var _ref = _async_to_generator(function(api) {
|
|
151
|
-
var _pluginOptions_userConfig, _modernjsConfig_server, modernjsConfig, _pluginOptions_userConfig_ssr, enableSSR
|
|
76
|
+
var _pluginOptions_userConfig, _modernjsConfig_server, modernjsConfig, _pluginOptions_userConfig_ssr, enableSSR;
|
|
152
77
|
return _ts_generator(this, function(_state) {
|
|
153
78
|
modernjsConfig = api.getConfig();
|
|
154
79
|
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);
|
|
@@ -266,24 +191,13 @@ var moduleFederationSSRPlugin = function(pluginOptions) {
|
|
|
266
191
|
}
|
|
267
192
|
};
|
|
268
193
|
});
|
|
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
|
-
};
|
|
282
194
|
api.onAfterBuild(function() {
|
|
283
|
-
|
|
195
|
+
var nodePlugin = pluginOptions.nodePlugin, browserPlugin = pluginOptions.browserPlugin, distOutputDir = pluginOptions.distOutputDir;
|
|
196
|
+
updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir);
|
|
284
197
|
});
|
|
285
198
|
api.onDevCompileDone(function() {
|
|
286
|
-
|
|
199
|
+
var nodePlugin = pluginOptions.nodePlugin, browserPlugin = pluginOptions.browserPlugin, distOutputDir = pluginOptions.distOutputDir;
|
|
200
|
+
updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir);
|
|
287
201
|
});
|
|
288
202
|
return [
|
|
289
203
|
2
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import fs from "fs";
|
|
3
2
|
import { getIPV4, isWebTarget, skipByTarget } from "./utils";
|
|
4
3
|
import { encodeName } from "@module-federation/sdk";
|
|
5
4
|
import { bundle } from "@modern-js/node-bundle-require";
|
|
@@ -10,6 +9,7 @@ import { isDev } from "./utils";
|
|
|
10
9
|
const defaultPath = path.resolve(process.cwd(), "module-federation.config.ts");
|
|
11
10
|
function setEnv(enableSSR) {
|
|
12
11
|
if (enableSSR) {
|
|
12
|
+
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
13
13
|
process.env["MF_SSR_PRJ"] = "true";
|
|
14
14
|
}
|
|
15
15
|
}
|
|
@@ -112,17 +112,6 @@ const patchMFConfig = (mfConfig, isServer, remoteIpStrategy, enableSSR) => {
|
|
|
112
112
|
const runtimePlugins = [
|
|
113
113
|
...mfConfig.runtimePlugins || []
|
|
114
114
|
];
|
|
115
|
-
try {
|
|
116
|
-
const nodeModulesPath = path.resolve(process.cwd(), "node_modules");
|
|
117
|
-
const bridgeReactPath = path.join(nodeModulesPath, "@module-federation/bridge-react");
|
|
118
|
-
if (fs.existsSync(bridgeReactPath) && (!(mfConfig === null || mfConfig === void 0 ? void 0 : mfConfig.bridge) || !mfConfig.bridge.disableAlias)) {
|
|
119
|
-
mfConfig.bridge = {
|
|
120
|
-
disableAlias: true
|
|
121
|
-
};
|
|
122
|
-
logger.debug(`${PLUGIN_IDENTIFIER} use "@module-federation/modern-js/react" instead of "@module-federation/bridge-react" !`);
|
|
123
|
-
}
|
|
124
|
-
} catch (e) {
|
|
125
|
-
}
|
|
126
115
|
patchDTSConfig(mfConfig, isServer);
|
|
127
116
|
injectRuntimePlugins(require.resolve("@module-federation/modern-js/shared-strategy"), runtimePlugins);
|
|
128
117
|
if (enableSSR && isDev()) {
|
|
@@ -10,7 +10,6 @@ const moduleFederationPlugin = (userConfig = {}) => {
|
|
|
10
10
|
ssrConfig: void 0,
|
|
11
11
|
browserPlugin: void 0,
|
|
12
12
|
nodePlugin: void 0,
|
|
13
|
-
assetResources: {},
|
|
14
13
|
distOutputDir: "",
|
|
15
14
|
originPluginOptions: userConfig,
|
|
16
15
|
remoteIpStrategy: userConfig === null || userConfig === void 0 ? void 0 : userConfig.remoteIpStrategy,
|
|
@@ -6,31 +6,12 @@ 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";
|
|
10
9
|
import { isWebTarget, skipByTarget } from "./utils";
|
|
11
10
|
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
|
-
}
|
|
34
15
|
const mfSSRRsbuildPlugin = (pluginOptions) => {
|
|
35
16
|
return {
|
|
36
17
|
name: "@modern-js/plugin-mf-post-config",
|
|
@@ -38,43 +19,12 @@ const mfSSRRsbuildPlugin = (pluginOptions) => {
|
|
|
38
19
|
"@modern-js/builder-plugin-ssr"
|
|
39
20
|
],
|
|
40
21
|
setup(api) {
|
|
41
|
-
var _pluginOptions_csrConfig, _pluginOptions_ssrConfig;
|
|
42
22
|
if (pluginOptions.csrConfig.getPublicPath) {
|
|
43
23
|
return;
|
|
44
24
|
}
|
|
45
25
|
let csrOutputPath = "";
|
|
46
26
|
let ssrOutputPath = "";
|
|
47
27
|
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
|
-
};
|
|
78
28
|
api.modifyEnvironmentConfig((config, { name }) => {
|
|
79
29
|
const target = config.output.target;
|
|
80
30
|
if (skipByTarget(target)) {
|
|
@@ -82,7 +32,6 @@ const mfSSRRsbuildPlugin = (pluginOptions) => {
|
|
|
82
32
|
}
|
|
83
33
|
if (isWebTarget(target)) {
|
|
84
34
|
csrOutputPath = config.output.distPath.root;
|
|
85
|
-
csrEnv = name;
|
|
86
35
|
} else {
|
|
87
36
|
ssrOutputPath = config.output.distPath.root;
|
|
88
37
|
ssrEnv = name;
|
|
@@ -108,24 +57,6 @@ const mfSSRRsbuildPlugin = (pluginOptions) => {
|
|
|
108
57
|
modifySSRPublicPath(config, utils);
|
|
109
58
|
return config;
|
|
110
59
|
});
|
|
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
|
-
});
|
|
129
60
|
}
|
|
130
61
|
};
|
|
131
62
|
};
|
|
@@ -250,24 +181,13 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
|
|
|
250
181
|
}
|
|
251
182
|
};
|
|
252
183
|
});
|
|
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
|
-
};
|
|
266
184
|
api.onAfterBuild(() => {
|
|
267
|
-
|
|
185
|
+
const { nodePlugin, browserPlugin, distOutputDir } = pluginOptions;
|
|
186
|
+
updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir);
|
|
268
187
|
});
|
|
269
188
|
api.onDevCompileDone(() => {
|
|
270
|
-
|
|
189
|
+
const { nodePlugin, browserPlugin, distOutputDir } = pluginOptions;
|
|
190
|
+
updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir);
|
|
271
191
|
});
|
|
272
192
|
}
|
|
273
193
|
});
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { moduleFederationPlugin } from '@module-federation/sdk';
|
|
2
|
-
import type { StatsAssetResource } from '@module-federation/rsbuild-plugin/utils';
|
|
3
2
|
export interface PluginOptions {
|
|
4
3
|
config?: moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
5
4
|
configPath?: string;
|
|
@@ -16,10 +15,6 @@ export interface InternalModernPluginOptions {
|
|
|
16
15
|
originPluginOptions: PluginOptions;
|
|
17
16
|
browserPlugin?: BundlerPlugin;
|
|
18
17
|
nodePlugin?: BundlerPlugin;
|
|
19
|
-
assetResources: {
|
|
20
|
-
browser?: StatsAssetResource;
|
|
21
|
-
node?: StatsAssetResource;
|
|
22
|
-
};
|
|
23
18
|
remoteIpStrategy?: 'ipv4' | 'inherit';
|
|
24
19
|
userConfig?: PluginOptions;
|
|
25
20
|
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-research-issue-4085-20251016232757",
|
|
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/bridge-react": "0.0.0-
|
|
123
|
-
"@module-federation/
|
|
124
|
-
"@module-federation/enhanced": "0.0.0-
|
|
125
|
-
"@module-federation/
|
|
126
|
-
"@module-federation/
|
|
127
|
-
"@module-federation/node": "0.0.0-
|
|
128
|
-
"@module-federation/
|
|
122
|
+
"@module-federation/bridge-react": "0.0.0-research-issue-4085-20251016232757",
|
|
123
|
+
"@module-federation/rsbuild-plugin": "0.0.0-research-issue-4085-20251016232757",
|
|
124
|
+
"@module-federation/enhanced": "0.0.0-research-issue-4085-20251016232757",
|
|
125
|
+
"@module-federation/runtime": "0.0.0-research-issue-4085-20251016232757",
|
|
126
|
+
"@module-federation/sdk": "0.0.0-research-issue-4085-20251016232757",
|
|
127
|
+
"@module-federation/node": "0.0.0-research-issue-4085-20251016232757",
|
|
128
|
+
"@module-federation/cli": "0.0.0-research-issue-4085-20251016232757"
|
|
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-research-issue-4085-20251016232757"
|
|
141
141
|
},
|
|
142
142
|
"peerDependencies": {
|
|
143
143
|
"react": ">=17",
|