@module-federation/modern-js 0.14.3 → 0.15.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 +17 -13
- package/dist/cjs/cli/configPlugin.spec.js +3 -1
- package/dist/cjs/cli/index.js +3 -1
- package/dist/cjs/cli/mfRuntimePlugins/auto-fetch-data.js +98 -0
- package/dist/cjs/cli/server/data-fetch-server-plugin.js +189 -0
- package/dist/cjs/cli/ssrPlugin.js +31 -12
- package/dist/cjs/cli/utils.js +5 -0
- package/dist/cjs/constant.js +49 -2
- package/dist/cjs/{ssr-runtime/index.js → interfaces/global.js} +2 -8
- package/dist/cjs/{cli/logger.js → logger.js} +1 -1
- package/dist/cjs/runtime/AwaitDataFetch.js +144 -0
- package/dist/cjs/runtime/createRemoteComponent.js +327 -0
- package/dist/cjs/runtime/index.js +15 -3
- package/dist/cjs/{cli/constant.js → runtime/wrapNoSSR.js} +13 -6
- package/dist/cjs/ssr-runtime/{plugin.js → devPlugin.js} +9 -6
- package/dist/cjs/ssr-runtime/downgrade.js +114 -0
- package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +136 -0
- package/dist/cjs/utils/dataFetch.js +211 -0
- package/dist/cjs/utils/index.js +54 -0
- package/dist/esm/cli/configPlugin.js +18 -14
- package/dist/esm/cli/configPlugin.spec.js +3 -1
- package/dist/esm/cli/index.js +3 -1
- package/dist/esm/cli/mfRuntimePlugins/auto-fetch-data.js +74 -0
- package/dist/esm/cli/server/data-fetch-server-plugin.js +237 -0
- package/dist/esm/cli/ssrPlugin.js +28 -8
- package/dist/esm/cli/utils.js +4 -0
- package/dist/esm/constant.js +37 -1
- package/dist/esm/interfaces/global.js +0 -0
- package/dist/esm/{cli/logger.js → logger.js} +1 -1
- package/dist/esm/runtime/AwaitDataFetch.js +131 -0
- package/dist/esm/runtime/createRemoteComponent.js +417 -0
- package/dist/esm/runtime/index.js +13 -3
- package/dist/esm/runtime/wrapNoSSR.js +12 -0
- package/dist/esm/ssr-runtime/{plugin.js → devPlugin.js} +5 -2
- package/dist/esm/ssr-runtime/downgrade.js +150 -0
- package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.js +177 -0
- package/dist/esm/utils/dataFetch.js +237 -0
- package/dist/esm/utils/index.js +28 -0
- package/dist/esm-node/cli/configPlugin.js +18 -14
- package/dist/esm-node/cli/configPlugin.spec.js +3 -1
- package/dist/esm-node/cli/index.js +3 -1
- package/dist/esm-node/cli/mfRuntimePlugins/auto-fetch-data.js +68 -0
- package/dist/esm-node/cli/server/data-fetch-server-plugin.js +159 -0
- package/dist/esm-node/cli/ssrPlugin.js +27 -8
- package/dist/esm-node/cli/utils.js +4 -0
- package/dist/esm-node/constant.js +37 -1
- package/dist/esm-node/interfaces/global.js +0 -0
- package/dist/esm-node/{cli/logger.js → logger.js} +1 -1
- package/dist/esm-node/runtime/AwaitDataFetch.js +109 -0
- package/dist/esm-node/runtime/createRemoteComponent.js +291 -0
- package/dist/esm-node/runtime/index.js +13 -3
- package/dist/esm-node/runtime/wrapNoSSR.js +11 -0
- package/dist/esm-node/ssr-runtime/{plugin.js → devPlugin.js} +5 -2
- package/dist/esm-node/ssr-runtime/downgrade.js +88 -0
- package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.js +101 -0
- package/dist/esm-node/utils/dataFetch.js +166 -0
- package/dist/esm-node/utils/index.js +27 -0
- package/dist/types/cli/configPlugin.d.ts +1 -1
- package/dist/types/cli/index.d.ts +1 -0
- package/dist/types/cli/mfRuntimePlugins/auto-fetch-data.d.ts +3 -0
- package/dist/types/cli/server/data-fetch-server-plugin.d.ts +3 -0
- package/dist/types/cli/utils.d.ts +1 -0
- package/dist/types/constant.d.ts +23 -0
- package/dist/types/interfaces/global.d.ts +27 -0
- package/dist/types/runtime/AwaitDataFetch.d.ts +19 -0
- package/dist/types/runtime/createRemoteComponent.d.ts +26 -0
- package/dist/types/runtime/index.d.ts +7 -2
- package/dist/types/runtime/wrapNoSSR.d.ts +9 -0
- package/dist/types/ssr-runtime/devPlugin.d.ts +2 -0
- package/dist/types/ssr-runtime/downgrade.d.ts +4 -0
- package/dist/types/ssr-runtime/injectDataFetchFunctionPlugin.d.ts +7 -0
- package/dist/types/types/index.d.ts +2 -0
- package/dist/types/utils/dataFetch.d.ts +26 -0
- package/dist/types/utils/index.d.ts +15 -0
- package/package.json +37 -12
- package/dist/cjs/cli/manifest.js +0 -75
- package/dist/cjs/runtime/createRemoteSSRComponent.js +0 -201
- package/dist/esm/cli/constant.js +0 -4
- package/dist/esm/cli/manifest.js +0 -41
- package/dist/esm/runtime/createRemoteSSRComponent.js +0 -191
- package/dist/esm/ssr-runtime/index.js +0 -1
- package/dist/esm-node/cli/constant.js +0 -4
- package/dist/esm-node/cli/manifest.js +0 -41
- package/dist/esm-node/runtime/createRemoteSSRComponent.js +0 -166
- package/dist/esm-node/ssr-runtime/index.js +0 -1
- package/dist/types/cli/constant.d.ts +0 -1
- package/dist/types/cli/manifest.d.ts +0 -2
- package/dist/types/runtime/createRemoteSSRComponent.d.ts +0 -18
- package/dist/types/ssr-runtime/index.d.ts +0 -1
- package/dist/types/ssr-runtime/plugin.d.ts +0 -2
- /package/dist/types/{cli/logger.d.ts → logger.d.ts} +0 -0
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
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 _object_without_properties } from "@swc/helpers/_/_object_without_properties";
|
|
5
|
+
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
6
|
+
import { _ as _tagged_template_literal } from "@swc/helpers/_/_tagged_template_literal";
|
|
7
|
+
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
8
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
9
|
+
function _templateObject() {
|
|
10
|
+
var data = _tagged_template_literal([
|
|
11
|
+
"\n globalThis['",
|
|
12
|
+
"'] = globalThis['",
|
|
13
|
+
"'] || [];\n globalThis['",
|
|
14
|
+
"'].push(['",
|
|
15
|
+
"',",
|
|
16
|
+
"]);\n "
|
|
17
|
+
]);
|
|
18
|
+
_templateObject = function _templateObject2() {
|
|
19
|
+
return data;
|
|
20
|
+
};
|
|
21
|
+
return data;
|
|
22
|
+
}
|
|
23
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
24
|
+
import React, { useEffect, useState } from "react";
|
|
25
|
+
import logger from "../logger";
|
|
26
|
+
import { getInstance } from "@module-federation/enhanced/runtime";
|
|
27
|
+
import { AwaitDataFetch, transformError } from "./AwaitDataFetch";
|
|
28
|
+
import { fetchData, getDataFetchItem, getDataFetchMapKey } from "../utils/dataFetch";
|
|
29
|
+
import { getDataFetchInfo, getLoadedRemoteInfos, setDataFetchItemLoadedStatus, wrapDataFetchId } from "../utils";
|
|
30
|
+
import { DATA_FETCH_ERROR_PREFIX, DATA_FETCH_FUNCTION, FS_HREF, LOAD_REMOTE_ERROR_PREFIX, MF_DATA_FETCH_TYPE } from "../constant";
|
|
31
|
+
function getTargetModuleInfo(id) {
|
|
32
|
+
var instance = getInstance();
|
|
33
|
+
if (!instance) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
var loadedRemoteInfo = getLoadedRemoteInfos(id, instance);
|
|
37
|
+
if (!loadedRemoteInfo) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
var snapshot = loadedRemoteInfo.snapshot;
|
|
41
|
+
if (!snapshot) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
var publicPath = "publicPath" in snapshot ? snapshot.publicPath : "getPublicPath" in snapshot ? new Function(snapshot.getPublicPath)() : "";
|
|
45
|
+
if (!publicPath) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
var modules = "modules" in snapshot ? snapshot.modules : [];
|
|
49
|
+
var targetModule = modules.find(function(m) {
|
|
50
|
+
return m.modulePath === loadedRemoteInfo.expose;
|
|
51
|
+
});
|
|
52
|
+
if (!targetModule) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
var remoteEntry = "remoteEntry" in snapshot ? snapshot.remoteEntry : "";
|
|
56
|
+
if (!remoteEntry) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
module: targetModule,
|
|
61
|
+
publicPath,
|
|
62
|
+
remoteEntry
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function collectSSRAssets(options) {
|
|
66
|
+
var _ref = typeof options === "string" ? {
|
|
67
|
+
id: options
|
|
68
|
+
} : options, id = _ref.id, _ref_injectLink = _ref.injectLink, injectLink = _ref_injectLink === void 0 ? true : _ref_injectLink, _ref_injectScript = _ref.injectScript, injectScript = _ref_injectScript === void 0 ? false : _ref_injectScript;
|
|
69
|
+
var links = [];
|
|
70
|
+
var scripts = [];
|
|
71
|
+
var instance = getInstance();
|
|
72
|
+
if (!instance || !injectLink && !injectScript) {
|
|
73
|
+
return _to_consumable_array(scripts).concat(_to_consumable_array(links));
|
|
74
|
+
}
|
|
75
|
+
var moduleAndPublicPath = getTargetModuleInfo(id);
|
|
76
|
+
if (!moduleAndPublicPath) {
|
|
77
|
+
return _to_consumable_array(scripts).concat(_to_consumable_array(links));
|
|
78
|
+
}
|
|
79
|
+
var targetModule = moduleAndPublicPath.module, publicPath = moduleAndPublicPath.publicPath, remoteEntry = moduleAndPublicPath.remoteEntry;
|
|
80
|
+
if (injectLink) {
|
|
81
|
+
_to_consumable_array(targetModule.assets.css.sync).concat(_to_consumable_array(targetModule.assets.css.async)).sort().forEach(function(file, index) {
|
|
82
|
+
links.push(/* @__PURE__ */ _jsx("link", {
|
|
83
|
+
href: "".concat(publicPath).concat(file),
|
|
84
|
+
rel: "stylesheet",
|
|
85
|
+
type: "text/css"
|
|
86
|
+
}, "".concat(file.split(".")[0], "_").concat(index)));
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (injectScript) {
|
|
90
|
+
scripts.push(/* @__PURE__ */ _jsx("script", {
|
|
91
|
+
async: true,
|
|
92
|
+
src: "".concat(publicPath).concat(remoteEntry),
|
|
93
|
+
crossOrigin: "anonymous"
|
|
94
|
+
}, remoteEntry.split(".")[0]));
|
|
95
|
+
_to_consumable_array(targetModule.assets.js.sync).sort().forEach(function(file, index) {
|
|
96
|
+
scripts.push(/* @__PURE__ */ _jsx("script", {
|
|
97
|
+
async: true,
|
|
98
|
+
src: "".concat(publicPath).concat(file),
|
|
99
|
+
crossOrigin: "anonymous"
|
|
100
|
+
}, "".concat(file.split(".")[0], "_").concat(index)));
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
return _to_consumable_array(scripts).concat(_to_consumable_array(links));
|
|
104
|
+
}
|
|
105
|
+
function getServerNeedRemoteInfo(loadedRemoteInfo, id, noSSR) {
|
|
106
|
+
if (noSSR || typeof window !== "undefined" && window.location.href !== window[FS_HREF]) {
|
|
107
|
+
var _dataFetchItem_;
|
|
108
|
+
if (!(loadedRemoteInfo === null || loadedRemoteInfo === void 0 ? void 0 : loadedRemoteInfo.version)) {
|
|
109
|
+
throw new Error("".concat(loadedRemoteInfo === null || loadedRemoteInfo === void 0 ? void 0 : loadedRemoteInfo.name, " version is empty"));
|
|
110
|
+
}
|
|
111
|
+
var snapshot = loadedRemoteInfo.snapshot;
|
|
112
|
+
if (!snapshot) {
|
|
113
|
+
throw new Error("".concat(loadedRemoteInfo === null || loadedRemoteInfo === void 0 ? void 0 : loadedRemoteInfo.name, " snapshot is empty"));
|
|
114
|
+
}
|
|
115
|
+
var dataFetchItem = getDataFetchItem(id);
|
|
116
|
+
var isFetchServer = (dataFetchItem === null || dataFetchItem === void 0 ? void 0 : (_dataFetchItem_ = dataFetchItem[0]) === null || _dataFetchItem_ === void 0 ? void 0 : _dataFetchItem_[1]) === MF_DATA_FETCH_TYPE.FETCH_SERVER;
|
|
117
|
+
if (isFetchServer && (!("ssrPublicPath" in snapshot) || !snapshot.ssrPublicPath)) {
|
|
118
|
+
throw new Error("ssrPublicPath is required while fetching ".concat(loadedRemoteInfo === null || loadedRemoteInfo === void 0 ? void 0 : loadedRemoteInfo.name, " data in SSR project!"));
|
|
119
|
+
}
|
|
120
|
+
if (isFetchServer && (!("ssrRemoteEntry" in snapshot) || !snapshot.ssrRemoteEntry)) {
|
|
121
|
+
throw new Error("ssrRemoteEntry is required while loading ".concat(loadedRemoteInfo === null || loadedRemoteInfo === void 0 ? void 0 : loadedRemoteInfo.name, " data loader in SSR project!"));
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
name: loadedRemoteInfo.name,
|
|
125
|
+
version: loadedRemoteInfo.version,
|
|
126
|
+
ssrPublicPath: "ssrPublicPath" in snapshot ? snapshot.ssrPublicPath || "" : "",
|
|
127
|
+
ssrRemoteEntry: "ssrRemoteEntry" in snapshot ? snapshot.ssrRemoteEntry || "" : "",
|
|
128
|
+
globalName: loadedRemoteInfo.entryGlobalName
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
function createRemoteComponent(options) {
|
|
134
|
+
var exportName = (options === null || options === void 0 ? void 0 : options.export) || "default";
|
|
135
|
+
var callLoader = function() {
|
|
136
|
+
var _ref = _async_to_generator(function() {
|
|
137
|
+
var m;
|
|
138
|
+
return _ts_generator(this, function(_state) {
|
|
139
|
+
switch (_state.label) {
|
|
140
|
+
case 0:
|
|
141
|
+
logger.debug("callLoader start", Date.now());
|
|
142
|
+
return [
|
|
143
|
+
4,
|
|
144
|
+
options.loader()
|
|
145
|
+
];
|
|
146
|
+
case 1:
|
|
147
|
+
m = _state.sent();
|
|
148
|
+
logger.debug("callLoader end", Date.now());
|
|
149
|
+
if (!m) {
|
|
150
|
+
throw new Error("load remote failed");
|
|
151
|
+
}
|
|
152
|
+
return [
|
|
153
|
+
2,
|
|
154
|
+
m
|
|
155
|
+
];
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
return function callLoader2() {
|
|
160
|
+
return _ref.apply(this, arguments);
|
|
161
|
+
};
|
|
162
|
+
}();
|
|
163
|
+
var getData = function() {
|
|
164
|
+
var _ref = _async_to_generator(function(noSSR) {
|
|
165
|
+
var loadedRemoteInfo, moduleId, instance, m, e, errMsg, dataFetchMapKey, data, err, errMsg1;
|
|
166
|
+
return _ts_generator(this, function(_state) {
|
|
167
|
+
switch (_state.label) {
|
|
168
|
+
case 0:
|
|
169
|
+
instance = getInstance();
|
|
170
|
+
_state.label = 1;
|
|
171
|
+
case 1:
|
|
172
|
+
_state.trys.push([
|
|
173
|
+
1,
|
|
174
|
+
3,
|
|
175
|
+
,
|
|
176
|
+
4
|
|
177
|
+
]);
|
|
178
|
+
return [
|
|
179
|
+
4,
|
|
180
|
+
callLoader()
|
|
181
|
+
];
|
|
182
|
+
case 2:
|
|
183
|
+
m = _state.sent();
|
|
184
|
+
moduleId = m && m[Symbol.for("mf_module_id")];
|
|
185
|
+
if (!moduleId) {
|
|
186
|
+
throw new Error("moduleId is empty");
|
|
187
|
+
}
|
|
188
|
+
loadedRemoteInfo = getLoadedRemoteInfos(moduleId, instance);
|
|
189
|
+
if (!loadedRemoteInfo) {
|
|
190
|
+
throw new Error("can not find loaded remote('".concat(moduleId, "') info!"));
|
|
191
|
+
}
|
|
192
|
+
return [
|
|
193
|
+
3,
|
|
194
|
+
4
|
|
195
|
+
];
|
|
196
|
+
case 3:
|
|
197
|
+
e = _state.sent();
|
|
198
|
+
errMsg = "".concat(LOAD_REMOTE_ERROR_PREFIX).concat(e);
|
|
199
|
+
logger.debug(e);
|
|
200
|
+
throw new Error(errMsg);
|
|
201
|
+
case 4:
|
|
202
|
+
_state.trys.push([
|
|
203
|
+
4,
|
|
204
|
+
6,
|
|
205
|
+
,
|
|
206
|
+
7
|
|
207
|
+
]);
|
|
208
|
+
dataFetchMapKey = getDataFetchMapKey(getDataFetchInfo({
|
|
209
|
+
name: loadedRemoteInfo.name,
|
|
210
|
+
alias: loadedRemoteInfo.alias,
|
|
211
|
+
id: moduleId,
|
|
212
|
+
remoteSnapshot: loadedRemoteInfo.snapshot
|
|
213
|
+
}), {
|
|
214
|
+
name: instance.name,
|
|
215
|
+
version: instance === null || instance === void 0 ? void 0 : instance.options.version
|
|
216
|
+
});
|
|
217
|
+
logger.debug("getData dataFetchMapKey: ", dataFetchMapKey);
|
|
218
|
+
if (!dataFetchMapKey) {
|
|
219
|
+
return [
|
|
220
|
+
2
|
|
221
|
+
];
|
|
222
|
+
}
|
|
223
|
+
return [
|
|
224
|
+
4,
|
|
225
|
+
fetchData(dataFetchMapKey, _object_spread_props(_object_spread({}, options.dataFetchParams), {
|
|
226
|
+
isDowngrade: false
|
|
227
|
+
}), getServerNeedRemoteInfo(loadedRemoteInfo, dataFetchMapKey, noSSR))
|
|
228
|
+
];
|
|
229
|
+
case 5:
|
|
230
|
+
data = _state.sent();
|
|
231
|
+
setDataFetchItemLoadedStatus(dataFetchMapKey);
|
|
232
|
+
logger.debug("get data res: \n", data);
|
|
233
|
+
return [
|
|
234
|
+
2,
|
|
235
|
+
data
|
|
236
|
+
];
|
|
237
|
+
case 6:
|
|
238
|
+
err = _state.sent();
|
|
239
|
+
errMsg1 = "".concat(DATA_FETCH_ERROR_PREFIX).concat(wrapDataFetchId(dataFetchMapKey)).concat(err);
|
|
240
|
+
logger.debug(errMsg1);
|
|
241
|
+
throw new Error(errMsg1);
|
|
242
|
+
case 7:
|
|
243
|
+
return [
|
|
244
|
+
2
|
|
245
|
+
];
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
return function getData2(noSSR) {
|
|
250
|
+
return _ref.apply(this, arguments);
|
|
251
|
+
};
|
|
252
|
+
}();
|
|
253
|
+
var LazyComponent = /* @__PURE__ */ React.lazy(/* @__PURE__ */ _async_to_generator(function() {
|
|
254
|
+
var m, moduleId, instance, loadedRemoteInfo, dataFetchMapKey, assets, Com;
|
|
255
|
+
return _ts_generator(this, function(_state) {
|
|
256
|
+
switch (_state.label) {
|
|
257
|
+
case 0:
|
|
258
|
+
return [
|
|
259
|
+
4,
|
|
260
|
+
callLoader()
|
|
261
|
+
];
|
|
262
|
+
case 1:
|
|
263
|
+
m = _state.sent();
|
|
264
|
+
moduleId = m && m[Symbol.for("mf_module_id")];
|
|
265
|
+
instance = getInstance();
|
|
266
|
+
loadedRemoteInfo = getLoadedRemoteInfos(moduleId, instance);
|
|
267
|
+
loadedRemoteInfo === null || loadedRemoteInfo === void 0 ? void 0 : loadedRemoteInfo.snapshot;
|
|
268
|
+
dataFetchMapKey = loadedRemoteInfo ? getDataFetchMapKey(getDataFetchInfo({
|
|
269
|
+
name: loadedRemoteInfo.name,
|
|
270
|
+
alias: loadedRemoteInfo.alias,
|
|
271
|
+
id: moduleId,
|
|
272
|
+
remoteSnapshot: loadedRemoteInfo.snapshot
|
|
273
|
+
}), {
|
|
274
|
+
name: instance.name,
|
|
275
|
+
version: instance === null || instance === void 0 ? void 0 : instance.options.version
|
|
276
|
+
}) : void 0;
|
|
277
|
+
logger.debug("LazyComponent dataFetchMapKey: ", dataFetchMapKey);
|
|
278
|
+
assets = collectSSRAssets({
|
|
279
|
+
id: moduleId
|
|
280
|
+
});
|
|
281
|
+
Com = m[exportName];
|
|
282
|
+
if (exportName in m && typeof Com === "function") {
|
|
283
|
+
return [
|
|
284
|
+
2,
|
|
285
|
+
{
|
|
286
|
+
default: function(props) {
|
|
287
|
+
return /* @__PURE__ */ _jsxs(_Fragment, {
|
|
288
|
+
children: [
|
|
289
|
+
globalThis.FEDERATION_SSR && dataFetchMapKey && /* @__PURE__ */ _jsx("script", {
|
|
290
|
+
suppressHydrationWarning: true,
|
|
291
|
+
dangerouslySetInnerHTML: {
|
|
292
|
+
__html: String.raw(_templateObject(), DATA_FETCH_FUNCTION, DATA_FETCH_FUNCTION, DATA_FETCH_FUNCTION, dataFetchMapKey, JSON.stringify(props.mfData))
|
|
293
|
+
}
|
|
294
|
+
}),
|
|
295
|
+
globalThis.FEDERATION_SSR && assets,
|
|
296
|
+
/* @__PURE__ */ _jsx(Com, _object_spread({}, props))
|
|
297
|
+
]
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
];
|
|
302
|
+
} else {
|
|
303
|
+
throw Error("Make sure that ".concat(moduleId, " has the correct export when export is ").concat(String(exportName)));
|
|
304
|
+
}
|
|
305
|
+
return [
|
|
306
|
+
2
|
|
307
|
+
];
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
}));
|
|
311
|
+
return function(props) {
|
|
312
|
+
var key = props.key, args = _object_without_properties(props, [
|
|
313
|
+
"key"
|
|
314
|
+
]);
|
|
315
|
+
if (globalThis.FEDERATION_SSR && !options.noSSR) {
|
|
316
|
+
var key1 = props.key, args1 = _object_without_properties(props, [
|
|
317
|
+
"key"
|
|
318
|
+
]);
|
|
319
|
+
return /* @__PURE__ */ _jsx(AwaitDataFetch, {
|
|
320
|
+
resolve: getData(options.noSSR),
|
|
321
|
+
loading: options.loading,
|
|
322
|
+
errorElement: options.fallback,
|
|
323
|
+
children: function(data2) {
|
|
324
|
+
return /* @__PURE__ */ _jsx(LazyComponent, _object_spread_props(_object_spread({}, args1), {
|
|
325
|
+
mfData: data2
|
|
326
|
+
}));
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
} else {
|
|
330
|
+
var _useState = _sliced_to_array(useState(null), 2), data = _useState[0], setData = _useState[1];
|
|
331
|
+
var _useState1 = _sliced_to_array(useState(true), 2), loading = _useState1[0], setLoading = _useState1[1];
|
|
332
|
+
var _useState2 = _sliced_to_array(useState(null), 2), error = _useState2[0], setError = _useState2[1];
|
|
333
|
+
useEffect(function() {
|
|
334
|
+
var isMounted = true;
|
|
335
|
+
var fetchDataAsync = function() {
|
|
336
|
+
var _ref = _async_to_generator(function() {
|
|
337
|
+
var result, e;
|
|
338
|
+
return _ts_generator(this, function(_state) {
|
|
339
|
+
switch (_state.label) {
|
|
340
|
+
case 0:
|
|
341
|
+
_state.trys.push([
|
|
342
|
+
0,
|
|
343
|
+
2,
|
|
344
|
+
3,
|
|
345
|
+
4
|
|
346
|
+
]);
|
|
347
|
+
setLoading(true);
|
|
348
|
+
return [
|
|
349
|
+
4,
|
|
350
|
+
getData(options.noSSR)
|
|
351
|
+
];
|
|
352
|
+
case 1:
|
|
353
|
+
result = _state.sent();
|
|
354
|
+
if (isMounted) {
|
|
355
|
+
setData(result);
|
|
356
|
+
}
|
|
357
|
+
return [
|
|
358
|
+
3,
|
|
359
|
+
4
|
|
360
|
+
];
|
|
361
|
+
case 2:
|
|
362
|
+
e = _state.sent();
|
|
363
|
+
if (isMounted) {
|
|
364
|
+
setError(transformError(e));
|
|
365
|
+
}
|
|
366
|
+
return [
|
|
367
|
+
3,
|
|
368
|
+
4
|
|
369
|
+
];
|
|
370
|
+
case 3:
|
|
371
|
+
if (isMounted) {
|
|
372
|
+
setLoading(false);
|
|
373
|
+
}
|
|
374
|
+
return [
|
|
375
|
+
7
|
|
376
|
+
];
|
|
377
|
+
case 4:
|
|
378
|
+
return [
|
|
379
|
+
2
|
|
380
|
+
];
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
});
|
|
384
|
+
return function fetchDataAsync2() {
|
|
385
|
+
return _ref.apply(this, arguments);
|
|
386
|
+
};
|
|
387
|
+
}();
|
|
388
|
+
fetchDataAsync();
|
|
389
|
+
return function() {
|
|
390
|
+
isMounted = false;
|
|
391
|
+
};
|
|
392
|
+
}, []);
|
|
393
|
+
if (loading) {
|
|
394
|
+
return /* @__PURE__ */ _jsx(_Fragment, {
|
|
395
|
+
children: options.loading
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
if (error) {
|
|
399
|
+
return /* @__PURE__ */ _jsx(_Fragment, {
|
|
400
|
+
children: typeof options.fallback === "function" ? options.fallback(error) : options.fallback
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
return /* @__PURE__ */ _jsx(LazyComponent, _object_spread_props(_object_spread({}, args), {
|
|
404
|
+
mfData: data
|
|
405
|
+
}));
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
function createRemoteSSRComponent(options) {
|
|
410
|
+
logger.warn("createRemoteSSRComponent is deprecated, please use createRemoteComponent instead!");
|
|
411
|
+
return createRemoteComponent(options);
|
|
412
|
+
}
|
|
413
|
+
export {
|
|
414
|
+
collectSSRAssets,
|
|
415
|
+
createRemoteComponent,
|
|
416
|
+
createRemoteSSRComponent
|
|
417
|
+
};
|
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
export * from "@module-federation/enhanced/runtime";
|
|
2
|
+
import { ERROR_TYPE } from "../constant";
|
|
2
3
|
var kit = {
|
|
3
4
|
get createRemoteSSRComponent() {
|
|
4
|
-
return require("./
|
|
5
|
+
return require("./createRemoteComponent").createRemoteSSRComponent;
|
|
6
|
+
},
|
|
7
|
+
get createRemoteComponent() {
|
|
8
|
+
return require("./createRemoteComponent").createRemoteComponent;
|
|
5
9
|
},
|
|
6
10
|
get collectSSRAssets() {
|
|
7
|
-
return require("./
|
|
11
|
+
return require("./createRemoteComponent").collectSSRAssets;
|
|
12
|
+
},
|
|
13
|
+
get wrapNoSSR() {
|
|
14
|
+
return require("./wrapNoSSR").wrapNoSSR;
|
|
8
15
|
}
|
|
9
16
|
};
|
|
17
|
+
import { setSSREnv } from "../ssr-runtime/injectDataFetchFunctionPlugin";
|
|
10
18
|
export {
|
|
11
|
-
|
|
19
|
+
ERROR_TYPE,
|
|
20
|
+
kit,
|
|
21
|
+
setSSREnv
|
|
12
22
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
2
|
+
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
3
|
+
function wrapNoSSR(createComponentFn) {
|
|
4
|
+
return function(options) {
|
|
5
|
+
return createComponentFn(_object_spread_props(_object_spread({}, options), {
|
|
6
|
+
noSSR: true
|
|
7
|
+
}));
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
wrapNoSSR
|
|
12
|
+
};
|
|
@@ -3,7 +3,8 @@ 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
|
-
|
|
6
|
+
import { flushDataFetch } from "../utils";
|
|
7
|
+
var mfSSRDevPlugin = function() {
|
|
7
8
|
return {
|
|
8
9
|
name: "@module-federation/modern-js",
|
|
9
10
|
setup: function(api) {
|
|
@@ -30,6 +31,7 @@ var mfSSRPlugin = function() {
|
|
|
30
31
|
];
|
|
31
32
|
case 2:
|
|
32
33
|
shouldUpdate = _state.sent();
|
|
34
|
+
console.log("shouldUpdate: ", shouldUpdate);
|
|
33
35
|
if (!shouldUpdate)
|
|
34
36
|
return [
|
|
35
37
|
3,
|
|
@@ -42,6 +44,7 @@ var mfSSRPlugin = function() {
|
|
|
42
44
|
];
|
|
43
45
|
case 3:
|
|
44
46
|
_state.sent();
|
|
47
|
+
flushDataFetch();
|
|
45
48
|
globalThis.shouldUpdate = true;
|
|
46
49
|
_state.label = 4;
|
|
47
50
|
case 4:
|
|
@@ -66,5 +69,5 @@ var mfSSRPlugin = function() {
|
|
|
66
69
|
};
|
|
67
70
|
};
|
|
68
71
|
export {
|
|
69
|
-
|
|
72
|
+
mfSSRDevPlugin
|
|
70
73
|
};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
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 _type_of } from "@swc/helpers/_/_type_of";
|
|
5
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
6
|
+
import { DATA_FETCH_QUERY, DOWNGRADE_KEY } from "../constant";
|
|
7
|
+
import { MF_DATA_FETCH_STATUS, MF_DATA_FETCH_TYPE } from "../constant";
|
|
8
|
+
import { getDataFetchMap } from "../utils";
|
|
9
|
+
function getDowngradeTag() {
|
|
10
|
+
return globalThis[DOWNGRADE_KEY];
|
|
11
|
+
}
|
|
12
|
+
function callAllDowngrade() {
|
|
13
|
+
var dataFetchMap = getDataFetchMap();
|
|
14
|
+
if (!dataFetchMap) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
Object.keys(dataFetchMap).forEach(function(key) {
|
|
18
|
+
callDowngrade(key);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function callDowngrade(id, params, remoteInfo) {
|
|
22
|
+
return _callDowngrade.apply(this, arguments);
|
|
23
|
+
}
|
|
24
|
+
function _callDowngrade() {
|
|
25
|
+
_callDowngrade = _async_to_generator(function(id, params, remoteInfo) {
|
|
26
|
+
var dataFetchMap, mfDataFetch, promise, res, rej, dataFetchType, currentUrl, fetchServerQuery, fetchUrl, data, e;
|
|
27
|
+
return _ts_generator(this, function(_state) {
|
|
28
|
+
switch (_state.label) {
|
|
29
|
+
case 0:
|
|
30
|
+
dataFetchMap = getDataFetchMap();
|
|
31
|
+
if (!dataFetchMap) {
|
|
32
|
+
return [
|
|
33
|
+
2
|
|
34
|
+
];
|
|
35
|
+
}
|
|
36
|
+
mfDataFetch = dataFetchMap[id];
|
|
37
|
+
if (!((mfDataFetch === null || mfDataFetch === void 0 ? void 0 : mfDataFetch[2]) === MF_DATA_FETCH_STATUS.AWAIT))
|
|
38
|
+
return [
|
|
39
|
+
3,
|
|
40
|
+
6
|
|
41
|
+
];
|
|
42
|
+
mfDataFetch[2] = MF_DATA_FETCH_STATUS.LOADING;
|
|
43
|
+
if (mfDataFetch[1]) {
|
|
44
|
+
promise = mfDataFetch[1][0];
|
|
45
|
+
res = mfDataFetch[1][1];
|
|
46
|
+
rej = mfDataFetch[1][2];
|
|
47
|
+
} else {
|
|
48
|
+
promise = new Promise(function(resolve, reject) {
|
|
49
|
+
res = resolve;
|
|
50
|
+
rej = reject;
|
|
51
|
+
});
|
|
52
|
+
mfDataFetch[1] = [
|
|
53
|
+
promise,
|
|
54
|
+
res,
|
|
55
|
+
rej
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
dataFetchType = mfDataFetch[0][1];
|
|
59
|
+
if (!(dataFetchType === MF_DATA_FETCH_TYPE.FETCH_CLIENT))
|
|
60
|
+
return [
|
|
61
|
+
3,
|
|
62
|
+
1
|
|
63
|
+
];
|
|
64
|
+
try {
|
|
65
|
+
mfDataFetch[0][0]().then(function(getDataFetchFn) {
|
|
66
|
+
return getDataFetchFn(_object_spread_props(_object_spread({}, params), {
|
|
67
|
+
isDowngrade: true
|
|
68
|
+
})).then(function(data2) {
|
|
69
|
+
mfDataFetch[2] = MF_DATA_FETCH_STATUS.LOADED;
|
|
70
|
+
res(data2);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
} catch (e2) {
|
|
74
|
+
mfDataFetch[2] = MF_DATA_FETCH_STATUS.ERROR;
|
|
75
|
+
rej(e2);
|
|
76
|
+
}
|
|
77
|
+
return [
|
|
78
|
+
3,
|
|
79
|
+
5
|
|
80
|
+
];
|
|
81
|
+
case 1:
|
|
82
|
+
if (!(dataFetchType === MF_DATA_FETCH_TYPE.FETCH_SERVER))
|
|
83
|
+
return [
|
|
84
|
+
3,
|
|
85
|
+
5
|
|
86
|
+
];
|
|
87
|
+
_state.label = 2;
|
|
88
|
+
case 2:
|
|
89
|
+
_state.trys.push([
|
|
90
|
+
2,
|
|
91
|
+
4,
|
|
92
|
+
,
|
|
93
|
+
5
|
|
94
|
+
]);
|
|
95
|
+
currentUrl = new URL(window.location.href);
|
|
96
|
+
currentUrl.searchParams.set(DATA_FETCH_QUERY, encodeURIComponent(id));
|
|
97
|
+
if (params) {
|
|
98
|
+
currentUrl.searchParams.set("params", encodeURIComponent(JSON.stringify(params)));
|
|
99
|
+
}
|
|
100
|
+
if (remoteInfo) {
|
|
101
|
+
currentUrl.searchParams.set("remoteInfo", encodeURIComponent(JSON.stringify(remoteInfo)));
|
|
102
|
+
}
|
|
103
|
+
fetchServerQuery = globalThis.FEDERATION_SERVER_QUERY;
|
|
104
|
+
if (fetchServerQuery && (typeof fetchServerQuery === "undefined" ? "undefined" : _type_of(fetchServerQuery)) === "object") {
|
|
105
|
+
Object.keys(fetchServerQuery).forEach(function(key) {
|
|
106
|
+
currentUrl.searchParams.set(key, JSON.stringify(fetchServerQuery[key]));
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
fetchUrl = currentUrl.toString();
|
|
110
|
+
return [
|
|
111
|
+
4,
|
|
112
|
+
fetch(fetchUrl).then(function(res2) {
|
|
113
|
+
return res2.json();
|
|
114
|
+
})
|
|
115
|
+
];
|
|
116
|
+
case 3:
|
|
117
|
+
data = _state.sent();
|
|
118
|
+
mfDataFetch[2] = MF_DATA_FETCH_STATUS.LOADED;
|
|
119
|
+
res(data);
|
|
120
|
+
return [
|
|
121
|
+
3,
|
|
122
|
+
5
|
|
123
|
+
];
|
|
124
|
+
case 4:
|
|
125
|
+
e = _state.sent();
|
|
126
|
+
mfDataFetch[2] = MF_DATA_FETCH_STATUS.ERROR;
|
|
127
|
+
rej(e);
|
|
128
|
+
return [
|
|
129
|
+
3,
|
|
130
|
+
5
|
|
131
|
+
];
|
|
132
|
+
case 5:
|
|
133
|
+
return [
|
|
134
|
+
2,
|
|
135
|
+
promise
|
|
136
|
+
];
|
|
137
|
+
case 6:
|
|
138
|
+
return [
|
|
139
|
+
2
|
|
140
|
+
];
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
return _callDowngrade.apply(this, arguments);
|
|
145
|
+
}
|
|
146
|
+
export {
|
|
147
|
+
callAllDowngrade,
|
|
148
|
+
callDowngrade,
|
|
149
|
+
getDowngradeTag
|
|
150
|
+
};
|