@module-federation/modern-js 0.0.0-next-20240909083238 → 0.0.0-next-20240909092952
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/generateRoutes.js +3 -4
- package/dist/cjs/cli/dataLoader/ast/index.js +2 -11
- package/dist/cjs/cli/dataLoader/patchMFConfig.js +3 -8
- package/dist/cjs/cli/dataLoader/plugin.js +7 -18
- package/dist/cjs/cli/index.js +1 -2
- package/dist/cjs/cli/server/dataLoaderPlugin.js +1 -1
- package/dist/cjs/cli/server/fetchRemoteFullRoutesMap.js +6 -5
- package/dist/esm/cli/dataLoader/ast/generateRoutes.js +3 -4
- package/dist/esm/cli/dataLoader/ast/index.js +1 -7
- package/dist/esm/cli/dataLoader/patchMFConfig.js +3 -8
- package/dist/esm/cli/dataLoader/plugin.js +11 -18
- package/dist/esm/cli/index.js +1 -3
- package/dist/esm/cli/server/dataLoaderPlugin.js +1 -1
- package/dist/esm/cli/server/fetchRemoteFullRoutesMap.js +7 -5
- package/dist/esm-node/cli/dataLoader/ast/generateRoutes.js +3 -4
- package/dist/esm-node/cli/dataLoader/ast/index.js +1 -7
- package/dist/esm-node/cli/dataLoader/patchMFConfig.js +3 -8
- package/dist/esm-node/cli/dataLoader/plugin.js +9 -19
- package/dist/esm-node/cli/index.js +1 -2
- package/dist/esm-node/cli/server/dataLoaderPlugin.js +1 -1
- package/dist/esm-node/cli/server/fetchRemoteFullRoutesMap.js +6 -5
- package/dist/types/cli/dataLoader/ast/generateRoutes.d.ts +1 -3
- package/dist/types/cli/dataLoader/ast/index.d.ts +0 -3
- package/dist/types/cli/dataLoader/patchMFConfig.d.ts +0 -1
- package/dist/types/cli/dataLoader/plugin.d.ts +2 -2
- package/dist/types/interfaces/route.d.ts +0 -1
- package/dist/types/types/index.d.ts +1 -2
- package/package.json +11 -11
- 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/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-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/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
|
@@ -39,7 +39,7 @@ var t = __toESM(require("@babel/types"));
|
|
|
39
39
|
function findTargetKeyNode(nodeProperties, key) {
|
|
40
40
|
return nodeProperties.find((p) => t.isObjectProperty(p) && t.isStringLiteral(p.key) && p.key.value === key);
|
|
41
41
|
}
|
|
42
|
-
function generateRoutes({ sourceCode, filePath
|
|
42
|
+
function generateRoutes({ sourceCode, filePath }) {
|
|
43
43
|
const ast = babelParser.parse(sourceCode, {
|
|
44
44
|
sourceType: "module"
|
|
45
45
|
});
|
|
@@ -132,9 +132,8 @@ function generateRoutes({ sourceCode, filePath, prefix, baseName }) {
|
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
});
|
|
135
|
-
const { code
|
|
136
|
-
|
|
137
|
-
import_fs.default.writeFileSync(filePath, finalCode);
|
|
135
|
+
const { code } = (0, import_generator.default)(ast);
|
|
136
|
+
import_fs.default.writeFileSync(filePath, code);
|
|
138
137
|
}
|
|
139
138
|
// Annotate the CommonJS export names for ESM import in node:
|
|
140
139
|
0 && (module.exports = {
|
|
@@ -18,20 +18,11 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var ast_exports = {};
|
|
20
20
|
__export(ast_exports, {
|
|
21
|
-
generateRoutes: () => import_generateRoutes.generateRoutes
|
|
22
|
-
generateSelfRoutes: () => import_generateSelfRoutes.generateSelfRoutes,
|
|
23
|
-
generateSerializableRoutes: () => import_generateSerializableRoutes.generateSerializableRoutes,
|
|
24
|
-
generateSlimRoutes: () => import_generateSlimRoutes.generateSlimRoutes
|
|
21
|
+
generateRoutes: () => import_generateRoutes.generateRoutes
|
|
25
22
|
});
|
|
26
23
|
module.exports = __toCommonJS(ast_exports);
|
|
27
24
|
var import_generateRoutes = require("./generateRoutes");
|
|
28
|
-
var import_generateSlimRoutes = require("./generateSlimRoutes");
|
|
29
|
-
var import_generateSerializableRoutes = require("./generateSerializableRoutes");
|
|
30
|
-
var import_generateSelfRoutes = require("./generateSelfRoutes");
|
|
31
25
|
// Annotate the CommonJS export names for ESM import in node:
|
|
32
26
|
0 && (module.exports = {
|
|
33
|
-
generateRoutes
|
|
34
|
-
generateSelfRoutes,
|
|
35
|
-
generateSerializableRoutes,
|
|
36
|
-
generateSlimRoutes
|
|
27
|
+
generateRoutes
|
|
37
28
|
});
|
|
@@ -33,12 +33,11 @@ __export(patchMFConfig_exports, {
|
|
|
33
33
|
module.exports = __toCommonJS(patchMFConfig_exports);
|
|
34
34
|
var import_path = __toESM(require("path"));
|
|
35
35
|
var import_utils = require("@modern-js/utils");
|
|
36
|
-
var import_utils2 = require("../../runtime/utils");
|
|
37
36
|
var import_constant = require("../../constant");
|
|
38
37
|
var import_constant2 = require("../../constant");
|
|
39
38
|
var import_ast = require("./ast");
|
|
40
39
|
function generateExtraExposeFiles(options) {
|
|
41
|
-
const { internalDirectory, mfConfig, isServer,
|
|
40
|
+
const { internalDirectory, mfConfig, isServer, entries } = options;
|
|
42
41
|
const entryMap = {};
|
|
43
42
|
const outputDir = import_path.default.resolve(process.cwd(), "node_modules/.federation/data-loader");
|
|
44
43
|
import_utils.fs.ensureDirSync(outputDir);
|
|
@@ -57,9 +56,7 @@ function generateExtraExposeFiles(options) {
|
|
|
57
56
|
const outputFullRoutesPath = import_path.default.resolve(outputEntryDir, addSuffix(import_constant2.MF_ROUTES));
|
|
58
57
|
(0, import_ast.generateRoutes)({
|
|
59
58
|
sourceCode: routesFileContent,
|
|
60
|
-
filePath: outputFullRoutesPath
|
|
61
|
-
prefix: (0, import_utils2.transformName2Prefix)(mfConfig.name),
|
|
62
|
-
baseName
|
|
59
|
+
filePath: outputFullRoutesPath
|
|
63
60
|
});
|
|
64
61
|
const routeServerLoaderPath = import_path.default.resolve(sourceDir, `${import_constant.MODERN_JS_ROUTE_SERVER_LOADER}.js`);
|
|
65
62
|
const outputRouteServerLoaderPath = import_path.default.resolve(outputEntryDir, `${import_constant.MODERN_JS_ROUTE_SERVER_LOADER}.js`);
|
|
@@ -67,9 +64,7 @@ function generateExtraExposeFiles(options) {
|
|
|
67
64
|
const routeServerLoaderContent = import_utils.fs.readFileSync(routeServerLoaderPath, "utf-8");
|
|
68
65
|
(0, import_ast.generateRoutes)({
|
|
69
66
|
sourceCode: routeServerLoaderContent,
|
|
70
|
-
filePath: outputRouteServerLoaderPath
|
|
71
|
-
prefix: (0, import_utils2.transformName2Prefix)(mfConfig.name),
|
|
72
|
-
baseName
|
|
67
|
+
filePath: outputRouteServerLoaderPath
|
|
73
68
|
});
|
|
74
69
|
}
|
|
75
70
|
entryMap[entry] = {
|
|
@@ -30,7 +30,6 @@ var plugin_exports = {};
|
|
|
30
30
|
__export(plugin_exports, {
|
|
31
31
|
default: () => plugin_default,
|
|
32
32
|
generateRoutes: () => import_ast.generateRoutes,
|
|
33
|
-
generateSlimRoutes: () => import_ast.generateSlimRoutes,
|
|
34
33
|
moduleFederationDataLoaderPlugin: () => moduleFederationDataLoaderPlugin
|
|
35
34
|
});
|
|
36
35
|
module.exports = __toCommonJS(plugin_exports);
|
|
@@ -66,31 +65,21 @@ const moduleFederationDataLoaderPlugin = (enable, internalOptions, userConfig) =
|
|
|
66
65
|
"@modern-js/plugin-router",
|
|
67
66
|
"@modern-js/plugin-module-federation"
|
|
68
67
|
],
|
|
69
|
-
setup: async ({
|
|
70
|
-
var _modernjsConfig_server, _modernjsConfig_server1, _modernjsConfig_server2, _modernjsConfig_server3, _modernjsConfig_server4;
|
|
68
|
+
setup: async ({ useAppContext }) => {
|
|
71
69
|
if (!enable) {
|
|
72
70
|
return;
|
|
73
71
|
}
|
|
74
72
|
const {
|
|
75
|
-
baseName,
|
|
76
|
-
partialSSRRemotes = [],
|
|
77
73
|
// patchMFConfig,
|
|
78
74
|
metaName = import_constant2.META_NAME,
|
|
79
75
|
serverPlugin = "@module-federation/modern-js/data-loader-server",
|
|
80
76
|
transformRuntimeOptions
|
|
81
77
|
} = userConfig;
|
|
82
|
-
if (!baseName) {
|
|
83
|
-
throw new Error(`${import_constant.PLUGIN_IDENTIFIER} 'baseName' is required if you enable 'dataLoader'!`);
|
|
84
|
-
}
|
|
85
|
-
const modernjsConfig = useConfigContext();
|
|
86
78
|
const appContext = useAppContext();
|
|
87
|
-
const enableSSR = Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
88
79
|
const name = internalOptions.csrConfig.name;
|
|
89
80
|
const internalDirectory = appContext.internalDirectory.replace(import_constant2.META_NAME, metaName || import_constant2.META_NAME);
|
|
90
81
|
const transformRuntimeFn = transformRuntimeOptions || _transformRuntimeOptions;
|
|
91
|
-
const
|
|
92
|
-
(_modernjsConfig_server4 = modernjsConfig.server) === null || _modernjsConfig_server4 === void 0 ? void 0 : _modernjsConfig_server4.baseUrl
|
|
93
|
-
] : [];
|
|
82
|
+
const partialSSRRemotes = [];
|
|
94
83
|
const entries = /* @__PURE__ */ new Set();
|
|
95
84
|
let remotePathMap = {};
|
|
96
85
|
const ssrByRouteIdsMap = {};
|
|
@@ -147,6 +136,9 @@ const moduleFederationDataLoaderPlugin = (enable, internalOptions, userConfig) =
|
|
|
147
136
|
const newId = `${remoteIdPrefix}${isLayout ? "layout" : "page"}`;
|
|
148
137
|
ssrByRouteIdsMap[originalId] = newId;
|
|
149
138
|
route.id = newId;
|
|
139
|
+
if (!partialSSRRemotes.includes(remoteName)) {
|
|
140
|
+
partialSSRRemotes.push(remoteName);
|
|
141
|
+
}
|
|
150
142
|
} else {
|
|
151
143
|
route.id = `${prefix}${route.id}`;
|
|
152
144
|
}
|
|
@@ -164,10 +156,9 @@ const moduleFederationDataLoaderPlugin = (enable, internalOptions, userConfig) =
|
|
|
164
156
|
return {
|
|
165
157
|
tools: {
|
|
166
158
|
// bundlerChain can not keep target order
|
|
167
|
-
rspack(
|
|
159
|
+
rspack(_config, { isServer }) {
|
|
168
160
|
(0, import_patchMFConfig.patchMFConfig)({
|
|
169
161
|
mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
|
|
170
|
-
baseName,
|
|
171
162
|
metaName,
|
|
172
163
|
isServer,
|
|
173
164
|
internalDirectory,
|
|
@@ -175,10 +166,9 @@ const moduleFederationDataLoaderPlugin = (enable, internalOptions, userConfig) =
|
|
|
175
166
|
});
|
|
176
167
|
},
|
|
177
168
|
// bundlerChain can not keep target order
|
|
178
|
-
webpack(
|
|
169
|
+
webpack(_config, { isServer }) {
|
|
179
170
|
(0, import_patchMFConfig.patchMFConfig)({
|
|
180
171
|
mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
|
|
181
|
-
baseName,
|
|
182
172
|
metaName,
|
|
183
173
|
isServer,
|
|
184
174
|
internalDirectory,
|
|
@@ -200,6 +190,5 @@ var plugin_default = moduleFederationDataLoaderPlugin;
|
|
|
200
190
|
// Annotate the CommonJS export names for ESM import in node:
|
|
201
191
|
0 && (module.exports = {
|
|
202
192
|
generateRoutes,
|
|
203
|
-
generateSlimRoutes,
|
|
204
193
|
moduleFederationDataLoaderPlugin
|
|
205
194
|
});
|
package/dist/cjs/cli/index.js
CHANGED
|
@@ -82,8 +82,7 @@ const moduleFederationPlugin = (userConfig = {}) => {
|
|
|
82
82
|
(0, import_configPlugin.moduleFederationConfigPlugin)(internalModernPluginOptions),
|
|
83
83
|
(0, import_ssrPlugin.moduleFederationSSRPlugin)(internalModernPluginOptions),
|
|
84
84
|
(0, import_plugin.moduleFederationDataLoaderPlugin)(Boolean(userConfig.dataLoader), internalModernPluginOptions, {
|
|
85
|
-
|
|
86
|
-
...userConfig.dataLoader
|
|
85
|
+
...typeof userConfig.dataLoader === "boolean" ? {} : userConfig.dataLoader
|
|
87
86
|
})
|
|
88
87
|
]
|
|
89
88
|
};
|
|
@@ -58,7 +58,7 @@ var dataLoaderPlugin_default = ({ runtimeOptions, partialSSRRemotes, ssrByRouteI
|
|
|
58
58
|
remotePath: (0, import_sdk.isBrowserEnv)() ? `${import_constant.DEFAULT_ENTRY}/${import_constant.MF_ROUTES}` : `${import_constant.DEFAULT_ENTRY}/${import_constant.MODERN_JS_ROUTE_SERVER_LOADER}`
|
|
59
59
|
});
|
|
60
60
|
const originalSSRByRouteIds = (_api_useConfigContext_server = api.useConfigContext().server) === null || _api_useConfigContext_server === void 0 ? void 0 : _api_useConfigContext_server.ssrByRouteIds;
|
|
61
|
-
if (originalSSRByRouteIds && partialSSRRemotes) {
|
|
61
|
+
if (originalSSRByRouteIds && partialSSRRemotes.length) {
|
|
62
62
|
const remoteSSRByRouteIds = (0, import_fetchRemoteFullRoutesMap.getSSRByRouteIds)(partialSSRRemotes, remoteFullRoutesMap) || [];
|
|
63
63
|
const ssrByRouteIds = /* @__PURE__ */ new Set([
|
|
64
64
|
...originalSSRByRouteIds,
|
|
@@ -39,9 +39,6 @@ async function fetchRemoteFullRoutesMap(options) {
|
|
|
39
39
|
return remoteRoutesMap;
|
|
40
40
|
}
|
|
41
41
|
function getSSRByRouteIds(partialSSRRemotes, remoteRoutesMap) {
|
|
42
|
-
if (!partialSSRRemotes.length) {
|
|
43
|
-
return void 0;
|
|
44
|
-
}
|
|
45
42
|
const remoteProviderRouteIds = /* @__PURE__ */ new Set();
|
|
46
43
|
const collectIds = (route) => {
|
|
47
44
|
remoteProviderRouteIds.add(route.id);
|
|
@@ -51,8 +48,12 @@ function getSSRByRouteIds(partialSSRRemotes, remoteRoutesMap) {
|
|
|
51
48
|
});
|
|
52
49
|
}
|
|
53
50
|
};
|
|
54
|
-
Object.
|
|
55
|
-
const
|
|
51
|
+
Object.entries(remoteRoutesMap).forEach((item) => {
|
|
52
|
+
const [remoteName, routesObj] = item;
|
|
53
|
+
if (!partialSSRRemotes.includes(remoteName)) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const { routes } = routesObj;
|
|
56
57
|
routes.forEach((route) => {
|
|
57
58
|
collectIds(route);
|
|
58
59
|
});
|
|
@@ -10,7 +10,7 @@ function findTargetKeyNode(nodeProperties, key) {
|
|
|
10
10
|
});
|
|
11
11
|
}
|
|
12
12
|
function generateRoutes(param) {
|
|
13
|
-
var sourceCode = param.sourceCode, filePath = param.filePath
|
|
13
|
+
var sourceCode = param.sourceCode, filePath = param.filePath;
|
|
14
14
|
var ast = babelParser.parse(sourceCode, {
|
|
15
15
|
sourceType: "module"
|
|
16
16
|
});
|
|
@@ -100,9 +100,8 @@ function generateRoutes(param) {
|
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
});
|
|
103
|
-
var
|
|
104
|
-
|
|
105
|
-
fs.writeFileSync(filePath, finalCode);
|
|
103
|
+
var code = generate(ast).code;
|
|
104
|
+
fs.writeFileSync(filePath, code);
|
|
106
105
|
}
|
|
107
106
|
export {
|
|
108
107
|
generateRoutes
|
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
import { generateRoutes } from "./generateRoutes";
|
|
2
|
-
import { generateSlimRoutes } from "./generateSlimRoutes";
|
|
3
|
-
import { generateSerializableRoutes } from "./generateSerializableRoutes";
|
|
4
|
-
import { generateSelfRoutes } from "./generateSelfRoutes";
|
|
5
2
|
export {
|
|
6
|
-
generateRoutes
|
|
7
|
-
generateSelfRoutes,
|
|
8
|
-
generateSerializableRoutes,
|
|
9
|
-
generateSlimRoutes
|
|
3
|
+
generateRoutes
|
|
10
4
|
};
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { fs } from "@modern-js/utils";
|
|
4
|
-
import { transformName2Prefix } from "../../runtime/utils";
|
|
5
4
|
import { MODERN_JS_ROUTE_SERVER_LOADER } from "../../constant";
|
|
6
5
|
import { MF_ROUTES, MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME } from "../../constant";
|
|
7
6
|
import { generateRoutes } from "./ast";
|
|
8
7
|
function generateExtraExposeFiles(options) {
|
|
9
|
-
var internalDirectory = options.internalDirectory, mfConfig = options.mfConfig, isServer = options.isServer,
|
|
8
|
+
var internalDirectory = options.internalDirectory, mfConfig = options.mfConfig, isServer = options.isServer, entries = options.entries;
|
|
10
9
|
var entryMap = {};
|
|
11
10
|
var outputDir = path.resolve(process.cwd(), "node_modules/.federation/data-loader");
|
|
12
11
|
fs.ensureDirSync(outputDir);
|
|
@@ -26,9 +25,7 @@ function generateExtraExposeFiles(options) {
|
|
|
26
25
|
var outputFullRoutesPath = path.resolve(outputEntryDir, addSuffix(MF_ROUTES));
|
|
27
26
|
generateRoutes({
|
|
28
27
|
sourceCode: routesFileContent,
|
|
29
|
-
filePath: outputFullRoutesPath
|
|
30
|
-
prefix: transformName2Prefix(mfConfig.name),
|
|
31
|
-
baseName
|
|
28
|
+
filePath: outputFullRoutesPath
|
|
32
29
|
});
|
|
33
30
|
var routeServerLoaderPath = path.resolve(sourceDir, "".concat(MODERN_JS_ROUTE_SERVER_LOADER, ".js"));
|
|
34
31
|
var outputRouteServerLoaderPath = path.resolve(outputEntryDir, "".concat(MODERN_JS_ROUTE_SERVER_LOADER, ".js"));
|
|
@@ -36,9 +33,7 @@ function generateExtraExposeFiles(options) {
|
|
|
36
33
|
var routeServerLoaderContent = fs.readFileSync(routeServerLoaderPath, "utf-8");
|
|
37
34
|
generateRoutes({
|
|
38
35
|
sourceCode: routeServerLoaderContent,
|
|
39
|
-
filePath: outputRouteServerLoaderPath
|
|
40
|
-
prefix: transformName2Prefix(mfConfig.name),
|
|
41
|
-
baseName
|
|
36
|
+
filePath: outputRouteServerLoaderPath
|
|
42
37
|
});
|
|
43
38
|
}
|
|
44
39
|
entryMap[entry] = {
|
|
@@ -2,9 +2,9 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
|
2
2
|
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
3
3
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
4
|
import { transformName2Prefix } from "../../runtime/utils";
|
|
5
|
-
import { DEFAULT_ENTRY
|
|
5
|
+
import { DEFAULT_ENTRY } from "../../constant";
|
|
6
6
|
import { META_NAME } from "../../constant";
|
|
7
|
-
import { generateRoutes
|
|
7
|
+
import { generateRoutes } from "./ast";
|
|
8
8
|
import { generateRouteFile } from "./generateRouteFile";
|
|
9
9
|
import { patchMFConfig } from "./patchMFConfig";
|
|
10
10
|
import path from "path";
|
|
@@ -36,29 +36,22 @@ var moduleFederationDataLoaderPlugin = function(enable, internalOptions, userCon
|
|
|
36
36
|
],
|
|
37
37
|
setup: function() {
|
|
38
38
|
var _ref = _async_to_generator(function(param) {
|
|
39
|
-
var
|
|
39
|
+
var useAppContext, _userConfig_metaName, metaName, _userConfig_serverPlugin, serverPlugin, transformRuntimeOptions, appContext, name, internalDirectory, transformRuntimeFn, partialSSRRemotes, entries, remotePathMap, ssrByRouteIdsMap, serverPluginOptions, csrConfig, _ref2, scanEntries, scanRemotePathMap;
|
|
40
40
|
return _ts_generator(this, function(_state) {
|
|
41
41
|
switch (_state.label) {
|
|
42
42
|
case 0:
|
|
43
|
-
|
|
43
|
+
useAppContext = param.useAppContext;
|
|
44
44
|
if (!enable) {
|
|
45
45
|
return [
|
|
46
46
|
2
|
|
47
47
|
];
|
|
48
48
|
}
|
|
49
|
-
|
|
50
|
-
if (!baseName) {
|
|
51
|
-
throw new Error("".concat(PLUGIN_IDENTIFIER, " 'baseName' is required if you enable 'dataLoader'!"));
|
|
52
|
-
}
|
|
53
|
-
modernjsConfig = useConfigContext();
|
|
49
|
+
_userConfig_metaName = userConfig.metaName, metaName = _userConfig_metaName === void 0 ? META_NAME : _userConfig_metaName, _userConfig_serverPlugin = userConfig.serverPlugin, serverPlugin = _userConfig_serverPlugin === void 0 ? "@module-federation/modern-js/data-loader-server" : _userConfig_serverPlugin, transformRuntimeOptions = userConfig.transformRuntimeOptions;
|
|
54
50
|
appContext = useAppContext();
|
|
55
|
-
enableSSR = Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
56
51
|
name = internalOptions.csrConfig.name;
|
|
57
52
|
internalDirectory = appContext.internalDirectory.replace(META_NAME, metaName || META_NAME);
|
|
58
53
|
transformRuntimeFn = transformRuntimeOptions || _transformRuntimeOptions;
|
|
59
|
-
|
|
60
|
-
(_modernjsConfig_server4 = modernjsConfig.server) === null || _modernjsConfig_server4 === void 0 ? void 0 : _modernjsConfig_server4.baseUrl
|
|
61
|
-
] : [];
|
|
54
|
+
partialSSRRemotes = [];
|
|
62
55
|
entries = /* @__PURE__ */ new Set();
|
|
63
56
|
remotePathMap = {};
|
|
64
57
|
ssrByRouteIdsMap = {};
|
|
@@ -138,6 +131,9 @@ var moduleFederationDataLoaderPlugin = function(enable, internalOptions, userCon
|
|
|
138
131
|
var newId = "".concat(remoteIdPrefix).concat(isLayout ? "layout" : "page");
|
|
139
132
|
ssrByRouteIdsMap[originalId] = newId;
|
|
140
133
|
route.id = newId;
|
|
134
|
+
if (!partialSSRRemotes.includes(remoteName)) {
|
|
135
|
+
partialSSRRemotes.push(remoteName);
|
|
136
|
+
}
|
|
141
137
|
} else {
|
|
142
138
|
route.id = "".concat(prefix).concat(route.id);
|
|
143
139
|
}
|
|
@@ -163,11 +159,10 @@ var moduleFederationDataLoaderPlugin = function(enable, internalOptions, userCon
|
|
|
163
159
|
{
|
|
164
160
|
tools: {
|
|
165
161
|
// bundlerChain can not keep target order
|
|
166
|
-
rspack: function rspack(
|
|
162
|
+
rspack: function rspack(_config, param2) {
|
|
167
163
|
var isServer = param2.isServer;
|
|
168
164
|
patchMFConfig({
|
|
169
165
|
mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
|
|
170
|
-
baseName,
|
|
171
166
|
metaName,
|
|
172
167
|
isServer,
|
|
173
168
|
internalDirectory,
|
|
@@ -175,11 +170,10 @@ var moduleFederationDataLoaderPlugin = function(enable, internalOptions, userCon
|
|
|
175
170
|
});
|
|
176
171
|
},
|
|
177
172
|
// bundlerChain can not keep target order
|
|
178
|
-
webpack: function webpack(
|
|
173
|
+
webpack: function webpack(_config, param2) {
|
|
179
174
|
var isServer = param2.isServer;
|
|
180
175
|
patchMFConfig({
|
|
181
176
|
mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
|
|
182
|
-
baseName,
|
|
183
177
|
metaName,
|
|
184
178
|
isServer,
|
|
185
179
|
internalDirectory,
|
|
@@ -211,6 +205,5 @@ var plugin_default = moduleFederationDataLoaderPlugin;
|
|
|
211
205
|
export {
|
|
212
206
|
plugin_default as default,
|
|
213
207
|
generateRoutes,
|
|
214
|
-
generateSlimRoutes,
|
|
215
208
|
moduleFederationDataLoaderPlugin
|
|
216
209
|
};
|
package/dist/esm/cli/index.js
CHANGED
|
@@ -82,9 +82,7 @@ var moduleFederationPlugin = function() {
|
|
|
82
82
|
usePlugins: [
|
|
83
83
|
moduleFederationConfigPlugin(internalModernPluginOptions),
|
|
84
84
|
moduleFederationSSRPlugin(internalModernPluginOptions),
|
|
85
|
-
moduleFederationDataLoaderPlugin(Boolean(userConfig.dataLoader), internalModernPluginOptions, _object_spread({
|
|
86
|
-
baseName: ""
|
|
87
|
-
}, userConfig.dataLoader))
|
|
85
|
+
moduleFederationDataLoaderPlugin(Boolean(userConfig.dataLoader), internalModernPluginOptions, _object_spread({}, typeof userConfig.dataLoader === "boolean" ? {} : userConfig.dataLoader))
|
|
88
86
|
]
|
|
89
87
|
};
|
|
90
88
|
};
|
|
@@ -62,7 +62,7 @@ function dataLoaderPlugin_default(param) {
|
|
|
62
62
|
case 3:
|
|
63
63
|
remoteFullRoutesMap = _state.sent();
|
|
64
64
|
originalSSRByRouteIds = (_api_useConfigContext_server = api.useConfigContext().server) === null || _api_useConfigContext_server === void 0 ? void 0 : _api_useConfigContext_server.ssrByRouteIds;
|
|
65
|
-
if (originalSSRByRouteIds && partialSSRRemotes) {
|
|
65
|
+
if (originalSSRByRouteIds && partialSSRRemotes.length) {
|
|
66
66
|
remoteSSRByRouteIds = getSSRByRouteIds(partialSSRRemotes, remoteFullRoutesMap) || [];
|
|
67
67
|
ssrByRouteIds = new Set(_to_consumable_array(originalSSRByRouteIds).concat(_to_consumable_array(remoteSSRByRouteIds.map(function(id) {
|
|
68
68
|
return ssrByRouteIdsMap[id] || id;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
2
3
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
3
4
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
5
|
function fetchRemoteFullRoutesMap(options) {
|
|
@@ -60,9 +61,6 @@ function _fetchRemoteFullRoutesMap() {
|
|
|
60
61
|
return _fetchRemoteFullRoutesMap.apply(this, arguments);
|
|
61
62
|
}
|
|
62
63
|
function getSSRByRouteIds(partialSSRRemotes, remoteRoutesMap) {
|
|
63
|
-
if (!partialSSRRemotes.length) {
|
|
64
|
-
return void 0;
|
|
65
|
-
}
|
|
66
64
|
var remoteProviderRouteIds = /* @__PURE__ */ new Set();
|
|
67
65
|
var collectIds = function(route) {
|
|
68
66
|
remoteProviderRouteIds.add(route.id);
|
|
@@ -72,8 +70,12 @@ function getSSRByRouteIds(partialSSRRemotes, remoteRoutesMap) {
|
|
|
72
70
|
});
|
|
73
71
|
}
|
|
74
72
|
};
|
|
75
|
-
Object.
|
|
76
|
-
var
|
|
73
|
+
Object.entries(remoteRoutesMap).forEach(function(item) {
|
|
74
|
+
var _item = _sliced_to_array(item, 2), remoteName = _item[0], routesObj = _item[1];
|
|
75
|
+
if (!partialSSRRemotes.includes(remoteName)) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
var routes = routesObj.routes;
|
|
77
79
|
routes.forEach(function(route) {
|
|
78
80
|
collectIds(route);
|
|
79
81
|
});
|
|
@@ -6,7 +6,7 @@ import * as t from "@babel/types";
|
|
|
6
6
|
function findTargetKeyNode(nodeProperties, key) {
|
|
7
7
|
return nodeProperties.find((p) => t.isObjectProperty(p) && t.isStringLiteral(p.key) && p.key.value === key);
|
|
8
8
|
}
|
|
9
|
-
function generateRoutes({ sourceCode, filePath
|
|
9
|
+
function generateRoutes({ sourceCode, filePath }) {
|
|
10
10
|
const ast = babelParser.parse(sourceCode, {
|
|
11
11
|
sourceType: "module"
|
|
12
12
|
});
|
|
@@ -99,9 +99,8 @@ function generateRoutes({ sourceCode, filePath, prefix, baseName }) {
|
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
});
|
|
102
|
-
const { code
|
|
103
|
-
|
|
104
|
-
fs.writeFileSync(filePath, finalCode);
|
|
102
|
+
const { code } = generate(ast);
|
|
103
|
+
fs.writeFileSync(filePath, code);
|
|
105
104
|
}
|
|
106
105
|
export {
|
|
107
106
|
generateRoutes
|
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
import { generateRoutes } from "./generateRoutes";
|
|
2
|
-
import { generateSlimRoutes } from "./generateSlimRoutes";
|
|
3
|
-
import { generateSerializableRoutes } from "./generateSerializableRoutes";
|
|
4
|
-
import { generateSelfRoutes } from "./generateSelfRoutes";
|
|
5
2
|
export {
|
|
6
|
-
generateRoutes
|
|
7
|
-
generateSelfRoutes,
|
|
8
|
-
generateSerializableRoutes,
|
|
9
|
-
generateSlimRoutes
|
|
3
|
+
generateRoutes
|
|
10
4
|
};
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { fs } from "@modern-js/utils";
|
|
3
|
-
import { transformName2Prefix } from "../../runtime/utils";
|
|
4
3
|
import { MODERN_JS_ROUTE_SERVER_LOADER } from "../../constant";
|
|
5
4
|
import { MF_ROUTES, MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME } from "../../constant";
|
|
6
5
|
import { generateRoutes } from "./ast";
|
|
7
6
|
function generateExtraExposeFiles(options) {
|
|
8
|
-
const { internalDirectory, mfConfig, isServer,
|
|
7
|
+
const { internalDirectory, mfConfig, isServer, entries } = options;
|
|
9
8
|
const entryMap = {};
|
|
10
9
|
const outputDir = path.resolve(process.cwd(), "node_modules/.federation/data-loader");
|
|
11
10
|
fs.ensureDirSync(outputDir);
|
|
@@ -24,9 +23,7 @@ function generateExtraExposeFiles(options) {
|
|
|
24
23
|
const outputFullRoutesPath = path.resolve(outputEntryDir, addSuffix(MF_ROUTES));
|
|
25
24
|
generateRoutes({
|
|
26
25
|
sourceCode: routesFileContent,
|
|
27
|
-
filePath: outputFullRoutesPath
|
|
28
|
-
prefix: transformName2Prefix(mfConfig.name),
|
|
29
|
-
baseName
|
|
26
|
+
filePath: outputFullRoutesPath
|
|
30
27
|
});
|
|
31
28
|
const routeServerLoaderPath = path.resolve(sourceDir, `${MODERN_JS_ROUTE_SERVER_LOADER}.js`);
|
|
32
29
|
const outputRouteServerLoaderPath = path.resolve(outputEntryDir, `${MODERN_JS_ROUTE_SERVER_LOADER}.js`);
|
|
@@ -34,9 +31,7 @@ function generateExtraExposeFiles(options) {
|
|
|
34
31
|
const routeServerLoaderContent = fs.readFileSync(routeServerLoaderPath, "utf-8");
|
|
35
32
|
generateRoutes({
|
|
36
33
|
sourceCode: routeServerLoaderContent,
|
|
37
|
-
filePath: outputRouteServerLoaderPath
|
|
38
|
-
prefix: transformName2Prefix(mfConfig.name),
|
|
39
|
-
baseName
|
|
34
|
+
filePath: outputRouteServerLoaderPath
|
|
40
35
|
});
|
|
41
36
|
}
|
|
42
37
|
entryMap[entry] = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { transformName2Prefix } from "../../runtime/utils";
|
|
2
|
-
import { DEFAULT_ENTRY
|
|
2
|
+
import { DEFAULT_ENTRY } from "../../constant";
|
|
3
3
|
import { META_NAME } from "../../constant";
|
|
4
|
-
import { generateRoutes
|
|
4
|
+
import { generateRoutes } from "./ast";
|
|
5
5
|
import { generateRouteFile } from "./generateRouteFile";
|
|
6
6
|
import { patchMFConfig } from "./patchMFConfig";
|
|
7
7
|
import path from "path";
|
|
@@ -30,31 +30,21 @@ const moduleFederationDataLoaderPlugin = (enable, internalOptions, userConfig) =
|
|
|
30
30
|
"@modern-js/plugin-router",
|
|
31
31
|
"@modern-js/plugin-module-federation"
|
|
32
32
|
],
|
|
33
|
-
setup: async ({
|
|
34
|
-
var _modernjsConfig_server, _modernjsConfig_server1, _modernjsConfig_server2, _modernjsConfig_server3, _modernjsConfig_server4;
|
|
33
|
+
setup: async ({ useAppContext }) => {
|
|
35
34
|
if (!enable) {
|
|
36
35
|
return;
|
|
37
36
|
}
|
|
38
37
|
const {
|
|
39
|
-
baseName,
|
|
40
|
-
partialSSRRemotes = [],
|
|
41
38
|
// patchMFConfig,
|
|
42
39
|
metaName = META_NAME,
|
|
43
40
|
serverPlugin = "@module-federation/modern-js/data-loader-server",
|
|
44
41
|
transformRuntimeOptions
|
|
45
42
|
} = userConfig;
|
|
46
|
-
if (!baseName) {
|
|
47
|
-
throw new Error(`${PLUGIN_IDENTIFIER} 'baseName' is required if you enable 'dataLoader'!`);
|
|
48
|
-
}
|
|
49
|
-
const modernjsConfig = useConfigContext();
|
|
50
43
|
const appContext = useAppContext();
|
|
51
|
-
const enableSSR = Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
52
44
|
const name = internalOptions.csrConfig.name;
|
|
53
45
|
const internalDirectory = appContext.internalDirectory.replace(META_NAME, metaName || META_NAME);
|
|
54
46
|
const transformRuntimeFn = transformRuntimeOptions || _transformRuntimeOptions;
|
|
55
|
-
const
|
|
56
|
-
(_modernjsConfig_server4 = modernjsConfig.server) === null || _modernjsConfig_server4 === void 0 ? void 0 : _modernjsConfig_server4.baseUrl
|
|
57
|
-
] : [];
|
|
47
|
+
const partialSSRRemotes = [];
|
|
58
48
|
const entries = /* @__PURE__ */ new Set();
|
|
59
49
|
let remotePathMap = {};
|
|
60
50
|
const ssrByRouteIdsMap = {};
|
|
@@ -111,6 +101,9 @@ const moduleFederationDataLoaderPlugin = (enable, internalOptions, userConfig) =
|
|
|
111
101
|
const newId = `${remoteIdPrefix}${isLayout ? "layout" : "page"}`;
|
|
112
102
|
ssrByRouteIdsMap[originalId] = newId;
|
|
113
103
|
route.id = newId;
|
|
104
|
+
if (!partialSSRRemotes.includes(remoteName)) {
|
|
105
|
+
partialSSRRemotes.push(remoteName);
|
|
106
|
+
}
|
|
114
107
|
} else {
|
|
115
108
|
route.id = `${prefix}${route.id}`;
|
|
116
109
|
}
|
|
@@ -128,10 +121,9 @@ const moduleFederationDataLoaderPlugin = (enable, internalOptions, userConfig) =
|
|
|
128
121
|
return {
|
|
129
122
|
tools: {
|
|
130
123
|
// bundlerChain can not keep target order
|
|
131
|
-
rspack(
|
|
124
|
+
rspack(_config, { isServer }) {
|
|
132
125
|
patchMFConfig({
|
|
133
126
|
mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
|
|
134
|
-
baseName,
|
|
135
127
|
metaName,
|
|
136
128
|
isServer,
|
|
137
129
|
internalDirectory,
|
|
@@ -139,10 +131,9 @@ const moduleFederationDataLoaderPlugin = (enable, internalOptions, userConfig) =
|
|
|
139
131
|
});
|
|
140
132
|
},
|
|
141
133
|
// bundlerChain can not keep target order
|
|
142
|
-
webpack(
|
|
134
|
+
webpack(_config, { isServer }) {
|
|
143
135
|
patchMFConfig({
|
|
144
136
|
mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
|
|
145
|
-
baseName,
|
|
146
137
|
metaName,
|
|
147
138
|
isServer,
|
|
148
139
|
internalDirectory,
|
|
@@ -164,6 +155,5 @@ var plugin_default = moduleFederationDataLoaderPlugin;
|
|
|
164
155
|
export {
|
|
165
156
|
plugin_default as default,
|
|
166
157
|
generateRoutes,
|
|
167
|
-
generateSlimRoutes,
|
|
168
158
|
moduleFederationDataLoaderPlugin
|
|
169
159
|
};
|
|
@@ -56,8 +56,7 @@ const moduleFederationPlugin = (userConfig = {}) => {
|
|
|
56
56
|
moduleFederationConfigPlugin(internalModernPluginOptions),
|
|
57
57
|
moduleFederationSSRPlugin(internalModernPluginOptions),
|
|
58
58
|
moduleFederationDataLoaderPlugin(Boolean(userConfig.dataLoader), internalModernPluginOptions, {
|
|
59
|
-
|
|
60
|
-
...userConfig.dataLoader
|
|
59
|
+
...typeof userConfig.dataLoader === "boolean" ? {} : userConfig.dataLoader
|
|
61
60
|
})
|
|
62
61
|
]
|
|
63
62
|
};
|
|
@@ -35,7 +35,7 @@ var dataLoaderPlugin_default = ({ runtimeOptions, partialSSRRemotes, ssrByRouteI
|
|
|
35
35
|
remotePath: isBrowserEnv() ? `${DEFAULT_ENTRY}/${MF_ROUTES}` : `${DEFAULT_ENTRY}/${MODERN_JS_ROUTE_SERVER_LOADER}`
|
|
36
36
|
});
|
|
37
37
|
const originalSSRByRouteIds = (_api_useConfigContext_server = api.useConfigContext().server) === null || _api_useConfigContext_server === void 0 ? void 0 : _api_useConfigContext_server.ssrByRouteIds;
|
|
38
|
-
if (originalSSRByRouteIds && partialSSRRemotes) {
|
|
38
|
+
if (originalSSRByRouteIds && partialSSRRemotes.length) {
|
|
39
39
|
const remoteSSRByRouteIds = getSSRByRouteIds(partialSSRRemotes, remoteFullRoutesMap) || [];
|
|
40
40
|
const ssrByRouteIds = /* @__PURE__ */ new Set([
|
|
41
41
|
...originalSSRByRouteIds,
|
|
@@ -15,9 +15,6 @@ async function fetchRemoteFullRoutesMap(options) {
|
|
|
15
15
|
return remoteRoutesMap;
|
|
16
16
|
}
|
|
17
17
|
function getSSRByRouteIds(partialSSRRemotes, remoteRoutesMap) {
|
|
18
|
-
if (!partialSSRRemotes.length) {
|
|
19
|
-
return void 0;
|
|
20
|
-
}
|
|
21
18
|
const remoteProviderRouteIds = /* @__PURE__ */ new Set();
|
|
22
19
|
const collectIds = (route) => {
|
|
23
20
|
remoteProviderRouteIds.add(route.id);
|
|
@@ -27,8 +24,12 @@ function getSSRByRouteIds(partialSSRRemotes, remoteRoutesMap) {
|
|
|
27
24
|
});
|
|
28
25
|
}
|
|
29
26
|
};
|
|
30
|
-
Object.
|
|
31
|
-
const
|
|
27
|
+
Object.entries(remoteRoutesMap).forEach((item) => {
|
|
28
|
+
const [remoteName, routesObj] = item;
|
|
29
|
+
if (!partialSSRRemotes.includes(remoteName)) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const { routes } = routesObj;
|
|
32
33
|
routes.forEach((route) => {
|
|
33
34
|
collectIds(route);
|
|
34
35
|
});
|