@module-federation/modern-js 0.0.0-next-20241106033302 → 0.0.0-next-20241106063644
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/index.js +7 -2
- 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/routes/ast/constant.js +49 -0
- package/dist/cjs/cli/routes/ast/generateRoutes.js +143 -0
- package/dist/cjs/cli/{constant.js → routes/ast/index.js} +6 -6
- package/dist/cjs/cli/routes/clearMFCache.js +57 -0
- package/dist/cjs/cli/routes/exportRoutePlugin.js +77 -0
- package/dist/cjs/cli/routes/importRoutesPlugin.js +120 -0
- package/dist/cjs/cli/routes/plugin.js +157 -0
- package/dist/cjs/cli/routes/traverseRouteFiles.js +148 -0
- package/dist/cjs/cli/routes/utils.js +168 -0
- package/dist/cjs/cli/server/fetchRemoteFullRoutesMap.js +72 -0
- package/dist/cjs/cli/server/fetchRoutePlugin.js +82 -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/index.js +4 -1
- package/dist/cjs/runtime/routes/plugin-inject-assets.js +92 -0
- package/dist/cjs/runtime/routes/plugin.js +75 -0
- package/dist/cjs/runtime/routes/utils.js +115 -0
- 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/cjs/types/routes.js +16 -0
- package/dist/esm/cli/index.js +7 -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/routes/ast/constant.js +18 -0
- package/dist/esm/cli/routes/ast/generateRoutes.js +110 -0
- package/dist/esm/cli/routes/ast/index.js +4 -0
- package/dist/esm/cli/routes/clearMFCache.js +34 -0
- package/dist/esm/cli/routes/exportRoutePlugin.js +79 -0
- package/dist/esm/cli/routes/importRoutesPlugin.js +122 -0
- package/dist/esm/cli/routes/plugin.js +266 -0
- package/dist/esm/cli/routes/traverseRouteFiles.js +313 -0
- package/dist/esm/cli/routes/utils.js +130 -0
- package/dist/esm/cli/server/fetchRemoteFullRoutesMap.js +93 -0
- package/dist/esm/cli/server/fetchRoutePlugin.js +105 -0
- package/dist/esm/cli/ssrPlugin.js +6 -3
- package/dist/esm/cli/utils.js +9 -5
- 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/index.js +3 -1
- package/dist/esm/runtime/routes/plugin-inject-assets.js +71 -0
- package/dist/esm/runtime/routes/plugin.js +97 -0
- package/dist/esm/runtime/routes/utils.js +86 -0
- 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/types/routes.js +0 -0
- package/dist/esm-node/cli/index.js +7 -2
- 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/routes/ast/constant.js +18 -0
- package/dist/esm-node/cli/routes/ast/generateRoutes.js +109 -0
- package/dist/esm-node/cli/routes/ast/index.js +4 -0
- package/dist/esm-node/cli/routes/clearMFCache.js +33 -0
- package/dist/esm-node/cli/routes/exportRoutePlugin.js +53 -0
- package/dist/esm-node/cli/routes/importRoutesPlugin.js +96 -0
- package/dist/esm-node/cli/routes/plugin.js +123 -0
- package/dist/esm-node/cli/routes/traverseRouteFiles.js +113 -0
- package/dist/esm-node/cli/routes/utils.js +133 -0
- package/dist/esm-node/cli/server/fetchRemoteFullRoutesMap.js +47 -0
- package/dist/esm-node/cli/server/fetchRoutePlugin.js +62 -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/index.js +3 -1
- package/dist/esm-node/runtime/routes/plugin-inject-assets.js +68 -0
- package/dist/esm-node/runtime/routes/plugin.js +51 -0
- package/dist/esm-node/runtime/routes/utils.js +86 -0
- 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/esm-node/types/routes.js +0 -0
- package/dist/types/cli/mfRuntimePlugins/node.d.ts +3 -0
- package/dist/types/cli/routes/ast/constant.d.ts +8 -0
- package/dist/types/cli/routes/ast/generateRoutes.d.ts +5 -0
- package/dist/types/cli/routes/ast/index.d.ts +1 -0
- package/dist/types/cli/routes/clearMFCache.d.ts +1 -0
- package/dist/types/cli/routes/exportRoutePlugin.d.ts +4 -0
- package/dist/types/cli/routes/importRoutesPlugin.d.ts +4 -0
- package/dist/types/cli/routes/plugin.d.ts +4 -0
- package/dist/types/cli/routes/traverseRouteFiles.d.ts +11 -0
- package/dist/types/cli/routes/utils.d.ts +11 -0
- package/dist/types/cli/server/fetchRemoteFullRoutesMap.d.ts +11 -0
- package/dist/types/cli/server/fetchRoutePlugin.d.ts +10 -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/index.d.ts +1 -0
- package/dist/types/runtime/routes/plugin-inject-assets.d.ts +4 -0
- package/dist/types/runtime/routes/plugin.d.ts +5 -0
- package/dist/types/runtime/routes/utils.d.ts +22 -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 +3 -1
- package/dist/types/types/modern.d.ts +12 -0
- package/dist/types/types/routes.d.ts +19 -0
- package/package.json +42 -5
- 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
package/dist/esm/cli/utils.js
CHANGED
|
@@ -81,7 +81,9 @@ var replaceRemoteUrl = function(mfConfig, remoteIpStrategy) {
|
|
|
81
81
|
if (typeof remoteObject === "string") {
|
|
82
82
|
return;
|
|
83
83
|
}
|
|
84
|
-
|
|
84
|
+
if ("entry" in remoteObject && typeof remoteObject.entry === "string") {
|
|
85
|
+
remoteObject.entry = remoteObject.entry.replace(LOCALHOST, ipv4);
|
|
86
|
+
}
|
|
85
87
|
});
|
|
86
88
|
} else if (typeof mfConfig.remotes !== "string") {
|
|
87
89
|
handleRemoteObject(mfConfig.remotes);
|
|
@@ -128,17 +130,18 @@ var patchMFConfig = function(mfConfig, isServer, remoteIpStrategy) {
|
|
|
128
130
|
throw new Error("".concat(PLUGIN_IDENTIFIER, " mfConfig.name can not be empty!"));
|
|
129
131
|
}
|
|
130
132
|
var runtimePlugins = _to_consumable_array(mfConfig.runtimePlugins || []);
|
|
133
|
+
var _mfConfig_shareStrategy;
|
|
134
|
+
mfConfig.shareStrategy = (_mfConfig_shareStrategy = mfConfig.shareStrategy) !== null && _mfConfig_shareStrategy !== void 0 ? _mfConfig_shareStrategy : "loaded-first";
|
|
131
135
|
patchDTSConfig(mfConfig, isServer);
|
|
132
|
-
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"), runtimePlugins);
|
|
133
136
|
if (isDev) {
|
|
134
137
|
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/resolve-entry-ipv4.js"), runtimePlugins);
|
|
135
138
|
}
|
|
136
139
|
if (isServer) {
|
|
137
|
-
injectRuntimePlugins(
|
|
140
|
+
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/node.js"), runtimePlugins);
|
|
138
141
|
if (isDev) {
|
|
139
142
|
injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
|
|
140
143
|
}
|
|
141
|
-
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/
|
|
144
|
+
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/node-fetch.js"), runtimePlugins);
|
|
142
145
|
if (!mfConfig.library) {
|
|
143
146
|
mfConfig.library = {
|
|
144
147
|
type: "commonjs-module",
|
|
@@ -341,5 +344,6 @@ export {
|
|
|
341
344
|
getMFConfig,
|
|
342
345
|
patchBundlerConfig,
|
|
343
346
|
patchIgnoreWarning,
|
|
344
|
-
patchMFConfig
|
|
347
|
+
patchMFConfig,
|
|
348
|
+
replaceRemoteUrl
|
|
345
349
|
};
|
|
@@ -41,10 +41,10 @@ describe("patchMFConfig", /* @__PURE__ */ _async_to_generator(function() {
|
|
|
41
41
|
remote: "http://".concat(ipv4, ":3000/remoteEntry.js")
|
|
42
42
|
},
|
|
43
43
|
remoteType: "script",
|
|
44
|
+
shareStrategy: "loaded-first",
|
|
44
45
|
runtimePlugins: [
|
|
45
|
-
path.resolve(__dirname, "./mfRuntimePlugins/
|
|
46
|
-
|
|
47
|
-
path.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js")
|
|
46
|
+
path.resolve(__dirname, "./mfRuntimePlugins/node.js"),
|
|
47
|
+
path.resolve(__dirname, "./mfRuntimePlugins/node-fetch.js")
|
|
48
48
|
],
|
|
49
49
|
shared: {
|
|
50
50
|
react: {
|
|
@@ -75,9 +75,8 @@ describe("patchMFConfig", /* @__PURE__ */ _async_to_generator(function() {
|
|
|
75
75
|
remote: "http://".concat(ipv4, ":3000/remoteEntry.js")
|
|
76
76
|
},
|
|
77
77
|
remoteType: "script",
|
|
78
|
-
runtimePlugins: [
|
|
79
|
-
|
|
80
|
-
],
|
|
78
|
+
runtimePlugins: [],
|
|
79
|
+
shareStrategy: "loaded-first",
|
|
81
80
|
shared: {
|
|
82
81
|
react: {
|
|
83
82
|
eager: true,
|
package/dist/esm/constant.js
CHANGED
|
@@ -1,8 +1,30 @@
|
|
|
1
1
|
var MODERN_JS_SERVER_DIR = "bundles";
|
|
2
2
|
var LOCALHOST = "localhost";
|
|
3
3
|
var PLUGIN_IDENTIFIER = "[ Modern.js Module Federation ]";
|
|
4
|
+
var isDev = process.env.NODE_ENV === "development";
|
|
5
|
+
var MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME = "routes";
|
|
6
|
+
var MODERN_JS_ROUTE_SERVER_LOADER = "route-server-loaders";
|
|
7
|
+
var META_NAME = "modern-js";
|
|
8
|
+
var FOLD_IDENTIFIER = "@mf";
|
|
9
|
+
var SEPARATOR = "_";
|
|
10
|
+
var MF_ROUTES = "mf-routes";
|
|
11
|
+
var DEFAULT_ENTRY = "main";
|
|
12
|
+
var DEFAULT_LAYOUT = "layout";
|
|
13
|
+
var MF_JSON = "mf.json";
|
|
14
|
+
var 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,71 @@
|
|
|
1
|
+
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useContext } from "react";
|
|
4
|
+
import { getInstance } from "@module-federation/enhanced/runtime";
|
|
5
|
+
import { collectSSRAssets } from "../createRemoteSSRComponent";
|
|
6
|
+
import { RuntimeReactContext } from "@meta/runtime";
|
|
7
|
+
import { decodeId, getRemoteId } from "./utils";
|
|
8
|
+
function traverseRoutes(routes, remoteNames) {
|
|
9
|
+
routes.forEach(function(route) {
|
|
10
|
+
route.id && remoteNames.add(decodeId(route.id));
|
|
11
|
+
route.children && traverseRoutes(route.children, remoteNames);
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
var ssrDataLoaderInjectAssetsPlugin = function(param) {
|
|
15
|
+
var metaName = param.metaName;
|
|
16
|
+
return {
|
|
17
|
+
name: "@modern-js/plugin-mf-routes-inject-assets",
|
|
18
|
+
pre: [
|
|
19
|
+
"@modern-js/plugin-mf-routes"
|
|
20
|
+
],
|
|
21
|
+
post: [
|
|
22
|
+
"@module-federation/modern-js",
|
|
23
|
+
"@".concat(metaName, "/plugin-router")
|
|
24
|
+
],
|
|
25
|
+
setup: function() {
|
|
26
|
+
return {
|
|
27
|
+
wrapRoot: function wrapRoot() {
|
|
28
|
+
var AppWrapper = function(props) {
|
|
29
|
+
var instance = getInstance();
|
|
30
|
+
if (!instance || !instance.options.remotes.length) {
|
|
31
|
+
return /* @__PURE__ */ _jsx(_Fragment, {
|
|
32
|
+
children: props.children
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
var context = useContext(RuntimeReactContext);
|
|
36
|
+
var remotes = instance.options.remotes;
|
|
37
|
+
var remoteNames = /* @__PURE__ */ new Set();
|
|
38
|
+
traverseRoutes(context.routes, remoteNames);
|
|
39
|
+
var remoteIds = _to_consumable_array(remoteNames).reduce(function(sum, cur) {
|
|
40
|
+
var matchRemote = remotes.find(function(r) {
|
|
41
|
+
return r.name === cur;
|
|
42
|
+
});
|
|
43
|
+
if (matchRemote) {
|
|
44
|
+
sum.add(getRemoteId(cur));
|
|
45
|
+
}
|
|
46
|
+
return sum;
|
|
47
|
+
}, /* @__PURE__ */ new Set());
|
|
48
|
+
var assets = [];
|
|
49
|
+
remoteIds.forEach(function(remoteId) {
|
|
50
|
+
var _assets;
|
|
51
|
+
(_assets = assets).push.apply(_assets, _to_consumable_array(collectSSRAssets({
|
|
52
|
+
id: remoteId,
|
|
53
|
+
injectScript: false
|
|
54
|
+
})));
|
|
55
|
+
});
|
|
56
|
+
return /* @__PURE__ */ _jsxs(_Fragment, {
|
|
57
|
+
children: [
|
|
58
|
+
assets,
|
|
59
|
+
props.children
|
|
60
|
+
]
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
return AppWrapper;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
export {
|
|
70
|
+
ssrDataLoaderInjectAssetsPlugin
|
|
71
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
|
+
import { getInstance } from "@module-federation/enhanced/runtime";
|
|
4
|
+
import { MF_ROUTES, DEFAULT_ENTRY } from "../../constant";
|
|
5
|
+
import { injectRemoteRoutes } from "./utils";
|
|
6
|
+
var ssrDataLoaderPlugin = function(param) {
|
|
7
|
+
var metaName = param.metaName, dataLoaderRemotes = param.dataLoaderRemotes;
|
|
8
|
+
return {
|
|
9
|
+
name: "@modern-js/plugin-mf-routes",
|
|
10
|
+
post: [
|
|
11
|
+
"@".concat(metaName, "/plugin-router"),
|
|
12
|
+
"@module-federation/modern-js"
|
|
13
|
+
],
|
|
14
|
+
setup: function() {
|
|
15
|
+
var remoteRoutesMap = {};
|
|
16
|
+
return {
|
|
17
|
+
beforeRender: function beforeRender() {
|
|
18
|
+
return _async_to_generator(function() {
|
|
19
|
+
var instance;
|
|
20
|
+
return _ts_generator(this, function(_state) {
|
|
21
|
+
switch (_state.label) {
|
|
22
|
+
case 0:
|
|
23
|
+
if (Object.keys(remoteRoutesMap).length) {
|
|
24
|
+
return [
|
|
25
|
+
2
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
instance = getInstance();
|
|
29
|
+
if (!instance) {
|
|
30
|
+
return [
|
|
31
|
+
2
|
|
32
|
+
];
|
|
33
|
+
}
|
|
34
|
+
if (!instance.options.remotes.length) {
|
|
35
|
+
return [
|
|
36
|
+
2
|
|
37
|
+
];
|
|
38
|
+
}
|
|
39
|
+
return [
|
|
40
|
+
4,
|
|
41
|
+
Promise.all(instance.options.remotes.map(function() {
|
|
42
|
+
var _ref = _async_to_generator(function(remote) {
|
|
43
|
+
var remoteId, routes;
|
|
44
|
+
return _ts_generator(this, function(_state2) {
|
|
45
|
+
switch (_state2.label) {
|
|
46
|
+
case 0:
|
|
47
|
+
if (!dataLoaderRemotes.includes(remote.name)) {
|
|
48
|
+
return [
|
|
49
|
+
2
|
|
50
|
+
];
|
|
51
|
+
}
|
|
52
|
+
remoteId = "".concat(remote.name, "/").concat(DEFAULT_ENTRY, "/").concat(MF_ROUTES);
|
|
53
|
+
return [
|
|
54
|
+
4,
|
|
55
|
+
instance.loadRemote(remoteId)
|
|
56
|
+
];
|
|
57
|
+
case 1:
|
|
58
|
+
routes = _state2.sent().routes;
|
|
59
|
+
remoteRoutesMap[remote.name] = {
|
|
60
|
+
routes
|
|
61
|
+
};
|
|
62
|
+
return [
|
|
63
|
+
2
|
|
64
|
+
];
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
return function(remote) {
|
|
69
|
+
return _ref.apply(this, arguments);
|
|
70
|
+
};
|
|
71
|
+
}()))
|
|
72
|
+
];
|
|
73
|
+
case 1:
|
|
74
|
+
_state.sent();
|
|
75
|
+
return [
|
|
76
|
+
2
|
|
77
|
+
];
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
})();
|
|
81
|
+
},
|
|
82
|
+
// runtime plugin not save route , so it needs to inject again when trigger
|
|
83
|
+
modifyRoutes: function(routes) {
|
|
84
|
+
injectRemoteRoutes({
|
|
85
|
+
entry: {
|
|
86
|
+
routes
|
|
87
|
+
}
|
|
88
|
+
}, remoteRoutesMap);
|
|
89
|
+
return routes;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
export {
|
|
96
|
+
ssrDataLoaderPlugin
|
|
97
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { encodeName, decodeName } from "@module-federation/sdk";
|
|
2
|
+
import { DEFAULT_ENTRY, DEFAULT_LAYOUT, MF_ROUTES } from "../../constant";
|
|
3
|
+
var SPLIT_SYMBOL = "@";
|
|
4
|
+
function transformName2Prefix(name) {
|
|
5
|
+
return "".concat(encodeName(name, "", false)).concat(SPLIT_SYMBOL);
|
|
6
|
+
}
|
|
7
|
+
function decodeId(prefix) {
|
|
8
|
+
var 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
|
+
var remoteName = decodeId(route.id);
|
|
16
|
+
var remoteRouteObj = remoteRoutesMap[remoteName];
|
|
17
|
+
if (!remoteRouteObj) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
var remoteRoutes = remoteRouteObj.routes[0];
|
|
21
|
+
return {
|
|
22
|
+
routes: remoteRoutes,
|
|
23
|
+
name: remoteName,
|
|
24
|
+
pathName: route.path
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function getRemoteLayoutId(remoteName) {
|
|
28
|
+
var prefix = transformName2Prefix(remoteName);
|
|
29
|
+
return "".concat(prefix).concat(DEFAULT_LAYOUT);
|
|
30
|
+
}
|
|
31
|
+
function getRemoteId(remoteName) {
|
|
32
|
+
return "".concat(remoteName, "/").concat(DEFAULT_ENTRY, "/").concat(MF_ROUTES);
|
|
33
|
+
}
|
|
34
|
+
function injectRemoteRoutes(initialRoutes, remoteRoutesMap) {
|
|
35
|
+
var traverse = function(route) {
|
|
36
|
+
var _route_children;
|
|
37
|
+
var remoteRoutesInfos = getRemoteRoutesInfos(route, remoteRoutesMap);
|
|
38
|
+
if (remoteRoutesInfos) {
|
|
39
|
+
var routes = remoteRoutesInfos.routes, pathName = remoteRoutesInfos.pathName;
|
|
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(function(r) {
|
|
62
|
+
traverse(r);
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
Object.keys(initialRoutes).forEach(function(entryName) {
|
|
66
|
+
var routes = initialRoutes[entryName];
|
|
67
|
+
if (Array.isArray(routes)) {
|
|
68
|
+
routes.forEach(function(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(function(r) {
|
|
74
|
+
traverse(r);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
export {
|
|
80
|
+
decodeId,
|
|
81
|
+
getRemoteId,
|
|
82
|
+
getRemoteLayoutId,
|
|
83
|
+
getRemoteRoutesInfos,
|
|
84
|
+
injectRemoteRoutes,
|
|
85
|
+
transformName2Prefix
|
|
86
|
+
};
|
|
@@ -4,13 +4,16 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
|
4
4
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
5
5
|
import hoistNonReactStatics from "hoist-non-react-statics";
|
|
6
6
|
import { SSRLiveReload } from "./SSRLiveReload";
|
|
7
|
-
var mfSSRPlugin = function() {
|
|
7
|
+
var mfSSRPlugin = function(param) {
|
|
8
|
+
var metaName = param.metaName;
|
|
8
9
|
return {
|
|
9
10
|
name: "@module-federation/modern-js",
|
|
11
|
+
pre: [
|
|
12
|
+
"@".concat(metaName, "/plugin-router")
|
|
13
|
+
],
|
|
10
14
|
setup: function() {
|
|
11
15
|
return {
|
|
12
|
-
|
|
13
|
-
var context = param.context;
|
|
16
|
+
beforeRender: function beforeRender() {
|
|
14
17
|
return _async_to_generator(function() {
|
|
15
18
|
var nodeUtils, shouldUpdate;
|
|
16
19
|
return _ts_generator(this, function(_state) {
|
|
@@ -18,10 +21,7 @@ var mfSSRPlugin = function() {
|
|
|
18
21
|
case 0:
|
|
19
22
|
if (typeof window !== "undefined") {
|
|
20
23
|
return [
|
|
21
|
-
2
|
|
22
|
-
next({
|
|
23
|
-
context
|
|
24
|
-
})
|
|
24
|
+
2
|
|
25
25
|
];
|
|
26
26
|
}
|
|
27
27
|
globalThis.shouldUpdate = false;
|
|
@@ -53,10 +53,7 @@ var mfSSRPlugin = function() {
|
|
|
53
53
|
_state.label = 4;
|
|
54
54
|
case 4:
|
|
55
55
|
return [
|
|
56
|
-
2
|
|
57
|
-
next({
|
|
58
|
-
context
|
|
59
|
-
})
|
|
56
|
+
2
|
|
60
57
|
];
|
|
61
58
|
}
|
|
62
59
|
});
|
|
File without changes
|
|
File without changes
|
|
@@ -2,6 +2,7 @@ import { ModuleFederationPlugin as WebpackModuleFederationPlugin, AsyncBoundaryP
|
|
|
2
2
|
import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
|
|
3
3
|
import { moduleFederationConfigPlugin } from "./configPlugin";
|
|
4
4
|
import { moduleFederationSSRPlugin } from "./ssrPlugin";
|
|
5
|
+
import { moduleFederationRoutesPlugin } from "./routes/plugin";
|
|
5
6
|
const moduleFederationPlugin = (userConfig = {}) => {
|
|
6
7
|
const internalModernPluginOptions = {
|
|
7
8
|
csrConfig: void 0,
|
|
@@ -10,7 +11,7 @@ const moduleFederationPlugin = (userConfig = {}) => {
|
|
|
10
11
|
nodePlugin: void 0,
|
|
11
12
|
distOutputDir: "",
|
|
12
13
|
originPluginOptions: userConfig,
|
|
13
|
-
remoteIpStrategy:
|
|
14
|
+
remoteIpStrategy: void 0
|
|
14
15
|
};
|
|
15
16
|
return {
|
|
16
17
|
name: "@modern-js/plugin-module-federation",
|
|
@@ -53,7 +54,11 @@ const moduleFederationPlugin = (userConfig = {}) => {
|
|
|
53
54
|
},
|
|
54
55
|
usePlugins: [
|
|
55
56
|
moduleFederationConfigPlugin(internalModernPluginOptions),
|
|
56
|
-
moduleFederationSSRPlugin(internalModernPluginOptions)
|
|
57
|
+
moduleFederationSSRPlugin(internalModernPluginOptions),
|
|
58
|
+
moduleFederationRoutesPlugin({
|
|
59
|
+
userConfig,
|
|
60
|
+
internalOptions: internalModernPluginOptions
|
|
61
|
+
})
|
|
57
62
|
]
|
|
58
63
|
};
|
|
59
64
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import nodeFetch from "node-fetch";
|
|
2
2
|
const injectNodeFetchPlugin = () => ({
|
|
3
|
-
name: "
|
|
3
|
+
name: "node-fetch-plugin",
|
|
4
4
|
beforeInit(args) {
|
|
5
5
|
if (!globalThis.fetch) {
|
|
6
6
|
globalThis.fetch = nodeFetch;
|
|
@@ -8,7 +8,7 @@ const injectNodeFetchPlugin = () => ({
|
|
|
8
8
|
return args;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
var
|
|
11
|
+
var node_fetch_default = injectNodeFetchPlugin;
|
|
12
12
|
export {
|
|
13
|
-
|
|
13
|
+
node_fetch_default as default
|
|
14
14
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
};
|
|
@@ -16,46 +16,48 @@ function replaceObjectLocalhost(key, obj) {
|
|
|
16
16
|
function replaceLocalhost(url) {
|
|
17
17
|
return url.replace(LOCALHOST, ipv4);
|
|
18
18
|
}
|
|
19
|
-
const resolveEntryIpv4Plugin = () =>
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
19
|
+
const resolveEntryIpv4Plugin = () => {
|
|
20
|
+
return {
|
|
21
|
+
name: "resolve-entry-ipv4",
|
|
22
|
+
beforeRegisterRemote(args) {
|
|
23
|
+
const { remote } = args;
|
|
24
|
+
replaceObjectLocalhost("entry", remote);
|
|
25
|
+
return args;
|
|
26
|
+
},
|
|
27
|
+
async afterResolve(args) {
|
|
28
|
+
const { remoteInfo } = args;
|
|
29
|
+
replaceObjectLocalhost("entry", remoteInfo);
|
|
30
|
+
return args;
|
|
31
|
+
},
|
|
32
|
+
beforeLoadRemoteSnapshot(args) {
|
|
33
|
+
const { moduleInfo } = args;
|
|
34
|
+
if ("entry" in moduleInfo) {
|
|
35
|
+
replaceObjectLocalhost("entry", moduleInfo);
|
|
36
|
+
return args;
|
|
37
|
+
}
|
|
38
|
+
if ("version" in moduleInfo) {
|
|
39
|
+
replaceObjectLocalhost("version", moduleInfo);
|
|
40
|
+
}
|
|
41
|
+
return args;
|
|
42
|
+
},
|
|
43
|
+
loadRemoteSnapshot(args) {
|
|
44
|
+
const { remoteSnapshot } = args;
|
|
45
|
+
if ("publicPath" in remoteSnapshot) {
|
|
46
|
+
replaceObjectLocalhost("publicPath", remoteSnapshot);
|
|
47
|
+
}
|
|
48
|
+
if ("getPublicPath" in remoteSnapshot) {
|
|
49
|
+
replaceObjectLocalhost("getPublicPath", remoteSnapshot);
|
|
50
|
+
}
|
|
51
|
+
if (remoteSnapshot.remotesInfo) {
|
|
52
|
+
Object.keys(remoteSnapshot.remotesInfo).forEach((key) => {
|
|
53
|
+
const remoteInfo = remoteSnapshot.remotesInfo[key];
|
|
54
|
+
replaceObjectLocalhost("matchedVersion", remoteInfo);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
35
57
|
return args;
|
|
36
58
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
return args;
|
|
41
|
-
},
|
|
42
|
-
loadRemoteSnapshot(args) {
|
|
43
|
-
const { remoteSnapshot } = args;
|
|
44
|
-
if ("publicPath" in remoteSnapshot) {
|
|
45
|
-
replaceObjectLocalhost("publicPath", remoteSnapshot);
|
|
46
|
-
}
|
|
47
|
-
if ("getPublicPath" in remoteSnapshot) {
|
|
48
|
-
replaceObjectLocalhost("getPublicPath", remoteSnapshot);
|
|
49
|
-
}
|
|
50
|
-
if (remoteSnapshot.remotesInfo) {
|
|
51
|
-
Object.keys(remoteSnapshot.remotesInfo).forEach((key) => {
|
|
52
|
-
const remoteInfo = remoteSnapshot.remotesInfo[key];
|
|
53
|
-
replaceObjectLocalhost("matchedVersion", remoteInfo);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
return args;
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
+
};
|
|
60
|
+
};
|
|
59
61
|
var resolve_entry_ipv4_default = resolveEntryIpv4Plugin;
|
|
60
62
|
export {
|
|
61
63
|
resolve_entry_ipv4_default as default
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const IS_ROOT = "isRoot";
|
|
2
|
+
const ID = "id";
|
|
3
|
+
const COMPONENT = "component";
|
|
4
|
+
const LAZY_COMPONENT = "lazyImport";
|
|
5
|
+
const SHOULD_REVALIDATE = "shouldRevalidate";
|
|
6
|
+
const PRIVATE_COMPONENT = "_component";
|
|
7
|
+
const ELEMENT = "element";
|
|
8
|
+
const LOADER = "loader";
|
|
9
|
+
export {
|
|
10
|
+
COMPONENT,
|
|
11
|
+
ELEMENT,
|
|
12
|
+
ID,
|
|
13
|
+
IS_ROOT,
|
|
14
|
+
LAZY_COMPONENT,
|
|
15
|
+
LOADER,
|
|
16
|
+
PRIVATE_COMPONENT,
|
|
17
|
+
SHOULD_REVALIDATE
|
|
18
|
+
};
|