@module-federation/modern-js 0.0.0-next-20241016083243 → 0.0.0-next-20241017102355
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/index.js +5 -4
- package/dist/cjs/cli/routes/exportRoutePlugin.js +77 -0
- package/dist/cjs/cli/routes/importRoutesPlugin.js +120 -0
- package/dist/cjs/cli/routes/plugin.js +157 -0
- package/dist/cjs/cli/{dataLoader/generateRouteFile.js → routes/traverseRouteFiles.js} +12 -12
- package/dist/cjs/cli/{dataLoader/patchMFConfig.js → routes/utils.js} +18 -10
- package/dist/cjs/cli/server/{dataLoaderPlugin.js → fetchRoutePlugin.js} +7 -7
- package/dist/cjs/runtime/{dataLoader → routes}/plugin-inject-assets.js +3 -3
- package/dist/cjs/runtime/{dataLoader → routes}/plugin.js +1 -1
- package/dist/cjs/types/routes.js +16 -0
- package/dist/esm/cli/index.js +6 -4
- package/dist/esm/cli/routes/exportRoutePlugin.js +79 -0
- package/dist/esm/cli/routes/importRoutesPlugin.js +122 -0
- package/dist/esm/cli/{dataLoader → routes}/plugin.js +74 -149
- package/dist/esm/cli/{dataLoader/generateRouteFile.js → routes/traverseRouteFiles.js} +23 -18
- package/dist/esm/cli/{dataLoader/patchMFConfig.js → routes/utils.js} +12 -6
- package/dist/esm/cli/server/{dataLoaderPlugin.js → fetchRoutePlugin.js} +4 -4
- package/dist/esm/runtime/{dataLoader → routes}/plugin-inject-assets.js +3 -3
- package/dist/esm/runtime/{dataLoader → routes}/plugin.js +1 -1
- package/dist/esm/types/routes.js +0 -0
- package/dist/esm-node/cli/index.js +5 -4
- package/dist/esm-node/cli/routes/exportRoutePlugin.js +53 -0
- package/dist/esm-node/cli/routes/importRoutesPlugin.js +96 -0
- package/dist/esm-node/cli/routes/plugin.js +123 -0
- package/dist/esm-node/cli/{dataLoader/generateRouteFile.js → routes/traverseRouteFiles.js} +8 -8
- package/dist/esm-node/cli/{dataLoader/patchMFConfig.js → routes/utils.js} +13 -6
- package/dist/esm-node/cli/server/{dataLoaderPlugin.js → fetchRoutePlugin.js} +4 -4
- package/dist/esm-node/runtime/{dataLoader → routes}/plugin-inject-assets.js +3 -3
- package/dist/esm-node/runtime/{dataLoader → routes}/plugin.js +1 -1
- package/dist/esm-node/types/routes.js +0 -0
- package/dist/types/cli/routes/exportRoutePlugin.d.ts +4 -0
- package/dist/types/cli/routes/importRoutesPlugin.d.ts +4 -0
- package/dist/types/cli/routes/plugin.d.ts +4 -0
- package/dist/types/cli/{dataLoader/generateRouteFile.d.ts → routes/traverseRouteFiles.d.ts} +4 -3
- package/dist/types/cli/{dataLoader/patchMFConfig.d.ts → routes/utils.d.ts} +2 -1
- package/dist/types/cli/server/{dataLoaderPlugin.d.ts → fetchRoutePlugin.d.ts} +2 -2
- package/dist/types/types/index.d.ts +2 -8
- package/dist/types/types/routes.d.ts +19 -0
- package/package.json +32 -32
- package/dist/cjs/cli/dataLoader/plugin.js +0 -219
- package/dist/esm-node/cli/dataLoader/plugin.js +0 -184
- package/dist/types/cli/dataLoader/plugin.d.ts +0 -6
- /package/dist/cjs/cli/{dataLoader → routes}/ast/constant.js +0 -0
- /package/dist/cjs/cli/{dataLoader → routes}/ast/generateRoutes.js +0 -0
- /package/dist/cjs/cli/{dataLoader → routes}/ast/index.js +0 -0
- /package/dist/cjs/cli/{dataLoader → routes}/clearMFCache.js +0 -0
- /package/dist/cjs/runtime/{dataLoader → routes}/utils.js +0 -0
- /package/dist/esm/cli/{dataLoader → routes}/ast/constant.js +0 -0
- /package/dist/esm/cli/{dataLoader → routes}/ast/generateRoutes.js +0 -0
- /package/dist/esm/cli/{dataLoader → routes}/ast/index.js +0 -0
- /package/dist/esm/cli/{dataLoader → routes}/clearMFCache.js +0 -0
- /package/dist/esm/runtime/{dataLoader → routes}/utils.js +0 -0
- /package/dist/esm-node/cli/{dataLoader → routes}/ast/constant.js +0 -0
- /package/dist/esm-node/cli/{dataLoader → routes}/ast/generateRoutes.js +0 -0
- /package/dist/esm-node/cli/{dataLoader → routes}/ast/index.js +0 -0
- /package/dist/esm-node/cli/{dataLoader → routes}/clearMFCache.js +0 -0
- /package/dist/esm-node/runtime/{dataLoader → routes}/utils.js +0 -0
- /package/dist/types/cli/{dataLoader → routes}/ast/constant.d.ts +0 -0
- /package/dist/types/cli/{dataLoader → routes}/ast/generateRoutes.d.ts +0 -0
- /package/dist/types/cli/{dataLoader → routes}/ast/index.d.ts +0 -0
- /package/dist/types/cli/{dataLoader → routes}/clearMFCache.d.ts +0 -0
- /package/dist/types/runtime/{dataLoader → routes}/plugin-inject-assets.d.ts +0 -0
- /package/dist/types/runtime/{dataLoader → routes}/plugin.d.ts +0 -0
- /package/dist/types/runtime/{dataLoader → routes}/utils.d.ts +0 -0
package/dist/cjs/cli/index.js
CHANGED
|
@@ -27,7 +27,7 @@ var import_enhanced = require("@module-federation/enhanced");
|
|
|
27
27
|
var import_rspack = require("@module-federation/enhanced/rspack");
|
|
28
28
|
var import_configPlugin = require("./configPlugin");
|
|
29
29
|
var import_ssrPlugin = require("./ssrPlugin");
|
|
30
|
-
var import_plugin = require("./
|
|
30
|
+
var import_plugin = require("./routes/plugin");
|
|
31
31
|
var import_enhanced2 = require("@module-federation/enhanced");
|
|
32
32
|
const moduleFederationPlugin = (userConfig = {}) => {
|
|
33
33
|
const internalModernPluginOptions = {
|
|
@@ -37,7 +37,7 @@ const moduleFederationPlugin = (userConfig = {}) => {
|
|
|
37
37
|
nodePlugin: void 0,
|
|
38
38
|
distOutputDir: "",
|
|
39
39
|
originPluginOptions: userConfig,
|
|
40
|
-
remoteIpStrategy:
|
|
40
|
+
remoteIpStrategy: void 0
|
|
41
41
|
};
|
|
42
42
|
return {
|
|
43
43
|
name: "@modern-js/plugin-module-federation",
|
|
@@ -81,8 +81,9 @@ const moduleFederationPlugin = (userConfig = {}) => {
|
|
|
81
81
|
usePlugins: [
|
|
82
82
|
(0, import_configPlugin.moduleFederationConfigPlugin)(internalModernPluginOptions),
|
|
83
83
|
(0, import_ssrPlugin.moduleFederationSSRPlugin)(internalModernPluginOptions),
|
|
84
|
-
(0, import_plugin.
|
|
85
|
-
|
|
84
|
+
(0, import_plugin.moduleFederationRoutesPlugin)({
|
|
85
|
+
userConfig,
|
|
86
|
+
internalOptions: internalModernPluginOptions
|
|
86
87
|
})
|
|
87
88
|
]
|
|
88
89
|
};
|
|
@@ -0,0 +1,77 @@
|
|
|
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 exportRoutePlugin_exports = {};
|
|
20
|
+
__export(exportRoutePlugin_exports, {
|
|
21
|
+
default: () => exportRoutePlugin_default,
|
|
22
|
+
moduleFederationExportRoutePlugin: () => moduleFederationExportRoutePlugin
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(exportRoutePlugin_exports);
|
|
25
|
+
var import_constant = require("../../constant");
|
|
26
|
+
var import_utils = require("./utils");
|
|
27
|
+
const moduleFederationExportRoutePlugin = ({ userConfig, internalOptions, entries }) => ({
|
|
28
|
+
name: "@modern-js/plugin-module-federation-export-routes",
|
|
29
|
+
pre: [
|
|
30
|
+
"@modern-js/plugin-module-federation-route"
|
|
31
|
+
],
|
|
32
|
+
post: [
|
|
33
|
+
"@modern-js/plugin-router",
|
|
34
|
+
"@modern-js/plugin-module-federation"
|
|
35
|
+
],
|
|
36
|
+
setup: async ({ useAppContext }) => {
|
|
37
|
+
if (!userConfig.exportRoutes) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const appContext = useAppContext();
|
|
41
|
+
const { metaName = import_constant.META_NAME } = internalOptions;
|
|
42
|
+
const internalDirectory = appContext.internalDirectory.replace(import_constant.META_NAME, metaName || import_constant.META_NAME);
|
|
43
|
+
return {
|
|
44
|
+
config: async () => {
|
|
45
|
+
return {
|
|
46
|
+
tools: {
|
|
47
|
+
// bundlerChain can not keep target order
|
|
48
|
+
rspack(_config, { isServer }) {
|
|
49
|
+
(0, import_utils.addExpose)({
|
|
50
|
+
mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
|
|
51
|
+
metaName,
|
|
52
|
+
isServer,
|
|
53
|
+
internalDirectory,
|
|
54
|
+
entries
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
// bundlerChain can not keep target order
|
|
58
|
+
webpack(_config, { isServer }) {
|
|
59
|
+
(0, import_utils.addExpose)({
|
|
60
|
+
mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
|
|
61
|
+
metaName,
|
|
62
|
+
isServer,
|
|
63
|
+
internalDirectory,
|
|
64
|
+
entries
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
var exportRoutePlugin_default = moduleFederationExportRoutePlugin;
|
|
74
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
75
|
+
0 && (module.exports = {
|
|
76
|
+
moduleFederationExportRoutePlugin
|
|
77
|
+
});
|
|
@@ -0,0 +1,120 @@
|
|
|
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 importRoutesPlugin_exports = {};
|
|
20
|
+
__export(importRoutesPlugin_exports, {
|
|
21
|
+
default: () => importRoutesPlugin_default,
|
|
22
|
+
moduleFederationImportRoutePlugin: () => moduleFederationImportRoutePlugin
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(importRoutesPlugin_exports);
|
|
25
|
+
var import_constant = require("../../constant");
|
|
26
|
+
var import_clearMFCache = require("./clearMFCache");
|
|
27
|
+
function _transformRuntimeOptions(buildOptions) {
|
|
28
|
+
const remotes = buildOptions.remotes || {};
|
|
29
|
+
const runtimeRemotes = Object.entries(remotes).map((remote) => {
|
|
30
|
+
const [alias, nameAndEntry] = remote;
|
|
31
|
+
const [name, entry] = nameAndEntry.split("@");
|
|
32
|
+
return {
|
|
33
|
+
name,
|
|
34
|
+
entry,
|
|
35
|
+
alias
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
return {
|
|
39
|
+
name: buildOptions.name,
|
|
40
|
+
remotes: runtimeRemotes
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const moduleFederationImportRoutePlugin = ({ userConfig, internalOptions, remotePathMap, serverPlugin = "@module-federation/modern-js/fetch-router-server-plugin", ssrByRouteIdsMap, transformRuntimeOptions }) => ({
|
|
44
|
+
name: "@modern-js/plugin-module-federation-import-routes",
|
|
45
|
+
pre: [
|
|
46
|
+
"@modern-js/plugin-module-federation-route"
|
|
47
|
+
],
|
|
48
|
+
post: [
|
|
49
|
+
"@modern-js/plugin-router",
|
|
50
|
+
"@modern-js/plugin-module-federation"
|
|
51
|
+
],
|
|
52
|
+
setup: async () => {
|
|
53
|
+
if (!userConfig.importRoutes) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const { metaName = import_constant.META_NAME } = internalOptions;
|
|
57
|
+
const transformRuntimeFn = transformRuntimeOptions || _transformRuntimeOptions;
|
|
58
|
+
const dataLoaderRemotes = [
|
|
59
|
+
...new Set(Object.values(remotePathMap).map((i) => i.name))
|
|
60
|
+
];
|
|
61
|
+
const serverPluginOptions = {
|
|
62
|
+
runtimeOptions: transformRuntimeFn(internalOptions.csrConfig),
|
|
63
|
+
dataLoaderRemotes,
|
|
64
|
+
ssrByRouteIdsMap
|
|
65
|
+
};
|
|
66
|
+
const hasDataLoaderRemotes = () => Boolean(serverPluginOptions.dataLoaderRemotes.length);
|
|
67
|
+
return {
|
|
68
|
+
_internalRuntimePlugins: ({ entrypoint, plugins }) => {
|
|
69
|
+
if (!hasDataLoaderRemotes()) {
|
|
70
|
+
return {
|
|
71
|
+
entrypoint,
|
|
72
|
+
plugins
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
plugins.push({
|
|
76
|
+
name: "ssrDataLoader",
|
|
77
|
+
path: "@module-federation/modern-js/routes",
|
|
78
|
+
config: {
|
|
79
|
+
metaName,
|
|
80
|
+
dataLoaderRemotes
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
plugins.push({
|
|
84
|
+
name: "ssrDataLoaderInjectAssets",
|
|
85
|
+
path: "@module-federation/modern-js/routes-inject-assets",
|
|
86
|
+
config: {
|
|
87
|
+
metaName,
|
|
88
|
+
dataLoaderRemotes
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
return {
|
|
92
|
+
entrypoint,
|
|
93
|
+
plugins
|
|
94
|
+
};
|
|
95
|
+
},
|
|
96
|
+
_internalServerPlugins({ plugins }) {
|
|
97
|
+
if (!hasDataLoaderRemotes()) {
|
|
98
|
+
return {
|
|
99
|
+
plugins
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
plugins.push({
|
|
103
|
+
name: serverPlugin,
|
|
104
|
+
options: serverPluginOptions
|
|
105
|
+
});
|
|
106
|
+
return {
|
|
107
|
+
plugins
|
|
108
|
+
};
|
|
109
|
+
},
|
|
110
|
+
async afterDev() {
|
|
111
|
+
(0, import_clearMFCache.clearMFCache)();
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
var importRoutesPlugin_default = moduleFederationImportRoutePlugin;
|
|
117
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
118
|
+
0 && (module.exports = {
|
|
119
|
+
moduleFederationImportRoutePlugin
|
|
120
|
+
});
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var plugin_exports = {};
|
|
30
|
+
__export(plugin_exports, {
|
|
31
|
+
default: () => plugin_default,
|
|
32
|
+
moduleFederationRoutesPlugin: () => moduleFederationRoutesPlugin
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(plugin_exports);
|
|
35
|
+
var import_path = __toESM(require("path"));
|
|
36
|
+
var import_utils = require("@modern-js/utils");
|
|
37
|
+
var import_utils2 = require("../../runtime/routes/utils");
|
|
38
|
+
var import_constant = require("../../constant");
|
|
39
|
+
var import_traverseRouteFiles = require("./traverseRouteFiles");
|
|
40
|
+
var import_exportRoutePlugin = require("./exportRoutePlugin");
|
|
41
|
+
var import_importRoutesPlugin = require("./importRoutesPlugin");
|
|
42
|
+
var import_utils3 = require("./utils");
|
|
43
|
+
var import_constant2 = require("../../constant");
|
|
44
|
+
const moduleFederationRoutesPlugin = ({ userConfig, internalOptions, serverPlugin, transformRuntimeOptions }) => {
|
|
45
|
+
const entries = /* @__PURE__ */ new Set();
|
|
46
|
+
const remotePathMap = {};
|
|
47
|
+
const ssrByRouteIdsMap = {};
|
|
48
|
+
const internalRoutesPluginOptions = {
|
|
49
|
+
userConfig,
|
|
50
|
+
internalOptions,
|
|
51
|
+
entries,
|
|
52
|
+
remotePathMap,
|
|
53
|
+
ssrByRouteIdsMap,
|
|
54
|
+
serverPlugin,
|
|
55
|
+
transformRuntimeOptions
|
|
56
|
+
};
|
|
57
|
+
return {
|
|
58
|
+
name: "@modern-js/plugin-module-federation-route",
|
|
59
|
+
pre: [
|
|
60
|
+
"@modern-js/plugin-module-federation-config"
|
|
61
|
+
],
|
|
62
|
+
setup: async ({ useAppContext }) => {
|
|
63
|
+
if (!userConfig.exportRoutes && !userConfig.importRoutes) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const appContext = useAppContext();
|
|
67
|
+
const name = internalOptions.csrConfig.name;
|
|
68
|
+
const { metaName = import_constant.META_NAME } = internalOptions;
|
|
69
|
+
const internalDirectory = appContext.internalDirectory.replace(import_constant.META_NAME, metaName || import_constant.META_NAME);
|
|
70
|
+
const csrConfig = internalOptions.csrConfig;
|
|
71
|
+
if (typeof csrConfig.remotes === "object" && Object.keys(csrConfig.remotes).length) {
|
|
72
|
+
const { entries: scanEntries } = await (0, import_traverseRouteFiles.traverseRouteFiles)({
|
|
73
|
+
appDirectory: appContext.appDirectory,
|
|
74
|
+
generateRouteFile: userConfig.importRoutes,
|
|
75
|
+
remotePathMap
|
|
76
|
+
});
|
|
77
|
+
scanEntries.forEach((e) => entries.add(e));
|
|
78
|
+
} else {
|
|
79
|
+
entries.add(import_constant2.DEFAULT_ENTRY);
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
config: async () => {
|
|
83
|
+
return {
|
|
84
|
+
tools: {
|
|
85
|
+
// bundlerChain can not keep target order
|
|
86
|
+
rspack(_config, { isServer }) {
|
|
87
|
+
(0, import_utils3.addShared)({
|
|
88
|
+
mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
|
|
89
|
+
metaName,
|
|
90
|
+
isServer,
|
|
91
|
+
internalDirectory,
|
|
92
|
+
entries
|
|
93
|
+
});
|
|
94
|
+
},
|
|
95
|
+
// bundlerChain can not keep target order
|
|
96
|
+
webpack(_config, { isServer }) {
|
|
97
|
+
(0, import_utils3.addShared)({
|
|
98
|
+
mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
|
|
99
|
+
metaName,
|
|
100
|
+
isServer,
|
|
101
|
+
internalDirectory,
|
|
102
|
+
entries
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
source: {
|
|
107
|
+
define: {
|
|
108
|
+
MODERN_ROUTER_ID_PREFIX: JSON.stringify((0, import_utils2.transformName2Prefix)(name))
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
},
|
|
113
|
+
async modifyFileSystemRoutes(options) {
|
|
114
|
+
const { routes, entrypoint } = options;
|
|
115
|
+
const { entryName } = entrypoint;
|
|
116
|
+
const prefix = (0, import_utils2.transformName2Prefix)(internalOptions.csrConfig.name);
|
|
117
|
+
const modifyRouteIds = async (route, pathName) => {
|
|
118
|
+
const currentPathName = route.path ? import_path.default.join("/", pathName, route.path) : pathName;
|
|
119
|
+
if (route.id) {
|
|
120
|
+
const originalId = route.id;
|
|
121
|
+
route.originalId = originalId;
|
|
122
|
+
const remoteInfo = remotePathMap[currentPathName];
|
|
123
|
+
if (remoteInfo) {
|
|
124
|
+
const { path: path2, name: name2 } = remoteInfo;
|
|
125
|
+
const remoteIdPrefix = (0, import_utils2.transformName2Prefix)(name2);
|
|
126
|
+
const isLayout = Boolean(route.children);
|
|
127
|
+
const newId = `${remoteIdPrefix}${isLayout ? "layout" : "page"}`;
|
|
128
|
+
ssrByRouteIdsMap[originalId] = newId;
|
|
129
|
+
const content = import_utils.fs.readFileSync(path2, "utf-8");
|
|
130
|
+
await import_utils.fs.writeFile(path2, content.replace(import_constant2.ROUTE_ID, originalId));
|
|
131
|
+
route.id = newId;
|
|
132
|
+
} else {
|
|
133
|
+
route.id = `${prefix}${route.id}`;
|
|
134
|
+
}
|
|
135
|
+
route.children && await Promise.all(route.children.map(async (r) => {
|
|
136
|
+
return await modifyRouteIds(r, currentPathName);
|
|
137
|
+
}));
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
await Promise.all(routes.map(async (route) => {
|
|
141
|
+
await modifyRouteIds(route, entryName === import_constant2.DEFAULT_ENTRY ? "" : entryName);
|
|
142
|
+
}));
|
|
143
|
+
return options;
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
},
|
|
147
|
+
usePlugins: [
|
|
148
|
+
(0, import_exportRoutePlugin.moduleFederationExportRoutePlugin)(internalRoutesPluginOptions),
|
|
149
|
+
(0, import_importRoutesPlugin.moduleFederationImportRoutePlugin)(internalRoutesPluginOptions)
|
|
150
|
+
]
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
var plugin_default = moduleFederationRoutesPlugin;
|
|
154
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
155
|
+
0 && (module.exports = {
|
|
156
|
+
moduleFederationRoutesPlugin
|
|
157
|
+
});
|
|
@@ -26,17 +26,17 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var
|
|
30
|
-
__export(
|
|
29
|
+
var traverseRouteFiles_exports = {};
|
|
30
|
+
__export(traverseRouteFiles_exports, {
|
|
31
31
|
calcPathName: () => calcPathName,
|
|
32
|
-
|
|
32
|
+
traverseRouteFiles: () => traverseRouteFiles
|
|
33
33
|
});
|
|
34
|
-
module.exports = __toCommonJS(
|
|
34
|
+
module.exports = __toCommonJS(traverseRouteFiles_exports);
|
|
35
35
|
var import_utils = require("@modern-js/utils");
|
|
36
36
|
var import_path = __toESM(require("path"));
|
|
37
37
|
var import_os = __toESM(require("os"));
|
|
38
38
|
var import_constant = require("../../constant");
|
|
39
|
-
var import_utils2 = require("../../runtime/
|
|
39
|
+
var import_utils2 = require("../../runtime/routes/utils");
|
|
40
40
|
const ROUTES = "routes";
|
|
41
41
|
function calcPathName(filePath, rootDir, entry) {
|
|
42
42
|
const relativePath = import_path.default.relative(rootDir, filePath);
|
|
@@ -65,10 +65,9 @@ function calcPathName(filePath, rootDir, entry) {
|
|
|
65
65
|
}, []);
|
|
66
66
|
return import_path.default.join("/", entry, splitPaths.filter((p) => !!p).join("/"));
|
|
67
67
|
}
|
|
68
|
-
async function
|
|
69
|
-
const { appDirectory } = options;
|
|
68
|
+
async function traverseRouteFiles(options) {
|
|
69
|
+
const { appDirectory, generateRouteFile, remotePathMap } = options;
|
|
70
70
|
const entries = [];
|
|
71
|
-
const remotePathMap = {};
|
|
72
71
|
const srcPath = `${appDirectory}/src`;
|
|
73
72
|
const traverse = async (filepath, rootDir, entry) => {
|
|
74
73
|
if (!await import_utils.fs.pathExists(filepath)) {
|
|
@@ -122,7 +121,9 @@ async function generateRouteFile(options) {
|
|
|
122
121
|
const entry = import_path.default.relative(srcPath, dir);
|
|
123
122
|
entries.push(entry);
|
|
124
123
|
const rootDir = `${dir}/${ROUTES}`;
|
|
125
|
-
|
|
124
|
+
if (generateRouteFile) {
|
|
125
|
+
await traverse(rootDir, rootDir, entry);
|
|
126
|
+
}
|
|
126
127
|
} else {
|
|
127
128
|
await Promise.all(items.map(async (item) => {
|
|
128
129
|
await traverseRoutes(import_path.default.join(dir, item), level++);
|
|
@@ -137,12 +138,11 @@ async function generateRouteFile(options) {
|
|
|
137
138
|
return entry;
|
|
138
139
|
});
|
|
139
140
|
return {
|
|
140
|
-
entries: normalizedEntries
|
|
141
|
-
remotePathMap
|
|
141
|
+
entries: normalizedEntries
|
|
142
142
|
};
|
|
143
143
|
}
|
|
144
144
|
// Annotate the CommonJS export names for ESM import in node:
|
|
145
145
|
0 && (module.exports = {
|
|
146
146
|
calcPathName,
|
|
147
|
-
|
|
147
|
+
traverseRouteFiles
|
|
148
148
|
});
|
|
@@ -26,11 +26,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var
|
|
30
|
-
__export(
|
|
31
|
-
|
|
29
|
+
var utils_exports = {};
|
|
30
|
+
__export(utils_exports, {
|
|
31
|
+
addExpose: () => addExpose,
|
|
32
|
+
addShared: () => addShared
|
|
32
33
|
});
|
|
33
|
-
module.exports = __toCommonJS(
|
|
34
|
+
module.exports = __toCommonJS(utils_exports);
|
|
34
35
|
var import_path = __toESM(require("path"));
|
|
35
36
|
var import_utils = require("@modern-js/utils");
|
|
36
37
|
var import_constant = require("../../constant");
|
|
@@ -109,7 +110,8 @@ function addExpose(options) {
|
|
|
109
110
|
});
|
|
110
111
|
}
|
|
111
112
|
function addShared(options) {
|
|
112
|
-
const {
|
|
113
|
+
const { mfConfig } = options;
|
|
114
|
+
const styledComponents = `styled-components`;
|
|
113
115
|
const reactRouterDom = `react-router-dom`;
|
|
114
116
|
const reactRouterDomServer = `react-router-dom/server`;
|
|
115
117
|
if (!mfConfig.shared) {
|
|
@@ -119,6 +121,9 @@ function addShared(options) {
|
|
|
119
121
|
},
|
|
120
122
|
[reactRouterDomServer]: {
|
|
121
123
|
singleton: true
|
|
124
|
+
},
|
|
125
|
+
[styledComponents]: {
|
|
126
|
+
singleton: true
|
|
122
127
|
}
|
|
123
128
|
};
|
|
124
129
|
} else {
|
|
@@ -129,6 +134,9 @@ function addShared(options) {
|
|
|
129
134
|
mfConfig.shared[reactRouterDomServer] = {
|
|
130
135
|
singleton: true
|
|
131
136
|
};
|
|
137
|
+
mfConfig.shared[styledComponents] = {
|
|
138
|
+
singleton: true
|
|
139
|
+
};
|
|
132
140
|
} else {
|
|
133
141
|
mfConfig.shared = mfConfig.shared.reduce((sum, cur) => {
|
|
134
142
|
if (typeof cur === "string") {
|
|
@@ -147,14 +155,14 @@ function addShared(options) {
|
|
|
147
155
|
mfConfig.shared[reactRouterDomServer] = {
|
|
148
156
|
singleton: true
|
|
149
157
|
};
|
|
158
|
+
mfConfig.shared[styledComponents] = {
|
|
159
|
+
singleton: true
|
|
160
|
+
};
|
|
150
161
|
}
|
|
151
162
|
}
|
|
152
163
|
}
|
|
153
|
-
function patchMFConfig(options) {
|
|
154
|
-
addShared(options);
|
|
155
|
-
addExpose(options);
|
|
156
|
-
}
|
|
157
164
|
// Annotate the CommonJS export names for ESM import in node:
|
|
158
165
|
0 && (module.exports = {
|
|
159
|
-
|
|
166
|
+
addExpose,
|
|
167
|
+
addShared
|
|
160
168
|
});
|
|
@@ -16,18 +16,18 @@ 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
|
-
default: () =>
|
|
19
|
+
var fetchRoutePlugin_exports = {};
|
|
20
|
+
__export(fetchRoutePlugin_exports, {
|
|
21
|
+
default: () => fetchRoutePlugin_default
|
|
22
22
|
});
|
|
23
|
-
module.exports = __toCommonJS(
|
|
23
|
+
module.exports = __toCommonJS(fetchRoutePlugin_exports);
|
|
24
24
|
var import_runtime = require("@module-federation/enhanced/runtime");
|
|
25
25
|
var import_sdk = require("@module-federation/sdk");
|
|
26
26
|
var import_fetchRemoteFullRoutesMap = require("./fetchRemoteFullRoutesMap");
|
|
27
|
-
var import_utils = require("../../runtime/
|
|
27
|
+
var import_utils = require("../../runtime/routes/utils");
|
|
28
28
|
var import_constant = require("../../constant");
|
|
29
|
-
var
|
|
30
|
-
name: "
|
|
29
|
+
var fetchRoutePlugin_default = ({ runtimeOptions, dataLoaderRemotes, ssrByRouteIdsMap }) => ({
|
|
30
|
+
name: "@module-federation/modern-js-fetch-route",
|
|
31
31
|
pre: [
|
|
32
32
|
"@modern-js/plugin-inject-resource"
|
|
33
33
|
],
|
|
@@ -35,9 +35,9 @@ function traverseRoutes(routes, remoteNames) {
|
|
|
35
35
|
}
|
|
36
36
|
const ssrDataLoaderInjectAssetsPlugin = ({ metaName }) => {
|
|
37
37
|
return {
|
|
38
|
-
name: "@modern-js/plugin-mf-
|
|
38
|
+
name: "@modern-js/plugin-mf-routes-inject-assets",
|
|
39
39
|
pre: [
|
|
40
|
-
"@modern-js/plugin-mf-
|
|
40
|
+
"@modern-js/plugin-mf-routes"
|
|
41
41
|
],
|
|
42
42
|
post: [
|
|
43
43
|
"@module-federation/modern-js",
|
|
@@ -45,7 +45,7 @@ const ssrDataLoaderInjectAssetsPlugin = ({ metaName }) => {
|
|
|
45
45
|
],
|
|
46
46
|
setup: () => {
|
|
47
47
|
return {
|
|
48
|
-
wrapRoot(
|
|
48
|
+
wrapRoot() {
|
|
49
49
|
const AppWrapper = (props) => {
|
|
50
50
|
const instance = (0, import_runtime.getInstance)();
|
|
51
51
|
if (!instance || !instance.options.remotes.length) {
|
|
@@ -26,7 +26,7 @@ var import_constant = require("../../constant");
|
|
|
26
26
|
var import_utils = require("./utils");
|
|
27
27
|
const ssrDataLoaderPlugin = ({ metaName, dataLoaderRemotes }) => {
|
|
28
28
|
return {
|
|
29
|
-
name: "@modern-js/plugin-mf-
|
|
29
|
+
name: "@modern-js/plugin-mf-routes",
|
|
30
30
|
post: [
|
|
31
31
|
`@${metaName}/plugin-router`,
|
|
32
32
|
"@module-federation/modern-js"
|
|
@@ -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 routes_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(routes_exports);
|
package/dist/esm/cli/index.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
-
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
3
2
|
import { _ as _type_of } from "@swc/helpers/_/_type_of";
|
|
4
3
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
5
4
|
import { ModuleFederationPlugin as WebpackModuleFederationPlugin, AsyncBoundaryPlugin } from "@module-federation/enhanced";
|
|
6
5
|
import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
|
|
7
6
|
import { moduleFederationConfigPlugin } from "./configPlugin";
|
|
8
7
|
import { moduleFederationSSRPlugin } from "./ssrPlugin";
|
|
9
|
-
import {
|
|
8
|
+
import { moduleFederationRoutesPlugin } from "./routes/plugin";
|
|
10
9
|
var moduleFederationPlugin = function() {
|
|
11
10
|
var userConfig = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
12
11
|
var internalModernPluginOptions = {
|
|
@@ -16,7 +15,7 @@ var moduleFederationPlugin = function() {
|
|
|
16
15
|
nodePlugin: void 0,
|
|
17
16
|
distOutputDir: "",
|
|
18
17
|
originPluginOptions: userConfig,
|
|
19
|
-
remoteIpStrategy:
|
|
18
|
+
remoteIpStrategy: void 0
|
|
20
19
|
};
|
|
21
20
|
return {
|
|
22
21
|
name: "@modern-js/plugin-module-federation",
|
|
@@ -83,7 +82,10 @@ var moduleFederationPlugin = function() {
|
|
|
83
82
|
usePlugins: [
|
|
84
83
|
moduleFederationConfigPlugin(internalModernPluginOptions),
|
|
85
84
|
moduleFederationSSRPlugin(internalModernPluginOptions),
|
|
86
|
-
|
|
85
|
+
moduleFederationRoutesPlugin({
|
|
86
|
+
userConfig,
|
|
87
|
+
internalOptions: internalModernPluginOptions
|
|
88
|
+
})
|
|
87
89
|
]
|
|
88
90
|
};
|
|
89
91
|
};
|