@module-federation/modern-js 0.0.0-next-20240814085621 → 0.0.0-next-20240815093707
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/configPlugin.js +0 -1
- package/dist/cjs/cli/constant.js +0 -6
- package/dist/cjs/cli/index.js +1 -6
- package/dist/cjs/cli/ssrPlugin.js +4 -4
- package/dist/cjs/runtime/index.js +1 -4
- package/dist/cjs/ssr-runtime/plugin.js +7 -5
- package/dist/esm/cli/configPlugin.js +0 -1
- package/dist/esm/cli/constant.js +0 -4
- package/dist/esm/cli/index.js +1 -6
- package/dist/esm/cli/ssrPlugin.js +2 -2
- package/dist/esm/runtime/index.js +1 -3
- package/dist/esm/ssr-runtime/plugin.js +10 -5
- package/dist/esm-node/cli/configPlugin.js +0 -1
- package/dist/esm-node/cli/constant.js +0 -4
- package/dist/esm-node/cli/index.js +1 -6
- package/dist/esm-node/cli/ssrPlugin.js +2 -2
- package/dist/esm-node/runtime/index.js +1 -3
- package/dist/esm-node/ssr-runtime/plugin.js +7 -5
- package/dist/types/cli/constant.d.ts +0 -2
- package/dist/types/runtime/index.d.ts +0 -1
- package/dist/types/types/index.d.ts +0 -17
- package/package.json +11 -37
- package/dist/cjs/cli/ast/constant.js +0 -46
- package/dist/cjs/cli/ast/generateRoutes.js +0 -140
- package/dist/cjs/cli/ast/generateSlimRoutes.js +0 -106
- package/dist/cjs/cli/ast/index.js +0 -31
- package/dist/cjs/cli/dataLoaderPlugin.js +0 -221
- package/dist/cjs/cli/server/dataLoaderPlugin.js +0 -78
- package/dist/cjs/interfaces/route.js +0 -16
- package/dist/cjs/runtime/constant.js +0 -34
- package/dist/cjs/runtime/dataLoader.js +0 -87
- package/dist/cjs/runtime/utils.js +0 -43
- package/dist/cjs/runtime/withMFRouteId.js +0 -31
- package/dist/esm/cli/ast/constant.js +0 -16
- package/dist/esm/cli/ast/generateRoutes.js +0 -107
- package/dist/esm/cli/ast/generateSlimRoutes.js +0 -75
- package/dist/esm/cli/ast/index.js +0 -6
- package/dist/esm/cli/dataLoaderPlugin.js +0 -208
- package/dist/esm/cli/server/dataLoaderPlugin.js +0 -122
- package/dist/esm/interfaces/route.js +0 -0
- package/dist/esm/runtime/constant.js +0 -8
- package/dist/esm/runtime/dataLoader.js +0 -125
- package/dist/esm/runtime/utils.js +0 -16
- package/dist/esm/runtime/withMFRouteId.js +0 -7
- package/dist/esm-node/cli/ast/constant.js +0 -16
- package/dist/esm-node/cli/ast/generateRoutes.js +0 -106
- package/dist/esm-node/cli/ast/generateSlimRoutes.js +0 -72
- package/dist/esm-node/cli/ast/index.js +0 -6
- package/dist/esm-node/cli/dataLoaderPlugin.js +0 -185
- package/dist/esm-node/cli/server/dataLoaderPlugin.js +0 -58
- package/dist/esm-node/interfaces/route.js +0 -0
- package/dist/esm-node/runtime/constant.js +0 -8
- package/dist/esm-node/runtime/dataLoader.js +0 -63
- package/dist/esm-node/runtime/utils.js +0 -19
- package/dist/esm-node/runtime/withMFRouteId.js +0 -7
- package/dist/types/cli/ast/constant.d.ts +0 -7
- package/dist/types/cli/ast/generateRoutes.d.ts +0 -7
- package/dist/types/cli/ast/generateSlimRoutes.d.ts +0 -7
- package/dist/types/cli/ast/index.d.ts +0 -2
- package/dist/types/cli/dataLoaderPlugin.d.ts +0 -6
- package/dist/types/cli/server/dataLoaderPlugin.d.ts +0 -5
- package/dist/types/interfaces/route.d.ts +0 -13
- package/dist/types/runtime/constant.d.ts +0 -3
- package/dist/types/runtime/dataLoader.d.ts +0 -7
- package/dist/types/runtime/utils.d.ts +0 -1
- package/dist/types/runtime/withMFRouteId.d.ts +0 -1
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
import traverse from "@babel/traverse";
|
|
4
|
-
import * as babelParser from "@babel/parser";
|
|
5
|
-
import generate from "@babel/generator";
|
|
6
|
-
import * as t from "@babel/types";
|
|
7
|
-
function findTargetKeyNode(nodeProperties, key) {
|
|
8
|
-
return nodeProperties.find(function(p) {
|
|
9
|
-
return t.isObjectProperty(p) && t.isStringLiteral(p.key) && p.key.value === key;
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
function generateRoutes(param) {
|
|
13
|
-
var sourceCode = param.sourceCode, filePath = param.filePath, prefix = param.prefix, baseName = param.baseName;
|
|
14
|
-
var ast = babelParser.parse(sourceCode, {
|
|
15
|
-
sourceType: "module"
|
|
16
|
-
});
|
|
17
|
-
var lazyComponentDeclarations = [];
|
|
18
|
-
var componentDeclarations = [];
|
|
19
|
-
var componentId = 0;
|
|
20
|
-
traverse(ast, {
|
|
21
|
-
ImportDeclaration: function ImportDeclaration(path) {
|
|
22
|
-
var source = path.node.source.value;
|
|
23
|
-
var routeIdMatch = source.match(/routeId=([^&]+)/);
|
|
24
|
-
if (routeIdMatch) {
|
|
25
|
-
var originalRouteId = routeIdMatch[1];
|
|
26
|
-
var newRouteId = "".concat(prefix).concat(originalRouteId);
|
|
27
|
-
var newSource = source.replace(/routeId=[^&]+/, "routeId=".concat(newRouteId));
|
|
28
|
-
path.node.source = t.stringLiteral(newSource);
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
ObjectExpression: function ObjectExpression(path) {
|
|
32
|
-
var componentName = "";
|
|
33
|
-
var lazyComponentName = "";
|
|
34
|
-
if (!Array.isArray(path.node.properties)) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
var idNode = findTargetKeyNode(path.node.properties, "id");
|
|
38
|
-
if (idNode && t.isObjectProperty(idNode) && t.isStringLiteral(idNode.value)) {
|
|
39
|
-
idNode.value = t.stringLiteral("".concat(prefix).concat(idNode.value.value));
|
|
40
|
-
}
|
|
41
|
-
var isRootNode = findTargetKeyNode(path.node.properties, "isRoot");
|
|
42
|
-
if (isRootNode && t.isObjectProperty(isRootNode) && t.isBooleanLiteral(isRootNode.value)) {
|
|
43
|
-
isRootNode.value.value = false;
|
|
44
|
-
}
|
|
45
|
-
if (!isRootNode) {
|
|
46
|
-
var lazyComponentNode = findTargetKeyNode(path.node.properties, "lazyImport");
|
|
47
|
-
if (lazyComponentNode && t.isObjectProperty(lazyComponentNode) && t.isArrowFunctionExpression(lazyComponentNode.value)) {
|
|
48
|
-
lazyComponentName = "LazyComponent_".concat(componentId);
|
|
49
|
-
var lazyDeclaration = t.variableDeclaration("const", [
|
|
50
|
-
t.variableDeclarator(t.identifier(lazyComponentName), lazyComponentNode.value)
|
|
51
|
-
]);
|
|
52
|
-
lazyComponentNode.value = t.identifier(lazyComponentName);
|
|
53
|
-
var componentNode = findTargetKeyNode(path.node.properties, "component");
|
|
54
|
-
if (componentNode && t.isObjectProperty(componentNode) && t.isCallExpression(componentNode.value) && t.isIdentifier(componentNode.value.callee)) {
|
|
55
|
-
componentNode.value = t.callExpression(t.identifier("lazy"), [
|
|
56
|
-
t.identifier(lazyComponentName)
|
|
57
|
-
]);
|
|
58
|
-
}
|
|
59
|
-
lazyComponentDeclarations.push(lazyDeclaration);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
var componentNode1 = findTargetKeyNode(path.node.properties, "component");
|
|
63
|
-
if (componentNode1 && t.isObjectProperty(componentNode1) && t.isCallExpression(componentNode1.value) && t.isIdentifier(componentNode1.value.callee)) {
|
|
64
|
-
componentName = "Component_".concat(componentId);
|
|
65
|
-
var componentDeclaration = t.variableDeclaration("const", [
|
|
66
|
-
t.variableDeclarator(t.identifier(componentName), lazyComponentName ? t.callExpression(t.identifier("lazy"), [
|
|
67
|
-
t.identifier(lazyComponentName)
|
|
68
|
-
]) : componentNode1.value)
|
|
69
|
-
]);
|
|
70
|
-
componentDeclarations.push(componentDeclaration);
|
|
71
|
-
componentNode1.value = t.identifier(componentName);
|
|
72
|
-
}
|
|
73
|
-
if (lazyComponentName || componentName) {
|
|
74
|
-
componentId++;
|
|
75
|
-
if (componentName) {
|
|
76
|
-
var upperFirstName = componentName.slice(0, 1).toUpperCase() + componentName.slice(1);
|
|
77
|
-
var jsxElement = t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier(upperFirstName), [], true), null, [], true);
|
|
78
|
-
path.node.properties.push(t.objectProperty(t.identifier("element"), jsxElement));
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
traverse(ast, {
|
|
84
|
-
Program: function Program(path) {
|
|
85
|
-
var lastImportIndex = path.get("body").reduce(function(lastIndex, p, index) {
|
|
86
|
-
if (t.isImportDeclaration(p.node)) {
|
|
87
|
-
lastIndex = index;
|
|
88
|
-
}
|
|
89
|
-
return lastIndex;
|
|
90
|
-
}, -1);
|
|
91
|
-
if (lastImportIndex >= 0) {
|
|
92
|
-
var lastImport = path.get("body.".concat(lastImportIndex));
|
|
93
|
-
_to_consumable_array(componentDeclarations).concat(_to_consumable_array(lazyComponentDeclarations)).forEach(function(declaration) {
|
|
94
|
-
if ("insertAfter" in lastImport) {
|
|
95
|
-
lastImport.insertAfter(declaration);
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
var _generate = generate(ast), newCode = _generate.code;
|
|
102
|
-
var finalCode = "".concat(newCode, "export const baseName = '").concat(baseName, "';");
|
|
103
|
-
fs.writeFileSync(filePath, finalCode);
|
|
104
|
-
}
|
|
105
|
-
export {
|
|
106
|
-
generateRoutes
|
|
107
|
-
};
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import traverse from "@babel/traverse";
|
|
3
|
-
import * as babelParser from "@babel/parser";
|
|
4
|
-
import generate from "@babel/generator";
|
|
5
|
-
import * as t from "@babel/types";
|
|
6
|
-
import { COMPONENT, ID, SHOULD_REVALIDATE, LAZY_COMPONENT, PRIVATE_COMPONENT } from "./constant";
|
|
7
|
-
function generateSlimRoutes(param) {
|
|
8
|
-
var sourceCode = param.sourceCode, filePath = param.filePath, prefix = param.prefix, baseName = param.baseName;
|
|
9
|
-
var ast = babelParser.parse(sourceCode, {
|
|
10
|
-
sourceType: "module"
|
|
11
|
-
});
|
|
12
|
-
var removedKeys = [
|
|
13
|
-
COMPONENT,
|
|
14
|
-
SHOULD_REVALIDATE,
|
|
15
|
-
LAZY_COMPONENT,
|
|
16
|
-
PRIVATE_COMPONENT
|
|
17
|
-
];
|
|
18
|
-
traverse(ast, {
|
|
19
|
-
ImportDeclaration: function ImportDeclaration(path) {
|
|
20
|
-
var source = path.node.source.value;
|
|
21
|
-
var routeIdMatch = source.match(/routeId=([^&]+)/);
|
|
22
|
-
if (routeIdMatch) {
|
|
23
|
-
var originalRouteId = routeIdMatch[1];
|
|
24
|
-
var newRouteId = "".concat(prefix).concat(originalRouteId);
|
|
25
|
-
var newSource = source.replace(/routeId=[^&]+/, "routeId=".concat(newRouteId));
|
|
26
|
-
path.node.source = t.stringLiteral(newSource);
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
ObjectExpression: function ObjectExpression(path) {
|
|
30
|
-
if (!Array.isArray(path.node.properties)) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
path.node.properties.forEach(function(prop) {
|
|
34
|
-
if (t.isObjectProperty(prop) && t.isStringLiteral(prop.key) && t.isStringLiteral(prop.value) && prop.key.value === ID) {
|
|
35
|
-
prop.value = t.stringLiteral("".concat(prefix).concat(prop.value.value));
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
path.node.properties = path.node.properties.filter(function(p) {
|
|
39
|
-
if (t.isObjectProperty(p) && t.isStringLiteral(p.key)) {
|
|
40
|
-
return !removedKeys.includes(p.key.value);
|
|
41
|
-
} else {
|
|
42
|
-
return true;
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
var tempCode = generate(ast).code;
|
|
48
|
-
var tempAst = babelParser.parse(tempCode, {
|
|
49
|
-
sourceType: "module"
|
|
50
|
-
});
|
|
51
|
-
var usedIdentifiers = /* @__PURE__ */ new Set();
|
|
52
|
-
traverse(tempAst, {
|
|
53
|
-
Identifier: function Identifier(path) {
|
|
54
|
-
if (t.isProperty(path.parent)) {
|
|
55
|
-
usedIdentifiers.add(path.node.name);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
traverse(tempAst, {
|
|
60
|
-
ImportDeclaration: function ImportDeclaration(path) {
|
|
61
|
-
path.node.specifiers = path.node.specifiers.filter(function(specifier) {
|
|
62
|
-
return usedIdentifiers.has(specifier.local.name);
|
|
63
|
-
});
|
|
64
|
-
if (!path.node.specifiers.length) {
|
|
65
|
-
path.remove();
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
var _generate = generate(tempAst), newCode = _generate.code;
|
|
70
|
-
var finalCode = "".concat(newCode, "export const baseName = '").concat(baseName, "';");
|
|
71
|
-
fs.writeFileSync(filePath, finalCode);
|
|
72
|
-
}
|
|
73
|
-
export {
|
|
74
|
-
generateSlimRoutes
|
|
75
|
-
};
|
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
-
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
3
|
-
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
4
|
-
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
5
|
-
import path from "path";
|
|
6
|
-
import { fs } from "@modern-js/utils";
|
|
7
|
-
import { transformName2Prefix } from "../runtime/utils";
|
|
8
|
-
import { PLUGIN_IDENTIFIER } from "../constant";
|
|
9
|
-
import { MF_FULL_ROUTES, MF_SLIM_ROUTES, MF_ROUTES_META } from "../runtime/constant";
|
|
10
|
-
import { generateRoutes, generateSlimRoutes } from "./ast";
|
|
11
|
-
import { MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME, META_NAME } from "./constant";
|
|
12
|
-
function generateExtraExposeFiles(options) {
|
|
13
|
-
var routesFilePath = options.routesFilePath, mfConfig = options.mfConfig, isServer = options.isServer, baseName = options.baseName;
|
|
14
|
-
var outputDir = path.resolve(process.cwd(), "node_modules/.federation");
|
|
15
|
-
fs.ensureDirSync(outputDir);
|
|
16
|
-
var addSuffix = function(fileName) {
|
|
17
|
-
if (!isServer) {
|
|
18
|
-
return "".concat(fileName, ".jsx");
|
|
19
|
-
}
|
|
20
|
-
return "".concat(fileName, ".server.jsx");
|
|
21
|
-
};
|
|
22
|
-
var routesFileContent = fs.readFileSync(routesFilePath, "utf-8");
|
|
23
|
-
var outputSlimRoutesPath = path.resolve(outputDir, addSuffix(MF_SLIM_ROUTES));
|
|
24
|
-
var outputFullRoutesPath = path.resolve(outputDir, addSuffix(MF_FULL_ROUTES));
|
|
25
|
-
var outputRoutesMetaPath = path.resolve(outputDir, "".concat(MF_ROUTES_META, ".js"));
|
|
26
|
-
generateSlimRoutes({
|
|
27
|
-
sourceCode: routesFileContent,
|
|
28
|
-
filePath: outputSlimRoutesPath,
|
|
29
|
-
prefix: transformName2Prefix(mfConfig.name),
|
|
30
|
-
baseName
|
|
31
|
-
});
|
|
32
|
-
generateRoutes({
|
|
33
|
-
sourceCode: routesFileContent,
|
|
34
|
-
filePath: outputFullRoutesPath,
|
|
35
|
-
prefix: transformName2Prefix(mfConfig.name),
|
|
36
|
-
baseName
|
|
37
|
-
});
|
|
38
|
-
fs.writeFileSync(outputRoutesMetaPath, "export const baseName = '".concat(baseName, "';"));
|
|
39
|
-
return {
|
|
40
|
-
outputSlimRoutesPath,
|
|
41
|
-
outputFullRoutesPath,
|
|
42
|
-
outputRoutesMetaPath
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
function addExpose(options) {
|
|
46
|
-
var mfConfig = options.mfConfig;
|
|
47
|
-
var _generateExtraExposeFiles = generateExtraExposeFiles(options), outputSlimRoutesPath = _generateExtraExposeFiles.outputSlimRoutesPath, outputFullRoutesPath = _generateExtraExposeFiles.outputFullRoutesPath, outputRoutesMetaPath = _generateExtraExposeFiles.outputRoutesMetaPath;
|
|
48
|
-
var fullRoutesKey = "./".concat(MF_FULL_ROUTES);
|
|
49
|
-
var slimRoutesKey = "./".concat(MF_SLIM_ROUTES);
|
|
50
|
-
var routeMetaKey = "./".concat(MF_ROUTES_META);
|
|
51
|
-
if (!mfConfig.exposes) {
|
|
52
|
-
var _obj;
|
|
53
|
-
mfConfig.exposes = (_obj = {}, _define_property(_obj, fullRoutesKey, outputFullRoutesPath), _define_property(_obj, slimRoutesKey, outputSlimRoutesPath), _define_property(_obj, routeMetaKey, outputRoutesMetaPath), _obj);
|
|
54
|
-
} else {
|
|
55
|
-
if (!Array.isArray(mfConfig.exposes)) {
|
|
56
|
-
if (!mfConfig.exposes[fullRoutesKey]) {
|
|
57
|
-
mfConfig.exposes[fullRoutesKey] = outputFullRoutesPath;
|
|
58
|
-
}
|
|
59
|
-
if (!mfConfig.exposes[slimRoutesKey]) {
|
|
60
|
-
mfConfig.exposes[slimRoutesKey] = outputSlimRoutesPath;
|
|
61
|
-
}
|
|
62
|
-
if (!mfConfig.exposes[routeMetaKey]) {
|
|
63
|
-
mfConfig.exposes[routeMetaKey] = outputRoutesMetaPath;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
function addShared(options) {
|
|
69
|
-
var metaName = options.metaName, mfConfig = options.mfConfig;
|
|
70
|
-
var alias = "@".concat(metaName, "/runtime/router");
|
|
71
|
-
if (!mfConfig.shared) {
|
|
72
|
-
mfConfig.shared = _define_property({}, alias, {
|
|
73
|
-
singleton: true
|
|
74
|
-
});
|
|
75
|
-
} else {
|
|
76
|
-
if (!Array.isArray(mfConfig.shared)) {
|
|
77
|
-
mfConfig.shared[alias] = {
|
|
78
|
-
singleton: true
|
|
79
|
-
};
|
|
80
|
-
} else {
|
|
81
|
-
mfConfig.shared.push(alias);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
function _pathMfConfig(options) {
|
|
86
|
-
addShared(options);
|
|
87
|
-
addExpose(options);
|
|
88
|
-
}
|
|
89
|
-
function _transformRuntimeOptions(buildOptions) {
|
|
90
|
-
var remotes = buildOptions.remotes || {};
|
|
91
|
-
var runtimeRemotes = Object.entries(remotes).map(function(remote) {
|
|
92
|
-
var _remote = _sliced_to_array(remote, 2), _alias = _remote[0], nameAndEntry = _remote[1];
|
|
93
|
-
var _nameAndEntry_split = _sliced_to_array(nameAndEntry.split("@"), 2), name = _nameAndEntry_split[0], entry = _nameAndEntry_split[1];
|
|
94
|
-
return {
|
|
95
|
-
name,
|
|
96
|
-
entry
|
|
97
|
-
};
|
|
98
|
-
});
|
|
99
|
-
return {
|
|
100
|
-
name: buildOptions.name,
|
|
101
|
-
remotes: runtimeRemotes
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
var moduleFederationDataLoaderPlugin = function(enable, internalOptions, userConfig) {
|
|
105
|
-
return {
|
|
106
|
-
name: "@modern-js/plugin-module-federation-data-loader",
|
|
107
|
-
pre: [
|
|
108
|
-
"@modern-js/plugin-module-federation-config"
|
|
109
|
-
],
|
|
110
|
-
post: [
|
|
111
|
-
"@modern-js/plugin-router",
|
|
112
|
-
"@modern-js/plugin-module-federation"
|
|
113
|
-
],
|
|
114
|
-
setup: function() {
|
|
115
|
-
var _ref = _async_to_generator(function(param) {
|
|
116
|
-
var useConfigContext, useAppContext, _modernjsConfig_server, _internalOptions_csrConfig, baseName, _userConfig_partialSSRRemotes, partialSSRRemotes, fetchSSRByRouteIds, patchMFConfig, _userConfig_metaName, metaName, _userConfig_serverPlugin, serverPlugin, transformRuntimeOptions, modernjsConfig, appContext, enableSSR, name, routesFilePath, transformRuntimeFn;
|
|
117
|
-
return _ts_generator(this, function(_state) {
|
|
118
|
-
useConfigContext = param.useConfigContext, useAppContext = param.useAppContext;
|
|
119
|
-
if (!enable) {
|
|
120
|
-
return [
|
|
121
|
-
2
|
|
122
|
-
];
|
|
123
|
-
}
|
|
124
|
-
baseName = userConfig.baseName, _userConfig_partialSSRRemotes = userConfig.partialSSRRemotes, partialSSRRemotes = _userConfig_partialSSRRemotes === void 0 ? [] : _userConfig_partialSSRRemotes, fetchSSRByRouteIds = userConfig.fetchSSRByRouteIds, patchMFConfig = userConfig.patchMFConfig, _userConfig_metaName = userConfig.metaName, metaName = _userConfig_metaName === void 0 ? META_NAME : _userConfig_metaName, _userConfig_serverPlugin = userConfig.serverPlugin, serverPlugin = _userConfig_serverPlugin === void 0 ? "@module-federation/modern-js/data-loader-server" : _userConfig_serverPlugin, transformRuntimeOptions = userConfig.transformRuntimeOptions;
|
|
125
|
-
if (!baseName) {
|
|
126
|
-
throw new Error("".concat(PLUGIN_IDENTIFIER, " 'baseName' is required if you enable 'dataLoader'!"));
|
|
127
|
-
}
|
|
128
|
-
modernjsConfig = useConfigContext();
|
|
129
|
-
appContext = useAppContext();
|
|
130
|
-
enableSSR = Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
131
|
-
name = (_internalOptions_csrConfig = internalOptions.csrConfig) === null || _internalOptions_csrConfig === void 0 ? void 0 : _internalOptions_csrConfig.name;
|
|
132
|
-
routesFilePath = path.resolve(appContext.internalDirectory.replace(META_NAME, metaName || META_NAME), "./main/".concat(MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME));
|
|
133
|
-
transformRuntimeFn = transformRuntimeOptions || _transformRuntimeOptions;
|
|
134
|
-
return [
|
|
135
|
-
2,
|
|
136
|
-
{
|
|
137
|
-
_internalRuntimePlugins: function(param2) {
|
|
138
|
-
var entrypoint = param2.entrypoint, plugins = param2.plugins;
|
|
139
|
-
plugins.push({
|
|
140
|
-
name: "ssrDataLoader",
|
|
141
|
-
path: "@module-federation/modern-js/data-loader",
|
|
142
|
-
config: {}
|
|
143
|
-
});
|
|
144
|
-
return {
|
|
145
|
-
entrypoint,
|
|
146
|
-
plugins
|
|
147
|
-
};
|
|
148
|
-
},
|
|
149
|
-
_internalServerPlugins: function _internalServerPlugins(param2) {
|
|
150
|
-
var plugins = param2.plugins;
|
|
151
|
-
plugins.push({
|
|
152
|
-
name: serverPlugin,
|
|
153
|
-
options: transformRuntimeFn(internalOptions.csrConfig)
|
|
154
|
-
});
|
|
155
|
-
return {
|
|
156
|
-
plugins
|
|
157
|
-
};
|
|
158
|
-
},
|
|
159
|
-
config: /* @__PURE__ */ _async_to_generator(function() {
|
|
160
|
-
var patchMFConfigFn;
|
|
161
|
-
return _ts_generator(this, function(_state2) {
|
|
162
|
-
console.log("dataloader plugin config");
|
|
163
|
-
patchMFConfigFn = patchMFConfig || _pathMfConfig;
|
|
164
|
-
return [
|
|
165
|
-
2,
|
|
166
|
-
{
|
|
167
|
-
// server: {
|
|
168
|
-
// ssrByRouteIds: ssrByRouteIds,
|
|
169
|
-
// },
|
|
170
|
-
tools: {
|
|
171
|
-
rspack: function rspack(_config, param2) {
|
|
172
|
-
var isServer = param2.isServer;
|
|
173
|
-
patchMFConfigFn({
|
|
174
|
-
mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
|
|
175
|
-
baseName,
|
|
176
|
-
metaName,
|
|
177
|
-
isServer,
|
|
178
|
-
routesFilePath
|
|
179
|
-
});
|
|
180
|
-
console.log("dataloader plugin rspack");
|
|
181
|
-
}
|
|
182
|
-
},
|
|
183
|
-
source: {
|
|
184
|
-
define: {
|
|
185
|
-
MODERN_ROUTER_ID_PREFIX: JSON.stringify(transformName2Prefix(name))
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
];
|
|
190
|
-
});
|
|
191
|
-
})
|
|
192
|
-
}
|
|
193
|
-
];
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
return function(_) {
|
|
197
|
-
return _ref.apply(this, arguments);
|
|
198
|
-
};
|
|
199
|
-
}()
|
|
200
|
-
};
|
|
201
|
-
};
|
|
202
|
-
var dataLoaderPlugin_default = moduleFederationDataLoaderPlugin;
|
|
203
|
-
export {
|
|
204
|
-
dataLoaderPlugin_default as default,
|
|
205
|
-
generateRoutes,
|
|
206
|
-
generateSlimRoutes,
|
|
207
|
-
moduleFederationDataLoaderPlugin
|
|
208
|
-
};
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
-
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
3
|
-
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
|
-
import { getInstance, init } from "@module-federation/enhanced/runtime";
|
|
5
|
-
import { MF_SLIM_ROUTES } from "../../runtime/constant";
|
|
6
|
-
function dataLoaderPlugin_default(mfRuntimeOptions) {
|
|
7
|
-
return {
|
|
8
|
-
name: "MFDataLoaderServerPlugin",
|
|
9
|
-
pre: [
|
|
10
|
-
"@modern-js/plugin-inject-resource"
|
|
11
|
-
],
|
|
12
|
-
setup: function setup(api) {
|
|
13
|
-
var remotes = mfRuntimeOptions.remotes, name = mfRuntimeOptions.name;
|
|
14
|
-
if (!remotes.length) {
|
|
15
|
-
return {};
|
|
16
|
-
}
|
|
17
|
-
var isHandled = false;
|
|
18
|
-
return {
|
|
19
|
-
prepare: function prepare() {
|
|
20
|
-
var middlewares = api.useAppContext().middlewares;
|
|
21
|
-
middlewares.push({
|
|
22
|
-
name: "MFDataLoaderServerPlugin",
|
|
23
|
-
handler: function() {
|
|
24
|
-
var _ref = _async_to_generator(function(c, next) {
|
|
25
|
-
var serverManifest, loaderBundles, instance, slimRoutes;
|
|
26
|
-
return _ts_generator(this, function(_state) {
|
|
27
|
-
switch (_state.label) {
|
|
28
|
-
case 0:
|
|
29
|
-
console.log("isHandled : ", isHandled);
|
|
30
|
-
serverManifest = c.get("serverManifest");
|
|
31
|
-
loaderBundles = serverManifest.loaderBundles;
|
|
32
|
-
console.log("loaderBundles.main.routes : ", loaderBundles.main.routes);
|
|
33
|
-
if (!isHandled)
|
|
34
|
-
return [
|
|
35
|
-
3,
|
|
36
|
-
2
|
|
37
|
-
];
|
|
38
|
-
return [
|
|
39
|
-
4,
|
|
40
|
-
next()
|
|
41
|
-
];
|
|
42
|
-
case 1:
|
|
43
|
-
_state.sent();
|
|
44
|
-
return [
|
|
45
|
-
3,
|
|
46
|
-
5
|
|
47
|
-
];
|
|
48
|
-
case 2:
|
|
49
|
-
instance = getInstance() || init({
|
|
50
|
-
name,
|
|
51
|
-
remotes
|
|
52
|
-
});
|
|
53
|
-
return [
|
|
54
|
-
4,
|
|
55
|
-
Promise.all(remotes.map(function() {
|
|
56
|
-
var _ref2 = _async_to_generator(function(remote) {
|
|
57
|
-
var _ref3, routes, baseName;
|
|
58
|
-
return _ts_generator(this, function(_state2) {
|
|
59
|
-
switch (_state2.label) {
|
|
60
|
-
case 0:
|
|
61
|
-
return [
|
|
62
|
-
4,
|
|
63
|
-
instance.loadRemote("".concat(remote.name, "/").concat(MF_SLIM_ROUTES))
|
|
64
|
-
];
|
|
65
|
-
case 1:
|
|
66
|
-
_ref3 = _state2.sent(), routes = _ref3.routes, baseName = _ref3.baseName;
|
|
67
|
-
return [
|
|
68
|
-
2,
|
|
69
|
-
{
|
|
70
|
-
routes,
|
|
71
|
-
baseName
|
|
72
|
-
}
|
|
73
|
-
];
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
return function(remote) {
|
|
78
|
-
return _ref2.apply(this, arguments);
|
|
79
|
-
};
|
|
80
|
-
}()))
|
|
81
|
-
];
|
|
82
|
-
case 3:
|
|
83
|
-
slimRoutes = _state.sent();
|
|
84
|
-
slimRoutes.forEach(function(slimRoute) {
|
|
85
|
-
var _loaderBundles_main_routes;
|
|
86
|
-
var routes = slimRoute.routes, baseName = slimRoute.baseName;
|
|
87
|
-
routes[0].path = "/".concat(baseName);
|
|
88
|
-
(_loaderBundles_main_routes = loaderBundles.main.routes).push.apply(_loaderBundles_main_routes, _to_consumable_array(routes));
|
|
89
|
-
});
|
|
90
|
-
console.log("loaderBundles.main.routes : ", loaderBundles.main.routes);
|
|
91
|
-
isHandled = true;
|
|
92
|
-
return [
|
|
93
|
-
4,
|
|
94
|
-
next()
|
|
95
|
-
];
|
|
96
|
-
case 4:
|
|
97
|
-
_state.sent();
|
|
98
|
-
_state.label = 5;
|
|
99
|
-
case 5:
|
|
100
|
-
return [
|
|
101
|
-
2
|
|
102
|
-
];
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
return function(c, next) {
|
|
107
|
-
return _ref.apply(this, arguments);
|
|
108
|
-
};
|
|
109
|
-
}(),
|
|
110
|
-
before: [
|
|
111
|
-
"render"
|
|
112
|
-
]
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
;
|
|
120
|
-
export {
|
|
121
|
-
dataLoaderPlugin_default as default
|
|
122
|
-
};
|
|
File without changes
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
-
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
3
|
-
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
-
import { getInstance, loadRemote } from "@module-federation/enhanced/runtime";
|
|
6
|
-
import { MF_FULL_ROUTES } from "./constant";
|
|
7
|
-
globalThis.mfRemoteRoutes = globalThis.mfRemoteRoutes || [];
|
|
8
|
-
var _globalThis_mfHasLoadedRemoteRoutes;
|
|
9
|
-
globalThis.mfHasLoadedRemoteRoutes = (_globalThis_mfHasLoadedRemoteRoutes = globalThis.mfHasLoadedRemoteRoutes) !== null && _globalThis_mfHasLoadedRemoteRoutes !== void 0 ? _globalThis_mfHasLoadedRemoteRoutes : false;
|
|
10
|
-
function loadRoutes() {
|
|
11
|
-
return _loadRoutes.apply(this, arguments);
|
|
12
|
-
}
|
|
13
|
-
function _loadRoutes() {
|
|
14
|
-
_loadRoutes = _async_to_generator(function() {
|
|
15
|
-
var _getInstance, remotes, remoteModuleIds, traverse;
|
|
16
|
-
return _ts_generator(this, function(_state) {
|
|
17
|
-
switch (_state.label) {
|
|
18
|
-
case 0:
|
|
19
|
-
if (globalThis.mfHasLoadedRemoteRoutes) {
|
|
20
|
-
return [
|
|
21
|
-
2
|
|
22
|
-
];
|
|
23
|
-
}
|
|
24
|
-
remotes = (_getInstance = getInstance()) === null || _getInstance === void 0 ? void 0 : _getInstance.options.remotes;
|
|
25
|
-
if (!remotes) {
|
|
26
|
-
return [
|
|
27
|
-
2
|
|
28
|
-
];
|
|
29
|
-
}
|
|
30
|
-
remoteModuleIds = remotes.map(function(remote) {
|
|
31
|
-
return "".concat(remote.name, "/").concat(MF_FULL_ROUTES);
|
|
32
|
-
});
|
|
33
|
-
traverse = function(cRoutes, prefix) {
|
|
34
|
-
cRoutes.forEach(function(i) {
|
|
35
|
-
i.id = prefix + i.id;
|
|
36
|
-
var Comp = i.component;
|
|
37
|
-
i.element = /* @__PURE__ */ _jsx(Comp, {});
|
|
38
|
-
if (i.children) {
|
|
39
|
-
traverse(i.children, prefix);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
};
|
|
43
|
-
return [
|
|
44
|
-
4,
|
|
45
|
-
Promise.all(remoteModuleIds.map(function() {
|
|
46
|
-
var _ref = _async_to_generator(function(remoteModuleId) {
|
|
47
|
-
var _globalThis_mfRemoteRoutes, remoteName, _ref2, routes, baseName;
|
|
48
|
-
return _ts_generator(this, function(_state2) {
|
|
49
|
-
switch (_state2.label) {
|
|
50
|
-
case 0:
|
|
51
|
-
remoteName = remoteModuleId.split("/".concat(MF_FULL_ROUTES))[0];
|
|
52
|
-
return [
|
|
53
|
-
4,
|
|
54
|
-
loadRemote(remoteModuleId)
|
|
55
|
-
];
|
|
56
|
-
case 1:
|
|
57
|
-
_ref2 = _state2.sent(), routes = _ref2.routes, baseName = _ref2.baseName;
|
|
58
|
-
routes[0].path = "/".concat(baseName);
|
|
59
|
-
routes[0].isRoot = false;
|
|
60
|
-
(_globalThis_mfRemoteRoutes = globalThis.mfRemoteRoutes).push.apply(_globalThis_mfRemoteRoutes, _to_consumable_array(routes));
|
|
61
|
-
return [
|
|
62
|
-
2
|
|
63
|
-
];
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
return function(remoteModuleId) {
|
|
68
|
-
return _ref.apply(this, arguments);
|
|
69
|
-
};
|
|
70
|
-
}()))
|
|
71
|
-
];
|
|
72
|
-
case 1:
|
|
73
|
-
_state.sent();
|
|
74
|
-
globalThis.mfHasLoadedRemoteRoutes = true;
|
|
75
|
-
return [
|
|
76
|
-
2,
|
|
77
|
-
globalThis.mfRemoteRoutes
|
|
78
|
-
];
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
return _loadRoutes.apply(this, arguments);
|
|
83
|
-
}
|
|
84
|
-
var ssrDataLoaderPlugin = function() {
|
|
85
|
-
return {
|
|
86
|
-
name: "@modern-js/plugin-mf-data-loader",
|
|
87
|
-
post: [
|
|
88
|
-
"@modern-js/plugin-router"
|
|
89
|
-
],
|
|
90
|
-
setup: function() {
|
|
91
|
-
return {
|
|
92
|
-
beforeRender: function beforeRender(param) {
|
|
93
|
-
var context = param.context;
|
|
94
|
-
return _async_to_generator(function() {
|
|
95
|
-
return _ts_generator(this, function(_state) {
|
|
96
|
-
switch (_state.label) {
|
|
97
|
-
case 0:
|
|
98
|
-
console.log("init");
|
|
99
|
-
return [
|
|
100
|
-
4,
|
|
101
|
-
loadRoutes()
|
|
102
|
-
];
|
|
103
|
-
case 1:
|
|
104
|
-
_state.sent();
|
|
105
|
-
return [
|
|
106
|
-
2
|
|
107
|
-
];
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
})();
|
|
111
|
-
},
|
|
112
|
-
modifyRoutes: function(routes) {
|
|
113
|
-
var _routes;
|
|
114
|
-
console.log("modifyRoutes");
|
|
115
|
-
(_routes = routes).push.apply(_routes, _to_consumable_array(globalThis.mfRemoteRoutes));
|
|
116
|
-
console.log("routes: ", routes);
|
|
117
|
-
return routes;
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
};
|
|
123
|
-
export {
|
|
124
|
-
ssrDataLoaderPlugin
|
|
125
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
|
-
function transformName2Prefix(name) {
|
|
3
|
-
var NameTransformSymbol = {
|
|
4
|
-
AT: "@",
|
|
5
|
-
HYPHEN: "-",
|
|
6
|
-
SLASH: "/",
|
|
7
|
-
UNDERLINE: "_"
|
|
8
|
-
};
|
|
9
|
-
var _obj;
|
|
10
|
-
var NameTransformMap = (_obj = {}, _define_property(_obj, NameTransformSymbol.AT, "SCOPE"), _define_property(_obj, NameTransformSymbol.HYPHEN, "HYPHEN"), _define_property(_obj, NameTransformSymbol.SLASH, "SLASH"), _define_property(_obj, NameTransformSymbol.UNDERLINE, "UNDERLINE"), _obj);
|
|
11
|
-
var SPLIT_SYMBOL = "@";
|
|
12
|
-
return "".concat(name.replace(new RegExp("".concat(NameTransformSymbol.AT), "g"), NameTransformMap[NameTransformSymbol.AT]).replace(new RegExp("".concat(NameTransformSymbol.HYPHEN), "g"), NameTransformMap[NameTransformSymbol.HYPHEN]).replace(new RegExp("".concat(NameTransformSymbol.SLASH), "g"), NameTransformMap[NameTransformSymbol.SLASH]).replace(new RegExp("".concat(NameTransformSymbol.UNDERLINE), "g"), NameTransformMap[NameTransformSymbol.UNDERLINE])).concat(SPLIT_SYMBOL);
|
|
13
|
-
}
|
|
14
|
-
export {
|
|
15
|
-
transformName2Prefix
|
|
16
|
-
};
|