@module-federation/modern-js 0.0.0-next-20241017102355 → 0.0.0-next-20241018034800
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/{routes/ast/index.js → constant.js} +6 -6
- package/dist/cjs/cli/index.js +2 -7
- package/dist/cjs/cli/mfRuntimePlugins/{node-fetch.js → inject-node-fetch.js} +6 -6
- package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +38 -40
- package/dist/cjs/{runtime/withMFRouteId.js → cli/mfRuntimePlugins/shared-strategy.js} +23 -11
- package/dist/cjs/cli/ssrPlugin.js +2 -5
- package/dist/cjs/cli/utils.js +6 -11
- package/dist/cjs/cli/utils.spec.js +6 -5
- package/dist/cjs/constant.js +2 -35
- package/dist/cjs/runtime/index.js +1 -4
- package/dist/cjs/ssr-runtime/plugin.js +8 -7
- package/dist/esm/cli/constant.js +4 -0
- package/dist/esm/cli/index.js +2 -7
- package/dist/esm/cli/mfRuntimePlugins/{node-fetch.js → inject-node-fetch.js} +3 -3
- package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +25 -0
- package/dist/esm/cli/ssrPlugin.js +3 -6
- package/dist/esm/cli/utils.js +5 -9
- package/dist/esm/cli/utils.spec.js +6 -5
- package/dist/esm/constant.js +1 -23
- package/dist/esm/runtime/index.js +1 -3
- package/dist/esm/ssr-runtime/plugin.js +11 -8
- package/dist/esm-node/cli/constant.js +4 -0
- package/dist/esm-node/cli/index.js +2 -7
- package/dist/esm-node/cli/mfRuntimePlugins/{node-fetch.js → inject-node-fetch.js} +3 -3
- package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +38 -40
- package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +23 -0
- package/dist/esm-node/cli/ssrPlugin.js +2 -5
- package/dist/esm-node/cli/utils.js +5 -9
- package/dist/esm-node/cli/utils.spec.js +6 -5
- package/dist/esm-node/constant.js +1 -23
- package/dist/esm-node/runtime/index.js +1 -3
- package/dist/esm-node/ssr-runtime/plugin.js +8 -7
- package/dist/types/cli/constant.d.ts +1 -0
- package/dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts +3 -0
- package/dist/types/cli/utils.d.ts +0 -2
- package/dist/types/constant.d.ts +0 -11
- package/dist/types/runtime/index.d.ts +0 -1
- package/dist/types/ssr-runtime/plugin.d.ts +1 -3
- package/dist/types/types/index.d.ts +1 -3
- package/package.json +12 -49
- package/dist/cjs/cli/mfRuntimePlugins/node.js +0 -41
- package/dist/cjs/cli/routes/ast/constant.js +0 -49
- package/dist/cjs/cli/routes/ast/generateRoutes.js +0 -143
- package/dist/cjs/cli/routes/clearMFCache.js +0 -57
- package/dist/cjs/cli/routes/exportRoutePlugin.js +0 -77
- package/dist/cjs/cli/routes/importRoutesPlugin.js +0 -120
- package/dist/cjs/cli/routes/plugin.js +0 -157
- package/dist/cjs/cli/routes/traverseRouteFiles.js +0 -148
- package/dist/cjs/cli/routes/utils.js +0 -168
- package/dist/cjs/cli/server/fetchRemoteFullRoutesMap.js +0 -72
- package/dist/cjs/cli/server/fetchRoutePlugin.js +0 -81
- package/dist/cjs/interfaces/route.js +0 -16
- package/dist/cjs/runtime/routes/plugin-inject-assets.js +0 -92
- package/dist/cjs/runtime/routes/plugin.js +0 -75
- package/dist/cjs/runtime/routes/utils.js +0 -115
- package/dist/cjs/types/modern.js +0 -16
- package/dist/cjs/types/routes.js +0 -16
- package/dist/esm/cli/mfRuntimePlugins/node.js +0 -13
- package/dist/esm/cli/routes/ast/constant.js +0 -18
- package/dist/esm/cli/routes/ast/generateRoutes.js +0 -110
- package/dist/esm/cli/routes/ast/index.js +0 -4
- package/dist/esm/cli/routes/clearMFCache.js +0 -34
- package/dist/esm/cli/routes/exportRoutePlugin.js +0 -79
- package/dist/esm/cli/routes/importRoutesPlugin.js +0 -122
- package/dist/esm/cli/routes/plugin.js +0 -266
- package/dist/esm/cli/routes/traverseRouteFiles.js +0 -313
- package/dist/esm/cli/routes/utils.js +0 -130
- package/dist/esm/cli/server/fetchRemoteFullRoutesMap.js +0 -93
- package/dist/esm/cli/server/fetchRoutePlugin.js +0 -104
- package/dist/esm/interfaces/route.js +0 -0
- package/dist/esm/runtime/routes/plugin-inject-assets.js +0 -71
- package/dist/esm/runtime/routes/plugin.js +0 -97
- package/dist/esm/runtime/routes/utils.js +0 -86
- package/dist/esm/runtime/withMFRouteId.js +0 -7
- package/dist/esm/types/modern.js +0 -0
- package/dist/esm/types/routes.js +0 -0
- package/dist/esm-node/cli/mfRuntimePlugins/node.js +0 -11
- package/dist/esm-node/cli/routes/ast/constant.js +0 -18
- package/dist/esm-node/cli/routes/ast/generateRoutes.js +0 -109
- package/dist/esm-node/cli/routes/ast/index.js +0 -4
- package/dist/esm-node/cli/routes/clearMFCache.js +0 -33
- package/dist/esm-node/cli/routes/exportRoutePlugin.js +0 -53
- package/dist/esm-node/cli/routes/importRoutesPlugin.js +0 -96
- package/dist/esm-node/cli/routes/plugin.js +0 -123
- package/dist/esm-node/cli/routes/traverseRouteFiles.js +0 -113
- package/dist/esm-node/cli/routes/utils.js +0 -133
- package/dist/esm-node/cli/server/fetchRemoteFullRoutesMap.js +0 -47
- package/dist/esm-node/cli/server/fetchRoutePlugin.js +0 -61
- package/dist/esm-node/interfaces/route.js +0 -0
- package/dist/esm-node/runtime/routes/plugin-inject-assets.js +0 -68
- package/dist/esm-node/runtime/routes/plugin.js +0 -51
- package/dist/esm-node/runtime/routes/utils.js +0 -86
- package/dist/esm-node/runtime/withMFRouteId.js +0 -7
- 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 +0 -3
- package/dist/types/cli/routes/ast/constant.d.ts +0 -8
- package/dist/types/cli/routes/ast/generateRoutes.d.ts +0 -5
- package/dist/types/cli/routes/ast/index.d.ts +0 -1
- package/dist/types/cli/routes/clearMFCache.d.ts +0 -1
- package/dist/types/cli/routes/exportRoutePlugin.d.ts +0 -4
- package/dist/types/cli/routes/importRoutesPlugin.d.ts +0 -4
- package/dist/types/cli/routes/plugin.d.ts +0 -4
- package/dist/types/cli/routes/traverseRouteFiles.d.ts +0 -11
- package/dist/types/cli/routes/utils.d.ts +0 -11
- package/dist/types/cli/server/fetchRemoteFullRoutesMap.d.ts +0 -11
- package/dist/types/cli/server/fetchRoutePlugin.d.ts +0 -10
- package/dist/types/interfaces/route.d.ts +0 -12
- package/dist/types/runtime/routes/plugin-inject-assets.d.ts +0 -4
- package/dist/types/runtime/routes/plugin.d.ts +0 -5
- package/dist/types/runtime/routes/utils.d.ts +0 -22
- package/dist/types/runtime/withMFRouteId.d.ts +0 -1
- package/dist/types/types/modern.d.ts +0 -12
- package/dist/types/types/routes.d.ts +0 -19
- /package/dist/types/cli/mfRuntimePlugins/{node-fetch.d.ts → inject-node-fetch.d.ts} +0 -0
|
@@ -1,143 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,57 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,77 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,120 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,157 +0,0 @@
|
|
|
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 plugin_exports = {};
|
|
30
|
-
__export(plugin_exports, {
|
|
31
|
-
default: () => plugin_default,
|
|
32
|
-
moduleFederationRoutesPlugin: () => moduleFederationRoutesPlugin
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(plugin_exports);
|
|
35
|
-
var import_path = __toESM(require("path"));
|
|
36
|
-
var import_utils = require("@modern-js/utils");
|
|
37
|
-
var import_utils2 = require("../../runtime/routes/utils");
|
|
38
|
-
var import_constant = require("../../constant");
|
|
39
|
-
var import_traverseRouteFiles = require("./traverseRouteFiles");
|
|
40
|
-
var import_exportRoutePlugin = require("./exportRoutePlugin");
|
|
41
|
-
var import_importRoutesPlugin = require("./importRoutesPlugin");
|
|
42
|
-
var import_utils3 = require("./utils");
|
|
43
|
-
var import_constant2 = require("../../constant");
|
|
44
|
-
const moduleFederationRoutesPlugin = ({ userConfig, internalOptions, serverPlugin, transformRuntimeOptions }) => {
|
|
45
|
-
const entries = /* @__PURE__ */ new Set();
|
|
46
|
-
const remotePathMap = {};
|
|
47
|
-
const ssrByRouteIdsMap = {};
|
|
48
|
-
const internalRoutesPluginOptions = {
|
|
49
|
-
userConfig,
|
|
50
|
-
internalOptions,
|
|
51
|
-
entries,
|
|
52
|
-
remotePathMap,
|
|
53
|
-
ssrByRouteIdsMap,
|
|
54
|
-
serverPlugin,
|
|
55
|
-
transformRuntimeOptions
|
|
56
|
-
};
|
|
57
|
-
return {
|
|
58
|
-
name: "@modern-js/plugin-module-federation-route",
|
|
59
|
-
pre: [
|
|
60
|
-
"@modern-js/plugin-module-federation-config"
|
|
61
|
-
],
|
|
62
|
-
setup: async ({ useAppContext }) => {
|
|
63
|
-
if (!userConfig.exportRoutes && !userConfig.importRoutes) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
const appContext = useAppContext();
|
|
67
|
-
const name = internalOptions.csrConfig.name;
|
|
68
|
-
const { metaName = import_constant.META_NAME } = internalOptions;
|
|
69
|
-
const internalDirectory = appContext.internalDirectory.replace(import_constant.META_NAME, metaName || import_constant.META_NAME);
|
|
70
|
-
const csrConfig = internalOptions.csrConfig;
|
|
71
|
-
if (typeof csrConfig.remotes === "object" && Object.keys(csrConfig.remotes).length) {
|
|
72
|
-
const { entries: scanEntries } = await (0, import_traverseRouteFiles.traverseRouteFiles)({
|
|
73
|
-
appDirectory: appContext.appDirectory,
|
|
74
|
-
generateRouteFile: userConfig.importRoutes,
|
|
75
|
-
remotePathMap
|
|
76
|
-
});
|
|
77
|
-
scanEntries.forEach((e) => entries.add(e));
|
|
78
|
-
} else {
|
|
79
|
-
entries.add(import_constant2.DEFAULT_ENTRY);
|
|
80
|
-
}
|
|
81
|
-
return {
|
|
82
|
-
config: async () => {
|
|
83
|
-
return {
|
|
84
|
-
tools: {
|
|
85
|
-
// bundlerChain can not keep target order
|
|
86
|
-
rspack(_config, { isServer }) {
|
|
87
|
-
(0, import_utils3.addShared)({
|
|
88
|
-
mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
|
|
89
|
-
metaName,
|
|
90
|
-
isServer,
|
|
91
|
-
internalDirectory,
|
|
92
|
-
entries
|
|
93
|
-
});
|
|
94
|
-
},
|
|
95
|
-
// bundlerChain can not keep target order
|
|
96
|
-
webpack(_config, { isServer }) {
|
|
97
|
-
(0, import_utils3.addShared)({
|
|
98
|
-
mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
|
|
99
|
-
metaName,
|
|
100
|
-
isServer,
|
|
101
|
-
internalDirectory,
|
|
102
|
-
entries
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
source: {
|
|
107
|
-
define: {
|
|
108
|
-
MODERN_ROUTER_ID_PREFIX: JSON.stringify((0, import_utils2.transformName2Prefix)(name))
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
},
|
|
113
|
-
async modifyFileSystemRoutes(options) {
|
|
114
|
-
const { routes, entrypoint } = options;
|
|
115
|
-
const { entryName } = entrypoint;
|
|
116
|
-
const prefix = (0, import_utils2.transformName2Prefix)(internalOptions.csrConfig.name);
|
|
117
|
-
const modifyRouteIds = async (route, pathName) => {
|
|
118
|
-
const currentPathName = route.path ? import_path.default.join("/", pathName, route.path) : pathName;
|
|
119
|
-
if (route.id) {
|
|
120
|
-
const originalId = route.id;
|
|
121
|
-
route.originalId = originalId;
|
|
122
|
-
const remoteInfo = remotePathMap[currentPathName];
|
|
123
|
-
if (remoteInfo) {
|
|
124
|
-
const { path: path2, name: name2 } = remoteInfo;
|
|
125
|
-
const remoteIdPrefix = (0, import_utils2.transformName2Prefix)(name2);
|
|
126
|
-
const isLayout = Boolean(route.children);
|
|
127
|
-
const newId = `${remoteIdPrefix}${isLayout ? "layout" : "page"}`;
|
|
128
|
-
ssrByRouteIdsMap[originalId] = newId;
|
|
129
|
-
const content = import_utils.fs.readFileSync(path2, "utf-8");
|
|
130
|
-
await import_utils.fs.writeFile(path2, content.replace(import_constant2.ROUTE_ID, originalId));
|
|
131
|
-
route.id = newId;
|
|
132
|
-
} else {
|
|
133
|
-
route.id = `${prefix}${route.id}`;
|
|
134
|
-
}
|
|
135
|
-
route.children && await Promise.all(route.children.map(async (r) => {
|
|
136
|
-
return await modifyRouteIds(r, currentPathName);
|
|
137
|
-
}));
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
await Promise.all(routes.map(async (route) => {
|
|
141
|
-
await modifyRouteIds(route, entryName === import_constant2.DEFAULT_ENTRY ? "" : entryName);
|
|
142
|
-
}));
|
|
143
|
-
return options;
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
},
|
|
147
|
-
usePlugins: [
|
|
148
|
-
(0, import_exportRoutePlugin.moduleFederationExportRoutePlugin)(internalRoutesPluginOptions),
|
|
149
|
-
(0, import_importRoutesPlugin.moduleFederationImportRoutePlugin)(internalRoutesPluginOptions)
|
|
150
|
-
]
|
|
151
|
-
};
|
|
152
|
-
};
|
|
153
|
-
var plugin_default = moduleFederationRoutesPlugin;
|
|
154
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
155
|
-
0 && (module.exports = {
|
|
156
|
-
moduleFederationRoutesPlugin
|
|
157
|
-
});
|