@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,106 +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 generateSlimRoutes_exports = {};
|
|
30
|
-
__export(generateSlimRoutes_exports, {
|
|
31
|
-
generateSlimRoutes: () => generateSlimRoutes
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(generateSlimRoutes_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
|
-
var import_constant = require("./constant");
|
|
40
|
-
function generateSlimRoutes({ sourceCode, filePath, prefix, baseName }) {
|
|
41
|
-
const ast = babelParser.parse(sourceCode, {
|
|
42
|
-
sourceType: "module"
|
|
43
|
-
});
|
|
44
|
-
const removedKeys = [
|
|
45
|
-
import_constant.COMPONENT,
|
|
46
|
-
import_constant.SHOULD_REVALIDATE,
|
|
47
|
-
import_constant.LAZY_COMPONENT,
|
|
48
|
-
import_constant.PRIVATE_COMPONENT
|
|
49
|
-
];
|
|
50
|
-
(0, import_traverse.default)(ast, {
|
|
51
|
-
ImportDeclaration(path) {
|
|
52
|
-
const source = path.node.source.value;
|
|
53
|
-
const routeIdMatch = source.match(/routeId=([^&]+)/);
|
|
54
|
-
if (routeIdMatch) {
|
|
55
|
-
const originalRouteId = routeIdMatch[1];
|
|
56
|
-
const newRouteId = `${prefix}${originalRouteId}`;
|
|
57
|
-
const newSource = source.replace(/routeId=[^&]+/, `routeId=${newRouteId}`);
|
|
58
|
-
path.node.source = t.stringLiteral(newSource);
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
ObjectExpression(path) {
|
|
62
|
-
if (!Array.isArray(path.node.properties)) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
path.node.properties.forEach((prop) => {
|
|
66
|
-
if (t.isObjectProperty(prop) && t.isStringLiteral(prop.key) && t.isStringLiteral(prop.value) && prop.key.value === import_constant.ID) {
|
|
67
|
-
prop.value = t.stringLiteral(`${prefix}${prop.value.value}`);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
path.node.properties = path.node.properties.filter((p) => {
|
|
71
|
-
if (t.isObjectProperty(p) && t.isStringLiteral(p.key)) {
|
|
72
|
-
return !removedKeys.includes(p.key.value);
|
|
73
|
-
} else {
|
|
74
|
-
return true;
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
const tempCode = (0, import_generator.default)(ast).code;
|
|
80
|
-
const tempAst = babelParser.parse(tempCode, {
|
|
81
|
-
sourceType: "module"
|
|
82
|
-
});
|
|
83
|
-
const usedIdentifiers = /* @__PURE__ */ new Set();
|
|
84
|
-
(0, import_traverse.default)(tempAst, {
|
|
85
|
-
Identifier(path) {
|
|
86
|
-
if (t.isProperty(path.parent)) {
|
|
87
|
-
usedIdentifiers.add(path.node.name);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
(0, import_traverse.default)(tempAst, {
|
|
92
|
-
ImportDeclaration(path) {
|
|
93
|
-
path.node.specifiers = path.node.specifiers.filter((specifier) => usedIdentifiers.has(specifier.local.name));
|
|
94
|
-
if (!path.node.specifiers.length) {
|
|
95
|
-
path.remove();
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
const { code: newCode } = (0, import_generator.default)(tempAst);
|
|
100
|
-
const finalCode = `${newCode}export const baseName = '${baseName}';`;
|
|
101
|
-
import_fs.default.writeFileSync(filePath, finalCode);
|
|
102
|
-
}
|
|
103
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
104
|
-
0 && (module.exports = {
|
|
105
|
-
generateSlimRoutes
|
|
106
|
-
});
|
|
@@ -1,31 +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 ast_exports = {};
|
|
20
|
-
__export(ast_exports, {
|
|
21
|
-
generateRoutes: () => import_generateRoutes.generateRoutes,
|
|
22
|
-
generateSlimRoutes: () => import_generateSlimRoutes.generateSlimRoutes
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(ast_exports);
|
|
25
|
-
var import_generateRoutes = require("./generateRoutes");
|
|
26
|
-
var import_generateSlimRoutes = require("./generateSlimRoutes");
|
|
27
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
-
0 && (module.exports = {
|
|
29
|
-
generateRoutes,
|
|
30
|
-
generateSlimRoutes
|
|
31
|
-
});
|
|
@@ -1,221 +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 dataLoaderPlugin_exports = {};
|
|
30
|
-
__export(dataLoaderPlugin_exports, {
|
|
31
|
-
default: () => dataLoaderPlugin_default,
|
|
32
|
-
generateRoutes: () => import_ast.generateRoutes,
|
|
33
|
-
generateSlimRoutes: () => import_ast.generateSlimRoutes,
|
|
34
|
-
moduleFederationDataLoaderPlugin: () => moduleFederationDataLoaderPlugin
|
|
35
|
-
});
|
|
36
|
-
module.exports = __toCommonJS(dataLoaderPlugin_exports);
|
|
37
|
-
var import_path = __toESM(require("path"));
|
|
38
|
-
var import_utils = require("@modern-js/utils");
|
|
39
|
-
var import_utils2 = require("../runtime/utils");
|
|
40
|
-
var import_constant = require("../constant");
|
|
41
|
-
var import_constant2 = require("../runtime/constant");
|
|
42
|
-
var import_ast = require("./ast");
|
|
43
|
-
var import_constant3 = require("./constant");
|
|
44
|
-
function generateExtraExposeFiles(options) {
|
|
45
|
-
const { routesFilePath, mfConfig, isServer, baseName } = options;
|
|
46
|
-
const outputDir = import_path.default.resolve(process.cwd(), "node_modules/.federation");
|
|
47
|
-
import_utils.fs.ensureDirSync(outputDir);
|
|
48
|
-
const addSuffix = (fileName) => {
|
|
49
|
-
if (!isServer) {
|
|
50
|
-
return `${fileName}.jsx`;
|
|
51
|
-
}
|
|
52
|
-
return `${fileName}.server.jsx`;
|
|
53
|
-
};
|
|
54
|
-
const routesFileContent = import_utils.fs.readFileSync(routesFilePath, "utf-8");
|
|
55
|
-
const outputSlimRoutesPath = import_path.default.resolve(outputDir, addSuffix(import_constant2.MF_SLIM_ROUTES));
|
|
56
|
-
const outputFullRoutesPath = import_path.default.resolve(outputDir, addSuffix(import_constant2.MF_FULL_ROUTES));
|
|
57
|
-
const outputRoutesMetaPath = import_path.default.resolve(outputDir, `${import_constant2.MF_ROUTES_META}.js`);
|
|
58
|
-
(0, import_ast.generateSlimRoutes)({
|
|
59
|
-
sourceCode: routesFileContent,
|
|
60
|
-
filePath: outputSlimRoutesPath,
|
|
61
|
-
prefix: (0, import_utils2.transformName2Prefix)(mfConfig.name),
|
|
62
|
-
baseName
|
|
63
|
-
});
|
|
64
|
-
(0, import_ast.generateRoutes)({
|
|
65
|
-
sourceCode: routesFileContent,
|
|
66
|
-
filePath: outputFullRoutesPath,
|
|
67
|
-
prefix: (0, import_utils2.transformName2Prefix)(mfConfig.name),
|
|
68
|
-
baseName
|
|
69
|
-
});
|
|
70
|
-
import_utils.fs.writeFileSync(outputRoutesMetaPath, `export const baseName = '${baseName}';`);
|
|
71
|
-
return {
|
|
72
|
-
outputSlimRoutesPath,
|
|
73
|
-
outputFullRoutesPath,
|
|
74
|
-
outputRoutesMetaPath
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
function addExpose(options) {
|
|
78
|
-
const { mfConfig } = options;
|
|
79
|
-
const { outputSlimRoutesPath, outputFullRoutesPath, outputRoutesMetaPath } = generateExtraExposeFiles(options);
|
|
80
|
-
const fullRoutesKey = `./${import_constant2.MF_FULL_ROUTES}`;
|
|
81
|
-
const slimRoutesKey = `./${import_constant2.MF_SLIM_ROUTES}`;
|
|
82
|
-
const routeMetaKey = `./${import_constant2.MF_ROUTES_META}`;
|
|
83
|
-
if (!mfConfig.exposes) {
|
|
84
|
-
mfConfig.exposes = {
|
|
85
|
-
[fullRoutesKey]: outputFullRoutesPath,
|
|
86
|
-
[slimRoutesKey]: outputSlimRoutesPath,
|
|
87
|
-
[routeMetaKey]: outputRoutesMetaPath
|
|
88
|
-
};
|
|
89
|
-
} else {
|
|
90
|
-
if (!Array.isArray(mfConfig.exposes)) {
|
|
91
|
-
if (!mfConfig.exposes[fullRoutesKey]) {
|
|
92
|
-
mfConfig.exposes[fullRoutesKey] = outputFullRoutesPath;
|
|
93
|
-
}
|
|
94
|
-
if (!mfConfig.exposes[slimRoutesKey]) {
|
|
95
|
-
mfConfig.exposes[slimRoutesKey] = outputSlimRoutesPath;
|
|
96
|
-
}
|
|
97
|
-
if (!mfConfig.exposes[routeMetaKey]) {
|
|
98
|
-
mfConfig.exposes[routeMetaKey] = outputRoutesMetaPath;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
function addShared(options) {
|
|
104
|
-
const { metaName, mfConfig } = options;
|
|
105
|
-
const alias = `@${metaName}/runtime/router`;
|
|
106
|
-
if (!mfConfig.shared) {
|
|
107
|
-
mfConfig.shared = {
|
|
108
|
-
[alias]: {
|
|
109
|
-
singleton: true
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
} else {
|
|
113
|
-
if (!Array.isArray(mfConfig.shared)) {
|
|
114
|
-
mfConfig.shared[alias] = {
|
|
115
|
-
singleton: true
|
|
116
|
-
};
|
|
117
|
-
} else {
|
|
118
|
-
mfConfig.shared.push(alias);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
function _pathMfConfig(options) {
|
|
123
|
-
addShared(options);
|
|
124
|
-
addExpose(options);
|
|
125
|
-
}
|
|
126
|
-
function _transformRuntimeOptions(buildOptions) {
|
|
127
|
-
const remotes = buildOptions.remotes || {};
|
|
128
|
-
const runtimeRemotes = Object.entries(remotes).map((remote) => {
|
|
129
|
-
const [_alias, nameAndEntry] = remote;
|
|
130
|
-
const [name, entry] = nameAndEntry.split("@");
|
|
131
|
-
return {
|
|
132
|
-
name,
|
|
133
|
-
entry
|
|
134
|
-
};
|
|
135
|
-
});
|
|
136
|
-
return {
|
|
137
|
-
name: buildOptions.name,
|
|
138
|
-
remotes: runtimeRemotes
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
const moduleFederationDataLoaderPlugin = (enable, internalOptions, userConfig) => ({
|
|
142
|
-
name: "@modern-js/plugin-module-federation-data-loader",
|
|
143
|
-
pre: [
|
|
144
|
-
"@modern-js/plugin-module-federation-config"
|
|
145
|
-
],
|
|
146
|
-
post: [
|
|
147
|
-
"@modern-js/plugin-router",
|
|
148
|
-
"@modern-js/plugin-module-federation"
|
|
149
|
-
],
|
|
150
|
-
setup: async ({ useConfigContext, useAppContext }) => {
|
|
151
|
-
var _modernjsConfig_server, _internalOptions_csrConfig;
|
|
152
|
-
if (!enable) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
const { baseName, partialSSRRemotes = [], fetchSSRByRouteIds, patchMFConfig, metaName = import_constant3.META_NAME, serverPlugin = "@module-federation/modern-js/data-loader-server", transformRuntimeOptions } = userConfig;
|
|
156
|
-
if (!baseName) {
|
|
157
|
-
throw new Error(`${import_constant.PLUGIN_IDENTIFIER} 'baseName' is required if you enable 'dataLoader'!`);
|
|
158
|
-
}
|
|
159
|
-
const modernjsConfig = useConfigContext();
|
|
160
|
-
const appContext = useAppContext();
|
|
161
|
-
const enableSSR = Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
162
|
-
const name = (_internalOptions_csrConfig = internalOptions.csrConfig) === null || _internalOptions_csrConfig === void 0 ? void 0 : _internalOptions_csrConfig.name;
|
|
163
|
-
const routesFilePath = import_path.default.resolve(appContext.internalDirectory.replace(import_constant3.META_NAME, metaName || import_constant3.META_NAME), `./main/${import_constant3.MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME}`);
|
|
164
|
-
const transformRuntimeFn = transformRuntimeOptions || _transformRuntimeOptions;
|
|
165
|
-
return {
|
|
166
|
-
_internalRuntimePlugins: ({ entrypoint, plugins }) => {
|
|
167
|
-
plugins.push({
|
|
168
|
-
name: "ssrDataLoader",
|
|
169
|
-
path: "@module-federation/modern-js/data-loader",
|
|
170
|
-
config: {}
|
|
171
|
-
});
|
|
172
|
-
return {
|
|
173
|
-
entrypoint,
|
|
174
|
-
plugins
|
|
175
|
-
};
|
|
176
|
-
},
|
|
177
|
-
_internalServerPlugins({ plugins }) {
|
|
178
|
-
plugins.push({
|
|
179
|
-
name: serverPlugin,
|
|
180
|
-
options: transformRuntimeFn(internalOptions.csrConfig)
|
|
181
|
-
});
|
|
182
|
-
return {
|
|
183
|
-
plugins
|
|
184
|
-
};
|
|
185
|
-
},
|
|
186
|
-
config: async () => {
|
|
187
|
-
console.log("dataloader plugin config");
|
|
188
|
-
const patchMFConfigFn = patchMFConfig || _pathMfConfig;
|
|
189
|
-
return {
|
|
190
|
-
// server: {
|
|
191
|
-
// ssrByRouteIds: ssrByRouteIds,
|
|
192
|
-
// },
|
|
193
|
-
tools: {
|
|
194
|
-
rspack(_config, { isServer }) {
|
|
195
|
-
patchMFConfigFn({
|
|
196
|
-
mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
|
|
197
|
-
baseName,
|
|
198
|
-
metaName,
|
|
199
|
-
isServer,
|
|
200
|
-
routesFilePath
|
|
201
|
-
});
|
|
202
|
-
console.log("dataloader plugin rspack");
|
|
203
|
-
}
|
|
204
|
-
},
|
|
205
|
-
source: {
|
|
206
|
-
define: {
|
|
207
|
-
MODERN_ROUTER_ID_PREFIX: JSON.stringify((0, import_utils2.transformName2Prefix)(name))
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
var dataLoaderPlugin_default = moduleFederationDataLoaderPlugin;
|
|
216
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
217
|
-
0 && (module.exports = {
|
|
218
|
-
generateRoutes,
|
|
219
|
-
generateSlimRoutes,
|
|
220
|
-
moduleFederationDataLoaderPlugin
|
|
221
|
-
});
|
|
@@ -1,78 +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 dataLoaderPlugin_exports = {};
|
|
20
|
-
__export(dataLoaderPlugin_exports, {
|
|
21
|
-
default: () => dataLoaderPlugin_default
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(dataLoaderPlugin_exports);
|
|
24
|
-
var import_runtime = require("@module-federation/enhanced/runtime");
|
|
25
|
-
var import_constant = require("../../runtime/constant");
|
|
26
|
-
var dataLoaderPlugin_default = (mfRuntimeOptions) => ({
|
|
27
|
-
name: "MFDataLoaderServerPlugin",
|
|
28
|
-
pre: [
|
|
29
|
-
"@modern-js/plugin-inject-resource"
|
|
30
|
-
],
|
|
31
|
-
setup(api) {
|
|
32
|
-
const { remotes, name } = mfRuntimeOptions;
|
|
33
|
-
if (!remotes.length) {
|
|
34
|
-
return {};
|
|
35
|
-
}
|
|
36
|
-
let isHandled = false;
|
|
37
|
-
return {
|
|
38
|
-
prepare() {
|
|
39
|
-
const { middlewares } = api.useAppContext();
|
|
40
|
-
middlewares.push({
|
|
41
|
-
name: "MFDataLoaderServerPlugin",
|
|
42
|
-
handler: async (c, next) => {
|
|
43
|
-
console.log("isHandled : ", isHandled);
|
|
44
|
-
const serverManifest = c.get("serverManifest");
|
|
45
|
-
const { loaderBundles } = serverManifest;
|
|
46
|
-
console.log("loaderBundles.main.routes : ", loaderBundles.main.routes);
|
|
47
|
-
if (isHandled) {
|
|
48
|
-
await next();
|
|
49
|
-
} else {
|
|
50
|
-
const instance = (0, import_runtime.getInstance)() || (0, import_runtime.init)({
|
|
51
|
-
name,
|
|
52
|
-
remotes
|
|
53
|
-
});
|
|
54
|
-
const slimRoutes = await Promise.all(remotes.map(async (remote) => {
|
|
55
|
-
const { routes, baseName } = await instance.loadRemote(`${remote.name}/${import_constant.MF_SLIM_ROUTES}`);
|
|
56
|
-
return {
|
|
57
|
-
routes,
|
|
58
|
-
baseName
|
|
59
|
-
};
|
|
60
|
-
}));
|
|
61
|
-
slimRoutes.forEach((slimRoute) => {
|
|
62
|
-
const { routes, baseName } = slimRoute;
|
|
63
|
-
routes[0].path = `/${baseName}`;
|
|
64
|
-
loaderBundles.main.routes.push(...routes);
|
|
65
|
-
});
|
|
66
|
-
console.log("loaderBundles.main.routes : ", loaderBundles.main.routes);
|
|
67
|
-
isHandled = true;
|
|
68
|
-
await next();
|
|
69
|
-
}
|
|
70
|
-
},
|
|
71
|
-
before: [
|
|
72
|
-
"render"
|
|
73
|
-
]
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
});
|
|
@@ -1,16 +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 __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
var route_exports = {};
|
|
16
|
-
module.exports = __toCommonJS(route_exports);
|
|
@@ -1,34 +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
|
-
MF_FULL_ROUTES: () => MF_FULL_ROUTES,
|
|
22
|
-
MF_ROUTES_META: () => MF_ROUTES_META,
|
|
23
|
-
MF_SLIM_ROUTES: () => MF_SLIM_ROUTES
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(constant_exports);
|
|
26
|
-
const MF_SLIM_ROUTES = "mf-slim-routes";
|
|
27
|
-
const MF_FULL_ROUTES = "mf-full-routes";
|
|
28
|
-
const MF_ROUTES_META = "mf-routes-meta";
|
|
29
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
-
0 && (module.exports = {
|
|
31
|
-
MF_FULL_ROUTES,
|
|
32
|
-
MF_ROUTES_META,
|
|
33
|
-
MF_SLIM_ROUTES
|
|
34
|
-
});
|
|
@@ -1,87 +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 dataLoader_exports = {};
|
|
20
|
-
__export(dataLoader_exports, {
|
|
21
|
-
ssrDataLoaderPlugin: () => ssrDataLoaderPlugin
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(dataLoader_exports);
|
|
24
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
|
-
var import_runtime = require("@module-federation/enhanced/runtime");
|
|
26
|
-
var import_constant = require("./constant");
|
|
27
|
-
globalThis.mfRemoteRoutes = globalThis.mfRemoteRoutes || [];
|
|
28
|
-
var _globalThis_mfHasLoadedRemoteRoutes;
|
|
29
|
-
globalThis.mfHasLoadedRemoteRoutes = (_globalThis_mfHasLoadedRemoteRoutes = globalThis.mfHasLoadedRemoteRoutes) !== null && _globalThis_mfHasLoadedRemoteRoutes !== void 0 ? _globalThis_mfHasLoadedRemoteRoutes : false;
|
|
30
|
-
async function loadRoutes() {
|
|
31
|
-
var _getInstance;
|
|
32
|
-
if (globalThis.mfHasLoadedRemoteRoutes) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
const remotes = (_getInstance = (0, import_runtime.getInstance)()) === null || _getInstance === void 0 ? void 0 : _getInstance.options.remotes;
|
|
36
|
-
if (!remotes) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
const remoteModuleIds = remotes.map((remote) => {
|
|
40
|
-
return `${remote.name}/${import_constant.MF_FULL_ROUTES}`;
|
|
41
|
-
});
|
|
42
|
-
const traverse = (cRoutes, prefix) => {
|
|
43
|
-
cRoutes.forEach((i) => {
|
|
44
|
-
i.id = prefix + i.id;
|
|
45
|
-
const Comp = i.component;
|
|
46
|
-
i.element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Comp, {});
|
|
47
|
-
if (i.children) {
|
|
48
|
-
traverse(i.children, prefix);
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
await Promise.all(remoteModuleIds.map(async (remoteModuleId) => {
|
|
53
|
-
const remoteName = remoteModuleId.split(`/${import_constant.MF_FULL_ROUTES}`)[0];
|
|
54
|
-
const { routes, baseName } = await (0, import_runtime.loadRemote)(remoteModuleId);
|
|
55
|
-
routes[0].path = `/${baseName}`;
|
|
56
|
-
routes[0].isRoot = false;
|
|
57
|
-
globalThis.mfRemoteRoutes.push(...routes);
|
|
58
|
-
}));
|
|
59
|
-
globalThis.mfHasLoadedRemoteRoutes = true;
|
|
60
|
-
return globalThis.mfRemoteRoutes;
|
|
61
|
-
}
|
|
62
|
-
const ssrDataLoaderPlugin = () => {
|
|
63
|
-
return {
|
|
64
|
-
name: "@modern-js/plugin-mf-data-loader",
|
|
65
|
-
post: [
|
|
66
|
-
"@modern-js/plugin-router"
|
|
67
|
-
],
|
|
68
|
-
setup: () => {
|
|
69
|
-
return {
|
|
70
|
-
async beforeRender({ context }) {
|
|
71
|
-
console.log("init");
|
|
72
|
-
await loadRoutes();
|
|
73
|
-
},
|
|
74
|
-
modifyRoutes: (routes) => {
|
|
75
|
-
console.log("modifyRoutes");
|
|
76
|
-
routes.push(...globalThis.mfRemoteRoutes);
|
|
77
|
-
console.log("routes: ", routes);
|
|
78
|
-
return routes;
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
};
|
|
84
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
85
|
-
0 && (module.exports = {
|
|
86
|
-
ssrDataLoaderPlugin
|
|
87
|
-
});
|
|
@@ -1,43 +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 utils_exports = {};
|
|
20
|
-
__export(utils_exports, {
|
|
21
|
-
transformName2Prefix: () => transformName2Prefix
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(utils_exports);
|
|
24
|
-
function transformName2Prefix(name) {
|
|
25
|
-
const NameTransformSymbol = {
|
|
26
|
-
AT: "@",
|
|
27
|
-
HYPHEN: "-",
|
|
28
|
-
SLASH: "/",
|
|
29
|
-
UNDERLINE: "_"
|
|
30
|
-
};
|
|
31
|
-
const NameTransformMap = {
|
|
32
|
-
[NameTransformSymbol.AT]: "SCOPE",
|
|
33
|
-
[NameTransformSymbol.HYPHEN]: "HYPHEN",
|
|
34
|
-
[NameTransformSymbol.SLASH]: "SLASH",
|
|
35
|
-
[NameTransformSymbol.UNDERLINE]: "UNDERLINE"
|
|
36
|
-
};
|
|
37
|
-
const SPLIT_SYMBOL = "@";
|
|
38
|
-
return `${name.replace(new RegExp(`${NameTransformSymbol.AT}`, "g"), NameTransformMap[NameTransformSymbol.AT]).replace(new RegExp(`${NameTransformSymbol.HYPHEN}`, "g"), NameTransformMap[NameTransformSymbol.HYPHEN]).replace(new RegExp(`${NameTransformSymbol.SLASH}`, "g"), NameTransformMap[NameTransformSymbol.SLASH]).replace(new RegExp(`${NameTransformSymbol.UNDERLINE}`, "g"), NameTransformMap[NameTransformSymbol.UNDERLINE])}${SPLIT_SYMBOL}`;
|
|
39
|
-
}
|
|
40
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
-
0 && (module.exports = {
|
|
42
|
-
transformName2Prefix
|
|
43
|
-
});
|
|
@@ -1,31 +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 withMFRouteId_exports = {};
|
|
20
|
-
__export(withMFRouteId_exports, {
|
|
21
|
-
withMFRouteId: () => withMFRouteId
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(withMFRouteId_exports);
|
|
24
|
-
function withMFRouteId(id) {
|
|
25
|
-
const prefix = typeof MODERN_ROUTER_ID_PREFIX === "string" ? MODERN_ROUTER_ID_PREFIX : "";
|
|
26
|
-
return prefix + id;
|
|
27
|
-
}
|
|
28
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
29
|
-
0 && (module.exports = {
|
|
30
|
-
withMFRouteId
|
|
31
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
var IS_ROOT = "isRoot";
|
|
2
|
-
var ID = "id";
|
|
3
|
-
var COMPONENT = "component";
|
|
4
|
-
var LAZY_COMPONENT = "lazyImport";
|
|
5
|
-
var SHOULD_REVALIDATE = "shouldRevalidate";
|
|
6
|
-
var PRIVATE_COMPONENT = "_component";
|
|
7
|
-
var ELEMENT = "element";
|
|
8
|
-
export {
|
|
9
|
-
COMPONENT,
|
|
10
|
-
ELEMENT,
|
|
11
|
-
ID,
|
|
12
|
-
IS_ROOT,
|
|
13
|
-
LAZY_COMPONENT,
|
|
14
|
-
PRIVATE_COMPONENT,
|
|
15
|
-
SHOULD_REVALIDATE
|
|
16
|
-
};
|