@module-federation/modern-js 0.0.0-next-20240909073915 → 0.0.0-next-20240909092952
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/dataLoader/ast/constant.js +49 -0
- package/dist/cjs/cli/dataLoader/ast/generateRoutes.js +141 -0
- package/dist/cjs/cli/{constant.js → dataLoader/ast/index.js} +6 -6
- package/dist/cjs/cli/dataLoader/generateRouteFile.js +143 -0
- package/dist/cjs/cli/dataLoader/patchMFConfig.js +132 -0
- package/dist/cjs/cli/dataLoader/plugin.js +194 -0
- package/dist/cjs/cli/index.js +5 -1
- package/dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js +7 -10
- package/dist/cjs/cli/mfRuntimePlugins/node.js +44 -0
- package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +40 -38
- package/dist/cjs/cli/server/dataLoaderPlugin.js +82 -0
- package/dist/cjs/cli/server/fetchRemoteFullRoutesMap.js +69 -0
- package/dist/cjs/cli/ssrPlugin.js +1 -1
- package/dist/cjs/cli/utils.js +8 -4
- package/dist/cjs/cli/utils.spec.js +1 -1
- package/dist/cjs/constant.js +32 -2
- package/dist/cjs/interfaces/route.js +16 -0
- package/dist/cjs/runtime/dataLoader/plugin.js +73 -0
- package/dist/cjs/runtime/dataLoader/utils.js +89 -0
- package/dist/cjs/runtime/index.js +4 -1
- package/dist/cjs/runtime/utils.js +38 -0
- package/dist/cjs/runtime/withMFRouteId.js +31 -0
- package/dist/cjs/ssr-runtime/plugin.js +7 -7
- package/dist/esm/cli/dataLoader/ast/constant.js +18 -0
- package/dist/esm/cli/dataLoader/ast/generateRoutes.js +108 -0
- package/dist/esm/cli/dataLoader/ast/index.js +4 -0
- package/dist/esm/cli/dataLoader/generateRouteFile.js +293 -0
- package/dist/esm/cli/dataLoader/patchMFConfig.js +98 -0
- package/dist/esm/cli/dataLoader/plugin.js +209 -0
- package/dist/esm/cli/index.js +4 -1
- package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.js +7 -10
- package/dist/esm/cli/mfRuntimePlugins/node.js +16 -0
- package/dist/esm/cli/server/dataLoaderPlugin.js +105 -0
- package/dist/esm/cli/server/fetchRemoteFullRoutesMap.js +88 -0
- package/dist/esm/cli/ssrPlugin.js +1 -1
- package/dist/esm/cli/utils.js +6 -3
- package/dist/esm/cli/utils.spec.js +1 -1
- package/dist/esm/constant.js +21 -1
- package/dist/esm/interfaces/route.js +0 -0
- package/dist/esm/runtime/dataLoader/plugin.js +92 -0
- package/dist/esm/runtime/dataLoader/utils.js +63 -0
- package/dist/esm/runtime/index.js +3 -1
- package/dist/esm/runtime/utils.js +13 -0
- package/dist/esm/runtime/withMFRouteId.js +7 -0
- package/dist/esm/ssr-runtime/plugin.js +7 -10
- package/dist/esm-node/cli/dataLoader/ast/constant.js +18 -0
- package/dist/esm-node/cli/dataLoader/ast/generateRoutes.js +107 -0
- package/dist/esm-node/cli/dataLoader/ast/index.js +4 -0
- package/dist/esm-node/cli/dataLoader/generateRouteFile.js +108 -0
- package/dist/esm-node/cli/dataLoader/patchMFConfig.js +98 -0
- package/dist/esm-node/cli/dataLoader/plugin.js +159 -0
- package/dist/esm-node/cli/index.js +5 -1
- package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.js +7 -10
- package/dist/esm-node/cli/mfRuntimePlugins/node.js +14 -0
- package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +40 -38
- package/dist/esm-node/cli/server/dataLoaderPlugin.js +62 -0
- package/dist/esm-node/cli/server/fetchRemoteFullRoutesMap.js +44 -0
- package/dist/esm-node/cli/ssrPlugin.js +1 -1
- package/dist/esm-node/cli/utils.js +6 -3
- package/dist/esm-node/cli/utils.spec.js +1 -1
- package/dist/esm-node/constant.js +21 -1
- package/dist/esm-node/interfaces/route.js +0 -0
- package/dist/esm-node/runtime/dataLoader/plugin.js +49 -0
- package/dist/esm-node/runtime/dataLoader/utils.js +63 -0
- package/dist/esm-node/runtime/index.js +3 -1
- package/dist/esm-node/runtime/utils.js +13 -0
- package/dist/esm-node/runtime/withMFRouteId.js +7 -0
- package/dist/esm-node/ssr-runtime/plugin.js +7 -7
- package/dist/types/cli/dataLoader/ast/constant.d.ts +8 -0
- package/dist/types/cli/dataLoader/ast/generateRoutes.d.ts +5 -0
- package/dist/types/cli/dataLoader/ast/index.d.ts +1 -0
- package/dist/types/cli/dataLoader/generateRouteFile.d.ts +7 -0
- package/dist/types/cli/dataLoader/patchMFConfig.d.ts +10 -0
- package/dist/types/cli/dataLoader/plugin.d.ts +6 -0
- package/dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts +2 -2
- package/dist/types/cli/mfRuntimePlugins/node.d.ts +3 -0
- package/dist/types/cli/server/dataLoaderPlugin.d.ts +10 -0
- package/dist/types/cli/server/fetchRemoteFullRoutesMap.d.ts +10 -0
- package/dist/types/cli/utils.d.ts +2 -0
- package/dist/types/constant.d.ts +10 -0
- package/dist/types/interfaces/route.d.ts +12 -0
- package/dist/types/runtime/dataLoader/plugin.d.ts +2 -0
- package/dist/types/runtime/dataLoader/utils.d.ts +19 -0
- package/dist/types/runtime/index.d.ts +1 -0
- package/dist/types/runtime/utils.d.ts +2 -0
- package/dist/types/runtime/withMFRouteId.d.ts +1 -0
- package/dist/types/types/index.d.ts +9 -0
- package/package.json +40 -11
- package/dist/esm/cli/constant.js +0 -4
- package/dist/esm-node/cli/constant.js +0 -4
- package/dist/types/cli/constant.d.ts +0 -1
package/dist/cjs/cli/index.js
CHANGED
|
@@ -27,6 +27,7 @@ var import_enhanced = require("@module-federation/enhanced");
|
|
|
27
27
|
var import_rspack = require("@module-federation/enhanced/rspack");
|
|
28
28
|
var import_configPlugin = require("./configPlugin");
|
|
29
29
|
var import_ssrPlugin = require("./ssrPlugin");
|
|
30
|
+
var import_plugin = require("./dataLoader/plugin");
|
|
30
31
|
var import_enhanced2 = require("@module-federation/enhanced");
|
|
31
32
|
const moduleFederationPlugin = (userConfig = {}) => {
|
|
32
33
|
const internalModernPluginOptions = {
|
|
@@ -79,7 +80,10 @@ const moduleFederationPlugin = (userConfig = {}) => {
|
|
|
79
80
|
},
|
|
80
81
|
usePlugins: [
|
|
81
82
|
(0, import_configPlugin.moduleFederationConfigPlugin)(internalModernPluginOptions),
|
|
82
|
-
(0, import_ssrPlugin.moduleFederationSSRPlugin)(internalModernPluginOptions)
|
|
83
|
+
(0, import_ssrPlugin.moduleFederationSSRPlugin)(internalModernPluginOptions),
|
|
84
|
+
(0, import_plugin.moduleFederationDataLoaderPlugin)(Boolean(userConfig.dataLoader), internalModernPluginOptions, {
|
|
85
|
+
...typeof userConfig.dataLoader === "boolean" ? {} : userConfig.dataLoader
|
|
86
|
+
})
|
|
83
87
|
]
|
|
84
88
|
};
|
|
85
89
|
};
|
|
@@ -31,14 +31,11 @@ __export(inject_node_fetch_exports, {
|
|
|
31
31
|
default: () => inject_node_fetch_default
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(inject_node_fetch_exports);
|
|
34
|
-
var
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
return args;
|
|
42
|
-
}
|
|
34
|
+
var import_runtimePlugin = __toESM(require("@module-federation/node/runtimePlugin"));
|
|
35
|
+
const isContainer = typeof __filename === "string" ? __filename.includes("remote") ? true : false : false;
|
|
36
|
+
const pluginName = `node-plugin-${isContainer}`;
|
|
37
|
+
const nodePlugin = () => ({
|
|
38
|
+
name: pluginName,
|
|
39
|
+
beforeInit: (0, import_runtimePlugin.default)().beforeInit
|
|
43
40
|
});
|
|
44
|
-
var inject_node_fetch_default =
|
|
41
|
+
var inject_node_fetch_default = nodePlugin;
|
|
@@ -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 node_exports = {};
|
|
30
|
+
__export(node_exports, {
|
|
31
|
+
default: () => node_default
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(node_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 node_default = injectNodeFetchPlugin;
|
|
@@ -39,44 +39,46 @@ function replaceObjectLocalhost(key, obj) {
|
|
|
39
39
|
function replaceLocalhost(url) {
|
|
40
40
|
return url.replace(import_constant.LOCALHOST, ipv4);
|
|
41
41
|
}
|
|
42
|
-
const resolveEntryIpv4Plugin = () =>
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
42
|
+
const resolveEntryIpv4Plugin = () => {
|
|
43
|
+
return {
|
|
44
|
+
name: "resolve-entry-ipv4",
|
|
45
|
+
beforeRegisterRemote(args) {
|
|
46
|
+
const { remote } = args;
|
|
47
|
+
replaceObjectLocalhost("entry", remote);
|
|
48
|
+
return args;
|
|
49
|
+
},
|
|
50
|
+
async afterResolve(args) {
|
|
51
|
+
const { remoteInfo } = args;
|
|
52
|
+
replaceObjectLocalhost("entry", remoteInfo);
|
|
53
|
+
return args;
|
|
54
|
+
},
|
|
55
|
+
beforeLoadRemoteSnapshot(args) {
|
|
56
|
+
const { moduleInfo } = args;
|
|
57
|
+
if ("entry" in moduleInfo) {
|
|
58
|
+
replaceObjectLocalhost("entry", moduleInfo);
|
|
59
|
+
return args;
|
|
60
|
+
}
|
|
61
|
+
if ("version" in moduleInfo) {
|
|
62
|
+
replaceObjectLocalhost("version", moduleInfo);
|
|
63
|
+
}
|
|
64
|
+
return args;
|
|
65
|
+
},
|
|
66
|
+
loadRemoteSnapshot(args) {
|
|
67
|
+
const { remoteSnapshot } = args;
|
|
68
|
+
if ("publicPath" in remoteSnapshot) {
|
|
69
|
+
replaceObjectLocalhost("publicPath", remoteSnapshot);
|
|
70
|
+
}
|
|
71
|
+
if ("getPublicPath" in remoteSnapshot) {
|
|
72
|
+
replaceObjectLocalhost("getPublicPath", remoteSnapshot);
|
|
73
|
+
}
|
|
74
|
+
if (remoteSnapshot.remotesInfo) {
|
|
75
|
+
Object.keys(remoteSnapshot.remotesInfo).forEach((key) => {
|
|
76
|
+
const remoteInfo = remoteSnapshot.remotesInfo[key];
|
|
77
|
+
replaceObjectLocalhost("matchedVersion", remoteInfo);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
58
80
|
return args;
|
|
59
81
|
}
|
|
60
|
-
|
|
61
|
-
|
|
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
|
+
};
|
|
83
|
+
};
|
|
82
84
|
var resolve_entry_ipv4_default = resolveEntryIpv4Plugin;
|
|
@@ -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 dataLoaderPlugin_exports = {};
|
|
20
|
+
__export(dataLoaderPlugin_exports, {
|
|
21
|
+
default: () => dataLoaderPlugin_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(dataLoaderPlugin_exports);
|
|
24
|
+
var import_runtime = require("@module-federation/enhanced/runtime");
|
|
25
|
+
var import_sdk = require("@module-federation/sdk");
|
|
26
|
+
var import_fetchRemoteFullRoutesMap = require("./fetchRemoteFullRoutesMap");
|
|
27
|
+
var import_utils = require("../../runtime/dataLoader/utils");
|
|
28
|
+
var import_constant = require("../../constant");
|
|
29
|
+
var dataLoaderPlugin_default = ({ runtimeOptions, partialSSRRemotes, ssrByRouteIdsMap }) => ({
|
|
30
|
+
name: "MFDataLoaderServerPlugin",
|
|
31
|
+
pre: [
|
|
32
|
+
"@modern-js/plugin-inject-resource"
|
|
33
|
+
],
|
|
34
|
+
setup(api) {
|
|
35
|
+
const { remotes, name } = runtimeOptions;
|
|
36
|
+
if (!remotes.length) {
|
|
37
|
+
return {};
|
|
38
|
+
}
|
|
39
|
+
let isHandled = false;
|
|
40
|
+
return {
|
|
41
|
+
prepare() {
|
|
42
|
+
const { middlewares } = api.useAppContext();
|
|
43
|
+
middlewares.push({
|
|
44
|
+
name: "MFDataLoaderServerPlugin",
|
|
45
|
+
handler: async (c, next) => {
|
|
46
|
+
const serverManifest = c.get("serverManifest");
|
|
47
|
+
const { loaderBundles, nestedRoutesJson } = serverManifest;
|
|
48
|
+
if (isHandled) {
|
|
49
|
+
await next();
|
|
50
|
+
} else {
|
|
51
|
+
var _api_useConfigContext_server;
|
|
52
|
+
const instance = (0, import_runtime.init)({
|
|
53
|
+
name,
|
|
54
|
+
remotes
|
|
55
|
+
});
|
|
56
|
+
const remoteFullRoutesMap = await (0, import_fetchRemoteFullRoutesMap.fetchRemoteFullRoutesMap)({
|
|
57
|
+
instance,
|
|
58
|
+
remotePath: (0, import_sdk.isBrowserEnv)() ? `${import_constant.DEFAULT_ENTRY}/${import_constant.MF_ROUTES}` : `${import_constant.DEFAULT_ENTRY}/${import_constant.MODERN_JS_ROUTE_SERVER_LOADER}`
|
|
59
|
+
});
|
|
60
|
+
const originalSSRByRouteIds = (_api_useConfigContext_server = api.useConfigContext().server) === null || _api_useConfigContext_server === void 0 ? void 0 : _api_useConfigContext_server.ssrByRouteIds;
|
|
61
|
+
if (originalSSRByRouteIds && partialSSRRemotes.length) {
|
|
62
|
+
const remoteSSRByRouteIds = (0, import_fetchRemoteFullRoutesMap.getSSRByRouteIds)(partialSSRRemotes, remoteFullRoutesMap) || [];
|
|
63
|
+
const ssrByRouteIds = /* @__PURE__ */ new Set([
|
|
64
|
+
...originalSSRByRouteIds,
|
|
65
|
+
...remoteSSRByRouteIds.map((id) => ssrByRouteIdsMap[id] || id)
|
|
66
|
+
]);
|
|
67
|
+
api.useConfigContext().server.ssrByRouteIds = Array.from(ssrByRouteIds);
|
|
68
|
+
}
|
|
69
|
+
(0, import_utils.injectRemoteRoutes)(loaderBundles, remoteFullRoutesMap);
|
|
70
|
+
(0, import_utils.injectRemoteRoutes)(nestedRoutesJson, remoteFullRoutesMap);
|
|
71
|
+
isHandled = true;
|
|
72
|
+
await next();
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
before: [
|
|
76
|
+
"render"
|
|
77
|
+
]
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
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 fetchRemoteFullRoutesMap_exports = {};
|
|
20
|
+
__export(fetchRemoteFullRoutesMap_exports, {
|
|
21
|
+
fetchRemoteFullRoutesMap: () => fetchRemoteFullRoutesMap,
|
|
22
|
+
getSSRByRouteIds: () => getSSRByRouteIds
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(fetchRemoteFullRoutesMap_exports);
|
|
25
|
+
async function fetchRemoteFullRoutesMap(options) {
|
|
26
|
+
const { instance, remotePath } = options;
|
|
27
|
+
const { remotes } = instance.options;
|
|
28
|
+
const remoteRoutesMap = {};
|
|
29
|
+
if (!remotes.length) {
|
|
30
|
+
return remoteRoutesMap;
|
|
31
|
+
}
|
|
32
|
+
await Promise.all(remotes.map(async (remote) => {
|
|
33
|
+
const remoteId = `${remote.name}/${remotePath}`;
|
|
34
|
+
const { routes } = await instance.loadRemote(remoteId);
|
|
35
|
+
remoteRoutesMap[remote.name] = {
|
|
36
|
+
routes
|
|
37
|
+
};
|
|
38
|
+
}));
|
|
39
|
+
return remoteRoutesMap;
|
|
40
|
+
}
|
|
41
|
+
function getSSRByRouteIds(partialSSRRemotes, remoteRoutesMap) {
|
|
42
|
+
const remoteProviderRouteIds = /* @__PURE__ */ new Set();
|
|
43
|
+
const collectIds = (route) => {
|
|
44
|
+
remoteProviderRouteIds.add(route.id);
|
|
45
|
+
if (route.children) {
|
|
46
|
+
route.children.forEach((r) => {
|
|
47
|
+
collectIds(r);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
Object.entries(remoteRoutesMap).forEach((item) => {
|
|
52
|
+
const [remoteName, routesObj] = item;
|
|
53
|
+
if (!partialSSRRemotes.includes(remoteName)) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const { routes } = routesObj;
|
|
57
|
+
routes.forEach((route) => {
|
|
58
|
+
collectIds(route);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
return [
|
|
62
|
+
...remoteProviderRouteIds
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
+
0 && (module.exports = {
|
|
67
|
+
fetchRemoteFullRoutesMap,
|
|
68
|
+
getSSRByRouteIds
|
|
69
|
+
});
|
|
@@ -39,7 +39,7 @@ var import_webpack = require("@module-federation/enhanced/webpack");
|
|
|
39
39
|
var import_rspack = require("@module-federation/enhanced/rspack");
|
|
40
40
|
var import_universe_entry_chunk_tracker_plugin = __toESM(require("@module-federation/node/universe-entry-chunk-tracker-plugin"));
|
|
41
41
|
var import_manifest = require("./manifest");
|
|
42
|
-
var import_constant = require("
|
|
42
|
+
var import_constant = require("../constant");
|
|
43
43
|
function setEnv() {
|
|
44
44
|
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
45
45
|
process.env["MF_SSR_PRJ"] = "true";
|
package/dist/cjs/cli/utils.js
CHANGED
|
@@ -32,7 +32,8 @@ __export(utils_exports, {
|
|
|
32
32
|
getMFConfig: () => getMFConfig,
|
|
33
33
|
patchBundlerConfig: () => patchBundlerConfig,
|
|
34
34
|
patchIgnoreWarning: () => patchIgnoreWarning,
|
|
35
|
-
patchMFConfig: () => patchMFConfig
|
|
35
|
+
patchMFConfig: () => patchMFConfig,
|
|
36
|
+
replaceRemoteUrl: () => replaceRemoteUrl
|
|
36
37
|
});
|
|
37
38
|
module.exports = __toCommonJS(utils_exports);
|
|
38
39
|
var import_sdk = require("@module-federation/sdk");
|
|
@@ -84,7 +85,9 @@ const replaceRemoteUrl = (mfConfig, remoteIpStrategy) => {
|
|
|
84
85
|
if (typeof remoteObject === "string") {
|
|
85
86
|
return;
|
|
86
87
|
}
|
|
87
|
-
|
|
88
|
+
if ("entry" in remoteObject && typeof remoteObject.entry === "string") {
|
|
89
|
+
remoteObject.entry = remoteObject.entry.replace(import_constant.LOCALHOST, ipv4);
|
|
90
|
+
}
|
|
88
91
|
});
|
|
89
92
|
} else if (typeof mfConfig.remotes !== "string") {
|
|
90
93
|
handleRemoteObject(mfConfig.remotes);
|
|
@@ -139,7 +142,7 @@ const patchMFConfig = (mfConfig, isServer, remoteIpStrategy) => {
|
|
|
139
142
|
injectRuntimePlugins(import_path.default.resolve(__dirname, "./mfRuntimePlugins/resolve-entry-ipv4.js"), runtimePlugins);
|
|
140
143
|
}
|
|
141
144
|
if (isServer) {
|
|
142
|
-
injectRuntimePlugins(require.resolve("
|
|
145
|
+
injectRuntimePlugins(require.resolve("./mfRuntimePlugins/node.js"), runtimePlugins);
|
|
143
146
|
if (isDev) {
|
|
144
147
|
injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
|
|
145
148
|
}
|
|
@@ -329,5 +332,6 @@ function autoDeleteSplitChunkCacheGroups(mfConfig, bundlerConfig) {
|
|
|
329
332
|
getMFConfig,
|
|
330
333
|
patchBundlerConfig,
|
|
331
334
|
patchIgnoreWarning,
|
|
332
|
-
patchMFConfig
|
|
335
|
+
patchMFConfig,
|
|
336
|
+
replaceRemoteUrl
|
|
333
337
|
});
|
|
@@ -61,7 +61,7 @@ const mfConfig = {
|
|
|
61
61
|
remoteType: "script",
|
|
62
62
|
runtimePlugins: [
|
|
63
63
|
import_path.default.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"),
|
|
64
|
-
require.resolve("
|
|
64
|
+
require.resolve("./mfRuntimePlugins/node.js"),
|
|
65
65
|
import_path.default.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js")
|
|
66
66
|
],
|
|
67
67
|
shared: {
|
package/dist/cjs/constant.js
CHANGED
|
@@ -18,17 +18,47 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var constant_exports = {};
|
|
20
20
|
__export(constant_exports, {
|
|
21
|
+
DEFAULT_ENTRY: () => DEFAULT_ENTRY,
|
|
22
|
+
DEFAULT_LAYOUT: () => DEFAULT_LAYOUT,
|
|
23
|
+
FOLD_IDENTIFIER: () => FOLD_IDENTIFIER,
|
|
21
24
|
LOCALHOST: () => LOCALHOST,
|
|
25
|
+
META_NAME: () => META_NAME,
|
|
26
|
+
MF_JSON: () => MF_JSON,
|
|
27
|
+
MF_ROUTES: () => MF_ROUTES,
|
|
28
|
+
MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME: () => MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME,
|
|
29
|
+
MODERN_JS_ROUTE_SERVER_LOADER: () => MODERN_JS_ROUTE_SERVER_LOADER,
|
|
22
30
|
MODERN_JS_SERVER_DIR: () => MODERN_JS_SERVER_DIR,
|
|
23
|
-
PLUGIN_IDENTIFIER: () => PLUGIN_IDENTIFIER
|
|
31
|
+
PLUGIN_IDENTIFIER: () => PLUGIN_IDENTIFIER,
|
|
32
|
+
SEPARATOR: () => SEPARATOR,
|
|
33
|
+
isDev: () => isDev
|
|
24
34
|
});
|
|
25
35
|
module.exports = __toCommonJS(constant_exports);
|
|
26
36
|
const MODERN_JS_SERVER_DIR = "bundles";
|
|
27
37
|
const LOCALHOST = "localhost";
|
|
28
38
|
const PLUGIN_IDENTIFIER = "[ Modern.js Module Federation ]";
|
|
39
|
+
const isDev = process.env.NODE_ENV === "development";
|
|
40
|
+
const MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME = "routes";
|
|
41
|
+
const MODERN_JS_ROUTE_SERVER_LOADER = "route-server-loaders";
|
|
42
|
+
const META_NAME = "modern-js";
|
|
43
|
+
const FOLD_IDENTIFIER = "@mf";
|
|
44
|
+
const SEPARATOR = "_";
|
|
45
|
+
const MF_ROUTES = "mf-routes";
|
|
46
|
+
const DEFAULT_ENTRY = "main";
|
|
47
|
+
const DEFAULT_LAYOUT = "layout";
|
|
48
|
+
const MF_JSON = "mf.json";
|
|
29
49
|
// Annotate the CommonJS export names for ESM import in node:
|
|
30
50
|
0 && (module.exports = {
|
|
51
|
+
DEFAULT_ENTRY,
|
|
52
|
+
DEFAULT_LAYOUT,
|
|
53
|
+
FOLD_IDENTIFIER,
|
|
31
54
|
LOCALHOST,
|
|
55
|
+
META_NAME,
|
|
56
|
+
MF_JSON,
|
|
57
|
+
MF_ROUTES,
|
|
58
|
+
MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME,
|
|
59
|
+
MODERN_JS_ROUTE_SERVER_LOADER,
|
|
32
60
|
MODERN_JS_SERVER_DIR,
|
|
33
|
-
PLUGIN_IDENTIFIER
|
|
61
|
+
PLUGIN_IDENTIFIER,
|
|
62
|
+
SEPARATOR,
|
|
63
|
+
isDev
|
|
34
64
|
});
|
|
@@ -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 route_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(route_exports);
|
|
@@ -0,0 +1,73 @@
|
|
|
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 plugin_exports = {};
|
|
20
|
+
__export(plugin_exports, {
|
|
21
|
+
ssrDataLoaderPlugin: () => ssrDataLoaderPlugin
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(plugin_exports);
|
|
24
|
+
var import_runtime = require("@module-federation/enhanced/runtime");
|
|
25
|
+
var import_constant = require("../../constant");
|
|
26
|
+
var import_utils = require("./utils");
|
|
27
|
+
const ssrDataLoaderPlugin = () => {
|
|
28
|
+
return {
|
|
29
|
+
name: "@modern-js/plugin-mf-data-loader",
|
|
30
|
+
post: [
|
|
31
|
+
"@modern-js/plugin-router"
|
|
32
|
+
],
|
|
33
|
+
setup: () => {
|
|
34
|
+
const remoteRoutesMap = {};
|
|
35
|
+
return {
|
|
36
|
+
async beforeRender() {
|
|
37
|
+
console.log("init");
|
|
38
|
+
if (Object.keys(remoteRoutesMap).length) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const instance = (0, import_runtime.getInstance)();
|
|
42
|
+
if (!instance) {
|
|
43
|
+
console.log("no instance!");
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (!instance.options.remotes.length) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
await Promise.all(instance.options.remotes.map(async (remote) => {
|
|
50
|
+
const remoteId = `${remote.name}/${import_constant.DEFAULT_ENTRY}/${import_constant.MF_ROUTES}`;
|
|
51
|
+
const { routes } = await instance.loadRemote(remoteId);
|
|
52
|
+
remoteRoutesMap[remote.name] = {
|
|
53
|
+
routes
|
|
54
|
+
};
|
|
55
|
+
}));
|
|
56
|
+
},
|
|
57
|
+
// runtime plugin not save route , so it needs to inject again when trigger
|
|
58
|
+
modifyRoutes: (routes) => {
|
|
59
|
+
(0, import_utils.injectRemoteRoutes)({
|
|
60
|
+
entry: {
|
|
61
|
+
routes
|
|
62
|
+
}
|
|
63
|
+
}, remoteRoutesMap);
|
|
64
|
+
return routes;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
71
|
+
0 && (module.exports = {
|
|
72
|
+
ssrDataLoaderPlugin
|
|
73
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
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 utils_exports = {};
|
|
20
|
+
__export(utils_exports, {
|
|
21
|
+
getRemoteLayoutId: () => getRemoteLayoutId,
|
|
22
|
+
getRemoteRoutesInfos: () => getRemoteRoutesInfos,
|
|
23
|
+
injectRemoteRoutes: () => injectRemoteRoutes
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(utils_exports);
|
|
26
|
+
var import_constant = require("../../constant");
|
|
27
|
+
var import_utils = require("../utils");
|
|
28
|
+
function getRemoteRoutesInfos(route, remoteRoutesMap) {
|
|
29
|
+
if (!route.id) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const remoteName = (0, import_utils.transformPrefix2Name)(route.id);
|
|
33
|
+
const remoteRouteObj = remoteRoutesMap[remoteName];
|
|
34
|
+
if (!remoteRouteObj) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const remoteRoutes = remoteRouteObj.routes[0];
|
|
38
|
+
return {
|
|
39
|
+
routes: remoteRoutes,
|
|
40
|
+
name: remoteName,
|
|
41
|
+
pathName: route.path
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function getRemoteLayoutId(remoteName) {
|
|
45
|
+
const prefix = (0, import_utils.transformName2Prefix)(remoteName);
|
|
46
|
+
return `${prefix}${import_constant.DEFAULT_LAYOUT}`;
|
|
47
|
+
}
|
|
48
|
+
function injectRemoteRoutes(initialRoutes, remoteRoutesMap) {
|
|
49
|
+
const traverse = (route) => {
|
|
50
|
+
var _route_children;
|
|
51
|
+
const remoteRoutesInfos = getRemoteRoutesInfos(route, remoteRoutesMap);
|
|
52
|
+
if (remoteRoutesInfos) {
|
|
53
|
+
const { routes, pathName } = remoteRoutesInfos;
|
|
54
|
+
route.id = routes.id;
|
|
55
|
+
route.path = pathName;
|
|
56
|
+
if (routes.loader) {
|
|
57
|
+
route.loader = routes.loader;
|
|
58
|
+
}
|
|
59
|
+
if (routes.children) {
|
|
60
|
+
route.children = routes.children;
|
|
61
|
+
}
|
|
62
|
+
route.element = routes.element;
|
|
63
|
+
route.Component = routes.Component;
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
(_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.forEach((r) => {
|
|
67
|
+
traverse(r);
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
Object.keys(initialRoutes).forEach((entryName) => {
|
|
71
|
+
const routes = initialRoutes[entryName];
|
|
72
|
+
if (Array.isArray(routes)) {
|
|
73
|
+
routes.forEach((route) => {
|
|
74
|
+
traverse(route);
|
|
75
|
+
});
|
|
76
|
+
} else {
|
|
77
|
+
var _routes_routes;
|
|
78
|
+
routes === null || routes === void 0 ? void 0 : (_routes_routes = routes.routes) === null || _routes_routes === void 0 ? void 0 : _routes_routes.forEach((r) => {
|
|
79
|
+
traverse(r);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
85
|
+
0 && (module.exports = {
|
|
86
|
+
getRemoteLayoutId,
|
|
87
|
+
getRemoteRoutesInfos,
|
|
88
|
+
injectRemoteRoutes
|
|
89
|
+
});
|
|
@@ -19,13 +19,16 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
|
|
|
19
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
20
|
var runtime_exports = {};
|
|
21
21
|
__export(runtime_exports, {
|
|
22
|
-
createRemoteSSRComponent: () => import_createRemoteSSRComponent.createRemoteSSRComponent
|
|
22
|
+
createRemoteSSRComponent: () => import_createRemoteSSRComponent.createRemoteSSRComponent,
|
|
23
|
+
withMFRouteId: () => import_withMFRouteId.withMFRouteId
|
|
23
24
|
});
|
|
24
25
|
module.exports = __toCommonJS(runtime_exports);
|
|
25
26
|
__reExport(runtime_exports, require("@module-federation/enhanced/runtime"), module.exports);
|
|
26
27
|
var import_createRemoteSSRComponent = require("./createRemoteSSRComponent");
|
|
28
|
+
var import_withMFRouteId = require("./withMFRouteId");
|
|
27
29
|
// Annotate the CommonJS export names for ESM import in node:
|
|
28
30
|
0 && (module.exports = {
|
|
29
31
|
createRemoteSSRComponent,
|
|
32
|
+
withMFRouteId,
|
|
30
33
|
...require("@module-federation/enhanced/runtime")
|
|
31
34
|
});
|
|
@@ -0,0 +1,38 @@
|
|
|
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 utils_exports = {};
|
|
20
|
+
__export(utils_exports, {
|
|
21
|
+
transformName2Prefix: () => transformName2Prefix,
|
|
22
|
+
transformPrefix2Name: () => transformPrefix2Name
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(utils_exports);
|
|
25
|
+
var import_sdk = require("@module-federation/sdk");
|
|
26
|
+
const SPLIT_SYMBOL = "@";
|
|
27
|
+
function transformName2Prefix(name) {
|
|
28
|
+
return `${(0, import_sdk.encodeName)(name, "", false)}${SPLIT_SYMBOL}`;
|
|
29
|
+
}
|
|
30
|
+
function transformPrefix2Name(prefix) {
|
|
31
|
+
const realPrefix = prefix.split(SPLIT_SYMBOL)[0];
|
|
32
|
+
return (0, import_sdk.decodeName)(realPrefix, "", false);
|
|
33
|
+
}
|
|
34
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
+
0 && (module.exports = {
|
|
36
|
+
transformName2Prefix,
|
|
37
|
+
transformPrefix2Name
|
|
38
|
+
});
|