@module-federation/modern-js 0.0.0-next-20241014092946 → 0.0.0-next-20241015060033
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/index.js → constant.js} +6 -6
- package/dist/cjs/cli/index.js +1 -5
- package/dist/cjs/cli/mfRuntimePlugins/{node-fetch.js → inject-node-fetch.js} +6 -6
- package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +38 -40
- package/dist/cjs/{runtime/withMFRouteId.js → cli/mfRuntimePlugins/shared-strategy.js} +23 -11
- package/dist/cjs/cli/ssrPlugin.js +2 -5
- package/dist/cjs/cli/utils.js +6 -11
- package/dist/cjs/cli/utils.spec.js +6 -5
- package/dist/cjs/constant.js +2 -35
- package/dist/cjs/runtime/index.js +1 -4
- package/dist/cjs/ssr-runtime/plugin.js +8 -7
- package/dist/esm/cli/constant.js +4 -0
- package/dist/esm/cli/index.js +2 -6
- package/dist/esm/cli/mfRuntimePlugins/{node-fetch.js → inject-node-fetch.js} +3 -3
- package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +25 -0
- package/dist/esm/cli/ssrPlugin.js +3 -6
- package/dist/esm/cli/utils.js +8 -13
- package/dist/esm/cli/utils.spec.js +6 -5
- package/dist/esm/constant.js +1 -23
- package/dist/esm/runtime/index.js +1 -3
- package/dist/esm/ssr-runtime/plugin.js +11 -8
- package/dist/esm-node/cli/constant.js +4 -0
- package/dist/esm-node/cli/index.js +1 -5
- package/dist/esm-node/cli/mfRuntimePlugins/{node-fetch.js → inject-node-fetch.js} +3 -3
- package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +38 -40
- package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +23 -0
- package/dist/esm-node/cli/ssrPlugin.js +2 -5
- package/dist/esm-node/cli/utils.js +5 -9
- package/dist/esm-node/cli/utils.spec.js +6 -5
- package/dist/esm-node/constant.js +1 -23
- package/dist/esm-node/runtime/index.js +1 -3
- package/dist/esm-node/ssr-runtime/plugin.js +8 -7
- package/dist/types/cli/constant.d.ts +1 -0
- package/dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts +3 -0
- package/dist/types/cli/utils.d.ts +0 -2
- package/dist/types/constant.d.ts +0 -11
- package/dist/types/runtime/index.d.ts +0 -1
- package/dist/types/ssr-runtime/plugin.d.ts +1 -3
- package/dist/types/types/index.d.ts +0 -8
- package/package.json +13 -50
- package/dist/cjs/cli/dataLoader/ast/constant.js +0 -49
- package/dist/cjs/cli/dataLoader/ast/generateRoutes.js +0 -143
- package/dist/cjs/cli/dataLoader/clearMFCache.js +0 -57
- package/dist/cjs/cli/dataLoader/generateRouteFile.js +0 -148
- package/dist/cjs/cli/dataLoader/patchMFConfig.js +0 -160
- package/dist/cjs/cli/dataLoader/plugin.js +0 -219
- package/dist/cjs/cli/mfRuntimePlugins/node.js +0 -41
- package/dist/cjs/cli/server/dataLoaderPlugin.js +0 -81
- package/dist/cjs/cli/server/fetchRemoteFullRoutesMap.js +0 -72
- package/dist/cjs/interfaces/route.js +0 -16
- package/dist/cjs/runtime/dataLoader/plugin-inject-assets.js +0 -92
- package/dist/cjs/runtime/dataLoader/plugin.js +0 -75
- package/dist/cjs/runtime/dataLoader/utils.js +0 -115
- package/dist/cjs/types/modern.js +0 -16
- package/dist/esm/cli/dataLoader/ast/constant.js +0 -18
- package/dist/esm/cli/dataLoader/ast/generateRoutes.js +0 -110
- package/dist/esm/cli/dataLoader/ast/index.js +0 -4
- package/dist/esm/cli/dataLoader/clearMFCache.js +0 -34
- package/dist/esm/cli/dataLoader/generateRouteFile.js +0 -308
- package/dist/esm/cli/dataLoader/patchMFConfig.js +0 -124
- package/dist/esm/cli/dataLoader/plugin.js +0 -341
- package/dist/esm/cli/mfRuntimePlugins/node.js +0 -13
- package/dist/esm/cli/server/dataLoaderPlugin.js +0 -104
- package/dist/esm/cli/server/fetchRemoteFullRoutesMap.js +0 -93
- package/dist/esm/interfaces/route.js +0 -0
- package/dist/esm/runtime/dataLoader/plugin-inject-assets.js +0 -71
- package/dist/esm/runtime/dataLoader/plugin.js +0 -97
- package/dist/esm/runtime/dataLoader/utils.js +0 -86
- package/dist/esm/runtime/withMFRouteId.js +0 -7
- package/dist/esm/types/modern.js +0 -0
- package/dist/esm-node/cli/dataLoader/ast/constant.js +0 -18
- package/dist/esm-node/cli/dataLoader/ast/generateRoutes.js +0 -109
- package/dist/esm-node/cli/dataLoader/ast/index.js +0 -4
- package/dist/esm-node/cli/dataLoader/clearMFCache.js +0 -33
- package/dist/esm-node/cli/dataLoader/generateRouteFile.js +0 -113
- package/dist/esm-node/cli/dataLoader/patchMFConfig.js +0 -126
- package/dist/esm-node/cli/dataLoader/plugin.js +0 -184
- package/dist/esm-node/cli/mfRuntimePlugins/node.js +0 -11
- package/dist/esm-node/cli/server/dataLoaderPlugin.js +0 -61
- package/dist/esm-node/cli/server/fetchRemoteFullRoutesMap.js +0 -47
- package/dist/esm-node/interfaces/route.js +0 -0
- package/dist/esm-node/runtime/dataLoader/plugin-inject-assets.js +0 -68
- package/dist/esm-node/runtime/dataLoader/plugin.js +0 -51
- package/dist/esm-node/runtime/dataLoader/utils.js +0 -86
- package/dist/esm-node/runtime/withMFRouteId.js +0 -7
- package/dist/esm-node/types/modern.js +0 -0
- package/dist/types/cli/dataLoader/ast/constant.d.ts +0 -8
- package/dist/types/cli/dataLoader/ast/generateRoutes.d.ts +0 -5
- package/dist/types/cli/dataLoader/ast/index.d.ts +0 -1
- package/dist/types/cli/dataLoader/clearMFCache.d.ts +0 -1
- package/dist/types/cli/dataLoader/generateRouteFile.d.ts +0 -10
- package/dist/types/cli/dataLoader/patchMFConfig.d.ts +0 -10
- package/dist/types/cli/dataLoader/plugin.d.ts +0 -6
- package/dist/types/cli/mfRuntimePlugins/node.d.ts +0 -3
- package/dist/types/cli/server/dataLoaderPlugin.d.ts +0 -10
- package/dist/types/cli/server/fetchRemoteFullRoutesMap.d.ts +0 -11
- package/dist/types/interfaces/route.d.ts +0 -12
- package/dist/types/runtime/dataLoader/plugin-inject-assets.d.ts +0 -4
- package/dist/types/runtime/dataLoader/plugin.d.ts +0 -5
- package/dist/types/runtime/dataLoader/utils.d.ts +0 -22
- package/dist/types/runtime/withMFRouteId.d.ts +0 -1
- package/dist/types/types/modern.d.ts +0 -12
- /package/dist/types/cli/mfRuntimePlugins/{node-fetch.d.ts → inject-node-fetch.d.ts} +0 -0
|
@@ -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);
|
|
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,41 +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 node_exports = {};
|
|
30
|
-
__export(node_exports, {
|
|
31
|
-
default: () => node_default
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(node_exports);
|
|
34
|
-
var import_runtimePlugin = __toESM(require("@module-federation/node/runtimePlugin"));
|
|
35
|
-
const isContainer = typeof __filename === "string" ? __filename.includes("remote") ? true : false : false;
|
|
36
|
-
const pluginName = `node-plugin-${isContainer}`;
|
|
37
|
-
const nodePlugin = () => ({
|
|
38
|
-
name: pluginName,
|
|
39
|
-
beforeInit: (0, import_runtimePlugin.default)().beforeInit
|
|
40
|
-
});
|
|
41
|
-
var node_default = nodePlugin;
|
|
@@ -1,81 +0,0 @@
|
|
|
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 dataLoaderPlugin_exports = {};
|
|
20
|
-
__export(dataLoaderPlugin_exports, {
|
|
21
|
-
default: () => dataLoaderPlugin_default
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(dataLoaderPlugin_exports);
|
|
24
|
-
var import_runtime = require("@module-federation/enhanced/runtime");
|
|
25
|
-
var import_sdk = require("@module-federation/sdk");
|
|
26
|
-
var import_fetchRemoteFullRoutesMap = require("./fetchRemoteFullRoutesMap");
|
|
27
|
-
var import_utils = require("../../runtime/dataLoader/utils");
|
|
28
|
-
var import_constant = require("../../constant");
|
|
29
|
-
var dataLoaderPlugin_default = ({ runtimeOptions, dataLoaderRemotes, ssrByRouteIdsMap }) => ({
|
|
30
|
-
name: "MFDataLoaderServerPlugin",
|
|
31
|
-
pre: [
|
|
32
|
-
"@modern-js/plugin-inject-resource"
|
|
33
|
-
],
|
|
34
|
-
setup(api) {
|
|
35
|
-
const { remotes, name } = runtimeOptions;
|
|
36
|
-
let isHandled = false;
|
|
37
|
-
return {
|
|
38
|
-
prepare() {
|
|
39
|
-
const { middlewares } = api.useAppContext();
|
|
40
|
-
middlewares.push({
|
|
41
|
-
name: "MFPatchRouteMiddleWare",
|
|
42
|
-
handler: async (c, next) => {
|
|
43
|
-
const serverManifest = c.get("serverManifest");
|
|
44
|
-
const { loaderBundles, nestedRoutesJson } = serverManifest;
|
|
45
|
-
if (isHandled && !globalThis.FORCE_MF_REFRESH) {
|
|
46
|
-
await next();
|
|
47
|
-
} else {
|
|
48
|
-
var _api_useConfigContext_server;
|
|
49
|
-
const instance = (0, import_runtime.init)({
|
|
50
|
-
name,
|
|
51
|
-
remotes
|
|
52
|
-
});
|
|
53
|
-
const remoteFullRoutesMap = await (0, import_fetchRemoteFullRoutesMap.fetchRemoteFullRoutesMap)({
|
|
54
|
-
instance,
|
|
55
|
-
remotePath: (0, import_sdk.isBrowserEnv)() ? `${import_constant.DEFAULT_ENTRY}/${import_constant.MF_ROUTES}` : `${import_constant.DEFAULT_ENTRY}/${import_constant.MODERN_JS_ROUTE_SERVER_LOADER}`,
|
|
56
|
-
dataLoaderRemotes
|
|
57
|
-
});
|
|
58
|
-
const originalSSRByRouteIds = (_api_useConfigContext_server = api.useConfigContext().server) === null || _api_useConfigContext_server === void 0 ? void 0 : _api_useConfigContext_server.ssrByRouteIds;
|
|
59
|
-
if (originalSSRByRouteIds && dataLoaderRemotes.length) {
|
|
60
|
-
const remoteSSRByRouteIds = (0, import_fetchRemoteFullRoutesMap.getSSRByRouteIds)(dataLoaderRemotes, remoteFullRoutesMap) || [];
|
|
61
|
-
const ssrByRouteIds = /* @__PURE__ */ new Set([
|
|
62
|
-
...originalSSRByRouteIds,
|
|
63
|
-
...remoteSSRByRouteIds.map((id) => ssrByRouteIdsMap[id] || id)
|
|
64
|
-
]);
|
|
65
|
-
api.useConfigContext().server.ssrByRouteIds = Array.from(ssrByRouteIds);
|
|
66
|
-
}
|
|
67
|
-
(0, import_utils.injectRemoteRoutes)(loaderBundles, remoteFullRoutesMap);
|
|
68
|
-
(0, import_utils.injectRemoteRoutes)(nestedRoutesJson, remoteFullRoutesMap);
|
|
69
|
-
isHandled = true;
|
|
70
|
-
globalThis.FORCE_MF_REFRESH = false;
|
|
71
|
-
await next();
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
before: [
|
|
75
|
-
"render"
|
|
76
|
-
]
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
});
|
|
@@ -1,72 +0,0 @@
|
|
|
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 fetchRemoteFullRoutesMap_exports = {};
|
|
20
|
-
__export(fetchRemoteFullRoutesMap_exports, {
|
|
21
|
-
fetchRemoteFullRoutesMap: () => fetchRemoteFullRoutesMap,
|
|
22
|
-
getSSRByRouteIds: () => getSSRByRouteIds
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(fetchRemoteFullRoutesMap_exports);
|
|
25
|
-
async function fetchRemoteFullRoutesMap(options) {
|
|
26
|
-
const { instance, remotePath, dataLoaderRemotes } = options;
|
|
27
|
-
const { remotes } = instance.options;
|
|
28
|
-
const remoteRoutesMap = {};
|
|
29
|
-
if (!remotes.length) {
|
|
30
|
-
return remoteRoutesMap;
|
|
31
|
-
}
|
|
32
|
-
await Promise.all(remotes.map(async (remote) => {
|
|
33
|
-
if (!dataLoaderRemotes.includes(remote.name)) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
const remoteId = `${remote.name}/${remotePath}`;
|
|
37
|
-
const { routes } = await instance.loadRemote(remoteId);
|
|
38
|
-
remoteRoutesMap[remote.name] = {
|
|
39
|
-
routes
|
|
40
|
-
};
|
|
41
|
-
}));
|
|
42
|
-
return remoteRoutesMap;
|
|
43
|
-
}
|
|
44
|
-
function getSSRByRouteIds(dataLoaderRemotes, remoteRoutesMap) {
|
|
45
|
-
const remoteProviderRouteIds = /* @__PURE__ */ new Set();
|
|
46
|
-
const collectIds = (route) => {
|
|
47
|
-
remoteProviderRouteIds.add(route.id);
|
|
48
|
-
if (route.children) {
|
|
49
|
-
route.children.forEach((r) => {
|
|
50
|
-
collectIds(r);
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
Object.entries(remoteRoutesMap).forEach((item) => {
|
|
55
|
-
const [remoteName, routesObj] = item;
|
|
56
|
-
if (!dataLoaderRemotes.includes(remoteName)) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
const { routes } = routesObj;
|
|
60
|
-
routes.forEach((route) => {
|
|
61
|
-
collectIds(route);
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
return [
|
|
65
|
-
...remoteProviderRouteIds
|
|
66
|
-
];
|
|
67
|
-
}
|
|
68
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
69
|
-
0 && (module.exports = {
|
|
70
|
-
fetchRemoteFullRoutesMap,
|
|
71
|
-
getSSRByRouteIds
|
|
72
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
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);
|
|
@@ -1,92 +0,0 @@
|
|
|
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 plugin_inject_assets_exports = {};
|
|
20
|
-
__export(plugin_inject_assets_exports, {
|
|
21
|
-
ssrDataLoaderInjectAssetsPlugin: () => ssrDataLoaderInjectAssetsPlugin
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(plugin_inject_assets_exports);
|
|
24
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
|
-
var import_react = require("react");
|
|
26
|
-
var import_runtime = require("@module-federation/enhanced/runtime");
|
|
27
|
-
var import_createRemoteSSRComponent = require("../createRemoteSSRComponent");
|
|
28
|
-
var import_runtime2 = require("@meta/runtime");
|
|
29
|
-
var import_utils = require("./utils");
|
|
30
|
-
function traverseRoutes(routes, remoteNames) {
|
|
31
|
-
routes.forEach((route) => {
|
|
32
|
-
route.id && remoteNames.add((0, import_utils.decodeId)(route.id));
|
|
33
|
-
route.children && traverseRoutes(route.children, remoteNames);
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
const ssrDataLoaderInjectAssetsPlugin = ({ metaName }) => {
|
|
37
|
-
return {
|
|
38
|
-
name: "@modern-js/plugin-mf-data-loader-inject-assets",
|
|
39
|
-
pre: [
|
|
40
|
-
"@modern-js/plugin-mf-data-loader"
|
|
41
|
-
],
|
|
42
|
-
post: [
|
|
43
|
-
"@module-federation/modern-js",
|
|
44
|
-
`@${metaName}/plugin-router`
|
|
45
|
-
],
|
|
46
|
-
setup: () => {
|
|
47
|
-
return {
|
|
48
|
-
wrapRoot(App) {
|
|
49
|
-
const AppWrapper = (props) => {
|
|
50
|
-
const instance = (0, import_runtime.getInstance)();
|
|
51
|
-
if (!instance || !instance.options.remotes.length) {
|
|
52
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
|
|
53
|
-
children: props.children
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
const context = (0, import_react.useContext)(import_runtime2.RuntimeReactContext);
|
|
57
|
-
const { remotes } = instance.options;
|
|
58
|
-
const remoteNames = /* @__PURE__ */ new Set();
|
|
59
|
-
traverseRoutes(context.routes, remoteNames);
|
|
60
|
-
const remoteIds = [
|
|
61
|
-
...remoteNames
|
|
62
|
-
].reduce((sum, cur) => {
|
|
63
|
-
const matchRemote = remotes.find((r) => r.name === cur);
|
|
64
|
-
if (matchRemote) {
|
|
65
|
-
sum.add((0, import_utils.getRemoteId)(cur));
|
|
66
|
-
}
|
|
67
|
-
return sum;
|
|
68
|
-
}, /* @__PURE__ */ new Set());
|
|
69
|
-
const assets = [];
|
|
70
|
-
remoteIds.forEach((remoteId) => {
|
|
71
|
-
assets.push(...(0, import_createRemoteSSRComponent.collectSSRAssets)({
|
|
72
|
-
id: remoteId,
|
|
73
|
-
injectScript: false
|
|
74
|
-
}));
|
|
75
|
-
});
|
|
76
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
|
|
77
|
-
children: [
|
|
78
|
-
assets,
|
|
79
|
-
props.children
|
|
80
|
-
]
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
return AppWrapper;
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
90
|
-
0 && (module.exports = {
|
|
91
|
-
ssrDataLoaderInjectAssetsPlugin
|
|
92
|
-
});
|
|
@@ -1,75 +0,0 @@
|
|
|
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 plugin_exports = {};
|
|
20
|
-
__export(plugin_exports, {
|
|
21
|
-
ssrDataLoaderPlugin: () => ssrDataLoaderPlugin
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(plugin_exports);
|
|
24
|
-
var import_runtime = require("@module-federation/enhanced/runtime");
|
|
25
|
-
var import_constant = require("../../constant");
|
|
26
|
-
var import_utils = require("./utils");
|
|
27
|
-
const ssrDataLoaderPlugin = ({ metaName, dataLoaderRemotes }) => {
|
|
28
|
-
return {
|
|
29
|
-
name: "@modern-js/plugin-mf-data-loader",
|
|
30
|
-
post: [
|
|
31
|
-
`@${metaName}/plugin-router`,
|
|
32
|
-
"@module-federation/modern-js"
|
|
33
|
-
],
|
|
34
|
-
setup: () => {
|
|
35
|
-
const remoteRoutesMap = {};
|
|
36
|
-
return {
|
|
37
|
-
async beforeRender() {
|
|
38
|
-
if (Object.keys(remoteRoutesMap).length) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
const instance = (0, import_runtime.getInstance)();
|
|
42
|
-
if (!instance) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
if (!instance.options.remotes.length) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
await Promise.all(instance.options.remotes.map(async (remote) => {
|
|
49
|
-
if (!dataLoaderRemotes.includes(remote.name)) {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
const remoteId = `${remote.name}/${import_constant.DEFAULT_ENTRY}/${import_constant.MF_ROUTES}`;
|
|
53
|
-
const { routes } = await instance.loadRemote(remoteId);
|
|
54
|
-
remoteRoutesMap[remote.name] = {
|
|
55
|
-
routes
|
|
56
|
-
};
|
|
57
|
-
}));
|
|
58
|
-
},
|
|
59
|
-
// runtime plugin not save route , so it needs to inject again when trigger
|
|
60
|
-
modifyRoutes: (routes) => {
|
|
61
|
-
(0, import_utils.injectRemoteRoutes)({
|
|
62
|
-
entry: {
|
|
63
|
-
routes
|
|
64
|
-
}
|
|
65
|
-
}, remoteRoutesMap);
|
|
66
|
-
return routes;
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
};
|
|
72
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
73
|
-
0 && (module.exports = {
|
|
74
|
-
ssrDataLoaderPlugin
|
|
75
|
-
});
|