@module-federation/modern-js 0.0.0-next-20241010084324 → 0.0.0-next-20241011105718
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/constant.js +49 -0
- package/dist/cjs/cli/dataLoader/ast/generateRoutes.js +143 -0
- package/dist/cjs/cli/{constant.js → dataLoader/ast/index.js} +6 -6
- package/dist/cjs/cli/dataLoader/clearMFCache.js +57 -0
- package/dist/cjs/cli/dataLoader/generateRouteFile.js +148 -0
- package/dist/cjs/cli/dataLoader/patchMFConfig.js +137 -0
- package/dist/cjs/cli/dataLoader/plugin.js +219 -0
- package/dist/cjs/cli/index.js +5 -1
- package/dist/cjs/cli/mfRuntimePlugins/{inject-node-fetch.js → node-fetch.js} +6 -6
- package/dist/cjs/cli/mfRuntimePlugins/node.js +41 -0
- package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +40 -38
- package/dist/cjs/cli/server/dataLoaderPlugin.js +81 -0
- package/dist/cjs/cli/server/fetchRemoteFullRoutesMap.js +72 -0
- package/dist/cjs/cli/ssrPlugin.js +5 -2
- package/dist/cjs/cli/utils.js +11 -6
- package/dist/cjs/cli/utils.spec.js +5 -6
- package/dist/cjs/constant.js +35 -2
- package/dist/cjs/interfaces/route.js +16 -0
- package/dist/cjs/runtime/dataLoader/plugin-inject-assets.js +92 -0
- package/dist/cjs/runtime/dataLoader/plugin.js +75 -0
- package/dist/cjs/runtime/dataLoader/utils.js +115 -0
- package/dist/cjs/runtime/index.js +4 -1
- package/dist/cjs/{cli/mfRuntimePlugins/shared-strategy.js → runtime/withMFRouteId.js} +11 -23
- package/dist/cjs/ssr-runtime/plugin.js +7 -8
- package/dist/cjs/types/modern.js +16 -0
- package/dist/esm/cli/dataLoader/ast/constant.js +18 -0
- package/dist/esm/cli/dataLoader/ast/generateRoutes.js +110 -0
- package/dist/esm/cli/dataLoader/ast/index.js +4 -0
- package/dist/esm/cli/dataLoader/clearMFCache.js +34 -0
- package/dist/esm/cli/dataLoader/generateRouteFile.js +308 -0
- package/dist/esm/cli/dataLoader/patchMFConfig.js +103 -0
- package/dist/esm/cli/dataLoader/plugin.js +341 -0
- package/dist/esm/cli/index.js +6 -2
- package/dist/esm/cli/mfRuntimePlugins/{inject-node-fetch.js → node-fetch.js} +3 -3
- package/dist/esm/cli/mfRuntimePlugins/node.js +13 -0
- package/dist/esm/cli/server/dataLoaderPlugin.js +104 -0
- package/dist/esm/cli/server/fetchRemoteFullRoutesMap.js +93 -0
- package/dist/esm/cli/ssrPlugin.js +6 -3
- package/dist/esm/cli/utils.js +13 -8
- package/dist/esm/cli/utils.spec.js +5 -6
- package/dist/esm/constant.js +23 -1
- package/dist/esm/interfaces/route.js +0 -0
- package/dist/esm/runtime/dataLoader/plugin-inject-assets.js +71 -0
- package/dist/esm/runtime/dataLoader/plugin.js +97 -0
- package/dist/esm/runtime/dataLoader/utils.js +86 -0
- package/dist/esm/runtime/index.js +3 -1
- package/dist/esm/runtime/withMFRouteId.js +7 -0
- package/dist/esm/ssr-runtime/plugin.js +8 -11
- package/dist/esm/types/modern.js +0 -0
- package/dist/esm-node/cli/dataLoader/ast/constant.js +18 -0
- package/dist/esm-node/cli/dataLoader/ast/generateRoutes.js +109 -0
- package/dist/esm-node/cli/dataLoader/ast/index.js +4 -0
- package/dist/esm-node/cli/dataLoader/clearMFCache.js +33 -0
- package/dist/esm-node/cli/dataLoader/generateRouteFile.js +113 -0
- package/dist/esm-node/cli/dataLoader/patchMFConfig.js +103 -0
- package/dist/esm-node/cli/dataLoader/plugin.js +184 -0
- package/dist/esm-node/cli/index.js +5 -1
- package/dist/esm-node/cli/mfRuntimePlugins/{inject-node-fetch.js → node-fetch.js} +3 -3
- package/dist/esm-node/cli/mfRuntimePlugins/node.js +11 -0
- package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +40 -38
- package/dist/esm-node/cli/server/dataLoaderPlugin.js +61 -0
- package/dist/esm-node/cli/server/fetchRemoteFullRoutesMap.js +47 -0
- package/dist/esm-node/cli/ssrPlugin.js +5 -2
- package/dist/esm-node/cli/utils.js +9 -5
- package/dist/esm-node/cli/utils.spec.js +5 -6
- package/dist/esm-node/constant.js +23 -1
- package/dist/esm-node/interfaces/route.js +0 -0
- package/dist/esm-node/runtime/dataLoader/plugin-inject-assets.js +68 -0
- package/dist/esm-node/runtime/dataLoader/plugin.js +51 -0
- package/dist/esm-node/runtime/dataLoader/utils.js +86 -0
- package/dist/esm-node/runtime/index.js +3 -1
- package/dist/esm-node/runtime/withMFRouteId.js +7 -0
- package/dist/esm-node/ssr-runtime/plugin.js +7 -8
- package/dist/esm-node/types/modern.js +0 -0
- package/dist/types/cli/dataLoader/ast/constant.d.ts +8 -0
- package/dist/types/cli/dataLoader/ast/generateRoutes.d.ts +5 -0
- package/dist/types/cli/dataLoader/ast/index.d.ts +1 -0
- package/dist/types/cli/dataLoader/clearMFCache.d.ts +1 -0
- package/dist/types/cli/dataLoader/generateRouteFile.d.ts +10 -0
- package/dist/types/cli/dataLoader/patchMFConfig.d.ts +10 -0
- package/dist/types/cli/dataLoader/plugin.d.ts +6 -0
- package/dist/types/cli/mfRuntimePlugins/node.d.ts +3 -0
- package/dist/types/cli/server/dataLoaderPlugin.d.ts +10 -0
- package/dist/types/cli/server/fetchRemoteFullRoutesMap.d.ts +11 -0
- package/dist/types/cli/utils.d.ts +2 -0
- package/dist/types/constant.d.ts +11 -0
- package/dist/types/interfaces/route.d.ts +12 -0
- package/dist/types/runtime/dataLoader/plugin-inject-assets.d.ts +4 -0
- package/dist/types/runtime/dataLoader/plugin.d.ts +5 -0
- package/dist/types/runtime/dataLoader/utils.d.ts +22 -0
- package/dist/types/runtime/index.d.ts +1 -0
- package/dist/types/runtime/withMFRouteId.d.ts +1 -0
- package/dist/types/ssr-runtime/plugin.d.ts +3 -1
- package/dist/types/types/index.d.ts +8 -0
- package/dist/types/types/modern.d.ts +12 -0
- package/package.json +48 -11
- package/dist/esm/cli/constant.js +0 -4
- package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +0 -25
- package/dist/esm-node/cli/constant.js +0 -4
- package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +0 -23
- package/dist/types/cli/constant.d.ts +0 -1
- package/dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts +0 -3
- /package/dist/types/cli/mfRuntimePlugins/{inject-node-fetch.d.ts → node-fetch.d.ts} +0 -0
|
@@ -47,7 +47,9 @@ const replaceRemoteUrl = (mfConfig, remoteIpStrategy) => {
|
|
|
47
47
|
if (typeof remoteObject === "string") {
|
|
48
48
|
return;
|
|
49
49
|
}
|
|
50
|
-
|
|
50
|
+
if ("entry" in remoteObject && typeof remoteObject.entry === "string") {
|
|
51
|
+
remoteObject.entry = remoteObject.entry.replace(LOCALHOST, ipv4);
|
|
52
|
+
}
|
|
51
53
|
});
|
|
52
54
|
} else if (typeof mfConfig.remotes !== "string") {
|
|
53
55
|
handleRemoteObject(mfConfig.remotes);
|
|
@@ -96,17 +98,18 @@ const patchMFConfig = (mfConfig, isServer, remoteIpStrategy) => {
|
|
|
96
98
|
const runtimePlugins = [
|
|
97
99
|
...mfConfig.runtimePlugins || []
|
|
98
100
|
];
|
|
101
|
+
var _mfConfig_shareStrategy;
|
|
102
|
+
mfConfig.shareStrategy = (_mfConfig_shareStrategy = mfConfig.shareStrategy) !== null && _mfConfig_shareStrategy !== void 0 ? _mfConfig_shareStrategy : "loaded-first";
|
|
99
103
|
patchDTSConfig(mfConfig, isServer);
|
|
100
|
-
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"), runtimePlugins);
|
|
101
104
|
if (isDev) {
|
|
102
105
|
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/resolve-entry-ipv4.js"), runtimePlugins);
|
|
103
106
|
}
|
|
104
107
|
if (isServer) {
|
|
105
|
-
injectRuntimePlugins(
|
|
108
|
+
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/node.js"), runtimePlugins);
|
|
106
109
|
if (isDev) {
|
|
107
110
|
injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
|
|
108
111
|
}
|
|
109
|
-
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/
|
|
112
|
+
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/node-fetch.js"), runtimePlugins);
|
|
110
113
|
if (!mfConfig.library) {
|
|
111
114
|
mfConfig.library = {
|
|
112
115
|
type: "commonjs-module",
|
|
@@ -291,5 +294,6 @@ export {
|
|
|
291
294
|
getMFConfig,
|
|
292
295
|
patchBundlerConfig,
|
|
293
296
|
patchIgnoreWarning,
|
|
294
|
-
patchMFConfig
|
|
297
|
+
patchMFConfig,
|
|
298
|
+
replaceRemoteUrl
|
|
295
299
|
};
|
|
@@ -36,10 +36,10 @@ describe("patchMFConfig", async () => {
|
|
|
36
36
|
remote: `http://${ipv4}:3000/remoteEntry.js`
|
|
37
37
|
},
|
|
38
38
|
remoteType: "script",
|
|
39
|
+
shareStrategy: "loaded-first",
|
|
39
40
|
runtimePlugins: [
|
|
40
|
-
path.resolve(__dirname, "./mfRuntimePlugins/
|
|
41
|
-
|
|
42
|
-
path.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js")
|
|
41
|
+
path.resolve(__dirname, "./mfRuntimePlugins/node.js"),
|
|
42
|
+
path.resolve(__dirname, "./mfRuntimePlugins/node-fetch.js")
|
|
43
43
|
],
|
|
44
44
|
shared: {
|
|
45
45
|
react: {
|
|
@@ -64,9 +64,8 @@ describe("patchMFConfig", async () => {
|
|
|
64
64
|
remote: `http://${ipv4}:3000/remoteEntry.js`
|
|
65
65
|
},
|
|
66
66
|
remoteType: "script",
|
|
67
|
-
runtimePlugins: [
|
|
68
|
-
|
|
69
|
-
],
|
|
67
|
+
runtimePlugins: [],
|
|
68
|
+
shareStrategy: "loaded-first",
|
|
70
69
|
shared: {
|
|
71
70
|
react: {
|
|
72
71
|
eager: true,
|
|
@@ -1,8 +1,30 @@
|
|
|
1
1
|
const MODERN_JS_SERVER_DIR = "bundles";
|
|
2
2
|
const LOCALHOST = "localhost";
|
|
3
3
|
const PLUGIN_IDENTIFIER = "[ Modern.js Module Federation ]";
|
|
4
|
+
const isDev = process.env.NODE_ENV === "development";
|
|
5
|
+
const MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME = "routes";
|
|
6
|
+
const MODERN_JS_ROUTE_SERVER_LOADER = "route-server-loaders";
|
|
7
|
+
const META_NAME = "modern-js";
|
|
8
|
+
const FOLD_IDENTIFIER = "@mf";
|
|
9
|
+
const SEPARATOR = "_";
|
|
10
|
+
const MF_ROUTES = "mf-routes";
|
|
11
|
+
const DEFAULT_ENTRY = "main";
|
|
12
|
+
const DEFAULT_LAYOUT = "layout";
|
|
13
|
+
const MF_JSON = "mf.json";
|
|
14
|
+
const ROUTE_ID = "ROUTE_ID";
|
|
4
15
|
export {
|
|
16
|
+
DEFAULT_ENTRY,
|
|
17
|
+
DEFAULT_LAYOUT,
|
|
18
|
+
FOLD_IDENTIFIER,
|
|
5
19
|
LOCALHOST,
|
|
20
|
+
META_NAME,
|
|
21
|
+
MF_JSON,
|
|
22
|
+
MF_ROUTES,
|
|
23
|
+
MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME,
|
|
24
|
+
MODERN_JS_ROUTE_SERVER_LOADER,
|
|
6
25
|
MODERN_JS_SERVER_DIR,
|
|
7
|
-
PLUGIN_IDENTIFIER
|
|
26
|
+
PLUGIN_IDENTIFIER,
|
|
27
|
+
ROUTE_ID,
|
|
28
|
+
SEPARATOR,
|
|
29
|
+
isDev
|
|
8
30
|
};
|
|
File without changes
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
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
|
+
};
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import hoistNonReactStatics from "hoist-non-react-statics";
|
|
3
3
|
import { SSRLiveReload } from "./SSRLiveReload";
|
|
4
|
-
const mfSSRPlugin = () => ({
|
|
4
|
+
const mfSSRPlugin = ({ metaName }) => ({
|
|
5
5
|
name: "@module-federation/modern-js",
|
|
6
|
+
pre: [
|
|
7
|
+
`@${metaName}/plugin-router`
|
|
8
|
+
],
|
|
6
9
|
setup: () => {
|
|
7
10
|
return {
|
|
8
|
-
async
|
|
11
|
+
async beforeRender() {
|
|
9
12
|
if (typeof window !== "undefined") {
|
|
10
|
-
return
|
|
11
|
-
context
|
|
12
|
-
});
|
|
13
|
+
return;
|
|
13
14
|
}
|
|
14
15
|
globalThis.shouldUpdate = false;
|
|
15
16
|
const nodeUtils = await import("@module-federation/node/utils");
|
|
@@ -19,9 +20,7 @@ const mfSSRPlugin = () => ({
|
|
|
19
20
|
await nodeUtils.flushChunks();
|
|
20
21
|
globalThis.shouldUpdate = true;
|
|
21
22
|
}
|
|
22
|
-
return
|
|
23
|
-
context
|
|
24
|
-
});
|
|
23
|
+
return;
|
|
25
24
|
},
|
|
26
25
|
wrapRoot(App) {
|
|
27
26
|
const AppWrapper = (props) => /* @__PURE__ */ _jsxs(_Fragment, {
|
|
File without changes
|
|
@@ -0,0 +1,8 @@
|
|
|
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";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { generateRoutes } from './generateRoutes';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function clearMFCache(): void;
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
}>;
|
|
@@ -0,0 +1,10 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,6 @@
|
|
|
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 };
|
|
@@ -0,0 +1,10 @@
|
|
|
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;
|
|
@@ -0,0 +1,11 @@
|
|
|
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[];
|
|
@@ -2,8 +2,10 @@ import type { webpack, UserConfig, AppTools, Rspack, Bundler } from '@modern-js/
|
|
|
2
2
|
import { moduleFederationPlugin } from '@module-federation/sdk';
|
|
3
3
|
import { PluginOptions } from '../types';
|
|
4
4
|
import { BundlerConfig } from '../interfaces/bundler';
|
|
5
|
+
import type { init } from '@module-federation/enhanced/runtime';
|
|
5
6
|
export type ConfigType<T> = T extends 'webpack' ? webpack.Configuration : T extends 'rspack' ? Rspack.Configuration : never;
|
|
6
7
|
export declare const getMFConfig: (userConfig: PluginOptions) => Promise<moduleFederationPlugin.ModuleFederationPluginOptions>;
|
|
8
|
+
export declare const replaceRemoteUrl: (mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions | Parameters<typeof init>[0], remoteIpStrategy?: "ipv4" | "inherit") => void;
|
|
7
9
|
export declare const patchMFConfig: (mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions, isServer: boolean, remoteIpStrategy?: "ipv4" | "inherit") => moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
8
10
|
export declare function patchIgnoreWarning<T extends Bundler>(bundlerConfig: BundlerConfig<T>): void;
|
|
9
11
|
export declare function patchBundlerConfig<T extends Bundler>(options: {
|
package/dist/types/constant.d.ts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
1
|
export declare const MODERN_JS_SERVER_DIR = "bundles";
|
|
2
2
|
export declare const LOCALHOST = "localhost";
|
|
3
3
|
export declare const PLUGIN_IDENTIFIER = "[ Modern.js Module Federation ]";
|
|
4
|
+
export declare const isDev: boolean;
|
|
5
|
+
export declare const MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME = "routes";
|
|
6
|
+
export declare const MODERN_JS_ROUTE_SERVER_LOADER = "route-server-loaders";
|
|
7
|
+
export declare const META_NAME = "modern-js";
|
|
8
|
+
export declare const FOLD_IDENTIFIER = "@mf";
|
|
9
|
+
export declare const SEPARATOR = "_";
|
|
10
|
+
export declare const MF_ROUTES = "mf-routes";
|
|
11
|
+
export declare const DEFAULT_ENTRY = "main";
|
|
12
|
+
export declare const DEFAULT_LAYOUT = "layout";
|
|
13
|
+
export declare const MF_JSON = "mf.json";
|
|
14
|
+
export declare const ROUTE_ID = "ROUTE_ID";
|
|
@@ -0,0 +1,22 @@
|
|
|
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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function withMFRouteId(id: string): string;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { moduleFederationPlugin } from '@module-federation/sdk';
|
|
2
2
|
import type { ModuleFederationPlugin as WebpackModuleFederationPlugin } from '@module-federation/enhanced';
|
|
3
3
|
import type { ModuleFederationPlugin as RspackModuleFederationPlugin } from '@module-federation/enhanced/rspack';
|
|
4
|
+
import type { init } from '@module-federation/enhanced/runtime';
|
|
4
5
|
export interface PluginOptions {
|
|
5
6
|
config?: moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
6
7
|
configPath?: string;
|
|
7
8
|
remoteIpStrategy?: 'ipv4' | 'inherit';
|
|
9
|
+
dataLoader?: boolean | DataLoaderOptions;
|
|
8
10
|
}
|
|
9
11
|
export interface InternalModernPluginOptions {
|
|
12
|
+
metaName?: string;
|
|
10
13
|
csrConfig?: moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
11
14
|
ssrConfig?: moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
12
15
|
distOutputDir: string;
|
|
@@ -16,3 +19,8 @@ export interface InternalModernPluginOptions {
|
|
|
16
19
|
remoteIpStrategy?: 'ipv4' | 'inherit';
|
|
17
20
|
}
|
|
18
21
|
export type BundlerPlugin = WebpackModuleFederationPlugin | RspackModuleFederationPlugin;
|
|
22
|
+
export type TransformRuntimeOptions = (mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions) => Parameters<typeof init>[0];
|
|
23
|
+
export type DataLoaderOptions = {
|
|
24
|
+
serverPlugin?: string;
|
|
25
|
+
transformRuntimeOptions?: TransformRuntimeOptions;
|
|
26
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
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 {};
|