@module-federation/modern-js 0.15.0 → 0.17.0
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/configPlugin.js +5 -4
- package/dist/cjs/cli/configPlugin.spec.js +1 -3
- package/dist/cjs/cli/server/data-fetch-server-plugin.js +2 -143
- package/dist/cjs/cli/ssrPlugin.js +8 -8
- package/dist/cjs/constant.js +2 -49
- package/dist/cjs/{runtime/wrapNoSSR.js → react/index.js} +22 -13
- package/dist/cjs/runtime/index.js +0 -28
- package/dist/cjs/ssr-runtime/devPlugin.js +2 -2
- package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +6 -102
- package/dist/esm/cli/configPlugin.js +5 -4
- package/dist/esm/cli/configPlugin.spec.js +1 -3
- package/dist/esm/cli/server/data-fetch-server-plugin.js +2 -219
- package/dist/esm/cli/ssrPlugin.js +1 -1
- package/dist/esm/constant.js +1 -37
- package/dist/esm/react/index.js +12 -0
- package/dist/esm/runtime/index.js +0 -21
- package/dist/esm/ssr-runtime/devPlugin.js +1 -1
- package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.js +4 -147
- package/dist/esm-node/cli/configPlugin.js +5 -4
- package/dist/esm-node/cli/configPlugin.spec.js +1 -3
- package/dist/esm-node/cli/server/data-fetch-server-plugin.js +2 -143
- package/dist/esm-node/cli/ssrPlugin.js +1 -1
- package/dist/esm-node/constant.js +1 -37
- package/dist/esm-node/react/index.js +12 -0
- package/dist/esm-node/runtime/index.js +0 -21
- package/dist/esm-node/ssr-runtime/devPlugin.js +1 -1
- package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.js +4 -89
- package/dist/types/cli/index.d.ts +1 -1
- package/dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts +2 -2
- package/dist/types/cli/mfRuntimePlugins/resolve-entry-ipv4.d.ts +2 -2
- package/dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts +2 -2
- package/dist/types/constant.d.ts +0 -23
- package/dist/types/react/index.d.ts +2 -0
- package/dist/types/runtime/index.d.ts +0 -9
- package/dist/types/ssr-runtime/injectDataFetchFunctionPlugin.d.ts +0 -3
- package/package.json +24 -24
- package/dist/cjs/cli/mfRuntimePlugins/auto-fetch-data.js +0 -98
- package/dist/cjs/interfaces/global.js +0 -16
- package/dist/cjs/runtime/AwaitDataFetch.js +0 -144
- package/dist/cjs/runtime/createRemoteComponent.js +0 -327
- package/dist/cjs/ssr-runtime/downgrade.js +0 -114
- package/dist/cjs/utils/dataFetch.js +0 -211
- package/dist/cjs/utils/index.js +0 -54
- package/dist/esm/cli/mfRuntimePlugins/auto-fetch-data.js +0 -74
- package/dist/esm/interfaces/global.js +0 -0
- package/dist/esm/runtime/AwaitDataFetch.js +0 -131
- package/dist/esm/runtime/createRemoteComponent.js +0 -417
- package/dist/esm/runtime/wrapNoSSR.js +0 -12
- package/dist/esm/ssr-runtime/downgrade.js +0 -150
- package/dist/esm/utils/dataFetch.js +0 -237
- package/dist/esm/utils/index.js +0 -28
- package/dist/esm-node/cli/mfRuntimePlugins/auto-fetch-data.js +0 -68
- package/dist/esm-node/interfaces/global.js +0 -0
- package/dist/esm-node/runtime/AwaitDataFetch.js +0 -109
- package/dist/esm-node/runtime/createRemoteComponent.js +0 -291
- package/dist/esm-node/runtime/wrapNoSSR.js +0 -11
- package/dist/esm-node/ssr-runtime/downgrade.js +0 -88
- package/dist/esm-node/utils/dataFetch.js +0 -166
- package/dist/esm-node/utils/index.js +0 -27
- package/dist/types/cli/mfRuntimePlugins/auto-fetch-data.d.ts +0 -3
- package/dist/types/interfaces/global.d.ts +0 -27
- package/dist/types/runtime/AwaitDataFetch.d.ts +0 -19
- package/dist/types/runtime/createRemoteComponent.d.ts +0 -26
- package/dist/types/runtime/wrapNoSSR.d.ts +0 -9
- package/dist/types/ssr-runtime/downgrade.d.ts +0 -4
- package/dist/types/utils/dataFetch.d.ts +0 -26
- package/dist/types/utils/index.d.ts +0 -15
|
@@ -1,221 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
3
|
-
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
4
|
-
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
5
|
-
import { DATA_FETCH_QUERY, MF_DATA_FETCH_STATUS } from "../../constant";
|
|
6
|
-
import logger from "../../logger";
|
|
7
|
-
import { getDataFetchMap } from "../../utils";
|
|
8
|
-
import { fetchData, initDataFetchMap, loadDataFetchModule } from "../../utils/dataFetch";
|
|
9
|
-
import { SEPARATOR, MANIFEST_EXT } from "@module-federation/sdk";
|
|
10
|
-
function wrapSetTimeout(targetPromise) {
|
|
11
|
-
var delay = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 2e4, id = arguments.length > 2 ? arguments[2] : void 0;
|
|
12
|
-
if (targetPromise && typeof targetPromise.then === "function") {
|
|
13
|
-
return new Promise(function(resolve, reject) {
|
|
14
|
-
var timeoutId = setTimeout(function() {
|
|
15
|
-
logger.warn("Data fetch for ID ".concat(id, " timed out after 20 seconds."));
|
|
16
|
-
reject(new Error("Data fetch for ID ".concat(id, " timed out after 20 seconds")));
|
|
17
|
-
}, delay);
|
|
18
|
-
targetPromise.then(function(value) {
|
|
19
|
-
clearTimeout(timeoutId);
|
|
20
|
-
resolve(value);
|
|
21
|
-
}).catch(function(err) {
|
|
22
|
-
clearTimeout(timeoutId);
|
|
23
|
-
reject(err);
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
function addProtocol(url) {
|
|
29
|
-
if (url.startsWith("//")) {
|
|
30
|
-
return "https:" + url;
|
|
31
|
-
}
|
|
32
|
-
return url;
|
|
33
|
-
}
|
|
34
|
-
var getDecodeQuery = function(url, name) {
|
|
35
|
-
var res = url.searchParams.get(name);
|
|
36
|
-
if (!res) {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
return decodeURIComponent(res);
|
|
40
|
-
};
|
|
41
|
-
var middleware = function() {
|
|
42
|
-
var _ref = _async_to_generator(function(ctx, next) {
|
|
43
|
-
var _globalThis___FEDERATION__, url, dataFetchId, params, remoteInfo, remoteInfoQuery, _dataFetchMap_dataFetchId, _dataFetchMap_dataFetchId1, dataFetchMap, fetchDataPromise, targetPromise, wrappedPromise, res, hostInstance, remoteEntry, remote, _hostInstance_snapshotHandler_getGlobalRemoteInfo, hostGlobalSnapshot, remoteSnapshot, dataFetchItem, callFetchDataPromise, wrappedPromise1, res1, remoteId, hostInstance1, dataFetchFn, data, e;
|
|
44
|
-
return _ts_generator(this, function(_state) {
|
|
45
|
-
switch (_state.label) {
|
|
46
|
-
case 0:
|
|
47
|
-
try {
|
|
48
|
-
url = new URL(ctx.req.url);
|
|
49
|
-
dataFetchId = getDecodeQuery(url, DATA_FETCH_QUERY);
|
|
50
|
-
params = JSON.parse(getDecodeQuery(url, "params") || "{}");
|
|
51
|
-
remoteInfoQuery = getDecodeQuery(url, "remoteInfo");
|
|
52
|
-
remoteInfo = remoteInfoQuery ? JSON.parse(remoteInfoQuery) : null;
|
|
53
|
-
} catch (e2) {
|
|
54
|
-
logger.error("fetch data from server, error: ", e2);
|
|
55
|
-
return [
|
|
56
|
-
2,
|
|
57
|
-
next()
|
|
58
|
-
];
|
|
59
|
-
}
|
|
60
|
-
if (!dataFetchId) {
|
|
61
|
-
return [
|
|
62
|
-
2,
|
|
63
|
-
next()
|
|
64
|
-
];
|
|
65
|
-
}
|
|
66
|
-
logger.log("fetch data from server, dataFetchId: ", dataFetchId);
|
|
67
|
-
logger.debug("fetch data from server, moduleInfo: ", (_globalThis___FEDERATION__ = globalThis.__FEDERATION__) === null || _globalThis___FEDERATION__ === void 0 ? void 0 : _globalThis___FEDERATION__.moduleInfo);
|
|
68
|
-
_state.label = 1;
|
|
69
|
-
case 1:
|
|
70
|
-
_state.trys.push([
|
|
71
|
-
1,
|
|
72
|
-
9,
|
|
73
|
-
,
|
|
74
|
-
10
|
|
75
|
-
]);
|
|
76
|
-
dataFetchMap = getDataFetchMap();
|
|
77
|
-
if (!dataFetchMap) {
|
|
78
|
-
initDataFetchMap();
|
|
79
|
-
}
|
|
80
|
-
fetchDataPromise = (_dataFetchMap_dataFetchId = dataFetchMap[dataFetchId]) === null || _dataFetchMap_dataFetchId === void 0 ? void 0 : _dataFetchMap_dataFetchId[1];
|
|
81
|
-
logger.debug("fetch data from server, fetchDataPromise: ", fetchDataPromise);
|
|
82
|
-
if (!(fetchDataPromise && ((_dataFetchMap_dataFetchId1 = dataFetchMap[dataFetchId]) === null || _dataFetchMap_dataFetchId1 === void 0 ? void 0 : _dataFetchMap_dataFetchId1[2]) !== MF_DATA_FETCH_STATUS.ERROR))
|
|
83
|
-
return [
|
|
84
|
-
3,
|
|
85
|
-
4
|
|
86
|
-
];
|
|
87
|
-
targetPromise = fetchDataPromise[0];
|
|
88
|
-
wrappedPromise = wrapSetTimeout(targetPromise, 2e4, dataFetchId);
|
|
89
|
-
if (!wrappedPromise)
|
|
90
|
-
return [
|
|
91
|
-
3,
|
|
92
|
-
3
|
|
93
|
-
];
|
|
94
|
-
return [
|
|
95
|
-
4,
|
|
96
|
-
wrappedPromise
|
|
97
|
-
];
|
|
98
|
-
case 2:
|
|
99
|
-
res = _state.sent();
|
|
100
|
-
logger.log("fetch data from server, fetchDataPromise res: ", res);
|
|
101
|
-
return [
|
|
102
|
-
2,
|
|
103
|
-
ctx.json(res)
|
|
104
|
-
];
|
|
105
|
-
case 3:
|
|
106
|
-
logger.error("Expected a Promise from fetchDataPromise[0] for dataFetchId ".concat(dataFetchId, ", but received:"), targetPromise, "Will try call new dataFetch again...");
|
|
107
|
-
_state.label = 4;
|
|
108
|
-
case 4:
|
|
109
|
-
if (remoteInfo) {
|
|
110
|
-
try {
|
|
111
|
-
hostInstance = globalThis.__FEDERATION__.__INSTANCES__[0];
|
|
112
|
-
remoteEntry = "".concat(addProtocol(remoteInfo.ssrPublicPath) + remoteInfo.ssrRemoteEntry);
|
|
113
|
-
if (!hostInstance) {
|
|
114
|
-
throw new Error("host instance not found!");
|
|
115
|
-
}
|
|
116
|
-
remote = hostInstance.options.remotes.find(function(remote2) {
|
|
117
|
-
return remote2.name === remoteInfo.name;
|
|
118
|
-
});
|
|
119
|
-
logger.debug("find remote: ", JSON.stringify(remote));
|
|
120
|
-
if (!remote) {
|
|
121
|
-
hostInstance.registerRemotes([
|
|
122
|
-
{
|
|
123
|
-
name: remoteInfo.name,
|
|
124
|
-
entry: remoteEntry,
|
|
125
|
-
entryGlobalName: remoteInfo.globalName
|
|
126
|
-
}
|
|
127
|
-
]);
|
|
128
|
-
} else if (!("entry" in remote) || !remote.entry.includes(MANIFEST_EXT)) {
|
|
129
|
-
_hostInstance_snapshotHandler_getGlobalRemoteInfo = hostInstance.snapshotHandler.getGlobalRemoteInfo(remoteInfo), hostGlobalSnapshot = _hostInstance_snapshotHandler_getGlobalRemoteInfo.hostGlobalSnapshot, remoteSnapshot = _hostInstance_snapshotHandler_getGlobalRemoteInfo.remoteSnapshot;
|
|
130
|
-
logger.debug("find hostGlobalSnapshot: ", JSON.stringify(hostGlobalSnapshot));
|
|
131
|
-
logger.debug("find remoteSnapshot: ", JSON.stringify(remoteSnapshot));
|
|
132
|
-
if (!hostGlobalSnapshot || !remoteSnapshot) {
|
|
133
|
-
if ("version" in remote) {
|
|
134
|
-
delete remote.version;
|
|
135
|
-
}
|
|
136
|
-
remote.entry = remoteEntry;
|
|
137
|
-
remote.entryGlobalName = remoteInfo.globalName;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
} catch (e2) {
|
|
141
|
-
ctx.status(500);
|
|
142
|
-
return [
|
|
143
|
-
2,
|
|
144
|
-
ctx.text("failed to fetch ".concat(remoteInfo.name, " data, error:\n ").concat(e2))
|
|
145
|
-
];
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
dataFetchItem = dataFetchMap[dataFetchId];
|
|
149
|
-
logger.debug("fetch data from server, dataFetchItem: ", dataFetchItem);
|
|
150
|
-
if (!dataFetchItem)
|
|
151
|
-
return [
|
|
152
|
-
3,
|
|
153
|
-
6
|
|
154
|
-
];
|
|
155
|
-
callFetchDataPromise = fetchData(dataFetchId, _object_spread_props(_object_spread({}, params), {
|
|
156
|
-
isDowngrade: !remoteInfo
|
|
157
|
-
}));
|
|
158
|
-
wrappedPromise1 = wrapSetTimeout(callFetchDataPromise, 2e4, dataFetchId);
|
|
159
|
-
if (!wrappedPromise1)
|
|
160
|
-
return [
|
|
161
|
-
3,
|
|
162
|
-
6
|
|
163
|
-
];
|
|
164
|
-
return [
|
|
165
|
-
4,
|
|
166
|
-
wrappedPromise1
|
|
167
|
-
];
|
|
168
|
-
case 5:
|
|
169
|
-
res1 = _state.sent();
|
|
170
|
-
logger.log("fetch data from server, dataFetchItem res: ", res1);
|
|
171
|
-
return [
|
|
172
|
-
2,
|
|
173
|
-
ctx.json(res1)
|
|
174
|
-
];
|
|
175
|
-
case 6:
|
|
176
|
-
remoteId = dataFetchId.split(SEPARATOR)[0];
|
|
177
|
-
hostInstance1 = globalThis.__FEDERATION__.__INSTANCES__[0];
|
|
178
|
-
if (!hostInstance1) {
|
|
179
|
-
throw new Error("host instance not found!");
|
|
180
|
-
}
|
|
181
|
-
return [
|
|
182
|
-
4,
|
|
183
|
-
loadDataFetchModule(hostInstance1, remoteId)
|
|
184
|
-
];
|
|
185
|
-
case 7:
|
|
186
|
-
dataFetchFn = _state.sent();
|
|
187
|
-
return [
|
|
188
|
-
4,
|
|
189
|
-
dataFetchFn(_object_spread_props(_object_spread({}, params), {
|
|
190
|
-
isDowngrade: !remoteInfo
|
|
191
|
-
}))
|
|
192
|
-
];
|
|
193
|
-
case 8:
|
|
194
|
-
data = _state.sent();
|
|
195
|
-
logger.log("fetch data from server, loadDataFetchModule res: ", data);
|
|
196
|
-
return [
|
|
197
|
-
2,
|
|
198
|
-
ctx.json(data)
|
|
199
|
-
];
|
|
200
|
-
case 9:
|
|
201
|
-
e = _state.sent();
|
|
202
|
-
logger.error("server plugin data fetch error: ", e);
|
|
203
|
-
ctx.status(500);
|
|
204
|
-
return [
|
|
205
|
-
2,
|
|
206
|
-
ctx.text("failed to fetch ".concat(remoteInfo.name, " data, error:\n ").concat(e))
|
|
207
|
-
];
|
|
208
|
-
case 10:
|
|
209
|
-
return [
|
|
210
|
-
2
|
|
211
|
-
];
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
return function middleware2(ctx, next) {
|
|
216
|
-
return _ref.apply(this, arguments);
|
|
217
|
-
};
|
|
218
|
-
}();
|
|
1
|
+
import dataFetchMiddleWare from "@module-federation/bridge-react/data-fetch-server-middleware";
|
|
219
2
|
var dataFetchServePlugin = function() {
|
|
220
3
|
return {
|
|
221
4
|
name: "mf-data-fetch-server-plugin",
|
|
@@ -225,7 +8,7 @@ var dataFetchServePlugin = function() {
|
|
|
225
8
|
middlewares.push({
|
|
226
9
|
name: "module-federation-serve-manifest",
|
|
227
10
|
// @ts-ignore type error
|
|
228
|
-
handler:
|
|
11
|
+
handler: dataFetchMiddleWare
|
|
229
12
|
});
|
|
230
13
|
});
|
|
231
14
|
}
|
|
@@ -8,7 +8,7 @@ import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-
|
|
|
8
8
|
import UniverseEntryChunkTrackerPlugin from "@module-federation/node/universe-entry-chunk-tracker-plugin";
|
|
9
9
|
import logger from "../logger";
|
|
10
10
|
import { isDev } from "./utils";
|
|
11
|
-
import { updateStatsAndManifest } from "@module-federation/rsbuild-plugin/
|
|
11
|
+
import { updateStatsAndManifest } from "@module-federation/rsbuild-plugin/utils";
|
|
12
12
|
import { isWebTarget, skipByTarget } from "./utils";
|
|
13
13
|
function setEnv() {
|
|
14
14
|
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
package/dist/esm/constant.js
CHANGED
|
@@ -1,42 +1,6 @@
|
|
|
1
1
|
var LOCALHOST = "localhost";
|
|
2
2
|
var PLUGIN_IDENTIFIER = "[ Modern.js Module Federation ]";
|
|
3
|
-
var DATA_FETCH_QUERY = "x-mf-data-fetch";
|
|
4
|
-
var DATA_FETCH_ERROR_PREFIX = "caught the following error during dataFetch: ";
|
|
5
|
-
var LOAD_REMOTE_ERROR_PREFIX = "caught the following error during loadRemote: ";
|
|
6
|
-
var DOWNGRADE_KEY = "_mfSSRDowngrade";
|
|
7
|
-
var DATA_FETCH_MAP_KEY = "__MF_DATA_FETCH_MAP__";
|
|
8
|
-
var DATA_FETCH_FUNCTION = "_mfDataFetch";
|
|
9
|
-
var FS_HREF = "_mfFSHref";
|
|
10
|
-
var ERROR_TYPE = {
|
|
11
|
-
DATA_FETCH: 1,
|
|
12
|
-
LOAD_REMOTE: 2,
|
|
13
|
-
UNKNOWN: 3
|
|
14
|
-
};
|
|
15
|
-
var WRAP_DATA_FETCH_ID_IDENTIFIER = "wrap_dfip_identifier";
|
|
16
|
-
var MF_DATA_FETCH_TYPE;
|
|
17
|
-
(function(MF_DATA_FETCH_TYPE2) {
|
|
18
|
-
MF_DATA_FETCH_TYPE2[MF_DATA_FETCH_TYPE2["FETCH_SERVER"] = 1] = "FETCH_SERVER";
|
|
19
|
-
MF_DATA_FETCH_TYPE2[MF_DATA_FETCH_TYPE2["FETCH_CLIENT"] = 2] = "FETCH_CLIENT";
|
|
20
|
-
})(MF_DATA_FETCH_TYPE || (MF_DATA_FETCH_TYPE = {}));
|
|
21
|
-
var MF_DATA_FETCH_STATUS;
|
|
22
|
-
(function(MF_DATA_FETCH_STATUS2) {
|
|
23
|
-
MF_DATA_FETCH_STATUS2[MF_DATA_FETCH_STATUS2["LOADED"] = 1] = "LOADED";
|
|
24
|
-
MF_DATA_FETCH_STATUS2[MF_DATA_FETCH_STATUS2["LOADING"] = 2] = "LOADING";
|
|
25
|
-
MF_DATA_FETCH_STATUS2[MF_DATA_FETCH_STATUS2["AWAIT"] = 0] = "AWAIT";
|
|
26
|
-
MF_DATA_FETCH_STATUS2[MF_DATA_FETCH_STATUS2["ERROR"] = 3] = "ERROR";
|
|
27
|
-
})(MF_DATA_FETCH_STATUS || (MF_DATA_FETCH_STATUS = {}));
|
|
28
3
|
export {
|
|
29
|
-
DATA_FETCH_ERROR_PREFIX,
|
|
30
|
-
DATA_FETCH_FUNCTION,
|
|
31
|
-
DATA_FETCH_MAP_KEY,
|
|
32
|
-
DATA_FETCH_QUERY,
|
|
33
|
-
DOWNGRADE_KEY,
|
|
34
|
-
ERROR_TYPE,
|
|
35
|
-
FS_HREF,
|
|
36
|
-
LOAD_REMOTE_ERROR_PREFIX,
|
|
37
4
|
LOCALHOST,
|
|
38
|
-
|
|
39
|
-
MF_DATA_FETCH_TYPE,
|
|
40
|
-
PLUGIN_IDENTIFIER,
|
|
41
|
-
WRAP_DATA_FETCH_ID_IDENTIFIER
|
|
5
|
+
PLUGIN_IDENTIFIER
|
|
42
6
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ERROR_TYPE, CacheSize, CacheTime, configureCache, generateKey, cache, revalidateTag, clearStore, lazyLoadComponentPlugin } from "@module-federation/bridge-react";
|
|
2
|
+
export {
|
|
3
|
+
CacheSize,
|
|
4
|
+
CacheTime,
|
|
5
|
+
ERROR_TYPE,
|
|
6
|
+
cache,
|
|
7
|
+
clearStore,
|
|
8
|
+
configureCache,
|
|
9
|
+
generateKey,
|
|
10
|
+
lazyLoadComponentPlugin,
|
|
11
|
+
revalidateTag
|
|
12
|
+
};
|
|
@@ -1,22 +1 @@
|
|
|
1
1
|
export * from "@module-federation/enhanced/runtime";
|
|
2
|
-
import { ERROR_TYPE } from "../constant";
|
|
3
|
-
var kit = {
|
|
4
|
-
get createRemoteSSRComponent() {
|
|
5
|
-
return require("./createRemoteComponent").createRemoteSSRComponent;
|
|
6
|
-
},
|
|
7
|
-
get createRemoteComponent() {
|
|
8
|
-
return require("./createRemoteComponent").createRemoteComponent;
|
|
9
|
-
},
|
|
10
|
-
get collectSSRAssets() {
|
|
11
|
-
return require("./createRemoteComponent").collectSSRAssets;
|
|
12
|
-
},
|
|
13
|
-
get wrapNoSSR() {
|
|
14
|
-
return require("./wrapNoSSR").wrapNoSSR;
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
import { setSSREnv } from "../ssr-runtime/injectDataFetchFunctionPlugin";
|
|
18
|
-
export {
|
|
19
|
-
ERROR_TYPE,
|
|
20
|
-
kit,
|
|
21
|
-
setSSREnv
|
|
22
|
-
};
|
|
@@ -3,7 +3,7 @@ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
|
3
3
|
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 { SSRLiveReload } from "./SSRLiveReload";
|
|
6
|
-
import { flushDataFetch } from "
|
|
6
|
+
import { flushDataFetch } from "@module-federation/bridge-react/lazy-utils";
|
|
7
7
|
var mfSSRDevPlugin = function() {
|
|
8
8
|
return {
|
|
9
9
|
name: "@module-federation/modern-js",
|
|
@@ -1,167 +1,25 @@
|
|
|
1
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
2
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import { getDataFetchMap, getDataFetchItem, initDataFetchMap } from "../utils";
|
|
7
|
-
import { callAllDowngrade, callDowngrade, getDowngradeTag } from "./downgrade";
|
|
8
|
-
function setSSREnv(param) {
|
|
9
|
-
var fetchServerQuery = param.fetchServerQuery;
|
|
10
|
-
globalThis.FEDERATION_SSR = true;
|
|
11
|
-
globalThis.FEDERATION_SERVER_QUERY = fetchServerQuery;
|
|
12
|
-
}
|
|
3
|
+
import { callDataFetch } from "@module-federation/bridge-react/data-fetch-utils";
|
|
4
|
+
import { setSSREnv } from "@module-federation/bridge-react/lazy-utils";
|
|
13
5
|
var injectDataFetchFunctionPlugin = function(param) {
|
|
14
6
|
var fetchServerQuery = param.fetchServerQuery;
|
|
15
7
|
return {
|
|
16
8
|
name: "@module-federation/inject-data-fetch-function-plugin",
|
|
17
9
|
setup: function(api) {
|
|
18
10
|
api.onBeforeRender(/* @__PURE__ */ _async_to_generator(function() {
|
|
19
|
-
var _globalThis, _DATA_FETCH_FUNCTION, dataFetchFunction, dataFetch;
|
|
20
11
|
return _ts_generator(this, function(_state) {
|
|
21
12
|
switch (_state.label) {
|
|
22
13
|
case 0:
|
|
23
14
|
setSSREnv({
|
|
24
15
|
fetchServerQuery
|
|
25
16
|
});
|
|
26
|
-
if (typeof window === "undefined") {
|
|
27
|
-
return [
|
|
28
|
-
2
|
|
29
|
-
];
|
|
30
|
-
}
|
|
31
|
-
dataFetchFunction = function() {
|
|
32
|
-
var _ref = _async_to_generator(function(options) {
|
|
33
|
-
var _options, id, data, downgrade, dataFetchItem, _dataFetchItem__, _dataFetchItem_, dataFetchMap, res, rej, p, mfDowngrade, mfDowngrade1;
|
|
34
|
-
return _ts_generator(this, function(_state2) {
|
|
35
|
-
_options = _sliced_to_array(options, 3), id = _options[0], data = _options[1], downgrade = _options[2];
|
|
36
|
-
logger.debug("==========call data fetch function!");
|
|
37
|
-
if (data) {
|
|
38
|
-
if (!id) {
|
|
39
|
-
throw new Error("id is required!");
|
|
40
|
-
}
|
|
41
|
-
if (!getDataFetchMap()) {
|
|
42
|
-
initDataFetchMap();
|
|
43
|
-
}
|
|
44
|
-
dataFetchItem = getDataFetchItem(id);
|
|
45
|
-
if (dataFetchItem) {
|
|
46
|
-
;
|
|
47
|
-
(_dataFetchItem_ = dataFetchItem[1]) === null || _dataFetchItem_ === void 0 ? void 0 : (_dataFetchItem__ = _dataFetchItem_[1]) === null || _dataFetchItem__ === void 0 ? void 0 : _dataFetchItem__.call(_dataFetchItem_, data);
|
|
48
|
-
dataFetchItem[2] = MF_DATA_FETCH_STATUS.LOADED;
|
|
49
|
-
return [
|
|
50
|
-
2
|
|
51
|
-
];
|
|
52
|
-
}
|
|
53
|
-
if (!dataFetchItem) {
|
|
54
|
-
dataFetchMap = getDataFetchMap();
|
|
55
|
-
;
|
|
56
|
-
;
|
|
57
|
-
p = new Promise(function(resolve, reject) {
|
|
58
|
-
res = resolve;
|
|
59
|
-
rej = reject;
|
|
60
|
-
});
|
|
61
|
-
dataFetchMap[id] = [
|
|
62
|
-
[
|
|
63
|
-
/* @__PURE__ */ _async_to_generator(function() {
|
|
64
|
-
return _ts_generator(this, function(_state3) {
|
|
65
|
-
return [
|
|
66
|
-
2,
|
|
67
|
-
_async_to_generator(function() {
|
|
68
|
-
return _ts_generator(this, function(_state4) {
|
|
69
|
-
return [
|
|
70
|
-
2,
|
|
71
|
-
""
|
|
72
|
-
];
|
|
73
|
-
});
|
|
74
|
-
})
|
|
75
|
-
];
|
|
76
|
-
});
|
|
77
|
-
}),
|
|
78
|
-
MF_DATA_FETCH_TYPE.FETCH_SERVER
|
|
79
|
-
],
|
|
80
|
-
[
|
|
81
|
-
p,
|
|
82
|
-
res,
|
|
83
|
-
rej
|
|
84
|
-
],
|
|
85
|
-
MF_DATA_FETCH_STATUS.LOADED
|
|
86
|
-
];
|
|
87
|
-
res(data);
|
|
88
|
-
return [
|
|
89
|
-
2
|
|
90
|
-
];
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (downgrade) {
|
|
94
|
-
mfDowngrade = getDowngradeTag();
|
|
95
|
-
if (!mfDowngrade) {
|
|
96
|
-
globalThis[DOWNGRADE_KEY] = id ? [
|
|
97
|
-
id
|
|
98
|
-
] : true;
|
|
99
|
-
} else if (Array.isArray(mfDowngrade) && id && !mfDowngrade.includes(id)) {
|
|
100
|
-
mfDowngrade.push(id);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
mfDowngrade1 = getDowngradeTag();
|
|
104
|
-
if (typeof mfDowngrade1 === "boolean") {
|
|
105
|
-
return [
|
|
106
|
-
2,
|
|
107
|
-
callAllDowngrade()
|
|
108
|
-
];
|
|
109
|
-
}
|
|
110
|
-
if (Array.isArray(mfDowngrade1)) {
|
|
111
|
-
if (!id) {
|
|
112
|
-
globalThis[DOWNGRADE_KEY] = true;
|
|
113
|
-
return [
|
|
114
|
-
2,
|
|
115
|
-
callAllDowngrade()
|
|
116
|
-
];
|
|
117
|
-
}
|
|
118
|
-
if (!mfDowngrade1.includes(id)) {
|
|
119
|
-
mfDowngrade1.push(id);
|
|
120
|
-
}
|
|
121
|
-
return [
|
|
122
|
-
2,
|
|
123
|
-
callDowngrade(id)
|
|
124
|
-
];
|
|
125
|
-
}
|
|
126
|
-
return [
|
|
127
|
-
2
|
|
128
|
-
];
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
return function dataFetchFunction2(options) {
|
|
132
|
-
return _ref.apply(this, arguments);
|
|
133
|
-
};
|
|
134
|
-
}();
|
|
135
|
-
globalThis[FS_HREF] = window.location.href;
|
|
136
|
-
(_globalThis = globalThis)[_DATA_FETCH_FUNCTION = DATA_FETCH_FUNCTION] || (_globalThis[_DATA_FETCH_FUNCTION] = []);
|
|
137
|
-
dataFetch = globalThis[DATA_FETCH_FUNCTION];
|
|
138
17
|
return [
|
|
139
18
|
4,
|
|
140
|
-
|
|
141
|
-
var _ref = _async_to_generator(function(options) {
|
|
142
|
-
return _ts_generator(this, function(_state2) {
|
|
143
|
-
switch (_state2.label) {
|
|
144
|
-
case 0:
|
|
145
|
-
return [
|
|
146
|
-
4,
|
|
147
|
-
dataFetchFunction(options)
|
|
148
|
-
];
|
|
149
|
-
case 1:
|
|
150
|
-
_state2.sent();
|
|
151
|
-
return [
|
|
152
|
-
2
|
|
153
|
-
];
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
return function(options) {
|
|
158
|
-
return _ref.apply(this, arguments);
|
|
159
|
-
};
|
|
160
|
-
}()))
|
|
19
|
+
callDataFetch()
|
|
161
20
|
];
|
|
162
21
|
case 1:
|
|
163
22
|
_state.sent();
|
|
164
|
-
dataFetch.push = dataFetchFunction;
|
|
165
23
|
return [
|
|
166
24
|
2
|
|
167
25
|
];
|
|
@@ -172,6 +30,5 @@ var injectDataFetchFunctionPlugin = function(param) {
|
|
|
172
30
|
};
|
|
173
31
|
};
|
|
174
32
|
export {
|
|
175
|
-
injectDataFetchFunctionPlugin
|
|
176
|
-
setSSREnv
|
|
33
|
+
injectDataFetchFunctionPlugin
|
|
177
34
|
};
|
|
@@ -107,7 +107,6 @@ const patchMFConfig = (mfConfig, isServer, remoteIpStrategy, enableSSR) => {
|
|
|
107
107
|
];
|
|
108
108
|
patchDTSConfig(mfConfig, isServer);
|
|
109
109
|
injectRuntimePlugins(require.resolve("@module-federation/modern-js/shared-strategy"), runtimePlugins);
|
|
110
|
-
injectRuntimePlugins(require.resolve("@module-federation/modern-js/auto-fetch-data"), runtimePlugins);
|
|
111
110
|
if (enableSSR && isDev()) {
|
|
112
111
|
injectRuntimePlugins(require.resolve("@module-federation/modern-js/resolve-entry-ipv4"), runtimePlugins);
|
|
113
112
|
}
|
|
@@ -223,7 +222,7 @@ function patchBundlerConfig(options) {
|
|
|
223
222
|
const uniqueName = mfConfig.name || chain.output.get("uniqueName");
|
|
224
223
|
const chunkFileName = chain.output.get("chunkFilename");
|
|
225
224
|
if (typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
226
|
-
const suffix = `${encodeName(uniqueName)}-[
|
|
225
|
+
const suffix = `${encodeName(uniqueName)}-[contenthash].js`;
|
|
227
226
|
chain.output.chunkFilename(chunkFileName.replace(".js", suffix));
|
|
228
227
|
}
|
|
229
228
|
}
|
|
@@ -311,11 +310,13 @@ const moduleFederationConfigPlugin = (userConfig) => ({
|
|
|
311
310
|
headers: corsHeaders
|
|
312
311
|
}
|
|
313
312
|
},
|
|
314
|
-
|
|
313
|
+
resolve: {
|
|
315
314
|
alias: {
|
|
316
315
|
// TODO: deprecated
|
|
317
316
|
"@modern-js/runtime/mf": require.resolve("@module-federation/modern-js/runtime")
|
|
318
|
-
}
|
|
317
|
+
}
|
|
318
|
+
},
|
|
319
|
+
source: {
|
|
319
320
|
define: defineConfig,
|
|
320
321
|
enableAsyncEntry: bundlerType === "rspack" ? (_modernjsConfig_source_enableAsyncEntry = (_modernjsConfig_source = modernjsConfig.source) === null || _modernjsConfig_source === void 0 ? void 0 : _modernjsConfig_source.enableAsyncEntry) !== null && _modernjsConfig_source_enableAsyncEntry !== void 0 ? _modernjsConfig_source_enableAsyncEntry : true : (_modernjsConfig_source1 = modernjsConfig.source) === null || _modernjsConfig_source1 === void 0 ? void 0 : _modernjsConfig_source1.enableAsyncEntry
|
|
321
322
|
},
|
|
@@ -38,7 +38,6 @@ describe("patchMFConfig", async () => {
|
|
|
38
38
|
remoteType: "script",
|
|
39
39
|
runtimePlugins: [
|
|
40
40
|
require.resolve("@module-federation/modern-js/shared-strategy"),
|
|
41
|
-
require.resolve("@module-federation/modern-js/auto-fetch-data"),
|
|
42
41
|
require.resolve("@module-federation/node/runtimePlugin"),
|
|
43
42
|
require.resolve("@module-federation/modern-js/inject-node-fetch")
|
|
44
43
|
],
|
|
@@ -66,8 +65,7 @@ describe("patchMFConfig", async () => {
|
|
|
66
65
|
},
|
|
67
66
|
remoteType: "script",
|
|
68
67
|
runtimePlugins: [
|
|
69
|
-
require.resolve("@module-federation/modern-js/shared-strategy")
|
|
70
|
-
require.resolve("@module-federation/modern-js/auto-fetch-data")
|
|
68
|
+
require.resolve("@module-federation/modern-js/shared-strategy")
|
|
71
69
|
],
|
|
72
70
|
shared: {
|
|
73
71
|
react: {
|