@module-federation/modern-js 0.14.2 → 0.14.3
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/LICENSE +21 -0
- package/dist/cjs/cli/configPlugin.js +377 -0
- package/dist/cjs/cli/configPlugin.spec.js +112 -0
- package/dist/cjs/cli/constant.js +28 -0
- package/dist/cjs/cli/index.js +93 -0
- package/dist/cjs/cli/logger.js +27 -0
- package/dist/cjs/cli/manifest.js +75 -0
- package/dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js +44 -0
- package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +82 -0
- package/dist/cjs/cli/mfRuntimePlugins/shared-strategy.js +43 -0
- package/dist/cjs/cli/ssrPlugin.js +217 -0
- package/dist/cjs/cli/utils.js +85 -0
- package/dist/cjs/constant.js +31 -0
- package/dist/cjs/interfaces/bundler.js +16 -0
- package/dist/cjs/runtime/createRemoteSSRComponent.js +201 -0
- package/dist/cjs/runtime/index.js +38 -0
- package/dist/cjs/server/fileCache.js +84 -0
- package/dist/cjs/server/fileCache.spec.js +28 -0
- package/dist/cjs/server/index.js +58 -0
- package/dist/cjs/server/staticMiddleware.js +77 -0
- package/dist/cjs/server/staticMiddleware.spec.js +185 -0
- package/dist/cjs/ssr-runtime/SSRLiveReload.js +43 -0
- package/dist/cjs/ssr-runtime/index.js +22 -0
- package/dist/cjs/ssr-runtime/plugin.js +68 -0
- package/dist/cjs/types/index.js +16 -0
- package/dist/esm/cli/configPlugin.js +384 -0
- package/dist/esm/cli/configPlugin.spec.js +108 -0
- package/dist/esm/cli/constant.js +4 -0
- package/dist/esm/cli/index.js +88 -0
- package/dist/esm/cli/logger.js +7 -0
- package/dist/esm/cli/manifest.js +41 -0
- package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.js +16 -0
- package/dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.js +74 -0
- package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +25 -0
- package/dist/esm/cli/ssrPlugin.js +199 -0
- package/dist/esm/cli/utils.js +49 -0
- package/dist/esm/constant.js +6 -0
- package/dist/esm/interfaces/bundler.js +0 -0
- package/dist/esm/runtime/createRemoteSSRComponent.js +191 -0
- package/dist/esm/runtime/index.js +12 -0
- package/dist/esm/server/fileCache.js +98 -0
- package/dist/esm/server/fileCache.spec.js +50 -0
- package/dist/esm/server/index.js +36 -0
- package/dist/esm/server/staticMiddleware.js +81 -0
- package/dist/esm/server/staticMiddleware.spec.js +328 -0
- package/dist/esm/ssr-runtime/SSRLiveReload.js +26 -0
- package/dist/esm/ssr-runtime/index.js +1 -0
- package/dist/esm/ssr-runtime/plugin.js +70 -0
- package/dist/esm/types/index.js +0 -0
- package/dist/esm-node/cli/configPlugin.js +336 -0
- package/dist/esm-node/cli/configPlugin.spec.js +89 -0
- package/dist/esm-node/cli/constant.js +4 -0
- package/dist/esm-node/cli/index.js +68 -0
- package/dist/esm-node/cli/logger.js +7 -0
- package/dist/esm-node/cli/manifest.js +41 -0
- package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.js +14 -0
- package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +62 -0
- package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +23 -0
- package/dist/esm-node/cli/ssrPlugin.js +181 -0
- package/dist/esm-node/cli/utils.js +49 -0
- package/dist/esm-node/constant.js +6 -0
- package/dist/esm-node/interfaces/bundler.js +0 -0
- package/dist/esm-node/runtime/createRemoteSSRComponent.js +166 -0
- package/dist/esm-node/runtime/index.js +12 -0
- package/dist/esm-node/server/fileCache.js +49 -0
- package/dist/esm-node/server/fileCache.spec.js +27 -0
- package/dist/esm-node/server/index.js +34 -0
- package/dist/esm-node/server/staticMiddleware.js +43 -0
- package/dist/esm-node/server/staticMiddleware.spec.js +162 -0
- package/dist/esm-node/ssr-runtime/SSRLiveReload.js +19 -0
- package/dist/esm-node/ssr-runtime/index.js +1 -0
- package/dist/esm-node/ssr-runtime/plugin.js +34 -0
- package/dist/esm-node/types/index.js +0 -0
- package/dist/types/cli/configPlugin.d.ts +21 -0
- package/dist/types/cli/configPlugin.spec.d.ts +1 -0
- package/dist/types/cli/constant.d.ts +1 -0
- package/dist/types/cli/index.d.ts +5 -0
- package/dist/types/cli/logger.d.ts +2 -0
- package/dist/types/cli/manifest.d.ts +2 -0
- package/dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts +3 -0
- package/dist/types/cli/mfRuntimePlugins/resolve-entry-ipv4.d.ts +3 -0
- package/dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts +3 -0
- package/dist/types/cli/ssrPlugin.d.ts +6 -0
- package/dist/types/cli/utils.d.ts +5 -0
- package/dist/types/constant.d.ts +2 -0
- package/dist/types/interfaces/bundler.d.ts +18 -0
- package/dist/types/runtime/createRemoteSSRComponent.d.ts +18 -0
- package/dist/types/runtime/index.d.ts +5 -0
- package/dist/types/server/fileCache.d.ts +14 -0
- package/dist/types/server/fileCache.spec.d.ts +1 -0
- package/dist/types/server/index.d.ts +4 -0
- package/dist/types/server/staticMiddleware.d.ts +6 -0
- package/dist/types/server/staticMiddleware.spec.d.ts +1 -0
- package/dist/types/ssr-runtime/SSRLiveReload.d.ts +1 -0
- package/dist/types/ssr-runtime/index.d.ts +1 -0
- package/dist/types/ssr-runtime/plugin.d.ts +2 -0
- package/dist/types/types/index.d.ts +22 -0
- package/package.json +7 -7
|
@@ -0,0 +1,75 @@
|
|
|
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 manifest_exports = {};
|
|
30
|
+
__export(manifest_exports, {
|
|
31
|
+
updateStatsAndManifest: () => updateStatsAndManifest
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(manifest_exports);
|
|
34
|
+
var import_path = __toESM(require("path"));
|
|
35
|
+
var import_fs_extra = __toESM(require("fs-extra"));
|
|
36
|
+
function mergeStats(browserStats, nodeStats) {
|
|
37
|
+
const ssrRemoteEntry = nodeStats.metaData.remoteEntry;
|
|
38
|
+
browserStats.metaData.ssrRemoteEntry = ssrRemoteEntry;
|
|
39
|
+
if ("publicPath" in browserStats.metaData) {
|
|
40
|
+
browserStats.metaData.ssrPublicPath = nodeStats.metaData.publicPath;
|
|
41
|
+
}
|
|
42
|
+
return browserStats;
|
|
43
|
+
}
|
|
44
|
+
function mergeManifest(browserManifest, nodeManifest) {
|
|
45
|
+
const ssrRemoteEntry = nodeManifest.metaData.remoteEntry;
|
|
46
|
+
browserManifest.metaData.ssrRemoteEntry = ssrRemoteEntry;
|
|
47
|
+
if ("publicPath" in browserManifest.metaData) {
|
|
48
|
+
browserManifest.metaData.ssrPublicPath = nodeManifest.metaData.publicPath;
|
|
49
|
+
}
|
|
50
|
+
return browserManifest;
|
|
51
|
+
}
|
|
52
|
+
function mergeStatsAndManifest(nodePlugin, browserPlugin) {
|
|
53
|
+
const nodeResourceInfo = nodePlugin.statsResourceInfo;
|
|
54
|
+
const browserResourceInfo = browserPlugin.statsResourceInfo;
|
|
55
|
+
if (!browserResourceInfo || !nodeResourceInfo || !browserResourceInfo.stats || !nodeResourceInfo.stats || !browserResourceInfo.manifest || !nodeResourceInfo.manifest) {
|
|
56
|
+
throw new Error("can not get browserResourceInfo or nodeResourceInfo");
|
|
57
|
+
}
|
|
58
|
+
const mergedStats = mergeStats(browserResourceInfo.stats.stats, nodeResourceInfo.stats.stats);
|
|
59
|
+
const mergedManifest = mergeManifest(browserResourceInfo.manifest.manifest, nodeResourceInfo.manifest.manifest);
|
|
60
|
+
return {
|
|
61
|
+
mergedStats,
|
|
62
|
+
mergedStatsFilePath: browserResourceInfo.stats.filename,
|
|
63
|
+
mergedManifest,
|
|
64
|
+
mergedManifestFilePath: browserResourceInfo.manifest.filename
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function updateStatsAndManifest(nodePlugin, browserPlugin, outputDir) {
|
|
68
|
+
const { mergedStats, mergedStatsFilePath, mergedManifest, mergedManifestFilePath } = mergeStatsAndManifest(nodePlugin, browserPlugin);
|
|
69
|
+
import_fs_extra.default.writeFileSync(import_path.default.resolve(outputDir, mergedStatsFilePath), JSON.stringify(mergedStats, null, 2));
|
|
70
|
+
import_fs_extra.default.writeFileSync(import_path.default.resolve(outputDir, mergedManifestFilePath), JSON.stringify(mergedManifest, null, 2));
|
|
71
|
+
}
|
|
72
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
73
|
+
0 && (module.exports = {
|
|
74
|
+
updateStatsAndManifest
|
|
75
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
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 inject_node_fetch_exports = {};
|
|
30
|
+
__export(inject_node_fetch_exports, {
|
|
31
|
+
default: () => inject_node_fetch_default
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(inject_node_fetch_exports);
|
|
34
|
+
var import_node_fetch = __toESM(require("node-fetch"));
|
|
35
|
+
const injectNodeFetchPlugin = () => ({
|
|
36
|
+
name: "inject-node-fetch-plugin",
|
|
37
|
+
beforeInit(args) {
|
|
38
|
+
if (!globalThis.fetch) {
|
|
39
|
+
globalThis.fetch = import_node_fetch.default;
|
|
40
|
+
}
|
|
41
|
+
return args;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
var inject_node_fetch_default = injectNodeFetchPlugin;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var resolve_entry_ipv4_exports = {};
|
|
20
|
+
__export(resolve_entry_ipv4_exports, {
|
|
21
|
+
default: () => resolve_entry_ipv4_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(resolve_entry_ipv4_exports);
|
|
24
|
+
var import_constant = require("../../constant");
|
|
25
|
+
const ipv4 = typeof FEDERATION_IPV4 !== "undefined" ? FEDERATION_IPV4 : "127.0.0.1";
|
|
26
|
+
const remoteIpStrategy = typeof REMOTE_IP_STRATEGY !== "undefined" ? REMOTE_IP_STRATEGY : "inherit";
|
|
27
|
+
function replaceObjectLocalhost(key, obj) {
|
|
28
|
+
if (remoteIpStrategy !== "ipv4") {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (!(key in obj)) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const remote = obj[key];
|
|
35
|
+
if (remote && typeof remote === "string" && remote.includes(import_constant.LOCALHOST)) {
|
|
36
|
+
obj[key] = replaceLocalhost(remote);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function replaceLocalhost(url) {
|
|
40
|
+
return url.replace(import_constant.LOCALHOST, ipv4);
|
|
41
|
+
}
|
|
42
|
+
const resolveEntryIpv4Plugin = () => ({
|
|
43
|
+
name: "resolve-entry-ipv4",
|
|
44
|
+
beforeRegisterRemote(args) {
|
|
45
|
+
const { remote } = args;
|
|
46
|
+
replaceObjectLocalhost("entry", remote);
|
|
47
|
+
return args;
|
|
48
|
+
},
|
|
49
|
+
async afterResolve(args) {
|
|
50
|
+
const { remoteInfo } = args;
|
|
51
|
+
replaceObjectLocalhost("entry", remoteInfo);
|
|
52
|
+
return args;
|
|
53
|
+
},
|
|
54
|
+
beforeLoadRemoteSnapshot(args) {
|
|
55
|
+
const { moduleInfo } = args;
|
|
56
|
+
if ("entry" in moduleInfo) {
|
|
57
|
+
replaceObjectLocalhost("entry", moduleInfo);
|
|
58
|
+
return args;
|
|
59
|
+
}
|
|
60
|
+
if ("version" in moduleInfo) {
|
|
61
|
+
replaceObjectLocalhost("version", moduleInfo);
|
|
62
|
+
}
|
|
63
|
+
return args;
|
|
64
|
+
},
|
|
65
|
+
loadRemoteSnapshot(args) {
|
|
66
|
+
const { remoteSnapshot } = args;
|
|
67
|
+
if ("publicPath" in remoteSnapshot) {
|
|
68
|
+
replaceObjectLocalhost("publicPath", remoteSnapshot);
|
|
69
|
+
}
|
|
70
|
+
if ("getPublicPath" in remoteSnapshot) {
|
|
71
|
+
replaceObjectLocalhost("getPublicPath", remoteSnapshot);
|
|
72
|
+
}
|
|
73
|
+
if (remoteSnapshot.remotesInfo) {
|
|
74
|
+
Object.keys(remoteSnapshot.remotesInfo).forEach((key) => {
|
|
75
|
+
const remoteInfo = remoteSnapshot.remotesInfo[key];
|
|
76
|
+
replaceObjectLocalhost("matchedVersion", remoteInfo);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return args;
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
var resolve_entry_ipv4_default = resolveEntryIpv4Plugin;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var shared_strategy_exports = {};
|
|
20
|
+
__export(shared_strategy_exports, {
|
|
21
|
+
default: () => shared_strategy_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(shared_strategy_exports);
|
|
24
|
+
const sharedStrategy = () => ({
|
|
25
|
+
name: "shared-strategy-plugin",
|
|
26
|
+
beforeInit(args) {
|
|
27
|
+
const { userOptions } = args;
|
|
28
|
+
const shared = userOptions.shared;
|
|
29
|
+
if (shared) {
|
|
30
|
+
Object.keys(shared).forEach((sharedKey) => {
|
|
31
|
+
const sharedConfigs = shared[sharedKey];
|
|
32
|
+
const arraySharedConfigs = Array.isArray(sharedConfigs) ? sharedConfigs : [
|
|
33
|
+
sharedConfigs
|
|
34
|
+
];
|
|
35
|
+
arraySharedConfigs.forEach((s) => {
|
|
36
|
+
s.strategy = "loaded-first";
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return args;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
var shared_strategy_default = sharedStrategy;
|
|
@@ -0,0 +1,217 @@
|
|
|
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
|
|
35
|
+
});
|
|
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_manifest = require("./manifest");
|
|
43
|
+
var import_constant = require("./constant");
|
|
44
|
+
var import_logger = __toESM(require("./logger"));
|
|
45
|
+
var import_utils = require("./utils");
|
|
46
|
+
function setEnv() {
|
|
47
|
+
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
48
|
+
process.env["MF_SSR_PRJ"] = "true";
|
|
49
|
+
}
|
|
50
|
+
const CHAIN_MF_PLUGIN_ID = "plugin-module-federation-server";
|
|
51
|
+
const mfSSRRsbuildPlugin = (pluginOptions) => {
|
|
52
|
+
return {
|
|
53
|
+
name: "@modern-js/plugin-mf-post-config",
|
|
54
|
+
pre: [
|
|
55
|
+
"@modern-js/builder-plugin-ssr"
|
|
56
|
+
],
|
|
57
|
+
setup(api) {
|
|
58
|
+
if (pluginOptions.csrConfig.getPublicPath) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
let csrOutputPath = "";
|
|
62
|
+
let ssrOutputPath = "";
|
|
63
|
+
let ssrEnv = "";
|
|
64
|
+
api.modifyEnvironmentConfig((config, { name }) => {
|
|
65
|
+
const target = config.output.target;
|
|
66
|
+
if ((0, import_utils.skipByTarget)(target)) {
|
|
67
|
+
return config;
|
|
68
|
+
}
|
|
69
|
+
if ((0, import_utils.isWebTarget)(target)) {
|
|
70
|
+
csrOutputPath = config.output.distPath.root;
|
|
71
|
+
} else {
|
|
72
|
+
ssrOutputPath = config.output.distPath.root;
|
|
73
|
+
ssrEnv = name;
|
|
74
|
+
}
|
|
75
|
+
return config;
|
|
76
|
+
});
|
|
77
|
+
const modifySSRPublicPath = (config, utils) => {
|
|
78
|
+
if (ssrEnv !== utils.environment.name) {
|
|
79
|
+
return config;
|
|
80
|
+
}
|
|
81
|
+
const userSSRConfig = pluginOptions.userConfig.ssr ? typeof pluginOptions.userConfig.ssr === "object" ? pluginOptions.userConfig.ssr : {} : {};
|
|
82
|
+
if (userSSRConfig.distOutputDir) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
config.output.publicPath = `${config.output.publicPath}${import_path.default.relative(csrOutputPath, ssrOutputPath)}/`;
|
|
86
|
+
return config;
|
|
87
|
+
};
|
|
88
|
+
api.modifyWebpackConfig((config, utils) => {
|
|
89
|
+
modifySSRPublicPath(config, utils);
|
|
90
|
+
return config;
|
|
91
|
+
});
|
|
92
|
+
api.modifyRspackConfig((config, utils) => {
|
|
93
|
+
modifySSRPublicPath(config, utils);
|
|
94
|
+
return config;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
const moduleFederationSSRPlugin = (pluginOptions) => ({
|
|
100
|
+
name: "@modern-js/plugin-module-federation-ssr",
|
|
101
|
+
pre: [
|
|
102
|
+
"@modern-js/plugin-module-federation-config",
|
|
103
|
+
"@modern-js/plugin-module-federation"
|
|
104
|
+
],
|
|
105
|
+
setup: async (api) => {
|
|
106
|
+
var _pluginOptions_userConfig, _modernjsConfig_server;
|
|
107
|
+
const modernjsConfig = api.getConfig();
|
|
108
|
+
var _pluginOptions_userConfig_ssr;
|
|
109
|
+
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);
|
|
110
|
+
if (!enableSSR) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
setEnv();
|
|
114
|
+
api._internalRuntimePlugins(({ entrypoint, plugins }) => {
|
|
115
|
+
if (!import_constant.isDev) {
|
|
116
|
+
return {
|
|
117
|
+
entrypoint,
|
|
118
|
+
plugins
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
plugins.push({
|
|
122
|
+
name: "mfSSR",
|
|
123
|
+
path: "@module-federation/modern-js/ssr-runtime",
|
|
124
|
+
config: {}
|
|
125
|
+
});
|
|
126
|
+
return {
|
|
127
|
+
entrypoint,
|
|
128
|
+
plugins
|
|
129
|
+
};
|
|
130
|
+
});
|
|
131
|
+
api.modifyBundlerChain((chain) => {
|
|
132
|
+
const target = chain.get("target");
|
|
133
|
+
if ((0, import_utils.skipByTarget)(target)) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
137
|
+
const MFPlugin = bundlerType === "webpack" ? import_webpack.ModuleFederationPlugin : import_rspack.ModuleFederationPlugin;
|
|
138
|
+
const isWeb = (0, import_utils.isWebTarget)(target);
|
|
139
|
+
if (!isWeb) {
|
|
140
|
+
if (!chain.plugins.has(CHAIN_MF_PLUGIN_ID)) {
|
|
141
|
+
chain.plugin(CHAIN_MF_PLUGIN_ID).use(MFPlugin, [
|
|
142
|
+
pluginOptions.ssrConfig
|
|
143
|
+
]).init((Plugin, args) => {
|
|
144
|
+
pluginOptions.nodePlugin = new Plugin(args[0]);
|
|
145
|
+
return pluginOptions.nodePlugin;
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (!isWeb) {
|
|
150
|
+
chain.target("async-node");
|
|
151
|
+
if (import_constant.isDev) {
|
|
152
|
+
chain.plugin("UniverseEntryChunkTrackerPlugin").use(import_universe_entry_chunk_tracker_plugin.default);
|
|
153
|
+
}
|
|
154
|
+
const userSSRConfig = pluginOptions.userConfig.ssr ? typeof pluginOptions.userConfig.ssr === "object" ? pluginOptions.userConfig.ssr : {} : {};
|
|
155
|
+
const publicPath = chain.output.get("publicPath");
|
|
156
|
+
if (userSSRConfig.distOutputDir && publicPath) {
|
|
157
|
+
chain.output.publicPath(`${publicPath}${userSSRConfig.distOutputDir}/`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (import_constant.isDev && isWeb) {
|
|
161
|
+
chain.externals({
|
|
162
|
+
"@module-federation/node/utils": "NOT_USED_IN_BROWSER"
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
api.config(() => {
|
|
167
|
+
return {
|
|
168
|
+
builderPlugins: [
|
|
169
|
+
mfSSRRsbuildPlugin(pluginOptions)
|
|
170
|
+
],
|
|
171
|
+
tools: {
|
|
172
|
+
devServer: {
|
|
173
|
+
before: [
|
|
174
|
+
(req, res, next) => {
|
|
175
|
+
if (!enableSSR) {
|
|
176
|
+
next();
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
try {
|
|
180
|
+
var _req_url, _req_url1;
|
|
181
|
+
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"))) {
|
|
182
|
+
const filepath = import_path.default.join(process.cwd(), `dist${req.url}`);
|
|
183
|
+
import_fs_extra.default.statSync(filepath);
|
|
184
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
185
|
+
res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH, OPTIONS");
|
|
186
|
+
res.setHeader("Access-Control-Allow-Headers", "*");
|
|
187
|
+
import_fs_extra.default.createReadStream(filepath).pipe(res);
|
|
188
|
+
} else {
|
|
189
|
+
next();
|
|
190
|
+
}
|
|
191
|
+
} catch (err) {
|
|
192
|
+
import_logger.default.debug(err);
|
|
193
|
+
next();
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
]
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
});
|
|
201
|
+
api.onAfterBuild(() => {
|
|
202
|
+
const { nodePlugin, browserPlugin, distOutputDir } = pluginOptions;
|
|
203
|
+
(0, import_manifest.updateStatsAndManifest)(nodePlugin, browserPlugin, distOutputDir);
|
|
204
|
+
});
|
|
205
|
+
api.onDevCompileDone(() => {
|
|
206
|
+
const { nodePlugin, browserPlugin, distOutputDir } = pluginOptions;
|
|
207
|
+
(0, import_manifest.updateStatsAndManifest)(nodePlugin, browserPlugin, distOutputDir);
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
var ssrPlugin_default = moduleFederationSSRPlugin;
|
|
212
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
213
|
+
0 && (module.exports = {
|
|
214
|
+
CHAIN_MF_PLUGIN_ID,
|
|
215
|
+
moduleFederationSSRPlugin,
|
|
216
|
+
setEnv
|
|
217
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
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 utils_exports = {};
|
|
30
|
+
__export(utils_exports, {
|
|
31
|
+
getIPV4: () => getIPV4,
|
|
32
|
+
isWebTarget: () => isWebTarget,
|
|
33
|
+
skipByTarget: () => skipByTarget
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(utils_exports);
|
|
36
|
+
var import_os = __toESM(require("os"));
|
|
37
|
+
const localIpv4 = "127.0.0.1";
|
|
38
|
+
const getIpv4Interfaces = () => {
|
|
39
|
+
try {
|
|
40
|
+
const interfaces = import_os.default.networkInterfaces();
|
|
41
|
+
const ipv4Interfaces = [];
|
|
42
|
+
Object.values(interfaces).forEach((detail) => {
|
|
43
|
+
detail === null || detail === void 0 ? void 0 : detail.forEach((detail2) => {
|
|
44
|
+
const familyV4Value = typeof detail2.family === "string" ? "IPv4" : 4;
|
|
45
|
+
if (detail2.family === familyV4Value && detail2.address !== localIpv4) {
|
|
46
|
+
ipv4Interfaces.push(detail2);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
return ipv4Interfaces;
|
|
51
|
+
} catch (_err) {
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const getIPV4 = () => {
|
|
56
|
+
const ipv4Interfaces = getIpv4Interfaces();
|
|
57
|
+
const ipv4Interface = ipv4Interfaces[0] || {
|
|
58
|
+
address: localIpv4
|
|
59
|
+
};
|
|
60
|
+
return ipv4Interface.address;
|
|
61
|
+
};
|
|
62
|
+
const isWebTarget = (target) => {
|
|
63
|
+
const WEB_TARGET = "web";
|
|
64
|
+
if (Array.isArray(target)) {
|
|
65
|
+
return target.includes(WEB_TARGET);
|
|
66
|
+
} else if (typeof target === "string") {
|
|
67
|
+
return target === WEB_TARGET;
|
|
68
|
+
}
|
|
69
|
+
return false;
|
|
70
|
+
};
|
|
71
|
+
const skipByTarget = (target) => {
|
|
72
|
+
const IGNORE_TARGET = "webworker";
|
|
73
|
+
if (Array.isArray(target)) {
|
|
74
|
+
return target.includes(IGNORE_TARGET);
|
|
75
|
+
} else if (typeof target === "string") {
|
|
76
|
+
return target === IGNORE_TARGET;
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
};
|
|
80
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
81
|
+
0 && (module.exports = {
|
|
82
|
+
getIPV4,
|
|
83
|
+
isWebTarget,
|
|
84
|
+
skipByTarget
|
|
85
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var constant_exports = {};
|
|
20
|
+
__export(constant_exports, {
|
|
21
|
+
LOCALHOST: () => LOCALHOST,
|
|
22
|
+
PLUGIN_IDENTIFIER: () => PLUGIN_IDENTIFIER
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(constant_exports);
|
|
25
|
+
const LOCALHOST = "localhost";
|
|
26
|
+
const PLUGIN_IDENTIFIER = "[ Modern.js Module Federation ]";
|
|
27
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
+
0 && (module.exports = {
|
|
29
|
+
LOCALHOST,
|
|
30
|
+
PLUGIN_IDENTIFIER
|
|
31
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var bundler_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(bundler_exports);
|