@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.
Files changed (64) hide show
  1. package/dist/cjs/cli/index.js +5 -4
  2. package/dist/cjs/cli/routes/exportRoutePlugin.js +77 -0
  3. package/dist/cjs/cli/routes/importRoutesPlugin.js +120 -0
  4. package/dist/cjs/cli/routes/plugin.js +157 -0
  5. package/dist/cjs/cli/{dataLoader/generateRouteFile.js → routes/traverseRouteFiles.js} +12 -12
  6. package/dist/cjs/cli/{dataLoader/patchMFConfig.js → routes/utils.js} +18 -10
  7. package/dist/cjs/cli/server/{dataLoaderPlugin.js → fetchRoutePlugin.js} +7 -7
  8. package/dist/cjs/runtime/{dataLoader → routes}/plugin-inject-assets.js +3 -3
  9. package/dist/cjs/runtime/{dataLoader → routes}/plugin.js +1 -1
  10. package/dist/cjs/types/routes.js +16 -0
  11. package/dist/esm/cli/index.js +6 -4
  12. package/dist/esm/cli/routes/exportRoutePlugin.js +79 -0
  13. package/dist/esm/cli/routes/importRoutesPlugin.js +122 -0
  14. package/dist/esm/cli/{dataLoader → routes}/plugin.js +74 -149
  15. package/dist/esm/cli/{dataLoader/generateRouteFile.js → routes/traverseRouteFiles.js} +23 -18
  16. package/dist/esm/cli/{dataLoader/patchMFConfig.js → routes/utils.js} +12 -6
  17. package/dist/esm/cli/server/{dataLoaderPlugin.js → fetchRoutePlugin.js} +4 -4
  18. package/dist/esm/runtime/{dataLoader → routes}/plugin-inject-assets.js +3 -3
  19. package/dist/esm/runtime/{dataLoader → routes}/plugin.js +1 -1
  20. package/dist/esm/types/routes.js +0 -0
  21. package/dist/esm-node/cli/index.js +5 -4
  22. package/dist/esm-node/cli/routes/exportRoutePlugin.js +53 -0
  23. package/dist/esm-node/cli/routes/importRoutesPlugin.js +96 -0
  24. package/dist/esm-node/cli/routes/plugin.js +123 -0
  25. package/dist/esm-node/cli/{dataLoader/generateRouteFile.js → routes/traverseRouteFiles.js} +8 -8
  26. package/dist/esm-node/cli/{dataLoader/patchMFConfig.js → routes/utils.js} +13 -6
  27. package/dist/esm-node/cli/server/{dataLoaderPlugin.js → fetchRoutePlugin.js} +4 -4
  28. package/dist/esm-node/runtime/{dataLoader → routes}/plugin-inject-assets.js +3 -3
  29. package/dist/esm-node/runtime/{dataLoader → routes}/plugin.js +1 -1
  30. package/dist/esm-node/types/routes.js +0 -0
  31. package/dist/types/cli/routes/exportRoutePlugin.d.ts +4 -0
  32. package/dist/types/cli/routes/importRoutesPlugin.d.ts +4 -0
  33. package/dist/types/cli/routes/plugin.d.ts +4 -0
  34. package/dist/types/cli/{dataLoader/generateRouteFile.d.ts → routes/traverseRouteFiles.d.ts} +4 -3
  35. package/dist/types/cli/{dataLoader/patchMFConfig.d.ts → routes/utils.d.ts} +2 -1
  36. package/dist/types/cli/server/{dataLoaderPlugin.d.ts → fetchRoutePlugin.d.ts} +2 -2
  37. package/dist/types/types/index.d.ts +2 -8
  38. package/dist/types/types/routes.d.ts +19 -0
  39. package/package.json +32 -32
  40. package/dist/cjs/cli/dataLoader/plugin.js +0 -219
  41. package/dist/esm-node/cli/dataLoader/plugin.js +0 -184
  42. package/dist/types/cli/dataLoader/plugin.d.ts +0 -6
  43. /package/dist/cjs/cli/{dataLoader → routes}/ast/constant.js +0 -0
  44. /package/dist/cjs/cli/{dataLoader → routes}/ast/generateRoutes.js +0 -0
  45. /package/dist/cjs/cli/{dataLoader → routes}/ast/index.js +0 -0
  46. /package/dist/cjs/cli/{dataLoader → routes}/clearMFCache.js +0 -0
  47. /package/dist/cjs/runtime/{dataLoader → routes}/utils.js +0 -0
  48. /package/dist/esm/cli/{dataLoader → routes}/ast/constant.js +0 -0
  49. /package/dist/esm/cli/{dataLoader → routes}/ast/generateRoutes.js +0 -0
  50. /package/dist/esm/cli/{dataLoader → routes}/ast/index.js +0 -0
  51. /package/dist/esm/cli/{dataLoader → routes}/clearMFCache.js +0 -0
  52. /package/dist/esm/runtime/{dataLoader → routes}/utils.js +0 -0
  53. /package/dist/esm-node/cli/{dataLoader → routes}/ast/constant.js +0 -0
  54. /package/dist/esm-node/cli/{dataLoader → routes}/ast/generateRoutes.js +0 -0
  55. /package/dist/esm-node/cli/{dataLoader → routes}/ast/index.js +0 -0
  56. /package/dist/esm-node/cli/{dataLoader → routes}/clearMFCache.js +0 -0
  57. /package/dist/esm-node/runtime/{dataLoader → routes}/utils.js +0 -0
  58. /package/dist/types/cli/{dataLoader → routes}/ast/constant.d.ts +0 -0
  59. /package/dist/types/cli/{dataLoader → routes}/ast/generateRoutes.d.ts +0 -0
  60. /package/dist/types/cli/{dataLoader → routes}/ast/index.d.ts +0 -0
  61. /package/dist/types/cli/{dataLoader → routes}/clearMFCache.d.ts +0 -0
  62. /package/dist/types/runtime/{dataLoader → routes}/plugin-inject-assets.d.ts +0 -0
  63. /package/dist/types/runtime/{dataLoader → routes}/plugin.d.ts +0 -0
  64. /package/dist/types/runtime/{dataLoader → routes}/utils.d.ts +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/modern-js",
