@module-federation/modern-js 0.0.0-next-20241010084324 → 0.0.0-next-20241011070539
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/cli/dataLoader/ast/constant.js +49 -0
- package/dist/cjs/cli/dataLoader/ast/generateRoutes.js +143 -0
- package/dist/cjs/cli/{constant.js → dataLoader/ast/index.js} +6 -6
- package/dist/cjs/cli/dataLoader/clearMFCache.js +57 -0
- package/dist/cjs/cli/dataLoader/generateRouteFile.js +148 -0
- package/dist/cjs/cli/dataLoader/patchMFConfig.js +137 -0
- package/dist/cjs/cli/dataLoader/plugin.js +219 -0
- package/dist/cjs/cli/index.js +5 -1
- package/dist/cjs/cli/mfRuntimePlugins/{inject-node-fetch.js → node-fetch.js} +6 -6
- package/dist/cjs/cli/mfRuntimePlugins/node.js +41 -0
- package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +40 -38
- package/dist/cjs/cli/server/dataLoaderPlugin.js +81 -0
- package/dist/cjs/cli/server/fetchRemoteFullRoutesMap.js +72 -0
- package/dist/cjs/cli/ssrPlugin.js +5 -2
- package/dist/cjs/cli/utils.js +11 -6
- package/dist/cjs/cli/utils.spec.js +5 -6
- package/dist/cjs/constant.js +35 -2
- package/dist/cjs/interfaces/route.js +16 -0
- package/dist/cjs/runtime/dataLoader/plugin-inject-assets.js +92 -0
- package/dist/cjs/runtime/dataLoader/plugin.js +75 -0
- package/dist/cjs/runtime/dataLoader/utils.js +110 -0
- package/dist/cjs/runtime/index.js +4 -1
- package/dist/cjs/{cli/mfRuntimePlugins/shared-strategy.js → runtime/withMFRouteId.js} +11 -23
- package/dist/cjs/ssr-runtime/plugin.js +7 -8
- package/dist/cjs/types/modern.js +16 -0
- package/dist/esm/cli/dataLoader/ast/constant.js +18 -0
- package/dist/esm/cli/dataLoader/ast/generateRoutes.js +110 -0
- package/dist/esm/cli/dataLoader/ast/index.js +4 -0
- package/dist/esm/cli/dataLoader/clearMFCache.js +34 -0
- package/dist/esm/cli/dataLoader/generateRouteFile.js +308 -0
- package/dist/esm/cli/dataLoader/patchMFConfig.js +103 -0
- package/dist/esm/cli/dataLoader/plugin.js +341 -0
- package/dist/esm/cli/index.js +6 -2
- package/dist/esm/cli/mfRuntimePlugins/{inject-node-fetch.js → node-fetch.js} +3 -3
- package/dist/esm/cli/mfRuntimePlugins/node.js +13 -0
- package/dist/esm/cli/server/dataLoaderPlugin.js +104 -0
- package/dist/esm/cli/server/fetchRemoteFullRoutesMap.js +93 -0
- package/dist/esm/cli/ssrPlugin.js +6 -3
- package/dist/esm/cli/utils.js +13 -8
- package/dist/esm/cli/utils.spec.js +5 -6
- package/dist/esm/constant.js +23 -1
- package/dist/esm/interfaces/route.js +0 -0
- package/dist/esm/runtime/dataLoader/plugin-inject-assets.js +71 -0
- package/dist/esm/runtime/dataLoader/plugin.js +97 -0
- package/dist/esm/runtime/dataLoader/utils.js +81 -0
- package/dist/esm/runtime/index.js +3 -1
- package/dist/esm/runtime/withMFRouteId.js +7 -0
- package/dist/esm/ssr-runtime/plugin.js +8 -11
- package/dist/esm/types/modern.js +0 -0
- package/dist/esm-node/cli/dataLoader/ast/constant.js +18 -0
- package/dist/esm-node/cli/dataLoader/ast/generateRoutes.js +109 -0
- package/dist/esm-node/cli/dataLoader/ast/index.js +4 -0
- package/dist/esm-node/cli/dataLoader/clearMFCache.js +33 -0
- package/dist/esm-node/cli/dataLoader/generateRouteFile.js +113 -0
- package/dist/esm-node/cli/dataLoader/patchMFConfig.js +103 -0
- package/dist/esm-node/cli/dataLoader/plugin.js +184 -0
- package/dist/esm-node/cli/index.js +5 -1
- package/dist/esm-node/cli/mfRuntimePlugins/{inject-node-fetch.js → node-fetch.js} +3 -3
- package/dist/esm-node/cli/mfRuntimePlugins/node.js +11 -0
- package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +40 -38
- package/dist/esm-node/cli/server/dataLoaderPlugin.js +61 -0
- package/dist/esm-node/cli/server/fetchRemoteFullRoutesMap.js +47 -0
- package/dist/esm-node/cli/ssrPlugin.js +5 -2
- package/dist/esm-node/cli/utils.js +9 -5
- package/dist/esm-node/cli/utils.spec.js +5 -6
- package/dist/esm-node/constant.js +23 -1
- package/dist/esm-node/interfaces/route.js +0 -0
- package/dist/esm-node/runtime/dataLoader/plugin-inject-assets.js +68 -0
- package/dist/esm-node/runtime/dataLoader/plugin.js +51 -0
- package/dist/esm-node/runtime/dataLoader/utils.js +81 -0
- package/dist/esm-node/runtime/index.js +3 -1
- package/dist/esm-node/runtime/withMFRouteId.js +7 -0
- package/dist/esm-node/ssr-runtime/plugin.js +7 -8
- package/dist/esm-node/types/modern.js +0 -0
- package/dist/types/cli/dataLoader/ast/constant.d.ts +8 -0
- package/dist/types/cli/dataLoader/ast/generateRoutes.d.ts +5 -0
- package/dist/types/cli/dataLoader/ast/index.d.ts +1 -0
- package/dist/types/cli/dataLoader/clearMFCache.d.ts +1 -0
- package/dist/types/cli/dataLoader/generateRouteFile.d.ts +10 -0
- package/dist/types/cli/dataLoader/patchMFConfig.d.ts +10 -0
- package/dist/types/cli/dataLoader/plugin.d.ts +6 -0
- package/dist/types/cli/mfRuntimePlugins/node.d.ts +3 -0
- package/dist/types/cli/server/dataLoaderPlugin.d.ts +10 -0
- package/dist/types/cli/server/fetchRemoteFullRoutesMap.d.ts +11 -0
- package/dist/types/cli/utils.d.ts +2 -0
- package/dist/types/constant.d.ts +11 -0
- package/dist/types/interfaces/route.d.ts +12 -0
- package/dist/types/runtime/dataLoader/plugin-inject-assets.d.ts +4 -0
- package/dist/types/runtime/dataLoader/plugin.d.ts +5 -0
- package/dist/types/runtime/dataLoader/utils.d.ts +22 -0
- package/dist/types/runtime/index.d.ts +1 -0
- package/dist/types/runtime/withMFRouteId.d.ts +1 -0
- package/dist/types/ssr-runtime/plugin.d.ts +3 -1
- package/dist/types/types/index.d.ts +8 -0
- package/dist/types/types/modern.d.ts +12 -0
- package/package.json +48 -11
- package/dist/esm/cli/constant.js +0 -4
- package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +0 -25
- package/dist/esm-node/cli/constant.js +0 -4
- package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +0 -23
- package/dist/types/cli/constant.d.ts +0 -1
- package/dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts +0 -3
- /package/dist/types/cli/mfRuntimePlugins/{inject-node-fetch.d.ts → node-fetch.d.ts} +0 -0
package/dist/cjs/constant.js
CHANGED
|
@@ -18,17 +18,50 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var constant_exports = {};
|
|
20
20
|
__export(constant_exports, {
|
|
21
|
+
DEFAULT_ENTRY: () => DEFAULT_ENTRY,
|
|
22
|
+
DEFAULT_LAYOUT: () => DEFAULT_LAYOUT,
|
|
23
|
+
FOLD_IDENTIFIER: () => FOLD_IDENTIFIER,
|
|
21
24
|
LOCALHOST: () => LOCALHOST,
|
|
25
|
+
META_NAME: () => META_NAME,
|
|
26
|
+
MF_JSON: () => MF_JSON,
|
|
27
|
+
MF_ROUTES: () => MF_ROUTES,
|
|
28
|
+
MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME: () => MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME,
|
|
29
|
+
MODERN_JS_ROUTE_SERVER_LOADER: () => MODERN_JS_ROUTE_SERVER_LOADER,
|
|
22
30
|
MODERN_JS_SERVER_DIR: () => MODERN_JS_SERVER_DIR,
|
|
23
|
-
PLUGIN_IDENTIFIER: () => PLUGIN_IDENTIFIER
|
|
31
|
+
PLUGIN_IDENTIFIER: () => PLUGIN_IDENTIFIER,
|
|
32
|
+
ROUTE_ID: () => ROUTE_ID,
|
|
33
|
+
SEPARATOR: () => SEPARATOR,
|
|
34
|
+
isDev: () => isDev
|
|
24
35
|
});
|
|
25
36
|
module.exports = __toCommonJS(constant_exports);
|
|
26
37
|
const MODERN_JS_SERVER_DIR = "bundles";
|
|
27
38
|
const LOCALHOST = "localhost";
|
|
28
39
|
const PLUGIN_IDENTIFIER = "[ Modern.js Module Federation ]";
|
|
40
|
+
const isDev = process.env.NODE_ENV === "development";
|
|
41
|
+
const MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME = "routes";
|
|
42
|
+
const MODERN_JS_ROUTE_SERVER_LOADER = "route-server-loaders";
|
|
43
|
+
const META_NAME = "modern-js";
|
|
44
|
+
const FOLD_IDENTIFIER = "@mf";
|
|
45
|
+
const SEPARATOR = "_";
|
|
46
|
+
const MF_ROUTES = "mf-routes";
|
|
47
|
+
const DEFAULT_ENTRY = "main";
|
|
48
|
+
const DEFAULT_LAYOUT = "layout";
|
|
49
|
+
const MF_JSON = "mf.json";
|
|
50
|
+
const ROUTE_ID = "ROUTE_ID";
|
|
29
51
|
// Annotate the CommonJS export names for ESM import in node:
|
|
30
52
|
0 && (module.exports = {
|
|
53
|
+
DEFAULT_ENTRY,
|
|
54
|
+
DEFAULT_LAYOUT,
|
|
55
|
+
FOLD_IDENTIFIER,
|
|
31
56
|
LOCALHOST,
|
|
57
|
+
META_NAME,
|
|
58
|
+
MF_JSON,
|
|
59
|
+
MF_ROUTES,
|
|
60
|
+
MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME,
|
|
61
|
+
MODERN_JS_ROUTE_SERVER_LOADER,
|
|
32
62
|
MODERN_JS_SERVER_DIR,
|
|
33
|
-
PLUGIN_IDENTIFIER
|
|
63
|
+
PLUGIN_IDENTIFIER,
|
|
64
|
+
ROUTE_ID,
|
|
65
|
+
SEPARATOR,
|
|
66
|
+
isDev
|
|
34
67
|
});
|
|
@@ -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,92 @@
|
|
|
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 plugin_inject_assets_exports = {};
|
|
20
|
+
__export(plugin_inject_assets_exports, {
|
|
21
|
+
ssrDataLoaderInjectAssetsPlugin: () => ssrDataLoaderInjectAssetsPlugin
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(plugin_inject_assets_exports);
|
|
24
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
|
+
var import_react = require("react");
|
|
26
|
+
var import_runtime = require("@module-federation/enhanced/runtime");
|
|
27
|
+
var import_createRemoteSSRComponent = require("../createRemoteSSRComponent");
|
|
28
|
+
var import_runtime2 = require("@meta/runtime");
|
|
29
|
+
var import_utils = require("./utils");
|
|
30
|
+
function traverseRoutes(routes, remoteNames) {
|
|
31
|
+
routes.forEach((route) => {
|
|
32
|
+
route.id && remoteNames.add((0, import_utils.decodeId)(route.id));
|
|
33
|
+
route.children && traverseRoutes(route.children, remoteNames);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
const ssrDataLoaderInjectAssetsPlugin = ({ metaName }) => {
|
|
37
|
+
return {
|
|
38
|
+
name: "@modern-js/plugin-mf-data-loader-inject-assets",
|
|
39
|
+
pre: [
|
|
40
|
+
"@modern-js/plugin-mf-data-loader"
|
|
41
|
+
],
|
|
42
|
+
post: [
|
|
43
|
+
"@module-federation/modern-js",
|
|
44
|
+
`@${metaName}/plugin-router`
|
|
45
|
+
],
|
|
46
|
+
setup: () => {
|
|
47
|
+
return {
|
|
48
|
+
wrapRoot(App) {
|
|
49
|
+
const AppWrapper = (props) => {
|
|
50
|
+
const instance = (0, import_runtime.getInstance)();
|
|
51
|
+
if (!instance || !instance.options.remotes.length) {
|
|
52
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
|
|
53
|
+
children: props.children
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
const context = (0, import_react.useContext)(import_runtime2.RuntimeReactContext);
|
|
57
|
+
const { remotes } = instance.options;
|
|
58
|
+
const remoteNames = /* @__PURE__ */ new Set();
|
|
59
|
+
traverseRoutes(context.routes, remoteNames);
|
|
60
|
+
const remoteIds = [
|
|
61
|
+
...remoteNames
|
|
62
|
+
].reduce((sum, cur) => {
|
|
63
|
+
const matchRemote = remotes.find((r) => r.name === cur);
|
|
64
|
+
if (matchRemote) {
|
|
65
|
+
sum.add((0, import_utils.getRemoteId)(cur));
|
|
66
|
+
}
|
|
67
|
+
return sum;
|
|
68
|
+
}, /* @__PURE__ */ new Set());
|
|
69
|
+
const assets = [];
|
|
70
|
+
remoteIds.forEach((remoteId) => {
|
|
71
|
+
assets.push(...(0, import_createRemoteSSRComponent.collectSSRAssets)({
|
|
72
|
+
id: remoteId,
|
|
73
|
+
injectScript: false
|
|
74
|
+
}));
|
|
75
|
+
});
|
|
76
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
|
|
77
|
+
children: [
|
|
78
|
+
assets,
|
|
79
|
+
props.children
|
|
80
|
+
]
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
return AppWrapper;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
90
|
+
0 && (module.exports = {
|
|
91
|
+
ssrDataLoaderInjectAssetsPlugin
|
|
92
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
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 plugin_exports = {};
|
|
20
|
+
__export(plugin_exports, {
|
|
21
|
+
ssrDataLoaderPlugin: () => ssrDataLoaderPlugin
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(plugin_exports);
|
|
24
|
+
var import_runtime = require("@module-federation/enhanced/runtime");
|
|
25
|
+
var import_constant = require("../../constant");
|
|
26
|
+
var import_utils = require("./utils");
|
|
27
|
+
const ssrDataLoaderPlugin = ({ metaName, dataLoaderRemotes }) => {
|
|
28
|
+
return {
|
|
29
|
+
name: "@modern-js/plugin-mf-data-loader",
|
|
30
|
+
post: [
|
|
31
|
+
`@${metaName}/plugin-router`,
|
|
32
|
+
"@module-federation/modern-js"
|
|
33
|
+
],
|
|
34
|
+
setup: () => {
|
|
35
|
+
const remoteRoutesMap = {};
|
|
36
|
+
return {
|
|
37
|
+
async beforeRender() {
|
|
38
|
+
if (Object.keys(remoteRoutesMap).length) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const instance = (0, import_runtime.getInstance)();
|
|
42
|
+
if (!instance) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (!instance.options.remotes.length) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
await Promise.all(instance.options.remotes.map(async (remote) => {
|
|
49
|
+
if (!dataLoaderRemotes.includes(remote.name)) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const remoteId = `${remote.name}/${import_constant.DEFAULT_ENTRY}/${import_constant.MF_ROUTES}`;
|
|
53
|
+
const { routes } = await instance.loadRemote(remoteId);
|
|
54
|
+
remoteRoutesMap[remote.name] = {
|
|
55
|
+
routes
|
|
56
|
+
};
|
|
57
|
+
}));
|
|
58
|
+
},
|
|
59
|
+
// runtime plugin not save route , so it needs to inject again when trigger
|
|
60
|
+
modifyRoutes: (routes) => {
|
|
61
|
+
(0, import_utils.injectRemoteRoutes)({
|
|
62
|
+
entry: {
|
|
63
|
+
routes
|
|
64
|
+
}
|
|
65
|
+
}, remoteRoutesMap);
|
|
66
|
+
return routes;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
73
|
+
0 && (module.exports = {
|
|
74
|
+
ssrDataLoaderPlugin
|
|
75
|
+
});
|
|
@@ -0,0 +1,110 @@
|
|
|
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
|
+
decodeId: () => decodeId,
|
|
22
|
+
getRemoteId: () => getRemoteId,
|
|
23
|
+
getRemoteLayoutId: () => getRemoteLayoutId,
|
|
24
|
+
getRemoteRoutesInfos: () => getRemoteRoutesInfos,
|
|
25
|
+
injectRemoteRoutes: () => injectRemoteRoutes,
|
|
26
|
+
transformName2Prefix: () => transformName2Prefix
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(utils_exports);
|
|
29
|
+
var import_sdk = require("@module-federation/sdk");
|
|
30
|
+
var import_constant = require("../../constant");
|
|
31
|
+
const SPLIT_SYMBOL = "@";
|
|
32
|
+
function transformName2Prefix(name) {
|
|
33
|
+
return `${(0, import_sdk.encodeName)(name, "", false)}${SPLIT_SYMBOL}`;
|
|
34
|
+
}
|
|
35
|
+
function decodeId(prefix) {
|
|
36
|
+
const realPrefix = prefix.split(SPLIT_SYMBOL)[0];
|
|
37
|
+
return (0, import_sdk.decodeName)(realPrefix, "", false);
|
|
38
|
+
}
|
|
39
|
+
function getRemoteRoutesInfos(route, remoteRoutesMap) {
|
|
40
|
+
if (!route.id) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const remoteName = decodeId(route.id);
|
|
44
|
+
const remoteRouteObj = remoteRoutesMap[remoteName];
|
|
45
|
+
if (!remoteRouteObj) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const remoteRoutes = remoteRouteObj.routes[0];
|
|
49
|
+
return {
|
|
50
|
+
routes: remoteRoutes,
|
|
51
|
+
name: remoteName,
|
|
52
|
+
pathName: route.path
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function getRemoteLayoutId(remoteName) {
|
|
56
|
+
const prefix = transformName2Prefix(remoteName);
|
|
57
|
+
return `${prefix}${import_constant.DEFAULT_LAYOUT}`;
|
|
58
|
+
}
|
|
59
|
+
function getRemoteId(remoteName) {
|
|
60
|
+
return `${remoteName}/${import_constant.DEFAULT_ENTRY}/${import_constant.MF_ROUTES}`;
|
|
61
|
+
}
|
|
62
|
+
function injectRemoteRoutes(initialRoutes, remoteRoutesMap) {
|
|
63
|
+
const traverse = (route) => {
|
|
64
|
+
var _route_children;
|
|
65
|
+
const remoteRoutesInfos = getRemoteRoutesInfos(route, remoteRoutesMap);
|
|
66
|
+
if (remoteRoutesInfos) {
|
|
67
|
+
const { routes, pathName } = remoteRoutesInfos;
|
|
68
|
+
route.id = routes.id;
|
|
69
|
+
route.path = pathName;
|
|
70
|
+
if (routes.loader) {
|
|
71
|
+
route.loader = routes.loader;
|
|
72
|
+
}
|
|
73
|
+
if (routes.children) {
|
|
74
|
+
route.children = routes.children;
|
|
75
|
+
}
|
|
76
|
+
routes.element && (route.element = routes.element);
|
|
77
|
+
if (routes.Component) {
|
|
78
|
+
route.Component = routes.Component;
|
|
79
|
+
} else if (routes.element) {
|
|
80
|
+
route.element = routes.element;
|
|
81
|
+
}
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
(_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.forEach((r) => {
|
|
85
|
+
traverse(r);
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
Object.keys(initialRoutes).forEach((entryName) => {
|
|
89
|
+
const routes = initialRoutes[entryName];
|
|
90
|
+
if (Array.isArray(routes)) {
|
|
91
|
+
routes.forEach((route) => {
|
|
92
|
+
traverse(route);
|
|
93
|
+
});
|
|
94
|
+
} else {
|
|
95
|
+
var _routes_routes;
|
|
96
|
+
routes === null || routes === void 0 ? void 0 : (_routes_routes = routes.routes) === null || _routes_routes === void 0 ? void 0 : _routes_routes.forEach((r) => {
|
|
97
|
+
traverse(r);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
103
|
+
0 && (module.exports = {
|
|
104
|
+
decodeId,
|
|
105
|
+
getRemoteId,
|
|
106
|
+
getRemoteLayoutId,
|
|
107
|
+
getRemoteRoutesInfos,
|
|
108
|
+
injectRemoteRoutes,
|
|
109
|
+
transformName2Prefix
|
|
110
|
+
});
|
|
@@ -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
|
});
|
|
@@ -16,28 +16,16 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
21
|
-
|
|
19
|
+
var withMFRouteId_exports = {};
|
|
20
|
+
__export(withMFRouteId_exports, {
|
|
21
|
+
withMFRouteId: () => withMFRouteId
|
|
22
22
|
});
|
|
23
|
-
module.exports = __toCommonJS(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const sharedConfigs = shared[sharedKey];
|
|
32
|
-
const arraySharedConfigs = Array.isArray(sharedConfigs) ? sharedConfigs : [
|
|
33
|
-
sharedConfigs
|
|
34
|
-
];
|
|
35
|
-
arraySharedConfigs.forEach((s) => {
|
|
36
|
-
s.strategy = "loaded-first";
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
return args;
|
|
41
|
-
}
|
|
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
|
|
42
31
|
});
|
|
43
|
-
var shared_strategy_default = sharedStrategy;
|
|
@@ -34,15 +34,16 @@ module.exports = __toCommonJS(plugin_exports);
|
|
|
34
34
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
35
35
|
var import_hoist_non_react_statics = __toESM(require("hoist-non-react-statics"));
|
|
36
36
|
var import_SSRLiveReload = require("./SSRLiveReload");
|
|
37
|
-
const mfSSRPlugin = () => ({
|
|
37
|
+
const mfSSRPlugin = ({ metaName }) => ({
|
|
38
38
|
name: "@module-federation/modern-js",
|
|
39
|
+
pre: [
|
|
40
|
+
`@${metaName}/plugin-router`
|
|
41
|
+
],
|
|
39
42
|
setup: () => {
|
|
40
43
|
return {
|
|
41
|
-
async
|
|
44
|
+
async beforeRender() {
|
|
42
45
|
if (typeof window !== "undefined") {
|
|
43
|
-
return
|
|
44
|
-
context
|
|
45
|
-
});
|
|
46
|
+
return;
|
|
46
47
|
}
|
|
47
48
|
globalThis.shouldUpdate = false;
|
|
48
49
|
const nodeUtils = await Promise.resolve().then(() => __toESM(require("@module-federation/node/utils")));
|
|
@@ -52,9 +53,7 @@ const mfSSRPlugin = () => ({
|
|
|
52
53
|
await nodeUtils.flushChunks();
|
|
53
54
|
globalThis.shouldUpdate = true;
|
|
54
55
|
}
|
|
55
|
-
return
|
|
56
|
-
context
|
|
57
|
-
});
|
|
56
|
+
return;
|
|
58
57
|
},
|
|
59
58
|
wrapRoot(App) {
|
|
60
59
|
const AppWrapper = (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
|
|
@@ -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 modern_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(modern_exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import traverse from "@babel/traverse";
|
|
4
|
+
import * as babelParser from "@babel/parser";
|
|
5
|
+
import generate from "@babel/generator";
|
|
6
|
+
import * as t from "@babel/types";
|
|
7
|
+
function findTargetKeyNode(nodeProperties, key) {
|
|
8
|
+
return nodeProperties.find(function(p) {
|
|
9
|
+
return t.isObjectProperty(p) && t.isStringLiteral(p.key) && p.key.value === key;
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
function generateRoutes(param) {
|
|
13
|
+
var sourceCode = param.sourceCode, filePath = param.filePath;
|
|
14
|
+
var ast = babelParser.parse(sourceCode, {
|
|
15
|
+
sourceType: "module"
|
|
16
|
+
});
|
|
17
|
+
var lazyComponentDeclarations = [];
|
|
18
|
+
var componentDeclarations = [];
|
|
19
|
+
var componentId = 0;
|
|
20
|
+
traverse(ast, {
|
|
21
|
+
// ImportDeclaration(path) {
|
|
22
|
+
// const source = path.node.source.value;
|
|
23
|
+
// const routeIdMatch = source.match(/routeId=([^&]+)/);
|
|
24
|
+
// if (routeIdMatch) {
|
|
25
|
+
// const originalRouteId = routeIdMatch[1];
|
|
26
|
+
// const newRouteId = `${prefix}${originalRouteId}`;
|
|
27
|
+
// const newSource = source.replace(
|
|
28
|
+
// /routeId=[^&]+/,
|
|
29
|
+
// `routeId=${newRouteId}`,
|
|
30
|
+
// );
|
|
31
|
+
// path.node.source = t.stringLiteral(newSource);
|
|
32
|
+
// }
|
|
33
|
+
// },
|
|
34
|
+
ObjectExpression: function ObjectExpression(path) {
|
|
35
|
+
var componentName = "";
|
|
36
|
+
var lazyComponentName = "";
|
|
37
|
+
if (!Array.isArray(path.node.properties)) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
var idNode = findTargetKeyNode(path.node.properties, "id");
|
|
41
|
+
if (idNode && t.isObjectProperty(idNode) && t.isStringLiteral(idNode.value)) {
|
|
42
|
+
}
|
|
43
|
+
var isRootNode = findTargetKeyNode(path.node.properties, "isRoot");
|
|
44
|
+
if (isRootNode && t.isObjectProperty(isRootNode) && t.isBooleanLiteral(isRootNode.value)) {
|
|
45
|
+
isRootNode.value.value = false;
|
|
46
|
+
}
|
|
47
|
+
var lazyComponentNode = findTargetKeyNode(path.node.properties, "lazyImport");
|
|
48
|
+
if (lazyComponentNode && t.isObjectProperty(lazyComponentNode) && t.isArrowFunctionExpression(lazyComponentNode.value)) {
|
|
49
|
+
lazyComponentName = "LazyComponent_".concat(componentId);
|
|
50
|
+
var lazyDeclaration = t.variableDeclaration("const", [
|
|
51
|
+
t.variableDeclarator(t.identifier(lazyComponentName), lazyComponentNode.value)
|
|
52
|
+
]);
|
|
53
|
+
lazyComponentNode.value = t.identifier(lazyComponentName);
|
|
54
|
+
var componentNode = findTargetKeyNode(path.node.properties, "component");
|
|
55
|
+
if (componentNode && t.isObjectProperty(componentNode) && t.isCallExpression(componentNode.value) && t.isIdentifier(componentNode.value.callee)) {
|
|
56
|
+
componentNode.value = t.callExpression(t.identifier("lazy"), [
|
|
57
|
+
t.identifier(lazyComponentName)
|
|
58
|
+
]);
|
|
59
|
+
}
|
|
60
|
+
lazyComponentDeclarations.push(lazyDeclaration);
|
|
61
|
+
}
|
|
62
|
+
var componentNode1 = findTargetKeyNode(path.node.properties, "component");
|
|
63
|
+
if (componentNode1 && t.isObjectProperty(componentNode1) && t.isCallExpression(componentNode1.value) && t.isIdentifier(componentNode1.value.callee)) {
|
|
64
|
+
componentName = "Component_".concat(componentId);
|
|
65
|
+
var componentDeclaration = t.variableDeclaration("const", [
|
|
66
|
+
t.variableDeclarator(t.identifier(componentName), lazyComponentName ? t.callExpression(t.identifier("lazy"), [
|
|
67
|
+
t.identifier(lazyComponentName)
|
|
68
|
+
]) : componentNode1.value)
|
|
69
|
+
]);
|
|
70
|
+
componentDeclarations.push(componentDeclaration);
|
|
71
|
+
componentNode1.value = t.identifier(componentName);
|
|
72
|
+
}
|
|
73
|
+
if (lazyComponentName || componentName) {
|
|
74
|
+
componentId++;
|
|
75
|
+
if (componentName) {
|
|
76
|
+
var upperFirstName = componentName.slice(0, 1).toUpperCase() + componentName.slice(1);
|
|
77
|
+
var jsxElement = t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier(upperFirstName), [], true), null, [], true);
|
|
78
|
+
path.node.properties.push(t.objectProperty(t.identifier("element"), jsxElement));
|
|
79
|
+
} else {
|
|
80
|
+
path.node.properties.push(t.objectProperty(t.identifier("Component"), t.callExpression(t.identifier("lazy"), [
|
|
81
|
+
t.identifier(lazyComponentName)
|
|
82
|
+
])));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
traverse(ast, {
|
|
88
|
+
Program: function Program(path) {
|
|
89
|
+
var lastImportIndex = path.get("body").reduce(function(lastIndex, p, index) {
|
|
90
|
+
if (t.isImportDeclaration(p.node)) {
|
|
91
|
+
lastIndex = index;
|
|
92
|
+
}
|
|
93
|
+
return lastIndex;
|
|
94
|
+
}, -1);
|
|
95
|
+
if (lastImportIndex >= 0) {
|
|
96
|
+
var lastImport = path.get("body.".concat(lastImportIndex));
|
|
97
|
+
_to_consumable_array(componentDeclarations).concat(_to_consumable_array(lazyComponentDeclarations)).forEach(function(declaration) {
|
|
98
|
+
if ("insertAfter" in lastImport) {
|
|
99
|
+
lastImport.insertAfter(declaration);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
var code = generate(ast).code;
|
|
106
|
+
fs.writeFileSync(filePath, code);
|
|
107
|
+
}
|
|
108
|
+
export {
|
|
109
|
+
generateRoutes
|
|
110
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { _ as _type_of } from "@swc/helpers/_/_type_of";
|
|
2
|
+
function clearMFCache() {
|
|
3
|
+
if (!globalThis.__FEDERATION__) {
|
|
4
|
+
console.log("clearMFCache no globalThis.__FEDERATION__");
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
globalThis.__FEDERATION__.__INSTANCES__.map(function(i) {
|
|
8
|
+
i.moduleCache.forEach(function(mc) {
|
|
9
|
+
if (mc.remoteInfo && mc.remoteInfo.entryGlobalName) {
|
|
10
|
+
delete globalThis[mc.remoteInfo.entryGlobalName];
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
i.moduleCache.clear();
|
|
14
|
+
if (globalThis[i.name]) {
|
|
15
|
+
delete globalThis[i.name];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.keys(globalThis.__FEDERATION__).forEach(function(key) {
|
|
19
|
+
if (Array.isArray(globalThis.__FEDERATION__[key])) {
|
|
20
|
+
globalThis.__FEDERATION__[key] = [];
|
|
21
|
+
} else if (key === "__PRELOADED_MAP__") {
|
|
22
|
+
globalThis.__FEDERATION__[key] = /* @__PURE__ */ new Map();
|
|
23
|
+
} else if (_type_of(globalThis.__FEDERATION__[key]) === "object") {
|
|
24
|
+
globalThis.__FEDERATION__[key] = {};
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
if (globalThis.__GLOBAL_LOADING_REMOTE_ENTRY__) {
|
|
28
|
+
globalThis.__GLOBAL_LOADING_REMOTE_ENTRY__ = {};
|
|
29
|
+
}
|
|
30
|
+
globalThis.FORCE_MF_REFRESH = true;
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
clearMFCache
|
|
34
|
+
};
|