@module-federation/modern-js 0.0.0-next-20240816090839 → 0.0.0-next-20240816102736
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/ast/constant.js +49 -0
- package/dist/cjs/cli/ast/generateRoutes.js +140 -0
- package/dist/cjs/cli/ast/generateSerializableRoutes.js +91 -0
- package/dist/cjs/cli/ast/generateSlimRoutes.js +106 -0
- package/dist/cjs/cli/ast/index.js +34 -0
- package/dist/cjs/cli/bundler-plugins/SerializableRoutesPlugin.js +65 -0
- package/dist/cjs/cli/constant.js +6 -0
- package/dist/cjs/cli/dataLoaderPlugin.js +281 -0
- package/dist/cjs/cli/index.js +6 -1
- package/dist/cjs/cli/server/dataLoaderPlugin.js +83 -0
- package/dist/cjs/cli/ssrPlugin.js +4 -4
- package/dist/cjs/cli/utils.js +4 -2
- package/dist/cjs/interfaces/route.js +16 -0
- package/dist/cjs/runtime/constant.js +34 -0
- package/dist/cjs/runtime/dataLoader.js +87 -0
- package/dist/cjs/runtime/index.js +4 -1
- package/dist/cjs/runtime/utils.js +43 -0
- package/dist/cjs/runtime/withMFRouteId.js +31 -0
- package/dist/cjs/ssr-runtime/plugin.js +8 -7
- package/dist/esm/cli/ast/constant.js +18 -0
- package/dist/esm/cli/ast/generateRoutes.js +107 -0
- package/dist/esm/cli/ast/generateSerializableRoutes.js +58 -0
- package/dist/esm/cli/ast/generateSlimRoutes.js +75 -0
- package/dist/esm/cli/ast/index.js +8 -0
- package/dist/esm/cli/bundler-plugins/SerializableRoutesPlugin.js +45 -0
- package/dist/esm/cli/constant.js +4 -0
- package/dist/esm/cli/dataLoaderPlugin.js +326 -0
- package/dist/esm/cli/index.js +6 -1
- package/dist/esm/cli/server/dataLoaderPlugin.js +146 -0
- package/dist/esm/cli/ssrPlugin.js +2 -2
- package/dist/esm/cli/utils.js +2 -1
- package/dist/esm/interfaces/route.js +0 -0
- package/dist/esm/runtime/constant.js +8 -0
- package/dist/esm/runtime/dataLoader.js +125 -0
- package/dist/esm/runtime/index.js +3 -1
- package/dist/esm/runtime/utils.js +16 -0
- package/dist/esm/runtime/withMFRouteId.js +7 -0
- package/dist/esm/ssr-runtime/plugin.js +8 -10
- package/dist/esm-node/cli/ast/constant.js +18 -0
- package/dist/esm-node/cli/ast/generateRoutes.js +106 -0
- package/dist/esm-node/cli/ast/generateSerializableRoutes.js +57 -0
- package/dist/esm-node/cli/ast/generateSlimRoutes.js +72 -0
- package/dist/esm-node/cli/ast/index.js +8 -0
- package/dist/esm-node/cli/bundler-plugins/SerializableRoutesPlugin.js +30 -0
- package/dist/esm-node/cli/constant.js +4 -0
- package/dist/esm-node/cli/dataLoaderPlugin.js +245 -0
- package/dist/esm-node/cli/index.js +6 -1
- package/dist/esm-node/cli/server/dataLoaderPlugin.js +63 -0
- package/dist/esm-node/cli/ssrPlugin.js +2 -2
- package/dist/esm-node/cli/utils.js +2 -1
- package/dist/esm-node/interfaces/route.js +0 -0
- package/dist/esm-node/runtime/constant.js +8 -0
- package/dist/esm-node/runtime/dataLoader.js +63 -0
- package/dist/esm-node/runtime/index.js +3 -1
- package/dist/esm-node/runtime/utils.js +19 -0
- package/dist/esm-node/runtime/withMFRouteId.js +7 -0
- package/dist/esm-node/ssr-runtime/plugin.js +8 -7
- package/dist/types/cli/ast/constant.d.ts +8 -0
- package/dist/types/cli/ast/generateRoutes.d.ts +7 -0
- package/dist/types/cli/ast/generateSerializableRoutes.d.ts +5 -0
- package/dist/types/cli/ast/generateSlimRoutes.d.ts +7 -0
- package/dist/types/cli/ast/index.d.ts +3 -0
- package/dist/types/cli/bundler-plugins/SerializableRoutesPlugin.d.ts +12 -0
- package/dist/types/cli/constant.d.ts +2 -0
- package/dist/types/cli/dataLoaderPlugin.d.ts +6 -0
- package/dist/types/cli/server/dataLoaderPlugin.d.ts +5 -0
- package/dist/types/cli/utils.d.ts +1 -0
- package/dist/types/interfaces/route.d.ts +13 -0
- package/dist/types/runtime/constant.d.ts +3 -0
- package/dist/types/runtime/dataLoader.d.ts +7 -0
- package/dist/types/runtime/index.d.ts +1 -0
- package/dist/types/runtime/utils.d.ts +1 -0
- package/dist/types/runtime/withMFRouteId.d.ts +1 -0
- package/dist/types/types/index.d.ts +18 -0
- package/package.json +37 -11
|
@@ -0,0 +1,281 @@
|
|
|
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
|
+
});
|
package/dist/cjs/cli/index.js
CHANGED
|
@@ -27,6 +27,7 @@ var import_enhanced = require("@module-federation/enhanced");
|
|
|
27
27
|
var import_rspack = require("@module-federation/enhanced/rspack");
|
|
28
28
|
var import_configPlugin = require("./configPlugin");
|
|
29
29
|
var import_ssrPlugin = require("./ssrPlugin");
|
|
30
|
+
var import_dataLoaderPlugin = require("./dataLoaderPlugin");
|
|
30
31
|
var import_enhanced2 = require("@module-federation/enhanced");
|
|
31
32
|
const moduleFederationPlugin = (userConfig = {}) => {
|
|
32
33
|
const internalModernPluginOptions = {
|
|
@@ -79,7 +80,11 @@ const moduleFederationPlugin = (userConfig = {}) => {
|
|
|
79
80
|
},
|
|
80
81
|
usePlugins: [
|
|
81
82
|
(0, import_configPlugin.moduleFederationConfigPlugin)(internalModernPluginOptions),
|
|
82
|
-
(0, import_ssrPlugin.moduleFederationSSRPlugin)(internalModernPluginOptions)
|
|
83
|
+
(0, import_ssrPlugin.moduleFederationSSRPlugin)(internalModernPluginOptions),
|
|
84
|
+
(0, import_dataLoaderPlugin.moduleFederationDataLoaderPlugin)(Boolean(userConfig.dataLoader), internalModernPluginOptions, {
|
|
85
|
+
baseName: "",
|
|
86
|
+
...userConfig.dataLoader
|
|
87
|
+
})
|
|
83
88
|
]
|
|
84
89
|
};
|
|
85
90
|
};
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
});
|
|
@@ -35,9 +35,9 @@ __export(ssrPlugin_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(ssrPlugin_exports);
|
|
36
36
|
var import_path = __toESM(require("path"));
|
|
37
37
|
var import_utils = require("@modern-js/utils");
|
|
38
|
-
var
|
|
38
|
+
var import_enhanced = require("@module-federation/enhanced");
|
|
39
39
|
var import_rspack = require("@module-federation/enhanced/rspack");
|
|
40
|
-
var
|
|
40
|
+
var import_node = require("@module-federation/node");
|
|
41
41
|
var import_manifest = require("./manifest");
|
|
42
42
|
var import_constant = require("./constant");
|
|
43
43
|
function setEnv() {
|
|
@@ -101,7 +101,7 @@ const moduleFederationSSRPlugin = (userConfig) => ({
|
|
|
101
101
|
if (isServer) {
|
|
102
102
|
if (!userConfig.nodePlugin) {
|
|
103
103
|
var _config_plugins;
|
|
104
|
-
userConfig.nodePlugin = new
|
|
104
|
+
userConfig.nodePlugin = new import_enhanced.ModuleFederationPlugin(userConfig.ssrConfig);
|
|
105
105
|
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(userConfig.nodePlugin);
|
|
106
106
|
}
|
|
107
107
|
} else {
|
|
@@ -141,7 +141,7 @@ const moduleFederationSSRPlugin = (userConfig) => ({
|
|
|
141
141
|
if (isServer) {
|
|
142
142
|
chain.target("async-node");
|
|
143
143
|
if (import_constant.isDev) {
|
|
144
|
-
chain.plugin("UniverseEntryChunkTrackerPlugin").use(
|
|
144
|
+
chain.plugin("UniverseEntryChunkTrackerPlugin").use(import_node.UniverseEntryChunkTrackerPlugin);
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
if (import_constant.isDev && !isServer) {
|
package/dist/cjs/cli/utils.js
CHANGED
|
@@ -32,7 +32,8 @@ __export(utils_exports, {
|
|
|
32
32
|
getMFConfig: () => getMFConfig,
|
|
33
33
|
patchBundlerConfig: () => patchBundlerConfig,
|
|
34
34
|
patchIgnoreWarning: () => patchIgnoreWarning,
|
|
35
|
-
patchMFConfig: () => patchMFConfig
|
|
35
|
+
patchMFConfig: () => patchMFConfig,
|
|
36
|
+
replaceRemoteUrl: () => replaceRemoteUrl
|
|
36
37
|
});
|
|
37
38
|
module.exports = __toCommonJS(utils_exports);
|
|
38
39
|
var import_sdk = require("@module-federation/sdk");
|
|
@@ -329,5 +330,6 @@ function autoDeleteSplitChunkCacheGroups(mfConfig, bundlerConfig) {
|
|
|
329
330
|
getMFConfig,
|
|
330
331
|
patchBundlerConfig,
|
|
331
332
|
patchIgnoreWarning,
|
|
332
|
-
patchMFConfig
|
|
333
|
+
patchMFConfig,
|
|
334
|
+
replaceRemoteUrl
|
|
333
335
|
});
|
|
@@ -0,0 +1,16 @@
|
|
|
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);
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
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
|
+
});
|
|
@@ -19,13 +19,16 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
|
|
|
19
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
20
|
var runtime_exports = {};
|
|
21
21
|
__export(runtime_exports, {
|
|
22
|
-
createRemoteSSRComponent: () => import_createRemoteSSRComponent.createRemoteSSRComponent
|
|
22
|
+
createRemoteSSRComponent: () => import_createRemoteSSRComponent.createRemoteSSRComponent,
|
|
23
|
+
withMFRouteId: () => import_withMFRouteId.withMFRouteId
|
|
23
24
|
});
|
|
24
25
|
module.exports = __toCommonJS(runtime_exports);
|
|
25
26
|
__reExport(runtime_exports, require("@module-federation/enhanced/runtime"), module.exports);
|
|
26
27
|
var import_createRemoteSSRComponent = require("./createRemoteSSRComponent");
|
|
28
|
+
var import_withMFRouteId = require("./withMFRouteId");
|
|
27
29
|
// Annotate the CommonJS export names for ESM import in node:
|
|
28
30
|
0 && (module.exports = {
|
|
29
31
|
createRemoteSSRComponent,
|
|
32
|
+
withMFRouteId,
|
|
30
33
|
...require("@module-federation/enhanced/runtime")
|
|
31
34
|
});
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
});
|