3
- "version": "0.0.0-next-20241016083243",
3
+ "version": "0.0.0-next-20241017102355",
4
4
  "files": [
5
5
  "dist/",
6
6
  "types.d.ts",
@@ -23,22 +23,22 @@
23
23
  "types": "./dist/types/ssr-runtime/index.d.ts",
24
24
  "default": "./dist/esm/ssr-runtime/index.js"
25
25
  },
26
- "./data-loader": {
27
- "types": "./dist/types/runtime/dataLoader/plugin.d.ts",
28
- "default": "./dist/esm/runtime/dataLoader/plugin.js"
26
+ "./routes": {
27
+ "types": "./dist/types/runtime/routes/plugin.d.ts",
28
+ "default": "./dist/esm/runtime/routes/plugin.js"
29
29
  },
30
- "./data-loader-inject-assets": {
31
- "types": "./dist/types/runtime/dataLoader/plugin-inject-assets.d.ts",
32
- "default": "./dist/esm/runtime/dataLoader/plugin-inject-assets.js"
30
+ "./routes-inject-assets": {
31
+ "types": "./dist/types/runtime/routes/plugin-inject-assets.d.ts",
32
+ "default": "./dist/esm/runtime/routes/plugin-inject-assets.js"
33
33
  },
34
- "./data-loader-server": {
35
- "types": "./dist/types/cli/server/dataLoaderPlugin.d.ts",
36
- "default": "./dist/cjs/cli/server/dataLoaderPlugin.js"
34
+ "./fetch-router-server-plugin": {
35
+ "types": "./dist/types/cli/server/fetchRoutePlugin.d.ts",
36
+ "default": "./dist/cjs/cli/server/fetchRoutePlugin.js"
37
37
  },
38
- "./data-loader-plugin": {
39
- "import": "./dist/esm/cli/dataLoader/plugin.js",
40
- "require": "./dist/cjs/cli/dataLoader/plugin.js",
41
- "types": "./dist/types/cli/dataLoader/plugin.d.ts"
38
+ "./routes-plugin": {
39
+ "import": "./dist/esm/cli/routes/plugin.js",
40
+ "require": "./dist/cjs/cli/routes/plugin.js",
41
+ "types": "./dist/types/cli/routes/plugin.d.ts"
42
42
  },
43
43
  "./config-plugin": {
44
44
  "import": "./dist/esm/cli/configPlugin.js",
@@ -65,17 +65,17 @@
65
65
  "ssr-plugin": [
66
66
  "./dist/types/cli/ssrPlugin.d.ts"
67
67
  ],
68
- "data-loader-plugin": [
69
- "./dist/types/cli/dataLoader/plugin.d.ts"
68
+ "routes-plugin": [
69
+ "./dist/types/cli/routes/plugin.d.ts"
70
70
  ],
71
- "data-loader": [
71
+ "routes": [
72
72
  "./dist/types/runtime/dataLoader/plugin.d.ts"
73
73
  ],
74
- "data-loader-inject-assets": [
74
+ "routes-inject-assets": [
75
75
  "./dist/types/runtime/dataLoader/plugin-inject-assets.d.ts"
76
76
  ],
77
- "data-loader-server": [
78
- "./dist/types/cli/server/dataLoaderPlugin.d.ts"
77
+ "fetch-router-server-plugin": [
78
+ "./dist/types/cli/server/fetchRoutePlugin.d.ts"
79
79
  ]
80
80
  }
81
81
  },
@@ -84,8 +84,8 @@
84
84
  "author": "hanric <hanric.zhang@gmail.com>",
85
85
  "license": "MIT",
86
86
  "dependencies": {
87
- "@modern-js/node-bundle-require": "2.60.3",
88
- "@modern-js/utils": "2.60.3",
87
+ "@modern-js/node-bundle-require": "2.60.2",
88
+ "@modern-js/utils": "2.60.2",
89
89
  "@swc/helpers": "0.5.12",
90
90
  "hoist-non-react-statics": "3.3.2",
91
91
  "node-fetch": "~3.3.0",
@@ -94,21 +94,21 @@
94
94
  "@babel/parser": "7.25.3",
95
95
  "@babel/traverse": "7.25.3",
96
96
  "@babel/types": "7.25.2",
97
- "@module-federation/enhanced": "0.0.0-next-20241016083243",
98
- "@module-federation/node": "0.0.0-next-20241016083243",
99
- "@module-federation/sdk": "0.0.0-next-20241016083243"
97
+ "@module-federation/enhanced": "0.0.0-next-20241017102355",
98
+ "@module-federation/node": "0.0.0-next-20241017102355",
99
+ "@module-federation/sdk": "0.0.0-next-20241017102355"
100
100
  },
101
101
  "devDependencies": {
102
- "@modern-js/app-tools": "2.60.3",
103
- "@modern-js/core": "2.60.3",
104
- "@modern-js/module-tools": "2.60.3",
105
- "@modern-js/runtime": "2.60.3",
106
- "@modern-js/tsconfig": "2.60.3",
102
+ "@modern-js/app-tools": "2.60.2",
103
+ "@modern-js/core": "2.60.2",
104
+ "@modern-js/module-tools": "2.60.2",
105
+ "@modern-js/runtime": "2.60.2",
106
+ "@modern-js/tsconfig": "2.60.2",
107
107
  "@types/hoist-non-react-statics": "3.3.5",
108
108
  "@types/babel__traverse": "7.20.6",
109
109
  "@types/babel__generator": "7.6.8",
110
- "@modern-js/server-core": "2.60.3",
111
- "@module-federation/manifest": "0.0.0-next-20241016083243"
110
+ "@modern-js/server-core": "2.60.2",
111
+ "@module-federation/manifest": "0.0.0-next-20241017102355"
112
112
  },
113
113
  "peerDependencies": {
114
114
  "@modern-js/runtime": "^2.60.2",
@@ -1,219 +0,0 @@
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
- generateRoutes: () => import_ast.generateRoutes,
33
- moduleFederationDataLoaderPlugin: () => moduleFederationDataLoaderPlugin
34
- });
35
- module.exports = __toCommonJS(plugin_exports);
36
- var import_utils = require("@modern-js/utils");
37
- var import_utils2 = require("../../runtime/dataLoader/utils");
38
- var import_constant = require("../../constant");
39
- var import_constant2 = require("../../constant");
40
- var import_ast = require("./ast");
41
- var import_generateRouteFile = require("./generateRouteFile");
42
- var import_patchMFConfig = require("./patchMFConfig");
43
- var import_clearMFCache = require("./clearMFCache");
44
- var import_path = __toESM(require("path"));
45
- function _transformRuntimeOptions(buildOptions) {
46
- const remotes = buildOptions.remotes || {};
47
- const runtimeRemotes = Object.entries(remotes).map((remote) => {
48
- const [alias, nameAndEntry] = remote;
49
- const [name, entry] = nameAndEntry.split("@");
50
- return {
51
- name,
52
- entry,
53
- alias
54
- };
55
- });
56
- return {
57
- name: buildOptions.name,
58
- remotes: runtimeRemotes
59
- };
60
- }
61
- const moduleFederationDataLoaderPlugin = (enable, internalOptions, userConfig) => ({
62
- name: "@modern-js/plugin-module-federation-data-loader",
63
- pre: [
64
- "@modern-js/plugin-module-federation-config"
65
- ],
66
- post: [
67
- "@modern-js/plugin-router",
68
- "@modern-js/plugin-module-federation"
69
- ],
70
- setup: async ({ useAppContext }) => {
71
- if (!enable) {
72
- return;
73
- }
74
- const { serverPlugin = "@module-federation/modern-js/data-loader-server", transformRuntimeOptions } = userConfig;
75
- const appContext = useAppContext();
76
- const name = internalOptions.csrConfig.name;
77
- const { metaName = import_constant2.META_NAME } = internalOptions;
78
- const internalDirectory = appContext.internalDirectory.replace(import_constant2.META_NAME, metaName || import_constant2.META_NAME);
79
- const transformRuntimeFn = transformRuntimeOptions || _transformRuntimeOptions;
80
- const entries = /* @__PURE__ */ new Set();
81
- let remotePathMap = {};
82
- const ssrByRouteIdsMap = {};
83
- const csrConfig = internalOptions.csrConfig;
84
- if (typeof csrConfig.remotes === "object" && Object.keys(csrConfig.remotes).length) {
85
- const { entries: scanEntries, remotePathMap: scanRemotePathMap } = await (0, import_generateRouteFile.generateRouteFile)({
86
- appDirectory: appContext.appDirectory
87
- });
88
- scanEntries.forEach((e) => entries.add(e));
89
- remotePathMap = scanRemotePathMap;
90
- } else {
91
- entries.add(import_constant.DEFAULT_ENTRY);
92
- }
93
- const dataLoaderRemotes = [
94
- ...new Set(Object.values(remotePathMap).map((i) => i.name))
95
- ];
96
- const serverPluginOptions = {
97
- runtimeOptions: transformRuntimeFn(internalOptions.csrConfig),
98
- dataLoaderRemotes,
99
- ssrByRouteIdsMap
100
- };
101
- const hasDataLoaderRemotes = () => Boolean(serverPluginOptions.dataLoaderRemotes.length);
102
- return {
103
- _internalRuntimePlugins: ({ entrypoint, plugins }) => {
104
- if (!hasDataLoaderRemotes()) {
105
- return {
106
- entrypoint,
107
- plugins
108
- };
109
- }
110
- plugins.push({
111
- name: "ssrDataLoader",
112
- path: "@module-federation/modern-js/data-loader",
113
- config: {
114
- metaName,
115
- dataLoaderRemotes
116
- }
117
- });
118
- plugins.push({
119
- name: "ssrDataLoaderInjectAssets",
120
- path: "@module-federation/modern-js/data-loader-inject-assets",
121
- config: {
122
- metaName,
123
- dataLoaderRemotes
124
- }
125
- });
126
- return {
127
- entrypoint,
128
- plugins
129
- };
130
- },
131
- _internalServerPlugins({ plugins }) {
132
- if (!hasDataLoaderRemotes()) {
133
- return {
134
- plugins
135
- };
136
- }
137
- plugins.push({
138
- name: serverPlugin,
139
- options: serverPluginOptions
140
- });
141
- return {
142
- plugins
143
- };
144
- },
145
- async modifyFileSystemRoutes(options) {
146
- const { routes, entrypoint } = options;
147
- const { entryName } = entrypoint;
148
- const prefix = (0, import_utils2.transformName2Prefix)(internalOptions.csrConfig.name);
149
- const modifyRouteIds = async (route, pathName) => {
150
- const currentPathName = route.path ? import_path.default.join("/", pathName, route.path) : pathName;
151
- if (route.id) {
152
- const originalId = route.id;
153
- route.originalId = originalId;
154
- const remoteInfo = remotePathMap[currentPathName];
155
- if (remoteInfo) {
156
- const { path: path2, name: name2 } = remoteInfo;
157
- const remoteIdPrefix = (0, import_utils2.transformName2Prefix)(name2);
158
- const isLayout = Boolean(route.children);
159
- const newId = `${remoteIdPrefix}${isLayout ? "layout" : "page"}`;
160
- ssrByRouteIdsMap[originalId] = newId;
161
- const content = import_utils.fs.readFileSync(path2, "utf-8");
162
- await import_utils.fs.writeFile(path2, content.replace(import_constant.ROUTE_ID, originalId));
163
- route.id = newId;
164
- } else {
165
- route.id = `${prefix}${route.id}`;
166
- }
167
- route.children && await Promise.all(route.children.map(async (r) => {
168
- return await modifyRouteIds(r, currentPathName);
169
- }));
170
- }
171
- };
172
- await Promise.all(routes.map(async (route) => {
173
- await modifyRouteIds(route, entryName === import_constant.DEFAULT_ENTRY ? "" : entryName);
174
- }));
175
- return options;
176
- },
177
- config: async () => {
178
- return {
179
- tools: {
180
- // bundlerChain can not keep target order
181
- rspack(_config, { isServer }) {
182
- (0, import_patchMFConfig.patchMFConfig)({
183
- mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
184
- metaName,
185
- isServer,
186
- internalDirectory,
187
- entries
188
- });
189
- },
190
- // bundlerChain can not keep target order
191
- webpack(_config, { isServer }) {
192
- (0, import_patchMFConfig.patchMFConfig)({
193
- mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
194
- metaName,
195
- isServer,
196
- internalDirectory,
197
- entries
198
- });
199
- }
200
- },
201
- source: {
202
- define: {
203
- MODERN_ROUTER_ID_PREFIX: JSON.stringify((0, import_utils2.transformName2Prefix)(name))
204
- }
205
- }
206
- };
207
- },
208
- async afterDev() {
209
- (0, import_clearMFCache.clearMFCache)();
210
- }
211
- };
212
- }
213
- });
214
- var plugin_default = moduleFederationDataLoaderPlugin;
215
- // Annotate the CommonJS export names for ESM import in node:
216
- 0 && (module.exports = {
217
- generateRoutes,
218
- moduleFederationDataLoaderPlugin
219
- });
@@ -1,184 +0,0 @@
1
- import { fs } from "@modern-js/utils";
2
- import { transformName2Prefix } from "../../runtime/dataLoader/utils";
3
- import { DEFAULT_ENTRY, ROUTE_ID } from "../../constant";
4
- import { META_NAME } from "../../constant";
5
- import { generateRoutes } from "./ast";
6
- import { generateRouteFile } from "./generateRouteFile";
7
- import { patchMFConfig } from "./patchMFConfig";
8
- import { clearMFCache } from "./clearMFCache";
9
- import path from "path";
10
- function _transformRuntimeOptions(buildOptions) {
11
- const remotes = buildOptions.remotes || {};
12
- const runtimeRemotes = Object.entries(remotes).map((remote) => {
13
- const [alias, nameAndEntry] = remote;
14
- const [name, entry] = nameAndEntry.split("@");
15
- return {
16
- name,
17
- entry,
18
- alias
19
- };
20
- });
21
- return {
22
- name: buildOptions.name,
23
- remotes: runtimeRemotes
24
- };
25
- }
26
- const moduleFederationDataLoaderPlugin = (enable, internalOptions, userConfig) => ({
27
- name: "@modern-js/plugin-module-federation-data-loader",
28
- pre: [
29
- "@modern-js/plugin-module-federation-config"
30
- ],
31
- post: [
32
- "@modern-js/plugin-router",
33
- "@modern-js/plugin-module-federation"
34
- ],
35
- setup: async ({ useAppContext }) => {
36
- if (!enable) {
37
- return;
38
- }
39
- const { serverPlugin = "@module-federation/modern-js/data-loader-server", transformRuntimeOptions } = userConfig;
40
- const appContext = useAppContext();
41
- const name = internalOptions.csrConfig.name;
42
- const { metaName = META_NAME } = internalOptions;
43
- const internalDirectory = appContext.internalDirectory.replace(META_NAME, metaName || META_NAME);
44
- const transformRuntimeFn = transformRuntimeOptions || _transformRuntimeOptions;
45
- const entries = /* @__PURE__ */ new Set();
46
- let remotePathMap = {};
47
- const ssrByRouteIdsMap = {};
48
- const csrConfig = internalOptions.csrConfig;
49
- if (typeof csrConfig.remotes === "object" && Object.keys(csrConfig.remotes).length) {
50
- const { entries: scanEntries, remotePathMap: scanRemotePathMap } = await generateRouteFile({
51
- appDirectory: appContext.appDirectory
52
- });
53
- scanEntries.forEach((e) => entries.add(e));
54
- remotePathMap = scanRemotePathMap;
55
- } else {
56
- entries.add(DEFAULT_ENTRY);
57
- }
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/data-loader",
78
- config: {
79
- metaName,
80
- dataLoaderRemotes
81
- }
82
- });
83
- plugins.push({
84
- name: "ssrDataLoaderInjectAssets",
85
- path: "@module-federation/modern-js/data-loader-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 modifyFileSystemRoutes(options) {
111
- const { routes, entrypoint } = options;
112
- const { entryName } = entrypoint;
113
- const prefix = transformName2Prefix(internalOptions.csrConfig.name);
114
- const modifyRouteIds = async (route, pathName) => {
115
- const currentPathName = route.path ? path.join("/", pathName, route.path) : pathName;
116
- if (route.id) {
117
- const originalId = route.id;
118
- route.originalId = originalId;
119
- const remoteInfo = remotePathMap[currentPathName];
120
- if (remoteInfo) {
121
- const { path: path2, name: name2 } = remoteInfo;
122
- const remoteIdPrefix = transformName2Prefix(name2);
123
- const isLayout = Boolean(route.children);
124
- const newId = `${remoteIdPrefix}${isLayout ? "layout" : "page"}`;
125
- ssrByRouteIdsMap[originalId] = newId;
126
- const content = fs.readFileSync(path2, "utf-8");
127
- await fs.writeFile(path2, content.replace(ROUTE_ID, originalId));
128
- route.id = newId;
129
- } else {
130
- route.id = `${prefix}${route.id}`;
131
- }
132
- route.children && await Promise.all(route.children.map(async (r) => {
133
- return await modifyRouteIds(r, currentPathName);
134
- }));
135
- }
136
- };
137
- await Promise.all(routes.map(async (route) => {
138
- await modifyRouteIds(route, entryName === DEFAULT_ENTRY ? "" : entryName);
139
- }));
140
- return options;
141
- },
142
- config: async () => {
143
- return {
144
- tools: {
145
- // bundlerChain can not keep target order
146
- rspack(_config, { isServer }) {
147
- patchMFConfig({
148
- mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
149
- metaName,
150
- isServer,
151
- internalDirectory,
152
- entries
153
- });
154
- },
155
- // bundlerChain can not keep target order
156
- webpack(_config, { isServer }) {
157
- patchMFConfig({
158
- mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
159
- metaName,
160
- isServer,
161
- internalDirectory,
162
- entries
163
- });
164
- }
165
- },
166
- source: {
167
- define: {
168
- MODERN_ROUTER_ID_PREFIX: JSON.stringify(transformName2Prefix(name))
169
- }
170
- }
171
- };
172
- },
173
- async afterDev() {
174
- clearMFCache();
175
- }
176
- };
177
- }
178
- });
179
- var plugin_default = moduleFederationDataLoaderPlugin;
180
- export {
181
- plugin_default as default,
182
- generateRoutes,
183
- moduleFederationDataLoaderPlugin
184
- };
@@ -1,6 +0,0 @@
1
- import type { CliPlugin, AppTools } from '@modern-js/app-tools';
2
- import type { DataLoaderOptions, InternalModernPluginOptions } from '../../types';
3
- import { generateRoutes } from './ast';
4
- export declare const moduleFederationDataLoaderPlugin: (enable: boolean, internalOptions: InternalModernPluginOptions, userConfig: DataLoaderOptions) => CliPlugin<AppTools>;
5
- export default moduleFederationDataLoaderPlugin;
6
- export { generateRoutes };