@module-federation/modern-js 0.0.0-next-20240911095451 → 0.0.0-next-20240912070754
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 +141 -0
- package/dist/cjs/cli/{constant.js → dataLoader/ast/index.js} +6 -6
- package/dist/cjs/cli/dataLoader/generateRouteFile.js +143 -0
- package/dist/cjs/cli/dataLoader/patchMFConfig.js +140 -0
- package/dist/cjs/cli/dataLoader/plugin.js +199 -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 +82 -0
- package/dist/cjs/cli/server/fetchRemoteFullRoutesMap.js +69 -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 +32 -2
- package/dist/cjs/interfaces/route.js +16 -0
- package/dist/cjs/runtime/dataLoader/plugin-inject-assets.js +87 -0
- package/dist/cjs/runtime/dataLoader/plugin.js +73 -0
- package/dist/cjs/runtime/dataLoader/utils.js +106 -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 +8 -8
- package/dist/esm/cli/dataLoader/ast/constant.js +18 -0
- package/dist/esm/cli/dataLoader/ast/generateRoutes.js +108 -0
- package/dist/esm/cli/dataLoader/ast/index.js +4 -0
- package/dist/esm/cli/dataLoader/generateRouteFile.js +293 -0
- package/dist/esm/cli/dataLoader/patchMFConfig.js +106 -0
- package/dist/esm/cli/dataLoader/plugin.js +220 -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 +105 -0
- package/dist/esm/cli/server/fetchRemoteFullRoutesMap.js +88 -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 +21 -1
- package/dist/esm/interfaces/route.js +0 -0
- package/dist/esm/runtime/dataLoader/plugin-inject-assets.js +67 -0
- package/dist/esm/runtime/dataLoader/plugin.js +93 -0
- package/dist/esm/runtime/dataLoader/utils.js +77 -0
- package/dist/esm/runtime/index.js +3 -1
- package/dist/esm/runtime/withMFRouteId.js +7 -0
- package/dist/esm/ssr-runtime/plugin.js +9 -11
- package/dist/esm-node/cli/dataLoader/ast/constant.js +18 -0
- package/dist/esm-node/cli/dataLoader/ast/generateRoutes.js +107 -0
- package/dist/esm-node/cli/dataLoader/ast/index.js +4 -0
- package/dist/esm-node/cli/dataLoader/generateRouteFile.js +108 -0
- package/dist/esm-node/cli/dataLoader/patchMFConfig.js +106 -0
- package/dist/esm-node/cli/dataLoader/plugin.js +164 -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 +62 -0
- package/dist/esm-node/cli/server/fetchRemoteFullRoutesMap.js +44 -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 +21 -1
- package/dist/esm-node/interfaces/route.js +0 -0
- package/dist/esm-node/runtime/dataLoader/plugin-inject-assets.js +63 -0
- package/dist/esm-node/runtime/dataLoader/plugin.js +49 -0
- package/dist/esm-node/runtime/dataLoader/utils.js +77 -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 +8 -8
- 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/generateRouteFile.d.ts +7 -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 +10 -0
- package/dist/types/cli/utils.d.ts +2 -0
- package/dist/types/constant.d.ts +10 -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 +4 -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 +9 -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
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
3
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
|
+
import { init } from "@module-federation/enhanced/runtime";
|
|
5
|
+
import { isBrowserEnv } from "@module-federation/sdk";
|
|
6
|
+
import { fetchRemoteFullRoutesMap, getSSRByRouteIds } from "./fetchRemoteFullRoutesMap";
|
|
7
|
+
import { injectRemoteRoutes } from "../../runtime/dataLoader/utils";
|
|
8
|
+
import { MF_ROUTES, DEFAULT_ENTRY, MODERN_JS_ROUTE_SERVER_LOADER } from "../../constant";
|
|
9
|
+
function dataLoaderPlugin_default(param) {
|
|
10
|
+
var runtimeOptions = param.runtimeOptions, partialSSRRemotes = param.partialSSRRemotes, ssrByRouteIdsMap = param.ssrByRouteIdsMap;
|
|
11
|
+
return {
|
|
12
|
+
name: "MFDataLoaderServerPlugin",
|
|
13
|
+
pre: [
|
|
14
|
+
"@modern-js/plugin-inject-resource"
|
|
15
|
+
],
|
|
16
|
+
setup: function setup(api) {
|
|
17
|
+
var remotes = runtimeOptions.remotes, name = runtimeOptions.name;
|
|
18
|
+
if (!remotes.length) {
|
|
19
|
+
return {};
|
|
20
|
+
}
|
|
21
|
+
var isHandled = false;
|
|
22
|
+
return {
|
|
23
|
+
prepare: function prepare() {
|
|
24
|
+
var middlewares = api.useAppContext().middlewares;
|
|
25
|
+
middlewares.push({
|
|
26
|
+
name: "MFDataLoaderServerPlugin",
|
|
27
|
+
handler: function() {
|
|
28
|
+
var _ref = _async_to_generator(function(c, next) {
|
|
29
|
+
var serverManifest, loaderBundles, nestedRoutesJson, _api_useConfigContext_server, instance, remoteFullRoutesMap, originalSSRByRouteIds, remoteSSRByRouteIds, ssrByRouteIds;
|
|
30
|
+
return _ts_generator(this, function(_state) {
|
|
31
|
+
switch (_state.label) {
|
|
32
|
+
case 0:
|
|
33
|
+
serverManifest = c.get("serverManifest");
|
|
34
|
+
loaderBundles = serverManifest.loaderBundles, nestedRoutesJson = serverManifest.nestedRoutesJson;
|
|
35
|
+
if (!isHandled)
|
|
36
|
+
return [
|
|
37
|
+
3,
|
|
38
|
+
2
|
|
39
|
+
];
|
|
40
|
+
return [
|
|
41
|
+
4,
|
|
42
|
+
next()
|
|
43
|
+
];
|
|
44
|
+
case 1:
|
|
45
|
+
_state.sent();
|
|
46
|
+
return [
|
|
47
|
+
3,
|
|
48
|
+
5
|
|
49
|
+
];
|
|
50
|
+
case 2:
|
|
51
|
+
instance = init({
|
|
52
|
+
name,
|
|
53
|
+
remotes
|
|
54
|
+
});
|
|
55
|
+
return [
|
|
56
|
+
4,
|
|
57
|
+
fetchRemoteFullRoutesMap({
|
|
58
|
+
instance,
|
|
59
|
+
remotePath: isBrowserEnv() ? "".concat(DEFAULT_ENTRY, "/").concat(MF_ROUTES) : "".concat(DEFAULT_ENTRY, "/").concat(MODERN_JS_ROUTE_SERVER_LOADER)
|
|
60
|
+
})
|
|
61
|
+
];
|
|
62
|
+
case 3:
|
|
63
|
+
remoteFullRoutesMap = _state.sent();
|
|
64
|
+
originalSSRByRouteIds = (_api_useConfigContext_server = api.useConfigContext().server) === null || _api_useConfigContext_server === void 0 ? void 0 : _api_useConfigContext_server.ssrByRouteIds;
|
|
65
|
+
if (originalSSRByRouteIds && partialSSRRemotes.length) {
|
|
66
|
+
remoteSSRByRouteIds = getSSRByRouteIds(partialSSRRemotes, remoteFullRoutesMap) || [];
|
|
67
|
+
ssrByRouteIds = new Set(_to_consumable_array(originalSSRByRouteIds).concat(_to_consumable_array(remoteSSRByRouteIds.map(function(id) {
|
|
68
|
+
return ssrByRouteIdsMap[id] || id;
|
|
69
|
+
}))));
|
|
70
|
+
api.useConfigContext().server.ssrByRouteIds = Array.from(ssrByRouteIds);
|
|
71
|
+
}
|
|
72
|
+
injectRemoteRoutes(loaderBundles, remoteFullRoutesMap);
|
|
73
|
+
injectRemoteRoutes(nestedRoutesJson, remoteFullRoutesMap);
|
|
74
|
+
isHandled = true;
|
|
75
|
+
return [
|
|
76
|
+
4,
|
|
77
|
+
next()
|
|
78
|
+
];
|
|
79
|
+
case 4:
|
|
80
|
+
_state.sent();
|
|
81
|
+
_state.label = 5;
|
|
82
|
+
case 5:
|
|
83
|
+
return [
|
|
84
|
+
2
|
|
85
|
+
];
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
return function(c, next) {
|
|
90
|
+
return _ref.apply(this, arguments);
|
|
91
|
+
};
|
|
92
|
+
}(),
|
|
93
|
+
before: [
|
|
94
|
+
"render"
|
|
95
|
+
]
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
;
|
|
103
|
+
export {
|
|
104
|
+
dataLoaderPlugin_default as default
|
|
105
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
3
|
+
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
4
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
5
|
+
function fetchRemoteFullRoutesMap(options) {
|
|
6
|
+
return _fetchRemoteFullRoutesMap.apply(this, arguments);
|
|
7
|
+
}
|
|
8
|
+
function _fetchRemoteFullRoutesMap() {
|
|
9
|
+
_fetchRemoteFullRoutesMap = _async_to_generator(function(options) {
|
|
10
|
+
var instance, remotePath, remotes, remoteRoutesMap;
|
|
11
|
+
return _ts_generator(this, function(_state) {
|
|
12
|
+
switch (_state.label) {
|
|
13
|
+
case 0:
|
|
14
|
+
instance = options.instance, remotePath = options.remotePath;
|
|
15
|
+
remotes = instance.options.remotes;
|
|
16
|
+
remoteRoutesMap = {};
|
|
17
|
+
if (!remotes.length) {
|
|
18
|
+
return [
|
|
19
|
+
2,
|
|
20
|
+
remoteRoutesMap
|
|
21
|
+
];
|
|
22
|
+
}
|
|
23
|
+
return [
|
|
24
|
+
4,
|
|
25
|
+
Promise.all(remotes.map(function() {
|
|
26
|
+
var _ref = _async_to_generator(function(remote) {
|
|
27
|
+
var remoteId, routes;
|
|
28
|
+
return _ts_generator(this, function(_state2) {
|
|
29
|
+
switch (_state2.label) {
|
|
30
|
+
case 0:
|
|
31
|
+
remoteId = "".concat(remote.name, "/").concat(remotePath);
|
|
32
|
+
return [
|
|
33
|
+
4,
|
|
34
|
+
instance.loadRemote(remoteId)
|
|
35
|
+
];
|
|
36
|
+
case 1:
|
|
37
|
+
routes = _state2.sent().routes;
|
|
38
|
+
remoteRoutesMap[remote.name] = {
|
|
39
|
+
routes
|
|
40
|
+
};
|
|
41
|
+
return [
|
|
42
|
+
2
|
|
43
|
+
];
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
return function(remote) {
|
|
48
|
+
return _ref.apply(this, arguments);
|
|
49
|
+
};
|
|
50
|
+
}()))
|
|
51
|
+
];
|
|
52
|
+
case 1:
|
|
53
|
+
_state.sent();
|
|
54
|
+
return [
|
|
55
|
+
2,
|
|
56
|
+
remoteRoutesMap
|
|
57
|
+
];
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
return _fetchRemoteFullRoutesMap.apply(this, arguments);
|
|
62
|
+
}
|
|
63
|
+
function getSSRByRouteIds(partialSSRRemotes, remoteRoutesMap) {
|
|
64
|
+
var remoteProviderRouteIds = /* @__PURE__ */ new Set();
|
|
65
|
+
var collectIds = function(route) {
|
|
66
|
+
remoteProviderRouteIds.add(route.id);
|
|
67
|
+
if (route.children) {
|
|
68
|
+
route.children.forEach(function(r) {
|
|
69
|
+
collectIds(r);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
Object.entries(remoteRoutesMap).forEach(function(item) {
|
|
74
|
+
var _item = _sliced_to_array(item, 2), remoteName = _item[0], routesObj = _item[1];
|
|
75
|
+
if (!partialSSRRemotes.includes(remoteName)) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
var routes = routesObj.routes;
|
|
79
|
+
routes.forEach(function(route) {
|
|
80
|
+
collectIds(route);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
return _to_consumable_array(remoteProviderRouteIds);
|
|
84
|
+
}
|
|
85
|
+
export {
|
|
86
|
+
fetchRemoteFullRoutesMap,
|
|
87
|
+
getSSRByRouteIds
|
|
88
|
+
};
|
|
@@ -6,7 +6,7 @@ import { ModuleFederationPlugin } from "@module-federation/enhanced/webpack";
|
|
|
6
6
|
import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
|
|
7
7
|
import UniverseEntryChunkTrackerPlugin from "@module-federation/node/universe-entry-chunk-tracker-plugin";
|
|
8
8
|
import { updateStatsAndManifest } from "./manifest";
|
|
9
|
-
import { isDev } from "
|
|
9
|
+
import { isDev, META_NAME } from "../constant";
|
|
10
10
|
function setEnv() {
|
|
11
11
|
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
12
12
|
process.env["MF_SSR_PRJ"] = "true";
|
|
@@ -20,10 +20,11 @@ var moduleFederationSSRPlugin = function(userConfig) {
|
|
|
20
20
|
],
|
|
21
21
|
setup: function() {
|
|
22
22
|
var _ref = _async_to_generator(function(param) {
|
|
23
|
-
var useConfigContext, useAppContext, _modernjsConfig_server, modernjsConfig, enableSSR;
|
|
23
|
+
var useConfigContext, useAppContext, _modernjsConfig_server, modernjsConfig, _userConfig_metaName, metaName, enableSSR;
|
|
24
24
|
return _ts_generator(this, function(_state) {
|
|
25
25
|
useConfigContext = param.useConfigContext, useAppContext = param.useAppContext;
|
|
26
26
|
modernjsConfig = useConfigContext();
|
|
27
|
+
_userConfig_metaName = userConfig.metaName, metaName = _userConfig_metaName === void 0 ? META_NAME : _userConfig_metaName;
|
|
27
28
|
enableSSR = Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
28
29
|
if (!enableSSR) {
|
|
29
30
|
return [
|
|
@@ -46,7 +47,9 @@ var moduleFederationSSRPlugin = function(userConfig) {
|
|
|
46
47
|
plugins.push({
|
|
47
48
|
name: "mfSSR",
|
|
48
49
|
path: "@module-federation/modern-js/ssr-runtime",
|
|
49
|
-
config: {
|
|
50
|
+
config: {
|
|
51
|
+
metaName
|
|
52
|
+
}
|
|
50
53
|
});
|
|
51
54
|
return {
|
|
52
55
|
entrypoint,
|
package/dist/esm/cli/utils.js
CHANGED
|
@@ -2,6 +2,7 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
|
2
2
|
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
3
3
|
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
4
4
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
5
|
+
import { _ as _type_of } from "@swc/helpers/_/_type_of";
|
|
5
6
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
6
7
|
import { encodeName } from "@module-federation/sdk";
|
|
7
8
|
import path from "path";
|
|
@@ -69,7 +70,7 @@ var replaceRemoteUrl = function(mfConfig, remoteIpStrategy) {
|
|
|
69
70
|
if (typeof remote === "string" && remote.includes(LOCALHOST)) {
|
|
70
71
|
remoteObject[remoteKey] = remote.replace(LOCALHOST, ipv4);
|
|
71
72
|
}
|
|
72
|
-
if (typeof remote === "object" && !Array.isArray(remote.external) && remote.external.includes(LOCALHOST)) {
|
|
73
|
+
if ((typeof remote === "undefined" ? "undefined" : _type_of(remote)) === "object" && !Array.isArray(remote.external) && remote.external.includes(LOCALHOST)) {
|
|
73
74
|
remote.external = remote.external.replace(LOCALHOST, ipv4);
|
|
74
75
|
}
|
|
75
76
|
});
|
|
@@ -79,7 +80,9 @@ var replaceRemoteUrl = function(mfConfig, remoteIpStrategy) {
|
|
|
79
80
|
if (typeof remoteObject === "string") {
|
|
80
81
|
return;
|
|
81
82
|
}
|
|
82
|
-
|
|
83
|
+
if ("entry" in remoteObject && typeof remoteObject.entry === "string") {
|
|
84
|
+
remoteObject.entry = remoteObject.entry.replace(LOCALHOST, ipv4);
|
|
85
|
+
}
|
|
83
86
|
});
|
|
84
87
|
} else if (typeof mfConfig.remotes !== "string") {
|
|
85
88
|
handleRemoteObject(mfConfig.remotes);
|
|
@@ -126,17 +129,18 @@ var patchMFConfig = function(mfConfig, isServer, remoteIpStrategy) {
|
|
|
126
129
|
throw new Error("".concat(PLUGIN_IDENTIFIER, " mfConfig.name can not be empty!"));
|
|
127
130
|
}
|
|
128
131
|
var runtimePlugins = _to_consumable_array(mfConfig.runtimePlugins || []);
|
|
132
|
+
var _mfConfig_shareStrategy;
|
|
133
|
+
mfConfig.shareStrategy = (_mfConfig_shareStrategy = mfConfig.shareStrategy) !== null && _mfConfig_shareStrategy !== void 0 ? _mfConfig_shareStrategy : "loaded-first";
|
|
129
134
|
patchDTSConfig(mfConfig, isServer);
|
|
130
|
-
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"), runtimePlugins);
|
|
131
135
|
if (isDev) {
|
|
132
136
|
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/resolve-entry-ipv4.js"), runtimePlugins);
|
|
133
137
|
}
|
|
134
138
|
if (isServer) {
|
|
135
|
-
injectRuntimePlugins(
|
|
139
|
+
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/node.js"), runtimePlugins);
|
|
136
140
|
if (isDev) {
|
|
137
141
|
injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
|
|
138
142
|
}
|
|
139
|
-
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/
|
|
143
|
+
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/node-fetch.js"), runtimePlugins);
|
|
140
144
|
if (!mfConfig.library) {
|
|
141
145
|
mfConfig.library = {
|
|
142
146
|
type: "commonjs-module",
|
|
@@ -197,7 +201,7 @@ function patchBundlerConfig(options) {
|
|
|
197
201
|
}
|
|
198
202
|
}
|
|
199
203
|
if (mfConfig.dts !== false) {
|
|
200
|
-
if (
|
|
204
|
+
if (_type_of(mfConfig.dts) === "object" && _type_of(mfConfig.dts.consumeTypes) === "object" && mfConfig.dts.consumeTypes.remoteTypesFolder) {
|
|
201
205
|
bundlerConfig.watchOptions.ignored.push("**/".concat(mfConfig.dts.consumeTypes.remoteTypesFolder, "/**"));
|
|
202
206
|
} else {
|
|
203
207
|
bundlerConfig.watchOptions.ignored.push("**/@mf-types/**");
|
|
@@ -218,7 +222,7 @@ function patchBundlerConfig(options) {
|
|
|
218
222
|
if (!isServer) {
|
|
219
223
|
autoDeleteSplitChunkCacheGroups(mfConfig, bundlerConfig);
|
|
220
224
|
}
|
|
221
|
-
if (!isServer && enableSSR &&
|
|
225
|
+
if (!isServer && enableSSR && _type_of((_bundlerConfig_optimization1 = bundlerConfig.optimization) === null || _bundlerConfig_optimization1 === void 0 ? void 0 : _bundlerConfig_optimization1.splitChunks) === "object" && bundlerConfig.optimization.splitChunks.cacheGroups) {
|
|
222
226
|
bundlerConfig.optimization.splitChunks.chunks = "async";
|
|
223
227
|
console.warn("".concat(PLUGIN_IDENTIFIER, ' splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"'));
|
|
224
228
|
}
|
|
@@ -339,5 +343,6 @@ export {
|
|
|
339
343
|
getMFConfig,
|
|
340
344
|
patchBundlerConfig,
|
|
341
345
|
patchIgnoreWarning,
|
|
342
|
-
patchMFConfig
|
|
346
|
+
patchMFConfig,
|
|
347
|
+
replaceRemoteUrl
|
|
343
348
|
};
|
|
@@ -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,28 @@
|
|
|
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";
|
|
4
14
|
export {
|
|
15
|
+
DEFAULT_ENTRY,
|
|
16
|
+
DEFAULT_LAYOUT,
|
|
17
|
+
FOLD_IDENTIFIER,
|
|
5
18
|
LOCALHOST,
|
|
19
|
+
META_NAME,
|
|
20
|
+
MF_JSON,
|
|
21
|
+
MF_ROUTES,
|
|
22
|
+
MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME,
|
|
23
|
+
MODERN_JS_ROUTE_SERVER_LOADER,
|
|
6
24
|
MODERN_JS_SERVER_DIR,
|
|
7
|
-
PLUGIN_IDENTIFIER
|
|
25
|
+
PLUGIN_IDENTIFIER,
|
|
26
|
+
SEPARATOR,
|
|
27
|
+
isDev
|
|
8
28
|
};
|
|
File without changes
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
2
|
+
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
3
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
4
|
+
import { useContext } from "react";
|
|
5
|
+
import { getInstance } from "@module-federation/enhanced/runtime";
|
|
6
|
+
import { collectSSRAssets } from "../createRemoteSSRComponent";
|
|
7
|
+
import { RuntimeReactContext } from "@meta/runtime";
|
|
8
|
+
import { decodeId, getRemoteId } from "./utils";
|
|
9
|
+
var ssrDataLoaderInjectAssetsPlugin = function(param) {
|
|
10
|
+
var metaName = param.metaName;
|
|
11
|
+
return {
|
|
12
|
+
name: "@modern-js/plugin-mf-data-loader-inject-assets",
|
|
13
|
+
pre: [
|
|
14
|
+
"@".concat(metaName, "/plugin-router"),
|
|
15
|
+
"@modern-js/plugin-mf-data-loader"
|
|
16
|
+
],
|
|
17
|
+
setup: function() {
|
|
18
|
+
return {
|
|
19
|
+
wrapRoot: function wrapRoot(App) {
|
|
20
|
+
var AppWrapper = function(props) {
|
|
21
|
+
var _context_routerContext;
|
|
22
|
+
var instance = getInstance();
|
|
23
|
+
if (!instance || !instance.options.remotes.length) {
|
|
24
|
+
console.log("plugin-mf-data-loader-inject-assets no instance!");
|
|
25
|
+
return /* @__PURE__ */ _jsx(_Fragment, {
|
|
26
|
+
children: /* @__PURE__ */ _jsx(App, _object_spread({}, props))
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
var context = useContext(RuntimeReactContext);
|
|
30
|
+
var remotes = instance.options.remotes;
|
|
31
|
+
var remoteNames = ((_context_routerContext = context.routerContext) === null || _context_routerContext === void 0 ? void 0 : _context_routerContext.matches.map(function(match) {
|
|
32
|
+
return decodeId(match.route.id);
|
|
33
|
+
})) || [];
|
|
34
|
+
var remoteIds = remoteNames.reduce(function(sum, cur) {
|
|
35
|
+
var matchRemote = remotes.find(function(r) {
|
|
36
|
+
return r.name === cur;
|
|
37
|
+
});
|
|
38
|
+
if (matchRemote) {
|
|
39
|
+
sum.add(getRemoteId(cur));
|
|
40
|
+
}
|
|
41
|
+
return sum;
|
|
42
|
+
}, /* @__PURE__ */ new Set());
|
|
43
|
+
var assets = [];
|
|
44
|
+
remoteIds.forEach(function(remoteId) {
|
|
45
|
+
var _assets;
|
|
46
|
+
(_assets = assets).push.apply(_assets, _to_consumable_array(collectSSRAssets({
|
|
47
|
+
id: remoteId,
|
|
48
|
+
injectScript: false
|
|
49
|
+
})));
|
|
50
|
+
});
|
|
51
|
+
console.log("plugin-mf-data-loader-inject-assets has assets: ", assets);
|
|
52
|
+
return /* @__PURE__ */ _jsxs(_Fragment, {
|
|
53
|
+
children: [
|
|
54
|
+
assets,
|
|
55
|
+
/* @__PURE__ */ _jsx(App, _object_spread({}, props))
|
|
56
|
+
]
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
return AppWrapper;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
export {
|
|
66
|
+
ssrDataLoaderInjectAssetsPlugin
|
|
67
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
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;
|
|
8
|
+
return {
|
|
9
|
+
name: "@modern-js/plugin-mf-data-loader",
|
|
10
|
+
post: [
|
|
11
|
+
"@".concat(metaName, "/plugin-router")
|
|
12
|
+
],
|
|
13
|
+
setup: function() {
|
|
14
|
+
var remoteRoutesMap = {};
|
|
15
|
+
return {
|
|
16
|
+
beforeRender: function beforeRender() {
|
|
17
|
+
return _async_to_generator(function() {
|
|
18
|
+
var instance;
|
|
19
|
+
return _ts_generator(this, function(_state) {
|
|
20
|
+
switch (_state.label) {
|
|
21
|
+
case 0:
|
|
22
|
+
console.log("init");
|
|
23
|
+
if (Object.keys(remoteRoutesMap).length) {
|
|
24
|
+
return [
|
|
25
|
+
2
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
instance = getInstance();
|
|
29
|
+
if (!instance) {
|
|
30
|
+
console.log("no instance!");
|
|
31
|
+
return [
|
|
32
|
+
2
|
|
33
|
+
];
|
|
34
|
+
}
|
|
35
|
+
if (!instance.options.remotes.length) {
|
|
36
|
+
return [
|
|
37
|
+
2
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
return [
|
|
41
|
+
4,
|
|
42
|
+
Promise.all(instance.options.remotes.map(function() {
|
|
43
|
+
var _ref = _async_to_generator(function(remote) {
|
|
44
|
+
var remoteId, routes;
|
|
45
|
+
return _ts_generator(this, function(_state2) {
|
|
46
|
+
switch (_state2.label) {
|
|
47
|
+
case 0:
|
|
48
|
+
remoteId = "".concat(remote.name, "/").concat(DEFAULT_ENTRY, "/").concat(MF_ROUTES);
|
|
49
|
+
return [
|
|
50
|
+
4,
|
|
51
|
+
instance.loadRemote(remoteId)
|
|
52
|
+
];
|
|
53
|
+
case 1:
|
|
54
|
+
routes = _state2.sent().routes;
|
|
55
|
+
remoteRoutesMap[remote.name] = {
|
|
56
|
+
routes
|
|
57
|
+
};
|
|
58
|
+
return [
|
|
59
|
+
2
|
|
60
|
+
];
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
return function(remote) {
|
|
65
|
+
return _ref.apply(this, arguments);
|
|
66
|
+
};
|
|
67
|
+
}()))
|
|
68
|
+
];
|
|
69
|
+
case 1:
|
|
70
|
+
_state.sent();
|
|
71
|
+
return [
|
|
72
|
+
2
|
|
73
|
+
];
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
})();
|
|
77
|
+
},
|
|
78
|
+
// runtime plugin not save route , so it needs to inject again when trigger
|
|
79
|
+
modifyRoutes: function(routes) {
|
|
80
|
+
injectRemoteRoutes({
|
|
81
|
+
entry: {
|
|
82
|
+
routes
|
|
83
|
+
}
|
|
84
|
+
}, remoteRoutesMap);
|
|
85
|
+
return routes;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
export {
|
|
92
|
+
ssrDataLoaderPlugin
|
|
93
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
route.element = routes.element;
|
|
49
|
+
route.Component = routes.Component;
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
(_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.forEach(function(r) {
|
|
53
|
+
traverse(r);
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
Object.keys(initialRoutes).forEach(function(entryName) {
|
|
57
|
+
var routes = initialRoutes[entryName];
|
|
58
|
+
if (Array.isArray(routes)) {
|
|
59
|
+
routes.forEach(function(route) {
|
|
60
|
+
traverse(route);
|
|
61
|
+
});
|
|
62
|
+
} else {
|
|
63
|
+
var _routes_routes;
|
|
64
|
+
routes === null || routes === void 0 ? void 0 : (_routes_routes = routes.routes) === null || _routes_routes === void 0 ? void 0 : _routes_routes.forEach(function(r) {
|
|
65
|
+
traverse(r);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
export {
|
|
71
|
+
decodeId,
|
|
72
|
+
getRemoteId,
|
|
73
|
+
getRemoteLayoutId,
|
|
74
|
+
getRemoteRoutesInfos,
|
|
75
|
+
injectRemoteRoutes,
|
|
76
|
+
transformName2Prefix
|
|
77
|
+
};
|
|
@@ -4,13 +4,17 @@ 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
|
-
|
|
7
|
+
console.log("mfSSRPlugin trigger");
|
|
8
|
+
var mfSSRPlugin = function(param) {
|
|
9
|
+
var metaName = param.metaName;
|
|
8
10
|
return {
|
|
9
11
|
name: "@module-federation/modern-js",
|
|
12
|
+
pre: [
|
|
13
|
+
"@".concat(metaName, "/plugin-router")
|
|
14
|
+
],
|
|
10
15
|
setup: function() {
|
|
11
16
|
return {
|
|
12
|
-
|
|
13
|
-
var context = param.context;
|
|
17
|
+
beforeRender: function beforeRender() {
|
|
14
18
|
return _async_to_generator(function() {
|
|
15
19
|
var nodeUtils, shouldUpdate;
|
|
16
20
|
return _ts_generator(this, function(_state) {
|
|
@@ -18,10 +22,7 @@ var mfSSRPlugin = function() {
|
|
|
18
22
|
case 0:
|
|
19
23
|
if (typeof window !== "undefined") {
|
|
20
24
|
return [
|
|
21
|
-
2
|
|
22
|
-
next({
|
|
23
|
-
context
|
|
24
|
-
})
|
|
25
|
+
2
|
|
25
26
|
];
|
|
26
27
|
}
|
|
27
28
|
globalThis.shouldUpdate = false;
|
|
@@ -53,10 +54,7 @@ var mfSSRPlugin = function() {
|
|
|
53
54
|
_state.label = 4;
|
|
54
55
|
case 4:
|
|
55
56
|
return [
|
|
56
|
-
2
|
|
57
|
-
next({
|
|
58
|
-
context
|
|
59
|
-
})
|
|
57
|
+
2
|
|
60
58
|
];
|
|
61
59
|
}
|
|
62
60
|
});
|