@module-federation/modern-js 0.0.0-next-20240813065037 → 0.0.0-next-20240814082511
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 +46 -0
- package/dist/cjs/cli/ast/generateRoutes.js +140 -0
- package/dist/cjs/cli/ast/generateSlimRoutes.js +106 -0
- package/dist/cjs/cli/ast/index.js +31 -0
- package/dist/cjs/cli/configPlugin.js +1 -0
- package/dist/cjs/cli/constant.js +6 -0
- package/dist/cjs/cli/dataLoaderPlugin.js +220 -0
- package/dist/cjs/cli/index.js +6 -1
- package/dist/cjs/cli/server/dataLoaderPlugin.js +78 -0
- package/dist/cjs/cli/ssrPlugin.js +4 -4
- 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 +5 -7
- package/dist/esm/cli/ast/constant.js +16 -0
- package/dist/esm/cli/ast/generateRoutes.js +107 -0
- package/dist/esm/cli/ast/generateSlimRoutes.js +75 -0
- package/dist/esm/cli/ast/index.js +6 -0
- package/dist/esm/cli/configPlugin.js +1 -0
- package/dist/esm/cli/constant.js +4 -0
- package/dist/esm/cli/dataLoaderPlugin.js +207 -0
- package/dist/esm/cli/index.js +6 -1
- package/dist/esm/cli/server/dataLoaderPlugin.js +122 -0
- package/dist/esm/cli/ssrPlugin.js +2 -2
- 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 +5 -10
- package/dist/esm-node/cli/ast/constant.js +16 -0
- package/dist/esm-node/cli/ast/generateRoutes.js +106 -0
- package/dist/esm-node/cli/ast/generateSlimRoutes.js +72 -0
- package/dist/esm-node/cli/ast/index.js +6 -0
- package/dist/esm-node/cli/configPlugin.js +1 -0
- package/dist/esm-node/cli/constant.js +4 -0
- package/dist/esm-node/cli/dataLoaderPlugin.js +184 -0
- package/dist/esm-node/cli/index.js +6 -1
- package/dist/esm-node/cli/server/dataLoaderPlugin.js +58 -0
- package/dist/esm-node/cli/ssrPlugin.js +2 -2
- 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 +5 -7
- package/dist/types/cli/ast/constant.d.ts +7 -0
- package/dist/types/cli/ast/generateRoutes.d.ts +7 -0
- package/dist/types/cli/ast/generateSlimRoutes.d.ts +7 -0
- package/dist/types/cli/ast/index.d.ts +2 -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/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 +17 -0
- package/package.json +37 -11
|
@@ -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) {
|
|
@@ -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
|
+
});
|
|
@@ -34,15 +34,15 @@ 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",
|
|
39
40
|
setup: () => {
|
|
40
41
|
return {
|
|
41
|
-
async
|
|
42
|
+
async beforeRender() {
|
|
43
|
+
console.log(111, "beforeRender");
|
|
42
44
|
if (typeof window !== "undefined") {
|
|
43
|
-
return
|
|
44
|
-
context
|
|
45
|
-
});
|
|
45
|
+
return;
|
|
46
46
|
}
|
|
47
47
|
globalThis.shouldUpdate = false;
|
|
48
48
|
const nodeUtils = await Promise.resolve().then(() => __toESM(require("@module-federation/node/utils")));
|
|
@@ -52,9 +52,7 @@ const mfSSRPlugin = () => ({
|
|
|
52
52
|
await nodeUtils.flushChunks();
|
|
53
53
|
globalThis.shouldUpdate = true;
|
|
54
54
|
}
|
|
55
|
-
return
|
|
56
|
-
context
|
|
57
|
-
});
|
|
55
|
+
return;
|
|
58
56
|
},
|
|
59
57
|
wrapRoot(App) {
|
|
60
58
|
const AppWrapper = (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
export {
|
|
9
|
+
COMPONENT,
|
|
10
|
+
ELEMENT,
|
|
11
|
+
ID,
|
|
12
|
+
IS_ROOT,
|
|
13
|
+
LAZY_COMPONENT,
|
|
14
|
+
PRIVATE_COMPONENT,
|
|
15
|
+
SHOULD_REVALIDATE
|
|
16
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
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, prefix = param.prefix, baseName = param.baseName;
|
|
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: function ImportDeclaration(path) {
|
|
22
|
+
var source = path.node.source.value;
|
|
23
|
+
var routeIdMatch = source.match(/routeId=([^&]+)/);
|
|
24
|
+
if (routeIdMatch) {
|
|
25
|
+
var originalRouteId = routeIdMatch[1];
|
|
26
|
+
var newRouteId = "".concat(prefix).concat(originalRouteId);
|
|
27
|
+
var newSource = source.replace(/routeId=[^&]+/, "routeId=".concat(newRouteId));
|
|
28
|
+
path.node.source = t.stringLiteral(newSource);
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
ObjectExpression: function ObjectExpression(path) {
|
|
32
|
+
var componentName = "";
|
|
33
|
+
var lazyComponentName = "";
|
|
34
|
+
if (!Array.isArray(path.node.properties)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
var idNode = findTargetKeyNode(path.node.properties, "id");
|
|
38
|
+
if (idNode && t.isObjectProperty(idNode) && t.isStringLiteral(idNode.value)) {
|
|
39
|
+
idNode.value = t.stringLiteral("".concat(prefix).concat(idNode.value.value));
|
|
40
|
+
}
|
|
41
|
+
var isRootNode = findTargetKeyNode(path.node.properties, "isRoot");
|
|
42
|
+
if (isRootNode && t.isObjectProperty(isRootNode) && t.isBooleanLiteral(isRootNode.value)) {
|
|
43
|
+
isRootNode.value.value = false;
|
|
44
|
+
}
|
|
45
|
+
if (!isRootNode) {
|
|
46
|
+
var lazyComponentNode = findTargetKeyNode(path.node.properties, "lazyImport");
|
|
47
|
+
if (lazyComponentNode && t.isObjectProperty(lazyComponentNode) && t.isArrowFunctionExpression(lazyComponentNode.value)) {
|
|
48
|
+
lazyComponentName = "LazyComponent_".concat(componentId);
|
|
49
|
+
var lazyDeclaration = t.variableDeclaration("const", [
|
|
50
|
+
t.variableDeclarator(t.identifier(lazyComponentName), lazyComponentNode.value)
|
|
51
|
+
]);
|
|
52
|
+
lazyComponentNode.value = t.identifier(lazyComponentName);
|
|
53
|
+
var componentNode = findTargetKeyNode(path.node.properties, "component");
|
|
54
|
+
if (componentNode && t.isObjectProperty(componentNode) && t.isCallExpression(componentNode.value) && t.isIdentifier(componentNode.value.callee)) {
|
|
55
|
+
componentNode.value = t.callExpression(t.identifier("lazy"), [
|
|
56
|
+
t.identifier(lazyComponentName)
|
|
57
|
+
]);
|
|
58
|
+
}
|
|
59
|
+
lazyComponentDeclarations.push(lazyDeclaration);
|
|
60
|
+
}
|
|
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
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
traverse(ast, {
|
|
84
|
+
Program: function Program(path) {
|
|
85
|
+
var lastImportIndex = path.get("body").reduce(function(lastIndex, p, index) {
|
|
86
|
+
if (t.isImportDeclaration(p.node)) {
|
|
87
|
+
lastIndex = index;
|
|
88
|
+
}
|
|
89
|
+
return lastIndex;
|
|
90
|
+
}, -1);
|
|
91
|
+
if (lastImportIndex >= 0) {
|
|
92
|
+
var lastImport = path.get("body.".concat(lastImportIndex));
|
|
93
|
+
_to_consumable_array(componentDeclarations).concat(_to_consumable_array(lazyComponentDeclarations)).forEach(function(declaration) {
|
|
94
|
+
if ("insertAfter" in lastImport) {
|
|
95
|
+
lastImport.insertAfter(declaration);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
var _generate = generate(ast), newCode = _generate.code;
|
|
102
|
+
var finalCode = "".concat(newCode, "export const baseName = '").concat(baseName, "';");
|
|
103
|
+
fs.writeFileSync(filePath, finalCode);
|
|
104
|
+
}
|
|
105
|
+
export {
|
|
106
|
+
generateRoutes
|
|
107
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
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, ID, SHOULD_REVALIDATE, LAZY_COMPONENT, PRIVATE_COMPONENT } from "./constant";
|
|
7
|
+
function generateSlimRoutes(param) {
|
|
8
|
+
var sourceCode = param.sourceCode, filePath = param.filePath, prefix = param.prefix, baseName = param.baseName;
|
|
9
|
+
var ast = babelParser.parse(sourceCode, {
|
|
10
|
+
sourceType: "module"
|
|
11
|
+
});
|
|
12
|
+
var removedKeys = [
|
|
13
|
+
COMPONENT,
|
|
14
|
+
SHOULD_REVALIDATE,
|
|
15
|
+
LAZY_COMPONENT,
|
|
16
|
+
PRIVATE_COMPONENT
|
|
17
|
+
];
|
|
18
|
+
traverse(ast, {
|
|
19
|
+
ImportDeclaration: function ImportDeclaration(path) {
|
|
20
|
+
var source = path.node.source.value;
|
|
21
|
+
var routeIdMatch = source.match(/routeId=([^&]+)/);
|
|
22
|
+
if (routeIdMatch) {
|
|
23
|
+
var originalRouteId = routeIdMatch[1];
|
|
24
|
+
var newRouteId = "".concat(prefix).concat(originalRouteId);
|
|
25
|
+
var newSource = source.replace(/routeId=[^&]+/, "routeId=".concat(newRouteId));
|
|
26
|
+
path.node.source = t.stringLiteral(newSource);
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
ObjectExpression: function ObjectExpression(path) {
|
|
30
|
+
if (!Array.isArray(path.node.properties)) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
path.node.properties.forEach(function(prop) {
|
|
34
|
+
if (t.isObjectProperty(prop) && t.isStringLiteral(prop.key) && t.isStringLiteral(prop.value) && prop.key.value === ID) {
|
|
35
|
+
prop.value = t.stringLiteral("".concat(prefix).concat(prop.value.value));
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
path.node.properties = path.node.properties.filter(function(p) {
|
|
39
|
+
if (t.isObjectProperty(p) && t.isStringLiteral(p.key)) {
|
|
40
|
+
return !removedKeys.includes(p.key.value);
|
|
41
|
+
} else {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
var tempCode = generate(ast).code;
|
|
48
|
+
var tempAst = babelParser.parse(tempCode, {
|
|
49
|
+
sourceType: "module"
|
|
50
|
+
});
|
|
51
|
+
var usedIdentifiers = /* @__PURE__ */ new Set();
|
|
52
|
+
traverse(tempAst, {
|
|
53
|
+
Identifier: function Identifier(path) {
|
|
54
|
+
if (t.isProperty(path.parent)) {
|
|
55
|
+
usedIdentifiers.add(path.node.name);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
traverse(tempAst, {
|
|
60
|
+
ImportDeclaration: function ImportDeclaration(path) {
|
|
61
|
+
path.node.specifiers = path.node.specifiers.filter(function(specifier) {
|
|
62
|
+
return usedIdentifiers.has(specifier.local.name);
|
|
63
|
+
});
|
|
64
|
+
if (!path.node.specifiers.length) {
|
|
65
|
+
path.remove();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
var _generate = generate(tempAst), newCode = _generate.code;
|
|
70
|
+
var finalCode = "".concat(newCode, "export const baseName = '").concat(baseName, "';");
|
|
71
|
+
fs.writeFileSync(filePath, finalCode);
|
|
72
|
+
}
|
|
73
|
+
export {
|
|
74
|
+
generateSlimRoutes
|
|
75
|
+
};
|
|
@@ -49,6 +49,7 @@ var moduleFederationConfigPlugin = function(userConfig) {
|
|
|
49
49
|
config: /* @__PURE__ */ _async_to_generator(function() {
|
|
50
50
|
var _modernjsConfig_server, _modernjsConfig_dev, bundlerType, ipv4, enableSSR;
|
|
51
51
|
return _ts_generator(this, function(_state2) {
|
|
52
|
+
console.log("config plugin config");
|
|
52
53
|
bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
53
54
|
ipv4 = getIPV4();
|
|
54
55
|
enableSSR = Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|