@module-federation/modern-js 0.0.0-next-20241106033151 → 0.0.0-next-20241106063644
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/index.js +7 -2
- package/dist/cjs/cli/mfRuntimePlugins/{inject-node-fetch.js → node-fetch.js} +6 -6
- package/dist/cjs/cli/mfRuntimePlugins/node.js +41 -0
- package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +40 -38
- package/dist/cjs/cli/routes/ast/constant.js +49 -0
- package/dist/cjs/cli/routes/ast/generateRoutes.js +143 -0
- package/dist/cjs/cli/{constant.js → routes/ast/index.js} +6 -6
- package/dist/cjs/cli/routes/clearMFCache.js +57 -0
- package/dist/cjs/cli/routes/exportRoutePlugin.js +77 -0
- package/dist/cjs/cli/routes/importRoutesPlugin.js +120 -0
- package/dist/cjs/cli/routes/plugin.js +157 -0
- package/dist/cjs/cli/routes/traverseRouteFiles.js +148 -0
- package/dist/cjs/cli/routes/utils.js +168 -0
- package/dist/cjs/cli/server/fetchRemoteFullRoutesMap.js +72 -0
- package/dist/cjs/cli/server/fetchRoutePlugin.js +82 -0
- package/dist/cjs/cli/ssrPlugin.js +5 -2
- package/dist/cjs/cli/utils.js +11 -6
- package/dist/cjs/cli/utils.spec.js +5 -6
- package/dist/cjs/constant.js +35 -2
- package/dist/cjs/interfaces/route.js +16 -0
- package/dist/cjs/runtime/index.js +4 -1
- package/dist/cjs/runtime/routes/plugin-inject-assets.js +92 -0
- package/dist/cjs/runtime/routes/plugin.js +75 -0
- package/dist/cjs/runtime/routes/utils.js +115 -0
- package/dist/cjs/{cli/mfRuntimePlugins/shared-strategy.js → runtime/withMFRouteId.js} +11 -23
- package/dist/cjs/ssr-runtime/plugin.js +7 -8
- package/dist/cjs/types/modern.js +16 -0
- package/dist/cjs/types/routes.js +16 -0
- package/dist/esm/cli/index.js +7 -2
- package/dist/esm/cli/mfRuntimePlugins/{inject-node-fetch.js → node-fetch.js} +3 -3
- package/dist/esm/cli/mfRuntimePlugins/node.js +13 -0
- package/dist/esm/cli/routes/ast/constant.js +18 -0
- package/dist/esm/cli/routes/ast/generateRoutes.js +110 -0
- package/dist/esm/cli/routes/ast/index.js +4 -0
- package/dist/esm/cli/routes/clearMFCache.js +34 -0
- package/dist/esm/cli/routes/exportRoutePlugin.js +79 -0
- package/dist/esm/cli/routes/importRoutesPlugin.js +122 -0
- package/dist/esm/cli/routes/plugin.js +266 -0
- package/dist/esm/cli/routes/traverseRouteFiles.js +313 -0
- package/dist/esm/cli/routes/utils.js +130 -0
- package/dist/esm/cli/server/fetchRemoteFullRoutesMap.js +93 -0
- package/dist/esm/cli/server/fetchRoutePlugin.js +105 -0
- package/dist/esm/cli/ssrPlugin.js +6 -3
- package/dist/esm/cli/utils.js +9 -5
- package/dist/esm/cli/utils.spec.js +5 -6
- package/dist/esm/constant.js +23 -1
- package/dist/esm/interfaces/route.js +0 -0
- package/dist/esm/runtime/index.js +3 -1
- package/dist/esm/runtime/routes/plugin-inject-assets.js +71 -0
- package/dist/esm/runtime/routes/plugin.js +97 -0
- package/dist/esm/runtime/routes/utils.js +86 -0
- package/dist/esm/runtime/withMFRouteId.js +7 -0
- package/dist/esm/ssr-runtime/plugin.js +8 -11
- package/dist/esm/types/modern.js +0 -0
- package/dist/esm/types/routes.js +0 -0
- package/dist/esm-node/cli/index.js +7 -2
- package/dist/esm-node/cli/mfRuntimePlugins/{inject-node-fetch.js → node-fetch.js} +3 -3
- package/dist/esm-node/cli/mfRuntimePlugins/node.js +11 -0
- package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +40 -38
- package/dist/esm-node/cli/routes/ast/constant.js +18 -0
- package/dist/esm-node/cli/routes/ast/generateRoutes.js +109 -0
- package/dist/esm-node/cli/routes/ast/index.js +4 -0
- package/dist/esm-node/cli/routes/clearMFCache.js +33 -0
- package/dist/esm-node/cli/routes/exportRoutePlugin.js +53 -0
- package/dist/esm-node/cli/routes/importRoutesPlugin.js +96 -0
- package/dist/esm-node/cli/routes/plugin.js +123 -0
- package/dist/esm-node/cli/routes/traverseRouteFiles.js +113 -0
- package/dist/esm-node/cli/routes/utils.js +133 -0
- package/dist/esm-node/cli/server/fetchRemoteFullRoutesMap.js +47 -0
- package/dist/esm-node/cli/server/fetchRoutePlugin.js +62 -0
- package/dist/esm-node/cli/ssrPlugin.js +5 -2
- package/dist/esm-node/cli/utils.js +9 -5
- package/dist/esm-node/cli/utils.spec.js +5 -6
- package/dist/esm-node/constant.js +23 -1
- package/dist/esm-node/interfaces/route.js +0 -0
- package/dist/esm-node/runtime/index.js +3 -1
- package/dist/esm-node/runtime/routes/plugin-inject-assets.js +68 -0
- package/dist/esm-node/runtime/routes/plugin.js +51 -0
- package/dist/esm-node/runtime/routes/utils.js +86 -0
- package/dist/esm-node/runtime/withMFRouteId.js +7 -0
- package/dist/esm-node/ssr-runtime/plugin.js +7 -8
- package/dist/esm-node/types/modern.js +0 -0
- package/dist/esm-node/types/routes.js +0 -0
- package/dist/types/cli/mfRuntimePlugins/node.d.ts +3 -0
- package/dist/types/cli/routes/ast/constant.d.ts +8 -0
- package/dist/types/cli/routes/ast/generateRoutes.d.ts +5 -0
- package/dist/types/cli/routes/ast/index.d.ts +1 -0
- package/dist/types/cli/routes/clearMFCache.d.ts +1 -0
- package/dist/types/cli/routes/exportRoutePlugin.d.ts +4 -0
- package/dist/types/cli/routes/importRoutesPlugin.d.ts +4 -0
- package/dist/types/cli/routes/plugin.d.ts +4 -0
- package/dist/types/cli/routes/traverseRouteFiles.d.ts +11 -0
- package/dist/types/cli/routes/utils.d.ts +11 -0
- package/dist/types/cli/server/fetchRemoteFullRoutesMap.d.ts +11 -0
- package/dist/types/cli/server/fetchRoutePlugin.d.ts +10 -0
- package/dist/types/cli/utils.d.ts +2 -0
- package/dist/types/constant.d.ts +11 -0
- package/dist/types/interfaces/route.d.ts +12 -0
- package/dist/types/runtime/index.d.ts +1 -0
- package/dist/types/runtime/routes/plugin-inject-assets.d.ts +4 -0
- package/dist/types/runtime/routes/plugin.d.ts +5 -0
- package/dist/types/runtime/routes/utils.d.ts +22 -0
- package/dist/types/runtime/withMFRouteId.d.ts +1 -0
- package/dist/types/ssr-runtime/plugin.d.ts +3 -1
- package/dist/types/types/index.d.ts +3 -1
- package/dist/types/types/modern.d.ts +12 -0
- package/dist/types/types/routes.d.ts +19 -0
- package/package.json +42 -5
- package/dist/esm/cli/constant.js +0 -4
- package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +0 -25
- package/dist/esm-node/cli/constant.js +0 -4
- package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +0 -23
- package/dist/types/cli/constant.d.ts +0 -1
- package/dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts +0 -3
- /package/dist/types/cli/mfRuntimePlugins/{inject-node-fetch.d.ts → node-fetch.d.ts} +0 -0
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("./routes/plugin");
|
|
30
31
|
var import_enhanced2 = require("@module-federation/enhanced");
|
|
31
32
|
const moduleFederationPlugin = (userConfig = {}) => {
|
|
32
33
|
const internalModernPluginOptions = {
|
|
@@ -36,7 +37,7 @@ const moduleFederationPlugin = (userConfig = {}) => {
|
|
|
36
37
|
nodePlugin: void 0,
|
|
37
38
|
distOutputDir: "",
|
|
38
39
|
originPluginOptions: userConfig,
|
|
39
|
-
remoteIpStrategy:
|
|
40
|
+
remoteIpStrategy: void 0
|
|
40
41
|
};
|
|
41
42
|
return {
|
|
42
43
|
name: "@modern-js/plugin-module-federation",
|
|
@@ -79,7 +80,11 @@ 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.moduleFederationRoutesPlugin)({
|
|
85
|
+
userConfig,
|
|
86
|
+
internalOptions: internalModernPluginOptions
|
|
87
|
+
})
|
|
83
88
|
]
|
|
84
89
|
};
|
|
85
90
|
};
|
|
@@ -26,14 +26,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var
|
|
30
|
-
__export(
|
|
31
|
-
default: () =>
|
|
29
|
+
var node_fetch_exports = {};
|
|
30
|
+
__export(node_fetch_exports, {
|
|
31
|
+
default: () => node_fetch_default
|
|
32
32
|
});
|
|
33
|
-
module.exports = __toCommonJS(
|
|
33
|
+
module.exports = __toCommonJS(node_fetch_exports);
|
|
34
34
|
var import_node_fetch = __toESM(require("node-fetch"));
|
|
35
35
|
const injectNodeFetchPlugin = () => ({
|
|
36
|
-
name: "
|
|
36
|
+
name: "node-fetch-plugin",
|
|
37
37
|
beforeInit(args) {
|
|
38
38
|
if (!globalThis.fetch) {
|
|
39
39
|
globalThis.fetch = import_node_fetch.default;
|
|
@@ -41,4 +41,4 @@ const injectNodeFetchPlugin = () => ({
|
|
|
41
41
|
return args;
|
|
42
42
|
}
|
|
43
43
|
});
|
|
44
|
-
var
|
|
44
|
+
var node_fetch_default = injectNodeFetchPlugin;
|
|
@@ -0,0 +1,41 @@
|
|
|
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_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
|
|
40
|
+
});
|
|
41
|
+
var node_default = nodePlugin;
|
|
@@ -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,49 @@
|
|
|
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
|
+
COMPONENT: () => COMPONENT,
|
|
22
|
+
ELEMENT: () => ELEMENT,
|
|
23
|
+
ID: () => ID,
|
|
24
|
+
IS_ROOT: () => IS_ROOT,
|
|
25
|
+
LAZY_COMPONENT: () => LAZY_COMPONENT,
|
|
26
|
+
LOADER: () => LOADER,
|
|
27
|
+
PRIVATE_COMPONENT: () => PRIVATE_COMPONENT,
|
|
28
|
+
SHOULD_REVALIDATE: () => SHOULD_REVALIDATE
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(constant_exports);
|
|
31
|
+
const IS_ROOT = "isRoot";
|
|
32
|
+
const ID = "id";
|
|
33
|
+
const COMPONENT = "component";
|
|
34
|
+
const LAZY_COMPONENT = "lazyImport";
|
|
35
|
+
const SHOULD_REVALIDATE = "shouldRevalidate";
|
|
36
|
+
const PRIVATE_COMPONENT = "_component";
|
|
37
|
+
const ELEMENT = "element";
|
|
38
|
+
const LOADER = "loader";
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
COMPONENT,
|
|
42
|
+
ELEMENT,
|
|
43
|
+
ID,
|
|
44
|
+
IS_ROOT,
|
|
45
|
+
LAZY_COMPONENT,
|
|
46
|
+
LOADER,
|
|
47
|
+
PRIVATE_COMPONENT,
|
|
48
|
+
SHOULD_REVALIDATE
|
|
49
|
+
});
|
|
@@ -0,0 +1,143 @@
|
|
|
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 generateRoutes_exports = {};
|
|
30
|
+
__export(generateRoutes_exports, {
|
|
31
|
+
generateRoutes: () => generateRoutes
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(generateRoutes_exports);
|
|
34
|
+
var import_fs = __toESM(require("fs"));
|
|
35
|
+
var import_traverse = __toESM(require("@babel/traverse"));
|
|
36
|
+
var babelParser = __toESM(require("@babel/parser"));
|
|
37
|
+
var import_generator = __toESM(require("@babel/generator"));
|
|
38
|
+
var t = __toESM(require("@babel/types"));
|
|
39
|
+
function findTargetKeyNode(nodeProperties, key) {
|
|
40
|
+
return nodeProperties.find((p) => t.isObjectProperty(p) && t.isStringLiteral(p.key) && p.key.value === key);
|
|
41
|
+
}
|
|
42
|
+
function generateRoutes({ sourceCode, filePath }) {
|
|
43
|
+
const ast = babelParser.parse(sourceCode, {
|
|
44
|
+
sourceType: "module"
|
|
45
|
+
});
|
|
46
|
+
const lazyComponentDeclarations = [];
|
|
47
|
+
const componentDeclarations = [];
|
|
48
|
+
let componentId = 0;
|
|
49
|
+
(0, import_traverse.default)(ast, {
|
|
50
|
+
// ImportDeclaration(path) {
|
|
51
|
+
// const source = path.node.source.value;
|
|
52
|
+
// const routeIdMatch = source.match(/routeId=([^&]+)/);
|
|
53
|
+
// if (routeIdMatch) {
|
|
54
|
+
// const originalRouteId = routeIdMatch[1];
|
|
55
|
+
// const newRouteId = `${prefix}${originalRouteId}`;
|
|
56
|
+
// const newSource = source.replace(
|
|
57
|
+
// /routeId=[^&]+/,
|
|
58
|
+
// `routeId=${newRouteId}`,
|
|
59
|
+
// );
|
|
60
|
+
// path.node.source = t.stringLiteral(newSource);
|
|
61
|
+
// }
|
|
62
|
+
// },
|
|
63
|
+
ObjectExpression(path) {
|
|
64
|
+
let componentName = "";
|
|
65
|
+
let lazyComponentName = "";
|
|
66
|
+
if (!Array.isArray(path.node.properties)) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const idNode = findTargetKeyNode(path.node.properties, "id");
|
|
70
|
+
if (idNode && t.isObjectProperty(idNode) && t.isStringLiteral(idNode.value)) {
|
|
71
|
+
}
|
|
72
|
+
const isRootNode = findTargetKeyNode(path.node.properties, "isRoot");
|
|
73
|
+
if (isRootNode && t.isObjectProperty(isRootNode) && t.isBooleanLiteral(isRootNode.value)) {
|
|
74
|
+
isRootNode.value.value = false;
|
|
75
|
+
}
|
|
76
|
+
const lazyComponentNode = findTargetKeyNode(path.node.properties, "lazyImport");
|
|
77
|
+
if (lazyComponentNode && t.isObjectProperty(lazyComponentNode) && t.isArrowFunctionExpression(lazyComponentNode.value)) {
|
|
78
|
+
lazyComponentName = `LazyComponent_${componentId}`;
|
|
79
|
+
const lazyDeclaration = t.variableDeclaration("const", [
|
|
80
|
+
t.variableDeclarator(t.identifier(lazyComponentName), lazyComponentNode.value)
|
|
81
|
+
]);
|
|
82
|
+
lazyComponentNode.value = t.identifier(lazyComponentName);
|
|
83
|
+
const componentNode2 = findTargetKeyNode(path.node.properties, "component");
|
|
84
|
+
if (componentNode2 && t.isObjectProperty(componentNode2) && t.isCallExpression(componentNode2.value) && t.isIdentifier(componentNode2.value.callee)) {
|
|
85
|
+
componentNode2.value = t.callExpression(t.identifier("lazy"), [
|
|
86
|
+
t.identifier(lazyComponentName)
|
|
87
|
+
]);
|
|
88
|
+
}
|
|
89
|
+
lazyComponentDeclarations.push(lazyDeclaration);
|
|
90
|
+
}
|
|
91
|
+
const componentNode = findTargetKeyNode(path.node.properties, "component");
|
|
92
|
+
if (componentNode && t.isObjectProperty(componentNode) && t.isCallExpression(componentNode.value) && t.isIdentifier(componentNode.value.callee)) {
|
|
93
|
+
componentName = `Component_${componentId}`;
|
|
94
|
+
const componentDeclaration = t.variableDeclaration("const", [
|
|
95
|
+
t.variableDeclarator(t.identifier(componentName), lazyComponentName ? t.callExpression(t.identifier("lazy"), [
|
|
96
|
+
t.identifier(lazyComponentName)
|
|
97
|
+
]) : componentNode.value)
|
|
98
|
+
]);
|
|
99
|
+
componentDeclarations.push(componentDeclaration);
|
|
100
|
+
componentNode.value = t.identifier(componentName);
|
|
101
|
+
}
|
|
102
|
+
if (lazyComponentName || componentName) {
|
|
103
|
+
componentId++;
|
|
104
|
+
if (componentName) {
|
|
105
|
+
const upperFirstName = componentName.slice(0, 1).toUpperCase() + componentName.slice(1);
|
|
106
|
+
const jsxElement = t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier(upperFirstName), [], true), null, [], true);
|
|
107
|
+
path.node.properties.push(t.objectProperty(t.identifier("element"), jsxElement));
|
|
108
|
+
} else {
|
|
109
|
+
path.node.properties.push(t.objectProperty(t.identifier("Component"), t.callExpression(t.identifier("lazy"), [
|
|
110
|
+
t.identifier(lazyComponentName)
|
|
111
|
+
])));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
(0, import_traverse.default)(ast, {
|
|
117
|
+
Program(path) {
|
|
118
|
+
const lastImportIndex = path.get("body").reduce((lastIndex, p, index) => {
|
|
119
|
+
if (t.isImportDeclaration(p.node)) {
|
|
120
|
+
lastIndex = index;
|
|
121
|
+
}
|
|
122
|
+
return lastIndex;
|
|
123
|
+
}, -1);
|
|
124
|
+
if (lastImportIndex >= 0) {
|
|
125
|
+
const lastImport = path.get(`body.${lastImportIndex}`);
|
|
126
|
+
[
|
|
127
|
+
...componentDeclarations,
|
|
128
|
+
...lazyComponentDeclarations
|
|
129
|
+
].forEach((declaration) => {
|
|
130
|
+
if ("insertAfter" in lastImport) {
|
|
131
|
+
lastImport.insertAfter(declaration);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
const { code } = (0, import_generator.default)(ast);
|
|
138
|
+
import_fs.default.writeFileSync(filePath, code);
|
|
139
|
+
}
|
|
140
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
141
|
+
0 && (module.exports = {
|
|
142
|
+
generateRoutes
|
|
143
|
+
});
|
|
@@ -16,13 +16,13 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
21
|
-
|
|
19
|
+
var ast_exports = {};
|
|
20
|
+
__export(ast_exports, {
|
|
21
|
+
generateRoutes: () => import_generateRoutes.generateRoutes
|
|
22
22
|
});
|
|
23
|
-
module.exports = __toCommonJS(
|
|
24
|
-
|
|
23
|
+
module.exports = __toCommonJS(ast_exports);
|
|
24
|
+
var import_generateRoutes = require("./generateRoutes");
|
|
25
25
|
// Annotate the CommonJS export names for ESM import in node:
|
|
26
26
|
0 && (module.exports = {
|
|
27
|
-
|
|
27
|
+
generateRoutes
|
|
28
28
|
});
|
|
@@ -0,0 +1,57 @@
|
|
|
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 clearMFCache_exports = {};
|
|
20
|
+
__export(clearMFCache_exports, {
|
|
21
|
+
clearMFCache: () => clearMFCache
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(clearMFCache_exports);
|
|
24
|
+
function clearMFCache() {
|
|
25
|
+
if (!globalThis.__FEDERATION__) {
|
|
26
|
+
console.log("clearMFCache no globalThis.__FEDERATION__");
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
globalThis.__FEDERATION__.__INSTANCES__.map((i) => {
|
|
30
|
+
i.moduleCache.forEach((mc) => {
|
|
31
|
+
if (mc.remoteInfo && mc.remoteInfo.entryGlobalName) {
|
|
32
|
+
delete globalThis[mc.remoteInfo.entryGlobalName];
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
i.moduleCache.clear();
|
|
36
|
+
if (globalThis[i.name]) {
|
|
37
|
+
delete globalThis[i.name];
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
Object.keys(globalThis.__FEDERATION__).forEach((key) => {
|
|
41
|
+
if (Array.isArray(globalThis.__FEDERATION__[key])) {
|
|
42
|
+
globalThis.__FEDERATION__[key] = [];
|
|
43
|
+
} else if (key === "__PRELOADED_MAP__") {
|
|
44
|
+
globalThis.__FEDERATION__[key] = /* @__PURE__ */ new Map();
|
|
45
|
+
} else if (typeof globalThis.__FEDERATION__[key] === "object") {
|
|
46
|
+
globalThis.__FEDERATION__[key] = {};
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
if (globalThis.__GLOBAL_LOADING_REMOTE_ENTRY__) {
|
|
50
|
+
globalThis.__GLOBAL_LOADING_REMOTE_ENTRY__ = {};
|
|
51
|
+
}
|
|
52
|
+
globalThis.FORCE_MF_REFRESH = true;
|
|
53
|
+
}
|
|
54
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
55
|
+
0 && (module.exports = {
|
|
56
|
+
clearMFCache
|
|
57
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
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 exportRoutePlugin_exports = {};
|
|
20
|
+
__export(exportRoutePlugin_exports, {
|
|
21
|
+
default: () => exportRoutePlugin_default,
|
|
22
|
+
moduleFederationExportRoutePlugin: () => moduleFederationExportRoutePlugin
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(exportRoutePlugin_exports);
|
|
25
|
+
var import_constant = require("../../constant");
|
|
26
|
+
var import_utils = require("./utils");
|
|
27
|
+
const moduleFederationExportRoutePlugin = ({ userConfig, internalOptions, entries }) => ({
|
|
28
|
+
name: "@modern-js/plugin-module-federation-export-routes",
|
|
29
|
+
pre: [
|
|
30
|
+
"@modern-js/plugin-module-federation-route"
|
|
31
|
+
],
|
|
32
|
+
post: [
|
|
33
|
+
"@modern-js/plugin-router",
|
|
34
|
+
"@modern-js/plugin-module-federation"
|
|
35
|
+
],
|
|
36
|
+
setup: async ({ useAppContext }) => {
|
|
37
|
+
if (!userConfig.exportRoutes) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const appContext = useAppContext();
|
|
41
|
+
const { metaName = import_constant.META_NAME } = internalOptions;
|
|
42
|
+
const internalDirectory = appContext.internalDirectory.replace(import_constant.META_NAME, metaName || import_constant.META_NAME);
|
|
43
|
+
return {
|
|
44
|
+
config: async () => {
|
|
45
|
+
return {
|
|
46
|
+
tools: {
|
|
47
|
+
// bundlerChain can not keep target order
|
|
48
|
+
rspack(_config, { isServer }) {
|
|
49
|
+
(0, import_utils.addExpose)({
|
|
50
|
+
mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
|
|
51
|
+
metaName,
|
|
52
|
+
isServer,
|
|
53
|
+
internalDirectory,
|
|
54
|
+
entries
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
// bundlerChain can not keep target order
|
|
58
|
+
webpack(_config, { isServer }) {
|
|
59
|
+
(0, import_utils.addExpose)({
|
|
60
|
+
mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
|
|
61
|
+
metaName,
|
|
62
|
+
isServer,
|
|
63
|
+
internalDirectory,
|
|
64
|
+
entries
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
var exportRoutePlugin_default = moduleFederationExportRoutePlugin;
|
|
74
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
75
|
+
0 && (module.exports = {
|
|
76
|
+
moduleFederationExportRoutePlugin
|
|
77
|
+
});
|
|
@@ -0,0 +1,120 @@
|
|
|
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 importRoutesPlugin_exports = {};
|
|
20
|
+
__export(importRoutesPlugin_exports, {
|
|
21
|
+
default: () => importRoutesPlugin_default,
|
|
22
|
+
moduleFederationImportRoutePlugin: () => moduleFederationImportRoutePlugin
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(importRoutesPlugin_exports);
|
|
25
|
+
var import_constant = require("../../constant");
|
|
26
|
+
var import_clearMFCache = require("./clearMFCache");
|
|
27
|
+
function _transformRuntimeOptions(buildOptions) {
|
|
28
|
+
const remotes = buildOptions.remotes || {};
|
|
29
|
+
const runtimeRemotes = Object.entries(remotes).map((remote) => {
|
|
30
|
+
const [alias, nameAndEntry] = remote;
|
|
31
|
+
const [name, entry] = nameAndEntry.split("@");
|
|
32
|
+
return {
|
|
33
|
+
name,
|
|
34
|
+
entry,
|
|
35
|
+
alias
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
return {
|
|
39
|
+
name: buildOptions.name,
|
|
40
|
+
remotes: runtimeRemotes
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const moduleFederationImportRoutePlugin = ({ userConfig, internalOptions, remotePathMap, serverPlugin = "@module-federation/modern-js/fetch-router-server-plugin", ssrByRouteIdsMap, transformRuntimeOptions }) => ({
|
|
44
|
+
name: "@modern-js/plugin-module-federation-import-routes",
|
|
45
|
+
pre: [
|
|
46
|
+
"@modern-js/plugin-module-federation-route"
|
|
47
|
+
],
|
|
48
|
+
post: [
|
|
49
|
+
"@modern-js/plugin-router",
|
|
50
|
+
"@modern-js/plugin-module-federation"
|
|
51
|
+
],
|
|
52
|
+
setup: async () => {
|
|
53
|
+
if (!userConfig.importRoutes) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const { metaName = import_constant.META_NAME } = internalOptions;
|
|
57
|
+
const transformRuntimeFn = transformRuntimeOptions || _transformRuntimeOptions;
|
|
58
|
+
const dataLoaderRemotes = [
|
|
59
|
+
...new Set(Object.values(remotePathMap).map((i) => i.name))
|
|
60
|
+
];
|
|
61
|
+
const serverPluginOptions = {
|
|
62
|
+
runtimeOptions: transformRuntimeFn(internalOptions.csrConfig),
|
|
63
|
+
dataLoaderRemotes,
|
|
64
|
+
ssrByRouteIdsMap
|
|
65
|
+
};
|
|
66
|
+
const hasDataLoaderRemotes = () => Boolean(serverPluginOptions.dataLoaderRemotes.length);
|
|
67
|
+
return {
|
|
68
|
+
_internalRuntimePlugins: ({ entrypoint, plugins }) => {
|
|
69
|
+
if (!hasDataLoaderRemotes()) {
|
|
70
|
+
return {
|
|
71
|
+
entrypoint,
|
|
72
|
+
plugins
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
plugins.push({
|
|
76
|
+
name: "ssrDataLoader",
|
|
77
|
+
path: "@module-federation/modern-js/routes",
|
|
78
|
+
config: {
|
|
79
|
+
metaName,
|
|
80
|
+
dataLoaderRemotes
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
plugins.push({
|
|
84
|
+
name: "ssrDataLoaderInjectAssets",
|
|
85
|
+
path: "@module-federation/modern-js/routes-inject-assets",
|
|
86
|
+
config: {
|
|
87
|
+
metaName,
|
|
88
|
+
dataLoaderRemotes
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
return {
|
|
92
|
+
entrypoint,
|
|
93
|
+
plugins
|
|
94
|
+
};
|
|
95
|
+
},
|
|
96
|
+
_internalServerPlugins({ plugins }) {
|
|
97
|
+
if (!hasDataLoaderRemotes()) {
|
|
98
|
+
return {
|
|
99
|
+
plugins
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
plugins.push({
|
|
103
|
+
name: serverPlugin,
|
|
104
|
+
options: serverPluginOptions
|
|
105
|
+
});
|
|
106
|
+
return {
|
|
107
|
+
plugins
|
|
108
|
+
};
|
|
109
|
+
},
|
|
110
|
+
async afterDev() {
|
|
111
|
+
(0, import_clearMFCache.clearMFCache)();
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
var importRoutesPlugin_default = moduleFederationImportRoutePlugin;
|
|
117
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
118
|
+
0 && (module.exports = {
|
|
119
|
+
moduleFederationImportRoutePlugin
|
|
120
|
+
});
|