@module-federation/modern-js 0.0.0-next-20240909101028 → 0.0.0-next-20240910102933
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 +141 -0
- package/dist/cjs/cli/{constant.js → dataLoader/ast/index.js} +6 -6
- package/dist/cjs/cli/dataLoader/generateRouteFile.js +143 -0
- package/dist/cjs/cli/dataLoader/patchMFConfig.js +140 -0
- package/dist/cjs/cli/dataLoader/plugin.js +199 -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 +82 -0
- package/dist/cjs/cli/server/fetchRemoteFullRoutesMap.js +69 -0
- package/dist/cjs/cli/ssrPlugin.js +1 -1
- package/dist/cjs/cli/utils.js +11 -6
- package/dist/cjs/cli/utils.spec.js +5 -6
- package/dist/cjs/constant.js +32 -2
- package/dist/cjs/interfaces/route.js +16 -0
- package/dist/cjs/runtime/dataLoader/plugin-inject-assets.js +84 -0
- package/dist/cjs/runtime/dataLoader/plugin.js +74 -0
- package/dist/cjs/runtime/dataLoader/utils.js +106 -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 -7
- package/dist/esm/cli/dataLoader/ast/constant.js +18 -0
- package/dist/esm/cli/dataLoader/ast/generateRoutes.js +108 -0
- package/dist/esm/cli/dataLoader/ast/index.js +4 -0
- package/dist/esm/cli/dataLoader/generateRouteFile.js +293 -0
- package/dist/esm/cli/dataLoader/patchMFConfig.js +106 -0
- package/dist/esm/cli/dataLoader/plugin.js +214 -0
- package/dist/esm/cli/index.js +4 -1
- 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 +105 -0
- package/dist/esm/cli/server/fetchRemoteFullRoutesMap.js +88 -0
- package/dist/esm/cli/ssrPlugin.js +1 -1
- package/dist/esm/cli/utils.js +9 -5
- package/dist/esm/cli/utils.spec.js +5 -6
- package/dist/esm/constant.js +21 -1
- package/dist/esm/interfaces/route.js +0 -0
- package/dist/esm/runtime/dataLoader/plugin-inject-assets.js +63 -0
- package/dist/esm/runtime/dataLoader/plugin.js +93 -0
- package/dist/esm/runtime/dataLoader/utils.js +77 -0
- package/dist/esm/runtime/index.js +3 -1
- package/dist/esm/runtime/withMFRouteId.js +7 -0
- package/dist/esm/ssr-runtime/plugin.js +7 -10
- package/dist/esm-node/cli/dataLoader/ast/constant.js +18 -0
- package/dist/esm-node/cli/dataLoader/ast/generateRoutes.js +107 -0
- package/dist/esm-node/cli/dataLoader/ast/index.js +4 -0
- package/dist/esm-node/cli/dataLoader/generateRouteFile.js +108 -0
- package/dist/esm-node/cli/dataLoader/patchMFConfig.js +106 -0
- package/dist/esm-node/cli/dataLoader/plugin.js +164 -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 +62 -0
- package/dist/esm-node/cli/server/fetchRemoteFullRoutesMap.js +44 -0
- package/dist/esm-node/cli/ssrPlugin.js +1 -1
- 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 +21 -1
- package/dist/esm-node/interfaces/route.js +0 -0
- package/dist/esm-node/runtime/dataLoader/plugin-inject-assets.js +60 -0
- package/dist/esm-node/runtime/dataLoader/plugin.js +50 -0
- package/dist/esm-node/runtime/dataLoader/utils.js +77 -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 -7
- 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/generateRouteFile.d.ts +7 -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 +10 -0
- package/dist/types/cli/utils.d.ts +2 -0
- package/dist/types/constant.d.ts +10 -0
- package/dist/types/interfaces/route.d.ts +12 -0
- package/dist/types/runtime/dataLoader/plugin-inject-assets.d.ts +2 -0
- package/dist/types/runtime/dataLoader/plugin.d.ts +2 -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/types/index.d.ts +9 -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
|
@@ -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,84 @@
|
|
|
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
|
+
const ssrDataLoaderInjectAssetsPlugin = () => {
|
|
31
|
+
return {
|
|
32
|
+
name: "@modern-js/plugin-mf-data-loader-inject-assets",
|
|
33
|
+
pre: [
|
|
34
|
+
"@modern-js/plugin-router",
|
|
35
|
+
"@modern-js/plugin-mf-data-loader"
|
|
36
|
+
],
|
|
37
|
+
setup: () => {
|
|
38
|
+
return {
|
|
39
|
+
wrapRoot(App) {
|
|
40
|
+
const AppWrapper = (props) => {
|
|
41
|
+
var _context_routerContext;
|
|
42
|
+
const instance = (0, import_runtime.getInstance)();
|
|
43
|
+
if (!instance || !instance.options.remotes.length) {
|
|
44
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
|
|
45
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
|
|
46
|
+
...props
|
|
47
|
+
})
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
const context = (0, import_react.useContext)(import_runtime2.RuntimeReactContext);
|
|
51
|
+
const { remotes } = instance.options;
|
|
52
|
+
const remoteNames = ((_context_routerContext = context.routerContext) === null || _context_routerContext === void 0 ? void 0 : _context_routerContext.matches.map((match) => (0, import_utils.decodeId)(match.route.id))) || [];
|
|
53
|
+
const remoteIds = remoteNames.reduce((sum, cur) => {
|
|
54
|
+
const matchRemote = remotes.find((r) => r.name === cur);
|
|
55
|
+
if (matchRemote) {
|
|
56
|
+
sum.add((0, import_utils.getRemoteId)(cur));
|
|
57
|
+
}
|
|
58
|
+
return sum;
|
|
59
|
+
}, /* @__PURE__ */ new Set());
|
|
60
|
+
const assets = [];
|
|
61
|
+
remoteIds.forEach((remoteId) => {
|
|
62
|
+
assets.push(...(0, import_createRemoteSSRComponent.collectSSRAssets)({
|
|
63
|
+
id: remoteId
|
|
64
|
+
}));
|
|
65
|
+
});
|
|
66
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
|
|
67
|
+
children: [
|
|
68
|
+
assets,
|
|
69
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
|
|
70
|
+
...props
|
|
71
|
+
})
|
|
72
|
+
]
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
return AppWrapper;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
82
|
+
0 && (module.exports = {
|
|
83
|
+
ssrDataLoaderInjectAssetsPlugin
|
|
84
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
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 = () => {
|
|
28
|
+
return {
|
|
29
|
+
name: "@modern-js/plugin-mf-data-loader",
|
|
30
|
+
post: [
|
|
31
|
+
"@modern-js/plugin-router"
|
|
32
|
+
],
|
|
33
|
+
setup: () => {
|
|
34
|
+
const remoteRoutesMap = {};
|
|
35
|
+
const pathRemoteMap = {};
|
|
36
|
+
return {
|
|
37
|
+
async beforeRender() {
|
|
38
|
+
console.log("init");
|
|
39
|
+
if (Object.keys(remoteRoutesMap).length) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const instance = (0, import_runtime.getInstance)();
|
|
43
|
+
if (!instance) {
|
|
44
|
+
console.log("no instance!");
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (!instance.options.remotes.length) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
await Promise.all(instance.options.remotes.map(async (remote) => {
|
|
51
|
+
const remoteId = `${remote.name}/${import_constant.DEFAULT_ENTRY}/${import_constant.MF_ROUTES}`;
|
|
52
|
+
const { routes } = await instance.loadRemote(remoteId);
|
|
53
|
+
remoteRoutesMap[remote.name] = {
|
|
54
|
+
routes
|
|
55
|
+
};
|
|
56
|
+
}));
|
|
57
|
+
},
|
|
58
|
+
// runtime plugin not save route , so it needs to inject again when trigger
|
|
59
|
+
modifyRoutes: (routes) => {
|
|
60
|
+
(0, import_utils.injectRemoteRoutes)({
|
|
61
|
+
entry: {
|
|
62
|
+
routes
|
|
63
|
+
}
|
|
64
|
+
}, remoteRoutesMap);
|
|
65
|
+
return routes;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
72
|
+
0 && (module.exports = {
|
|
73
|
+
ssrDataLoaderPlugin
|
|
74
|
+
});
|
|
@@ -0,0 +1,106 @@
|
|
|
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
|
+
route.element = routes.element;
|
|
77
|
+
route.Component = routes.Component;
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
(_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.forEach((r) => {
|
|
81
|
+
traverse(r);
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
Object.keys(initialRoutes).forEach((entryName) => {
|
|
85
|
+
const routes = initialRoutes[entryName];
|
|
86
|
+
if (Array.isArray(routes)) {
|
|
87
|
+
routes.forEach((route) => {
|
|
88
|
+
traverse(route);
|
|
89
|
+
});
|
|
90
|
+
} else {
|
|
91
|
+
var _routes_routes;
|
|
92
|
+
routes === null || routes === void 0 ? void 0 : (_routes_routes = routes.routes) === null || _routes_routes === void 0 ? void 0 : _routes_routes.forEach((r) => {
|
|
93
|
+
traverse(r);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
99
|
+
0 && (module.exports = {
|
|
100
|
+
decodeId,
|
|
101
|
+
getRemoteId,
|
|
102
|
+
getRemoteLayoutId,
|
|
103
|
+
getRemoteRoutesInfos,
|
|
104
|
+
injectRemoteRoutes,
|
|
105
|
+
transformName2Prefix
|
|
106
|
+
});
|
|
@@ -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,17 @@ 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
|
+
console.log("mfSSRPlugin trigger");
|
|
37
38
|
const mfSSRPlugin = () => ({
|
|
38
39
|
name: "@module-federation/modern-js",
|
|
40
|
+
pre: [
|
|
41
|
+
"@modern-js/plugin-router"
|
|
42
|
+
],
|
|
39
43
|
setup: () => {
|
|
40
44
|
return {
|
|
41
|
-
async
|
|
45
|
+
async beforeRender() {
|
|
42
46
|
if (typeof window !== "undefined") {
|
|
43
|
-
return
|
|
44
|
-
context
|
|
45
|
-
});
|
|
47
|
+
return;
|
|
46
48
|
}
|
|
47
49
|
globalThis.shouldUpdate = false;
|
|
48
50
|
const nodeUtils = await Promise.resolve().then(() => __toESM(require("@module-federation/node/utils")));
|
|
@@ -52,9 +54,7 @@ const mfSSRPlugin = () => ({
|
|
|
52
54
|
await nodeUtils.flushChunks();
|
|
53
55
|
globalThis.shouldUpdate = true;
|
|
54
56
|
}
|
|
55
|
-
return
|
|
56
|
-
context
|
|
57
|
-
});
|
|
57
|
+
return;
|
|
58
58
|
},
|
|
59
59
|
wrapRoot(App) {
|
|
60
60
|
const AppWrapper = (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
|
|
@@ -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,108 @@
|
|
|
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
|
+
if (!isRootNode) {
|
|
48
|
+
var lazyComponentNode = findTargetKeyNode(path.node.properties, "lazyImport");
|
|
49
|
+
if (lazyComponentNode && t.isObjectProperty(lazyComponentNode) && t.isArrowFunctionExpression(lazyComponentNode.value)) {
|
|
50
|
+
lazyComponentName = "LazyComponent_".concat(componentId);
|
|
51
|
+
var lazyDeclaration = t.variableDeclaration("const", [
|
|
52
|
+
t.variableDeclarator(t.identifier(lazyComponentName), lazyComponentNode.value)
|
|
53
|
+
]);
|
|
54
|
+
lazyComponentNode.value = t.identifier(lazyComponentName);
|
|
55
|
+
var componentNode = findTargetKeyNode(path.node.properties, "component");
|
|
56
|
+
if (componentNode && t.isObjectProperty(componentNode) && t.isCallExpression(componentNode.value) && t.isIdentifier(componentNode.value.callee)) {
|
|
57
|
+
componentNode.value = t.callExpression(t.identifier("lazy"), [
|
|
58
|
+
t.identifier(lazyComponentName)
|
|
59
|
+
]);
|
|
60
|
+
}
|
|
61
|
+
lazyComponentDeclarations.push(lazyDeclaration);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
var componentNode1 = findTargetKeyNode(path.node.properties, "component");
|
|
65
|
+
if (componentNode1 && t.isObjectProperty(componentNode1) && t.isCallExpression(componentNode1.value) && t.isIdentifier(componentNode1.value.callee)) {
|
|
66
|
+
componentName = "Component_".concat(componentId);
|
|
67
|
+
var componentDeclaration = t.variableDeclaration("const", [
|
|
68
|
+
t.variableDeclarator(t.identifier(componentName), lazyComponentName ? t.callExpression(t.identifier("lazy"), [
|
|
69
|
+
t.identifier(lazyComponentName)
|
|
70
|
+
]) : componentNode1.value)
|
|
71
|
+
]);
|
|
72
|
+
componentDeclarations.push(componentDeclaration);
|
|
73
|
+
componentNode1.value = t.identifier(componentName);
|
|
74
|
+
}
|
|
75
|
+
if (lazyComponentName || componentName) {
|
|
76
|
+
componentId++;
|
|
77
|
+
if (componentName) {
|
|
78
|
+
var upperFirstName = componentName.slice(0, 1).toUpperCase() + componentName.slice(1);
|
|
79
|
+
var jsxElement = t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier(upperFirstName), [], true), null, [], true);
|
|
80
|
+
path.node.properties.push(t.objectProperty(t.identifier("element"), jsxElement));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
traverse(ast, {
|
|
86
|
+
Program: function Program(path) {
|
|
87
|
+
var lastImportIndex = path.get("body").reduce(function(lastIndex, p, index) {
|
|
88
|
+
if (t.isImportDeclaration(p.node)) {
|
|
89
|
+
lastIndex = index;
|
|
90
|
+
}
|
|
91
|
+
return lastIndex;
|
|
92
|
+
}, -1);
|
|
93
|
+
if (lastImportIndex >= 0) {
|
|
94
|
+
var lastImport = path.get("body.".concat(lastImportIndex));
|
|
95
|
+
_to_consumable_array(componentDeclarations).concat(_to_consumable_array(lazyComponentDeclarations)).forEach(function(declaration) {
|
|
96
|
+
if ("insertAfter" in lastImport) {
|
|
97
|
+
lastImport.insertAfter(declaration);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
var code = generate(ast).code;
|
|
104
|
+
fs.writeFileSync(filePath, code);
|
|
105
|
+
}
|
|
106
|
+
export {
|
|
107
|
+
generateRoutes
|
|
108
|
+
};
|