@module-federation/modern-js 0.0.0-next-20240909073915 → 0.0.0-next-20240909092952
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 +132 -0
- package/dist/cjs/cli/dataLoader/plugin.js +194 -0
- package/dist/cjs/cli/index.js +5 -1
- package/dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js +7 -10
- package/dist/cjs/cli/mfRuntimePlugins/node.js +44 -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 +1 -1
- package/dist/cjs/cli/utils.js +8 -4
- package/dist/cjs/cli/utils.spec.js +1 -1
- package/dist/cjs/constant.js +32 -2
- package/dist/cjs/interfaces/route.js +16 -0
- package/dist/cjs/runtime/dataLoader/plugin.js +73 -0
- package/dist/cjs/runtime/dataLoader/utils.js +89 -0
- package/dist/cjs/runtime/index.js +4 -1
- package/dist/cjs/runtime/utils.js +38 -0
- package/dist/cjs/runtime/withMFRouteId.js +31 -0
- package/dist/cjs/ssr-runtime/plugin.js +7 -7
- 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 +98 -0
- package/dist/esm/cli/dataLoader/plugin.js +209 -0
- package/dist/esm/cli/index.js +4 -1
- package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.js +7 -10
- package/dist/esm/cli/mfRuntimePlugins/node.js +16 -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 +1 -1
- package/dist/esm/cli/utils.js +6 -3
- package/dist/esm/cli/utils.spec.js +1 -1
- package/dist/esm/constant.js +21 -1
- package/dist/esm/interfaces/route.js +0 -0
- package/dist/esm/runtime/dataLoader/plugin.js +92 -0
- package/dist/esm/runtime/dataLoader/utils.js +63 -0
- package/dist/esm/runtime/index.js +3 -1
- package/dist/esm/runtime/utils.js +13 -0
- package/dist/esm/runtime/withMFRouteId.js +7 -0
- package/dist/esm/ssr-runtime/plugin.js +7 -10
- 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 +98 -0
- package/dist/esm-node/cli/dataLoader/plugin.js +159 -0
- package/dist/esm-node/cli/index.js +5 -1
- package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.js +7 -10
- package/dist/esm-node/cli/mfRuntimePlugins/node.js +14 -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 +1 -1
- package/dist/esm-node/cli/utils.js +6 -3
- package/dist/esm-node/cli/utils.spec.js +1 -1
- package/dist/esm-node/constant.js +21 -1
- package/dist/esm-node/interfaces/route.js +0 -0
- package/dist/esm-node/runtime/dataLoader/plugin.js +49 -0
- package/dist/esm-node/runtime/dataLoader/utils.js +63 -0
- package/dist/esm-node/runtime/index.js +3 -1
- package/dist/esm-node/runtime/utils.js +13 -0
- package/dist/esm-node/runtime/withMFRouteId.js +7 -0
- package/dist/esm-node/ssr-runtime/plugin.js +7 -7
- 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/inject-node-fetch.d.ts +2 -2
- 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.d.ts +2 -0
- package/dist/types/runtime/dataLoader/utils.d.ts +19 -0
- package/dist/types/runtime/index.d.ts +1 -0
- package/dist/types/runtime/utils.d.ts +2 -0
- package/dist/types/runtime/withMFRouteId.d.ts +1 -0
- package/dist/types/types/index.d.ts +9 -0
- package/package.json +40 -11
- package/dist/esm/cli/constant.js +0 -4
- package/dist/esm-node/cli/constant.js +0 -4
- package/dist/types/cli/constant.d.ts +0 -1
|
@@ -0,0 +1,209 @@
|
|
|
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 _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
|
+
import { transformName2Prefix } from "../../runtime/utils";
|
|
5
|
+
import { DEFAULT_ENTRY } from "../../constant";
|
|
6
|
+
import { META_NAME } from "../../constant";
|
|
7
|
+
import { generateRoutes } from "./ast";
|
|
8
|
+
import { generateRouteFile } from "./generateRouteFile";
|
|
9
|
+
import { patchMFConfig } from "./patchMFConfig";
|
|
10
|
+
import path from "path";
|
|
11
|
+
function _transformRuntimeOptions(buildOptions) {
|
|
12
|
+
var remotes = buildOptions.remotes || {};
|
|
13
|
+
var runtimeRemotes = Object.entries(remotes).map(function(remote) {
|
|
14
|
+
var _remote = _sliced_to_array(remote, 2), alias = _remote[0], nameAndEntry = _remote[1];
|
|
15
|
+
var _nameAndEntry_split = _sliced_to_array(nameAndEntry.split("@"), 2), name = _nameAndEntry_split[0], entry = _nameAndEntry_split[1];
|
|
16
|
+
return {
|
|
17
|
+
name,
|
|
18
|
+
entry,
|
|
19
|
+
alias
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
return {
|
|
23
|
+
name: buildOptions.name,
|
|
24
|
+
remotes: runtimeRemotes
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
var moduleFederationDataLoaderPlugin = function(enable, internalOptions, userConfig) {
|
|
28
|
+
return {
|
|
29
|
+
name: "@modern-js/plugin-module-federation-data-loader",
|
|
30
|
+
pre: [
|
|
31
|
+
"@modern-js/plugin-module-federation-config"
|
|
32
|
+
],
|
|
33
|
+
post: [
|
|
34
|
+
"@modern-js/plugin-router",
|
|
35
|
+
"@modern-js/plugin-module-federation"
|
|
36
|
+
],
|
|
37
|
+
setup: function() {
|
|
38
|
+
var _ref = _async_to_generator(function(param) {
|
|
39
|
+
var useAppContext, _userConfig_metaName, metaName, _userConfig_serverPlugin, serverPlugin, transformRuntimeOptions, appContext, name, internalDirectory, transformRuntimeFn, partialSSRRemotes, entries, remotePathMap, ssrByRouteIdsMap, serverPluginOptions, csrConfig, _ref2, scanEntries, scanRemotePathMap;
|
|
40
|
+
return _ts_generator(this, function(_state) {
|
|
41
|
+
switch (_state.label) {
|
|
42
|
+
case 0:
|
|
43
|
+
useAppContext = param.useAppContext;
|
|
44
|
+
if (!enable) {
|
|
45
|
+
return [
|
|
46
|
+
2
|
|
47
|
+
];
|
|
48
|
+
}
|
|
49
|
+
_userConfig_metaName = userConfig.metaName, metaName = _userConfig_metaName === void 0 ? META_NAME : _userConfig_metaName, _userConfig_serverPlugin = userConfig.serverPlugin, serverPlugin = _userConfig_serverPlugin === void 0 ? "@module-federation/modern-js/data-loader-server" : _userConfig_serverPlugin, transformRuntimeOptions = userConfig.transformRuntimeOptions;
|
|
50
|
+
appContext = useAppContext();
|
|
51
|
+
name = internalOptions.csrConfig.name;
|
|
52
|
+
internalDirectory = appContext.internalDirectory.replace(META_NAME, metaName || META_NAME);
|
|
53
|
+
transformRuntimeFn = transformRuntimeOptions || _transformRuntimeOptions;
|
|
54
|
+
partialSSRRemotes = [];
|
|
55
|
+
entries = /* @__PURE__ */ new Set();
|
|
56
|
+
remotePathMap = {};
|
|
57
|
+
ssrByRouteIdsMap = {};
|
|
58
|
+
serverPluginOptions = {
|
|
59
|
+
runtimeOptions: transformRuntimeFn(internalOptions.csrConfig),
|
|
60
|
+
partialSSRRemotes,
|
|
61
|
+
ssrByRouteIdsMap
|
|
62
|
+
};
|
|
63
|
+
csrConfig = internalOptions.csrConfig;
|
|
64
|
+
if (!(typeof csrConfig.remotes === "object" && Object.keys(csrConfig.remotes).length))
|
|
65
|
+
return [
|
|
66
|
+
3,
|
|
67
|
+
2
|
|
68
|
+
];
|
|
69
|
+
return [
|
|
70
|
+
4,
|
|
71
|
+
generateRouteFile({
|
|
72
|
+
appDirectory: appContext.appDirectory
|
|
73
|
+
})
|
|
74
|
+
];
|
|
75
|
+
case 1:
|
|
76
|
+
_ref2 = _state.sent(), scanEntries = _ref2.entries, scanRemotePathMap = _ref2.remotePathMap;
|
|
77
|
+
scanEntries.forEach(function(e) {
|
|
78
|
+
return entries.add(e);
|
|
79
|
+
});
|
|
80
|
+
remotePathMap = scanRemotePathMap;
|
|
81
|
+
return [
|
|
82
|
+
3,
|
|
83
|
+
3
|
|
84
|
+
];
|
|
85
|
+
case 2:
|
|
86
|
+
entries.add(DEFAULT_ENTRY);
|
|
87
|
+
_state.label = 3;
|
|
88
|
+
case 3:
|
|
89
|
+
return [
|
|
90
|
+
2,
|
|
91
|
+
{
|
|
92
|
+
_internalRuntimePlugins: function(param2) {
|
|
93
|
+
var entrypoint = param2.entrypoint, plugins = param2.plugins;
|
|
94
|
+
plugins.push({
|
|
95
|
+
name: "ssrDataLoader",
|
|
96
|
+
path: "@module-federation/modern-js/data-loader",
|
|
97
|
+
config: {}
|
|
98
|
+
});
|
|
99
|
+
return {
|
|
100
|
+
entrypoint,
|
|
101
|
+
plugins
|
|
102
|
+
};
|
|
103
|
+
},
|
|
104
|
+
_internalServerPlugins: function _internalServerPlugins(param2) {
|
|
105
|
+
var plugins = param2.plugins;
|
|
106
|
+
plugins.push({
|
|
107
|
+
name: serverPlugin,
|
|
108
|
+
options: serverPluginOptions
|
|
109
|
+
});
|
|
110
|
+
return {
|
|
111
|
+
plugins
|
|
112
|
+
};
|
|
113
|
+
},
|
|
114
|
+
modifyFileSystemRoutes: function modifyFileSystemRoutes(options) {
|
|
115
|
+
return _async_to_generator(function() {
|
|
116
|
+
var routes, entrypoint, entryName, prefix, modifyRouteIds;
|
|
117
|
+
return _ts_generator(this, function(_state2) {
|
|
118
|
+
routes = options.routes, entrypoint = options.entrypoint;
|
|
119
|
+
entryName = entrypoint.entryName;
|
|
120
|
+
prefix = transformName2Prefix(internalOptions.csrConfig.name);
|
|
121
|
+
modifyRouteIds = function(route, pathName) {
|
|
122
|
+
var currentPathName = route.path ? path.join(pathName, route.path) : pathName;
|
|
123
|
+
if (route.id) {
|
|
124
|
+
var _route_children;
|
|
125
|
+
var originalId = route.id;
|
|
126
|
+
route.originalId = originalId;
|
|
127
|
+
var remoteName = remotePathMap[currentPathName];
|
|
128
|
+
if (remoteName) {
|
|
129
|
+
var remoteIdPrefix = transformName2Prefix(remoteName);
|
|
130
|
+
var isLayout = Boolean(route.children);
|
|
131
|
+
var newId = "".concat(remoteIdPrefix).concat(isLayout ? "layout" : "page");
|
|
132
|
+
ssrByRouteIdsMap[originalId] = newId;
|
|
133
|
+
route.id = newId;
|
|
134
|
+
if (!partialSSRRemotes.includes(remoteName)) {
|
|
135
|
+
partialSSRRemotes.push(remoteName);
|
|
136
|
+
}
|
|
137
|
+
} else {
|
|
138
|
+
route.id = "".concat(prefix).concat(route.id);
|
|
139
|
+
}
|
|
140
|
+
(_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.forEach(function(r) {
|
|
141
|
+
modifyRouteIds(r, currentPathName);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
routes.forEach(function(route) {
|
|
146
|
+
modifyRouteIds(route, entryName);
|
|
147
|
+
});
|
|
148
|
+
return [
|
|
149
|
+
2,
|
|
150
|
+
options
|
|
151
|
+
];
|
|
152
|
+
});
|
|
153
|
+
})();
|
|
154
|
+
},
|
|
155
|
+
config: /* @__PURE__ */ _async_to_generator(function() {
|
|
156
|
+
return _ts_generator(this, function(_state2) {
|
|
157
|
+
return [
|
|
158
|
+
2,
|
|
159
|
+
{
|
|
160
|
+
tools: {
|
|
161
|
+
// bundlerChain can not keep target order
|
|
162
|
+
rspack: function rspack(_config, param2) {
|
|
163
|
+
var isServer = param2.isServer;
|
|
164
|
+
patchMFConfig({
|
|
165
|
+
mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
|
|
166
|
+
metaName,
|
|
167
|
+
isServer,
|
|
168
|
+
internalDirectory,
|
|
169
|
+
entries
|
|
170
|
+
});
|
|
171
|
+
},
|
|
172
|
+
// bundlerChain can not keep target order
|
|
173
|
+
webpack: function webpack(_config, param2) {
|
|
174
|
+
var isServer = param2.isServer;
|
|
175
|
+
patchMFConfig({
|
|
176
|
+
mfConfig: isServer ? internalOptions.ssrConfig : internalOptions.csrConfig,
|
|
177
|
+
metaName,
|
|
178
|
+
isServer,
|
|
179
|
+
internalDirectory,
|
|
180
|
+
entries
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
source: {
|
|
185
|
+
define: {
|
|
186
|
+
MODERN_ROUTER_ID_PREFIX: JSON.stringify(transformName2Prefix(name))
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
];
|
|
191
|
+
});
|
|
192
|
+
})
|
|
193
|
+
}
|
|
194
|
+
];
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
return function(_) {
|
|
199
|
+
return _ref.apply(this, arguments);
|
|
200
|
+
};
|
|
201
|
+
}()
|
|
202
|
+
};
|
|
203
|
+
};
|
|
204
|
+
var plugin_default = moduleFederationDataLoaderPlugin;
|
|
205
|
+
export {
|
|
206
|
+
plugin_default as default,
|
|
207
|
+
generateRoutes,
|
|
208
|
+
moduleFederationDataLoaderPlugin
|
|
209
|
+
};
|
package/dist/esm/cli/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
2
3
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
4
|
import { ModuleFederationPlugin as WebpackModuleFederationPlugin, AsyncBoundaryPlugin } from "@module-federation/enhanced";
|
|
4
5
|
import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
|
|
5
6
|
import { moduleFederationConfigPlugin } from "./configPlugin";
|
|
6
7
|
import { moduleFederationSSRPlugin } from "./ssrPlugin";
|
|
8
|
+
import { moduleFederationDataLoaderPlugin } from "./dataLoader/plugin";
|
|
7
9
|
var moduleFederationPlugin = function() {
|
|
8
10
|
var userConfig = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
9
11
|
var internalModernPluginOptions = {
|
|
@@ -79,7 +81,8 @@ var moduleFederationPlugin = function() {
|
|
|
79
81
|
}(),
|
|
80
82
|
usePlugins: [
|
|
81
83
|
moduleFederationConfigPlugin(internalModernPluginOptions),
|
|
82
|
-
moduleFederationSSRPlugin(internalModernPluginOptions)
|
|
84
|
+
moduleFederationSSRPlugin(internalModernPluginOptions),
|
|
85
|
+
moduleFederationDataLoaderPlugin(Boolean(userConfig.dataLoader), internalModernPluginOptions, _object_spread({}, typeof userConfig.dataLoader === "boolean" ? {} : userConfig.dataLoader))
|
|
83
86
|
]
|
|
84
87
|
};
|
|
85
88
|
};
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
var
|
|
1
|
+
import nodeRuntimePlugin from "@module-federation/node/runtimePlugin";
|
|
2
|
+
var isContainer = typeof __filename === "string" ? __filename.includes("remote") ? true : false : false;
|
|
3
|
+
var pluginName = "node-plugin-".concat(isContainer);
|
|
4
|
+
var nodePlugin = function() {
|
|
3
5
|
return {
|
|
4
|
-
name:
|
|
5
|
-
beforeInit:
|
|
6
|
-
if (!globalThis.fetch) {
|
|
7
|
-
globalThis.fetch = nodeFetch;
|
|
8
|
-
}
|
|
9
|
-
return args;
|
|
10
|
-
}
|
|
6
|
+
name: pluginName,
|
|
7
|
+
beforeInit: nodeRuntimePlugin().beforeInit
|
|
11
8
|
};
|
|
12
9
|
};
|
|
13
|
-
var inject_node_fetch_default =
|
|
10
|
+
var inject_node_fetch_default = nodePlugin;
|
|
14
11
|
export {
|
|
15
12
|
inject_node_fetch_default as default
|
|
16
13
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import nodeFetch from "node-fetch";
|
|
2
|
+
var injectNodeFetchPlugin = function() {
|
|
3
|
+
return {
|
|
4
|
+
name: "inject-node-fetch-plugin",
|
|
5
|
+
beforeInit: function beforeInit(args) {
|
|
6
|
+
if (!globalThis.fetch) {
|
|
7
|
+
globalThis.fetch = nodeFetch;
|
|
8
|
+
}
|
|
9
|
+
return args;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
var node_default = injectNodeFetchPlugin;
|
|
14
|
+
export {
|
|
15
|
+
node_default as default
|
|
16
|
+
};
|
|
@@ -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 } from "../constant";
|
|
10
10
|
function setEnv() {
|
|
11
11
|
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
12
12
|
process.env["MF_SSR_PRJ"] = "true";
|
package/dist/esm/cli/utils.js
CHANGED
|
@@ -79,7 +79,9 @@ var replaceRemoteUrl = function(mfConfig, remoteIpStrategy) {
|
|
|
79
79
|
if (typeof remoteObject === "string") {
|
|
80
80
|
return;
|
|
81
81
|
}
|
|
82
|
-
|
|
82
|
+
if ("entry" in remoteObject && typeof remoteObject.entry === "string") {
|
|
83
|
+
remoteObject.entry = remoteObject.entry.replace(LOCALHOST, ipv4);
|
|
84
|
+
}
|
|
83
85
|
});
|
|
84
86
|
} else if (typeof mfConfig.remotes !== "string") {
|
|
85
87
|
handleRemoteObject(mfConfig.remotes);
|
|
@@ -132,7 +134,7 @@ var patchMFConfig = function(mfConfig, isServer, remoteIpStrategy) {
|
|
|
132
134
|
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/resolve-entry-ipv4.js"), runtimePlugins);
|
|
133
135
|
}
|
|
134
136
|
if (isServer) {
|
|
135
|
-
injectRuntimePlugins(require.resolve("
|
|
137
|
+
injectRuntimePlugins(require.resolve("./mfRuntimePlugins/node.js"), runtimePlugins);
|
|
136
138
|
if (isDev) {
|
|
137
139
|
injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
|
|
138
140
|
}
|
|
@@ -339,5 +341,6 @@ export {
|
|
|
339
341
|
getMFConfig,
|
|
340
342
|
patchBundlerConfig,
|
|
341
343
|
patchIgnoreWarning,
|
|
342
|
-
patchMFConfig
|
|
344
|
+
patchMFConfig,
|
|
345
|
+
replaceRemoteUrl
|
|
343
346
|
};
|
|
@@ -43,7 +43,7 @@ describe("patchMFConfig", /* @__PURE__ */ _async_to_generator(function() {
|
|
|
43
43
|
remoteType: "script",
|
|
44
44
|
runtimePlugins: [
|
|
45
45
|
path.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"),
|
|
46
|
-
require.resolve("
|
|
46
|
+
require.resolve("./mfRuntimePlugins/node.js"),
|
|
47
47
|
path.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js")
|
|
48
48
|
],
|
|
49
49
|
shared: {
|
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,92 @@
|
|
|
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() {
|
|
7
|
+
return {
|
|
8
|
+
name: "@modern-js/plugin-mf-data-loader",
|
|
9
|
+
post: [
|
|
10
|
+
"@modern-js/plugin-router"
|
|
11
|
+
],
|
|
12
|
+
setup: function() {
|
|
13
|
+
var remoteRoutesMap = {};
|
|
14
|
+
return {
|
|
15
|
+
beforeRender: function beforeRender() {
|
|
16
|
+
return _async_to_generator(function() {
|
|
17
|
+
var instance;
|
|
18
|
+
return _ts_generator(this, function(_state) {
|
|
19
|
+
switch (_state.label) {
|
|
20
|
+
case 0:
|
|
21
|
+
console.log("init");
|
|
22
|
+
if (Object.keys(remoteRoutesMap).length) {
|
|
23
|
+
return [
|
|
24
|
+
2
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
instance = getInstance();
|
|
28
|
+
if (!instance) {
|
|
29
|
+
console.log("no 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
|
+
remoteId = "".concat(remote.name, "/").concat(DEFAULT_ENTRY, "/").concat(MF_ROUTES);
|
|
48
|
+
return [
|
|
49
|
+
4,
|
|
50
|
+
instance.loadRemote(remoteId)
|
|
51
|
+
];
|
|
52
|
+
case 1:
|
|
53
|
+
routes = _state2.sent().routes;
|
|
54
|
+
remoteRoutesMap[remote.name] = {
|
|
55
|
+
routes
|
|
56
|
+
};
|
|
57
|
+
return [
|
|
58
|
+
2
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
return function(remote) {
|
|
64
|
+
return _ref.apply(this, arguments);
|
|
65
|
+
};
|
|
66
|
+
}()))
|
|
67
|
+
];
|
|
68
|
+
case 1:
|
|
69
|
+
_state.sent();
|
|
70
|
+
return [
|
|
71
|
+
2
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
})();
|
|
76
|
+
},
|
|
77
|
+
// runtime plugin not save route , so it needs to inject again when trigger
|
|
78
|
+
modifyRoutes: function(routes) {
|
|
79
|
+
injectRemoteRoutes({
|
|
80
|
+
entry: {
|
|
81
|
+
routes
|
|
82
|
+
}
|
|
83
|
+
}, remoteRoutesMap);
|
|
84
|
+
return routes;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
export {
|
|
91
|
+
ssrDataLoaderPlugin
|
|
92
|
+
};
|