@module-federation/modern-js 0.0.0-next-20240816084239 → 0.0.0-next-20240816090839
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/constant.js +0 -6
- package/dist/cjs/cli/index.js +1 -6
- package/dist/cjs/cli/ssrPlugin.js +4 -4
- package/dist/cjs/cli/utils.js +2 -4
- package/dist/cjs/runtime/index.js +1 -4
- package/dist/cjs/ssr-runtime/plugin.js +7 -5
- 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/cli/utils.js +1 -2
- package/dist/esm/runtime/index.js +1 -3
- package/dist/esm/ssr-runtime/plugin.js +10 -5
- 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/cli/utils.js +1 -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/cli/utils.d.ts +0 -1
- package/dist/types/runtime/index.d.ts +0 -1
- package/dist/types/types/index.d.ts +0 -18
- package/package.json +11 -37
- package/dist/cjs/cli/ast/constant.js +0 -49
- package/dist/cjs/cli/ast/generateRoutes.js +0 -140
- package/dist/cjs/cli/ast/generateSerializableRoutes.js +0 -91
- package/dist/cjs/cli/ast/generateSlimRoutes.js +0 -106
- package/dist/cjs/cli/ast/index.js +0 -34
- package/dist/cjs/cli/bundler-plugins/SerializableRoutesPlugin.js +0 -65
- package/dist/cjs/cli/dataLoaderPlugin.js +0 -281
- package/dist/cjs/cli/server/dataLoaderPlugin.js +0 -83
- 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 -18
- package/dist/esm/cli/ast/generateRoutes.js +0 -107
- package/dist/esm/cli/ast/generateSerializableRoutes.js +0 -58
- package/dist/esm/cli/ast/generateSlimRoutes.js +0 -75
- package/dist/esm/cli/ast/index.js +0 -8
- package/dist/esm/cli/bundler-plugins/SerializableRoutesPlugin.js +0 -45
- package/dist/esm/cli/dataLoaderPlugin.js +0 -326
- package/dist/esm/cli/server/dataLoaderPlugin.js +0 -146
- 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 -18
- package/dist/esm-node/cli/ast/generateRoutes.js +0 -106
- package/dist/esm-node/cli/ast/generateSerializableRoutes.js +0 -57
- package/dist/esm-node/cli/ast/generateSlimRoutes.js +0 -72
- package/dist/esm-node/cli/ast/index.js +0 -8
- package/dist/esm-node/cli/bundler-plugins/SerializableRoutesPlugin.js +0 -30
- package/dist/esm-node/cli/dataLoaderPlugin.js +0 -245
- package/dist/esm-node/cli/server/dataLoaderPlugin.js +0 -63
- 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 -8
- package/dist/types/cli/ast/generateRoutes.d.ts +0 -7
- package/dist/types/cli/ast/generateSerializableRoutes.d.ts +0 -5
- package/dist/types/cli/ast/generateSlimRoutes.d.ts +0 -7
- package/dist/types/cli/ast/index.d.ts +0 -3
- package/dist/types/cli/bundler-plugins/SerializableRoutesPlugin.d.ts +0 -12
- 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,281 +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
|
-
var import_utils3 = require("./utils");
|
|
45
|
-
var import_SerializableRoutesPlugin = require("./bundler-plugins/SerializableRoutesPlugin");
|
|
46
|
-
function generateExtraExposeFiles(options) {
|
|
47
|
-
const { routesFilePath, mfConfig, isServer, baseName } = options;
|
|
48
|
-
const outputDir = import_path.default.resolve(process.cwd(), "node_modules/.federation");
|
|
49
|
-
import_utils.fs.ensureDirSync(outputDir);
|
|
50
|
-
const addSuffix = (fileName) => {
|
|
51
|
-
if (!isServer) {
|
|
52
|
-
return `${fileName}.jsx`;
|
|
53
|
-
}
|
|
54
|
-
return `${fileName}.server.jsx`;
|
|
55
|
-
};
|
|
56
|
-
const routesFileContent = import_utils.fs.readFileSync(routesFilePath, "utf-8");
|
|
57
|
-
const outputSlimRoutesPath = import_path.default.resolve(outputDir, addSuffix(import_constant2.MF_SLIM_ROUTES));
|
|
58
|
-
const outputFullRoutesPath = import_path.default.resolve(outputDir, addSuffix(import_constant2.MF_FULL_ROUTES));
|
|
59
|
-
const outputRoutesMetaPath = import_path.default.resolve(outputDir, `${import_constant2.MF_ROUTES_META}.js`);
|
|
60
|
-
(0, import_ast.generateSlimRoutes)({
|
|
61
|
-
sourceCode: routesFileContent,
|
|
62
|
-
filePath: outputSlimRoutesPath,
|
|
63
|
-
prefix: (0, import_utils2.transformName2Prefix)(mfConfig.name),
|
|
64
|
-
baseName
|
|
65
|
-
});
|
|
66
|
-
(0, import_ast.generateRoutes)({
|
|
67
|
-
sourceCode: routesFileContent,
|
|
68
|
-
filePath: outputFullRoutesPath,
|
|
69
|
-
prefix: (0, import_utils2.transformName2Prefix)(mfConfig.name),
|
|
70
|
-
baseName
|
|
71
|
-
});
|
|
72
|
-
import_utils.fs.writeFileSync(outputRoutesMetaPath, `export const baseName = '${baseName}';`);
|
|
73
|
-
return {
|
|
74
|
-
outputSlimRoutesPath,
|
|
75
|
-
outputFullRoutesPath,
|
|
76
|
-
outputRoutesMetaPath
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
function addExpose(options) {
|
|
80
|
-
const { mfConfig } = options;
|
|
81
|
-
const { outputSlimRoutesPath, outputFullRoutesPath, outputRoutesMetaPath } = generateExtraExposeFiles(options);
|
|
82
|
-
const fullRoutesKey = `./${import_constant2.MF_FULL_ROUTES}`;
|
|
83
|
-
const slimRoutesKey = `./${import_constant2.MF_SLIM_ROUTES}`;
|
|
84
|
-
const routeMetaKey = `./${import_constant2.MF_ROUTES_META}`;
|
|
85
|
-
if (!mfConfig.exposes) {
|
|
86
|
-
mfConfig.exposes = {
|
|
87
|
-
[fullRoutesKey]: outputFullRoutesPath,
|
|
88
|
-
[slimRoutesKey]: outputSlimRoutesPath,
|
|
89
|
-
[routeMetaKey]: outputRoutesMetaPath
|
|
90
|
-
};
|
|
91
|
-
} else {
|
|
92
|
-
if (!Array.isArray(mfConfig.exposes)) {
|
|
93
|
-
if (!mfConfig.exposes[fullRoutesKey]) {
|
|
94
|
-
mfConfig.exposes[fullRoutesKey] = outputFullRoutesPath;
|
|
95
|
-
}
|
|
96
|
-
if (!mfConfig.exposes[slimRoutesKey]) {
|
|
97
|
-
mfConfig.exposes[slimRoutesKey] = outputSlimRoutesPath;
|
|
98
|
-
}
|
|
99
|
-
if (!mfConfig.exposes[routeMetaKey]) {
|
|
100
|
-
mfConfig.exposes[routeMetaKey] = outputRoutesMetaPath;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
function addShared(options) {
|
|
106
|
-
const { metaName, mfConfig } = options;
|
|
107
|
-
const alias = `@${metaName}/runtime/router`;
|
|
108
|
-
if (!mfConfig.shared) {
|
|
109
|
-
mfConfig.shared = {
|
|
110
|
-
[alias]: {
|
|
111
|
-
singleton: true
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
} else {
|
|
115
|
-
if (!Array.isArray(mfConfig.shared)) {
|
|
116
|
-
mfConfig.shared[alias] = {
|
|
117
|
-
singleton: true
|
|
118
|
-
};
|
|
119
|
-
} else {
|
|
120
|
-
mfConfig.shared.push(alias);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
function _pathMfConfig(options) {
|
|
125
|
-
addShared(options);
|
|
126
|
-
addExpose(options);
|
|
127
|
-
}
|
|
128
|
-
async function _fetchSSRByRouteIds(partialSSRRemotes, mfConfig, transformRuntimeFn) {
|
|
129
|
-
const partialMfConfig = {
|
|
130
|
-
name: mfConfig.name,
|
|
131
|
-
remotes: {
|
|
132
|
-
...mfConfig.remotes
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
(0, import_utils3.replaceRemoteUrl)(partialMfConfig, "ipv4");
|
|
136
|
-
const runtimeInitOptions = transformRuntimeFn(partialMfConfig);
|
|
137
|
-
if (!runtimeInitOptions.remotes.length || !partialSSRRemotes.length) {
|
|
138
|
-
return void 0;
|
|
139
|
-
}
|
|
140
|
-
const remoteProviderRouteIds = /* @__PURE__ */ new Set();
|
|
141
|
-
const collectIds = (route) => {
|
|
142
|
-
remoteProviderRouteIds.add(route.id);
|
|
143
|
-
if (route.children) {
|
|
144
|
-
route.children.forEach((r) => {
|
|
145
|
-
collectIds(r);
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
await Promise.all(runtimeInitOptions.remotes.map(async (remote) => {
|
|
150
|
-
const entry = "entry" in remote ? remote.entry : "";
|
|
151
|
-
if (!entry) {
|
|
152
|
-
return void 0;
|
|
153
|
-
}
|
|
154
|
-
const ipv4 = (0, import_utils3.getIPV4)();
|
|
155
|
-
const url = new URL(entry);
|
|
156
|
-
const serializableRoutesUrl = url.href.replace(url.pathname, `/${import_SerializableRoutesPlugin.SERIALIZABLE_ROUTES}`).replace("localhost", ipv4);
|
|
157
|
-
const serializableRoutesRet = await fetch(serializableRoutesUrl);
|
|
158
|
-
const serializableRoutes = await serializableRoutesRet.json();
|
|
159
|
-
serializableRoutes.forEach((serializableRoute) => {
|
|
160
|
-
collectIds(serializableRoute);
|
|
161
|
-
});
|
|
162
|
-
}));
|
|
163
|
-
return [
|
|
164
|
-
...remoteProviderRouteIds
|
|
165
|
-
];
|
|
166
|
-
}
|
|
167
|
-
function _transformRuntimeOptions(buildOptions) {
|
|
168
|
-
const remotes = buildOptions.remotes || {};
|
|
169
|
-
const runtimeRemotes = Object.entries(remotes).map((remote) => {
|
|
170
|
-
const [_alias, nameAndEntry] = remote;
|
|
171
|
-
const [name, entry] = nameAndEntry.split("@");
|
|
172
|
-
return {
|
|
173
|
-
name,
|
|
174
|
-
entry
|
|
175
|
-
};
|
|
176
|
-
});
|
|
177
|
-
return {
|
|
178
|
-
name: buildOptions.name,
|
|
179
|
-
remotes: runtimeRemotes
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
const moduleFederationDataLoaderPlugin = (enable, internalOptions, userConfig) => ({
|
|
183
|
-
name: "@modern-js/plugin-module-federation-data-loader",
|
|
184
|
-
pre: [
|
|
185
|
-
"@modern-js/plugin-module-federation-config"
|
|
186
|
-
],
|
|
187
|
-
post: [
|
|
188
|
-
"@modern-js/plugin-router",
|
|
189
|
-
"@modern-js/plugin-module-federation"
|
|
190
|
-
],
|
|
191
|
-
setup: async ({ useConfigContext, useAppContext }) => {
|
|
192
|
-
var _modernjsConfig_server, _internalOptions_csrConfig;
|
|
193
|
-
if (!enable) {
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
const { baseName, partialSSRRemotes = [], fetchSSRByRouteIds, patchMFConfig, metaName = import_constant3.META_NAME, serverPlugin = "@module-federation/modern-js/data-loader-server", transformRuntimeOptions } = userConfig;
|
|
197
|
-
if (!baseName) {
|
|
198
|
-
throw new Error(`${import_constant.PLUGIN_IDENTIFIER} 'baseName' is required if you enable 'dataLoader'!`);
|
|
199
|
-
}
|
|
200
|
-
const modernjsConfig = useConfigContext();
|
|
201
|
-
const appContext = useAppContext();
|
|
202
|
-
const enableSSR = Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
203
|
-
const name = (_internalOptions_csrConfig = internalOptions.csrConfig) === null || _internalOptions_csrConfig === void 0 ? void 0 : _internalOptions_csrConfig.name;
|
|
204
|
-
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}`);
|
|
205
|
-
const transformRuntimeFn = transformRuntimeOptions || _transformRuntimeOptions;
|
|
206
|
-
return {
|
|
207
|
-
_internalRuntimePlugins: ({ entrypoint, plugins }) => {
|
|
208
|
-
plugins.push({
|
|
209
|
-
name: "ssrDataLoader",
|
|
210
|
-
path: "@module-federation/modern-js/data-loader",
|
|
211
|
-
config: {}
|
|
212
|
-
});
|
|
213
|
-
return {
|
|
214
|
-
entrypoint,
|
|
215
|
-
plugins
|
|
216
|
-
};
|
|
217
|
-
},
|
|
218
|
-
_internalServerPlugins({ plugins }) {
|
|
219
|
-
plugins.push({
|
|
220
|
-
name: serverPlugin,
|
|
221
|
-
options: transformRuntimeFn(internalOptions.csrConfig)
|
|
222
|
-
});
|
|
223
|
-
return {
|
|
224
|
-
plugins
|
|
225
|
-
};
|
|
226
|
-
},
|
|
227
|
-
config: async () => {
|
|
228
|
-
const fetchFn = fetchSSRByRouteIds || _fetchSSRByRouteIds;
|
|
229
|
-
const ssrByRouteIds = await fetchFn(partialSSRRemotes, internalOptions.csrConfig, transformRuntimeFn);
|
|
230
|
-
const patchMFConfigFn = patchMFConfig || _pathMfConfig;
|
|
231
|
-
return {
|
|
232
|
-
server: {
|
|
233
|
-
ssrByRouteIds
|
|
234
|
-
},
|
|
235
|
-
tools: {
|
|
236
|
-
rspack(_config, { isServer }) {
|
|
237
|
-
patchMFConfigFn({
|
|
238
|
-
mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
|
|
239
|
-
baseName,
|
|
240
|
-
metaName,
|
|
241
|
-
isServer,
|
|
242
|
-
routesFilePath
|
|
243
|
-
});
|
|
244
|
-
},
|
|
245
|
-
webpack(_config, { isServer }) {
|
|
246
|
-
patchMFConfigFn({
|
|
247
|
-
mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
|
|
248
|
-
baseName,
|
|
249
|
-
metaName,
|
|
250
|
-
isServer,
|
|
251
|
-
routesFilePath
|
|
252
|
-
});
|
|
253
|
-
},
|
|
254
|
-
bundlerChain(chain, { isServer }) {
|
|
255
|
-
if (!isServer && internalOptions.csrConfig && Object.keys(internalOptions.csrConfig.exposes).length) {
|
|
256
|
-
chain.plugin("SerializableRoutesPlugin").use(import_SerializableRoutesPlugin.SerializableRoutesPlugin, [
|
|
257
|
-
{
|
|
258
|
-
routesFilePath,
|
|
259
|
-
prefix: (0, import_utils2.transformName2Prefix)(internalOptions.csrConfig.name)
|
|
260
|
-
}
|
|
261
|
-
]);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
},
|
|
265
|
-
source: {
|
|
266
|
-
define: {
|
|
267
|
-
MODERN_ROUTER_ID_PREFIX: JSON.stringify((0, import_utils2.transformName2Prefix)(name))
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
var dataLoaderPlugin_default = moduleFederationDataLoaderPlugin;
|
|
276
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
277
|
-
0 && (module.exports = {
|
|
278
|
-
generateRoutes,
|
|
279
|
-
generateSlimRoutes,
|
|
280
|
-
moduleFederationDataLoaderPlugin
|
|
281
|
-
});
|
|
@@ -1,83 +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
|
-
async function getSlimRemotes(mfInstance) {
|
|
27
|
-
return await Promise.all(mfInstance.options.remotes.map(async (remote) => {
|
|
28
|
-
const { routes, baseName } = await mfInstance.loadRemote(`${remote.name}/${import_constant.MF_SLIM_ROUTES}`);
|
|
29
|
-
return {
|
|
30
|
-
routes,
|
|
31
|
-
baseName
|
|
32
|
-
};
|
|
33
|
-
}));
|
|
34
|
-
}
|
|
35
|
-
var dataLoaderPlugin_default = (mfRuntimeOptions) => ({
|
|
36
|
-
name: "MFDataLoaderServerPlugin",
|
|
37
|
-
pre: [
|
|
38
|
-
"@modern-js/plugin-inject-resource"
|
|
39
|
-
],
|
|
40
|
-
setup(api) {
|
|
41
|
-
const { remotes, name } = mfRuntimeOptions;
|
|
42
|
-
if (!remotes.length) {
|
|
43
|
-
return {};
|
|
44
|
-
}
|
|
45
|
-
let isHandled = false;
|
|
46
|
-
return {
|
|
47
|
-
prepare() {
|
|
48
|
-
const { middlewares } = api.useAppContext();
|
|
49
|
-
middlewares.push({
|
|
50
|
-
name: "MFDataLoaderServerPlugin",
|
|
51
|
-
handler: async (c, next) => {
|
|
52
|
-
console.log("isHandled : ", isHandled);
|
|
53
|
-
const serverManifest = c.get("serverManifest");
|
|
54
|
-
const { loaderBundles, nestedRoutesJson } = serverManifest;
|
|
55
|
-
console.log("nestedRoutesJson: ", nestedRoutesJson);
|
|
56
|
-
console.log("loaderBundles.main.routes : ", loaderBundles.main.routes);
|
|
57
|
-
if (isHandled) {
|
|
58
|
-
await next();
|
|
59
|
-
} else {
|
|
60
|
-
const instance = (0, import_runtime.getInstance)() || (0, import_runtime.init)({
|
|
61
|
-
name,
|
|
62
|
-
remotes
|
|
63
|
-
});
|
|
64
|
-
const slimRoutes = await getSlimRemotes(instance);
|
|
65
|
-
slimRoutes.forEach((slimRoute) => {
|
|
66
|
-
const { routes, baseName } = slimRoute;
|
|
67
|
-
routes[0].path = `/${baseName}`;
|
|
68
|
-
loaderBundles.main.routes.push(...routes);
|
|
69
|
-
nestedRoutesJson.default.main.push(...routes);
|
|
70
|
-
});
|
|
71
|
-
console.log("push loaderBundles.main.routes done ");
|
|
72
|
-
isHandled = true;
|
|
73
|
-
await next();
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
before: [
|
|
77
|
-
"render"
|
|
78
|
-
]
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
});
|
|
@@ -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,18 +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
|
-
var LOADER = "loader";
|
|
9
|
-
export {
|
|
10
|
-
COMPONENT,
|
|
11
|
-
ELEMENT,
|
|
12
|
-
ID,
|
|
13
|
-
IS_ROOT,
|
|
14
|
-
LAZY_COMPONENT,
|
|
15
|
-
LOADER,
|
|
16
|
-
PRIVATE_COMPONENT,
|
|
17
|
-
SHOULD_REVALIDATE
|
|
18
|
-
};
|