@module-federation/modern-js 0.0.0-next-20240918073359 → 0.0.0-next-20240918080432
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/index.js → constant.js} +6 -6
- package/dist/cjs/cli/index.js +1 -5
- 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 +22 -9
- package/dist/esm/cli/constant.js +4 -0
- package/dist/esm/cli/index.js +2 -6
- 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 +8 -13
- 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 +26 -10
- package/dist/esm-node/cli/constant.js +4 -0
- package/dist/esm-node/cli/index.js +1 -5
- 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 +22 -9
- 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 +0 -8
- package/package.json +11 -48
- package/dist/cjs/cli/dataLoader/ast/constant.js +0 -49
- package/dist/cjs/cli/dataLoader/ast/generateRoutes.js +0 -141
- package/dist/cjs/cli/dataLoader/clearMFCache.js +0 -57
- package/dist/cjs/cli/dataLoader/generateRouteFile.js +0 -147
- package/dist/cjs/cli/dataLoader/patchMFConfig.js +0 -137
- package/dist/cjs/cli/dataLoader/plugin.js +0 -208
- package/dist/cjs/cli/mfRuntimePlugins/node.js +0 -41
- package/dist/cjs/cli/server/dataLoaderPlugin.js +0 -86
- package/dist/cjs/cli/server/fetchRemoteFullRoutesMap.js +0 -72
- package/dist/cjs/interfaces/route.js +0 -16
- package/dist/cjs/runtime/dataLoader/plugin-inject-assets.js +0 -94
- package/dist/cjs/runtime/dataLoader/plugin.js +0 -77
- package/dist/cjs/runtime/dataLoader/utils.js +0 -106
- package/dist/esm/cli/dataLoader/ast/constant.js +0 -18
- package/dist/esm/cli/dataLoader/ast/generateRoutes.js +0 -108
- package/dist/esm/cli/dataLoader/ast/index.js +0 -4
- package/dist/esm/cli/dataLoader/clearMFCache.js +0 -34
- package/dist/esm/cli/dataLoader/generateRouteFile.js +0 -307
- package/dist/esm/cli/dataLoader/patchMFConfig.js +0 -103
- package/dist/esm/cli/dataLoader/plugin.js +0 -328
- package/dist/esm/cli/mfRuntimePlugins/node.js +0 -13
- package/dist/esm/cli/server/dataLoaderPlugin.js +0 -109
- package/dist/esm/cli/server/fetchRemoteFullRoutesMap.js +0 -93
- package/dist/esm/interfaces/route.js +0 -0
- package/dist/esm/runtime/dataLoader/plugin-inject-assets.js +0 -73
- package/dist/esm/runtime/dataLoader/plugin.js +0 -99
- package/dist/esm/runtime/dataLoader/utils.js +0 -77
- package/dist/esm/runtime/withMFRouteId.js +0 -7
- package/dist/esm-node/cli/dataLoader/ast/constant.js +0 -18
- package/dist/esm-node/cli/dataLoader/ast/generateRoutes.js +0 -107
- package/dist/esm-node/cli/dataLoader/ast/index.js +0 -4
- package/dist/esm-node/cli/dataLoader/clearMFCache.js +0 -33
- package/dist/esm-node/cli/dataLoader/generateRouteFile.js +0 -112
- package/dist/esm-node/cli/dataLoader/patchMFConfig.js +0 -103
- package/dist/esm-node/cli/dataLoader/plugin.js +0 -173
- package/dist/esm-node/cli/mfRuntimePlugins/node.js +0 -11
- package/dist/esm-node/cli/server/dataLoaderPlugin.js +0 -66
- package/dist/esm-node/cli/server/fetchRemoteFullRoutesMap.js +0 -47
- package/dist/esm-node/interfaces/route.js +0 -0
- package/dist/esm-node/runtime/dataLoader/plugin-inject-assets.js +0 -70
- package/dist/esm-node/runtime/dataLoader/plugin.js +0 -53
- package/dist/esm-node/runtime/dataLoader/utils.js +0 -77
- package/dist/esm-node/runtime/withMFRouteId.js +0 -7
- package/dist/types/cli/dataLoader/ast/constant.d.ts +0 -8
- package/dist/types/cli/dataLoader/ast/generateRoutes.d.ts +0 -5
- package/dist/types/cli/dataLoader/ast/index.d.ts +0 -1
- package/dist/types/cli/dataLoader/clearMFCache.d.ts +0 -1
- package/dist/types/cli/dataLoader/generateRouteFile.d.ts +0 -10
- package/dist/types/cli/dataLoader/patchMFConfig.d.ts +0 -10
- package/dist/types/cli/dataLoader/plugin.d.ts +0 -6
- package/dist/types/cli/mfRuntimePlugins/node.d.ts +0 -3
- package/dist/types/cli/server/dataLoaderPlugin.d.ts +0 -10
- package/dist/types/cli/server/fetchRemoteFullRoutesMap.d.ts +0 -11
- package/dist/types/interfaces/route.d.ts +0 -12
- package/dist/types/runtime/dataLoader/plugin-inject-assets.d.ts +0 -4
- package/dist/types/runtime/dataLoader/plugin.d.ts +0 -5
- package/dist/types/runtime/dataLoader/utils.d.ts +0 -22
- package/dist/types/runtime/withMFRouteId.d.ts +0 -1
- /package/dist/types/cli/mfRuntimePlugins/{node-fetch.d.ts → inject-node-fetch.d.ts} +0 -0
|
@@ -1,49 +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 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
|
-
});
|
|
@@ -1,141 +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
|
-
if (!isRootNode) {
|
|
77
|
-
const lazyComponentNode = findTargetKeyNode(path.node.properties, "lazyImport");
|
|
78
|
-
if (lazyComponentNode && t.isObjectProperty(lazyComponentNode) && t.isArrowFunctionExpression(lazyComponentNode.value)) {
|
|
79
|
-
lazyComponentName = `LazyComponent_${componentId}`;
|
|
80
|
-
const lazyDeclaration = t.variableDeclaration("const", [
|
|
81
|
-
t.variableDeclarator(t.identifier(lazyComponentName), lazyComponentNode.value)
|
|
82
|
-
]);
|
|
83
|
-
lazyComponentNode.value = t.identifier(lazyComponentName);
|
|
84
|
-
const componentNode2 = findTargetKeyNode(path.node.properties, "component");
|
|
85
|
-
if (componentNode2 && t.isObjectProperty(componentNode2) && t.isCallExpression(componentNode2.value) && t.isIdentifier(componentNode2.value.callee)) {
|
|
86
|
-
componentNode2.value = t.callExpression(t.identifier("lazy"), [
|
|
87
|
-
t.identifier(lazyComponentName)
|
|
88
|
-
]);
|
|
89
|
-
}
|
|
90
|
-
lazyComponentDeclarations.push(lazyDeclaration);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
const componentNode = findTargetKeyNode(path.node.properties, "component");
|
|
94
|
-
if (componentNode && t.isObjectProperty(componentNode) && t.isCallExpression(componentNode.value) && t.isIdentifier(componentNode.value.callee)) {
|
|
95
|
-
componentName = `Component_${componentId}`;
|
|
96
|
-
const componentDeclaration = t.variableDeclaration("const", [
|
|
97
|
-
t.variableDeclarator(t.identifier(componentName), lazyComponentName ? t.callExpression(t.identifier("lazy"), [
|
|
98
|
-
t.identifier(lazyComponentName)
|
|
99
|
-
]) : componentNode.value)
|
|
100
|
-
]);
|
|
101
|
-
componentDeclarations.push(componentDeclaration);
|
|
102
|
-
componentNode.value = t.identifier(componentName);
|
|
103
|
-
}
|
|
104
|
-
if (lazyComponentName || componentName) {
|
|
105
|
-
componentId++;
|
|
106
|
-
if (componentName) {
|
|
107
|
-
const upperFirstName = componentName.slice(0, 1).toUpperCase() + componentName.slice(1);
|
|
108
|
-
const jsxElement = t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier(upperFirstName), [], true), null, [], true);
|
|
109
|
-
path.node.properties.push(t.objectProperty(t.identifier("element"), jsxElement));
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
(0, import_traverse.default)(ast, {
|
|
115
|
-
Program(path) {
|
|
116
|
-
const lastImportIndex = path.get("body").reduce((lastIndex, p, index) => {
|
|
117
|
-
if (t.isImportDeclaration(p.node)) {
|
|
118
|
-
lastIndex = index;
|
|
119
|
-
}
|
|
120
|
-
return lastIndex;
|
|
121
|
-
}, -1);
|
|
122
|
-
if (lastImportIndex >= 0) {
|
|
123
|
-
const lastImport = path.get(`body.${lastImportIndex}`);
|
|
124
|
-
[
|
|
125
|
-
...componentDeclarations,
|
|
126
|
-
...lazyComponentDeclarations
|
|
127
|
-
].forEach((declaration) => {
|
|
128
|
-
if ("insertAfter" in lastImport) {
|
|
129
|
-
lastImport.insertAfter(declaration);
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
const { code } = (0, import_generator.default)(ast);
|
|
136
|
-
import_fs.default.writeFileSync(filePath, code);
|
|
137
|
-
}
|
|
138
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
139
|
-
0 && (module.exports = {
|
|
140
|
-
generateRoutes
|
|
141
|
-
});
|
|
@@ -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,147 +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 generateRouteFile_exports = {};
|
|
30
|
-
__export(generateRouteFile_exports, {
|
|
31
|
-
calcPathName: () => calcPathName,
|
|
32
|
-
generateRouteFile: () => generateRouteFile
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(generateRouteFile_exports);
|
|
35
|
-
var import_utils = require("@modern-js/utils");
|
|
36
|
-
var import_path = __toESM(require("path"));
|
|
37
|
-
var import_constant = require("../../constant");
|
|
38
|
-
var import_utils2 = require("../../runtime/dataLoader/utils");
|
|
39
|
-
const ROUTES = "routes";
|
|
40
|
-
function calcPathName(filePath, rootDir, entry) {
|
|
41
|
-
const relativePath = import_path.default.relative(rootDir, filePath);
|
|
42
|
-
const conditionalReg = /^\[(.*)\]$/;
|
|
43
|
-
const splitPaths = relativePath.split("/").reduce((sum, cur) => {
|
|
44
|
-
if (cur.includes(".")) {
|
|
45
|
-
const split = cur.split(".").map((i) => {
|
|
46
|
-
const match = i.match(conditionalReg);
|
|
47
|
-
if (match) {
|
|
48
|
-
return `:${match[1]}`;
|
|
49
|
-
}
|
|
50
|
-
return i.startsWith("__") ? "" : i;
|
|
51
|
-
});
|
|
52
|
-
sum.push(...split);
|
|
53
|
-
} else {
|
|
54
|
-
const match = cur.match(conditionalReg);
|
|
55
|
-
if (match) {
|
|
56
|
-
sum.push(`:${match[1]}`);
|
|
57
|
-
} else {
|
|
58
|
-
if (!cur.startsWith("__")) {
|
|
59
|
-
sum.push(cur);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return sum;
|
|
64
|
-
}, []);
|
|
65
|
-
return import_path.default.join(entry, splitPaths.filter((p) => !!p).join("/"));
|
|
66
|
-
}
|
|
67
|
-
async function generateRouteFile(options) {
|
|
68
|
-
const { appDirectory } = options;
|
|
69
|
-
const entries = [];
|
|
70
|
-
const remotePathMap = {};
|
|
71
|
-
const srcPath = `${appDirectory}/src`;
|
|
72
|
-
const traverse = async (filepath, rootDir, entry) => {
|
|
73
|
-
if (!await import_utils.fs.pathExists(filepath)) {
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
const isDirectory = (await import_utils.fs.stat(filepath)).isDirectory();
|
|
77
|
-
if (!isDirectory) {
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
const items = await import_utils.fs.readdir(filepath);
|
|
81
|
-
const mfJson = items.find((i) => i === import_constant.MF_JSON);
|
|
82
|
-
if (mfJson) {
|
|
83
|
-
const mfJsonContent = await import_utils.fs.readJSON((0, import_utils.normalizeToPosixPath)(import_path.default.join(filepath, mfJson)));
|
|
84
|
-
const { remoteName } = mfJsonContent;
|
|
85
|
-
const remoteLayoutId = (0, import_utils2.getRemoteLayoutId)(remoteName);
|
|
86
|
-
const writeFile = async (id, type, pathname) => {
|
|
87
|
-
const generatedFilePath = (0, import_utils.normalizeToPosixPath)(import_path.default.join(filepath, `${type}.tsx`));
|
|
88
|
-
const content = [
|
|
89
|
-
"// Do not edit this file. It is a auto generated.",
|
|
90
|
-
`// It will render ${remoteName}'s ${type}.`,
|
|
91
|
-
`// The ${type} pathname is: ${pathname}`,
|
|
92
|
-
`// The ${type} route id is: ${import_constant.ROUTE_ID}`
|
|
93
|
-
];
|
|
94
|
-
await import_utils.fs.writeFile(generatedFilePath, content.join("\n"));
|
|
95
|
-
return generatedFilePath;
|
|
96
|
-
};
|
|
97
|
-
if (remoteLayoutId) {
|
|
98
|
-
const pathname = calcPathName(filepath, rootDir, entry);
|
|
99
|
-
const filePath = await writeFile(remoteLayoutId, "layout", pathname);
|
|
100
|
-
remotePathMap[pathname] = {
|
|
101
|
-
name: remoteName,
|
|
102
|
-
path: filePath
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
await Promise.all(items.map(async (item) => {
|
|
108
|
-
await traverse((0, import_utils.normalizeToPosixPath)(import_path.default.join(filepath, item)), rootDir, entry);
|
|
109
|
-
}));
|
|
110
|
-
};
|
|
111
|
-
const traverseRoutes = async (dir, level = 1) => {
|
|
112
|
-
if (level > 3) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
const isDirectory = (await import_utils.fs.stat(dir)).isDirectory();
|
|
116
|
-
if (!isDirectory) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
const items = await import_utils.fs.readdir(dir);
|
|
120
|
-
if (items.find((i) => i === ROUTES)) {
|
|
121
|
-
const entry = import_path.default.relative(srcPath, dir);
|
|
122
|
-
entries.push(entry);
|
|
123
|
-
const rootDir = `${dir}/${ROUTES}`;
|
|
124
|
-
await traverse(rootDir, rootDir, entry);
|
|
125
|
-
} else {
|
|
126
|
-
await Promise.all(items.map(async (item) => {
|
|
127
|
-
await traverseRoutes(import_path.default.join(dir, item), level++);
|
|
128
|
-
}));
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
await traverseRoutes(srcPath);
|
|
132
|
-
const normalizedEntries = entries.map((entry) => {
|
|
133
|
-
if (entry === "") {
|
|
134
|
-
return "main";
|
|
135
|
-
}
|
|
136
|
-
return entry;
|
|
137
|
-
});
|
|
138
|
-
return {
|
|
139
|
-
entries: normalizedEntries,
|
|
140
|
-
remotePathMap
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
144
|
-
0 && (module.exports = {
|
|
145
|
-
calcPathName,
|
|
146
|
-
generateRouteFile
|
|
147
|
-
});
|
|
@@ -1,137 +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 patchMFConfig_exports = {};
|
|
30
|
-
__export(patchMFConfig_exports, {
|
|
31
|
-
patchMFConfig: () => patchMFConfig
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(patchMFConfig_exports);
|
|
34
|
-
var import_path = __toESM(require("path"));
|
|
35
|
-
var import_utils = require("@modern-js/utils");
|
|
36
|
-
var import_constant = require("../../constant");
|
|
37
|
-
var import_constant2 = require("../../constant");
|
|
38
|
-
var import_ast = require("./ast");
|
|
39
|
-
function generateExtraExposeFiles(options) {
|
|
40
|
-
const { internalDirectory, mfConfig, isServer, entries } = options;
|
|
41
|
-
const entryMap = {};
|
|
42
|
-
const outputDir = import_path.default.resolve(process.cwd(), "node_modules/.federation/data-loader");
|
|
43
|
-
import_utils.fs.ensureDirSync(outputDir);
|
|
44
|
-
const addSuffix = (fileName, ext = ".jsx") => {
|
|
45
|
-
if (!isServer) {
|
|
46
|
-
return `${fileName}${ext}`;
|
|
47
|
-
}
|
|
48
|
-
return `${fileName}.server${ext}`;
|
|
49
|
-
};
|
|
50
|
-
const generateEntryRoutes = (entry) => {
|
|
51
|
-
const outputEntryDir = import_path.default.resolve(outputDir, entry);
|
|
52
|
-
import_utils.fs.ensureDirSync(outputEntryDir);
|
|
53
|
-
const sourceDir = import_path.default.resolve(internalDirectory, entry);
|
|
54
|
-
const routesFilePath = import_path.default.resolve(sourceDir, addSuffix(import_constant2.MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME, ".js"));
|
|
55
|
-
const routesFileContent = import_utils.fs.readFileSync(routesFilePath, "utf-8");
|
|
56
|
-
const outputFullRoutesPath = import_path.default.resolve(outputEntryDir, addSuffix(import_constant2.MF_ROUTES));
|
|
57
|
-
(0, import_ast.generateRoutes)({
|
|
58
|
-
sourceCode: routesFileContent,
|
|
59
|
-
filePath: outputFullRoutesPath
|
|
60
|
-
});
|
|
61
|
-
const routeServerLoaderPath = import_path.default.resolve(sourceDir, `${import_constant.MODERN_JS_ROUTE_SERVER_LOADER}.js`);
|
|
62
|
-
const outputRouteServerLoaderPath = import_path.default.resolve(outputEntryDir, `${import_constant.MODERN_JS_ROUTE_SERVER_LOADER}.js`);
|
|
63
|
-
const clientRouteServerLoaderPath = outputRouteServerLoaderPath.replace(import_constant.MODERN_JS_ROUTE_SERVER_LOADER, `${import_constant.MODERN_JS_ROUTE_SERVER_LOADER}-client`);
|
|
64
|
-
if (isServer) {
|
|
65
|
-
const routeServerLoaderContent = import_utils.fs.readFileSync(routeServerLoaderPath, "utf-8");
|
|
66
|
-
(0, import_ast.generateRoutes)({
|
|
67
|
-
sourceCode: routeServerLoaderContent,
|
|
68
|
-
filePath: outputRouteServerLoaderPath
|
|
69
|
-
});
|
|
70
|
-
} else {
|
|
71
|
-
import_utils.fs.writeFileSync(clientRouteServerLoaderPath, `export const routes = []`);
|
|
72
|
-
}
|
|
73
|
-
entryMap[entry] = {
|
|
74
|
-
routesPath: outputFullRoutesPath,
|
|
75
|
-
routeServerLoaderPath: outputRouteServerLoaderPath,
|
|
76
|
-
clientRouteServerLoaderPath
|
|
77
|
-
};
|
|
78
|
-
};
|
|
79
|
-
entries.forEach((entry) => {
|
|
80
|
-
generateEntryRoutes(entry);
|
|
81
|
-
});
|
|
82
|
-
return {
|
|
83
|
-
entryMap
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
function addExpose(options) {
|
|
87
|
-
const { mfConfig, isServer } = options;
|
|
88
|
-
const { entryMap } = generateExtraExposeFiles(options);
|
|
89
|
-
const addExposeByEntry = (entry, routesPath, routeServerLoaderPath, clientRouteServerLoaderPath) => {
|
|
90
|
-
if (!mfConfig.exposes) {
|
|
91
|
-
mfConfig.exposes = {};
|
|
92
|
-
}
|
|
93
|
-
const routesKey = `./${entry}/${import_constant2.MF_ROUTES}`;
|
|
94
|
-
if (!mfConfig.exposes[routesKey]) {
|
|
95
|
-
mfConfig.exposes[routesKey] = routesPath;
|
|
96
|
-
}
|
|
97
|
-
const routeServerLoaderKey = `./${entry}/${import_constant.MODERN_JS_ROUTE_SERVER_LOADER}`;
|
|
98
|
-
if (!mfConfig.exposes[routeServerLoaderKey]) {
|
|
99
|
-
if (isServer) {
|
|
100
|
-
mfConfig.exposes[routeServerLoaderKey] = routeServerLoaderPath;
|
|
101
|
-
} else {
|
|
102
|
-
mfConfig.exposes[routeServerLoaderKey] = clientRouteServerLoaderPath;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
Object.keys(entryMap).forEach((entry) => {
|
|
107
|
-
const { routesPath, routeServerLoaderPath, clientRouteServerLoaderPath } = entryMap[entry];
|
|
108
|
-
addExposeByEntry(entry, routesPath, routeServerLoaderPath, clientRouteServerLoaderPath);
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
function addShared(options) {
|
|
112
|
-
const { metaName, mfConfig } = options;
|
|
113
|
-
const alias = `@${metaName}/runtime/router`;
|
|
114
|
-
if (!mfConfig.shared) {
|
|
115
|
-
mfConfig.shared = {
|
|
116
|
-
[alias]: {
|
|
117
|
-
singleton: true
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
} else {
|
|
121
|
-
if (!Array.isArray(mfConfig.shared)) {
|
|
122
|
-
mfConfig.shared[alias] = {
|
|
123
|
-
singleton: true
|
|
124
|
-
};
|
|
125
|
-
} else {
|
|
126
|
-
mfConfig.shared.push(alias);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
function patchMFConfig(options) {
|
|
131
|
-
addShared(options);
|
|
132
|
-
addExpose(options);
|
|
133
|
-
}
|
|
134
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
135
|
-
0 && (module.exports = {
|
|
136
|
-
patchMFConfig
|
|
137
|
-
});
|