@module-federation/modern-js 0.0.0-next-20240909083238 → 0.0.0-next-20240909101028
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/{runtime/withMFRouteId.js → cli/constant.js} +6 -9
- package/dist/cjs/cli/index.js +1 -6
- package/dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js +10 -7
- package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +38 -40
- package/dist/cjs/cli/ssrPlugin.js +1 -1
- package/dist/cjs/cli/utils.js +4 -8
- package/dist/cjs/cli/utils.spec.js +1 -1
- package/dist/cjs/constant.js +2 -32
- package/dist/cjs/runtime/index.js +1 -4
- package/dist/cjs/ssr-runtime/plugin.js +7 -7
- package/dist/esm/cli/constant.js +4 -0
- package/dist/esm/cli/index.js +1 -6
- package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.js +10 -7
- package/dist/esm/cli/ssrPlugin.js +1 -1
- package/dist/esm/cli/utils.js +3 -6
- package/dist/esm/cli/utils.spec.js +1 -1
- package/dist/esm/constant.js +1 -21
- package/dist/esm/runtime/index.js +1 -3
- package/dist/esm/ssr-runtime/plugin.js +10 -7
- package/dist/esm-node/cli/constant.js +4 -0
- package/dist/esm-node/cli/index.js +1 -6
- package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.js +10 -7
- package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +38 -40
- package/dist/esm-node/cli/ssrPlugin.js +1 -1
- package/dist/esm-node/cli/utils.js +3 -6
- package/dist/esm-node/cli/utils.spec.js +1 -1
- package/dist/esm-node/constant.js +1 -21
- package/dist/esm-node/runtime/index.js +1 -3
- package/dist/esm-node/ssr-runtime/plugin.js +7 -7
- package/dist/types/cli/constant.d.ts +1 -0
- package/dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts +2 -2
- package/dist/types/cli/utils.d.ts +0 -2
- package/dist/types/constant.d.ts +0 -10
- package/dist/types/runtime/index.d.ts +0 -1
- package/dist/types/types/index.d.ts +0 -10
- package/package.json +11 -40
- package/dist/cjs/cli/dataLoader/ast/constant.js +0 -49
- package/dist/cjs/cli/dataLoader/ast/generateRoutes.js +0 -142
- package/dist/cjs/cli/dataLoader/ast/generateSelfRoutes.js +0 -48
- package/dist/cjs/cli/dataLoader/ast/generateSerializableRoutes.js +0 -90
- package/dist/cjs/cli/dataLoader/ast/generateSlimRoutes.js +0 -104
- package/dist/cjs/cli/dataLoader/ast/index.js +0 -37
- package/dist/cjs/cli/dataLoader/generateRouteFile.js +0 -143
- package/dist/cjs/cli/dataLoader/patchMFConfig.js +0 -137
- package/dist/cjs/cli/dataLoader/plugin.js +0 -205
- package/dist/cjs/cli/mfRuntimePlugins/node.js +0 -44
- package/dist/cjs/cli/server/dataLoaderPlugin.js +0 -82
- package/dist/cjs/cli/server/fetchRemoteFullRoutesMap.js +0 -68
- package/dist/cjs/interfaces/route.js +0 -16
- package/dist/cjs/runtime/dataLoader/plugin.js +0 -73
- package/dist/cjs/runtime/dataLoader/utils.js +0 -89
- package/dist/cjs/runtime/utils.js +0 -38
- package/dist/esm/cli/dataLoader/ast/constant.js +0 -18
- package/dist/esm/cli/dataLoader/ast/generateRoutes.js +0 -109
- package/dist/esm/cli/dataLoader/ast/generateSelfRoutes.js +0 -17
- package/dist/esm/cli/dataLoader/ast/generateSerializableRoutes.js +0 -57
- package/dist/esm/cli/dataLoader/ast/generateSlimRoutes.js +0 -73
- package/dist/esm/cli/dataLoader/ast/index.js +0 -10
- package/dist/esm/cli/dataLoader/generateRouteFile.js +0 -293
- package/dist/esm/cli/dataLoader/patchMFConfig.js +0 -103
- package/dist/esm/cli/dataLoader/plugin.js +0 -216
- package/dist/esm/cli/mfRuntimePlugins/node.js +0 -16
- package/dist/esm/cli/server/dataLoaderPlugin.js +0 -105
- package/dist/esm/cli/server/fetchRemoteFullRoutesMap.js +0 -86
- package/dist/esm/interfaces/route.js +0 -0
- package/dist/esm/runtime/dataLoader/plugin.js +0 -92
- package/dist/esm/runtime/dataLoader/utils.js +0 -63
- package/dist/esm/runtime/utils.js +0 -13
- package/dist/esm/runtime/withMFRouteId.js +0 -7
- package/dist/esm-node/cli/dataLoader/ast/constant.js +0 -18
- package/dist/esm-node/cli/dataLoader/ast/generateRoutes.js +0 -108
- package/dist/esm-node/cli/dataLoader/ast/generateSelfRoutes.js +0 -14
- package/dist/esm-node/cli/dataLoader/ast/generateSerializableRoutes.js +0 -56
- package/dist/esm-node/cli/dataLoader/ast/generateSlimRoutes.js +0 -70
- package/dist/esm-node/cli/dataLoader/ast/index.js +0 -10
- package/dist/esm-node/cli/dataLoader/generateRouteFile.js +0 -108
- package/dist/esm-node/cli/dataLoader/patchMFConfig.js +0 -103
- package/dist/esm-node/cli/dataLoader/plugin.js +0 -169
- package/dist/esm-node/cli/mfRuntimePlugins/node.js +0 -14
- package/dist/esm-node/cli/server/dataLoaderPlugin.js +0 -62
- package/dist/esm-node/cli/server/fetchRemoteFullRoutesMap.js +0 -43
- package/dist/esm-node/interfaces/route.js +0 -0
- package/dist/esm-node/runtime/dataLoader/plugin.js +0 -49
- package/dist/esm-node/runtime/dataLoader/utils.js +0 -63
- package/dist/esm-node/runtime/utils.js +0 -13
- package/dist/esm-node/runtime/withMFRouteId.js +0 -7
- package/dist/types/cli/dataLoader/ast/constant.d.ts +0 -8
- package/dist/types/cli/dataLoader/ast/generateRoutes.d.ts +0 -7
- package/dist/types/cli/dataLoader/ast/generateSelfRoutes.d.ts +0 -7
- package/dist/types/cli/dataLoader/ast/generateSerializableRoutes.d.ts +0 -5
- package/dist/types/cli/dataLoader/ast/generateSlimRoutes.d.ts +0 -7
- package/dist/types/cli/dataLoader/ast/index.d.ts +0 -4
- package/dist/types/cli/dataLoader/generateRouteFile.d.ts +0 -7
- package/dist/types/cli/dataLoader/patchMFConfig.d.ts +0 -11
- package/dist/types/cli/dataLoader/plugin.d.ts +0 -6
- package/dist/types/cli/mfRuntimePlugins/node.d.ts +0 -3
- package/dist/types/cli/server/dataLoaderPlugin.d.ts +0 -10
- package/dist/types/cli/server/fetchRemoteFullRoutesMap.d.ts +0 -10
- package/dist/types/interfaces/route.d.ts +0 -13
- package/dist/types/runtime/dataLoader/plugin.d.ts +0 -2
- package/dist/types/runtime/dataLoader/utils.d.ts +0 -19
- package/dist/types/runtime/utils.d.ts +0 -2
- package/dist/types/runtime/withMFRouteId.d.ts +0 -1
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
-
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
3
|
-
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
|
-
import { init } from "@module-federation/enhanced/runtime";
|
|
5
|
-
import { isBrowserEnv } from "@module-federation/sdk";
|
|
6
|
-
import { fetchRemoteFullRoutesMap, getSSRByRouteIds } from "./fetchRemoteFullRoutesMap";
|
|
7
|
-
import { injectRemoteRoutes } from "../../runtime/dataLoader/utils";
|
|
8
|
-
import { MF_ROUTES, DEFAULT_ENTRY, MODERN_JS_ROUTE_SERVER_LOADER } from "../../constant";
|
|
9
|
-
function dataLoaderPlugin_default(param) {
|
|
10
|
-
var runtimeOptions = param.runtimeOptions, partialSSRRemotes = param.partialSSRRemotes, ssrByRouteIdsMap = param.ssrByRouteIdsMap;
|
|
11
|
-
return {
|
|
12
|
-
name: "MFDataLoaderServerPlugin",
|
|
13
|
-
pre: [
|
|
14
|
-
"@modern-js/plugin-inject-resource"
|
|
15
|
-
],
|
|
16
|
-
setup: function setup(api) {
|
|
17
|
-
var remotes = runtimeOptions.remotes, name = runtimeOptions.name;
|
|
18
|
-
if (!remotes.length) {
|
|
19
|
-
return {};
|
|
20
|
-
}
|
|
21
|
-
var isHandled = false;
|
|
22
|
-
return {
|
|
23
|
-
prepare: function prepare() {
|
|
24
|
-
var middlewares = api.useAppContext().middlewares;
|
|
25
|
-
middlewares.push({
|
|
26
|
-
name: "MFDataLoaderServerPlugin",
|
|
27
|
-
handler: function() {
|
|
28
|
-
var _ref = _async_to_generator(function(c, next) {
|
|
29
|
-
var serverManifest, loaderBundles, nestedRoutesJson, _api_useConfigContext_server, instance, remoteFullRoutesMap, originalSSRByRouteIds, remoteSSRByRouteIds, ssrByRouteIds;
|
|
30
|
-
return _ts_generator(this, function(_state) {
|
|
31
|
-
switch (_state.label) {
|
|
32
|
-
case 0:
|
|
33
|
-
serverManifest = c.get("serverManifest");
|
|
34
|
-
loaderBundles = serverManifest.loaderBundles, nestedRoutesJson = serverManifest.nestedRoutesJson;
|
|
35
|
-
if (!isHandled)
|
|
36
|
-
return [
|
|
37
|
-
3,
|
|
38
|
-
2
|
|
39
|
-
];
|
|
40
|
-
return [
|
|
41
|
-
4,
|
|
42
|
-
next()
|
|
43
|
-
];
|
|
44
|
-
case 1:
|
|
45
|
-
_state.sent();
|
|
46
|
-
return [
|
|
47
|
-
3,
|
|
48
|
-
5
|
|
49
|
-
];
|
|
50
|
-
case 2:
|
|
51
|
-
instance = init({
|
|
52
|
-
name,
|
|
53
|
-
remotes
|
|
54
|
-
});
|
|
55
|
-
return [
|
|
56
|
-
4,
|
|
57
|
-
fetchRemoteFullRoutesMap({
|
|
58
|
-
instance,
|
|
59
|
-
remotePath: isBrowserEnv() ? "".concat(DEFAULT_ENTRY, "/").concat(MF_ROUTES) : "".concat(DEFAULT_ENTRY, "/").concat(MODERN_JS_ROUTE_SERVER_LOADER)
|
|
60
|
-
})
|
|
61
|
-
];
|
|
62
|
-
case 3:
|
|
63
|
-
remoteFullRoutesMap = _state.sent();
|
|
64
|
-
originalSSRByRouteIds = (_api_useConfigContext_server = api.useConfigContext().server) === null || _api_useConfigContext_server === void 0 ? void 0 : _api_useConfigContext_server.ssrByRouteIds;
|
|
65
|
-
if (originalSSRByRouteIds && partialSSRRemotes) {
|
|
66
|
-
remoteSSRByRouteIds = getSSRByRouteIds(partialSSRRemotes, remoteFullRoutesMap) || [];
|
|
67
|
-
ssrByRouteIds = new Set(_to_consumable_array(originalSSRByRouteIds).concat(_to_consumable_array(remoteSSRByRouteIds.map(function(id) {
|
|
68
|
-
return ssrByRouteIdsMap[id] || id;
|
|
69
|
-
}))));
|
|
70
|
-
api.useConfigContext().server.ssrByRouteIds = Array.from(ssrByRouteIds);
|
|
71
|
-
}
|
|
72
|
-
injectRemoteRoutes(loaderBundles, remoteFullRoutesMap);
|
|
73
|
-
injectRemoteRoutes(nestedRoutesJson, remoteFullRoutesMap);
|
|
74
|
-
isHandled = true;
|
|
75
|
-
return [
|
|
76
|
-
4,
|
|
77
|
-
next()
|
|
78
|
-
];
|
|
79
|
-
case 4:
|
|
80
|
-
_state.sent();
|
|
81
|
-
_state.label = 5;
|
|
82
|
-
case 5:
|
|
83
|
-
return [
|
|
84
|
-
2
|
|
85
|
-
];
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
return function(c, next) {
|
|
90
|
-
return _ref.apply(this, arguments);
|
|
91
|
-
};
|
|
92
|
-
}(),
|
|
93
|
-
before: [
|
|
94
|
-
"render"
|
|
95
|
-
]
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
;
|
|
103
|
-
export {
|
|
104
|
-
dataLoaderPlugin_default as default
|
|
105
|
-
};
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
-
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
3
|
-
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
|
-
function fetchRemoteFullRoutesMap(options) {
|
|
5
|
-
return _fetchRemoteFullRoutesMap.apply(this, arguments);
|
|
6
|
-
}
|
|
7
|
-
function _fetchRemoteFullRoutesMap() {
|
|
8
|
-
_fetchRemoteFullRoutesMap = _async_to_generator(function(options) {
|
|
9
|
-
var instance, remotePath, remotes, remoteRoutesMap;
|
|
10
|
-
return _ts_generator(this, function(_state) {
|
|
11
|
-
switch (_state.label) {
|
|
12
|
-
case 0:
|
|
13
|
-
instance = options.instance, remotePath = options.remotePath;
|
|
14
|
-
remotes = instance.options.remotes;
|
|
15
|
-
remoteRoutesMap = {};
|
|
16
|
-
if (!remotes.length) {
|
|
17
|
-
return [
|
|
18
|
-
2,
|
|
19
|
-
remoteRoutesMap
|
|
20
|
-
];
|
|
21
|
-
}
|
|
22
|
-
return [
|
|
23
|
-
4,
|
|
24
|
-
Promise.all(remotes.map(function() {
|
|
25
|
-
var _ref = _async_to_generator(function(remote) {
|
|
26
|
-
var remoteId, routes;
|
|
27
|
-
return _ts_generator(this, function(_state2) {
|
|
28
|
-
switch (_state2.label) {
|
|
29
|
-
case 0:
|
|
30
|
-
remoteId = "".concat(remote.name, "/").concat(remotePath);
|
|
31
|
-
return [
|
|
32
|
-
4,
|
|
33
|
-
instance.loadRemote(remoteId)
|
|
34
|
-
];
|
|
35
|
-
case 1:
|
|
36
|
-
routes = _state2.sent().routes;
|
|
37
|
-
remoteRoutesMap[remote.name] = {
|
|
38
|
-
routes
|
|
39
|
-
};
|
|
40
|
-
return [
|
|
41
|
-
2
|
|
42
|
-
];
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
return function(remote) {
|
|
47
|
-
return _ref.apply(this, arguments);
|
|
48
|
-
};
|
|
49
|
-
}()))
|
|
50
|
-
];
|
|
51
|
-
case 1:
|
|
52
|
-
_state.sent();
|
|
53
|
-
return [
|
|
54
|
-
2,
|
|
55
|
-
remoteRoutesMap
|
|
56
|
-
];
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
return _fetchRemoteFullRoutesMap.apply(this, arguments);
|
|
61
|
-
}
|
|
62
|
-
function getSSRByRouteIds(partialSSRRemotes, remoteRoutesMap) {
|
|
63
|
-
if (!partialSSRRemotes.length) {
|
|
64
|
-
return void 0;
|
|
65
|
-
}
|
|
66
|
-
var remoteProviderRouteIds = /* @__PURE__ */ new Set();
|
|
67
|
-
var collectIds = function(route) {
|
|
68
|
-
remoteProviderRouteIds.add(route.id);
|
|
69
|
-
if (route.children) {
|
|
70
|
-
route.children.forEach(function(r) {
|
|
71
|
-
collectIds(r);
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
Object.values(remoteRoutesMap).forEach(function(item) {
|
|
76
|
-
var routes = item.routes;
|
|
77
|
-
routes.forEach(function(route) {
|
|
78
|
-
collectIds(route);
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
return _to_consumable_array(remoteProviderRouteIds);
|
|
82
|
-
}
|
|
83
|
-
export {
|
|
84
|
-
fetchRemoteFullRoutesMap,
|
|
85
|
-
getSSRByRouteIds
|
|
86
|
-
};
|
|
File without changes
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
-
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
|
-
import { getInstance } from "@module-federation/enhanced/runtime";
|
|
4
|
-
import { MF_ROUTES, DEFAULT_ENTRY } from "../../constant";
|
|
5
|
-
import { injectRemoteRoutes } from "./utils";
|
|
6
|
-
var ssrDataLoaderPlugin = function() {
|
|
7
|
-
return {
|
|
8
|
-
name: "@modern-js/plugin-mf-data-loader",
|
|
9
|
-
post: [
|
|
10
|
-
"@modern-js/plugin-router"
|
|
11
|
-
],
|
|
12
|
-
setup: function() {
|
|
13
|
-
var remoteRoutesMap = {};
|
|
14
|
-
return {
|
|
15
|
-
beforeRender: function beforeRender() {
|
|
16
|
-
return _async_to_generator(function() {
|
|
17
|
-
var instance;
|
|
18
|
-
return _ts_generator(this, function(_state) {
|
|
19
|
-
switch (_state.label) {
|
|
20
|
-
case 0:
|
|
21
|
-
console.log("init");
|
|
22
|
-
if (Object.keys(remoteRoutesMap).length) {
|
|
23
|
-
return [
|
|
24
|
-
2
|
|
25
|
-
];
|
|
26
|
-
}
|
|
27
|
-
instance = getInstance();
|
|
28
|
-
if (!instance) {
|
|
29
|
-
console.log("no instance!");
|
|
30
|
-
return [
|
|
31
|
-
2
|
|
32
|
-
];
|
|
33
|
-
}
|
|
34
|
-
if (!instance.options.remotes.length) {
|
|
35
|
-
return [
|
|
36
|
-
2
|
|
37
|
-
];
|
|
38
|
-
}
|
|
39
|
-
return [
|
|
40
|
-
4,
|
|
41
|
-
Promise.all(instance.options.remotes.map(function() {
|
|
42
|
-
var _ref = _async_to_generator(function(remote) {
|
|
43
|
-
var remoteId, routes;
|
|
44
|
-
return _ts_generator(this, function(_state2) {
|
|
45
|
-
switch (_state2.label) {
|
|
46
|
-
case 0:
|
|
47
|
-
remoteId = "".concat(remote.name, "/").concat(DEFAULT_ENTRY, "/").concat(MF_ROUTES);
|
|
48
|
-
return [
|
|
49
|
-
4,
|
|
50
|
-
instance.loadRemote(remoteId)
|
|
51
|
-
];
|
|
52
|
-
case 1:
|
|
53
|
-
routes = _state2.sent().routes;
|
|
54
|
-
remoteRoutesMap[remote.name] = {
|
|
55
|
-
routes
|
|
56
|
-
};
|
|
57
|
-
return [
|
|
58
|
-
2
|
|
59
|
-
];
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
return function(remote) {
|
|
64
|
-
return _ref.apply(this, arguments);
|
|
65
|
-
};
|
|
66
|
-
}()))
|
|
67
|
-
];
|
|
68
|
-
case 1:
|
|
69
|
-
_state.sent();
|
|
70
|
-
return [
|
|
71
|
-
2
|
|
72
|
-
];
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
})();
|
|
76
|
-
},
|
|
77
|
-
// runtime plugin not save route , so it needs to inject again when trigger
|
|
78
|
-
modifyRoutes: function(routes) {
|
|
79
|
-
injectRemoteRoutes({
|
|
80
|
-
entry: {
|
|
81
|
-
routes
|
|
82
|
-
}
|
|
83
|
-
}, remoteRoutesMap);
|
|
84
|
-
return routes;
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
export {
|
|
91
|
-
ssrDataLoaderPlugin
|
|
92
|
-
};
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { DEFAULT_LAYOUT } from "../../constant";
|
|
2
|
-
import { transformName2Prefix, transformPrefix2Name } from "../utils";
|
|
3
|
-
function getRemoteRoutesInfos(route, remoteRoutesMap) {
|
|
4
|
-
if (!route.id) {
|
|
5
|
-
return;
|
|
6
|
-
}
|
|
7
|
-
var remoteName = transformPrefix2Name(route.id);
|
|
8
|
-
var remoteRouteObj = remoteRoutesMap[remoteName];
|
|
9
|
-
if (!remoteRouteObj) {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
var remoteRoutes = remoteRouteObj.routes[0];
|
|
13
|
-
return {
|
|
14
|
-
routes: remoteRoutes,
|
|
15
|
-
name: remoteName,
|
|
16
|
-
pathName: route.path
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
function getRemoteLayoutId(remoteName) {
|
|
20
|
-
var prefix = transformName2Prefix(remoteName);
|
|
21
|
-
return "".concat(prefix).concat(DEFAULT_LAYOUT);
|
|
22
|
-
}
|
|
23
|
-
function injectRemoteRoutes(initialRoutes, remoteRoutesMap) {
|
|
24
|
-
var traverse = function(route) {
|
|
25
|
-
var _route_children;
|
|
26
|
-
var remoteRoutesInfos = getRemoteRoutesInfos(route, remoteRoutesMap);
|
|
27
|
-
if (remoteRoutesInfos) {
|
|
28
|
-
var routes = remoteRoutesInfos.routes, pathName = remoteRoutesInfos.pathName;
|
|
29
|
-
route.id = routes.id;
|
|
30
|
-
route.path = pathName;
|
|
31
|
-
if (routes.loader) {
|
|
32
|
-
route.loader = routes.loader;
|
|
33
|
-
}
|
|
34
|
-
if (routes.children) {
|
|
35
|
-
route.children = routes.children;
|
|
36
|
-
}
|
|
37
|
-
route.element = routes.element;
|
|
38
|
-
route.Component = routes.Component;
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
(_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.forEach(function(r) {
|
|
42
|
-
traverse(r);
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
Object.keys(initialRoutes).forEach(function(entryName) {
|
|
46
|
-
var routes = initialRoutes[entryName];
|
|
47
|
-
if (Array.isArray(routes)) {
|
|
48
|
-
routes.forEach(function(route) {
|
|
49
|
-
traverse(route);
|
|
50
|
-
});
|
|
51
|
-
} else {
|
|
52
|
-
var _routes_routes;
|
|
53
|
-
routes === null || routes === void 0 ? void 0 : (_routes_routes = routes.routes) === null || _routes_routes === void 0 ? void 0 : _routes_routes.forEach(function(r) {
|
|
54
|
-
traverse(r);
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
export {
|
|
60
|
-
getRemoteLayoutId,
|
|
61
|
-
getRemoteRoutesInfos,
|
|
62
|
-
injectRemoteRoutes
|
|
63
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { encodeName, decodeName } from "@module-federation/sdk";
|
|
2
|
-
var SPLIT_SYMBOL = "@";
|
|
3
|
-
function transformName2Prefix(name) {
|
|
4
|
-
return "".concat(encodeName(name, "", false)).concat(SPLIT_SYMBOL);
|
|
5
|
-
}
|
|
6
|
-
function transformPrefix2Name(prefix) {
|
|
7
|
-
var realPrefix = prefix.split(SPLIT_SYMBOL)[0];
|
|
8
|
-
return decodeName(realPrefix, "", false);
|
|
9
|
-
}
|
|
10
|
-
export {
|
|
11
|
-
transformName2Prefix,
|
|
12
|
-
transformPrefix2Name
|
|
13
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
const IS_ROOT = "isRoot";
|
|
2
|
-
const ID = "id";
|
|
3
|
-
const COMPONENT = "component";
|
|
4
|
-
const LAZY_COMPONENT = "lazyImport";
|
|
5
|
-
const SHOULD_REVALIDATE = "shouldRevalidate";
|
|
6
|
-
const PRIVATE_COMPONENT = "_component";
|
|
7
|
-
const ELEMENT = "element";
|
|
8
|
-
const 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
|
-
};
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import traverse from "@babel/traverse";
|
|
3
|
-
import * as babelParser from "@babel/parser";
|
|
4
|
-
import generate from "@babel/generator";
|
|
5
|
-
import * as t from "@babel/types";
|
|
6
|
-
function findTargetKeyNode(nodeProperties, key) {
|
|
7
|
-
return nodeProperties.find((p) => t.isObjectProperty(p) && t.isStringLiteral(p.key) && p.key.value === key);
|
|
8
|
-
}
|
|
9
|
-
function generateRoutes({ sourceCode, filePath, prefix, baseName }) {
|
|
10
|
-
const ast = babelParser.parse(sourceCode, {
|
|
11
|
-
sourceType: "module"
|
|
12
|
-
});
|
|
13
|
-
const lazyComponentDeclarations = [];
|
|
14
|
-
const componentDeclarations = [];
|
|
15
|
-
let componentId = 0;
|
|
16
|
-
traverse(ast, {
|
|
17
|
-
// ImportDeclaration(path) {
|
|
18
|
-
// const source = path.node.source.value;
|
|
19
|
-
// const routeIdMatch = source.match(/routeId=([^&]+)/);
|
|
20
|
-
// if (routeIdMatch) {
|
|
21
|
-
// const originalRouteId = routeIdMatch[1];
|
|
22
|
-
// const newRouteId = `${prefix}${originalRouteId}`;
|
|
23
|
-
// const newSource = source.replace(
|
|
24
|
-
// /routeId=[^&]+/,
|
|
25
|
-
// `routeId=${newRouteId}`,
|
|
26
|
-
// );
|
|
27
|
-
// path.node.source = t.stringLiteral(newSource);
|
|
28
|
-
// }
|
|
29
|
-
// },
|
|
30
|
-
ObjectExpression(path) {
|
|
31
|
-
let componentName = "";
|
|
32
|
-
let lazyComponentName = "";
|
|
33
|
-
if (!Array.isArray(path.node.properties)) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
const idNode = findTargetKeyNode(path.node.properties, "id");
|
|
37
|
-
if (idNode && t.isObjectProperty(idNode) && t.isStringLiteral(idNode.value)) {
|
|
38
|
-
}
|
|
39
|
-
const isRootNode = findTargetKeyNode(path.node.properties, "isRoot");
|
|
40
|
-
if (isRootNode && t.isObjectProperty(isRootNode) && t.isBooleanLiteral(isRootNode.value)) {
|
|
41
|
-
isRootNode.value.value = false;
|
|
42
|
-
}
|
|
43
|
-
if (!isRootNode) {
|
|
44
|
-
const lazyComponentNode = findTargetKeyNode(path.node.properties, "lazyImport");
|
|
45
|
-
if (lazyComponentNode && t.isObjectProperty(lazyComponentNode) && t.isArrowFunctionExpression(lazyComponentNode.value)) {
|
|
46
|
-
lazyComponentName = `LazyComponent_${componentId}`;
|
|
47
|
-
const lazyDeclaration = t.variableDeclaration("const", [
|
|
48
|
-
t.variableDeclarator(t.identifier(lazyComponentName), lazyComponentNode.value)
|
|
49
|
-
]);
|
|
50
|
-
lazyComponentNode.value = t.identifier(lazyComponentName);
|
|
51
|
-
const componentNode2 = findTargetKeyNode(path.node.properties, "component");
|
|
52
|
-
if (componentNode2 && t.isObjectProperty(componentNode2) && t.isCallExpression(componentNode2.value) && t.isIdentifier(componentNode2.value.callee)) {
|
|
53
|
-
componentNode2.value = t.callExpression(t.identifier("lazy"), [
|
|
54
|
-
t.identifier(lazyComponentName)
|
|
55
|
-
]);
|
|
56
|
-
}
|
|
57
|
-
lazyComponentDeclarations.push(lazyDeclaration);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
const componentNode = findTargetKeyNode(path.node.properties, "component");
|
|
61
|
-
if (componentNode && t.isObjectProperty(componentNode) && t.isCallExpression(componentNode.value) && t.isIdentifier(componentNode.value.callee)) {
|
|
62
|
-
componentName = `Component_${componentId}`;
|
|
63
|
-
const componentDeclaration = t.variableDeclaration("const", [
|
|
64
|
-
t.variableDeclarator(t.identifier(componentName), lazyComponentName ? t.callExpression(t.identifier("lazy"), [
|
|
65
|
-
t.identifier(lazyComponentName)
|
|
66
|
-
]) : componentNode.value)
|
|
67
|
-
]);
|
|
68
|
-
componentDeclarations.push(componentDeclaration);
|
|
69
|
-
componentNode.value = t.identifier(componentName);
|
|
70
|
-
}
|
|
71
|
-
if (lazyComponentName || componentName) {
|
|
72
|
-
componentId++;
|
|
73
|
-
if (componentName) {
|
|
74
|
-
const upperFirstName = componentName.slice(0, 1).toUpperCase() + componentName.slice(1);
|
|
75
|
-
const jsxElement = t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier(upperFirstName), [], true), null, [], true);
|
|
76
|
-
path.node.properties.push(t.objectProperty(t.identifier("element"), jsxElement));
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
traverse(ast, {
|
|
82
|
-
Program(path) {
|
|
83
|
-
const lastImportIndex = path.get("body").reduce((lastIndex, p, index) => {
|
|
84
|
-
if (t.isImportDeclaration(p.node)) {
|
|
85
|
-
lastIndex = index;
|
|
86
|
-
}
|
|
87
|
-
return lastIndex;
|
|
88
|
-
}, -1);
|
|
89
|
-
if (lastImportIndex >= 0) {
|
|
90
|
-
const lastImport = path.get(`body.${lastImportIndex}`);
|
|
91
|
-
[
|
|
92
|
-
...componentDeclarations,
|
|
93
|
-
...lazyComponentDeclarations
|
|
94
|
-
].forEach((declaration) => {
|
|
95
|
-
if ("insertAfter" in lastImport) {
|
|
96
|
-
lastImport.insertAfter(declaration);
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
const { code: newCode } = generate(ast);
|
|
103
|
-
const finalCode = `${newCode}export const baseName = '${baseName}';`;
|
|
104
|
-
fs.writeFileSync(filePath, finalCode);
|
|
105
|
-
}
|
|
106
|
-
export {
|
|
107
|
-
generateRoutes
|
|
108
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import * as t from "@babel/types";
|
|
3
|
-
function findTargetKeyNode(nodeProperties, key) {
|
|
4
|
-
return nodeProperties.find((p) => t.isObjectProperty(p) && t.isStringLiteral(p.key) && p.key.value === key);
|
|
5
|
-
}
|
|
6
|
-
function generateSelfRoutes({ sourceCode, filePath, prefix, baseName }) {
|
|
7
|
-
const lazyComponentDeclarations = [];
|
|
8
|
-
const componentDeclarations = [];
|
|
9
|
-
let componentId = 0;
|
|
10
|
-
fs.writeFileSync(filePath, sourceCode);
|
|
11
|
-
}
|
|
12
|
-
export {
|
|
13
|
-
generateSelfRoutes
|
|
14
|
-
};
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import traverse from "@babel/traverse";
|
|
2
|
-
import * as babelParser from "@babel/parser";
|
|
3
|
-
import generate from "@babel/generator";
|
|
4
|
-
import * as t from "@babel/types";
|
|
5
|
-
import { COMPONENT, ID, SHOULD_REVALIDATE, LAZY_COMPONENT, PRIVATE_COMPONENT, LOADER } from "./constant";
|
|
6
|
-
function generateSerializableRoutes({ sourceCode, prefix }) {
|
|
7
|
-
const ast = babelParser.parse(sourceCode, {
|
|
8
|
-
sourceType: "module"
|
|
9
|
-
});
|
|
10
|
-
const removedKeys = [
|
|
11
|
-
COMPONENT,
|
|
12
|
-
SHOULD_REVALIDATE,
|
|
13
|
-
LAZY_COMPONENT,
|
|
14
|
-
PRIVATE_COMPONENT,
|
|
15
|
-
LOADER
|
|
16
|
-
];
|
|
17
|
-
traverse(ast, {
|
|
18
|
-
ObjectExpression(path1) {
|
|
19
|
-
if (!Array.isArray(path1.node.properties)) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
path1.node.properties.forEach((prop1) => {
|
|
23
|
-
if (t.isObjectProperty(prop1) && t.isStringLiteral(prop1.key) && t.isStringLiteral(prop1.value) && prop1.key.value === ID) {
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
path1.node.properties = path1.node.properties.filter((p1) => {
|
|
27
|
-
if (t.isObjectProperty(p1) && t.isStringLiteral(p1.key)) {
|
|
28
|
-
return !removedKeys.includes(p1.key.value);
|
|
29
|
-
} else {
|
|
30
|
-
return true;
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
let routesValue = "";
|
|
36
|
-
traverse(ast, {
|
|
37
|
-
VariableDeclarator(path) {
|
|
38
|
-
if (t.isVariableDeclarator(path.node) && t.isIdentifier(path.node.id) && path.node.id.name === "routes") {
|
|
39
|
-
const routesAst = path.node.init;
|
|
40
|
-
if (!routesAst) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
const { code } = generate(routesAst, {
|
|
44
|
-
compact: true,
|
|
45
|
-
retainLines: false,
|
|
46
|
-
concise: true
|
|
47
|
-
});
|
|
48
|
-
routesValue = eval("(" + code + ")");
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
return routesValue;
|
|
53
|
-
}
|
|
54
|
-
export {
|
|
55
|
-
generateSerializableRoutes
|
|
56
|
-
};
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import traverse from "@babel/traverse";
|
|
3
|
-
import * as babelParser from "@babel/parser";
|
|
4
|
-
import generate from "@babel/generator";
|
|
5
|
-
import * as t from "@babel/types";
|
|
6
|
-
import { COMPONENT, SHOULD_REVALIDATE, LAZY_COMPONENT, PRIVATE_COMPONENT } from "./constant";
|
|
7
|
-
function generateSlimRoutes({ sourceCode, filePath, prefix, baseName }) {
|
|
8
|
-
const ast = babelParser.parse(sourceCode, {
|
|
9
|
-
sourceType: "module"
|
|
10
|
-
});
|
|
11
|
-
const removedKeys = [
|
|
12
|
-
COMPONENT,
|
|
13
|
-
SHOULD_REVALIDATE,
|
|
14
|
-
LAZY_COMPONENT,
|
|
15
|
-
PRIVATE_COMPONENT
|
|
16
|
-
];
|
|
17
|
-
traverse(ast, {
|
|
18
|
-
// ImportDeclaration(path) {
|
|
19
|
-
// const source = path.node.source.value;
|
|
20
|
-
// const routeIdMatch = source.match(/routeId=([^&]+)/);
|
|
21
|
-
// if (routeIdMatch) {
|
|
22
|
-
// const originalRouteId = routeIdMatch[1];
|
|
23
|
-
// const newRouteId = `${prefix}${originalRouteId}`;
|
|
24
|
-
// const newSource = source.replace(
|
|
25
|
-
// /routeId=[^&]+/,
|
|
26
|
-
// `routeId=${newRouteId}`,
|
|
27
|
-
// );
|
|
28
|
-
// path.node.source = t.stringLiteral(newSource);
|
|
29
|
-
// }
|
|
30
|
-
// },
|
|
31
|
-
ObjectExpression(path) {
|
|
32
|
-
if (!Array.isArray(path.node.properties)) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
path.node.properties = path.node.properties.filter((p) => {
|
|
36
|
-
if (t.isObjectProperty(p) && t.isStringLiteral(p.key)) {
|
|
37
|
-
return !removedKeys.includes(p.key.value);
|
|
38
|
-
} else {
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
const tempCode = generate(ast).code;
|
|
45
|
-
const tempAst = babelParser.parse(tempCode, {
|
|
46
|
-
sourceType: "module"
|
|
47
|
-
});
|
|
48
|
-
const usedIdentifiers = /* @__PURE__ */ new Set();
|
|
49
|
-
traverse(tempAst, {
|
|
50
|
-
Identifier(path) {
|
|
51
|
-
if (t.isProperty(path.parent)) {
|
|
52
|
-
usedIdentifiers.add(path.node.name);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
traverse(tempAst, {
|
|
57
|
-
ImportDeclaration(path) {
|
|
58
|
-
path.node.specifiers = path.node.specifiers.filter((specifier) => usedIdentifiers.has(specifier.local.name));
|
|
59
|
-
if (!path.node.specifiers.length) {
|
|
60
|
-
path.remove();
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
const { code: newCode } = generate(tempAst);
|
|
65
|
-
const finalCode = `${newCode}export const baseName = '${baseName}';`;
|
|
66
|
-
fs.writeFileSync(filePath, finalCode);
|
|
67
|
-
}
|
|
68
|
-
export {
|
|
69
|
-
generateSlimRoutes
|
|
70
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { generateRoutes } from "./generateRoutes";
|
|
2
|
-
import { generateSlimRoutes } from "./generateSlimRoutes";
|
|
3
|
-
import { generateSerializableRoutes } from "./generateSerializableRoutes";
|
|
4
|
-
import { generateSelfRoutes } from "./generateSelfRoutes";
|
|
5
|
-
export {
|
|
6
|
-
generateRoutes,
|
|
7
|
-
generateSelfRoutes,
|
|
8
|
-
generateSerializableRoutes,
|
|
9
|
-
generateSlimRoutes
|
|
10
|
-
};
|