@module-federation/modern-js 0.0.0-next-20241014092946 → 0.0.0-next-20241015065721
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,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);
|
|
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,11 +0,0 @@
|
|
|
1
|
-
import nodeRuntimePlugin from "@module-federation/node/runtimePlugin";
|
|
2
|
-
const isContainer = typeof __filename === "string" ? __filename.includes("remote") ? true : false : false;
|
|
3
|
-
const pluginName = `node-plugin-${isContainer}`;
|
|
4
|
-
const nodePlugin = () => ({
|
|
5
|
-
name: pluginName,
|
|
6
|
-
beforeInit: nodeRuntimePlugin().beforeInit
|
|
7
|
-
});
|
|
8
|
-
var node_default = nodePlugin;
|
|
9
|
-
export {
|
|
10
|
-
node_default as default
|
|
11
|
-
};
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { init } from "@module-federation/enhanced/runtime";
|
|
2
|
-
import { isBrowserEnv } from "@module-federation/sdk";
|
|
3
|
-
import { fetchRemoteFullRoutesMap, getSSRByRouteIds } from "./fetchRemoteFullRoutesMap";
|
|
4
|
-
import { injectRemoteRoutes } from "../../runtime/dataLoader/utils";
|
|
5
|
-
import { MF_ROUTES, DEFAULT_ENTRY, MODERN_JS_ROUTE_SERVER_LOADER } from "../../constant";
|
|
6
|
-
var dataLoaderPlugin_default = ({ runtimeOptions, dataLoaderRemotes, ssrByRouteIdsMap }) => ({
|
|
7
|
-
name: "MFDataLoaderServerPlugin",
|
|
8
|
-
pre: [
|
|
9
|
-
"@modern-js/plugin-inject-resource"
|
|
10
|
-
],
|
|
11
|
-
setup(api) {
|
|
12
|
-
const { remotes, name } = runtimeOptions;
|
|
13
|
-
let isHandled = false;
|
|
14
|
-
return {
|
|
15
|
-
prepare() {
|
|
16
|
-
const { middlewares } = api.useAppContext();
|
|
17
|
-
middlewares.push({
|
|
18
|
-
name: "MFPatchRouteMiddleWare",
|
|
19
|
-
handler: async (c, next) => {
|
|
20
|
-
const serverManifest = c.get("serverManifest");
|
|
21
|
-
const { loaderBundles, nestedRoutesJson } = serverManifest;
|
|
22
|
-
if (isHandled && !globalThis.FORCE_MF_REFRESH) {
|
|
23
|
-
await next();
|
|
24
|
-
} else {
|
|
25
|
-
var _api_useConfigContext_server;
|
|
26
|
-
const instance = init({
|
|
27
|
-
name,
|
|
28
|
-
remotes
|
|
29
|
-
});
|
|
30
|
-
const remoteFullRoutesMap = await fetchRemoteFullRoutesMap({
|
|
31
|
-
instance,
|
|
32
|
-
remotePath: isBrowserEnv() ? `${DEFAULT_ENTRY}/${MF_ROUTES}` : `${DEFAULT_ENTRY}/${MODERN_JS_ROUTE_SERVER_LOADER}`,
|
|
33
|
-
dataLoaderRemotes
|
|
34
|
-
});
|
|
35
|
-
const originalSSRByRouteIds = (_api_useConfigContext_server = api.useConfigContext().server) === null || _api_useConfigContext_server === void 0 ? void 0 : _api_useConfigContext_server.ssrByRouteIds;
|
|
36
|
-
if (originalSSRByRouteIds && dataLoaderRemotes.length) {
|
|
37
|
-
const remoteSSRByRouteIds = getSSRByRouteIds(dataLoaderRemotes, remoteFullRoutesMap) || [];
|
|
38
|
-
const ssrByRouteIds = /* @__PURE__ */ new Set([
|
|
39
|
-
...originalSSRByRouteIds,
|
|
40
|
-
...remoteSSRByRouteIds.map((id) => ssrByRouteIdsMap[id] || id)
|
|
41
|
-
]);
|
|
42
|
-
api.useConfigContext().server.ssrByRouteIds = Array.from(ssrByRouteIds);
|
|
43
|
-
}
|
|
44
|
-
injectRemoteRoutes(loaderBundles, remoteFullRoutesMap);
|
|
45
|
-
injectRemoteRoutes(nestedRoutesJson, remoteFullRoutesMap);
|
|
46
|
-
isHandled = true;
|
|
47
|
-
globalThis.FORCE_MF_REFRESH = false;
|
|
48
|
-
await next();
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
before: [
|
|
52
|
-
"render"
|
|
53
|
-
]
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
export {
|
|
60
|
-
dataLoaderPlugin_default as default
|
|
61
|
-
};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
async function fetchRemoteFullRoutesMap(options) {
|
|
2
|
-
const { instance, remotePath, dataLoaderRemotes } = options;
|
|
3
|
-
const { remotes } = instance.options;
|
|
4
|
-
const remoteRoutesMap = {};
|
|
5
|
-
if (!remotes.length) {
|
|
6
|
-
return remoteRoutesMap;
|
|
7
|
-
}
|
|
8
|
-
await Promise.all(remotes.map(async (remote) => {
|
|
9
|
-
if (!dataLoaderRemotes.includes(remote.name)) {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
const remoteId = `${remote.name}/${remotePath}`;
|
|
13
|
-
const { routes } = await instance.loadRemote(remoteId);
|
|
14
|
-
remoteRoutesMap[remote.name] = {
|
|
15
|
-
routes
|
|
16
|
-
};
|
|
17
|
-
}));
|
|
18
|
-
return remoteRoutesMap;
|
|
19
|
-
}
|
|
20
|
-
function getSSRByRouteIds(dataLoaderRemotes, remoteRoutesMap) {
|
|
21
|
-
const remoteProviderRouteIds = /* @__PURE__ */ new Set();
|
|
22
|
-
const collectIds = (route) => {
|
|
23
|
-
remoteProviderRouteIds.add(route.id);
|
|
24
|
-
if (route.children) {
|
|
25
|
-
route.children.forEach((r) => {
|
|
26
|
-
collectIds(r);
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
Object.entries(remoteRoutesMap).forEach((item) => {
|
|
31
|
-
const [remoteName, routesObj] = item;
|
|
32
|
-
if (!dataLoaderRemotes.includes(remoteName)) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
const { routes } = routesObj;
|
|
36
|
-
routes.forEach((route) => {
|
|
37
|
-
collectIds(route);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
return [
|
|
41
|
-
...remoteProviderRouteIds
|
|
42
|
-
];
|
|
43
|
-
}
|
|
44
|
-
export {
|
|
45
|
-
fetchRemoteFullRoutesMap,
|
|
46
|
-
getSSRByRouteIds
|
|
47
|
-
};
|
|
File without changes
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { useContext } from "react";
|
|
3
|
-
import { getInstance } from "@module-federation/enhanced/runtime";
|
|
4
|
-
import { collectSSRAssets } from "../createRemoteSSRComponent";
|
|
5
|
-
import { RuntimeReactContext } from "@meta/runtime";
|
|
6
|
-
import { decodeId, getRemoteId } from "./utils";
|
|
7
|
-
function traverseRoutes(routes, remoteNames) {
|
|
8
|
-
routes.forEach((route) => {
|
|
9
|
-
route.id && remoteNames.add(decodeId(route.id));
|
|
10
|
-
route.children && traverseRoutes(route.children, remoteNames);
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
const ssrDataLoaderInjectAssetsPlugin = ({ metaName }) => {
|
|
14
|
-
return {
|
|
15
|
-
name: "@modern-js/plugin-mf-data-loader-inject-assets",
|
|
16
|
-
pre: [
|
|
17
|
-
"@modern-js/plugin-mf-data-loader"
|
|
18
|
-
],
|
|
19
|
-
post: [
|
|
20
|
-
"@module-federation/modern-js",
|
|
21
|
-
`@${metaName}/plugin-router`
|
|
22
|
-
],
|
|
23
|
-
setup: () => {
|
|
24
|
-
return {
|
|
25
|
-
wrapRoot(App) {
|
|
26
|
-
const AppWrapper = (props) => {
|
|
27
|
-
const instance = getInstance();
|
|
28
|
-
if (!instance || !instance.options.remotes.length) {
|
|
29
|
-
return /* @__PURE__ */ _jsx(_Fragment, {
|
|
30
|
-
children: props.children
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
const context = useContext(RuntimeReactContext);
|
|
34
|
-
const { remotes } = instance.options;
|
|
35
|
-
const remoteNames = /* @__PURE__ */ new Set();
|
|
36
|
-
traverseRoutes(context.routes, remoteNames);
|
|
37
|
-
const remoteIds = [
|
|
38
|
-
...remoteNames
|
|
39
|
-
].reduce((sum, cur) => {
|
|
40
|
-
const matchRemote = remotes.find((r) => r.name === cur);
|
|
41
|
-
if (matchRemote) {
|
|
42
|
-
sum.add(getRemoteId(cur));
|
|
43
|
-
}
|
|
44
|
-
return sum;
|
|
45
|
-
}, /* @__PURE__ */ new Set());
|
|
46
|
-
const assets = [];
|
|
47
|
-
remoteIds.forEach((remoteId) => {
|
|
48
|
-
assets.push(...collectSSRAssets({
|
|
49
|
-
id: remoteId,
|
|
50
|
-
injectScript: false
|
|
51
|
-
}));
|
|
52
|
-
});
|
|
53
|
-
return /* @__PURE__ */ _jsxs(_Fragment, {
|
|
54
|
-
children: [
|
|
55
|
-
assets,
|
|
56
|
-
props.children
|
|
57
|
-
]
|
|
58
|
-
});
|
|
59
|
-
};
|
|
60
|
-
return AppWrapper;
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
export {
|
|
67
|
-
ssrDataLoaderInjectAssetsPlugin
|
|
68
|
-
};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { getInstance } from "@module-federation/enhanced/runtime";
|
|
2
|
-
import { MF_ROUTES, DEFAULT_ENTRY } from "../../constant";
|
|
3
|
-
import { injectRemoteRoutes } from "./utils";
|
|
4
|
-
const ssrDataLoaderPlugin = ({ metaName, dataLoaderRemotes }) => {
|
|
5
|
-
return {
|
|
6
|
-
name: "@modern-js/plugin-mf-data-loader",
|
|
7
|
-
post: [
|
|
8
|
-
`@${metaName}/plugin-router`,
|
|
9
|
-
"@module-federation/modern-js"
|
|
10
|
-
],
|
|
11
|
-
setup: () => {
|
|
12
|
-
const remoteRoutesMap = {};
|
|
13
|
-
return {
|
|
14
|
-
async beforeRender() {
|
|
15
|
-
if (Object.keys(remoteRoutesMap).length) {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
const instance = getInstance();
|
|
19
|
-
if (!instance) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
if (!instance.options.remotes.length) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
await Promise.all(instance.options.remotes.map(async (remote) => {
|
|
26
|
-
if (!dataLoaderRemotes.includes(remote.name)) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
const remoteId = `${remote.name}/${DEFAULT_ENTRY}/${MF_ROUTES}`;
|
|
30
|
-
const { routes } = await instance.loadRemote(remoteId);
|
|
31
|
-
remoteRoutesMap[remote.name] = {
|
|
32
|
-
routes
|
|
33
|
-
};
|
|
34
|
-
}));
|
|
35
|
-
},
|
|
36
|
-
// runtime plugin not save route , so it needs to inject again when trigger
|
|
37
|
-
modifyRoutes: (routes) => {
|
|
38
|
-
injectRemoteRoutes({
|
|
39
|
-
entry: {
|
|
40
|
-
routes
|
|
41
|
-
}
|
|
42
|
-
}, remoteRoutesMap);
|
|
43
|
-
return routes;
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
export {
|
|
50
|
-
ssrDataLoaderPlugin
|
|
51
|
-
};
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { encodeName, decodeName } from "@module-federation/sdk";
|
|
2
|
-
import { DEFAULT_ENTRY, DEFAULT_LAYOUT, MF_ROUTES } from "../../constant";
|
|
3
|
-
const SPLIT_SYMBOL = "@";
|
|
4
|
-
function transformName2Prefix(name) {
|
|
5
|
-
return `${encodeName(name, "", false)}${SPLIT_SYMBOL}`;
|
|
6
|
-
}
|
|
7
|
-
function decodeId(prefix) {
|
|
8
|
-
const realPrefix = prefix.split(SPLIT_SYMBOL)[0];
|
|
9
|
-
return decodeName(realPrefix, "", false);
|
|
10
|
-
}
|
|
11
|
-
function getRemoteRoutesInfos(route, remoteRoutesMap) {
|
|
12
|
-
if (!route.id) {
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
const remoteName = decodeId(route.id);
|
|
16
|
-
const remoteRouteObj = remoteRoutesMap[remoteName];
|
|
17
|
-
if (!remoteRouteObj) {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
const remoteRoutes = remoteRouteObj.routes[0];
|
|
21
|
-
return {
|
|
22
|
-
routes: remoteRoutes,
|
|
23
|
-
name: remoteName,
|
|
24
|
-
pathName: route.path
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
function getRemoteLayoutId(remoteName) {
|
|
28
|
-
const prefix = transformName2Prefix(remoteName);
|
|
29
|
-
return `${prefix}${DEFAULT_LAYOUT}`;
|
|
30
|
-
}
|
|
31
|
-
function getRemoteId(remoteName) {
|
|
32
|
-
return `${remoteName}/${DEFAULT_ENTRY}/${MF_ROUTES}`;
|
|
33
|
-
}
|
|
34
|
-
function injectRemoteRoutes(initialRoutes, remoteRoutesMap) {
|
|
35
|
-
const traverse = (route) => {
|
|
36
|
-
var _route_children;
|
|
37
|
-
const remoteRoutesInfos = getRemoteRoutesInfos(route, remoteRoutesMap);
|
|
38
|
-
if (remoteRoutesInfos) {
|
|
39
|
-
const { routes, pathName } = remoteRoutesInfos;
|
|
40
|
-
route.id = routes.id;
|
|
41
|
-
route.path = pathName;
|
|
42
|
-
if (routes.loader) {
|
|
43
|
-
route.loader = routes.loader;
|
|
44
|
-
}
|
|
45
|
-
if (routes.children) {
|
|
46
|
-
route.children = routes.children;
|
|
47
|
-
}
|
|
48
|
-
if (routes.Component) {
|
|
49
|
-
route.Component = routes.Component;
|
|
50
|
-
if (route.element) {
|
|
51
|
-
delete route.element;
|
|
52
|
-
}
|
|
53
|
-
} else if (routes.element) {
|
|
54
|
-
route.element = routes.element;
|
|
55
|
-
if (route.Component) {
|
|
56
|
-
delete route.Component;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
(_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.forEach((r) => {
|
|
62
|
-
traverse(r);
|
|
63
|
-
});
|
|
64
|
-
};
|
|
65
|
-
Object.keys(initialRoutes).forEach((entryName) => {
|
|
66
|
-
const routes = initialRoutes[entryName];
|
|
67
|
-
if (Array.isArray(routes)) {
|
|
68
|
-
routes.forEach((route) => {
|
|
69
|
-
traverse(route);
|
|
70
|
-
});
|
|
71
|
-
} else {
|
|
72
|
-
var _routes_routes;
|
|
73
|
-
routes === null || routes === void 0 ? void 0 : (_routes_routes = routes.routes) === null || _routes_routes === void 0 ? void 0 : _routes_routes.forEach((r) => {
|
|
74
|
-
traverse(r);
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
export {
|
|
80
|
-
decodeId,
|
|
81
|
-
getRemoteId,
|
|
82
|
-
getRemoteLayoutId,
|
|
83
|
-
getRemoteRoutesInfos,
|
|
84
|
-
injectRemoteRoutes,
|
|
85
|
-
transformName2Prefix
|
|
86
|
-
};
|
|
File without changes
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export declare const IS_ROOT = "isRoot";
|
|
2
|
-
export declare const ID = "id";
|
|
3
|
-
export declare const COMPONENT = "component";
|
|
4
|
-
export declare const LAZY_COMPONENT = "lazyImport";
|
|
5
|
-
export declare const SHOULD_REVALIDATE = "shouldRevalidate";
|
|
6
|
-
export declare const PRIVATE_COMPONENT = "_component";
|
|
7
|
-
export declare const ELEMENT = "element";
|
|
8
|
-
export declare const LOADER = "loader";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { generateRoutes } from './generateRoutes';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function clearMFCache(): void;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export declare function calcPathName(filePath: string, rootDir: string, entry: string): string;
|
|
2
|
-
export declare function generateRouteFile(options: {
|
|
3
|
-
appDirectory: string;
|
|
4
|
-
}): Promise<{
|
|
5
|
-
entries: string[];
|
|
6
|
-
remotePathMap: Record<string, {
|
|
7
|
-
name: string;
|
|
8
|
-
path: string;
|
|
9
|
-
}>;
|
|
10
|
-
}>;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { type moduleFederationPlugin } from '@module-federation/sdk';
|
|
2
|
-
type PatchMFConfigOptions = {
|
|
3
|
-
mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
4
|
-
metaName: string;
|
|
5
|
-
isServer: boolean;
|
|
6
|
-
internalDirectory: string;
|
|
7
|
-
entries: Set<string>;
|
|
8
|
-
};
|
|
9
|
-
export declare function patchMFConfig(options: PatchMFConfigOptions): void;
|
|
10
|
-
export {};
|
|
@@ -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 };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { ServerPlugin } from '@modern-js/server-core';
|
|
2
|
-
import { init } from '@module-federation/enhanced/runtime';
|
|
3
|
-
type MFRuntimeOptions = Parameters<typeof init>[0];
|
|
4
|
-
export type DataLoaderServerPluginOptions = {
|
|
5
|
-
runtimeOptions: MFRuntimeOptions;
|
|
6
|
-
dataLoaderRemotes: string[];
|
|
7
|
-
ssrByRouteIdsMap: Record<string, string>;
|
|
8
|
-
};
|
|
9
|
-
declare const _default: ({ runtimeOptions, dataLoaderRemotes, ssrByRouteIdsMap, }: DataLoaderServerPluginOptions) => ServerPlugin;
|
|
10
|
-
export default _default;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { FederationHost } from '@module-federation/enhanced/runtime';
|
|
2
|
-
import type { RouteObject } from '@modern-js/runtime/router';
|
|
3
|
-
export type RemoteRoutesMap = Record<string, {
|
|
4
|
-
routes: RouteObject[];
|
|
5
|
-
}>;
|
|
6
|
-
export declare function fetchRemoteFullRoutesMap(options: {
|
|
7
|
-
remotePath: string;
|
|
8
|
-
instance: FederationHost;
|
|
9
|
-
dataLoaderRemotes: string[];
|
|
10
|
-
}): Promise<RemoteRoutesMap>;
|
|
11
|
-
export declare function getSSRByRouteIds(dataLoaderRemotes: string[], remoteRoutesMap: RemoteRoutesMap): undefined | string[];
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { RouteObject } from '@modern-js/runtime/router';
|
|
2
|
-
export type RemoteRoutesMap = Record<string, {
|
|
3
|
-
routes: RouteObject[];
|
|
4
|
-
}>;
|
|
5
|
-
export type LoaderBundlesRoutes = {
|
|
6
|
-
[entryName: string]: {
|
|
7
|
-
routes: RouteObject[];
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
export type NestedRoutes = {
|
|
11
|
-
[entryName: string]: RouteObject[];
|
|
12
|
-
};
|
|
13
|
-
export declare function transformName2Prefix(name: string): string;
|
|
14
|
-
export declare function decodeId(prefix: string): string;
|
|
15
|
-
export declare function getRemoteRoutesInfos(route: RouteObject, remoteRoutesMap: RemoteRoutesMap): {
|
|
16
|
-
routes: RouteObject;
|
|
17
|
-
name: string;
|
|
18
|
-
pathName: string | undefined;
|
|
19
|
-
} | undefined;
|
|
20
|
-
export declare function getRemoteLayoutId(remoteName: string): string;
|
|
21
|
-
export declare function getRemoteId(remoteName: string): string;
|
|
22
|
-
export declare function injectRemoteRoutes(initialRoutes: LoaderBundlesRoutes | NestedRoutes, remoteRoutesMap: RemoteRoutesMap): void;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function withMFRouteId(id: string): string;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { AppToolsNormalizedConfig } from '@modern-js/app-tools';
|
|
2
|
-
type ArrayElement<ArrayType extends readonly unknown[]> = ArrayType extends readonly (infer ElementType)[] ? ElementType : never;
|
|
3
|
-
type ExcludeUndefined<T> = T extends undefined ? never : T;
|
|
4
|
-
type ExcludeVoid<T> = T extends void ? never : T;
|
|
5
|
-
type NonUndefined<T> = ExcludeUndefined<T>;
|
|
6
|
-
type NonVoid<T> = ExcludeVoid<T>;
|
|
7
|
-
type Must<T> = NonVoid<NonUndefined<T>>;
|
|
8
|
-
type PickObjectArr<T> = T extends Record<string, any>[] ? never : T;
|
|
9
|
-
type ExcludeFunction<T> = T extends (...args: any[]) => any ? never : T;
|
|
10
|
-
type WebpackPlugins = Must<AppToolsNormalizedConfig['tools']['webpack']>;
|
|
11
|
-
export type WebpackPluginType = ArrayElement<Must<ExcludeFunction<PickObjectArr<WebpackPlugins>>['plugins']>>;
|
|
12
|
-
export {};
|