@rayburst/cli 0.1.16 → 0.1.18
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/bin/rayburst.js +2 -18
- package/package.json +4 -11
- package/server.js +3 -4
- package/src/main.tsx +105 -6
- package/vite.config.ts +3 -4
- package/dist/assets/_commonjsHelpers-B85MJLTf.js +0 -5
- package/dist/assets/hostInit-CxHGTmfB.js +0 -9
- package/dist/assets/index-9R1akZrm.js +0 -578
- package/dist/assets/index-BW-RulSg.js +0 -258
- package/dist/assets/index-VnAMn3JB.js +0 -16587
- package/dist/assets/preload-helper-Dea3Szod.js +0 -54
- package/dist/assets/rayburstCli__loadRemote__rayburstApp_mf_1_App__loadRemote__-CHUYMhiU.js +0 -35
- package/dist/assets/rayburstCli__loadShare__react__loadShare__-CE7VtFm0.js +0 -19
- package/dist/assets/rayburstCli__mf_v__runtimeInit__mf_v__-C_SVfzik.js +0 -4173
- package/dist/assets/remoteEntry-lfoFMEF5.js +0 -122
- package/dist/assets/virtualExposes-DwA08f_D.js +0 -5
- package/dist/index.html +0 -56
|
@@ -1,4173 +0,0 @@
|
|
|
1
|
-
var index_cjs$3 = {};
|
|
2
|
-
|
|
3
|
-
var index_cjs$2 = {};
|
|
4
|
-
|
|
5
|
-
var polyfills_cjs$1 = {};
|
|
6
|
-
|
|
7
|
-
function _extends$2() {
|
|
8
|
-
_extends$2 = Object.assign || function assign(target) {
|
|
9
|
-
for(var i = 1; i < arguments.length; i++){
|
|
10
|
-
var source = arguments[i];
|
|
11
|
-
for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
12
|
-
}
|
|
13
|
-
return target;
|
|
14
|
-
};
|
|
15
|
-
return _extends$2.apply(this, arguments);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function _object_without_properties_loose(source, excluded) {
|
|
19
|
-
if (source == null) return {};
|
|
20
|
-
var target = {};
|
|
21
|
-
var sourceKeys = Object.keys(source);
|
|
22
|
-
var key, i;
|
|
23
|
-
for(i = 0; i < sourceKeys.length; i++){
|
|
24
|
-
key = sourceKeys[i];
|
|
25
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
26
|
-
target[key] = source[key];
|
|
27
|
-
}
|
|
28
|
-
return target;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
polyfills_cjs$1._extends = _extends$2;
|
|
32
|
-
polyfills_cjs$1._object_without_properties_loose = _object_without_properties_loose;
|
|
33
|
-
|
|
34
|
-
var index_cjs$1 = {};
|
|
35
|
-
|
|
36
|
-
var polyfills_cjs = {};
|
|
37
|
-
|
|
38
|
-
function _extends$1() {
|
|
39
|
-
_extends$1 = Object.assign || function assign(target) {
|
|
40
|
-
for(var i = 1; i < arguments.length; i++){
|
|
41
|
-
var source = arguments[i];
|
|
42
|
-
for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
43
|
-
}
|
|
44
|
-
return target;
|
|
45
|
-
};
|
|
46
|
-
return _extends$1.apply(this, arguments);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
polyfills_cjs._ = _extends$1;
|
|
50
|
-
|
|
51
|
-
var define_process_env_default = {};
|
|
52
|
-
var polyfills$1 = polyfills_cjs;
|
|
53
|
-
const FederationModuleManifest = "federation-manifest.json";
|
|
54
|
-
const MANIFEST_EXT = ".json";
|
|
55
|
-
const BROWSER_LOG_KEY = "FEDERATION_DEBUG";
|
|
56
|
-
const NameTransformSymbol = {
|
|
57
|
-
AT: "@",
|
|
58
|
-
HYPHEN: "-",
|
|
59
|
-
SLASH: "/"
|
|
60
|
-
};
|
|
61
|
-
const NameTransformMap = {
|
|
62
|
-
[NameTransformSymbol.AT]: "scope_",
|
|
63
|
-
[NameTransformSymbol.HYPHEN]: "_",
|
|
64
|
-
[NameTransformSymbol.SLASH]: "__"
|
|
65
|
-
};
|
|
66
|
-
const EncodedNameTransformMap = {
|
|
67
|
-
[NameTransformMap[NameTransformSymbol.AT]]: NameTransformSymbol.AT,
|
|
68
|
-
[NameTransformMap[NameTransformSymbol.HYPHEN]]: NameTransformSymbol.HYPHEN,
|
|
69
|
-
[NameTransformMap[NameTransformSymbol.SLASH]]: NameTransformSymbol.SLASH
|
|
70
|
-
};
|
|
71
|
-
const SEPARATOR = ":";
|
|
72
|
-
const ManifestFileName = "mf-manifest.json";
|
|
73
|
-
const StatsFileName = "mf-stats.json";
|
|
74
|
-
const MFModuleType = {
|
|
75
|
-
NPM: "npm",
|
|
76
|
-
APP: "app"
|
|
77
|
-
};
|
|
78
|
-
const MODULE_DEVTOOL_IDENTIFIER = "__MF_DEVTOOLS_MODULE_INFO__";
|
|
79
|
-
const ENCODE_NAME_PREFIX = "ENCODE_NAME_PREFIX";
|
|
80
|
-
const TEMP_DIR = ".federation";
|
|
81
|
-
const MFPrefetchCommon = {
|
|
82
|
-
identifier: "MFDataPrefetch",
|
|
83
|
-
globalKey: "__PREFETCH__",
|
|
84
|
-
library: "mf-data-prefetch",
|
|
85
|
-
exportsKey: "__PREFETCH_EXPORTS__",
|
|
86
|
-
fileName: "bootstrap.js"
|
|
87
|
-
};
|
|
88
|
-
var ContainerPlugin = /* @__PURE__ */ Object.freeze({
|
|
89
|
-
__proto__: null
|
|
90
|
-
});
|
|
91
|
-
var ContainerReferencePlugin = /* @__PURE__ */ Object.freeze({
|
|
92
|
-
__proto__: null
|
|
93
|
-
});
|
|
94
|
-
var ModuleFederationPlugin = /* @__PURE__ */ Object.freeze({
|
|
95
|
-
__proto__: null
|
|
96
|
-
});
|
|
97
|
-
var SharePlugin = /* @__PURE__ */ Object.freeze({
|
|
98
|
-
__proto__: null
|
|
99
|
-
});
|
|
100
|
-
function isBrowserEnv() {
|
|
101
|
-
return typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
102
|
-
}
|
|
103
|
-
function isReactNativeEnv() {
|
|
104
|
-
var _navigator;
|
|
105
|
-
return typeof navigator !== "undefined" && ((_navigator = navigator) == null ? void 0 : _navigator.product) === "ReactNative";
|
|
106
|
-
}
|
|
107
|
-
function isBrowserDebug() {
|
|
108
|
-
try {
|
|
109
|
-
if (isBrowserEnv() && window.localStorage) {
|
|
110
|
-
return Boolean(localStorage.getItem(BROWSER_LOG_KEY));
|
|
111
|
-
}
|
|
112
|
-
} catch (error2) {
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
function isDebugMode() {
|
|
118
|
-
if (typeof process !== "undefined" && define_process_env_default && define_process_env_default["FEDERATION_DEBUG"]) {
|
|
119
|
-
return Boolean(define_process_env_default["FEDERATION_DEBUG"]);
|
|
120
|
-
}
|
|
121
|
-
if (typeof FEDERATION_DEBUG !== "undefined" && Boolean(FEDERATION_DEBUG)) {
|
|
122
|
-
return true;
|
|
123
|
-
}
|
|
124
|
-
return isBrowserDebug();
|
|
125
|
-
}
|
|
126
|
-
const getProcessEnv = function() {
|
|
127
|
-
return typeof process !== "undefined" && define_process_env_default ? define_process_env_default : {};
|
|
128
|
-
};
|
|
129
|
-
const LOG_CATEGORY$1 = "[ Federation Runtime ]";
|
|
130
|
-
const parseEntry = (str, devVerOrUrl, separator = SEPARATOR) => {
|
|
131
|
-
const strSplit = str.split(separator);
|
|
132
|
-
const devVersionOrUrl = getProcessEnv()["NODE_ENV"] === "development" && devVerOrUrl;
|
|
133
|
-
const defaultVersion = "*";
|
|
134
|
-
const isEntry = (s) => s.startsWith("http") || s.includes(MANIFEST_EXT);
|
|
135
|
-
if (strSplit.length >= 2) {
|
|
136
|
-
let [name, ...versionOrEntryArr] = strSplit;
|
|
137
|
-
if (str.startsWith(separator)) {
|
|
138
|
-
name = strSplit.slice(0, 2).join(separator);
|
|
139
|
-
versionOrEntryArr = [
|
|
140
|
-
devVersionOrUrl || strSplit.slice(2).join(separator)
|
|
141
|
-
];
|
|
142
|
-
}
|
|
143
|
-
let versionOrEntry = devVersionOrUrl || versionOrEntryArr.join(separator);
|
|
144
|
-
if (isEntry(versionOrEntry)) {
|
|
145
|
-
return {
|
|
146
|
-
name,
|
|
147
|
-
entry: versionOrEntry
|
|
148
|
-
};
|
|
149
|
-
} else {
|
|
150
|
-
return {
|
|
151
|
-
name,
|
|
152
|
-
version: versionOrEntry || defaultVersion
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
} else if (strSplit.length === 1) {
|
|
156
|
-
const [name] = strSplit;
|
|
157
|
-
if (devVersionOrUrl && isEntry(devVersionOrUrl)) {
|
|
158
|
-
return {
|
|
159
|
-
name,
|
|
160
|
-
entry: devVersionOrUrl
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
return {
|
|
164
|
-
name,
|
|
165
|
-
version: devVersionOrUrl || defaultVersion
|
|
166
|
-
};
|
|
167
|
-
} else {
|
|
168
|
-
throw `Invalid entry value: ${str}`;
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
const composeKeyWithSeparator = function(...args) {
|
|
172
|
-
if (!args.length) {
|
|
173
|
-
return "";
|
|
174
|
-
}
|
|
175
|
-
return args.reduce((sum, cur) => {
|
|
176
|
-
if (!cur) {
|
|
177
|
-
return sum;
|
|
178
|
-
}
|
|
179
|
-
if (!sum) {
|
|
180
|
-
return cur;
|
|
181
|
-
}
|
|
182
|
-
return `${sum}${SEPARATOR}${cur}`;
|
|
183
|
-
}, "");
|
|
184
|
-
};
|
|
185
|
-
const encodeName = function(name, prefix = "", withExt = false) {
|
|
186
|
-
try {
|
|
187
|
-
const ext = withExt ? ".js" : "";
|
|
188
|
-
return `${prefix}${name.replace(new RegExp(`${NameTransformSymbol.AT}`, "g"), NameTransformMap[NameTransformSymbol.AT]).replace(new RegExp(`${NameTransformSymbol.HYPHEN}`, "g"), NameTransformMap[NameTransformSymbol.HYPHEN]).replace(new RegExp(`${NameTransformSymbol.SLASH}`, "g"), NameTransformMap[NameTransformSymbol.SLASH])}${ext}`;
|
|
189
|
-
} catch (err) {
|
|
190
|
-
throw err;
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
const decodeName = function(name, prefix, withExt) {
|
|
194
|
-
try {
|
|
195
|
-
let decodedName = name;
|
|
196
|
-
if (prefix) {
|
|
197
|
-
if (!decodedName.startsWith(prefix)) {
|
|
198
|
-
return decodedName;
|
|
199
|
-
}
|
|
200
|
-
decodedName = decodedName.replace(new RegExp(prefix, "g"), "");
|
|
201
|
-
}
|
|
202
|
-
decodedName = decodedName.replace(new RegExp(`${NameTransformMap[NameTransformSymbol.AT]}`, "g"), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.AT]]).replace(new RegExp(`${NameTransformMap[NameTransformSymbol.SLASH]}`, "g"), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.SLASH]]).replace(new RegExp(`${NameTransformMap[NameTransformSymbol.HYPHEN]}`, "g"), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.HYPHEN]]);
|
|
203
|
-
if (withExt) {
|
|
204
|
-
decodedName = decodedName.replace(".js", "");
|
|
205
|
-
}
|
|
206
|
-
return decodedName;
|
|
207
|
-
} catch (err) {
|
|
208
|
-
throw err;
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
const generateExposeFilename = (exposeName, withExt) => {
|
|
212
|
-
if (!exposeName) {
|
|
213
|
-
return "";
|
|
214
|
-
}
|
|
215
|
-
let expose = exposeName;
|
|
216
|
-
if (expose === ".") {
|
|
217
|
-
expose = "default_export";
|
|
218
|
-
}
|
|
219
|
-
if (expose.startsWith("./")) {
|
|
220
|
-
expose = expose.replace("./", "");
|
|
221
|
-
}
|
|
222
|
-
return encodeName(expose, "__federation_expose_", withExt);
|
|
223
|
-
};
|
|
224
|
-
const generateShareFilename = (pkgName, withExt) => {
|
|
225
|
-
if (!pkgName) {
|
|
226
|
-
return "";
|
|
227
|
-
}
|
|
228
|
-
return encodeName(pkgName, "__federation_shared_", withExt);
|
|
229
|
-
};
|
|
230
|
-
const getResourceUrl = (module, sourceUrl) => {
|
|
231
|
-
if ("getPublicPath" in module) {
|
|
232
|
-
let publicPath;
|
|
233
|
-
if (!module.getPublicPath.startsWith("function")) {
|
|
234
|
-
publicPath = new Function(module.getPublicPath)();
|
|
235
|
-
} else {
|
|
236
|
-
publicPath = new Function("return " + module.getPublicPath)()();
|
|
237
|
-
}
|
|
238
|
-
return `${publicPath}${sourceUrl}`;
|
|
239
|
-
} else if ("publicPath" in module) {
|
|
240
|
-
if (!isBrowserEnv() && !isReactNativeEnv() && "ssrPublicPath" in module) {
|
|
241
|
-
return `${module.ssrPublicPath}${sourceUrl}`;
|
|
242
|
-
}
|
|
243
|
-
return `${module.publicPath}${sourceUrl}`;
|
|
244
|
-
} else {
|
|
245
|
-
console.warn("Cannot get resource URL. If in debug mode, please ignore.", module, sourceUrl);
|
|
246
|
-
return "";
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
const assert$1 = (condition, msg) => {
|
|
250
|
-
if (!condition) {
|
|
251
|
-
error$1(msg);
|
|
252
|
-
}
|
|
253
|
-
};
|
|
254
|
-
const error$1 = (msg) => {
|
|
255
|
-
throw new Error(`${LOG_CATEGORY$1}: ${msg}`);
|
|
256
|
-
};
|
|
257
|
-
const warn$1 = (msg) => {
|
|
258
|
-
console.warn(`${LOG_CATEGORY$1}: ${msg}`);
|
|
259
|
-
};
|
|
260
|
-
function safeToString(info) {
|
|
261
|
-
try {
|
|
262
|
-
return JSON.stringify(info, null, 2);
|
|
263
|
-
} catch (e) {
|
|
264
|
-
return "";
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
const VERSION_PATTERN_REGEXP = /^([\d^=v<>~]|[*xX]$)/;
|
|
268
|
-
function isRequiredVersion(str) {
|
|
269
|
-
return VERSION_PATTERN_REGEXP.test(str);
|
|
270
|
-
}
|
|
271
|
-
const simpleJoinRemoteEntry = (rPath, rName) => {
|
|
272
|
-
if (!rPath) {
|
|
273
|
-
return rName;
|
|
274
|
-
}
|
|
275
|
-
const transformPath = (str) => {
|
|
276
|
-
if (str === ".") {
|
|
277
|
-
return "";
|
|
278
|
-
}
|
|
279
|
-
if (str.startsWith("./")) {
|
|
280
|
-
return str.replace("./", "");
|
|
281
|
-
}
|
|
282
|
-
if (str.startsWith("/")) {
|
|
283
|
-
const strWithoutSlash = str.slice(1);
|
|
284
|
-
if (strWithoutSlash.endsWith("/")) {
|
|
285
|
-
return strWithoutSlash.slice(0, -1);
|
|
286
|
-
}
|
|
287
|
-
return strWithoutSlash;
|
|
288
|
-
}
|
|
289
|
-
return str;
|
|
290
|
-
};
|
|
291
|
-
const transformedPath = transformPath(rPath);
|
|
292
|
-
if (!transformedPath) {
|
|
293
|
-
return rName;
|
|
294
|
-
}
|
|
295
|
-
if (transformedPath.endsWith("/")) {
|
|
296
|
-
return `${transformedPath}${rName}`;
|
|
297
|
-
}
|
|
298
|
-
return `${transformedPath}/${rName}`;
|
|
299
|
-
};
|
|
300
|
-
function inferAutoPublicPath(url2) {
|
|
301
|
-
return url2.replace(/#.*$/, "").replace(/\?.*$/, "").replace(/\/[^\/]+$/, "/");
|
|
302
|
-
}
|
|
303
|
-
function generateSnapshotFromManifest(manifest, options = {}) {
|
|
304
|
-
var _manifest_metaData, _manifest_metaData1;
|
|
305
|
-
const { remotes = {}, overrides = {}, version } = options;
|
|
306
|
-
let remoteSnapshot;
|
|
307
|
-
const getPublicPath = () => {
|
|
308
|
-
if ("publicPath" in manifest.metaData) {
|
|
309
|
-
if (manifest.metaData.publicPath === "auto" && version) {
|
|
310
|
-
return inferAutoPublicPath(version);
|
|
311
|
-
}
|
|
312
|
-
return manifest.metaData.publicPath;
|
|
313
|
-
} else {
|
|
314
|
-
return manifest.metaData.getPublicPath;
|
|
315
|
-
}
|
|
316
|
-
};
|
|
317
|
-
const overridesKeys = Object.keys(overrides);
|
|
318
|
-
let remotesInfo = {};
|
|
319
|
-
if (!Object.keys(remotes).length) {
|
|
320
|
-
var _manifest_remotes;
|
|
321
|
-
remotesInfo = ((_manifest_remotes = manifest.remotes) == null ? void 0 : _manifest_remotes.reduce((res2, next) => {
|
|
322
|
-
let matchedVersion;
|
|
323
|
-
const name = next.federationContainerName;
|
|
324
|
-
if (overridesKeys.includes(name)) {
|
|
325
|
-
matchedVersion = overrides[name];
|
|
326
|
-
} else {
|
|
327
|
-
if ("version" in next) {
|
|
328
|
-
matchedVersion = next.version;
|
|
329
|
-
} else {
|
|
330
|
-
matchedVersion = next.entry;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
res2[name] = {
|
|
334
|
-
matchedVersion
|
|
335
|
-
};
|
|
336
|
-
return res2;
|
|
337
|
-
}, {})) || {};
|
|
338
|
-
}
|
|
339
|
-
Object.keys(remotes).forEach((key) => remotesInfo[key] = {
|
|
340
|
-
// overrides will override dependencies
|
|
341
|
-
matchedVersion: overridesKeys.includes(key) ? overrides[key] : remotes[key]
|
|
342
|
-
});
|
|
343
|
-
const { remoteEntry: { path: remoteEntryPath, name: remoteEntryName, type: remoteEntryType }, types: remoteTypes, buildInfo: { buildVersion }, globalName, ssrRemoteEntry } = manifest.metaData;
|
|
344
|
-
const { exposes } = manifest;
|
|
345
|
-
let basicRemoteSnapshot = {
|
|
346
|
-
version: version ? version : "",
|
|
347
|
-
buildVersion,
|
|
348
|
-
globalName,
|
|
349
|
-
remoteEntry: simpleJoinRemoteEntry(remoteEntryPath, remoteEntryName),
|
|
350
|
-
remoteEntryType,
|
|
351
|
-
remoteTypes: simpleJoinRemoteEntry(remoteTypes.path, remoteTypes.name),
|
|
352
|
-
remoteTypesZip: remoteTypes.zip || "",
|
|
353
|
-
remoteTypesAPI: remoteTypes.api || "",
|
|
354
|
-
remotesInfo,
|
|
355
|
-
shared: manifest == null ? void 0 : manifest.shared.map((item) => ({
|
|
356
|
-
assets: item.assets,
|
|
357
|
-
sharedName: item.name,
|
|
358
|
-
version: item.version
|
|
359
|
-
})),
|
|
360
|
-
modules: exposes == null ? void 0 : exposes.map((expose) => ({
|
|
361
|
-
moduleName: expose.name,
|
|
362
|
-
modulePath: expose.path,
|
|
363
|
-
assets: expose.assets
|
|
364
|
-
}))
|
|
365
|
-
};
|
|
366
|
-
if ((_manifest_metaData = manifest.metaData) == null ? void 0 : _manifest_metaData.prefetchInterface) {
|
|
367
|
-
const prefetchInterface = manifest.metaData.prefetchInterface;
|
|
368
|
-
basicRemoteSnapshot = polyfills$1._({}, basicRemoteSnapshot, {
|
|
369
|
-
prefetchInterface
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
|
-
if ((_manifest_metaData1 = manifest.metaData) == null ? void 0 : _manifest_metaData1.prefetchEntry) {
|
|
373
|
-
const { path: path2, name, type } = manifest.metaData.prefetchEntry;
|
|
374
|
-
basicRemoteSnapshot = polyfills$1._({}, basicRemoteSnapshot, {
|
|
375
|
-
prefetchEntry: simpleJoinRemoteEntry(path2, name),
|
|
376
|
-
prefetchEntryType: type
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
if ("publicPath" in manifest.metaData) {
|
|
380
|
-
remoteSnapshot = polyfills$1._({}, basicRemoteSnapshot, {
|
|
381
|
-
publicPath: getPublicPath(),
|
|
382
|
-
ssrPublicPath: manifest.metaData.ssrPublicPath
|
|
383
|
-
});
|
|
384
|
-
} else {
|
|
385
|
-
remoteSnapshot = polyfills$1._({}, basicRemoteSnapshot, {
|
|
386
|
-
getPublicPath: getPublicPath()
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
if (ssrRemoteEntry) {
|
|
390
|
-
const fullSSRRemoteEntry = simpleJoinRemoteEntry(ssrRemoteEntry.path, ssrRemoteEntry.name);
|
|
391
|
-
remoteSnapshot.ssrRemoteEntry = fullSSRRemoteEntry;
|
|
392
|
-
remoteSnapshot.ssrRemoteEntryType = ssrRemoteEntry.type || "commonjs-module";
|
|
393
|
-
}
|
|
394
|
-
return remoteSnapshot;
|
|
395
|
-
}
|
|
396
|
-
function isManifestProvider(moduleInfo) {
|
|
397
|
-
if ("remoteEntry" in moduleInfo && moduleInfo.remoteEntry.includes(MANIFEST_EXT)) {
|
|
398
|
-
return true;
|
|
399
|
-
} else {
|
|
400
|
-
return false;
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
const PREFIX = "[ Module Federation ]";
|
|
404
|
-
let Logger = class Logger2 {
|
|
405
|
-
setPrefix(prefix) {
|
|
406
|
-
this.prefix = prefix;
|
|
407
|
-
}
|
|
408
|
-
log(...args) {
|
|
409
|
-
console.log(this.prefix, ...args);
|
|
410
|
-
}
|
|
411
|
-
warn(...args) {
|
|
412
|
-
console.log(this.prefix, ...args);
|
|
413
|
-
}
|
|
414
|
-
error(...args) {
|
|
415
|
-
console.log(this.prefix, ...args);
|
|
416
|
-
}
|
|
417
|
-
success(...args) {
|
|
418
|
-
console.log(this.prefix, ...args);
|
|
419
|
-
}
|
|
420
|
-
info(...args) {
|
|
421
|
-
console.log(this.prefix, ...args);
|
|
422
|
-
}
|
|
423
|
-
ready(...args) {
|
|
424
|
-
console.log(this.prefix, ...args);
|
|
425
|
-
}
|
|
426
|
-
debug(...args) {
|
|
427
|
-
if (isDebugMode()) {
|
|
428
|
-
console.log(this.prefix, ...args);
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
constructor(prefix) {
|
|
432
|
-
this.prefix = prefix;
|
|
433
|
-
}
|
|
434
|
-
};
|
|
435
|
-
function createLogger(prefix) {
|
|
436
|
-
return new Logger(prefix);
|
|
437
|
-
}
|
|
438
|
-
const logger$1 = createLogger(PREFIX);
|
|
439
|
-
async function safeWrapper$1(callback, disableWarn) {
|
|
440
|
-
try {
|
|
441
|
-
const res2 = await callback();
|
|
442
|
-
return res2;
|
|
443
|
-
} catch (e) {
|
|
444
|
-
!disableWarn && warn$1(e);
|
|
445
|
-
return;
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
function isStaticResourcesEqual$1(url1, url2) {
|
|
449
|
-
const REG_EXP = /^(https?:)?\/\//i;
|
|
450
|
-
const relativeUrl1 = url1.replace(REG_EXP, "").replace(/\/$/, "");
|
|
451
|
-
const relativeUrl2 = url2.replace(REG_EXP, "").replace(/\/$/, "");
|
|
452
|
-
return relativeUrl1 === relativeUrl2;
|
|
453
|
-
}
|
|
454
|
-
function createScript(info) {
|
|
455
|
-
let script2 = null;
|
|
456
|
-
let needAttach = true;
|
|
457
|
-
let timeout = 2e4;
|
|
458
|
-
let timeoutId;
|
|
459
|
-
const scripts = document.getElementsByTagName("script");
|
|
460
|
-
for (let i = 0; i < scripts.length; i++) {
|
|
461
|
-
const s = scripts[i];
|
|
462
|
-
const scriptSrc = s.getAttribute("src");
|
|
463
|
-
if (scriptSrc && isStaticResourcesEqual$1(scriptSrc, info.url)) {
|
|
464
|
-
script2 = s;
|
|
465
|
-
needAttach = false;
|
|
466
|
-
break;
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
if (!script2) {
|
|
470
|
-
const attrs2 = info.attrs;
|
|
471
|
-
script2 = document.createElement("script");
|
|
472
|
-
script2.type = (attrs2 == null ? void 0 : attrs2["type"]) === "module" ? "module" : "text/javascript";
|
|
473
|
-
let createScriptRes = void 0;
|
|
474
|
-
if (info.createScriptHook) {
|
|
475
|
-
createScriptRes = info.createScriptHook(info.url, info.attrs);
|
|
476
|
-
if (createScriptRes instanceof HTMLScriptElement) {
|
|
477
|
-
script2 = createScriptRes;
|
|
478
|
-
} else if (typeof createScriptRes === "object") {
|
|
479
|
-
if ("script" in createScriptRes && createScriptRes.script) {
|
|
480
|
-
script2 = createScriptRes.script;
|
|
481
|
-
}
|
|
482
|
-
if ("timeout" in createScriptRes && createScriptRes.timeout) {
|
|
483
|
-
timeout = createScriptRes.timeout;
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
if (!script2.src) {
|
|
488
|
-
script2.src = info.url;
|
|
489
|
-
}
|
|
490
|
-
if (attrs2 && !createScriptRes) {
|
|
491
|
-
Object.keys(attrs2).forEach((name) => {
|
|
492
|
-
if (script2) {
|
|
493
|
-
if (name === "async" || name === "defer") {
|
|
494
|
-
script2[name] = attrs2[name];
|
|
495
|
-
} else if (!script2.getAttribute(name)) {
|
|
496
|
-
script2.setAttribute(name, attrs2[name]);
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
});
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
const onScriptComplete = async (prev, event) => {
|
|
503
|
-
clearTimeout(timeoutId);
|
|
504
|
-
const onScriptCompleteCallback = () => {
|
|
505
|
-
if ((event == null ? void 0 : event.type) === "error") {
|
|
506
|
-
(info == null ? void 0 : info.onErrorCallback) && (info == null ? void 0 : info.onErrorCallback(event));
|
|
507
|
-
} else {
|
|
508
|
-
(info == null ? void 0 : info.cb) && (info == null ? void 0 : info.cb());
|
|
509
|
-
}
|
|
510
|
-
};
|
|
511
|
-
if (script2) {
|
|
512
|
-
script2.onerror = null;
|
|
513
|
-
script2.onload = null;
|
|
514
|
-
safeWrapper$1(() => {
|
|
515
|
-
const { needDeleteScript = true } = info;
|
|
516
|
-
if (needDeleteScript) {
|
|
517
|
-
(script2 == null ? void 0 : script2.parentNode) && script2.parentNode.removeChild(script2);
|
|
518
|
-
}
|
|
519
|
-
});
|
|
520
|
-
if (prev && typeof prev === "function") {
|
|
521
|
-
const result = prev(event);
|
|
522
|
-
if (result instanceof Promise) {
|
|
523
|
-
const res2 = await result;
|
|
524
|
-
onScriptCompleteCallback();
|
|
525
|
-
return res2;
|
|
526
|
-
}
|
|
527
|
-
onScriptCompleteCallback();
|
|
528
|
-
return result;
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
onScriptCompleteCallback();
|
|
532
|
-
};
|
|
533
|
-
script2.onerror = onScriptComplete.bind(null, script2.onerror);
|
|
534
|
-
script2.onload = onScriptComplete.bind(null, script2.onload);
|
|
535
|
-
timeoutId = setTimeout(() => {
|
|
536
|
-
onScriptComplete(null, new Error(`Remote script "${info.url}" time-outed.`));
|
|
537
|
-
}, timeout);
|
|
538
|
-
return {
|
|
539
|
-
script: script2,
|
|
540
|
-
needAttach
|
|
541
|
-
};
|
|
542
|
-
}
|
|
543
|
-
function createLink(info) {
|
|
544
|
-
let link = null;
|
|
545
|
-
let needAttach = true;
|
|
546
|
-
const links = document.getElementsByTagName("link");
|
|
547
|
-
for (let i = 0; i < links.length; i++) {
|
|
548
|
-
const l = links[i];
|
|
549
|
-
const linkHref = l.getAttribute("href");
|
|
550
|
-
const linkRel = l.getAttribute("rel");
|
|
551
|
-
if (linkHref && isStaticResourcesEqual$1(linkHref, info.url) && linkRel === info.attrs["rel"]) {
|
|
552
|
-
link = l;
|
|
553
|
-
needAttach = false;
|
|
554
|
-
break;
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
if (!link) {
|
|
558
|
-
link = document.createElement("link");
|
|
559
|
-
link.setAttribute("href", info.url);
|
|
560
|
-
let createLinkRes = void 0;
|
|
561
|
-
const attrs2 = info.attrs;
|
|
562
|
-
if (info.createLinkHook) {
|
|
563
|
-
createLinkRes = info.createLinkHook(info.url, attrs2);
|
|
564
|
-
if (createLinkRes instanceof HTMLLinkElement) {
|
|
565
|
-
link = createLinkRes;
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
if (attrs2 && !createLinkRes) {
|
|
569
|
-
Object.keys(attrs2).forEach((name) => {
|
|
570
|
-
if (link && !link.getAttribute(name)) {
|
|
571
|
-
link.setAttribute(name, attrs2[name]);
|
|
572
|
-
}
|
|
573
|
-
});
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
const onLinkComplete = (prev, event) => {
|
|
577
|
-
const onLinkCompleteCallback = () => {
|
|
578
|
-
if ((event == null ? void 0 : event.type) === "error") {
|
|
579
|
-
(info == null ? void 0 : info.onErrorCallback) && (info == null ? void 0 : info.onErrorCallback(event));
|
|
580
|
-
} else {
|
|
581
|
-
(info == null ? void 0 : info.cb) && (info == null ? void 0 : info.cb());
|
|
582
|
-
}
|
|
583
|
-
};
|
|
584
|
-
if (link) {
|
|
585
|
-
link.onerror = null;
|
|
586
|
-
link.onload = null;
|
|
587
|
-
safeWrapper$1(() => {
|
|
588
|
-
const { needDeleteLink = true } = info;
|
|
589
|
-
if (needDeleteLink) {
|
|
590
|
-
(link == null ? void 0 : link.parentNode) && link.parentNode.removeChild(link);
|
|
591
|
-
}
|
|
592
|
-
});
|
|
593
|
-
if (prev) {
|
|
594
|
-
const res2 = prev(event);
|
|
595
|
-
onLinkCompleteCallback();
|
|
596
|
-
return res2;
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
onLinkCompleteCallback();
|
|
600
|
-
};
|
|
601
|
-
link.onerror = onLinkComplete.bind(null, link.onerror);
|
|
602
|
-
link.onload = onLinkComplete.bind(null, link.onload);
|
|
603
|
-
return {
|
|
604
|
-
link,
|
|
605
|
-
needAttach
|
|
606
|
-
};
|
|
607
|
-
}
|
|
608
|
-
function loadScript(url2, info) {
|
|
609
|
-
const { attrs: attrs2 = {}, createScriptHook } = info;
|
|
610
|
-
return new Promise((resolve, reject) => {
|
|
611
|
-
const { script: script2, needAttach } = createScript({
|
|
612
|
-
url: url2,
|
|
613
|
-
cb: resolve,
|
|
614
|
-
onErrorCallback: reject,
|
|
615
|
-
attrs: polyfills$1._({
|
|
616
|
-
fetchpriority: "high"
|
|
617
|
-
}, attrs2),
|
|
618
|
-
createScriptHook,
|
|
619
|
-
needDeleteScript: true
|
|
620
|
-
});
|
|
621
|
-
needAttach && document.head.appendChild(script2);
|
|
622
|
-
});
|
|
623
|
-
}
|
|
624
|
-
const sdkImportCache = /* @__PURE__ */ new Map();
|
|
625
|
-
function importNodeModule(name) {
|
|
626
|
-
if (!name) {
|
|
627
|
-
throw new Error("import specifier is required");
|
|
628
|
-
}
|
|
629
|
-
if (sdkImportCache.has(name)) {
|
|
630
|
-
return sdkImportCache.get(name);
|
|
631
|
-
}
|
|
632
|
-
const importModule = new Function("name", `return import(name)`);
|
|
633
|
-
const promise = importModule(name).then((res2) => res2).catch((error2) => {
|
|
634
|
-
console.error(`Error importing module ${name}:`, error2);
|
|
635
|
-
sdkImportCache.delete(name);
|
|
636
|
-
throw error2;
|
|
637
|
-
});
|
|
638
|
-
sdkImportCache.set(name, promise);
|
|
639
|
-
return promise;
|
|
640
|
-
}
|
|
641
|
-
const loadNodeFetch = async () => {
|
|
642
|
-
const fetchModule = await importNodeModule("node-fetch");
|
|
643
|
-
return fetchModule.default || fetchModule;
|
|
644
|
-
};
|
|
645
|
-
const lazyLoaderHookFetch = async (input, init, loaderHook2) => {
|
|
646
|
-
const hook = (url2, init2) => {
|
|
647
|
-
return loaderHook2.lifecycle.fetch.emit(url2, init2);
|
|
648
|
-
};
|
|
649
|
-
const res2 = await hook(input, init || {});
|
|
650
|
-
if (!res2 || !(res2 instanceof Response)) {
|
|
651
|
-
const fetchFunction = typeof fetch === "undefined" ? await loadNodeFetch() : fetch;
|
|
652
|
-
return fetchFunction(input, init || {});
|
|
653
|
-
}
|
|
654
|
-
return res2;
|
|
655
|
-
};
|
|
656
|
-
const createScriptNode = typeof ENV_TARGET === "undefined" || ENV_TARGET !== "web" ? (url, cb, attrs, loaderHook) => {
|
|
657
|
-
if (loaderHook == null ? void 0 : loaderHook.createScriptHook) {
|
|
658
|
-
const hookResult = loaderHook.createScriptHook(url);
|
|
659
|
-
if (hookResult && typeof hookResult === "object" && "url" in hookResult) {
|
|
660
|
-
url = hookResult.url;
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
let urlObj;
|
|
664
|
-
try {
|
|
665
|
-
urlObj = new URL(url);
|
|
666
|
-
} catch (e) {
|
|
667
|
-
console.error("Error constructing URL:", e);
|
|
668
|
-
cb(new Error(`Invalid URL: ${e}`));
|
|
669
|
-
return;
|
|
670
|
-
}
|
|
671
|
-
const getFetch = async () => {
|
|
672
|
-
if (loaderHook == null ? void 0 : loaderHook.fetch) {
|
|
673
|
-
return (input, init) => lazyLoaderHookFetch(input, init, loaderHook);
|
|
674
|
-
}
|
|
675
|
-
return typeof fetch === "undefined" ? loadNodeFetch() : fetch;
|
|
676
|
-
};
|
|
677
|
-
const handleScriptFetch = async (f, urlObj) => {
|
|
678
|
-
try {
|
|
679
|
-
var _vm_constants;
|
|
680
|
-
const res = await f(urlObj.href);
|
|
681
|
-
const data = await res.text();
|
|
682
|
-
const [path, vm] = await Promise.all([
|
|
683
|
-
importNodeModule("path"),
|
|
684
|
-
importNodeModule("vm")
|
|
685
|
-
]);
|
|
686
|
-
const scriptContext = {
|
|
687
|
-
exports: {},
|
|
688
|
-
module: {
|
|
689
|
-
exports: {}
|
|
690
|
-
}
|
|
691
|
-
};
|
|
692
|
-
const urlDirname = urlObj.pathname.split("/").slice(0, -1).join("/");
|
|
693
|
-
const filename = path.basename(urlObj.pathname);
|
|
694
|
-
var _vm_constants_USE_MAIN_CONTEXT_DEFAULT_LOADER;
|
|
695
|
-
const script = new vm.Script(`(function(exports, module, require, __dirname, __filename) {${data}
|
|
696
|
-
})`, {
|
|
697
|
-
filename,
|
|
698
|
-
importModuleDynamically: (_vm_constants_USE_MAIN_CONTEXT_DEFAULT_LOADER = (_vm_constants = vm.constants) == null ? void 0 : _vm_constants.USE_MAIN_CONTEXT_DEFAULT_LOADER) != null ? _vm_constants_USE_MAIN_CONTEXT_DEFAULT_LOADER : importNodeModule
|
|
699
|
-
});
|
|
700
|
-
script.runInThisContext()(scriptContext.exports, scriptContext.module, eval("require"), urlDirname, filename);
|
|
701
|
-
const exportedInterface = scriptContext.module.exports || scriptContext.exports;
|
|
702
|
-
if (attrs && exportedInterface && attrs["globalName"]) {
|
|
703
|
-
const container = exportedInterface[attrs["globalName"]] || exportedInterface;
|
|
704
|
-
cb(void 0, container);
|
|
705
|
-
return;
|
|
706
|
-
}
|
|
707
|
-
cb(void 0, exportedInterface);
|
|
708
|
-
} catch (e) {
|
|
709
|
-
cb(e instanceof Error ? e : new Error(`Script execution error: ${e}`));
|
|
710
|
-
}
|
|
711
|
-
};
|
|
712
|
-
getFetch().then(async (f2) => {
|
|
713
|
-
if ((attrs == null ? void 0 : attrs["type"]) === "esm" || (attrs == null ? void 0 : attrs["type"]) === "module") {
|
|
714
|
-
return loadModule(urlObj.href, {
|
|
715
|
-
fetch: f2,
|
|
716
|
-
vm: await importNodeModule("vm")
|
|
717
|
-
}).then(async (module) => {
|
|
718
|
-
await module.evaluate();
|
|
719
|
-
cb(void 0, module.namespace);
|
|
720
|
-
}).catch((e) => {
|
|
721
|
-
cb(e instanceof Error ? e : new Error(`Script execution error: ${e}`));
|
|
722
|
-
});
|
|
723
|
-
}
|
|
724
|
-
handleScriptFetch(f2, urlObj);
|
|
725
|
-
}).catch((err) => {
|
|
726
|
-
cb(err);
|
|
727
|
-
});
|
|
728
|
-
} : (url2, cb2, attrs2, loaderHook2) => {
|
|
729
|
-
cb2(new Error("createScriptNode is disabled in non-Node.js environment"));
|
|
730
|
-
};
|
|
731
|
-
const loadScriptNode = typeof ENV_TARGET === "undefined" || ENV_TARGET !== "web" ? (url2, info) => {
|
|
732
|
-
return new Promise((resolve, reject) => {
|
|
733
|
-
createScriptNode(url2, (error2, scriptContext2) => {
|
|
734
|
-
if (error2) {
|
|
735
|
-
reject(error2);
|
|
736
|
-
} else {
|
|
737
|
-
var _info_attrs, _info_attrs1;
|
|
738
|
-
const remoteEntryKey = (info == null ? void 0 : (_info_attrs = info.attrs) == null ? void 0 : _info_attrs["globalName"]) || `__FEDERATION_${info == null ? void 0 : (_info_attrs1 = info.attrs) == null ? void 0 : _info_attrs1["name"]}:custom__`;
|
|
739
|
-
const entryExports = globalThis[remoteEntryKey] = scriptContext2;
|
|
740
|
-
resolve(entryExports);
|
|
741
|
-
}
|
|
742
|
-
}, info.attrs, info.loaderHook);
|
|
743
|
-
});
|
|
744
|
-
} : (url2, info) => {
|
|
745
|
-
throw new Error("loadScriptNode is disabled in non-Node.js environment");
|
|
746
|
-
};
|
|
747
|
-
const esmModuleCache = /* @__PURE__ */ new Map();
|
|
748
|
-
async function loadModule(url2, options) {
|
|
749
|
-
if (esmModuleCache.has(url2)) {
|
|
750
|
-
return esmModuleCache.get(url2);
|
|
751
|
-
}
|
|
752
|
-
const { fetch: fetch1, vm: vm2 } = options;
|
|
753
|
-
const response = await fetch1(url2);
|
|
754
|
-
const code = await response.text();
|
|
755
|
-
const module = new vm2.SourceTextModule(code, {
|
|
756
|
-
// @ts-ignore
|
|
757
|
-
importModuleDynamically: async (specifier, script2) => {
|
|
758
|
-
const resolvedUrl = new URL(specifier, url2).href;
|
|
759
|
-
return loadModule(resolvedUrl, options);
|
|
760
|
-
}
|
|
761
|
-
});
|
|
762
|
-
esmModuleCache.set(url2, module);
|
|
763
|
-
await module.link(async (specifier) => {
|
|
764
|
-
const resolvedUrl = new URL(specifier, url2).href;
|
|
765
|
-
const module2 = await loadModule(resolvedUrl, options);
|
|
766
|
-
return module2;
|
|
767
|
-
});
|
|
768
|
-
return module;
|
|
769
|
-
}
|
|
770
|
-
function normalizeOptions(enableDefault, defaultOptions, key) {
|
|
771
|
-
return function(options) {
|
|
772
|
-
if (options === false) {
|
|
773
|
-
return false;
|
|
774
|
-
}
|
|
775
|
-
if (typeof options === "undefined") {
|
|
776
|
-
if (enableDefault) {
|
|
777
|
-
return defaultOptions;
|
|
778
|
-
} else {
|
|
779
|
-
return false;
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
if (options === true) {
|
|
783
|
-
return defaultOptions;
|
|
784
|
-
}
|
|
785
|
-
if (options && typeof options === "object") {
|
|
786
|
-
return polyfills$1._({}, defaultOptions, options);
|
|
787
|
-
}
|
|
788
|
-
throw new Error(`Unexpected type for \`${key}\`, expect boolean/undefined/object, got: ${typeof options}`);
|
|
789
|
-
};
|
|
790
|
-
}
|
|
791
|
-
const createModuleFederationConfig = (options) => {
|
|
792
|
-
return options;
|
|
793
|
-
};
|
|
794
|
-
index_cjs$1.BROWSER_LOG_KEY = BROWSER_LOG_KEY;
|
|
795
|
-
index_cjs$1.ENCODE_NAME_PREFIX = ENCODE_NAME_PREFIX;
|
|
796
|
-
index_cjs$1.EncodedNameTransformMap = EncodedNameTransformMap;
|
|
797
|
-
index_cjs$1.FederationModuleManifest = FederationModuleManifest;
|
|
798
|
-
index_cjs$1.MANIFEST_EXT = MANIFEST_EXT;
|
|
799
|
-
index_cjs$1.MFModuleType = MFModuleType;
|
|
800
|
-
index_cjs$1.MFPrefetchCommon = MFPrefetchCommon;
|
|
801
|
-
index_cjs$1.MODULE_DEVTOOL_IDENTIFIER = MODULE_DEVTOOL_IDENTIFIER;
|
|
802
|
-
index_cjs$1.ManifestFileName = ManifestFileName;
|
|
803
|
-
index_cjs$1.NameTransformMap = NameTransformMap;
|
|
804
|
-
index_cjs$1.NameTransformSymbol = NameTransformSymbol;
|
|
805
|
-
index_cjs$1.SEPARATOR = SEPARATOR;
|
|
806
|
-
index_cjs$1.StatsFileName = StatsFileName;
|
|
807
|
-
index_cjs$1.TEMP_DIR = TEMP_DIR;
|
|
808
|
-
index_cjs$1.assert = assert$1;
|
|
809
|
-
index_cjs$1.composeKeyWithSeparator = composeKeyWithSeparator;
|
|
810
|
-
index_cjs$1.containerPlugin = ContainerPlugin;
|
|
811
|
-
index_cjs$1.containerReferencePlugin = ContainerReferencePlugin;
|
|
812
|
-
index_cjs$1.createLink = createLink;
|
|
813
|
-
index_cjs$1.createLogger = createLogger;
|
|
814
|
-
index_cjs$1.createModuleFederationConfig = createModuleFederationConfig;
|
|
815
|
-
index_cjs$1.createScript = createScript;
|
|
816
|
-
index_cjs$1.createScriptNode = createScriptNode;
|
|
817
|
-
index_cjs$1.decodeName = decodeName;
|
|
818
|
-
index_cjs$1.encodeName = encodeName;
|
|
819
|
-
index_cjs$1.error = error$1;
|
|
820
|
-
index_cjs$1.generateExposeFilename = generateExposeFilename;
|
|
821
|
-
index_cjs$1.generateShareFilename = generateShareFilename;
|
|
822
|
-
index_cjs$1.generateSnapshotFromManifest = generateSnapshotFromManifest;
|
|
823
|
-
index_cjs$1.getProcessEnv = getProcessEnv;
|
|
824
|
-
index_cjs$1.getResourceUrl = getResourceUrl;
|
|
825
|
-
index_cjs$1.inferAutoPublicPath = inferAutoPublicPath;
|
|
826
|
-
index_cjs$1.isBrowserEnv = isBrowserEnv;
|
|
827
|
-
index_cjs$1.isDebugMode = isDebugMode;
|
|
828
|
-
index_cjs$1.isManifestProvider = isManifestProvider;
|
|
829
|
-
index_cjs$1.isReactNativeEnv = isReactNativeEnv;
|
|
830
|
-
index_cjs$1.isRequiredVersion = isRequiredVersion;
|
|
831
|
-
index_cjs$1.isStaticResourcesEqual = isStaticResourcesEqual$1;
|
|
832
|
-
index_cjs$1.loadScript = loadScript;
|
|
833
|
-
index_cjs$1.loadScriptNode = loadScriptNode;
|
|
834
|
-
index_cjs$1.logger = logger$1;
|
|
835
|
-
index_cjs$1.moduleFederationPlugin = ModuleFederationPlugin;
|
|
836
|
-
index_cjs$1.normalizeOptions = normalizeOptions;
|
|
837
|
-
index_cjs$1.parseEntry = parseEntry;
|
|
838
|
-
index_cjs$1.safeToString = safeToString;
|
|
839
|
-
index_cjs$1.safeWrapper = safeWrapper$1;
|
|
840
|
-
index_cjs$1.sharePlugin = SharePlugin;
|
|
841
|
-
index_cjs$1.simpleJoinRemoteEntry = simpleJoinRemoteEntry;
|
|
842
|
-
index_cjs$1.warn = warn$1;
|
|
843
|
-
|
|
844
|
-
var index_cjs = {};
|
|
845
|
-
|
|
846
|
-
const RUNTIME_001 = 'RUNTIME-001';
|
|
847
|
-
const RUNTIME_002 = 'RUNTIME-002';
|
|
848
|
-
const RUNTIME_003 = 'RUNTIME-003';
|
|
849
|
-
const RUNTIME_004 = 'RUNTIME-004';
|
|
850
|
-
const RUNTIME_005 = 'RUNTIME-005';
|
|
851
|
-
const RUNTIME_006 = 'RUNTIME-006';
|
|
852
|
-
const RUNTIME_007 = 'RUNTIME-007';
|
|
853
|
-
const RUNTIME_008 = 'RUNTIME-008';
|
|
854
|
-
const RUNTIME_009 = 'RUNTIME-009';
|
|
855
|
-
const TYPE_001 = 'TYPE-001';
|
|
856
|
-
const BUILD_001 = 'BUILD-001';
|
|
857
|
-
const BUILD_002 = 'BUILD-002';
|
|
858
|
-
|
|
859
|
-
const getDocsUrl = (errorCode)=>{
|
|
860
|
-
const type = errorCode.split('-')[0].toLowerCase();
|
|
861
|
-
return `View the docs to see how to solve: https://module-federation.io/guide/troubleshooting/${type}/${errorCode}`;
|
|
862
|
-
};
|
|
863
|
-
const getShortErrorMsg = (errorCode, errorDescMap, args, originalErrorMsg)=>{
|
|
864
|
-
const msg = [
|
|
865
|
-
`${[
|
|
866
|
-
errorDescMap[errorCode]
|
|
867
|
-
]} #${errorCode}`
|
|
868
|
-
];
|
|
869
|
-
args && msg.push(`args: ${JSON.stringify(args)}`);
|
|
870
|
-
msg.push(getDocsUrl(errorCode));
|
|
871
|
-
originalErrorMsg && msg.push(`Original Error Message:\n ${originalErrorMsg}`);
|
|
872
|
-
return msg.join('\n');
|
|
873
|
-
};
|
|
874
|
-
|
|
875
|
-
function _extends() {
|
|
876
|
-
_extends = Object.assign || function assign(target) {
|
|
877
|
-
for(var i = 1; i < arguments.length; i++){
|
|
878
|
-
var source = arguments[i];
|
|
879
|
-
for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
880
|
-
}
|
|
881
|
-
return target;
|
|
882
|
-
};
|
|
883
|
-
return _extends.apply(this, arguments);
|
|
884
|
-
}
|
|
885
|
-
|
|
886
|
-
const runtimeDescMap = {
|
|
887
|
-
[RUNTIME_001]: 'Failed to get remoteEntry exports.',
|
|
888
|
-
[RUNTIME_002]: 'The remote entry interface does not contain "init"',
|
|
889
|
-
[RUNTIME_003]: 'Failed to get manifest.',
|
|
890
|
-
[RUNTIME_004]: 'Failed to locate remote.',
|
|
891
|
-
[RUNTIME_005]: 'Invalid loadShareSync function call from bundler runtime',
|
|
892
|
-
[RUNTIME_006]: 'Invalid loadShareSync function call from runtime',
|
|
893
|
-
[RUNTIME_007]: 'Failed to get remote snapshot.',
|
|
894
|
-
[RUNTIME_008]: 'Failed to load script resources.',
|
|
895
|
-
[RUNTIME_009]: 'Please call createInstance first.'
|
|
896
|
-
};
|
|
897
|
-
const typeDescMap = {
|
|
898
|
-
[TYPE_001]: 'Failed to generate type declaration. Execute the below cmd to reproduce and fix the error.'
|
|
899
|
-
};
|
|
900
|
-
const buildDescMap = {
|
|
901
|
-
[BUILD_001]: 'Failed to find expose module.',
|
|
902
|
-
[BUILD_002]: 'PublicPath is required in prod mode.'
|
|
903
|
-
};
|
|
904
|
-
const errorDescMap = _extends({}, runtimeDescMap, typeDescMap, buildDescMap);
|
|
905
|
-
|
|
906
|
-
index_cjs.BUILD_001 = BUILD_001;
|
|
907
|
-
index_cjs.BUILD_002 = BUILD_002;
|
|
908
|
-
index_cjs.RUNTIME_001 = RUNTIME_001;
|
|
909
|
-
index_cjs.RUNTIME_002 = RUNTIME_002;
|
|
910
|
-
index_cjs.RUNTIME_003 = RUNTIME_003;
|
|
911
|
-
index_cjs.RUNTIME_004 = RUNTIME_004;
|
|
912
|
-
index_cjs.RUNTIME_005 = RUNTIME_005;
|
|
913
|
-
index_cjs.RUNTIME_006 = RUNTIME_006;
|
|
914
|
-
index_cjs.RUNTIME_007 = RUNTIME_007;
|
|
915
|
-
index_cjs.RUNTIME_008 = RUNTIME_008;
|
|
916
|
-
index_cjs.RUNTIME_009 = RUNTIME_009;
|
|
917
|
-
index_cjs.TYPE_001 = TYPE_001;
|
|
918
|
-
index_cjs.buildDescMap = buildDescMap;
|
|
919
|
-
index_cjs.errorDescMap = errorDescMap;
|
|
920
|
-
index_cjs.getShortErrorMsg = getShortErrorMsg;
|
|
921
|
-
index_cjs.runtimeDescMap = runtimeDescMap;
|
|
922
|
-
index_cjs.typeDescMap = typeDescMap;
|
|
923
|
-
|
|
924
|
-
var polyfills = polyfills_cjs$1;
|
|
925
|
-
var sdk = index_cjs$1;
|
|
926
|
-
var errorCodes$1 = index_cjs;
|
|
927
|
-
|
|
928
|
-
const LOG_CATEGORY = '[ Federation Runtime ]';
|
|
929
|
-
// FIXME: pre-bundle ?
|
|
930
|
-
const logger = sdk.createLogger(LOG_CATEGORY);
|
|
931
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
932
|
-
function assert(condition, msg) {
|
|
933
|
-
if (!condition) {
|
|
934
|
-
error(msg);
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
function error(msg) {
|
|
938
|
-
if (msg instanceof Error) {
|
|
939
|
-
// Check if the message already starts with the log category to avoid duplication
|
|
940
|
-
if (!msg.message.startsWith(LOG_CATEGORY)) {
|
|
941
|
-
msg.message = `${LOG_CATEGORY}: ${msg.message}`;
|
|
942
|
-
}
|
|
943
|
-
throw msg;
|
|
944
|
-
}
|
|
945
|
-
throw new Error(`${LOG_CATEGORY}: ${msg}`);
|
|
946
|
-
}
|
|
947
|
-
function warn(msg) {
|
|
948
|
-
if (msg instanceof Error) {
|
|
949
|
-
// Check if the message already starts with the log category to avoid duplication
|
|
950
|
-
if (!msg.message.startsWith(LOG_CATEGORY)) {
|
|
951
|
-
msg.message = `${LOG_CATEGORY}: ${msg.message}`;
|
|
952
|
-
}
|
|
953
|
-
logger.warn(msg);
|
|
954
|
-
} else {
|
|
955
|
-
logger.warn(msg);
|
|
956
|
-
}
|
|
957
|
-
}
|
|
958
|
-
|
|
959
|
-
function addUniqueItem(arr, item) {
|
|
960
|
-
if (arr.findIndex((name)=>name === item) === -1) {
|
|
961
|
-
arr.push(item);
|
|
962
|
-
}
|
|
963
|
-
return arr;
|
|
964
|
-
}
|
|
965
|
-
function getFMId(remoteInfo) {
|
|
966
|
-
if ('version' in remoteInfo && remoteInfo.version) {
|
|
967
|
-
return `${remoteInfo.name}:${remoteInfo.version}`;
|
|
968
|
-
} else if ('entry' in remoteInfo && remoteInfo.entry) {
|
|
969
|
-
return `${remoteInfo.name}:${remoteInfo.entry}`;
|
|
970
|
-
} else {
|
|
971
|
-
return `${remoteInfo.name}`;
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
|
-
function isRemoteInfoWithEntry(remote) {
|
|
975
|
-
return typeof remote.entry !== 'undefined';
|
|
976
|
-
}
|
|
977
|
-
function isPureRemoteEntry(remote) {
|
|
978
|
-
return !remote.entry.includes('.json');
|
|
979
|
-
}
|
|
980
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
981
|
-
async function safeWrapper(callback, disableWarn) {
|
|
982
|
-
try {
|
|
983
|
-
const res = await callback();
|
|
984
|
-
return res;
|
|
985
|
-
} catch (e) {
|
|
986
|
-
!disableWarn && warn(e);
|
|
987
|
-
return;
|
|
988
|
-
}
|
|
989
|
-
}
|
|
990
|
-
function isObject(val) {
|
|
991
|
-
return val && typeof val === 'object';
|
|
992
|
-
}
|
|
993
|
-
const objectToString = Object.prototype.toString;
|
|
994
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
995
|
-
function isPlainObject(val) {
|
|
996
|
-
return objectToString.call(val) === '[object Object]';
|
|
997
|
-
}
|
|
998
|
-
function isStaticResourcesEqual(url1, url2) {
|
|
999
|
-
const REG_EXP = /^(https?:)?\/\//i;
|
|
1000
|
-
// Transform url1 and url2 into relative paths
|
|
1001
|
-
const relativeUrl1 = url1.replace(REG_EXP, '').replace(/\/$/, '');
|
|
1002
|
-
const relativeUrl2 = url2.replace(REG_EXP, '').replace(/\/$/, '');
|
|
1003
|
-
// Check if the relative paths are identical
|
|
1004
|
-
return relativeUrl1 === relativeUrl2;
|
|
1005
|
-
}
|
|
1006
|
-
function arrayOptions(options) {
|
|
1007
|
-
return Array.isArray(options) ? options : [
|
|
1008
|
-
options
|
|
1009
|
-
];
|
|
1010
|
-
}
|
|
1011
|
-
function getRemoteEntryInfoFromSnapshot(snapshot) {
|
|
1012
|
-
const defaultRemoteEntryInfo = {
|
|
1013
|
-
url: '',
|
|
1014
|
-
type: 'global',
|
|
1015
|
-
globalName: ''
|
|
1016
|
-
};
|
|
1017
|
-
if (sdk.isBrowserEnv() || sdk.isReactNativeEnv()) {
|
|
1018
|
-
return 'remoteEntry' in snapshot ? {
|
|
1019
|
-
url: snapshot.remoteEntry,
|
|
1020
|
-
type: snapshot.remoteEntryType,
|
|
1021
|
-
globalName: snapshot.globalName
|
|
1022
|
-
} : defaultRemoteEntryInfo;
|
|
1023
|
-
}
|
|
1024
|
-
if ('ssrRemoteEntry' in snapshot) {
|
|
1025
|
-
return {
|
|
1026
|
-
url: snapshot.ssrRemoteEntry || defaultRemoteEntryInfo.url,
|
|
1027
|
-
type: snapshot.ssrRemoteEntryType || defaultRemoteEntryInfo.type,
|
|
1028
|
-
globalName: snapshot.globalName
|
|
1029
|
-
};
|
|
1030
|
-
}
|
|
1031
|
-
return defaultRemoteEntryInfo;
|
|
1032
|
-
}
|
|
1033
|
-
const processModuleAlias = (name, subPath)=>{
|
|
1034
|
-
// @host/ ./button -> @host/button
|
|
1035
|
-
let moduleName;
|
|
1036
|
-
if (name.endsWith('/')) {
|
|
1037
|
-
moduleName = name.slice(0, -1);
|
|
1038
|
-
} else {
|
|
1039
|
-
moduleName = name;
|
|
1040
|
-
}
|
|
1041
|
-
if (subPath.startsWith('.')) {
|
|
1042
|
-
subPath = subPath.slice(1);
|
|
1043
|
-
}
|
|
1044
|
-
moduleName = moduleName + subPath;
|
|
1045
|
-
return moduleName;
|
|
1046
|
-
};
|
|
1047
|
-
|
|
1048
|
-
const CurrentGlobal = typeof globalThis === 'object' ? globalThis : window;
|
|
1049
|
-
const nativeGlobal = (()=>{
|
|
1050
|
-
try {
|
|
1051
|
-
// get real window (incase of sandbox)
|
|
1052
|
-
return document.defaultView;
|
|
1053
|
-
} catch (e) {
|
|
1054
|
-
// node env
|
|
1055
|
-
return CurrentGlobal;
|
|
1056
|
-
}
|
|
1057
|
-
})();
|
|
1058
|
-
const Global = nativeGlobal;
|
|
1059
|
-
function definePropertyGlobalVal(target, key, val) {
|
|
1060
|
-
Object.defineProperty(target, key, {
|
|
1061
|
-
value: val,
|
|
1062
|
-
configurable: false,
|
|
1063
|
-
writable: true
|
|
1064
|
-
});
|
|
1065
|
-
}
|
|
1066
|
-
function includeOwnProperty(target, key) {
|
|
1067
|
-
return Object.hasOwnProperty.call(target, key);
|
|
1068
|
-
}
|
|
1069
|
-
// This section is to prevent encapsulation by certain microfrontend frameworks. Due to reuse policies, sandbox escapes.
|
|
1070
|
-
// The sandbox in the microfrontend does not replicate the value of 'configurable'.
|
|
1071
|
-
// If there is no loading content on the global object, this section defines the loading object.
|
|
1072
|
-
if (!includeOwnProperty(CurrentGlobal, '__GLOBAL_LOADING_REMOTE_ENTRY__')) {
|
|
1073
|
-
definePropertyGlobalVal(CurrentGlobal, '__GLOBAL_LOADING_REMOTE_ENTRY__', {});
|
|
1074
|
-
}
|
|
1075
|
-
const globalLoading = CurrentGlobal.__GLOBAL_LOADING_REMOTE_ENTRY__;
|
|
1076
|
-
function setGlobalDefaultVal(target) {
|
|
1077
|
-
var _target___FEDERATION__, _target___FEDERATION__1, _target___FEDERATION__2, _target___FEDERATION__3, _target___FEDERATION__4, _target___FEDERATION__5;
|
|
1078
|
-
if (includeOwnProperty(target, '__VMOK__') && !includeOwnProperty(target, '__FEDERATION__')) {
|
|
1079
|
-
definePropertyGlobalVal(target, '__FEDERATION__', target.__VMOK__);
|
|
1080
|
-
}
|
|
1081
|
-
if (!includeOwnProperty(target, '__FEDERATION__')) {
|
|
1082
|
-
definePropertyGlobalVal(target, '__FEDERATION__', {
|
|
1083
|
-
__GLOBAL_PLUGIN__: [],
|
|
1084
|
-
__INSTANCES__: [],
|
|
1085
|
-
moduleInfo: {},
|
|
1086
|
-
__SHARE__: {},
|
|
1087
|
-
__MANIFEST_LOADING__: {},
|
|
1088
|
-
__PRELOADED_MAP__: new Map()
|
|
1089
|
-
});
|
|
1090
|
-
definePropertyGlobalVal(target, '__VMOK__', target.__FEDERATION__);
|
|
1091
|
-
}
|
|
1092
|
-
var ___GLOBAL_PLUGIN__;
|
|
1093
|
-
(___GLOBAL_PLUGIN__ = (_target___FEDERATION__ = target.__FEDERATION__).__GLOBAL_PLUGIN__) != null ? ___GLOBAL_PLUGIN__ : _target___FEDERATION__.__GLOBAL_PLUGIN__ = [];
|
|
1094
|
-
var ___INSTANCES__;
|
|
1095
|
-
(___INSTANCES__ = (_target___FEDERATION__1 = target.__FEDERATION__).__INSTANCES__) != null ? ___INSTANCES__ : _target___FEDERATION__1.__INSTANCES__ = [];
|
|
1096
|
-
var _moduleInfo;
|
|
1097
|
-
(_moduleInfo = (_target___FEDERATION__2 = target.__FEDERATION__).moduleInfo) != null ? _moduleInfo : _target___FEDERATION__2.moduleInfo = {};
|
|
1098
|
-
var ___SHARE__;
|
|
1099
|
-
(___SHARE__ = (_target___FEDERATION__3 = target.__FEDERATION__).__SHARE__) != null ? ___SHARE__ : _target___FEDERATION__3.__SHARE__ = {};
|
|
1100
|
-
var ___MANIFEST_LOADING__;
|
|
1101
|
-
(___MANIFEST_LOADING__ = (_target___FEDERATION__4 = target.__FEDERATION__).__MANIFEST_LOADING__) != null ? ___MANIFEST_LOADING__ : _target___FEDERATION__4.__MANIFEST_LOADING__ = {};
|
|
1102
|
-
var ___PRELOADED_MAP__;
|
|
1103
|
-
(___PRELOADED_MAP__ = (_target___FEDERATION__5 = target.__FEDERATION__).__PRELOADED_MAP__) != null ? ___PRELOADED_MAP__ : _target___FEDERATION__5.__PRELOADED_MAP__ = new Map();
|
|
1104
|
-
}
|
|
1105
|
-
setGlobalDefaultVal(CurrentGlobal);
|
|
1106
|
-
setGlobalDefaultVal(nativeGlobal);
|
|
1107
|
-
function resetFederationGlobalInfo() {
|
|
1108
|
-
CurrentGlobal.__FEDERATION__.__GLOBAL_PLUGIN__ = [];
|
|
1109
|
-
CurrentGlobal.__FEDERATION__.__INSTANCES__ = [];
|
|
1110
|
-
CurrentGlobal.__FEDERATION__.moduleInfo = {};
|
|
1111
|
-
CurrentGlobal.__FEDERATION__.__SHARE__ = {};
|
|
1112
|
-
CurrentGlobal.__FEDERATION__.__MANIFEST_LOADING__ = {};
|
|
1113
|
-
Object.keys(globalLoading).forEach((key)=>{
|
|
1114
|
-
delete globalLoading[key];
|
|
1115
|
-
});
|
|
1116
|
-
}
|
|
1117
|
-
function setGlobalFederationInstance(FederationInstance) {
|
|
1118
|
-
CurrentGlobal.__FEDERATION__.__INSTANCES__.push(FederationInstance);
|
|
1119
|
-
}
|
|
1120
|
-
function getGlobalFederationConstructor() {
|
|
1121
|
-
return CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR__;
|
|
1122
|
-
}
|
|
1123
|
-
function setGlobalFederationConstructor(FederationConstructor, isDebug = sdk.isDebugMode()) {
|
|
1124
|
-
if (isDebug) {
|
|
1125
|
-
CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
1126
|
-
CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.18.4";
|
|
1127
|
-
}
|
|
1128
|
-
}
|
|
1129
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
1130
|
-
function getInfoWithoutType(target, key) {
|
|
1131
|
-
if (typeof key === 'string') {
|
|
1132
|
-
const keyRes = target[key];
|
|
1133
|
-
if (keyRes) {
|
|
1134
|
-
return {
|
|
1135
|
-
value: target[key],
|
|
1136
|
-
key: key
|
|
1137
|
-
};
|
|
1138
|
-
} else {
|
|
1139
|
-
const targetKeys = Object.keys(target);
|
|
1140
|
-
for (const targetKey of targetKeys){
|
|
1141
|
-
const [targetTypeOrName, _] = targetKey.split(':');
|
|
1142
|
-
const nKey = `${targetTypeOrName}:${key}`;
|
|
1143
|
-
const typeWithKeyRes = target[nKey];
|
|
1144
|
-
if (typeWithKeyRes) {
|
|
1145
|
-
return {
|
|
1146
|
-
value: typeWithKeyRes,
|
|
1147
|
-
key: nKey
|
|
1148
|
-
};
|
|
1149
|
-
}
|
|
1150
|
-
}
|
|
1151
|
-
return {
|
|
1152
|
-
value: undefined,
|
|
1153
|
-
key: key
|
|
1154
|
-
};
|
|
1155
|
-
}
|
|
1156
|
-
} else {
|
|
1157
|
-
throw new Error('key must be string');
|
|
1158
|
-
}
|
|
1159
|
-
}
|
|
1160
|
-
const getGlobalSnapshot = ()=>nativeGlobal.__FEDERATION__.moduleInfo;
|
|
1161
|
-
const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot)=>{
|
|
1162
|
-
// Check if the remote is included in the hostSnapshot
|
|
1163
|
-
const moduleKey = getFMId(moduleInfo);
|
|
1164
|
-
const getModuleInfo = getInfoWithoutType(snapshot, moduleKey).value;
|
|
1165
|
-
// The remoteSnapshot might not include a version
|
|
1166
|
-
if (getModuleInfo && !getModuleInfo.version && 'version' in moduleInfo && moduleInfo['version']) {
|
|
1167
|
-
getModuleInfo.version = moduleInfo['version'];
|
|
1168
|
-
}
|
|
1169
|
-
if (getModuleInfo) {
|
|
1170
|
-
return getModuleInfo;
|
|
1171
|
-
}
|
|
1172
|
-
// If the remote is not included in the hostSnapshot, deploy a micro app snapshot
|
|
1173
|
-
if ('version' in moduleInfo && moduleInfo['version']) {
|
|
1174
|
-
const { version } = moduleInfo, resModuleInfo = polyfills._object_without_properties_loose(moduleInfo, [
|
|
1175
|
-
"version"
|
|
1176
|
-
]);
|
|
1177
|
-
const moduleKeyWithoutVersion = getFMId(resModuleInfo);
|
|
1178
|
-
const getModuleInfoWithoutVersion = getInfoWithoutType(nativeGlobal.__FEDERATION__.moduleInfo, moduleKeyWithoutVersion).value;
|
|
1179
|
-
if ((getModuleInfoWithoutVersion == null ? void 0 : getModuleInfoWithoutVersion.version) === version) {
|
|
1180
|
-
return getModuleInfoWithoutVersion;
|
|
1181
|
-
}
|
|
1182
|
-
}
|
|
1183
|
-
return;
|
|
1184
|
-
};
|
|
1185
|
-
const getGlobalSnapshotInfoByModuleInfo = (moduleInfo)=>getTargetSnapshotInfoByModuleInfo(moduleInfo, nativeGlobal.__FEDERATION__.moduleInfo);
|
|
1186
|
-
const setGlobalSnapshotInfoByModuleInfo = (remoteInfo, moduleDetailInfo)=>{
|
|
1187
|
-
const moduleKey = getFMId(remoteInfo);
|
|
1188
|
-
nativeGlobal.__FEDERATION__.moduleInfo[moduleKey] = moduleDetailInfo;
|
|
1189
|
-
return nativeGlobal.__FEDERATION__.moduleInfo;
|
|
1190
|
-
};
|
|
1191
|
-
const addGlobalSnapshot = (moduleInfos)=>{
|
|
1192
|
-
nativeGlobal.__FEDERATION__.moduleInfo = polyfills._extends({}, nativeGlobal.__FEDERATION__.moduleInfo, moduleInfos);
|
|
1193
|
-
return ()=>{
|
|
1194
|
-
const keys = Object.keys(moduleInfos);
|
|
1195
|
-
for (const key of keys){
|
|
1196
|
-
delete nativeGlobal.__FEDERATION__.moduleInfo[key];
|
|
1197
|
-
}
|
|
1198
|
-
};
|
|
1199
|
-
};
|
|
1200
|
-
const getRemoteEntryExports = (name, globalName)=>{
|
|
1201
|
-
const remoteEntryKey = globalName || `__FEDERATION_${name}:custom__`;
|
|
1202
|
-
const entryExports = CurrentGlobal[remoteEntryKey];
|
|
1203
|
-
return {
|
|
1204
|
-
remoteEntryKey,
|
|
1205
|
-
entryExports
|
|
1206
|
-
};
|
|
1207
|
-
};
|
|
1208
|
-
// This function is used to register global plugins.
|
|
1209
|
-
// It iterates over the provided plugins and checks if they are already registered.
|
|
1210
|
-
// If a plugin is not registered, it is added to the global plugins.
|
|
1211
|
-
// If a plugin is already registered, a warning message is logged.
|
|
1212
|
-
const registerGlobalPlugins = (plugins)=>{
|
|
1213
|
-
const { __GLOBAL_PLUGIN__ } = nativeGlobal.__FEDERATION__;
|
|
1214
|
-
plugins.forEach((plugin)=>{
|
|
1215
|
-
if (__GLOBAL_PLUGIN__.findIndex((p)=>p.name === plugin.name) === -1) {
|
|
1216
|
-
__GLOBAL_PLUGIN__.push(plugin);
|
|
1217
|
-
} else {
|
|
1218
|
-
warn(`The plugin ${plugin.name} has been registered.`);
|
|
1219
|
-
}
|
|
1220
|
-
});
|
|
1221
|
-
};
|
|
1222
|
-
const getGlobalHostPlugins = ()=>nativeGlobal.__FEDERATION__.__GLOBAL_PLUGIN__;
|
|
1223
|
-
const getPreloaded = (id)=>CurrentGlobal.__FEDERATION__.__PRELOADED_MAP__.get(id);
|
|
1224
|
-
const setPreloaded = (id)=>CurrentGlobal.__FEDERATION__.__PRELOADED_MAP__.set(id, true);
|
|
1225
|
-
|
|
1226
|
-
const DEFAULT_SCOPE = 'default';
|
|
1227
|
-
const DEFAULT_REMOTE_TYPE = 'global';
|
|
1228
|
-
|
|
1229
|
-
// fork from https://github.com/originjs/vite-plugin-federation/blob/v1.1.12/packages/lib/src/utils/semver/index.ts
|
|
1230
|
-
// those constants are based on https://www.rubydoc.info/gems/semantic_range/3.0.0/SemanticRange#BUILDIDENTIFIER-constant
|
|
1231
|
-
// Copyright (c)
|
|
1232
|
-
// vite-plugin-federation is licensed under Mulan PSL v2.
|
|
1233
|
-
// You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
1234
|
-
// You may obtain a copy of Mulan PSL v2 at:
|
|
1235
|
-
// http://license.coscl.org.cn/MulanPSL2
|
|
1236
|
-
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
1237
|
-
// See the Mulan PSL v2 for more details.
|
|
1238
|
-
const buildIdentifier = '[0-9A-Za-z-]+';
|
|
1239
|
-
const build = `(?:\\+(${buildIdentifier}(?:\\.${buildIdentifier})*))`;
|
|
1240
|
-
const numericIdentifier = '0|[1-9]\\d*';
|
|
1241
|
-
const numericIdentifierLoose = '[0-9]+';
|
|
1242
|
-
const nonNumericIdentifier = '\\d*[a-zA-Z-][a-zA-Z0-9-]*';
|
|
1243
|
-
const preReleaseIdentifierLoose = `(?:${numericIdentifierLoose}|${nonNumericIdentifier})`;
|
|
1244
|
-
const preReleaseLoose = `(?:-?(${preReleaseIdentifierLoose}(?:\\.${preReleaseIdentifierLoose})*))`;
|
|
1245
|
-
const preReleaseIdentifier = `(?:${numericIdentifier}|${nonNumericIdentifier})`;
|
|
1246
|
-
const preRelease = `(?:-(${preReleaseIdentifier}(?:\\.${preReleaseIdentifier})*))`;
|
|
1247
|
-
const xRangeIdentifier = `${numericIdentifier}|x|X|\\*`;
|
|
1248
|
-
const xRangePlain = `[v=\\s]*(${xRangeIdentifier})(?:\\.(${xRangeIdentifier})(?:\\.(${xRangeIdentifier})(?:${preRelease})?${build}?)?)?`;
|
|
1249
|
-
const hyphenRange = `^\\s*(${xRangePlain})\\s+-\\s+(${xRangePlain})\\s*$`;
|
|
1250
|
-
const mainVersionLoose = `(${numericIdentifierLoose})\\.(${numericIdentifierLoose})\\.(${numericIdentifierLoose})`;
|
|
1251
|
-
const loosePlain = `[v=\\s]*${mainVersionLoose}${preReleaseLoose}?${build}?`;
|
|
1252
|
-
const gtlt = '((?:<|>)?=?)';
|
|
1253
|
-
const comparatorTrim = `(\\s*)${gtlt}\\s*(${loosePlain}|${xRangePlain})`;
|
|
1254
|
-
const loneTilde = '(?:~>?)';
|
|
1255
|
-
const tildeTrim = `(\\s*)${loneTilde}\\s+`;
|
|
1256
|
-
const loneCaret = '(?:\\^)';
|
|
1257
|
-
const caretTrim = `(\\s*)${loneCaret}\\s+`;
|
|
1258
|
-
const star = '(<|>)?=?\\s*\\*';
|
|
1259
|
-
const caret = `^${loneCaret}${xRangePlain}$`;
|
|
1260
|
-
const mainVersion = `(${numericIdentifier})\\.(${numericIdentifier})\\.(${numericIdentifier})`;
|
|
1261
|
-
const fullPlain = `v?${mainVersion}${preRelease}?${build}?`;
|
|
1262
|
-
const tilde = `^${loneTilde}${xRangePlain}$`;
|
|
1263
|
-
const xRange = `^${gtlt}\\s*${xRangePlain}$`;
|
|
1264
|
-
const comparator = `^${gtlt}\\s*(${fullPlain})$|^$`;
|
|
1265
|
-
// copy from semver package
|
|
1266
|
-
const gte0 = '^\\s*>=\\s*0.0.0\\s*$';
|
|
1267
|
-
|
|
1268
|
-
// fork from https://github.com/originjs/vite-plugin-federation/blob/v1.1.12/packages/lib/src/utils/semver/index.ts
|
|
1269
|
-
// Copyright (c)
|
|
1270
|
-
// vite-plugin-federation is licensed under Mulan PSL v2.
|
|
1271
|
-
// You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
1272
|
-
// You may obtain a copy of Mulan PSL v2 at:
|
|
1273
|
-
// http://license.coscl.org.cn/MulanPSL2
|
|
1274
|
-
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
1275
|
-
// See the Mulan PSL v2 for more details.
|
|
1276
|
-
function parseRegex(source) {
|
|
1277
|
-
return new RegExp(source);
|
|
1278
|
-
}
|
|
1279
|
-
function isXVersion(version) {
|
|
1280
|
-
return !version || version.toLowerCase() === 'x' || version === '*';
|
|
1281
|
-
}
|
|
1282
|
-
function pipe(...fns) {
|
|
1283
|
-
return (x)=>fns.reduce((v, f)=>f(v), x);
|
|
1284
|
-
}
|
|
1285
|
-
function extractComparator(comparatorString) {
|
|
1286
|
-
return comparatorString.match(parseRegex(comparator));
|
|
1287
|
-
}
|
|
1288
|
-
function combineVersion(major, minor, patch, preRelease) {
|
|
1289
|
-
const mainVersion = `${major}.${minor}.${patch}`;
|
|
1290
|
-
if (preRelease) {
|
|
1291
|
-
return `${mainVersion}-${preRelease}`;
|
|
1292
|
-
}
|
|
1293
|
-
return mainVersion;
|
|
1294
|
-
}
|
|
1295
|
-
|
|
1296
|
-
// fork from https://github.com/originjs/vite-plugin-federation/blob/v1.1.12/packages/lib/src/utils/semver/index.ts
|
|
1297
|
-
// Copyright (c)
|
|
1298
|
-
// vite-plugin-federation is licensed under Mulan PSL v2.
|
|
1299
|
-
// You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
1300
|
-
// You may obtain a copy of Mulan PSL v2 at:
|
|
1301
|
-
// http://license.coscl.org.cn/MulanPSL2
|
|
1302
|
-
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
1303
|
-
// See the Mulan PSL v2 for more details.
|
|
1304
|
-
function parseHyphen(range) {
|
|
1305
|
-
return range.replace(parseRegex(hyphenRange), (_range, from, fromMajor, fromMinor, fromPatch, _fromPreRelease, _fromBuild, to, toMajor, toMinor, toPatch, toPreRelease)=>{
|
|
1306
|
-
if (isXVersion(fromMajor)) {
|
|
1307
|
-
from = '';
|
|
1308
|
-
} else if (isXVersion(fromMinor)) {
|
|
1309
|
-
from = `>=${fromMajor}.0.0`;
|
|
1310
|
-
} else if (isXVersion(fromPatch)) {
|
|
1311
|
-
from = `>=${fromMajor}.${fromMinor}.0`;
|
|
1312
|
-
} else {
|
|
1313
|
-
from = `>=${from}`;
|
|
1314
|
-
}
|
|
1315
|
-
if (isXVersion(toMajor)) {
|
|
1316
|
-
to = '';
|
|
1317
|
-
} else if (isXVersion(toMinor)) {
|
|
1318
|
-
to = `<${Number(toMajor) + 1}.0.0-0`;
|
|
1319
|
-
} else if (isXVersion(toPatch)) {
|
|
1320
|
-
to = `<${toMajor}.${Number(toMinor) + 1}.0-0`;
|
|
1321
|
-
} else if (toPreRelease) {
|
|
1322
|
-
to = `<=${toMajor}.${toMinor}.${toPatch}-${toPreRelease}`;
|
|
1323
|
-
} else {
|
|
1324
|
-
to = `<=${to}`;
|
|
1325
|
-
}
|
|
1326
|
-
return `${from} ${to}`.trim();
|
|
1327
|
-
});
|
|
1328
|
-
}
|
|
1329
|
-
function parseComparatorTrim(range) {
|
|
1330
|
-
return range.replace(parseRegex(comparatorTrim), '$1$2$3');
|
|
1331
|
-
}
|
|
1332
|
-
function parseTildeTrim(range) {
|
|
1333
|
-
return range.replace(parseRegex(tildeTrim), '$1~');
|
|
1334
|
-
}
|
|
1335
|
-
function parseCaretTrim(range) {
|
|
1336
|
-
return range.replace(parseRegex(caretTrim), '$1^');
|
|
1337
|
-
}
|
|
1338
|
-
function parseCarets(range) {
|
|
1339
|
-
return range.trim().split(/\s+/).map((rangeVersion)=>rangeVersion.replace(parseRegex(caret), (_, major, minor, patch, preRelease)=>{
|
|
1340
|
-
if (isXVersion(major)) {
|
|
1341
|
-
return '';
|
|
1342
|
-
} else if (isXVersion(minor)) {
|
|
1343
|
-
return `>=${major}.0.0 <${Number(major) + 1}.0.0-0`;
|
|
1344
|
-
} else if (isXVersion(patch)) {
|
|
1345
|
-
if (major === '0') {
|
|
1346
|
-
return `>=${major}.${minor}.0 <${major}.${Number(minor) + 1}.0-0`;
|
|
1347
|
-
} else {
|
|
1348
|
-
return `>=${major}.${minor}.0 <${Number(major) + 1}.0.0-0`;
|
|
1349
|
-
}
|
|
1350
|
-
} else if (preRelease) {
|
|
1351
|
-
if (major === '0') {
|
|
1352
|
-
if (minor === '0') {
|
|
1353
|
-
return `>=${major}.${minor}.${patch}-${preRelease} <${major}.${minor}.${Number(patch) + 1}-0`;
|
|
1354
|
-
} else {
|
|
1355
|
-
return `>=${major}.${minor}.${patch}-${preRelease} <${major}.${Number(minor) + 1}.0-0`;
|
|
1356
|
-
}
|
|
1357
|
-
} else {
|
|
1358
|
-
return `>=${major}.${minor}.${patch}-${preRelease} <${Number(major) + 1}.0.0-0`;
|
|
1359
|
-
}
|
|
1360
|
-
} else {
|
|
1361
|
-
if (major === '0') {
|
|
1362
|
-
if (minor === '0') {
|
|
1363
|
-
return `>=${major}.${minor}.${patch} <${major}.${minor}.${Number(patch) + 1}-0`;
|
|
1364
|
-
} else {
|
|
1365
|
-
return `>=${major}.${minor}.${patch} <${major}.${Number(minor) + 1}.0-0`;
|
|
1366
|
-
}
|
|
1367
|
-
}
|
|
1368
|
-
return `>=${major}.${minor}.${patch} <${Number(major) + 1}.0.0-0`;
|
|
1369
|
-
}
|
|
1370
|
-
})).join(' ');
|
|
1371
|
-
}
|
|
1372
|
-
function parseTildes(range) {
|
|
1373
|
-
return range.trim().split(/\s+/).map((rangeVersion)=>rangeVersion.replace(parseRegex(tilde), (_, major, minor, patch, preRelease)=>{
|
|
1374
|
-
if (isXVersion(major)) {
|
|
1375
|
-
return '';
|
|
1376
|
-
} else if (isXVersion(minor)) {
|
|
1377
|
-
return `>=${major}.0.0 <${Number(major) + 1}.0.0-0`;
|
|
1378
|
-
} else if (isXVersion(patch)) {
|
|
1379
|
-
return `>=${major}.${minor}.0 <${major}.${Number(minor) + 1}.0-0`;
|
|
1380
|
-
} else if (preRelease) {
|
|
1381
|
-
return `>=${major}.${minor}.${patch}-${preRelease} <${major}.${Number(minor) + 1}.0-0`;
|
|
1382
|
-
}
|
|
1383
|
-
return `>=${major}.${minor}.${patch} <${major}.${Number(minor) + 1}.0-0`;
|
|
1384
|
-
})).join(' ');
|
|
1385
|
-
}
|
|
1386
|
-
function parseXRanges(range) {
|
|
1387
|
-
return range.split(/\s+/).map((rangeVersion)=>rangeVersion.trim().replace(parseRegex(xRange), (ret, gtlt, major, minor, patch, preRelease)=>{
|
|
1388
|
-
const isXMajor = isXVersion(major);
|
|
1389
|
-
const isXMinor = isXMajor || isXVersion(minor);
|
|
1390
|
-
const isXPatch = isXMinor || isXVersion(patch);
|
|
1391
|
-
if (gtlt === '=' && isXPatch) {
|
|
1392
|
-
gtlt = '';
|
|
1393
|
-
}
|
|
1394
|
-
preRelease = '';
|
|
1395
|
-
if (isXMajor) {
|
|
1396
|
-
if (gtlt === '>' || gtlt === '<') {
|
|
1397
|
-
// nothing is allowed
|
|
1398
|
-
return '<0.0.0-0';
|
|
1399
|
-
} else {
|
|
1400
|
-
// nothing is forbidden
|
|
1401
|
-
return '*';
|
|
1402
|
-
}
|
|
1403
|
-
} else if (gtlt && isXPatch) {
|
|
1404
|
-
// replace X with 0
|
|
1405
|
-
if (isXMinor) {
|
|
1406
|
-
minor = 0;
|
|
1407
|
-
}
|
|
1408
|
-
patch = 0;
|
|
1409
|
-
if (gtlt === '>') {
|
|
1410
|
-
// >1 => >=2.0.0
|
|
1411
|
-
// >1.2 => >=1.3.0
|
|
1412
|
-
gtlt = '>=';
|
|
1413
|
-
if (isXMinor) {
|
|
1414
|
-
major = Number(major) + 1;
|
|
1415
|
-
minor = 0;
|
|
1416
|
-
patch = 0;
|
|
1417
|
-
} else {
|
|
1418
|
-
minor = Number(minor) + 1;
|
|
1419
|
-
patch = 0;
|
|
1420
|
-
}
|
|
1421
|
-
} else if (gtlt === '<=') {
|
|
1422
|
-
// <=0.7.x is actually <0.8.0, since any 0.7.x should pass
|
|
1423
|
-
// Similarly, <=7.x is actually <8.0.0, etc.
|
|
1424
|
-
gtlt = '<';
|
|
1425
|
-
if (isXMinor) {
|
|
1426
|
-
major = Number(major) + 1;
|
|
1427
|
-
} else {
|
|
1428
|
-
minor = Number(minor) + 1;
|
|
1429
|
-
}
|
|
1430
|
-
}
|
|
1431
|
-
if (gtlt === '<') {
|
|
1432
|
-
preRelease = '-0';
|
|
1433
|
-
}
|
|
1434
|
-
return `${gtlt + major}.${minor}.${patch}${preRelease}`;
|
|
1435
|
-
} else if (isXMinor) {
|
|
1436
|
-
return `>=${major}.0.0${preRelease} <${Number(major) + 1}.0.0-0`;
|
|
1437
|
-
} else if (isXPatch) {
|
|
1438
|
-
return `>=${major}.${minor}.0${preRelease} <${major}.${Number(minor) + 1}.0-0`;
|
|
1439
|
-
}
|
|
1440
|
-
return ret;
|
|
1441
|
-
})).join(' ');
|
|
1442
|
-
}
|
|
1443
|
-
function parseStar(range) {
|
|
1444
|
-
return range.trim().replace(parseRegex(star), '');
|
|
1445
|
-
}
|
|
1446
|
-
function parseGTE0(comparatorString) {
|
|
1447
|
-
return comparatorString.trim().replace(parseRegex(gte0), '');
|
|
1448
|
-
}
|
|
1449
|
-
|
|
1450
|
-
// fork from https://github.com/originjs/vite-plugin-federation/blob/v1.1.12/packages/lib/src/utils/semver/index.ts
|
|
1451
|
-
// Copyright (c)
|
|
1452
|
-
// vite-plugin-federation is licensed under Mulan PSL v2.
|
|
1453
|
-
// You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
1454
|
-
// You may obtain a copy of Mulan PSL v2 at:
|
|
1455
|
-
// http://license.coscl.org.cn/MulanPSL2
|
|
1456
|
-
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
1457
|
-
// See the Mulan PSL v2 for more details.
|
|
1458
|
-
function compareAtom(rangeAtom, versionAtom) {
|
|
1459
|
-
rangeAtom = Number(rangeAtom) || rangeAtom;
|
|
1460
|
-
versionAtom = Number(versionAtom) || versionAtom;
|
|
1461
|
-
if (rangeAtom > versionAtom) {
|
|
1462
|
-
return 1;
|
|
1463
|
-
}
|
|
1464
|
-
if (rangeAtom === versionAtom) {
|
|
1465
|
-
return 0;
|
|
1466
|
-
}
|
|
1467
|
-
return -1;
|
|
1468
|
-
}
|
|
1469
|
-
function comparePreRelease(rangeAtom, versionAtom) {
|
|
1470
|
-
const { preRelease: rangePreRelease } = rangeAtom;
|
|
1471
|
-
const { preRelease: versionPreRelease } = versionAtom;
|
|
1472
|
-
if (rangePreRelease === undefined && Boolean(versionPreRelease)) {
|
|
1473
|
-
return 1;
|
|
1474
|
-
}
|
|
1475
|
-
if (Boolean(rangePreRelease) && versionPreRelease === undefined) {
|
|
1476
|
-
return -1;
|
|
1477
|
-
}
|
|
1478
|
-
if (rangePreRelease === undefined && versionPreRelease === undefined) {
|
|
1479
|
-
return 0;
|
|
1480
|
-
}
|
|
1481
|
-
for(let i = 0, n = rangePreRelease.length; i <= n; i++){
|
|
1482
|
-
const rangeElement = rangePreRelease[i];
|
|
1483
|
-
const versionElement = versionPreRelease[i];
|
|
1484
|
-
if (rangeElement === versionElement) {
|
|
1485
|
-
continue;
|
|
1486
|
-
}
|
|
1487
|
-
if (rangeElement === undefined && versionElement === undefined) {
|
|
1488
|
-
return 0;
|
|
1489
|
-
}
|
|
1490
|
-
if (!rangeElement) {
|
|
1491
|
-
return 1;
|
|
1492
|
-
}
|
|
1493
|
-
if (!versionElement) {
|
|
1494
|
-
return -1;
|
|
1495
|
-
}
|
|
1496
|
-
return compareAtom(rangeElement, versionElement);
|
|
1497
|
-
}
|
|
1498
|
-
return 0;
|
|
1499
|
-
}
|
|
1500
|
-
function compareVersion(rangeAtom, versionAtom) {
|
|
1501
|
-
return compareAtom(rangeAtom.major, versionAtom.major) || compareAtom(rangeAtom.minor, versionAtom.minor) || compareAtom(rangeAtom.patch, versionAtom.patch) || comparePreRelease(rangeAtom, versionAtom);
|
|
1502
|
-
}
|
|
1503
|
-
function eq(rangeAtom, versionAtom) {
|
|
1504
|
-
return rangeAtom.version === versionAtom.version;
|
|
1505
|
-
}
|
|
1506
|
-
function compare(rangeAtom, versionAtom) {
|
|
1507
|
-
switch(rangeAtom.operator){
|
|
1508
|
-
case '':
|
|
1509
|
-
case '=':
|
|
1510
|
-
return eq(rangeAtom, versionAtom);
|
|
1511
|
-
case '>':
|
|
1512
|
-
return compareVersion(rangeAtom, versionAtom) < 0;
|
|
1513
|
-
case '>=':
|
|
1514
|
-
return eq(rangeAtom, versionAtom) || compareVersion(rangeAtom, versionAtom) < 0;
|
|
1515
|
-
case '<':
|
|
1516
|
-
return compareVersion(rangeAtom, versionAtom) > 0;
|
|
1517
|
-
case '<=':
|
|
1518
|
-
return eq(rangeAtom, versionAtom) || compareVersion(rangeAtom, versionAtom) > 0;
|
|
1519
|
-
case undefined:
|
|
1520
|
-
{
|
|
1521
|
-
// mean * or x -> all versions
|
|
1522
|
-
return true;
|
|
1523
|
-
}
|
|
1524
|
-
default:
|
|
1525
|
-
return false;
|
|
1526
|
-
}
|
|
1527
|
-
}
|
|
1528
|
-
|
|
1529
|
-
// fork from https://github.com/originjs/vite-plugin-federation/blob/v1.1.12/packages/lib/src/utils/semver/index.ts
|
|
1530
|
-
// Copyright (c)
|
|
1531
|
-
// vite-plugin-federation is licensed under Mulan PSL v2.
|
|
1532
|
-
// You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
1533
|
-
// You may obtain a copy of Mulan PSL v2 at:
|
|
1534
|
-
// http://license.coscl.org.cn/MulanPSL2
|
|
1535
|
-
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
1536
|
-
// See the Mulan PSL v2 for more details.
|
|
1537
|
-
function parseComparatorString(range) {
|
|
1538
|
-
return pipe(// handle caret
|
|
1539
|
-
// ^ --> * (any, kinda silly)
|
|
1540
|
-
// ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0-0
|
|
1541
|
-
// ^2.0, ^2.0.x --> >=2.0.0 <3.0.0-0
|
|
1542
|
-
// ^1.2, ^1.2.x --> >=1.2.0 <2.0.0-0
|
|
1543
|
-
// ^1.2.3 --> >=1.2.3 <2.0.0-0
|
|
1544
|
-
// ^1.2.0 --> >=1.2.0 <2.0.0-0
|
|
1545
|
-
parseCarets, // handle tilde
|
|
1546
|
-
// ~, ~> --> * (any, kinda silly)
|
|
1547
|
-
// ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0-0
|
|
1548
|
-
// ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0-0
|
|
1549
|
-
// ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0-0
|
|
1550
|
-
// ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0-0
|
|
1551
|
-
// ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0-0
|
|
1552
|
-
parseTildes, parseXRanges, parseStar)(range);
|
|
1553
|
-
}
|
|
1554
|
-
function parseRange(range) {
|
|
1555
|
-
return pipe(// handle hyphenRange
|
|
1556
|
-
// `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
|
|
1557
|
-
parseHyphen, // handle trim comparator
|
|
1558
|
-
// `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
|
|
1559
|
-
parseComparatorTrim, // handle trim tilde
|
|
1560
|
-
// `~ 1.2.3` => `~1.2.3`
|
|
1561
|
-
parseTildeTrim, // handle trim caret
|
|
1562
|
-
// `^ 1.2.3` => `^1.2.3`
|
|
1563
|
-
parseCaretTrim)(range.trim()).split(/\s+/).join(' ');
|
|
1564
|
-
}
|
|
1565
|
-
function satisfy(version, range) {
|
|
1566
|
-
if (!version) {
|
|
1567
|
-
return false;
|
|
1568
|
-
}
|
|
1569
|
-
// Extract version details once
|
|
1570
|
-
const extractedVersion = extractComparator(version);
|
|
1571
|
-
if (!extractedVersion) {
|
|
1572
|
-
// If the version string is invalid, it can't satisfy any range
|
|
1573
|
-
return false;
|
|
1574
|
-
}
|
|
1575
|
-
const [, versionOperator, , versionMajor, versionMinor, versionPatch, versionPreRelease] = extractedVersion;
|
|
1576
|
-
const versionAtom = {
|
|
1577
|
-
operator: versionOperator,
|
|
1578
|
-
version: combineVersion(versionMajor, versionMinor, versionPatch, versionPreRelease),
|
|
1579
|
-
major: versionMajor,
|
|
1580
|
-
minor: versionMinor,
|
|
1581
|
-
patch: versionPatch,
|
|
1582
|
-
preRelease: versionPreRelease == null ? void 0 : versionPreRelease.split('.')
|
|
1583
|
-
};
|
|
1584
|
-
// Split the range by || to handle OR conditions
|
|
1585
|
-
const orRanges = range.split('||');
|
|
1586
|
-
for (const orRange of orRanges){
|
|
1587
|
-
const trimmedOrRange = orRange.trim();
|
|
1588
|
-
if (!trimmedOrRange) {
|
|
1589
|
-
// An empty range string signifies wildcard *, satisfy any valid version
|
|
1590
|
-
// (We already checked if the version itself is valid)
|
|
1591
|
-
return true;
|
|
1592
|
-
}
|
|
1593
|
-
// Handle simple wildcards explicitly before complex parsing
|
|
1594
|
-
if (trimmedOrRange === '*' || trimmedOrRange === 'x') {
|
|
1595
|
-
return true;
|
|
1596
|
-
}
|
|
1597
|
-
try {
|
|
1598
|
-
// Apply existing parsing logic to the current OR sub-range
|
|
1599
|
-
const parsedSubRange = parseRange(trimmedOrRange); // Handles hyphens, trims etc.
|
|
1600
|
-
// Check if the result of initial parsing is empty, which can happen
|
|
1601
|
-
// for some wildcard cases handled by parseRange/parseComparatorString.
|
|
1602
|
-
// E.g. `parseStar` used in `parseComparatorString` returns ''.
|
|
1603
|
-
if (!parsedSubRange.trim()) {
|
|
1604
|
-
// If parsing results in empty string, treat as wildcard match
|
|
1605
|
-
return true;
|
|
1606
|
-
}
|
|
1607
|
-
const parsedComparatorString = parsedSubRange.split(' ').map((rangeVersion)=>parseComparatorString(rangeVersion)) // Expands ^, ~
|
|
1608
|
-
.join(' ');
|
|
1609
|
-
// Check again if the comparator string became empty after specific parsing like ^ or ~
|
|
1610
|
-
if (!parsedComparatorString.trim()) {
|
|
1611
|
-
return true;
|
|
1612
|
-
}
|
|
1613
|
-
// Split the sub-range by space for implicit AND conditions
|
|
1614
|
-
const comparators = parsedComparatorString.split(/\s+/).map((comparator)=>parseGTE0(comparator))// Filter out empty strings that might result from multiple spaces
|
|
1615
|
-
.filter(Boolean);
|
|
1616
|
-
// If a sub-range becomes empty after parsing (e.g., invalid characters),
|
|
1617
|
-
// it cannot be satisfied. This check might be redundant now but kept for safety.
|
|
1618
|
-
if (comparators.length === 0) {
|
|
1619
|
-
continue;
|
|
1620
|
-
}
|
|
1621
|
-
let subRangeSatisfied = true;
|
|
1622
|
-
for (const comparator of comparators){
|
|
1623
|
-
const extractedComparator = extractComparator(comparator);
|
|
1624
|
-
// If any part of the AND sub-range is invalid, the sub-range is not satisfied
|
|
1625
|
-
if (!extractedComparator) {
|
|
1626
|
-
subRangeSatisfied = false;
|
|
1627
|
-
break;
|
|
1628
|
-
}
|
|
1629
|
-
const [, rangeOperator, , rangeMajor, rangeMinor, rangePatch, rangePreRelease] = extractedComparator;
|
|
1630
|
-
const rangeAtom = {
|
|
1631
|
-
operator: rangeOperator,
|
|
1632
|
-
version: combineVersion(rangeMajor, rangeMinor, rangePatch, rangePreRelease),
|
|
1633
|
-
major: rangeMajor,
|
|
1634
|
-
minor: rangeMinor,
|
|
1635
|
-
patch: rangePatch,
|
|
1636
|
-
preRelease: rangePreRelease == null ? void 0 : rangePreRelease.split('.')
|
|
1637
|
-
};
|
|
1638
|
-
// Check if the version satisfies this specific comparator in the AND chain
|
|
1639
|
-
if (!compare(rangeAtom, versionAtom)) {
|
|
1640
|
-
subRangeSatisfied = false; // This part of the AND condition failed
|
|
1641
|
-
break; // No need to check further comparators in this sub-range
|
|
1642
|
-
}
|
|
1643
|
-
}
|
|
1644
|
-
// If all AND conditions within this OR sub-range were met, the overall range is satisfied
|
|
1645
|
-
if (subRangeSatisfied) {
|
|
1646
|
-
return true;
|
|
1647
|
-
}
|
|
1648
|
-
} catch (e) {
|
|
1649
|
-
// Log error and treat this sub-range as unsatisfied
|
|
1650
|
-
console.error(`[semver] Error processing range part "${trimmedOrRange}":`, e);
|
|
1651
|
-
continue;
|
|
1652
|
-
}
|
|
1653
|
-
}
|
|
1654
|
-
// If none of the OR sub-ranges were satisfied
|
|
1655
|
-
return false;
|
|
1656
|
-
}
|
|
1657
|
-
|
|
1658
|
-
function formatShare(shareArgs, from, name, shareStrategy) {
|
|
1659
|
-
let get;
|
|
1660
|
-
if ('get' in shareArgs) {
|
|
1661
|
-
// eslint-disable-next-line prefer-destructuring
|
|
1662
|
-
get = shareArgs.get;
|
|
1663
|
-
} else if ('lib' in shareArgs) {
|
|
1664
|
-
get = ()=>Promise.resolve(shareArgs.lib);
|
|
1665
|
-
} else {
|
|
1666
|
-
get = ()=>Promise.resolve(()=>{
|
|
1667
|
-
throw new Error(`Can not get shared '${name}'!`);
|
|
1668
|
-
});
|
|
1669
|
-
}
|
|
1670
|
-
var _shareArgs_version, _shareArgs_scope, _shareArgs_strategy;
|
|
1671
|
-
return polyfills._extends({
|
|
1672
|
-
deps: [],
|
|
1673
|
-
useIn: [],
|
|
1674
|
-
from,
|
|
1675
|
-
loading: null
|
|
1676
|
-
}, shareArgs, {
|
|
1677
|
-
shareConfig: polyfills._extends({
|
|
1678
|
-
requiredVersion: `^${shareArgs.version}`,
|
|
1679
|
-
singleton: false,
|
|
1680
|
-
eager: false,
|
|
1681
|
-
strictVersion: false
|
|
1682
|
-
}, shareArgs.shareConfig),
|
|
1683
|
-
get,
|
|
1684
|
-
loaded: (shareArgs == null ? void 0 : shareArgs.loaded) || 'lib' in shareArgs ? true : undefined,
|
|
1685
|
-
version: (_shareArgs_version = shareArgs.version) != null ? _shareArgs_version : '0',
|
|
1686
|
-
scope: Array.isArray(shareArgs.scope) ? shareArgs.scope : [
|
|
1687
|
-
(_shareArgs_scope = shareArgs.scope) != null ? _shareArgs_scope : 'default'
|
|
1688
|
-
],
|
|
1689
|
-
strategy: ((_shareArgs_strategy = shareArgs.strategy) != null ? _shareArgs_strategy : shareStrategy) || 'version-first'
|
|
1690
|
-
});
|
|
1691
|
-
}
|
|
1692
|
-
function formatShareConfigs(globalOptions, userOptions) {
|
|
1693
|
-
const shareArgs = userOptions.shared || {};
|
|
1694
|
-
const from = userOptions.name;
|
|
1695
|
-
const shareInfos = Object.keys(shareArgs).reduce((res, pkgName)=>{
|
|
1696
|
-
const arrayShareArgs = arrayOptions(shareArgs[pkgName]);
|
|
1697
|
-
res[pkgName] = res[pkgName] || [];
|
|
1698
|
-
arrayShareArgs.forEach((shareConfig)=>{
|
|
1699
|
-
res[pkgName].push(formatShare(shareConfig, from, pkgName, userOptions.shareStrategy));
|
|
1700
|
-
});
|
|
1701
|
-
return res;
|
|
1702
|
-
}, {});
|
|
1703
|
-
const shared = polyfills._extends({}, globalOptions.shared);
|
|
1704
|
-
Object.keys(shareInfos).forEach((shareKey)=>{
|
|
1705
|
-
if (!shared[shareKey]) {
|
|
1706
|
-
shared[shareKey] = shareInfos[shareKey];
|
|
1707
|
-
} else {
|
|
1708
|
-
shareInfos[shareKey].forEach((newUserSharedOptions)=>{
|
|
1709
|
-
const isSameVersion = shared[shareKey].find((sharedVal)=>sharedVal.version === newUserSharedOptions.version);
|
|
1710
|
-
if (!isSameVersion) {
|
|
1711
|
-
shared[shareKey].push(newUserSharedOptions);
|
|
1712
|
-
}
|
|
1713
|
-
});
|
|
1714
|
-
}
|
|
1715
|
-
});
|
|
1716
|
-
return {
|
|
1717
|
-
shared,
|
|
1718
|
-
shareInfos
|
|
1719
|
-
};
|
|
1720
|
-
}
|
|
1721
|
-
function versionLt(a, b) {
|
|
1722
|
-
const transformInvalidVersion = (version)=>{
|
|
1723
|
-
const isNumberVersion = !Number.isNaN(Number(version));
|
|
1724
|
-
if (isNumberVersion) {
|
|
1725
|
-
const splitArr = version.split('.');
|
|
1726
|
-
let validVersion = version;
|
|
1727
|
-
for(let i = 0; i < 3 - splitArr.length; i++){
|
|
1728
|
-
validVersion += '.0';
|
|
1729
|
-
}
|
|
1730
|
-
return validVersion;
|
|
1731
|
-
}
|
|
1732
|
-
return version;
|
|
1733
|
-
};
|
|
1734
|
-
if (satisfy(transformInvalidVersion(a), `<=${transformInvalidVersion(b)}`)) {
|
|
1735
|
-
return true;
|
|
1736
|
-
} else {
|
|
1737
|
-
return false;
|
|
1738
|
-
}
|
|
1739
|
-
}
|
|
1740
|
-
const findVersion = (shareVersionMap, cb)=>{
|
|
1741
|
-
const callback = cb || function(prev, cur) {
|
|
1742
|
-
return versionLt(prev, cur);
|
|
1743
|
-
};
|
|
1744
|
-
return Object.keys(shareVersionMap).reduce((prev, cur)=>{
|
|
1745
|
-
if (!prev) {
|
|
1746
|
-
return cur;
|
|
1747
|
-
}
|
|
1748
|
-
if (callback(prev, cur)) {
|
|
1749
|
-
return cur;
|
|
1750
|
-
}
|
|
1751
|
-
// default version is '0' https://github.com/webpack/webpack/blob/main/lib/sharing/ProvideSharedModule.js#L136
|
|
1752
|
-
if (prev === '0') {
|
|
1753
|
-
return cur;
|
|
1754
|
-
}
|
|
1755
|
-
return prev;
|
|
1756
|
-
}, 0);
|
|
1757
|
-
};
|
|
1758
|
-
const isLoaded = (shared)=>{
|
|
1759
|
-
return Boolean(shared.loaded) || typeof shared.lib === 'function';
|
|
1760
|
-
};
|
|
1761
|
-
const isLoading = (shared)=>{
|
|
1762
|
-
return Boolean(shared.loading);
|
|
1763
|
-
};
|
|
1764
|
-
function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) {
|
|
1765
|
-
const versions = shareScopeMap[scope][pkgName];
|
|
1766
|
-
const callback = function(prev, cur) {
|
|
1767
|
-
return !isLoaded(versions[prev]) && versionLt(prev, cur);
|
|
1768
|
-
};
|
|
1769
|
-
return findVersion(shareScopeMap[scope][pkgName], callback);
|
|
1770
|
-
}
|
|
1771
|
-
function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
|
|
1772
|
-
const versions = shareScopeMap[scope][pkgName];
|
|
1773
|
-
const callback = function(prev, cur) {
|
|
1774
|
-
const isLoadingOrLoaded = (shared)=>{
|
|
1775
|
-
return isLoaded(shared) || isLoading(shared);
|
|
1776
|
-
};
|
|
1777
|
-
if (isLoadingOrLoaded(versions[cur])) {
|
|
1778
|
-
if (isLoadingOrLoaded(versions[prev])) {
|
|
1779
|
-
return Boolean(versionLt(prev, cur));
|
|
1780
|
-
} else {
|
|
1781
|
-
return true;
|
|
1782
|
-
}
|
|
1783
|
-
}
|
|
1784
|
-
if (isLoadingOrLoaded(versions[prev])) {
|
|
1785
|
-
return false;
|
|
1786
|
-
}
|
|
1787
|
-
return versionLt(prev, cur);
|
|
1788
|
-
};
|
|
1789
|
-
return findVersion(shareScopeMap[scope][pkgName], callback);
|
|
1790
|
-
}
|
|
1791
|
-
function getFindShareFunction(strategy) {
|
|
1792
|
-
if (strategy === 'loaded-first') {
|
|
1793
|
-
return findSingletonVersionOrderByLoaded;
|
|
1794
|
-
}
|
|
1795
|
-
return findSingletonVersionOrderByVersion;
|
|
1796
|
-
}
|
|
1797
|
-
function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare) {
|
|
1798
|
-
if (!localShareScopeMap) {
|
|
1799
|
-
return;
|
|
1800
|
-
}
|
|
1801
|
-
const { shareConfig, scope = DEFAULT_SCOPE, strategy } = shareInfo;
|
|
1802
|
-
const scopes = Array.isArray(scope) ? scope : [
|
|
1803
|
-
scope
|
|
1804
|
-
];
|
|
1805
|
-
for (const sc of scopes){
|
|
1806
|
-
if (shareConfig && localShareScopeMap[sc] && localShareScopeMap[sc][pkgName]) {
|
|
1807
|
-
const { requiredVersion } = shareConfig;
|
|
1808
|
-
const findShareFunction = getFindShareFunction(strategy);
|
|
1809
|
-
const maxOrSingletonVersion = findShareFunction(localShareScopeMap, sc, pkgName);
|
|
1810
|
-
//@ts-ignore
|
|
1811
|
-
const defaultResolver = ()=>{
|
|
1812
|
-
if (shareConfig.singleton) {
|
|
1813
|
-
if (typeof requiredVersion === 'string' && !satisfy(maxOrSingletonVersion, requiredVersion)) {
|
|
1814
|
-
const msg = `Version ${maxOrSingletonVersion} from ${maxOrSingletonVersion && localShareScopeMap[sc][pkgName][maxOrSingletonVersion].from} of shared singleton module ${pkgName} does not satisfy the requirement of ${shareInfo.from} which needs ${requiredVersion})`;
|
|
1815
|
-
if (shareConfig.strictVersion) {
|
|
1816
|
-
error(msg);
|
|
1817
|
-
} else {
|
|
1818
|
-
warn(msg);
|
|
1819
|
-
}
|
|
1820
|
-
}
|
|
1821
|
-
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
|
|
1822
|
-
} else {
|
|
1823
|
-
if (requiredVersion === false || requiredVersion === '*') {
|
|
1824
|
-
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
|
|
1825
|
-
}
|
|
1826
|
-
if (satisfy(maxOrSingletonVersion, requiredVersion)) {
|
|
1827
|
-
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
|
|
1828
|
-
}
|
|
1829
|
-
for (const [versionKey, versionValue] of Object.entries(localShareScopeMap[sc][pkgName])){
|
|
1830
|
-
if (satisfy(versionKey, requiredVersion)) {
|
|
1831
|
-
return versionValue;
|
|
1832
|
-
}
|
|
1833
|
-
}
|
|
1834
|
-
}
|
|
1835
|
-
};
|
|
1836
|
-
const params = {
|
|
1837
|
-
shareScopeMap: localShareScopeMap,
|
|
1838
|
-
scope: sc,
|
|
1839
|
-
pkgName,
|
|
1840
|
-
version: maxOrSingletonVersion,
|
|
1841
|
-
GlobalFederation: Global.__FEDERATION__,
|
|
1842
|
-
resolver: defaultResolver
|
|
1843
|
-
};
|
|
1844
|
-
const resolveShared = resolveShare.emit(params) || params;
|
|
1845
|
-
return resolveShared.resolver();
|
|
1846
|
-
}
|
|
1847
|
-
}
|
|
1848
|
-
}
|
|
1849
|
-
function getGlobalShareScope() {
|
|
1850
|
-
return Global.__FEDERATION__.__SHARE__;
|
|
1851
|
-
}
|
|
1852
|
-
function getTargetSharedOptions(options) {
|
|
1853
|
-
const { pkgName, extraOptions, shareInfos } = options;
|
|
1854
|
-
const defaultResolver = (sharedOptions)=>{
|
|
1855
|
-
if (!sharedOptions) {
|
|
1856
|
-
return undefined;
|
|
1857
|
-
}
|
|
1858
|
-
const shareVersionMap = {};
|
|
1859
|
-
sharedOptions.forEach((shared)=>{
|
|
1860
|
-
shareVersionMap[shared.version] = shared;
|
|
1861
|
-
});
|
|
1862
|
-
const callback = function(prev, cur) {
|
|
1863
|
-
return !isLoaded(shareVersionMap[prev]) && versionLt(prev, cur);
|
|
1864
|
-
};
|
|
1865
|
-
const maxVersion = findVersion(shareVersionMap, callback);
|
|
1866
|
-
return shareVersionMap[maxVersion];
|
|
1867
|
-
};
|
|
1868
|
-
var _extraOptions_resolver;
|
|
1869
|
-
const resolver = (_extraOptions_resolver = extraOptions == null ? void 0 : extraOptions.resolver) != null ? _extraOptions_resolver : defaultResolver;
|
|
1870
|
-
return Object.assign({}, resolver(shareInfos[pkgName]), extraOptions == null ? void 0 : extraOptions.customShareInfo);
|
|
1871
|
-
}
|
|
1872
|
-
|
|
1873
|
-
function getBuilderId$1() {
|
|
1874
|
-
//@ts-ignore
|
|
1875
|
-
return typeof FEDERATION_BUILD_IDENTIFIER !== 'undefined' ? FEDERATION_BUILD_IDENTIFIER : '';
|
|
1876
|
-
}
|
|
1877
|
-
|
|
1878
|
-
// Function to match a remote with its name and expose
|
|
1879
|
-
// id: pkgName(@federation/app1) + expose(button) = @federation/app1/button
|
|
1880
|
-
// id: alias(app1) + expose(button) = app1/button
|
|
1881
|
-
// id: alias(app1/utils) + expose(loadash/sort) = app1/utils/loadash/sort
|
|
1882
|
-
function matchRemoteWithNameAndExpose(remotes, id) {
|
|
1883
|
-
for (const remote of remotes){
|
|
1884
|
-
// match pkgName
|
|
1885
|
-
const isNameMatched = id.startsWith(remote.name);
|
|
1886
|
-
let expose = id.replace(remote.name, '');
|
|
1887
|
-
if (isNameMatched) {
|
|
1888
|
-
if (expose.startsWith('/')) {
|
|
1889
|
-
const pkgNameOrAlias = remote.name;
|
|
1890
|
-
expose = `.${expose}`;
|
|
1891
|
-
return {
|
|
1892
|
-
pkgNameOrAlias,
|
|
1893
|
-
expose,
|
|
1894
|
-
remote
|
|
1895
|
-
};
|
|
1896
|
-
} else if (expose === '') {
|
|
1897
|
-
return {
|
|
1898
|
-
pkgNameOrAlias: remote.name,
|
|
1899
|
-
expose: '.',
|
|
1900
|
-
remote
|
|
1901
|
-
};
|
|
1902
|
-
}
|
|
1903
|
-
}
|
|
1904
|
-
// match alias
|
|
1905
|
-
const isAliasMatched = remote.alias && id.startsWith(remote.alias);
|
|
1906
|
-
let exposeWithAlias = remote.alias && id.replace(remote.alias, '');
|
|
1907
|
-
if (remote.alias && isAliasMatched) {
|
|
1908
|
-
if (exposeWithAlias && exposeWithAlias.startsWith('/')) {
|
|
1909
|
-
const pkgNameOrAlias = remote.alias;
|
|
1910
|
-
exposeWithAlias = `.${exposeWithAlias}`;
|
|
1911
|
-
return {
|
|
1912
|
-
pkgNameOrAlias,
|
|
1913
|
-
expose: exposeWithAlias,
|
|
1914
|
-
remote
|
|
1915
|
-
};
|
|
1916
|
-
} else if (exposeWithAlias === '') {
|
|
1917
|
-
return {
|
|
1918
|
-
pkgNameOrAlias: remote.alias,
|
|
1919
|
-
expose: '.',
|
|
1920
|
-
remote
|
|
1921
|
-
};
|
|
1922
|
-
}
|
|
1923
|
-
}
|
|
1924
|
-
}
|
|
1925
|
-
return;
|
|
1926
|
-
}
|
|
1927
|
-
// Function to match a remote with its name or alias
|
|
1928
|
-
function matchRemote(remotes, nameOrAlias) {
|
|
1929
|
-
for (const remote of remotes){
|
|
1930
|
-
const isNameMatched = nameOrAlias === remote.name;
|
|
1931
|
-
if (isNameMatched) {
|
|
1932
|
-
return remote;
|
|
1933
|
-
}
|
|
1934
|
-
const isAliasMatched = remote.alias && nameOrAlias === remote.alias;
|
|
1935
|
-
if (isAliasMatched) {
|
|
1936
|
-
return remote;
|
|
1937
|
-
}
|
|
1938
|
-
}
|
|
1939
|
-
return;
|
|
1940
|
-
}
|
|
1941
|
-
|
|
1942
|
-
function registerPlugins$1(plugins, instance) {
|
|
1943
|
-
const globalPlugins = getGlobalHostPlugins();
|
|
1944
|
-
const hookInstances = [
|
|
1945
|
-
instance.hooks,
|
|
1946
|
-
instance.remoteHandler.hooks,
|
|
1947
|
-
instance.sharedHandler.hooks,
|
|
1948
|
-
instance.snapshotHandler.hooks,
|
|
1949
|
-
instance.loaderHook,
|
|
1950
|
-
instance.bridgeHook
|
|
1951
|
-
];
|
|
1952
|
-
// Incorporate global plugins
|
|
1953
|
-
if (globalPlugins.length > 0) {
|
|
1954
|
-
globalPlugins.forEach((plugin)=>{
|
|
1955
|
-
if (plugins == null ? void 0 : plugins.find((item)=>item.name !== plugin.name)) {
|
|
1956
|
-
plugins.push(plugin);
|
|
1957
|
-
}
|
|
1958
|
-
});
|
|
1959
|
-
}
|
|
1960
|
-
if (plugins && plugins.length > 0) {
|
|
1961
|
-
plugins.forEach((plugin)=>{
|
|
1962
|
-
hookInstances.forEach((hookInstance)=>{
|
|
1963
|
-
hookInstance.applyPlugin(plugin, instance);
|
|
1964
|
-
});
|
|
1965
|
-
});
|
|
1966
|
-
}
|
|
1967
|
-
return plugins;
|
|
1968
|
-
}
|
|
1969
|
-
|
|
1970
|
-
const importCallback = '.then(callbacks[0]).catch(callbacks[1])';
|
|
1971
|
-
async function loadEsmEntry({ entry, remoteEntryExports }) {
|
|
1972
|
-
return new Promise((resolve, reject)=>{
|
|
1973
|
-
try {
|
|
1974
|
-
if (!remoteEntryExports) {
|
|
1975
|
-
if (typeof FEDERATION_ALLOW_NEW_FUNCTION !== 'undefined') {
|
|
1976
|
-
new Function('callbacks', `import("${entry}")${importCallback}`)([
|
|
1977
|
-
resolve,
|
|
1978
|
-
reject
|
|
1979
|
-
]);
|
|
1980
|
-
} else {
|
|
1981
|
-
import(/* webpackIgnore: true */ /* @vite-ignore */ entry).then(resolve).catch(reject);
|
|
1982
|
-
}
|
|
1983
|
-
} else {
|
|
1984
|
-
resolve(remoteEntryExports);
|
|
1985
|
-
}
|
|
1986
|
-
} catch (e) {
|
|
1987
|
-
reject(e);
|
|
1988
|
-
}
|
|
1989
|
-
});
|
|
1990
|
-
}
|
|
1991
|
-
async function loadSystemJsEntry({ entry, remoteEntryExports }) {
|
|
1992
|
-
return new Promise((resolve, reject)=>{
|
|
1993
|
-
try {
|
|
1994
|
-
if (!remoteEntryExports) {
|
|
1995
|
-
//@ts-ignore
|
|
1996
|
-
if (typeof __system_context__ === 'undefined') {
|
|
1997
|
-
//@ts-ignore
|
|
1998
|
-
System.import(entry).then(resolve).catch(reject);
|
|
1999
|
-
} else {
|
|
2000
|
-
new Function('callbacks', `System.import("${entry}")${importCallback}`)([
|
|
2001
|
-
resolve,
|
|
2002
|
-
reject
|
|
2003
|
-
]);
|
|
2004
|
-
}
|
|
2005
|
-
} else {
|
|
2006
|
-
resolve(remoteEntryExports);
|
|
2007
|
-
}
|
|
2008
|
-
} catch (e) {
|
|
2009
|
-
reject(e);
|
|
2010
|
-
}
|
|
2011
|
-
});
|
|
2012
|
-
}
|
|
2013
|
-
function handleRemoteEntryLoaded(name, globalName, entry) {
|
|
2014
|
-
const { remoteEntryKey, entryExports } = getRemoteEntryExports(name, globalName);
|
|
2015
|
-
assert(entryExports, errorCodes$1.getShortErrorMsg(errorCodes$1.RUNTIME_001, errorCodes$1.runtimeDescMap, {
|
|
2016
|
-
remoteName: name,
|
|
2017
|
-
remoteEntryUrl: entry,
|
|
2018
|
-
remoteEntryKey
|
|
2019
|
-
}));
|
|
2020
|
-
return entryExports;
|
|
2021
|
-
}
|
|
2022
|
-
async function loadEntryScript({ name, globalName, entry, loaderHook, getEntryUrl }) {
|
|
2023
|
-
const { entryExports: remoteEntryExports } = getRemoteEntryExports(name, globalName);
|
|
2024
|
-
if (remoteEntryExports) {
|
|
2025
|
-
return remoteEntryExports;
|
|
2026
|
-
}
|
|
2027
|
-
// if getEntryUrl is passed, use the getEntryUrl to get the entry url
|
|
2028
|
-
const url = getEntryUrl ? getEntryUrl(entry) : entry;
|
|
2029
|
-
return sdk.loadScript(url, {
|
|
2030
|
-
attrs: {},
|
|
2031
|
-
createScriptHook: (url, attrs)=>{
|
|
2032
|
-
const res = loaderHook.lifecycle.createScript.emit({
|
|
2033
|
-
url,
|
|
2034
|
-
attrs
|
|
2035
|
-
});
|
|
2036
|
-
if (!res) return;
|
|
2037
|
-
if (res instanceof HTMLScriptElement) {
|
|
2038
|
-
return res;
|
|
2039
|
-
}
|
|
2040
|
-
if ('script' in res || 'timeout' in res) {
|
|
2041
|
-
return res;
|
|
2042
|
-
}
|
|
2043
|
-
return;
|
|
2044
|
-
}
|
|
2045
|
-
}).then(()=>{
|
|
2046
|
-
return handleRemoteEntryLoaded(name, globalName, entry);
|
|
2047
|
-
}).catch((e)=>{
|
|
2048
|
-
assert(undefined, errorCodes$1.getShortErrorMsg(errorCodes$1.RUNTIME_008, errorCodes$1.runtimeDescMap, {
|
|
2049
|
-
remoteName: name,
|
|
2050
|
-
resourceUrl: entry
|
|
2051
|
-
}));
|
|
2052
|
-
throw e;
|
|
2053
|
-
});
|
|
2054
|
-
}
|
|
2055
|
-
async function loadEntryDom({ remoteInfo, remoteEntryExports, loaderHook, getEntryUrl }) {
|
|
2056
|
-
const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
|
|
2057
|
-
switch(type){
|
|
2058
|
-
case 'esm':
|
|
2059
|
-
case 'module':
|
|
2060
|
-
return loadEsmEntry({
|
|
2061
|
-
entry,
|
|
2062
|
-
remoteEntryExports
|
|
2063
|
-
});
|
|
2064
|
-
case 'system':
|
|
2065
|
-
return loadSystemJsEntry({
|
|
2066
|
-
entry,
|
|
2067
|
-
remoteEntryExports
|
|
2068
|
-
});
|
|
2069
|
-
default:
|
|
2070
|
-
return loadEntryScript({
|
|
2071
|
-
entry,
|
|
2072
|
-
globalName,
|
|
2073
|
-
name,
|
|
2074
|
-
loaderHook,
|
|
2075
|
-
getEntryUrl
|
|
2076
|
-
});
|
|
2077
|
-
}
|
|
2078
|
-
}
|
|
2079
|
-
async function loadEntryNode({ remoteInfo, loaderHook }) {
|
|
2080
|
-
const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
|
|
2081
|
-
const { entryExports: remoteEntryExports } = getRemoteEntryExports(name, globalName);
|
|
2082
|
-
if (remoteEntryExports) {
|
|
2083
|
-
return remoteEntryExports;
|
|
2084
|
-
}
|
|
2085
|
-
return sdk.loadScriptNode(entry, {
|
|
2086
|
-
attrs: {
|
|
2087
|
-
name,
|
|
2088
|
-
globalName,
|
|
2089
|
-
type
|
|
2090
|
-
},
|
|
2091
|
-
loaderHook: {
|
|
2092
|
-
createScriptHook: (url, attrs = {})=>{
|
|
2093
|
-
const res = loaderHook.lifecycle.createScript.emit({
|
|
2094
|
-
url,
|
|
2095
|
-
attrs
|
|
2096
|
-
});
|
|
2097
|
-
if (!res) return;
|
|
2098
|
-
if ('url' in res) {
|
|
2099
|
-
return res;
|
|
2100
|
-
}
|
|
2101
|
-
return;
|
|
2102
|
-
}
|
|
2103
|
-
}
|
|
2104
|
-
}).then(()=>{
|
|
2105
|
-
return handleRemoteEntryLoaded(name, globalName, entry);
|
|
2106
|
-
}).catch((e)=>{
|
|
2107
|
-
throw e;
|
|
2108
|
-
});
|
|
2109
|
-
}
|
|
2110
|
-
function getRemoteEntryUniqueKey(remoteInfo) {
|
|
2111
|
-
const { entry, name } = remoteInfo;
|
|
2112
|
-
return sdk.composeKeyWithSeparator(name, entry);
|
|
2113
|
-
}
|
|
2114
|
-
async function getRemoteEntry(params) {
|
|
2115
|
-
const { origin, remoteEntryExports, remoteInfo, getEntryUrl } = params;
|
|
2116
|
-
const uniqueKey = getRemoteEntryUniqueKey(remoteInfo);
|
|
2117
|
-
if (remoteEntryExports) {
|
|
2118
|
-
return remoteEntryExports;
|
|
2119
|
-
}
|
|
2120
|
-
if (!globalLoading[uniqueKey]) {
|
|
2121
|
-
const loadEntryHook = origin.remoteHandler.hooks.lifecycle.loadEntry;
|
|
2122
|
-
const loaderHook = origin.loaderHook;
|
|
2123
|
-
globalLoading[uniqueKey] = loadEntryHook.emit({
|
|
2124
|
-
loaderHook,
|
|
2125
|
-
remoteInfo,
|
|
2126
|
-
remoteEntryExports
|
|
2127
|
-
}).then((res)=>{
|
|
2128
|
-
if (res) {
|
|
2129
|
-
return res;
|
|
2130
|
-
}
|
|
2131
|
-
// Use ENV_TARGET if defined, otherwise fallback to isBrowserEnv, must keep this
|
|
2132
|
-
const isWebEnvironment = typeof ENV_TARGET !== 'undefined' ? ENV_TARGET === 'web' : sdk.isBrowserEnv();
|
|
2133
|
-
return isWebEnvironment ? loadEntryDom({
|
|
2134
|
-
remoteInfo,
|
|
2135
|
-
remoteEntryExports,
|
|
2136
|
-
loaderHook,
|
|
2137
|
-
getEntryUrl
|
|
2138
|
-
}) : loadEntryNode({
|
|
2139
|
-
remoteInfo,
|
|
2140
|
-
loaderHook
|
|
2141
|
-
});
|
|
2142
|
-
});
|
|
2143
|
-
}
|
|
2144
|
-
return globalLoading[uniqueKey];
|
|
2145
|
-
}
|
|
2146
|
-
function getRemoteInfo(remote) {
|
|
2147
|
-
return polyfills._extends({}, remote, {
|
|
2148
|
-
entry: 'entry' in remote ? remote.entry : '',
|
|
2149
|
-
type: remote.type || DEFAULT_REMOTE_TYPE,
|
|
2150
|
-
entryGlobalName: remote.entryGlobalName || remote.name,
|
|
2151
|
-
shareScope: remote.shareScope || DEFAULT_SCOPE
|
|
2152
|
-
});
|
|
2153
|
-
}
|
|
2154
|
-
|
|
2155
|
-
function defaultPreloadArgs(preloadConfig) {
|
|
2156
|
-
return polyfills._extends({
|
|
2157
|
-
resourceCategory: 'sync',
|
|
2158
|
-
share: true,
|
|
2159
|
-
depsRemote: true,
|
|
2160
|
-
prefetchInterface: false
|
|
2161
|
-
}, preloadConfig);
|
|
2162
|
-
}
|
|
2163
|
-
function formatPreloadArgs(remotes, preloadArgs) {
|
|
2164
|
-
return preloadArgs.map((args)=>{
|
|
2165
|
-
const remoteInfo = matchRemote(remotes, args.nameOrAlias);
|
|
2166
|
-
assert(remoteInfo, `Unable to preload ${args.nameOrAlias} as it is not included in ${!remoteInfo && sdk.safeToString({
|
|
2167
|
-
remoteInfo,
|
|
2168
|
-
remotes
|
|
2169
|
-
})}`);
|
|
2170
|
-
return {
|
|
2171
|
-
remote: remoteInfo,
|
|
2172
|
-
preloadConfig: defaultPreloadArgs(args)
|
|
2173
|
-
};
|
|
2174
|
-
});
|
|
2175
|
-
}
|
|
2176
|
-
function normalizePreloadExposes(exposes) {
|
|
2177
|
-
if (!exposes) {
|
|
2178
|
-
return [];
|
|
2179
|
-
}
|
|
2180
|
-
return exposes.map((expose)=>{
|
|
2181
|
-
if (expose === '.') {
|
|
2182
|
-
return expose;
|
|
2183
|
-
}
|
|
2184
|
-
if (expose.startsWith('./')) {
|
|
2185
|
-
return expose.replace('./', '');
|
|
2186
|
-
}
|
|
2187
|
-
return expose;
|
|
2188
|
-
});
|
|
2189
|
-
}
|
|
2190
|
-
function preloadAssets(remoteInfo, host, assets, // It is used to distinguish preload from load remote parallel loading
|
|
2191
|
-
useLinkPreload = true) {
|
|
2192
|
-
const { cssAssets, jsAssetsWithoutEntry, entryAssets } = assets;
|
|
2193
|
-
if (host.options.inBrowser) {
|
|
2194
|
-
entryAssets.forEach((asset)=>{
|
|
2195
|
-
const { moduleInfo } = asset;
|
|
2196
|
-
const module = host.moduleCache.get(remoteInfo.name);
|
|
2197
|
-
if (module) {
|
|
2198
|
-
getRemoteEntry({
|
|
2199
|
-
origin: host,
|
|
2200
|
-
remoteInfo: moduleInfo,
|
|
2201
|
-
remoteEntryExports: module.remoteEntryExports
|
|
2202
|
-
});
|
|
2203
|
-
} else {
|
|
2204
|
-
getRemoteEntry({
|
|
2205
|
-
origin: host,
|
|
2206
|
-
remoteInfo: moduleInfo,
|
|
2207
|
-
remoteEntryExports: undefined
|
|
2208
|
-
});
|
|
2209
|
-
}
|
|
2210
|
-
});
|
|
2211
|
-
if (useLinkPreload) {
|
|
2212
|
-
const defaultAttrs = {
|
|
2213
|
-
rel: 'preload',
|
|
2214
|
-
as: 'style'
|
|
2215
|
-
};
|
|
2216
|
-
cssAssets.forEach((cssUrl)=>{
|
|
2217
|
-
const { link: cssEl, needAttach } = sdk.createLink({
|
|
2218
|
-
url: cssUrl,
|
|
2219
|
-
cb: ()=>{
|
|
2220
|
-
// noop
|
|
2221
|
-
},
|
|
2222
|
-
attrs: defaultAttrs,
|
|
2223
|
-
createLinkHook: (url, attrs)=>{
|
|
2224
|
-
const res = host.loaderHook.lifecycle.createLink.emit({
|
|
2225
|
-
url,
|
|
2226
|
-
attrs
|
|
2227
|
-
});
|
|
2228
|
-
if (res instanceof HTMLLinkElement) {
|
|
2229
|
-
return res;
|
|
2230
|
-
}
|
|
2231
|
-
return;
|
|
2232
|
-
}
|
|
2233
|
-
});
|
|
2234
|
-
needAttach && document.head.appendChild(cssEl);
|
|
2235
|
-
});
|
|
2236
|
-
} else {
|
|
2237
|
-
const defaultAttrs = {
|
|
2238
|
-
rel: 'stylesheet',
|
|
2239
|
-
type: 'text/css'
|
|
2240
|
-
};
|
|
2241
|
-
cssAssets.forEach((cssUrl)=>{
|
|
2242
|
-
const { link: cssEl, needAttach } = sdk.createLink({
|
|
2243
|
-
url: cssUrl,
|
|
2244
|
-
cb: ()=>{
|
|
2245
|
-
// noop
|
|
2246
|
-
},
|
|
2247
|
-
attrs: defaultAttrs,
|
|
2248
|
-
createLinkHook: (url, attrs)=>{
|
|
2249
|
-
const res = host.loaderHook.lifecycle.createLink.emit({
|
|
2250
|
-
url,
|
|
2251
|
-
attrs
|
|
2252
|
-
});
|
|
2253
|
-
if (res instanceof HTMLLinkElement) {
|
|
2254
|
-
return res;
|
|
2255
|
-
}
|
|
2256
|
-
return;
|
|
2257
|
-
},
|
|
2258
|
-
needDeleteLink: false
|
|
2259
|
-
});
|
|
2260
|
-
needAttach && document.head.appendChild(cssEl);
|
|
2261
|
-
});
|
|
2262
|
-
}
|
|
2263
|
-
if (useLinkPreload) {
|
|
2264
|
-
const defaultAttrs = {
|
|
2265
|
-
rel: 'preload',
|
|
2266
|
-
as: 'script'
|
|
2267
|
-
};
|
|
2268
|
-
jsAssetsWithoutEntry.forEach((jsUrl)=>{
|
|
2269
|
-
const { link: linkEl, needAttach } = sdk.createLink({
|
|
2270
|
-
url: jsUrl,
|
|
2271
|
-
cb: ()=>{
|
|
2272
|
-
// noop
|
|
2273
|
-
},
|
|
2274
|
-
attrs: defaultAttrs,
|
|
2275
|
-
createLinkHook: (url, attrs)=>{
|
|
2276
|
-
const res = host.loaderHook.lifecycle.createLink.emit({
|
|
2277
|
-
url,
|
|
2278
|
-
attrs
|
|
2279
|
-
});
|
|
2280
|
-
if (res instanceof HTMLLinkElement) {
|
|
2281
|
-
return res;
|
|
2282
|
-
}
|
|
2283
|
-
return;
|
|
2284
|
-
}
|
|
2285
|
-
});
|
|
2286
|
-
needAttach && document.head.appendChild(linkEl);
|
|
2287
|
-
});
|
|
2288
|
-
} else {
|
|
2289
|
-
const defaultAttrs = {
|
|
2290
|
-
fetchpriority: 'high',
|
|
2291
|
-
type: (remoteInfo == null ? void 0 : remoteInfo.type) === 'module' ? 'module' : 'text/javascript'
|
|
2292
|
-
};
|
|
2293
|
-
jsAssetsWithoutEntry.forEach((jsUrl)=>{
|
|
2294
|
-
const { script: scriptEl, needAttach } = sdk.createScript({
|
|
2295
|
-
url: jsUrl,
|
|
2296
|
-
cb: ()=>{
|
|
2297
|
-
// noop
|
|
2298
|
-
},
|
|
2299
|
-
attrs: defaultAttrs,
|
|
2300
|
-
createScriptHook: (url, attrs)=>{
|
|
2301
|
-
const res = host.loaderHook.lifecycle.createScript.emit({
|
|
2302
|
-
url,
|
|
2303
|
-
attrs
|
|
2304
|
-
});
|
|
2305
|
-
if (res instanceof HTMLScriptElement) {
|
|
2306
|
-
return res;
|
|
2307
|
-
}
|
|
2308
|
-
return;
|
|
2309
|
-
},
|
|
2310
|
-
needDeleteScript: true
|
|
2311
|
-
});
|
|
2312
|
-
needAttach && document.head.appendChild(scriptEl);
|
|
2313
|
-
});
|
|
2314
|
-
}
|
|
2315
|
-
}
|
|
2316
|
-
}
|
|
2317
|
-
|
|
2318
|
-
const ShareUtils = {
|
|
2319
|
-
getRegisteredShare,
|
|
2320
|
-
getGlobalShareScope
|
|
2321
|
-
};
|
|
2322
|
-
const GlobalUtils = {
|
|
2323
|
-
Global,
|
|
2324
|
-
nativeGlobal,
|
|
2325
|
-
resetFederationGlobalInfo,
|
|
2326
|
-
setGlobalFederationInstance,
|
|
2327
|
-
getGlobalFederationConstructor,
|
|
2328
|
-
setGlobalFederationConstructor,
|
|
2329
|
-
getInfoWithoutType,
|
|
2330
|
-
getGlobalSnapshot,
|
|
2331
|
-
getTargetSnapshotInfoByModuleInfo,
|
|
2332
|
-
getGlobalSnapshotInfoByModuleInfo,
|
|
2333
|
-
setGlobalSnapshotInfoByModuleInfo,
|
|
2334
|
-
addGlobalSnapshot,
|
|
2335
|
-
getRemoteEntryExports,
|
|
2336
|
-
registerGlobalPlugins,
|
|
2337
|
-
getGlobalHostPlugins,
|
|
2338
|
-
getPreloaded,
|
|
2339
|
-
setPreloaded
|
|
2340
|
-
};
|
|
2341
|
-
var helpers = {
|
|
2342
|
-
global: GlobalUtils,
|
|
2343
|
-
share: ShareUtils,
|
|
2344
|
-
utils: {
|
|
2345
|
-
matchRemoteWithNameAndExpose,
|
|
2346
|
-
preloadAssets,
|
|
2347
|
-
getRemoteInfo
|
|
2348
|
-
}
|
|
2349
|
-
};
|
|
2350
|
-
|
|
2351
|
-
let Module = class Module {
|
|
2352
|
-
async getEntry() {
|
|
2353
|
-
if (this.remoteEntryExports) {
|
|
2354
|
-
return this.remoteEntryExports;
|
|
2355
|
-
}
|
|
2356
|
-
let remoteEntryExports;
|
|
2357
|
-
try {
|
|
2358
|
-
remoteEntryExports = await getRemoteEntry({
|
|
2359
|
-
origin: this.host,
|
|
2360
|
-
remoteInfo: this.remoteInfo,
|
|
2361
|
-
remoteEntryExports: this.remoteEntryExports
|
|
2362
|
-
});
|
|
2363
|
-
} catch (err) {
|
|
2364
|
-
const uniqueKey = getRemoteEntryUniqueKey(this.remoteInfo);
|
|
2365
|
-
// only when the error is RUNTIME_008 (script resource load failed) trigger loadEntryError.emit
|
|
2366
|
-
const isScriptLoadError = err instanceof Error && err.message.includes(errorCodes$1.RUNTIME_008);
|
|
2367
|
-
if (isScriptLoadError) {
|
|
2368
|
-
remoteEntryExports = await this.host.loaderHook.lifecycle.loadEntryError.emit({
|
|
2369
|
-
getRemoteEntry,
|
|
2370
|
-
origin: this.host,
|
|
2371
|
-
remoteInfo: this.remoteInfo,
|
|
2372
|
-
remoteEntryExports: this.remoteEntryExports,
|
|
2373
|
-
globalLoading,
|
|
2374
|
-
uniqueKey
|
|
2375
|
-
});
|
|
2376
|
-
} else {
|
|
2377
|
-
throw err;
|
|
2378
|
-
}
|
|
2379
|
-
}
|
|
2380
|
-
assert(remoteEntryExports, `remoteEntryExports is undefined \n ${sdk.safeToString(this.remoteInfo)}`);
|
|
2381
|
-
this.remoteEntryExports = remoteEntryExports;
|
|
2382
|
-
return this.remoteEntryExports;
|
|
2383
|
-
}
|
|
2384
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
2385
|
-
async get(id, expose, options, remoteSnapshot) {
|
|
2386
|
-
const { loadFactory = true } = options || {
|
|
2387
|
-
loadFactory: true
|
|
2388
|
-
};
|
|
2389
|
-
// Get remoteEntry.js
|
|
2390
|
-
const remoteEntryExports = await this.getEntry();
|
|
2391
|
-
if (!this.inited) {
|
|
2392
|
-
const localShareScopeMap = this.host.shareScopeMap;
|
|
2393
|
-
const shareScopeKeys = Array.isArray(this.remoteInfo.shareScope) ? this.remoteInfo.shareScope : [
|
|
2394
|
-
this.remoteInfo.shareScope
|
|
2395
|
-
];
|
|
2396
|
-
if (!shareScopeKeys.length) {
|
|
2397
|
-
shareScopeKeys.push('default');
|
|
2398
|
-
}
|
|
2399
|
-
shareScopeKeys.forEach((shareScopeKey)=>{
|
|
2400
|
-
if (!localShareScopeMap[shareScopeKey]) {
|
|
2401
|
-
localShareScopeMap[shareScopeKey] = {};
|
|
2402
|
-
}
|
|
2403
|
-
});
|
|
2404
|
-
// TODO: compate legacy init params, should use shareScopeMap if exist
|
|
2405
|
-
const shareScope = localShareScopeMap[shareScopeKeys[0]];
|
|
2406
|
-
const initScope = [];
|
|
2407
|
-
const remoteEntryInitOptions = {
|
|
2408
|
-
version: this.remoteInfo.version || '',
|
|
2409
|
-
shareScopeKeys: Array.isArray(this.remoteInfo.shareScope) ? shareScopeKeys : this.remoteInfo.shareScope || 'default'
|
|
2410
|
-
};
|
|
2411
|
-
// Help to find host instance
|
|
2412
|
-
Object.defineProperty(remoteEntryInitOptions, 'shareScopeMap', {
|
|
2413
|
-
value: localShareScopeMap,
|
|
2414
|
-
// remoteEntryInitOptions will be traversed and assigned during container init, ,so this attribute is not allowed to be traversed
|
|
2415
|
-
enumerable: false
|
|
2416
|
-
});
|
|
2417
|
-
const initContainerOptions = await this.host.hooks.lifecycle.beforeInitContainer.emit({
|
|
2418
|
-
shareScope,
|
|
2419
|
-
// @ts-ignore shareScopeMap will be set by Object.defineProperty
|
|
2420
|
-
remoteEntryInitOptions,
|
|
2421
|
-
initScope,
|
|
2422
|
-
remoteInfo: this.remoteInfo,
|
|
2423
|
-
origin: this.host
|
|
2424
|
-
});
|
|
2425
|
-
if (typeof (remoteEntryExports == null ? void 0 : remoteEntryExports.init) === 'undefined') {
|
|
2426
|
-
error(errorCodes$1.getShortErrorMsg(errorCodes$1.RUNTIME_002, errorCodes$1.runtimeDescMap, {
|
|
2427
|
-
hostName: this.host.name,
|
|
2428
|
-
remoteName: this.remoteInfo.name,
|
|
2429
|
-
remoteEntryUrl: this.remoteInfo.entry,
|
|
2430
|
-
remoteEntryKey: this.remoteInfo.entryGlobalName
|
|
2431
|
-
}));
|
|
2432
|
-
}
|
|
2433
|
-
await remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
|
|
2434
|
-
await this.host.hooks.lifecycle.initContainer.emit(polyfills._extends({}, initContainerOptions, {
|
|
2435
|
-
id,
|
|
2436
|
-
remoteSnapshot,
|
|
2437
|
-
remoteEntryExports
|
|
2438
|
-
}));
|
|
2439
|
-
}
|
|
2440
|
-
this.lib = remoteEntryExports;
|
|
2441
|
-
this.inited = true;
|
|
2442
|
-
let moduleFactory;
|
|
2443
|
-
moduleFactory = await this.host.loaderHook.lifecycle.getModuleFactory.emit({
|
|
2444
|
-
remoteEntryExports,
|
|
2445
|
-
expose,
|
|
2446
|
-
moduleInfo: this.remoteInfo
|
|
2447
|
-
});
|
|
2448
|
-
// get exposeGetter
|
|
2449
|
-
if (!moduleFactory) {
|
|
2450
|
-
moduleFactory = await remoteEntryExports.get(expose);
|
|
2451
|
-
}
|
|
2452
|
-
assert(moduleFactory, `${getFMId(this.remoteInfo)} remote don't export ${expose}.`);
|
|
2453
|
-
// keep symbol for module name always one format
|
|
2454
|
-
const symbolName = processModuleAlias(this.remoteInfo.name, expose);
|
|
2455
|
-
const wrapModuleFactory = this.wraperFactory(moduleFactory, symbolName);
|
|
2456
|
-
if (!loadFactory) {
|
|
2457
|
-
return wrapModuleFactory;
|
|
2458
|
-
}
|
|
2459
|
-
const exposeContent = await wrapModuleFactory();
|
|
2460
|
-
return exposeContent;
|
|
2461
|
-
}
|
|
2462
|
-
wraperFactory(moduleFactory, id) {
|
|
2463
|
-
function defineModuleId(res, id) {
|
|
2464
|
-
if (res && typeof res === 'object' && Object.isExtensible(res) && !Object.getOwnPropertyDescriptor(res, Symbol.for('mf_module_id'))) {
|
|
2465
|
-
Object.defineProperty(res, Symbol.for('mf_module_id'), {
|
|
2466
|
-
value: id,
|
|
2467
|
-
enumerable: false
|
|
2468
|
-
});
|
|
2469
|
-
}
|
|
2470
|
-
}
|
|
2471
|
-
if (moduleFactory instanceof Promise) {
|
|
2472
|
-
return async ()=>{
|
|
2473
|
-
const res = await moduleFactory();
|
|
2474
|
-
// This parameter is used for bridge debugging
|
|
2475
|
-
defineModuleId(res, id);
|
|
2476
|
-
return res;
|
|
2477
|
-
};
|
|
2478
|
-
} else {
|
|
2479
|
-
return ()=>{
|
|
2480
|
-
const res = moduleFactory();
|
|
2481
|
-
// This parameter is used for bridge debugging
|
|
2482
|
-
defineModuleId(res, id);
|
|
2483
|
-
return res;
|
|
2484
|
-
};
|
|
2485
|
-
}
|
|
2486
|
-
}
|
|
2487
|
-
constructor({ remoteInfo, host }){
|
|
2488
|
-
this.inited = false;
|
|
2489
|
-
this.lib = undefined;
|
|
2490
|
-
this.remoteInfo = remoteInfo;
|
|
2491
|
-
this.host = host;
|
|
2492
|
-
}
|
|
2493
|
-
};
|
|
2494
|
-
|
|
2495
|
-
class SyncHook {
|
|
2496
|
-
on(fn) {
|
|
2497
|
-
if (typeof fn === 'function') {
|
|
2498
|
-
this.listeners.add(fn);
|
|
2499
|
-
}
|
|
2500
|
-
}
|
|
2501
|
-
once(fn) {
|
|
2502
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
2503
|
-
const self = this;
|
|
2504
|
-
this.on(function wrapper(...args) {
|
|
2505
|
-
self.remove(wrapper);
|
|
2506
|
-
// eslint-disable-next-line prefer-spread
|
|
2507
|
-
return fn.apply(null, args);
|
|
2508
|
-
});
|
|
2509
|
-
}
|
|
2510
|
-
emit(...data) {
|
|
2511
|
-
let result;
|
|
2512
|
-
if (this.listeners.size > 0) {
|
|
2513
|
-
// eslint-disable-next-line prefer-spread
|
|
2514
|
-
this.listeners.forEach((fn)=>{
|
|
2515
|
-
result = fn(...data);
|
|
2516
|
-
});
|
|
2517
|
-
}
|
|
2518
|
-
return result;
|
|
2519
|
-
}
|
|
2520
|
-
remove(fn) {
|
|
2521
|
-
this.listeners.delete(fn);
|
|
2522
|
-
}
|
|
2523
|
-
removeAll() {
|
|
2524
|
-
this.listeners.clear();
|
|
2525
|
-
}
|
|
2526
|
-
constructor(type){
|
|
2527
|
-
this.type = '';
|
|
2528
|
-
this.listeners = new Set();
|
|
2529
|
-
if (type) {
|
|
2530
|
-
this.type = type;
|
|
2531
|
-
}
|
|
2532
|
-
}
|
|
2533
|
-
}
|
|
2534
|
-
|
|
2535
|
-
class AsyncHook extends SyncHook {
|
|
2536
|
-
emit(...data) {
|
|
2537
|
-
let result;
|
|
2538
|
-
const ls = Array.from(this.listeners);
|
|
2539
|
-
if (ls.length > 0) {
|
|
2540
|
-
let i = 0;
|
|
2541
|
-
const call = (prev)=>{
|
|
2542
|
-
if (prev === false) {
|
|
2543
|
-
return false; // Abort process
|
|
2544
|
-
} else if (i < ls.length) {
|
|
2545
|
-
return Promise.resolve(ls[i++].apply(null, data)).then(call);
|
|
2546
|
-
} else {
|
|
2547
|
-
return prev;
|
|
2548
|
-
}
|
|
2549
|
-
};
|
|
2550
|
-
result = call();
|
|
2551
|
-
}
|
|
2552
|
-
return Promise.resolve(result);
|
|
2553
|
-
}
|
|
2554
|
-
}
|
|
2555
|
-
|
|
2556
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
2557
|
-
function checkReturnData(originalData, returnedData) {
|
|
2558
|
-
if (!isObject(returnedData)) {
|
|
2559
|
-
return false;
|
|
2560
|
-
}
|
|
2561
|
-
if (originalData !== returnedData) {
|
|
2562
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
2563
|
-
for(const key in originalData){
|
|
2564
|
-
if (!(key in returnedData)) {
|
|
2565
|
-
return false;
|
|
2566
|
-
}
|
|
2567
|
-
}
|
|
2568
|
-
}
|
|
2569
|
-
return true;
|
|
2570
|
-
}
|
|
2571
|
-
class SyncWaterfallHook extends SyncHook {
|
|
2572
|
-
emit(data) {
|
|
2573
|
-
if (!isObject(data)) {
|
|
2574
|
-
error(`The data for the "${this.type}" hook should be an object.`);
|
|
2575
|
-
}
|
|
2576
|
-
for (const fn of this.listeners){
|
|
2577
|
-
try {
|
|
2578
|
-
const tempData = fn(data);
|
|
2579
|
-
if (checkReturnData(data, tempData)) {
|
|
2580
|
-
data = tempData;
|
|
2581
|
-
} else {
|
|
2582
|
-
this.onerror(`A plugin returned an unacceptable value for the "${this.type}" type.`);
|
|
2583
|
-
break;
|
|
2584
|
-
}
|
|
2585
|
-
} catch (e) {
|
|
2586
|
-
warn(e);
|
|
2587
|
-
this.onerror(e);
|
|
2588
|
-
}
|
|
2589
|
-
}
|
|
2590
|
-
return data;
|
|
2591
|
-
}
|
|
2592
|
-
constructor(type){
|
|
2593
|
-
super();
|
|
2594
|
-
this.onerror = error;
|
|
2595
|
-
this.type = type;
|
|
2596
|
-
}
|
|
2597
|
-
}
|
|
2598
|
-
|
|
2599
|
-
class AsyncWaterfallHook extends SyncHook {
|
|
2600
|
-
emit(data) {
|
|
2601
|
-
if (!isObject(data)) {
|
|
2602
|
-
error(`The response data for the "${this.type}" hook must be an object.`);
|
|
2603
|
-
}
|
|
2604
|
-
const ls = Array.from(this.listeners);
|
|
2605
|
-
if (ls.length > 0) {
|
|
2606
|
-
let i = 0;
|
|
2607
|
-
const processError = (e)=>{
|
|
2608
|
-
warn(e);
|
|
2609
|
-
this.onerror(e);
|
|
2610
|
-
return data;
|
|
2611
|
-
};
|
|
2612
|
-
const call = (prevData)=>{
|
|
2613
|
-
if (checkReturnData(data, prevData)) {
|
|
2614
|
-
data = prevData;
|
|
2615
|
-
if (i < ls.length) {
|
|
2616
|
-
try {
|
|
2617
|
-
return Promise.resolve(ls[i++](data)).then(call, processError);
|
|
2618
|
-
} catch (e) {
|
|
2619
|
-
return processError(e);
|
|
2620
|
-
}
|
|
2621
|
-
}
|
|
2622
|
-
} else {
|
|
2623
|
-
this.onerror(`A plugin returned an incorrect value for the "${this.type}" type.`);
|
|
2624
|
-
}
|
|
2625
|
-
return data;
|
|
2626
|
-
};
|
|
2627
|
-
return Promise.resolve(call(data));
|
|
2628
|
-
}
|
|
2629
|
-
return Promise.resolve(data);
|
|
2630
|
-
}
|
|
2631
|
-
constructor(type){
|
|
2632
|
-
super();
|
|
2633
|
-
this.onerror = error;
|
|
2634
|
-
this.type = type;
|
|
2635
|
-
}
|
|
2636
|
-
}
|
|
2637
|
-
|
|
2638
|
-
class PluginSystem {
|
|
2639
|
-
applyPlugin(plugin, instance) {
|
|
2640
|
-
assert(isPlainObject(plugin), 'Plugin configuration is invalid.');
|
|
2641
|
-
// The plugin's name is mandatory and must be unique
|
|
2642
|
-
const pluginName = plugin.name;
|
|
2643
|
-
assert(pluginName, 'A name must be provided by the plugin.');
|
|
2644
|
-
if (!this.registerPlugins[pluginName]) {
|
|
2645
|
-
this.registerPlugins[pluginName] = plugin;
|
|
2646
|
-
plugin.apply == null ? void 0 : plugin.apply.call(plugin, instance);
|
|
2647
|
-
Object.keys(this.lifecycle).forEach((key)=>{
|
|
2648
|
-
const pluginLife = plugin[key];
|
|
2649
|
-
if (pluginLife) {
|
|
2650
|
-
this.lifecycle[key].on(pluginLife);
|
|
2651
|
-
}
|
|
2652
|
-
});
|
|
2653
|
-
}
|
|
2654
|
-
}
|
|
2655
|
-
removePlugin(pluginName) {
|
|
2656
|
-
assert(pluginName, 'A name is required.');
|
|
2657
|
-
const plugin = this.registerPlugins[pluginName];
|
|
2658
|
-
assert(plugin, `The plugin "${pluginName}" is not registered.`);
|
|
2659
|
-
Object.keys(plugin).forEach((key)=>{
|
|
2660
|
-
if (key !== 'name') {
|
|
2661
|
-
this.lifecycle[key].remove(plugin[key]);
|
|
2662
|
-
}
|
|
2663
|
-
});
|
|
2664
|
-
}
|
|
2665
|
-
constructor(lifecycle){
|
|
2666
|
-
this.registerPlugins = {};
|
|
2667
|
-
this.lifecycle = lifecycle;
|
|
2668
|
-
this.lifecycleKeys = Object.keys(lifecycle);
|
|
2669
|
-
}
|
|
2670
|
-
}
|
|
2671
|
-
|
|
2672
|
-
function assignRemoteInfo(remoteInfo, remoteSnapshot) {
|
|
2673
|
-
const remoteEntryInfo = getRemoteEntryInfoFromSnapshot(remoteSnapshot);
|
|
2674
|
-
if (!remoteEntryInfo.url) {
|
|
2675
|
-
error(`The attribute remoteEntry of ${remoteInfo.name} must not be undefined.`);
|
|
2676
|
-
}
|
|
2677
|
-
let entryUrl = sdk.getResourceUrl(remoteSnapshot, remoteEntryInfo.url);
|
|
2678
|
-
if (!sdk.isBrowserEnv() && !entryUrl.startsWith('http')) {
|
|
2679
|
-
entryUrl = `https:${entryUrl}`;
|
|
2680
|
-
}
|
|
2681
|
-
remoteInfo.type = remoteEntryInfo.type;
|
|
2682
|
-
remoteInfo.entryGlobalName = remoteEntryInfo.globalName;
|
|
2683
|
-
remoteInfo.entry = entryUrl;
|
|
2684
|
-
remoteInfo.version = remoteSnapshot.version;
|
|
2685
|
-
remoteInfo.buildVersion = remoteSnapshot.buildVersion;
|
|
2686
|
-
}
|
|
2687
|
-
function snapshotPlugin() {
|
|
2688
|
-
return {
|
|
2689
|
-
name: 'snapshot-plugin',
|
|
2690
|
-
async afterResolve (args) {
|
|
2691
|
-
const { remote, pkgNameOrAlias, expose, origin, remoteInfo, id } = args;
|
|
2692
|
-
if (!isRemoteInfoWithEntry(remote) || !isPureRemoteEntry(remote)) {
|
|
2693
|
-
const { remoteSnapshot, globalSnapshot } = await origin.snapshotHandler.loadRemoteSnapshotInfo({
|
|
2694
|
-
moduleInfo: remote,
|
|
2695
|
-
id
|
|
2696
|
-
});
|
|
2697
|
-
assignRemoteInfo(remoteInfo, remoteSnapshot);
|
|
2698
|
-
// preloading assets
|
|
2699
|
-
const preloadOptions = {
|
|
2700
|
-
remote,
|
|
2701
|
-
preloadConfig: {
|
|
2702
|
-
nameOrAlias: pkgNameOrAlias,
|
|
2703
|
-
exposes: [
|
|
2704
|
-
expose
|
|
2705
|
-
],
|
|
2706
|
-
resourceCategory: 'sync',
|
|
2707
|
-
share: false,
|
|
2708
|
-
depsRemote: false
|
|
2709
|
-
}
|
|
2710
|
-
};
|
|
2711
|
-
const assets = await origin.remoteHandler.hooks.lifecycle.generatePreloadAssets.emit({
|
|
2712
|
-
origin,
|
|
2713
|
-
preloadOptions,
|
|
2714
|
-
remoteInfo,
|
|
2715
|
-
remote,
|
|
2716
|
-
remoteSnapshot,
|
|
2717
|
-
globalSnapshot
|
|
2718
|
-
});
|
|
2719
|
-
if (assets) {
|
|
2720
|
-
preloadAssets(remoteInfo, origin, assets, false);
|
|
2721
|
-
}
|
|
2722
|
-
return polyfills._extends({}, args, {
|
|
2723
|
-
remoteSnapshot
|
|
2724
|
-
});
|
|
2725
|
-
}
|
|
2726
|
-
return args;
|
|
2727
|
-
}
|
|
2728
|
-
};
|
|
2729
|
-
}
|
|
2730
|
-
|
|
2731
|
-
// name
|
|
2732
|
-
// name:version
|
|
2733
|
-
function splitId(id) {
|
|
2734
|
-
const splitInfo = id.split(':');
|
|
2735
|
-
if (splitInfo.length === 1) {
|
|
2736
|
-
return {
|
|
2737
|
-
name: splitInfo[0],
|
|
2738
|
-
version: undefined
|
|
2739
|
-
};
|
|
2740
|
-
} else if (splitInfo.length === 2) {
|
|
2741
|
-
return {
|
|
2742
|
-
name: splitInfo[0],
|
|
2743
|
-
version: splitInfo[1]
|
|
2744
|
-
};
|
|
2745
|
-
} else {
|
|
2746
|
-
return {
|
|
2747
|
-
name: splitInfo[1],
|
|
2748
|
-
version: splitInfo[2]
|
|
2749
|
-
};
|
|
2750
|
-
}
|
|
2751
|
-
}
|
|
2752
|
-
// Traverse all nodes in moduleInfo and traverse the entire snapshot
|
|
2753
|
-
function traverseModuleInfo(globalSnapshot, remoteInfo, traverse, isRoot, memo = {}, remoteSnapshot) {
|
|
2754
|
-
const id = getFMId(remoteInfo);
|
|
2755
|
-
const { value: snapshotValue } = getInfoWithoutType(globalSnapshot, id);
|
|
2756
|
-
const effectiveRemoteSnapshot = remoteSnapshot || snapshotValue;
|
|
2757
|
-
if (effectiveRemoteSnapshot && !sdk.isManifestProvider(effectiveRemoteSnapshot)) {
|
|
2758
|
-
traverse(effectiveRemoteSnapshot, remoteInfo, isRoot);
|
|
2759
|
-
if (effectiveRemoteSnapshot.remotesInfo) {
|
|
2760
|
-
const remoteKeys = Object.keys(effectiveRemoteSnapshot.remotesInfo);
|
|
2761
|
-
for (const key of remoteKeys){
|
|
2762
|
-
if (memo[key]) {
|
|
2763
|
-
continue;
|
|
2764
|
-
}
|
|
2765
|
-
memo[key] = true;
|
|
2766
|
-
const subRemoteInfo = splitId(key);
|
|
2767
|
-
const remoteValue = effectiveRemoteSnapshot.remotesInfo[key];
|
|
2768
|
-
traverseModuleInfo(globalSnapshot, {
|
|
2769
|
-
name: subRemoteInfo.name,
|
|
2770
|
-
version: remoteValue.matchedVersion
|
|
2771
|
-
}, traverse, false, memo, undefined);
|
|
2772
|
-
}
|
|
2773
|
-
}
|
|
2774
|
-
}
|
|
2775
|
-
}
|
|
2776
|
-
const isExisted = (type, url)=>{
|
|
2777
|
-
return document.querySelector(`${type}[${type === 'link' ? 'href' : 'src'}="${url}"]`);
|
|
2778
|
-
};
|
|
2779
|
-
// eslint-disable-next-line max-lines-per-function
|
|
2780
|
-
function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, remoteSnapshot) {
|
|
2781
|
-
const cssAssets = [];
|
|
2782
|
-
const jsAssets = [];
|
|
2783
|
-
const entryAssets = [];
|
|
2784
|
-
const loadedSharedJsAssets = new Set();
|
|
2785
|
-
const loadedSharedCssAssets = new Set();
|
|
2786
|
-
const { options } = origin;
|
|
2787
|
-
const { preloadConfig: rootPreloadConfig } = preloadOptions;
|
|
2788
|
-
const { depsRemote } = rootPreloadConfig;
|
|
2789
|
-
const memo = {};
|
|
2790
|
-
traverseModuleInfo(globalSnapshot, remote, (moduleInfoSnapshot, remoteInfo, isRoot)=>{
|
|
2791
|
-
let preloadConfig;
|
|
2792
|
-
if (isRoot) {
|
|
2793
|
-
preloadConfig = rootPreloadConfig;
|
|
2794
|
-
} else {
|
|
2795
|
-
if (Array.isArray(depsRemote)) {
|
|
2796
|
-
// eslint-disable-next-line array-callback-return
|
|
2797
|
-
const findPreloadConfig = depsRemote.find((remoteConfig)=>{
|
|
2798
|
-
if (remoteConfig.nameOrAlias === remoteInfo.name || remoteConfig.nameOrAlias === remoteInfo.alias) {
|
|
2799
|
-
return true;
|
|
2800
|
-
}
|
|
2801
|
-
return false;
|
|
2802
|
-
});
|
|
2803
|
-
if (!findPreloadConfig) {
|
|
2804
|
-
return;
|
|
2805
|
-
}
|
|
2806
|
-
preloadConfig = defaultPreloadArgs(findPreloadConfig);
|
|
2807
|
-
} else if (depsRemote === true) {
|
|
2808
|
-
preloadConfig = rootPreloadConfig;
|
|
2809
|
-
} else {
|
|
2810
|
-
return;
|
|
2811
|
-
}
|
|
2812
|
-
}
|
|
2813
|
-
const remoteEntryUrl = sdk.getResourceUrl(moduleInfoSnapshot, getRemoteEntryInfoFromSnapshot(moduleInfoSnapshot).url);
|
|
2814
|
-
if (remoteEntryUrl) {
|
|
2815
|
-
entryAssets.push({
|
|
2816
|
-
name: remoteInfo.name,
|
|
2817
|
-
moduleInfo: {
|
|
2818
|
-
name: remoteInfo.name,
|
|
2819
|
-
entry: remoteEntryUrl,
|
|
2820
|
-
type: 'remoteEntryType' in moduleInfoSnapshot ? moduleInfoSnapshot.remoteEntryType : 'global',
|
|
2821
|
-
entryGlobalName: 'globalName' in moduleInfoSnapshot ? moduleInfoSnapshot.globalName : remoteInfo.name,
|
|
2822
|
-
shareScope: '',
|
|
2823
|
-
version: 'version' in moduleInfoSnapshot ? moduleInfoSnapshot.version : undefined
|
|
2824
|
-
},
|
|
2825
|
-
url: remoteEntryUrl
|
|
2826
|
-
});
|
|
2827
|
-
}
|
|
2828
|
-
let moduleAssetsInfo = 'modules' in moduleInfoSnapshot ? moduleInfoSnapshot.modules : [];
|
|
2829
|
-
const normalizedPreloadExposes = normalizePreloadExposes(preloadConfig.exposes);
|
|
2830
|
-
if (normalizedPreloadExposes.length && 'modules' in moduleInfoSnapshot) {
|
|
2831
|
-
var _moduleInfoSnapshot_modules;
|
|
2832
|
-
moduleAssetsInfo = moduleInfoSnapshot == null ? void 0 : (_moduleInfoSnapshot_modules = moduleInfoSnapshot.modules) == null ? void 0 : _moduleInfoSnapshot_modules.reduce((assets, moduleAssetInfo)=>{
|
|
2833
|
-
if ((normalizedPreloadExposes == null ? void 0 : normalizedPreloadExposes.indexOf(moduleAssetInfo.moduleName)) !== -1) {
|
|
2834
|
-
assets.push(moduleAssetInfo);
|
|
2835
|
-
}
|
|
2836
|
-
return assets;
|
|
2837
|
-
}, []);
|
|
2838
|
-
}
|
|
2839
|
-
function handleAssets(assets) {
|
|
2840
|
-
const assetsRes = assets.map((asset)=>sdk.getResourceUrl(moduleInfoSnapshot, asset));
|
|
2841
|
-
if (preloadConfig.filter) {
|
|
2842
|
-
return assetsRes.filter(preloadConfig.filter);
|
|
2843
|
-
}
|
|
2844
|
-
return assetsRes;
|
|
2845
|
-
}
|
|
2846
|
-
if (moduleAssetsInfo) {
|
|
2847
|
-
const assetsLength = moduleAssetsInfo.length;
|
|
2848
|
-
for(let index = 0; index < assetsLength; index++){
|
|
2849
|
-
const assetsInfo = moduleAssetsInfo[index];
|
|
2850
|
-
const exposeFullPath = `${remoteInfo.name}/${assetsInfo.moduleName}`;
|
|
2851
|
-
origin.remoteHandler.hooks.lifecycle.handlePreloadModule.emit({
|
|
2852
|
-
id: assetsInfo.moduleName === '.' ? remoteInfo.name : exposeFullPath,
|
|
2853
|
-
name: remoteInfo.name,
|
|
2854
|
-
remoteSnapshot: moduleInfoSnapshot,
|
|
2855
|
-
preloadConfig,
|
|
2856
|
-
remote: remoteInfo,
|
|
2857
|
-
origin
|
|
2858
|
-
});
|
|
2859
|
-
const preloaded = getPreloaded(exposeFullPath);
|
|
2860
|
-
if (preloaded) {
|
|
2861
|
-
continue;
|
|
2862
|
-
}
|
|
2863
|
-
if (preloadConfig.resourceCategory === 'all') {
|
|
2864
|
-
cssAssets.push(...handleAssets(assetsInfo.assets.css.async));
|
|
2865
|
-
cssAssets.push(...handleAssets(assetsInfo.assets.css.sync));
|
|
2866
|
-
jsAssets.push(...handleAssets(assetsInfo.assets.js.async));
|
|
2867
|
-
jsAssets.push(...handleAssets(assetsInfo.assets.js.sync));
|
|
2868
|
-
// eslint-disable-next-line no-constant-condition
|
|
2869
|
-
} else if (preloadConfig.resourceCategory = 'sync') {
|
|
2870
|
-
cssAssets.push(...handleAssets(assetsInfo.assets.css.sync));
|
|
2871
|
-
jsAssets.push(...handleAssets(assetsInfo.assets.js.sync));
|
|
2872
|
-
}
|
|
2873
|
-
setPreloaded(exposeFullPath);
|
|
2874
|
-
}
|
|
2875
|
-
}
|
|
2876
|
-
}, true, memo, remoteSnapshot);
|
|
2877
|
-
if (remoteSnapshot.shared && remoteSnapshot.shared.length > 0) {
|
|
2878
|
-
const collectSharedAssets = (shareInfo, snapshotShared)=>{
|
|
2879
|
-
const registeredShared = getRegisteredShare(origin.shareScopeMap, snapshotShared.sharedName, shareInfo, origin.sharedHandler.hooks.lifecycle.resolveShare);
|
|
2880
|
-
// If the global share does not exist, or the lib function does not exist, it means that the shared has not been loaded yet and can be preloaded.
|
|
2881
|
-
if (registeredShared && typeof registeredShared.lib === 'function') {
|
|
2882
|
-
snapshotShared.assets.js.sync.forEach((asset)=>{
|
|
2883
|
-
loadedSharedJsAssets.add(asset);
|
|
2884
|
-
});
|
|
2885
|
-
snapshotShared.assets.css.sync.forEach((asset)=>{
|
|
2886
|
-
loadedSharedCssAssets.add(asset);
|
|
2887
|
-
});
|
|
2888
|
-
}
|
|
2889
|
-
};
|
|
2890
|
-
remoteSnapshot.shared.forEach((shared)=>{
|
|
2891
|
-
var _options_shared;
|
|
2892
|
-
const shareInfos = (_options_shared = options.shared) == null ? void 0 : _options_shared[shared.sharedName];
|
|
2893
|
-
if (!shareInfos) {
|
|
2894
|
-
return;
|
|
2895
|
-
}
|
|
2896
|
-
// if no version, preload all shared
|
|
2897
|
-
const sharedOptions = shared.version ? shareInfos.find((s)=>s.version === shared.version) : shareInfos;
|
|
2898
|
-
if (!sharedOptions) {
|
|
2899
|
-
return;
|
|
2900
|
-
}
|
|
2901
|
-
const arrayShareInfo = arrayOptions(sharedOptions);
|
|
2902
|
-
arrayShareInfo.forEach((s)=>{
|
|
2903
|
-
collectSharedAssets(s, shared);
|
|
2904
|
-
});
|
|
2905
|
-
});
|
|
2906
|
-
}
|
|
2907
|
-
const needPreloadJsAssets = jsAssets.filter((asset)=>!loadedSharedJsAssets.has(asset) && !isExisted('script', asset));
|
|
2908
|
-
const needPreloadCssAssets = cssAssets.filter((asset)=>!loadedSharedCssAssets.has(asset) && !isExisted('link', asset));
|
|
2909
|
-
return {
|
|
2910
|
-
cssAssets: needPreloadCssAssets,
|
|
2911
|
-
jsAssetsWithoutEntry: needPreloadJsAssets,
|
|
2912
|
-
entryAssets: entryAssets.filter((entry)=>!isExisted('script', entry.url))
|
|
2913
|
-
};
|
|
2914
|
-
}
|
|
2915
|
-
const generatePreloadAssetsPlugin = function() {
|
|
2916
|
-
return {
|
|
2917
|
-
name: 'generate-preload-assets-plugin',
|
|
2918
|
-
async generatePreloadAssets (args) {
|
|
2919
|
-
const { origin, preloadOptions, remoteInfo, remote, globalSnapshot, remoteSnapshot } = args;
|
|
2920
|
-
if (!sdk.isBrowserEnv()) {
|
|
2921
|
-
return {
|
|
2922
|
-
cssAssets: [],
|
|
2923
|
-
jsAssetsWithoutEntry: [],
|
|
2924
|
-
entryAssets: []
|
|
2925
|
-
};
|
|
2926
|
-
}
|
|
2927
|
-
if (isRemoteInfoWithEntry(remote) && isPureRemoteEntry(remote)) {
|
|
2928
|
-
return {
|
|
2929
|
-
cssAssets: [],
|
|
2930
|
-
jsAssetsWithoutEntry: [],
|
|
2931
|
-
entryAssets: [
|
|
2932
|
-
{
|
|
2933
|
-
name: remote.name,
|
|
2934
|
-
url: remote.entry,
|
|
2935
|
-
moduleInfo: {
|
|
2936
|
-
name: remoteInfo.name,
|
|
2937
|
-
entry: remote.entry,
|
|
2938
|
-
type: remoteInfo.type || 'global',
|
|
2939
|
-
entryGlobalName: '',
|
|
2940
|
-
shareScope: ''
|
|
2941
|
-
}
|
|
2942
|
-
}
|
|
2943
|
-
]
|
|
2944
|
-
};
|
|
2945
|
-
}
|
|
2946
|
-
assignRemoteInfo(remoteInfo, remoteSnapshot);
|
|
2947
|
-
const assets = generatePreloadAssets(origin, preloadOptions, remoteInfo, globalSnapshot, remoteSnapshot);
|
|
2948
|
-
return assets;
|
|
2949
|
-
}
|
|
2950
|
-
};
|
|
2951
|
-
};
|
|
2952
|
-
|
|
2953
|
-
function getGlobalRemoteInfo(moduleInfo, origin) {
|
|
2954
|
-
const hostGlobalSnapshot = getGlobalSnapshotInfoByModuleInfo({
|
|
2955
|
-
name: origin.name,
|
|
2956
|
-
version: origin.options.version
|
|
2957
|
-
});
|
|
2958
|
-
// get remote detail info from global
|
|
2959
|
-
const globalRemoteInfo = hostGlobalSnapshot && 'remotesInfo' in hostGlobalSnapshot && hostGlobalSnapshot.remotesInfo && getInfoWithoutType(hostGlobalSnapshot.remotesInfo, moduleInfo.name).value;
|
|
2960
|
-
if (globalRemoteInfo && globalRemoteInfo.matchedVersion) {
|
|
2961
|
-
return {
|
|
2962
|
-
hostGlobalSnapshot,
|
|
2963
|
-
globalSnapshot: getGlobalSnapshot(),
|
|
2964
|
-
remoteSnapshot: getGlobalSnapshotInfoByModuleInfo({
|
|
2965
|
-
name: moduleInfo.name,
|
|
2966
|
-
version: globalRemoteInfo.matchedVersion
|
|
2967
|
-
})
|
|
2968
|
-
};
|
|
2969
|
-
}
|
|
2970
|
-
return {
|
|
2971
|
-
hostGlobalSnapshot: undefined,
|
|
2972
|
-
globalSnapshot: getGlobalSnapshot(),
|
|
2973
|
-
remoteSnapshot: getGlobalSnapshotInfoByModuleInfo({
|
|
2974
|
-
name: moduleInfo.name,
|
|
2975
|
-
version: 'version' in moduleInfo ? moduleInfo.version : undefined
|
|
2976
|
-
})
|
|
2977
|
-
};
|
|
2978
|
-
}
|
|
2979
|
-
class SnapshotHandler {
|
|
2980
|
-
// eslint-disable-next-line max-lines-per-function
|
|
2981
|
-
async loadRemoteSnapshotInfo({ moduleInfo, id, expose }) {
|
|
2982
|
-
const { options } = this.HostInstance;
|
|
2983
|
-
await this.hooks.lifecycle.beforeLoadRemoteSnapshot.emit({
|
|
2984
|
-
options,
|
|
2985
|
-
moduleInfo
|
|
2986
|
-
});
|
|
2987
|
-
let hostSnapshot = getGlobalSnapshotInfoByModuleInfo({
|
|
2988
|
-
name: this.HostInstance.options.name,
|
|
2989
|
-
version: this.HostInstance.options.version
|
|
2990
|
-
});
|
|
2991
|
-
if (!hostSnapshot) {
|
|
2992
|
-
hostSnapshot = {
|
|
2993
|
-
version: this.HostInstance.options.version || '',
|
|
2994
|
-
remoteEntry: '',
|
|
2995
|
-
remotesInfo: {}
|
|
2996
|
-
};
|
|
2997
|
-
addGlobalSnapshot({
|
|
2998
|
-
[this.HostInstance.options.name]: hostSnapshot
|
|
2999
|
-
});
|
|
3000
|
-
}
|
|
3001
|
-
// In dynamic loadRemote scenarios, incomplete remotesInfo delivery may occur. In such cases, the remotesInfo in the host needs to be completed in the snapshot at runtime.
|
|
3002
|
-
// This ensures the snapshot's integrity and helps the chrome plugin correctly identify all producer modules, ensuring that proxyable producer modules will not be missing.
|
|
3003
|
-
if (hostSnapshot && 'remotesInfo' in hostSnapshot && !getInfoWithoutType(hostSnapshot.remotesInfo, moduleInfo.name).value) {
|
|
3004
|
-
if ('version' in moduleInfo || 'entry' in moduleInfo) {
|
|
3005
|
-
hostSnapshot.remotesInfo = polyfills._extends({}, hostSnapshot == null ? void 0 : hostSnapshot.remotesInfo, {
|
|
3006
|
-
[moduleInfo.name]: {
|
|
3007
|
-
matchedVersion: 'version' in moduleInfo ? moduleInfo.version : moduleInfo.entry
|
|
3008
|
-
}
|
|
3009
|
-
});
|
|
3010
|
-
}
|
|
3011
|
-
}
|
|
3012
|
-
const { hostGlobalSnapshot, remoteSnapshot, globalSnapshot } = this.getGlobalRemoteInfo(moduleInfo);
|
|
3013
|
-
const { remoteSnapshot: globalRemoteSnapshot, globalSnapshot: globalSnapshotRes } = await this.hooks.lifecycle.loadSnapshot.emit({
|
|
3014
|
-
options,
|
|
3015
|
-
moduleInfo,
|
|
3016
|
-
hostGlobalSnapshot,
|
|
3017
|
-
remoteSnapshot,
|
|
3018
|
-
globalSnapshot
|
|
3019
|
-
});
|
|
3020
|
-
let mSnapshot;
|
|
3021
|
-
let gSnapshot;
|
|
3022
|
-
// global snapshot includes manifest or module info includes manifest
|
|
3023
|
-
if (globalRemoteSnapshot) {
|
|
3024
|
-
if (sdk.isManifestProvider(globalRemoteSnapshot)) {
|
|
3025
|
-
const remoteEntry = sdk.isBrowserEnv() ? globalRemoteSnapshot.remoteEntry : globalRemoteSnapshot.ssrRemoteEntry || globalRemoteSnapshot.remoteEntry || '';
|
|
3026
|
-
const moduleSnapshot = await this.getManifestJson(remoteEntry, moduleInfo, {});
|
|
3027
|
-
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
3028
|
-
const globalSnapshotRes = setGlobalSnapshotInfoByModuleInfo(polyfills._extends({}, moduleInfo, {
|
|
3029
|
-
// The global remote may be overridden
|
|
3030
|
-
// Therefore, set the snapshot key to the global address of the actual request
|
|
3031
|
-
entry: remoteEntry
|
|
3032
|
-
}), moduleSnapshot);
|
|
3033
|
-
mSnapshot = moduleSnapshot;
|
|
3034
|
-
gSnapshot = globalSnapshotRes;
|
|
3035
|
-
} else {
|
|
3036
|
-
const { remoteSnapshot: remoteSnapshotRes } = await this.hooks.lifecycle.loadRemoteSnapshot.emit({
|
|
3037
|
-
options: this.HostInstance.options,
|
|
3038
|
-
moduleInfo,
|
|
3039
|
-
remoteSnapshot: globalRemoteSnapshot,
|
|
3040
|
-
from: 'global'
|
|
3041
|
-
});
|
|
3042
|
-
mSnapshot = remoteSnapshotRes;
|
|
3043
|
-
gSnapshot = globalSnapshotRes;
|
|
3044
|
-
}
|
|
3045
|
-
} else {
|
|
3046
|
-
if (isRemoteInfoWithEntry(moduleInfo)) {
|
|
3047
|
-
// get from manifest.json and merge remote info from remote server
|
|
3048
|
-
const moduleSnapshot = await this.getManifestJson(moduleInfo.entry, moduleInfo, {});
|
|
3049
|
-
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
3050
|
-
const globalSnapshotRes = setGlobalSnapshotInfoByModuleInfo(moduleInfo, moduleSnapshot);
|
|
3051
|
-
const { remoteSnapshot: remoteSnapshotRes } = await this.hooks.lifecycle.loadRemoteSnapshot.emit({
|
|
3052
|
-
options: this.HostInstance.options,
|
|
3053
|
-
moduleInfo,
|
|
3054
|
-
remoteSnapshot: moduleSnapshot,
|
|
3055
|
-
from: 'global'
|
|
3056
|
-
});
|
|
3057
|
-
mSnapshot = remoteSnapshotRes;
|
|
3058
|
-
gSnapshot = globalSnapshotRes;
|
|
3059
|
-
} else {
|
|
3060
|
-
error(errorCodes$1.getShortErrorMsg(errorCodes$1.RUNTIME_007, errorCodes$1.runtimeDescMap, {
|
|
3061
|
-
hostName: moduleInfo.name,
|
|
3062
|
-
hostVersion: moduleInfo.version,
|
|
3063
|
-
globalSnapshot: JSON.stringify(globalSnapshotRes)
|
|
3064
|
-
}));
|
|
3065
|
-
}
|
|
3066
|
-
}
|
|
3067
|
-
await this.hooks.lifecycle.afterLoadSnapshot.emit({
|
|
3068
|
-
id,
|
|
3069
|
-
host: this.HostInstance,
|
|
3070
|
-
options,
|
|
3071
|
-
moduleInfo,
|
|
3072
|
-
remoteSnapshot: mSnapshot
|
|
3073
|
-
});
|
|
3074
|
-
return {
|
|
3075
|
-
remoteSnapshot: mSnapshot,
|
|
3076
|
-
globalSnapshot: gSnapshot
|
|
3077
|
-
};
|
|
3078
|
-
}
|
|
3079
|
-
getGlobalRemoteInfo(moduleInfo) {
|
|
3080
|
-
return getGlobalRemoteInfo(moduleInfo, this.HostInstance);
|
|
3081
|
-
}
|
|
3082
|
-
async getManifestJson(manifestUrl, moduleInfo, extraOptions) {
|
|
3083
|
-
const getManifest = async ()=>{
|
|
3084
|
-
let manifestJson = this.manifestCache.get(manifestUrl);
|
|
3085
|
-
if (manifestJson) {
|
|
3086
|
-
return manifestJson;
|
|
3087
|
-
}
|
|
3088
|
-
try {
|
|
3089
|
-
let res = await this.loaderHook.lifecycle.fetch.emit(manifestUrl, {});
|
|
3090
|
-
if (!res || !(res instanceof Response)) {
|
|
3091
|
-
res = await fetch(manifestUrl, {});
|
|
3092
|
-
}
|
|
3093
|
-
manifestJson = await res.json();
|
|
3094
|
-
} catch (err) {
|
|
3095
|
-
manifestJson = await this.HostInstance.remoteHandler.hooks.lifecycle.errorLoadRemote.emit({
|
|
3096
|
-
id: manifestUrl,
|
|
3097
|
-
error: err,
|
|
3098
|
-
from: 'runtime',
|
|
3099
|
-
lifecycle: 'afterResolve',
|
|
3100
|
-
origin: this.HostInstance
|
|
3101
|
-
});
|
|
3102
|
-
if (!manifestJson) {
|
|
3103
|
-
delete this.manifestLoading[manifestUrl];
|
|
3104
|
-
error(errorCodes$1.getShortErrorMsg(errorCodes$1.RUNTIME_003, errorCodes$1.runtimeDescMap, {
|
|
3105
|
-
manifestUrl,
|
|
3106
|
-
moduleName: moduleInfo.name,
|
|
3107
|
-
hostName: this.HostInstance.options.name
|
|
3108
|
-
}, `${err}`));
|
|
3109
|
-
}
|
|
3110
|
-
}
|
|
3111
|
-
assert(manifestJson.metaData && manifestJson.exposes && manifestJson.shared, `${manifestUrl} is not a federation manifest`);
|
|
3112
|
-
this.manifestCache.set(manifestUrl, manifestJson);
|
|
3113
|
-
return manifestJson;
|
|
3114
|
-
};
|
|
3115
|
-
const asyncLoadProcess = async ()=>{
|
|
3116
|
-
const manifestJson = await getManifest();
|
|
3117
|
-
const remoteSnapshot = sdk.generateSnapshotFromManifest(manifestJson, {
|
|
3118
|
-
version: manifestUrl
|
|
3119
|
-
});
|
|
3120
|
-
const { remoteSnapshot: remoteSnapshotRes } = await this.hooks.lifecycle.loadRemoteSnapshot.emit({
|
|
3121
|
-
options: this.HostInstance.options,
|
|
3122
|
-
moduleInfo,
|
|
3123
|
-
manifestJson,
|
|
3124
|
-
remoteSnapshot,
|
|
3125
|
-
manifestUrl,
|
|
3126
|
-
from: 'manifest'
|
|
3127
|
-
});
|
|
3128
|
-
return remoteSnapshotRes;
|
|
3129
|
-
};
|
|
3130
|
-
if (!this.manifestLoading[manifestUrl]) {
|
|
3131
|
-
this.manifestLoading[manifestUrl] = asyncLoadProcess().then((res)=>res);
|
|
3132
|
-
}
|
|
3133
|
-
return this.manifestLoading[manifestUrl];
|
|
3134
|
-
}
|
|
3135
|
-
constructor(HostInstance){
|
|
3136
|
-
this.loadingHostSnapshot = null;
|
|
3137
|
-
this.manifestCache = new Map();
|
|
3138
|
-
this.hooks = new PluginSystem({
|
|
3139
|
-
beforeLoadRemoteSnapshot: new AsyncHook('beforeLoadRemoteSnapshot'),
|
|
3140
|
-
loadSnapshot: new AsyncWaterfallHook('loadGlobalSnapshot'),
|
|
3141
|
-
loadRemoteSnapshot: new AsyncWaterfallHook('loadRemoteSnapshot'),
|
|
3142
|
-
afterLoadSnapshot: new AsyncWaterfallHook('afterLoadSnapshot')
|
|
3143
|
-
});
|
|
3144
|
-
this.manifestLoading = Global.__FEDERATION__.__MANIFEST_LOADING__;
|
|
3145
|
-
this.HostInstance = HostInstance;
|
|
3146
|
-
this.loaderHook = HostInstance.loaderHook;
|
|
3147
|
-
}
|
|
3148
|
-
}
|
|
3149
|
-
|
|
3150
|
-
class SharedHandler {
|
|
3151
|
-
// register shared in shareScopeMap
|
|
3152
|
-
registerShared(globalOptions, userOptions) {
|
|
3153
|
-
const { shareInfos, shared } = formatShareConfigs(globalOptions, userOptions);
|
|
3154
|
-
const sharedKeys = Object.keys(shareInfos);
|
|
3155
|
-
sharedKeys.forEach((sharedKey)=>{
|
|
3156
|
-
const sharedVals = shareInfos[sharedKey];
|
|
3157
|
-
sharedVals.forEach((sharedVal)=>{
|
|
3158
|
-
const registeredShared = getRegisteredShare(this.shareScopeMap, sharedKey, sharedVal, this.hooks.lifecycle.resolveShare);
|
|
3159
|
-
if (!registeredShared && sharedVal && sharedVal.lib) {
|
|
3160
|
-
this.setShared({
|
|
3161
|
-
pkgName: sharedKey,
|
|
3162
|
-
lib: sharedVal.lib,
|
|
3163
|
-
get: sharedVal.get,
|
|
3164
|
-
loaded: true,
|
|
3165
|
-
shared: sharedVal,
|
|
3166
|
-
from: userOptions.name
|
|
3167
|
-
});
|
|
3168
|
-
}
|
|
3169
|
-
});
|
|
3170
|
-
});
|
|
3171
|
-
return {
|
|
3172
|
-
shareInfos,
|
|
3173
|
-
shared
|
|
3174
|
-
};
|
|
3175
|
-
}
|
|
3176
|
-
async loadShare(pkgName, extraOptions) {
|
|
3177
|
-
const { host } = this;
|
|
3178
|
-
// This function performs the following steps:
|
|
3179
|
-
// 1. Checks if the currently loaded share already exists, if not, it throws an error
|
|
3180
|
-
// 2. Searches globally for a matching share, if found, it uses it directly
|
|
3181
|
-
// 3. If not found, it retrieves it from the current share and stores the obtained share globally.
|
|
3182
|
-
const shareOptions = getTargetSharedOptions({
|
|
3183
|
-
pkgName,
|
|
3184
|
-
extraOptions,
|
|
3185
|
-
shareInfos: host.options.shared
|
|
3186
|
-
});
|
|
3187
|
-
if (shareOptions == null ? void 0 : shareOptions.scope) {
|
|
3188
|
-
await Promise.all(shareOptions.scope.map(async (shareScope)=>{
|
|
3189
|
-
await Promise.all(this.initializeSharing(shareScope, {
|
|
3190
|
-
strategy: shareOptions.strategy
|
|
3191
|
-
}));
|
|
3192
|
-
return;
|
|
3193
|
-
}));
|
|
3194
|
-
}
|
|
3195
|
-
const loadShareRes = await this.hooks.lifecycle.beforeLoadShare.emit({
|
|
3196
|
-
pkgName,
|
|
3197
|
-
shareInfo: shareOptions,
|
|
3198
|
-
shared: host.options.shared,
|
|
3199
|
-
origin: host
|
|
3200
|
-
});
|
|
3201
|
-
const { shareInfo: shareOptionsRes } = loadShareRes;
|
|
3202
|
-
// Assert that shareInfoRes exists, if not, throw an error
|
|
3203
|
-
assert(shareOptionsRes, `Cannot find ${pkgName} Share in the ${host.options.name}. Please ensure that the ${pkgName} Share parameters have been injected`);
|
|
3204
|
-
// Retrieve from cache
|
|
3205
|
-
const registeredShared = getRegisteredShare(this.shareScopeMap, pkgName, shareOptionsRes, this.hooks.lifecycle.resolveShare);
|
|
3206
|
-
const addUseIn = (shared)=>{
|
|
3207
|
-
if (!shared.useIn) {
|
|
3208
|
-
shared.useIn = [];
|
|
3209
|
-
}
|
|
3210
|
-
addUniqueItem(shared.useIn, host.options.name);
|
|
3211
|
-
};
|
|
3212
|
-
if (registeredShared && registeredShared.lib) {
|
|
3213
|
-
addUseIn(registeredShared);
|
|
3214
|
-
return registeredShared.lib;
|
|
3215
|
-
} else if (registeredShared && registeredShared.loading && !registeredShared.loaded) {
|
|
3216
|
-
const factory = await registeredShared.loading;
|
|
3217
|
-
registeredShared.loaded = true;
|
|
3218
|
-
if (!registeredShared.lib) {
|
|
3219
|
-
registeredShared.lib = factory;
|
|
3220
|
-
}
|
|
3221
|
-
addUseIn(registeredShared);
|
|
3222
|
-
return factory;
|
|
3223
|
-
} else if (registeredShared) {
|
|
3224
|
-
const asyncLoadProcess = async ()=>{
|
|
3225
|
-
const factory = await registeredShared.get();
|
|
3226
|
-
addUseIn(registeredShared);
|
|
3227
|
-
registeredShared.loaded = true;
|
|
3228
|
-
registeredShared.lib = factory;
|
|
3229
|
-
return factory;
|
|
3230
|
-
};
|
|
3231
|
-
const loading = asyncLoadProcess();
|
|
3232
|
-
this.setShared({
|
|
3233
|
-
pkgName,
|
|
3234
|
-
loaded: false,
|
|
3235
|
-
shared: registeredShared,
|
|
3236
|
-
from: host.options.name,
|
|
3237
|
-
lib: null,
|
|
3238
|
-
loading
|
|
3239
|
-
});
|
|
3240
|
-
return loading;
|
|
3241
|
-
} else {
|
|
3242
|
-
if (extraOptions == null ? void 0 : extraOptions.customShareInfo) {
|
|
3243
|
-
return false;
|
|
3244
|
-
}
|
|
3245
|
-
const asyncLoadProcess = async ()=>{
|
|
3246
|
-
const factory = await shareOptionsRes.get();
|
|
3247
|
-
shareOptionsRes.lib = factory;
|
|
3248
|
-
shareOptionsRes.loaded = true;
|
|
3249
|
-
addUseIn(shareOptionsRes);
|
|
3250
|
-
const gShared = getRegisteredShare(this.shareScopeMap, pkgName, shareOptionsRes, this.hooks.lifecycle.resolveShare);
|
|
3251
|
-
if (gShared) {
|
|
3252
|
-
gShared.lib = factory;
|
|
3253
|
-
gShared.loaded = true;
|
|
3254
|
-
gShared.from = shareOptionsRes.from;
|
|
3255
|
-
}
|
|
3256
|
-
return factory;
|
|
3257
|
-
};
|
|
3258
|
-
const loading = asyncLoadProcess();
|
|
3259
|
-
this.setShared({
|
|
3260
|
-
pkgName,
|
|
3261
|
-
loaded: false,
|
|
3262
|
-
shared: shareOptionsRes,
|
|
3263
|
-
from: host.options.name,
|
|
3264
|
-
lib: null,
|
|
3265
|
-
loading
|
|
3266
|
-
});
|
|
3267
|
-
return loading;
|
|
3268
|
-
}
|
|
3269
|
-
}
|
|
3270
|
-
/**
|
|
3271
|
-
* This function initializes the sharing sequence (executed only once per share scope).
|
|
3272
|
-
* It accepts one argument, the name of the share scope.
|
|
3273
|
-
* If the share scope does not exist, it creates one.
|
|
3274
|
-
*/ // eslint-disable-next-line @typescript-eslint/member-ordering
|
|
3275
|
-
initializeSharing(shareScopeName = DEFAULT_SCOPE, extraOptions) {
|
|
3276
|
-
const { host } = this;
|
|
3277
|
-
const from = extraOptions == null ? void 0 : extraOptions.from;
|
|
3278
|
-
const strategy = extraOptions == null ? void 0 : extraOptions.strategy;
|
|
3279
|
-
let initScope = extraOptions == null ? void 0 : extraOptions.initScope;
|
|
3280
|
-
const promises = [];
|
|
3281
|
-
if (from !== 'build') {
|
|
3282
|
-
const { initTokens } = this;
|
|
3283
|
-
if (!initScope) initScope = [];
|
|
3284
|
-
let initToken = initTokens[shareScopeName];
|
|
3285
|
-
if (!initToken) initToken = initTokens[shareScopeName] = {
|
|
3286
|
-
from: this.host.name
|
|
3287
|
-
};
|
|
3288
|
-
if (initScope.indexOf(initToken) >= 0) return promises;
|
|
3289
|
-
initScope.push(initToken);
|
|
3290
|
-
}
|
|
3291
|
-
const shareScope = this.shareScopeMap;
|
|
3292
|
-
const hostName = host.options.name;
|
|
3293
|
-
// Creates a new share scope if necessary
|
|
3294
|
-
if (!shareScope[shareScopeName]) {
|
|
3295
|
-
shareScope[shareScopeName] = {};
|
|
3296
|
-
}
|
|
3297
|
-
// Executes all initialization snippets from all accessible modules
|
|
3298
|
-
const scope = shareScope[shareScopeName];
|
|
3299
|
-
const register = (name, shared)=>{
|
|
3300
|
-
var _activeVersion_shareConfig;
|
|
3301
|
-
const { version, eager } = shared;
|
|
3302
|
-
scope[name] = scope[name] || {};
|
|
3303
|
-
const versions = scope[name];
|
|
3304
|
-
const activeVersion = versions[version];
|
|
3305
|
-
const activeVersionEager = Boolean(activeVersion && (activeVersion.eager || ((_activeVersion_shareConfig = activeVersion.shareConfig) == null ? void 0 : _activeVersion_shareConfig.eager)));
|
|
3306
|
-
if (!activeVersion || activeVersion.strategy !== 'loaded-first' && !activeVersion.loaded && (Boolean(!eager) !== !activeVersionEager ? eager : hostName > activeVersion.from)) {
|
|
3307
|
-
versions[version] = shared;
|
|
3308
|
-
}
|
|
3309
|
-
};
|
|
3310
|
-
const initFn = (mod)=>mod && mod.init && mod.init(shareScope[shareScopeName], initScope);
|
|
3311
|
-
const initRemoteModule = async (key)=>{
|
|
3312
|
-
const { module } = await host.remoteHandler.getRemoteModuleAndOptions({
|
|
3313
|
-
id: key
|
|
3314
|
-
});
|
|
3315
|
-
if (module.getEntry) {
|
|
3316
|
-
let remoteEntryExports;
|
|
3317
|
-
try {
|
|
3318
|
-
remoteEntryExports = await module.getEntry();
|
|
3319
|
-
} catch (error) {
|
|
3320
|
-
remoteEntryExports = await host.remoteHandler.hooks.lifecycle.errorLoadRemote.emit({
|
|
3321
|
-
id: key,
|
|
3322
|
-
error,
|
|
3323
|
-
from: 'runtime',
|
|
3324
|
-
lifecycle: 'beforeLoadShare',
|
|
3325
|
-
origin: host
|
|
3326
|
-
});
|
|
3327
|
-
}
|
|
3328
|
-
if (!module.inited) {
|
|
3329
|
-
await initFn(remoteEntryExports);
|
|
3330
|
-
module.inited = true;
|
|
3331
|
-
}
|
|
3332
|
-
}
|
|
3333
|
-
};
|
|
3334
|
-
Object.keys(host.options.shared).forEach((shareName)=>{
|
|
3335
|
-
const sharedArr = host.options.shared[shareName];
|
|
3336
|
-
sharedArr.forEach((shared)=>{
|
|
3337
|
-
if (shared.scope.includes(shareScopeName)) {
|
|
3338
|
-
register(shareName, shared);
|
|
3339
|
-
}
|
|
3340
|
-
});
|
|
3341
|
-
});
|
|
3342
|
-
// TODO: strategy==='version-first' need to be removed in the future
|
|
3343
|
-
if (host.options.shareStrategy === 'version-first' || strategy === 'version-first') {
|
|
3344
|
-
host.options.remotes.forEach((remote)=>{
|
|
3345
|
-
if (remote.shareScope === shareScopeName) {
|
|
3346
|
-
promises.push(initRemoteModule(remote.name));
|
|
3347
|
-
}
|
|
3348
|
-
});
|
|
3349
|
-
}
|
|
3350
|
-
return promises;
|
|
3351
|
-
}
|
|
3352
|
-
// The lib function will only be available if the shared set by eager or runtime init is set or the shared is successfully loaded.
|
|
3353
|
-
// 1. If the loaded shared already exists globally, then it will be reused
|
|
3354
|
-
// 2. If lib exists in local shared, it will be used directly
|
|
3355
|
-
// 3. If the local get returns something other than Promise, then it will be used directly
|
|
3356
|
-
loadShareSync(pkgName, extraOptions) {
|
|
3357
|
-
const { host } = this;
|
|
3358
|
-
const shareOptions = getTargetSharedOptions({
|
|
3359
|
-
pkgName,
|
|
3360
|
-
extraOptions,
|
|
3361
|
-
shareInfos: host.options.shared
|
|
3362
|
-
});
|
|
3363
|
-
if (shareOptions == null ? void 0 : shareOptions.scope) {
|
|
3364
|
-
shareOptions.scope.forEach((shareScope)=>{
|
|
3365
|
-
this.initializeSharing(shareScope, {
|
|
3366
|
-
strategy: shareOptions.strategy
|
|
3367
|
-
});
|
|
3368
|
-
});
|
|
3369
|
-
}
|
|
3370
|
-
const registeredShared = getRegisteredShare(this.shareScopeMap, pkgName, shareOptions, this.hooks.lifecycle.resolveShare);
|
|
3371
|
-
const addUseIn = (shared)=>{
|
|
3372
|
-
if (!shared.useIn) {
|
|
3373
|
-
shared.useIn = [];
|
|
3374
|
-
}
|
|
3375
|
-
addUniqueItem(shared.useIn, host.options.name);
|
|
3376
|
-
};
|
|
3377
|
-
if (registeredShared) {
|
|
3378
|
-
if (typeof registeredShared.lib === 'function') {
|
|
3379
|
-
addUseIn(registeredShared);
|
|
3380
|
-
if (!registeredShared.loaded) {
|
|
3381
|
-
registeredShared.loaded = true;
|
|
3382
|
-
if (registeredShared.from === host.options.name) {
|
|
3383
|
-
shareOptions.loaded = true;
|
|
3384
|
-
}
|
|
3385
|
-
}
|
|
3386
|
-
return registeredShared.lib;
|
|
3387
|
-
}
|
|
3388
|
-
if (typeof registeredShared.get === 'function') {
|
|
3389
|
-
const module = registeredShared.get();
|
|
3390
|
-
if (!(module instanceof Promise)) {
|
|
3391
|
-
addUseIn(registeredShared);
|
|
3392
|
-
this.setShared({
|
|
3393
|
-
pkgName,
|
|
3394
|
-
loaded: true,
|
|
3395
|
-
from: host.options.name,
|
|
3396
|
-
lib: module,
|
|
3397
|
-
shared: registeredShared
|
|
3398
|
-
});
|
|
3399
|
-
return module;
|
|
3400
|
-
}
|
|
3401
|
-
}
|
|
3402
|
-
}
|
|
3403
|
-
if (shareOptions.lib) {
|
|
3404
|
-
if (!shareOptions.loaded) {
|
|
3405
|
-
shareOptions.loaded = true;
|
|
3406
|
-
}
|
|
3407
|
-
return shareOptions.lib;
|
|
3408
|
-
}
|
|
3409
|
-
if (shareOptions.get) {
|
|
3410
|
-
const module = shareOptions.get();
|
|
3411
|
-
if (module instanceof Promise) {
|
|
3412
|
-
const errorCode = (extraOptions == null ? void 0 : extraOptions.from) === 'build' ? errorCodes$1.RUNTIME_005 : errorCodes$1.RUNTIME_006;
|
|
3413
|
-
throw new Error(errorCodes$1.getShortErrorMsg(errorCode, errorCodes$1.runtimeDescMap, {
|
|
3414
|
-
hostName: host.options.name,
|
|
3415
|
-
sharedPkgName: pkgName
|
|
3416
|
-
}));
|
|
3417
|
-
}
|
|
3418
|
-
shareOptions.lib = module;
|
|
3419
|
-
this.setShared({
|
|
3420
|
-
pkgName,
|
|
3421
|
-
loaded: true,
|
|
3422
|
-
from: host.options.name,
|
|
3423
|
-
lib: shareOptions.lib,
|
|
3424
|
-
shared: shareOptions
|
|
3425
|
-
});
|
|
3426
|
-
return shareOptions.lib;
|
|
3427
|
-
}
|
|
3428
|
-
throw new Error(errorCodes$1.getShortErrorMsg(errorCodes$1.RUNTIME_006, errorCodes$1.runtimeDescMap, {
|
|
3429
|
-
hostName: host.options.name,
|
|
3430
|
-
sharedPkgName: pkgName
|
|
3431
|
-
}));
|
|
3432
|
-
}
|
|
3433
|
-
initShareScopeMap(scopeName, shareScope, extraOptions = {}) {
|
|
3434
|
-
const { host } = this;
|
|
3435
|
-
this.shareScopeMap[scopeName] = shareScope;
|
|
3436
|
-
this.hooks.lifecycle.initContainerShareScopeMap.emit({
|
|
3437
|
-
shareScope,
|
|
3438
|
-
options: host.options,
|
|
3439
|
-
origin: host,
|
|
3440
|
-
scopeName,
|
|
3441
|
-
hostShareScopeMap: extraOptions.hostShareScopeMap
|
|
3442
|
-
});
|
|
3443
|
-
}
|
|
3444
|
-
setShared({ pkgName, shared, from, lib, loading, loaded, get }) {
|
|
3445
|
-
const { version, scope = 'default' } = shared, shareInfo = polyfills._object_without_properties_loose(shared, [
|
|
3446
|
-
"version",
|
|
3447
|
-
"scope"
|
|
3448
|
-
]);
|
|
3449
|
-
const scopes = Array.isArray(scope) ? scope : [
|
|
3450
|
-
scope
|
|
3451
|
-
];
|
|
3452
|
-
scopes.forEach((sc)=>{
|
|
3453
|
-
if (!this.shareScopeMap[sc]) {
|
|
3454
|
-
this.shareScopeMap[sc] = {};
|
|
3455
|
-
}
|
|
3456
|
-
if (!this.shareScopeMap[sc][pkgName]) {
|
|
3457
|
-
this.shareScopeMap[sc][pkgName] = {};
|
|
3458
|
-
}
|
|
3459
|
-
if (!this.shareScopeMap[sc][pkgName][version]) {
|
|
3460
|
-
this.shareScopeMap[sc][pkgName][version] = polyfills._extends({
|
|
3461
|
-
version,
|
|
3462
|
-
scope: [
|
|
3463
|
-
'default'
|
|
3464
|
-
]
|
|
3465
|
-
}, shareInfo, {
|
|
3466
|
-
lib,
|
|
3467
|
-
loaded,
|
|
3468
|
-
loading
|
|
3469
|
-
});
|
|
3470
|
-
if (get) {
|
|
3471
|
-
this.shareScopeMap[sc][pkgName][version].get = get;
|
|
3472
|
-
}
|
|
3473
|
-
return;
|
|
3474
|
-
}
|
|
3475
|
-
const registeredShared = this.shareScopeMap[sc][pkgName][version];
|
|
3476
|
-
if (loading && !registeredShared.loading) {
|
|
3477
|
-
registeredShared.loading = loading;
|
|
3478
|
-
}
|
|
3479
|
-
if (loaded && !registeredShared.loaded) {
|
|
3480
|
-
registeredShared.loaded = loaded;
|
|
3481
|
-
}
|
|
3482
|
-
if (from && registeredShared.from !== from) {
|
|
3483
|
-
registeredShared.from = from;
|
|
3484
|
-
}
|
|
3485
|
-
});
|
|
3486
|
-
}
|
|
3487
|
-
_setGlobalShareScopeMap(hostOptions) {
|
|
3488
|
-
const globalShareScopeMap = getGlobalShareScope();
|
|
3489
|
-
const identifier = hostOptions.id || hostOptions.name;
|
|
3490
|
-
if (identifier && !globalShareScopeMap[identifier]) {
|
|
3491
|
-
globalShareScopeMap[identifier] = this.shareScopeMap;
|
|
3492
|
-
}
|
|
3493
|
-
}
|
|
3494
|
-
constructor(host){
|
|
3495
|
-
this.hooks = new PluginSystem({
|
|
3496
|
-
afterResolve: new AsyncWaterfallHook('afterResolve'),
|
|
3497
|
-
beforeLoadShare: new AsyncWaterfallHook('beforeLoadShare'),
|
|
3498
|
-
// not used yet
|
|
3499
|
-
loadShare: new AsyncHook(),
|
|
3500
|
-
resolveShare: new SyncWaterfallHook('resolveShare'),
|
|
3501
|
-
// maybe will change, temporarily for internal use only
|
|
3502
|
-
initContainerShareScopeMap: new SyncWaterfallHook('initContainerShareScopeMap')
|
|
3503
|
-
});
|
|
3504
|
-
this.host = host;
|
|
3505
|
-
this.shareScopeMap = {};
|
|
3506
|
-
this.initTokens = {};
|
|
3507
|
-
this._setGlobalShareScopeMap(host.options);
|
|
3508
|
-
}
|
|
3509
|
-
}
|
|
3510
|
-
|
|
3511
|
-
class RemoteHandler {
|
|
3512
|
-
formatAndRegisterRemote(globalOptions, userOptions) {
|
|
3513
|
-
const userRemotes = userOptions.remotes || [];
|
|
3514
|
-
return userRemotes.reduce((res, remote)=>{
|
|
3515
|
-
this.registerRemote(remote, res, {
|
|
3516
|
-
force: false
|
|
3517
|
-
});
|
|
3518
|
-
return res;
|
|
3519
|
-
}, globalOptions.remotes);
|
|
3520
|
-
}
|
|
3521
|
-
setIdToRemoteMap(id, remoteMatchInfo) {
|
|
3522
|
-
const { remote, expose } = remoteMatchInfo;
|
|
3523
|
-
const { name, alias } = remote;
|
|
3524
|
-
this.idToRemoteMap[id] = {
|
|
3525
|
-
name: remote.name,
|
|
3526
|
-
expose
|
|
3527
|
-
};
|
|
3528
|
-
if (alias && id.startsWith(name)) {
|
|
3529
|
-
const idWithAlias = id.replace(name, alias);
|
|
3530
|
-
this.idToRemoteMap[idWithAlias] = {
|
|
3531
|
-
name: remote.name,
|
|
3532
|
-
expose
|
|
3533
|
-
};
|
|
3534
|
-
return;
|
|
3535
|
-
}
|
|
3536
|
-
if (alias && id.startsWith(alias)) {
|
|
3537
|
-
const idWithName = id.replace(alias, name);
|
|
3538
|
-
this.idToRemoteMap[idWithName] = {
|
|
3539
|
-
name: remote.name,
|
|
3540
|
-
expose
|
|
3541
|
-
};
|
|
3542
|
-
}
|
|
3543
|
-
}
|
|
3544
|
-
// eslint-disable-next-line max-lines-per-function
|
|
3545
|
-
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
3546
|
-
async loadRemote(id, options) {
|
|
3547
|
-
const { host } = this;
|
|
3548
|
-
try {
|
|
3549
|
-
const { loadFactory = true } = options || {
|
|
3550
|
-
loadFactory: true
|
|
3551
|
-
};
|
|
3552
|
-
// 1. Validate the parameters of the retrieved module. There are two module request methods: pkgName + expose and alias + expose.
|
|
3553
|
-
// 2. Request the snapshot information of the current host and globally store the obtained snapshot information. The retrieved module information is partially offline and partially online. The online module information will retrieve the modules used online.
|
|
3554
|
-
// 3. Retrieve the detailed information of the current module from global (remoteEntry address, expose resource address)
|
|
3555
|
-
// 4. After retrieving remoteEntry, call the init of the module, and then retrieve the exported content of the module through get
|
|
3556
|
-
// id: pkgName(@federation/app1) + expose(button) = @federation/app1/button
|
|
3557
|
-
// id: alias(app1) + expose(button) = app1/button
|
|
3558
|
-
// id: alias(app1/utils) + expose(loadash/sort) = app1/utils/loadash/sort
|
|
3559
|
-
const { module, moduleOptions, remoteMatchInfo } = await this.getRemoteModuleAndOptions({
|
|
3560
|
-
id
|
|
3561
|
-
});
|
|
3562
|
-
const { pkgNameOrAlias, remote, expose, id: idRes, remoteSnapshot } = remoteMatchInfo;
|
|
3563
|
-
const moduleOrFactory = await module.get(idRes, expose, options, remoteSnapshot);
|
|
3564
|
-
const moduleWrapper = await this.hooks.lifecycle.onLoad.emit({
|
|
3565
|
-
id: idRes,
|
|
3566
|
-
pkgNameOrAlias,
|
|
3567
|
-
expose,
|
|
3568
|
-
exposeModule: loadFactory ? moduleOrFactory : undefined,
|
|
3569
|
-
exposeModuleFactory: loadFactory ? undefined : moduleOrFactory,
|
|
3570
|
-
remote,
|
|
3571
|
-
options: moduleOptions,
|
|
3572
|
-
moduleInstance: module,
|
|
3573
|
-
origin: host
|
|
3574
|
-
});
|
|
3575
|
-
this.setIdToRemoteMap(id, remoteMatchInfo);
|
|
3576
|
-
if (typeof moduleWrapper === 'function') {
|
|
3577
|
-
return moduleWrapper;
|
|
3578
|
-
}
|
|
3579
|
-
return moduleOrFactory;
|
|
3580
|
-
} catch (error) {
|
|
3581
|
-
const { from = 'runtime' } = options || {
|
|
3582
|
-
from: 'runtime'
|
|
3583
|
-
};
|
|
3584
|
-
const failOver = await this.hooks.lifecycle.errorLoadRemote.emit({
|
|
3585
|
-
id,
|
|
3586
|
-
error,
|
|
3587
|
-
from,
|
|
3588
|
-
lifecycle: 'onLoad',
|
|
3589
|
-
origin: host
|
|
3590
|
-
});
|
|
3591
|
-
if (!failOver) {
|
|
3592
|
-
throw error;
|
|
3593
|
-
}
|
|
3594
|
-
return failOver;
|
|
3595
|
-
}
|
|
3596
|
-
}
|
|
3597
|
-
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
3598
|
-
async preloadRemote(preloadOptions) {
|
|
3599
|
-
const { host } = this;
|
|
3600
|
-
await this.hooks.lifecycle.beforePreloadRemote.emit({
|
|
3601
|
-
preloadOps: preloadOptions,
|
|
3602
|
-
options: host.options,
|
|
3603
|
-
origin: host
|
|
3604
|
-
});
|
|
3605
|
-
const preloadOps = formatPreloadArgs(host.options.remotes, preloadOptions);
|
|
3606
|
-
await Promise.all(preloadOps.map(async (ops)=>{
|
|
3607
|
-
const { remote } = ops;
|
|
3608
|
-
const remoteInfo = getRemoteInfo(remote);
|
|
3609
|
-
const { globalSnapshot, remoteSnapshot } = await host.snapshotHandler.loadRemoteSnapshotInfo({
|
|
3610
|
-
moduleInfo: remote
|
|
3611
|
-
});
|
|
3612
|
-
const assets = await this.hooks.lifecycle.generatePreloadAssets.emit({
|
|
3613
|
-
origin: host,
|
|
3614
|
-
preloadOptions: ops,
|
|
3615
|
-
remote,
|
|
3616
|
-
remoteInfo,
|
|
3617
|
-
globalSnapshot,
|
|
3618
|
-
remoteSnapshot
|
|
3619
|
-
});
|
|
3620
|
-
if (!assets) {
|
|
3621
|
-
return;
|
|
3622
|
-
}
|
|
3623
|
-
preloadAssets(remoteInfo, host, assets);
|
|
3624
|
-
}));
|
|
3625
|
-
}
|
|
3626
|
-
registerRemotes(remotes, options) {
|
|
3627
|
-
const { host } = this;
|
|
3628
|
-
remotes.forEach((remote)=>{
|
|
3629
|
-
this.registerRemote(remote, host.options.remotes, {
|
|
3630
|
-
force: options == null ? void 0 : options.force
|
|
3631
|
-
});
|
|
3632
|
-
});
|
|
3633
|
-
}
|
|
3634
|
-
async getRemoteModuleAndOptions(options) {
|
|
3635
|
-
const { host } = this;
|
|
3636
|
-
const { id } = options;
|
|
3637
|
-
let loadRemoteArgs;
|
|
3638
|
-
try {
|
|
3639
|
-
loadRemoteArgs = await this.hooks.lifecycle.beforeRequest.emit({
|
|
3640
|
-
id,
|
|
3641
|
-
options: host.options,
|
|
3642
|
-
origin: host
|
|
3643
|
-
});
|
|
3644
|
-
} catch (error) {
|
|
3645
|
-
loadRemoteArgs = await this.hooks.lifecycle.errorLoadRemote.emit({
|
|
3646
|
-
id,
|
|
3647
|
-
options: host.options,
|
|
3648
|
-
origin: host,
|
|
3649
|
-
from: 'runtime',
|
|
3650
|
-
error,
|
|
3651
|
-
lifecycle: 'beforeRequest'
|
|
3652
|
-
});
|
|
3653
|
-
if (!loadRemoteArgs) {
|
|
3654
|
-
throw error;
|
|
3655
|
-
}
|
|
3656
|
-
}
|
|
3657
|
-
const { id: idRes } = loadRemoteArgs;
|
|
3658
|
-
const remoteSplitInfo = matchRemoteWithNameAndExpose(host.options.remotes, idRes);
|
|
3659
|
-
assert(remoteSplitInfo, errorCodes$1.getShortErrorMsg(errorCodes$1.RUNTIME_004, errorCodes$1.runtimeDescMap, {
|
|
3660
|
-
hostName: host.options.name,
|
|
3661
|
-
requestId: idRes
|
|
3662
|
-
}));
|
|
3663
|
-
const { remote: rawRemote } = remoteSplitInfo;
|
|
3664
|
-
const remoteInfo = getRemoteInfo(rawRemote);
|
|
3665
|
-
const matchInfo = await host.sharedHandler.hooks.lifecycle.afterResolve.emit(polyfills._extends({
|
|
3666
|
-
id: idRes
|
|
3667
|
-
}, remoteSplitInfo, {
|
|
3668
|
-
options: host.options,
|
|
3669
|
-
origin: host,
|
|
3670
|
-
remoteInfo
|
|
3671
|
-
}));
|
|
3672
|
-
const { remote, expose } = matchInfo;
|
|
3673
|
-
assert(remote && expose, `The 'beforeRequest' hook was executed, but it failed to return the correct 'remote' and 'expose' values while loading ${idRes}.`);
|
|
3674
|
-
let module = host.moduleCache.get(remote.name);
|
|
3675
|
-
const moduleOptions = {
|
|
3676
|
-
host: host,
|
|
3677
|
-
remoteInfo
|
|
3678
|
-
};
|
|
3679
|
-
if (!module) {
|
|
3680
|
-
module = new Module(moduleOptions);
|
|
3681
|
-
host.moduleCache.set(remote.name, module);
|
|
3682
|
-
}
|
|
3683
|
-
return {
|
|
3684
|
-
module,
|
|
3685
|
-
moduleOptions,
|
|
3686
|
-
remoteMatchInfo: matchInfo
|
|
3687
|
-
};
|
|
3688
|
-
}
|
|
3689
|
-
registerRemote(remote, targetRemotes, options) {
|
|
3690
|
-
const { host } = this;
|
|
3691
|
-
const normalizeRemote = ()=>{
|
|
3692
|
-
if (remote.alias) {
|
|
3693
|
-
// Validate if alias equals the prefix of remote.name and remote.alias, if so, throw an error
|
|
3694
|
-
// As multi-level path references cannot guarantee unique names, alias being a prefix of remote.name is not supported
|
|
3695
|
-
const findEqual = targetRemotes.find((item)=>{
|
|
3696
|
-
var _item_alias;
|
|
3697
|
-
return remote.alias && (item.name.startsWith(remote.alias) || ((_item_alias = item.alias) == null ? void 0 : _item_alias.startsWith(remote.alias)));
|
|
3698
|
-
});
|
|
3699
|
-
assert(!findEqual, `The alias ${remote.alias} of remote ${remote.name} is not allowed to be the prefix of ${findEqual && findEqual.name} name or alias`);
|
|
3700
|
-
}
|
|
3701
|
-
// Set the remote entry to a complete path
|
|
3702
|
-
if ('entry' in remote) {
|
|
3703
|
-
if (sdk.isBrowserEnv() && !remote.entry.startsWith('http')) {
|
|
3704
|
-
remote.entry = new URL(remote.entry, window.location.origin).href;
|
|
3705
|
-
}
|
|
3706
|
-
}
|
|
3707
|
-
if (!remote.shareScope) {
|
|
3708
|
-
remote.shareScope = DEFAULT_SCOPE;
|
|
3709
|
-
}
|
|
3710
|
-
if (!remote.type) {
|
|
3711
|
-
remote.type = DEFAULT_REMOTE_TYPE;
|
|
3712
|
-
}
|
|
3713
|
-
};
|
|
3714
|
-
this.hooks.lifecycle.beforeRegisterRemote.emit({
|
|
3715
|
-
remote,
|
|
3716
|
-
origin: host
|
|
3717
|
-
});
|
|
3718
|
-
const registeredRemote = targetRemotes.find((item)=>item.name === remote.name);
|
|
3719
|
-
if (!registeredRemote) {
|
|
3720
|
-
normalizeRemote();
|
|
3721
|
-
targetRemotes.push(remote);
|
|
3722
|
-
this.hooks.lifecycle.registerRemote.emit({
|
|
3723
|
-
remote,
|
|
3724
|
-
origin: host
|
|
3725
|
-
});
|
|
3726
|
-
} else {
|
|
3727
|
-
const messages = [
|
|
3728
|
-
`The remote "${remote.name}" is already registered.`,
|
|
3729
|
-
'Please note that overriding it may cause unexpected errors.'
|
|
3730
|
-
];
|
|
3731
|
-
if (options == null ? void 0 : options.force) {
|
|
3732
|
-
// remove registered remote
|
|
3733
|
-
this.removeRemote(registeredRemote);
|
|
3734
|
-
normalizeRemote();
|
|
3735
|
-
targetRemotes.push(remote);
|
|
3736
|
-
this.hooks.lifecycle.registerRemote.emit({
|
|
3737
|
-
remote,
|
|
3738
|
-
origin: host
|
|
3739
|
-
});
|
|
3740
|
-
sdk.warn(messages.join(' '));
|
|
3741
|
-
}
|
|
3742
|
-
}
|
|
3743
|
-
}
|
|
3744
|
-
removeRemote(remote) {
|
|
3745
|
-
try {
|
|
3746
|
-
const { host } = this;
|
|
3747
|
-
const { name } = remote;
|
|
3748
|
-
const remoteIndex = host.options.remotes.findIndex((item)=>item.name === name);
|
|
3749
|
-
if (remoteIndex !== -1) {
|
|
3750
|
-
host.options.remotes.splice(remoteIndex, 1);
|
|
3751
|
-
}
|
|
3752
|
-
const loadedModule = host.moduleCache.get(remote.name);
|
|
3753
|
-
if (loadedModule) {
|
|
3754
|
-
const remoteInfo = loadedModule.remoteInfo;
|
|
3755
|
-
const key = remoteInfo.entryGlobalName;
|
|
3756
|
-
if (CurrentGlobal[key]) {
|
|
3757
|
-
var _Object_getOwnPropertyDescriptor;
|
|
3758
|
-
if ((_Object_getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor(CurrentGlobal, key)) == null ? void 0 : _Object_getOwnPropertyDescriptor.configurable) {
|
|
3759
|
-
delete CurrentGlobal[key];
|
|
3760
|
-
} else {
|
|
3761
|
-
// @ts-ignore
|
|
3762
|
-
CurrentGlobal[key] = undefined;
|
|
3763
|
-
}
|
|
3764
|
-
}
|
|
3765
|
-
const remoteEntryUniqueKey = getRemoteEntryUniqueKey(loadedModule.remoteInfo);
|
|
3766
|
-
if (globalLoading[remoteEntryUniqueKey]) {
|
|
3767
|
-
delete globalLoading[remoteEntryUniqueKey];
|
|
3768
|
-
}
|
|
3769
|
-
host.snapshotHandler.manifestCache.delete(remoteInfo.entry);
|
|
3770
|
-
// delete unloaded shared and instance
|
|
3771
|
-
let remoteInsId = remoteInfo.buildVersion ? sdk.composeKeyWithSeparator(remoteInfo.name, remoteInfo.buildVersion) : remoteInfo.name;
|
|
3772
|
-
const remoteInsIndex = CurrentGlobal.__FEDERATION__.__INSTANCES__.findIndex((ins)=>{
|
|
3773
|
-
if (remoteInfo.buildVersion) {
|
|
3774
|
-
return ins.options.id === remoteInsId;
|
|
3775
|
-
} else {
|
|
3776
|
-
return ins.name === remoteInsId;
|
|
3777
|
-
}
|
|
3778
|
-
});
|
|
3779
|
-
if (remoteInsIndex !== -1) {
|
|
3780
|
-
const remoteIns = CurrentGlobal.__FEDERATION__.__INSTANCES__[remoteInsIndex];
|
|
3781
|
-
remoteInsId = remoteIns.options.id || remoteInsId;
|
|
3782
|
-
const globalShareScopeMap = getGlobalShareScope();
|
|
3783
|
-
let isAllSharedNotUsed = true;
|
|
3784
|
-
const needDeleteKeys = [];
|
|
3785
|
-
Object.keys(globalShareScopeMap).forEach((instId)=>{
|
|
3786
|
-
const shareScopeMap = globalShareScopeMap[instId];
|
|
3787
|
-
shareScopeMap && Object.keys(shareScopeMap).forEach((shareScope)=>{
|
|
3788
|
-
const shareScopeVal = shareScopeMap[shareScope];
|
|
3789
|
-
shareScopeVal && Object.keys(shareScopeVal).forEach((shareName)=>{
|
|
3790
|
-
const sharedPkgs = shareScopeVal[shareName];
|
|
3791
|
-
sharedPkgs && Object.keys(sharedPkgs).forEach((shareVersion)=>{
|
|
3792
|
-
const shared = sharedPkgs[shareVersion];
|
|
3793
|
-
if (shared && typeof shared === 'object' && shared.from === remoteInfo.name) {
|
|
3794
|
-
if (shared.loaded || shared.loading) {
|
|
3795
|
-
shared.useIn = shared.useIn.filter((usedHostName)=>usedHostName !== remoteInfo.name);
|
|
3796
|
-
if (shared.useIn.length) {
|
|
3797
|
-
isAllSharedNotUsed = false;
|
|
3798
|
-
} else {
|
|
3799
|
-
needDeleteKeys.push([
|
|
3800
|
-
instId,
|
|
3801
|
-
shareScope,
|
|
3802
|
-
shareName,
|
|
3803
|
-
shareVersion
|
|
3804
|
-
]);
|
|
3805
|
-
}
|
|
3806
|
-
} else {
|
|
3807
|
-
needDeleteKeys.push([
|
|
3808
|
-
instId,
|
|
3809
|
-
shareScope,
|
|
3810
|
-
shareName,
|
|
3811
|
-
shareVersion
|
|
3812
|
-
]);
|
|
3813
|
-
}
|
|
3814
|
-
}
|
|
3815
|
-
});
|
|
3816
|
-
});
|
|
3817
|
-
});
|
|
3818
|
-
});
|
|
3819
|
-
if (isAllSharedNotUsed) {
|
|
3820
|
-
remoteIns.shareScopeMap = {};
|
|
3821
|
-
delete globalShareScopeMap[remoteInsId];
|
|
3822
|
-
}
|
|
3823
|
-
needDeleteKeys.forEach(([insId, shareScope, shareName, shareVersion])=>{
|
|
3824
|
-
var _globalShareScopeMap_insId_shareScope_shareName, _globalShareScopeMap_insId_shareScope, _globalShareScopeMap_insId;
|
|
3825
|
-
(_globalShareScopeMap_insId = globalShareScopeMap[insId]) == null ? true : (_globalShareScopeMap_insId_shareScope = _globalShareScopeMap_insId[shareScope]) == null ? true : (_globalShareScopeMap_insId_shareScope_shareName = _globalShareScopeMap_insId_shareScope[shareName]) == null ? true : delete _globalShareScopeMap_insId_shareScope_shareName[shareVersion];
|
|
3826
|
-
});
|
|
3827
|
-
CurrentGlobal.__FEDERATION__.__INSTANCES__.splice(remoteInsIndex, 1);
|
|
3828
|
-
}
|
|
3829
|
-
const { hostGlobalSnapshot } = getGlobalRemoteInfo(remote, host);
|
|
3830
|
-
if (hostGlobalSnapshot) {
|
|
3831
|
-
const remoteKey = hostGlobalSnapshot && 'remotesInfo' in hostGlobalSnapshot && hostGlobalSnapshot.remotesInfo && getInfoWithoutType(hostGlobalSnapshot.remotesInfo, remote.name).key;
|
|
3832
|
-
if (remoteKey) {
|
|
3833
|
-
delete hostGlobalSnapshot.remotesInfo[remoteKey];
|
|
3834
|
-
if (//eslint-disable-next-line no-extra-boolean-cast
|
|
3835
|
-
Boolean(Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey])) {
|
|
3836
|
-
delete Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey];
|
|
3837
|
-
}
|
|
3838
|
-
}
|
|
3839
|
-
}
|
|
3840
|
-
host.moduleCache.delete(remote.name);
|
|
3841
|
-
}
|
|
3842
|
-
} catch (err) {
|
|
3843
|
-
logger.log('removeRemote fail: ', err);
|
|
3844
|
-
}
|
|
3845
|
-
}
|
|
3846
|
-
constructor(host){
|
|
3847
|
-
this.hooks = new PluginSystem({
|
|
3848
|
-
beforeRegisterRemote: new SyncWaterfallHook('beforeRegisterRemote'),
|
|
3849
|
-
registerRemote: new SyncWaterfallHook('registerRemote'),
|
|
3850
|
-
beforeRequest: new AsyncWaterfallHook('beforeRequest'),
|
|
3851
|
-
onLoad: new AsyncHook('onLoad'),
|
|
3852
|
-
handlePreloadModule: new SyncHook('handlePreloadModule'),
|
|
3853
|
-
errorLoadRemote: new AsyncHook('errorLoadRemote'),
|
|
3854
|
-
beforePreloadRemote: new AsyncHook('beforePreloadRemote'),
|
|
3855
|
-
generatePreloadAssets: new AsyncHook('generatePreloadAssets'),
|
|
3856
|
-
// not used yet
|
|
3857
|
-
afterPreloadRemote: new AsyncHook(),
|
|
3858
|
-
loadEntry: new AsyncHook()
|
|
3859
|
-
});
|
|
3860
|
-
this.host = host;
|
|
3861
|
-
this.idToRemoteMap = {};
|
|
3862
|
-
}
|
|
3863
|
-
}
|
|
3864
|
-
|
|
3865
|
-
const USE_SNAPSHOT = typeof FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN === 'boolean' ? !FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN : true; // Default to true (use snapshot) when not explicitly defined
|
|
3866
|
-
class ModuleFederation {
|
|
3867
|
-
initOptions(userOptions) {
|
|
3868
|
-
this.registerPlugins(userOptions.plugins);
|
|
3869
|
-
const options = this.formatOptions(this.options, userOptions);
|
|
3870
|
-
this.options = options;
|
|
3871
|
-
return options;
|
|
3872
|
-
}
|
|
3873
|
-
async loadShare(pkgName, extraOptions) {
|
|
3874
|
-
return this.sharedHandler.loadShare(pkgName, extraOptions);
|
|
3875
|
-
}
|
|
3876
|
-
// The lib function will only be available if the shared set by eager or runtime init is set or the shared is successfully loaded.
|
|
3877
|
-
// 1. If the loaded shared already exists globally, then it will be reused
|
|
3878
|
-
// 2. If lib exists in local shared, it will be used directly
|
|
3879
|
-
// 3. If the local get returns something other than Promise, then it will be used directly
|
|
3880
|
-
loadShareSync(pkgName, extraOptions) {
|
|
3881
|
-
return this.sharedHandler.loadShareSync(pkgName, extraOptions);
|
|
3882
|
-
}
|
|
3883
|
-
initializeSharing(shareScopeName = DEFAULT_SCOPE, extraOptions) {
|
|
3884
|
-
return this.sharedHandler.initializeSharing(shareScopeName, extraOptions);
|
|
3885
|
-
}
|
|
3886
|
-
initRawContainer(name, url, container) {
|
|
3887
|
-
const remoteInfo = getRemoteInfo({
|
|
3888
|
-
name,
|
|
3889
|
-
entry: url
|
|
3890
|
-
});
|
|
3891
|
-
const module = new Module({
|
|
3892
|
-
host: this,
|
|
3893
|
-
remoteInfo
|
|
3894
|
-
});
|
|
3895
|
-
module.remoteEntryExports = container;
|
|
3896
|
-
this.moduleCache.set(name, module);
|
|
3897
|
-
return module;
|
|
3898
|
-
}
|
|
3899
|
-
// eslint-disable-next-line max-lines-per-function
|
|
3900
|
-
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
3901
|
-
async loadRemote(id, options) {
|
|
3902
|
-
return this.remoteHandler.loadRemote(id, options);
|
|
3903
|
-
}
|
|
3904
|
-
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
3905
|
-
async preloadRemote(preloadOptions) {
|
|
3906
|
-
return this.remoteHandler.preloadRemote(preloadOptions);
|
|
3907
|
-
}
|
|
3908
|
-
initShareScopeMap(scopeName, shareScope, extraOptions = {}) {
|
|
3909
|
-
this.sharedHandler.initShareScopeMap(scopeName, shareScope, extraOptions);
|
|
3910
|
-
}
|
|
3911
|
-
formatOptions(globalOptions, userOptions) {
|
|
3912
|
-
const { shared } = formatShareConfigs(globalOptions, userOptions);
|
|
3913
|
-
const { userOptions: userOptionsRes, options: globalOptionsRes } = this.hooks.lifecycle.beforeInit.emit({
|
|
3914
|
-
origin: this,
|
|
3915
|
-
userOptions,
|
|
3916
|
-
options: globalOptions,
|
|
3917
|
-
shareInfo: shared
|
|
3918
|
-
});
|
|
3919
|
-
const remotes = this.remoteHandler.formatAndRegisterRemote(globalOptionsRes, userOptionsRes);
|
|
3920
|
-
const { shared: handledShared } = this.sharedHandler.registerShared(globalOptionsRes, userOptionsRes);
|
|
3921
|
-
const plugins = [
|
|
3922
|
-
...globalOptionsRes.plugins
|
|
3923
|
-
];
|
|
3924
|
-
if (userOptionsRes.plugins) {
|
|
3925
|
-
userOptionsRes.plugins.forEach((plugin)=>{
|
|
3926
|
-
if (!plugins.includes(plugin)) {
|
|
3927
|
-
plugins.push(plugin);
|
|
3928
|
-
}
|
|
3929
|
-
});
|
|
3930
|
-
}
|
|
3931
|
-
const optionsRes = polyfills._extends({}, globalOptions, userOptions, {
|
|
3932
|
-
plugins,
|
|
3933
|
-
remotes,
|
|
3934
|
-
shared: handledShared
|
|
3935
|
-
});
|
|
3936
|
-
this.hooks.lifecycle.init.emit({
|
|
3937
|
-
origin: this,
|
|
3938
|
-
options: optionsRes
|
|
3939
|
-
});
|
|
3940
|
-
return optionsRes;
|
|
3941
|
-
}
|
|
3942
|
-
registerPlugins(plugins) {
|
|
3943
|
-
const pluginRes = registerPlugins$1(plugins, this);
|
|
3944
|
-
// Merge plugin
|
|
3945
|
-
this.options.plugins = this.options.plugins.reduce((res, plugin)=>{
|
|
3946
|
-
if (!plugin) return res;
|
|
3947
|
-
if (res && !res.find((item)=>item.name === plugin.name)) {
|
|
3948
|
-
res.push(plugin);
|
|
3949
|
-
}
|
|
3950
|
-
return res;
|
|
3951
|
-
}, pluginRes || []);
|
|
3952
|
-
}
|
|
3953
|
-
registerRemotes(remotes, options) {
|
|
3954
|
-
return this.remoteHandler.registerRemotes(remotes, options);
|
|
3955
|
-
}
|
|
3956
|
-
registerShared(shared) {
|
|
3957
|
-
this.sharedHandler.registerShared(this.options, polyfills._extends({}, this.options, {
|
|
3958
|
-
shared
|
|
3959
|
-
}));
|
|
3960
|
-
}
|
|
3961
|
-
constructor(userOptions){
|
|
3962
|
-
this.hooks = new PluginSystem({
|
|
3963
|
-
beforeInit: new SyncWaterfallHook('beforeInit'),
|
|
3964
|
-
init: new SyncHook(),
|
|
3965
|
-
// maybe will change, temporarily for internal use only
|
|
3966
|
-
beforeInitContainer: new AsyncWaterfallHook('beforeInitContainer'),
|
|
3967
|
-
// maybe will change, temporarily for internal use only
|
|
3968
|
-
initContainer: new AsyncWaterfallHook('initContainer')
|
|
3969
|
-
});
|
|
3970
|
-
this.version = "0.18.4";
|
|
3971
|
-
this.moduleCache = new Map();
|
|
3972
|
-
this.loaderHook = new PluginSystem({
|
|
3973
|
-
// FIXME: may not be suitable , not open to the public yet
|
|
3974
|
-
getModuleInfo: new SyncHook(),
|
|
3975
|
-
createScript: new SyncHook(),
|
|
3976
|
-
createLink: new SyncHook(),
|
|
3977
|
-
fetch: new AsyncHook(),
|
|
3978
|
-
loadEntryError: new AsyncHook(),
|
|
3979
|
-
getModuleFactory: new AsyncHook()
|
|
3980
|
-
});
|
|
3981
|
-
this.bridgeHook = new PluginSystem({
|
|
3982
|
-
beforeBridgeRender: new SyncHook(),
|
|
3983
|
-
afterBridgeRender: new SyncHook(),
|
|
3984
|
-
beforeBridgeDestroy: new SyncHook(),
|
|
3985
|
-
afterBridgeDestroy: new SyncHook()
|
|
3986
|
-
});
|
|
3987
|
-
const plugins = USE_SNAPSHOT ? [
|
|
3988
|
-
snapshotPlugin(),
|
|
3989
|
-
generatePreloadAssetsPlugin()
|
|
3990
|
-
] : [];
|
|
3991
|
-
// TODO: Validate the details of the options
|
|
3992
|
-
// Initialize options with default values
|
|
3993
|
-
const defaultOptions = {
|
|
3994
|
-
id: getBuilderId$1(),
|
|
3995
|
-
name: userOptions.name,
|
|
3996
|
-
plugins,
|
|
3997
|
-
remotes: [],
|
|
3998
|
-
shared: {},
|
|
3999
|
-
inBrowser: sdk.isBrowserEnv()
|
|
4000
|
-
};
|
|
4001
|
-
this.name = userOptions.name;
|
|
4002
|
-
this.options = defaultOptions;
|
|
4003
|
-
this.snapshotHandler = new SnapshotHandler(this);
|
|
4004
|
-
this.sharedHandler = new SharedHandler(this);
|
|
4005
|
-
this.remoteHandler = new RemoteHandler(this);
|
|
4006
|
-
this.shareScopeMap = this.sharedHandler.shareScopeMap;
|
|
4007
|
-
this.registerPlugins([
|
|
4008
|
-
...defaultOptions.plugins,
|
|
4009
|
-
...userOptions.plugins || []
|
|
4010
|
-
]);
|
|
4011
|
-
this.options = this.formatOptions(defaultOptions, userOptions);
|
|
4012
|
-
}
|
|
4013
|
-
}
|
|
4014
|
-
|
|
4015
|
-
var index = /*#__PURE__*/Object.freeze({
|
|
4016
|
-
__proto__: null
|
|
4017
|
-
});
|
|
4018
|
-
|
|
4019
|
-
index_cjs$2.loadScript = sdk.loadScript;
|
|
4020
|
-
index_cjs$2.loadScriptNode = sdk.loadScriptNode;
|
|
4021
|
-
index_cjs$2.CurrentGlobal = CurrentGlobal;
|
|
4022
|
-
index_cjs$2.Global = Global;
|
|
4023
|
-
index_cjs$2.Module = Module;
|
|
4024
|
-
index_cjs$2.ModuleFederation = ModuleFederation;
|
|
4025
|
-
index_cjs$2.addGlobalSnapshot = addGlobalSnapshot;
|
|
4026
|
-
index_cjs$2.assert = assert;
|
|
4027
|
-
index_cjs$2.getGlobalFederationConstructor = getGlobalFederationConstructor;
|
|
4028
|
-
index_cjs$2.getGlobalSnapshot = getGlobalSnapshot;
|
|
4029
|
-
index_cjs$2.getInfoWithoutType = getInfoWithoutType;
|
|
4030
|
-
index_cjs$2.getRegisteredShare = getRegisteredShare;
|
|
4031
|
-
index_cjs$2.getRemoteEntry = getRemoteEntry;
|
|
4032
|
-
index_cjs$2.getRemoteInfo = getRemoteInfo;
|
|
4033
|
-
index_cjs$2.helpers = helpers;
|
|
4034
|
-
index_cjs$2.isStaticResourcesEqual = isStaticResourcesEqual;
|
|
4035
|
-
index_cjs$2.matchRemoteWithNameAndExpose = matchRemoteWithNameAndExpose;
|
|
4036
|
-
index_cjs$2.registerGlobalPlugins = registerGlobalPlugins;
|
|
4037
|
-
index_cjs$2.resetFederationGlobalInfo = resetFederationGlobalInfo;
|
|
4038
|
-
index_cjs$2.safeWrapper = safeWrapper;
|
|
4039
|
-
index_cjs$2.satisfy = satisfy;
|
|
4040
|
-
index_cjs$2.setGlobalFederationConstructor = setGlobalFederationConstructor;
|
|
4041
|
-
index_cjs$2.setGlobalFederationInstance = setGlobalFederationInstance;
|
|
4042
|
-
index_cjs$2.types = index;
|
|
4043
|
-
|
|
4044
|
-
var utils_cjs = {};
|
|
4045
|
-
|
|
4046
|
-
var runtimeCore$1 = index_cjs$2;
|
|
4047
|
-
|
|
4048
|
-
// injected by bundler, so it can not use runtime-core stuff
|
|
4049
|
-
function getBuilderId() {
|
|
4050
|
-
//@ts-ignore
|
|
4051
|
-
return typeof FEDERATION_BUILD_IDENTIFIER !== 'undefined' ? FEDERATION_BUILD_IDENTIFIER : '';
|
|
4052
|
-
}
|
|
4053
|
-
function getGlobalFederationInstance(name, version) {
|
|
4054
|
-
const buildId = getBuilderId();
|
|
4055
|
-
return runtimeCore$1.CurrentGlobal.__FEDERATION__.__INSTANCES__.find((GMInstance)=>{
|
|
4056
|
-
if (buildId && GMInstance.options.id === buildId) {
|
|
4057
|
-
return true;
|
|
4058
|
-
}
|
|
4059
|
-
if (GMInstance.options.name === name && !GMInstance.options.version && !version) {
|
|
4060
|
-
return true;
|
|
4061
|
-
}
|
|
4062
|
-
if (GMInstance.options.name === name && version && GMInstance.options.version === version) {
|
|
4063
|
-
return true;
|
|
4064
|
-
}
|
|
4065
|
-
return false;
|
|
4066
|
-
});
|
|
4067
|
-
}
|
|
4068
|
-
|
|
4069
|
-
utils_cjs.getGlobalFederationInstance = getGlobalFederationInstance;
|
|
4070
|
-
|
|
4071
|
-
var runtimeCore = index_cjs$2;
|
|
4072
|
-
var errorCodes = index_cjs;
|
|
4073
|
-
var utils = utils_cjs;
|
|
4074
|
-
|
|
4075
|
-
function createInstance(options) {
|
|
4076
|
-
// Retrieve debug constructor
|
|
4077
|
-
const ModuleFederationConstructor = runtimeCore.getGlobalFederationConstructor() || runtimeCore.ModuleFederation;
|
|
4078
|
-
const instance = new ModuleFederationConstructor(options);
|
|
4079
|
-
runtimeCore.setGlobalFederationInstance(instance);
|
|
4080
|
-
return instance;
|
|
4081
|
-
}
|
|
4082
|
-
let FederationInstance = null;
|
|
4083
|
-
/**
|
|
4084
|
-
* @deprecated Use createInstance or getInstance instead
|
|
4085
|
-
*/ function init(options) {
|
|
4086
|
-
// Retrieve the same instance with the same name
|
|
4087
|
-
const instance = utils.getGlobalFederationInstance(options.name, options.version);
|
|
4088
|
-
if (!instance) {
|
|
4089
|
-
FederationInstance = createInstance(options);
|
|
4090
|
-
return FederationInstance;
|
|
4091
|
-
} else {
|
|
4092
|
-
// Merge options
|
|
4093
|
-
instance.initOptions(options);
|
|
4094
|
-
if (!FederationInstance) {
|
|
4095
|
-
FederationInstance = instance;
|
|
4096
|
-
}
|
|
4097
|
-
return instance;
|
|
4098
|
-
}
|
|
4099
|
-
}
|
|
4100
|
-
function loadRemote(...args) {
|
|
4101
|
-
runtimeCore.assert(FederationInstance, errorCodes.getShortErrorMsg(errorCodes.RUNTIME_009, errorCodes.runtimeDescMap));
|
|
4102
|
-
const loadRemote1 = FederationInstance.loadRemote;
|
|
4103
|
-
// eslint-disable-next-line prefer-spread
|
|
4104
|
-
return loadRemote1.apply(FederationInstance, args);
|
|
4105
|
-
}
|
|
4106
|
-
function loadShare(...args) {
|
|
4107
|
-
runtimeCore.assert(FederationInstance, errorCodes.getShortErrorMsg(errorCodes.RUNTIME_009, errorCodes.runtimeDescMap));
|
|
4108
|
-
// eslint-disable-next-line prefer-spread
|
|
4109
|
-
const loadShare1 = FederationInstance.loadShare;
|
|
4110
|
-
return loadShare1.apply(FederationInstance, args);
|
|
4111
|
-
}
|
|
4112
|
-
function loadShareSync(...args) {
|
|
4113
|
-
runtimeCore.assert(FederationInstance, errorCodes.getShortErrorMsg(errorCodes.RUNTIME_009, errorCodes.runtimeDescMap));
|
|
4114
|
-
const loadShareSync1 = FederationInstance.loadShareSync;
|
|
4115
|
-
// eslint-disable-next-line prefer-spread
|
|
4116
|
-
return loadShareSync1.apply(FederationInstance, args);
|
|
4117
|
-
}
|
|
4118
|
-
function preloadRemote(...args) {
|
|
4119
|
-
runtimeCore.assert(FederationInstance, errorCodes.getShortErrorMsg(errorCodes.RUNTIME_009, errorCodes.runtimeDescMap));
|
|
4120
|
-
// eslint-disable-next-line prefer-spread
|
|
4121
|
-
return FederationInstance.preloadRemote.apply(FederationInstance, args);
|
|
4122
|
-
}
|
|
4123
|
-
function registerRemotes(...args) {
|
|
4124
|
-
runtimeCore.assert(FederationInstance, errorCodes.getShortErrorMsg(errorCodes.RUNTIME_009, errorCodes.runtimeDescMap));
|
|
4125
|
-
// eslint-disable-next-line prefer-spread
|
|
4126
|
-
return FederationInstance.registerRemotes.apply(FederationInstance, args);
|
|
4127
|
-
}
|
|
4128
|
-
function registerPlugins(...args) {
|
|
4129
|
-
runtimeCore.assert(FederationInstance, errorCodes.getShortErrorMsg(errorCodes.RUNTIME_009, errorCodes.runtimeDescMap));
|
|
4130
|
-
// eslint-disable-next-line prefer-spread
|
|
4131
|
-
return FederationInstance.registerPlugins.apply(FederationInstance, args);
|
|
4132
|
-
}
|
|
4133
|
-
function getInstance() {
|
|
4134
|
-
return FederationInstance;
|
|
4135
|
-
}
|
|
4136
|
-
function registerShared(...args) {
|
|
4137
|
-
runtimeCore.assert(FederationInstance, errorCodes.getShortErrorMsg(errorCodes.RUNTIME_009, errorCodes.runtimeDescMap));
|
|
4138
|
-
// eslint-disable-next-line prefer-spread
|
|
4139
|
-
return FederationInstance.registerShared.apply(FederationInstance, args);
|
|
4140
|
-
}
|
|
4141
|
-
// Inject for debug
|
|
4142
|
-
runtimeCore.setGlobalFederationConstructor(runtimeCore.ModuleFederation);
|
|
4143
|
-
|
|
4144
|
-
index_cjs$3.Module = runtimeCore.Module;
|
|
4145
|
-
index_cjs$3.ModuleFederation = runtimeCore.ModuleFederation;
|
|
4146
|
-
index_cjs$3.getRemoteEntry = runtimeCore.getRemoteEntry;
|
|
4147
|
-
index_cjs$3.getRemoteInfo = runtimeCore.getRemoteInfo;
|
|
4148
|
-
index_cjs$3.loadScript = runtimeCore.loadScript;
|
|
4149
|
-
index_cjs$3.loadScriptNode = runtimeCore.loadScriptNode;
|
|
4150
|
-
index_cjs$3.registerGlobalPlugins = runtimeCore.registerGlobalPlugins;
|
|
4151
|
-
index_cjs$3.createInstance = createInstance;
|
|
4152
|
-
index_cjs$3.getInstance = getInstance;
|
|
4153
|
-
var init_1 = index_cjs$3.init = init;
|
|
4154
|
-
index_cjs$3.loadRemote = loadRemote;
|
|
4155
|
-
index_cjs$3.loadShare = loadShare;
|
|
4156
|
-
index_cjs$3.loadShareSync = loadShareSync;
|
|
4157
|
-
index_cjs$3.preloadRemote = preloadRemote;
|
|
4158
|
-
index_cjs$3.registerPlugins = registerPlugins;
|
|
4159
|
-
index_cjs$3.registerRemotes = registerRemotes;
|
|
4160
|
-
index_cjs$3.registerShared = registerShared;
|
|
4161
|
-
|
|
4162
|
-
let initResolve, initReject;
|
|
4163
|
-
const initPromise = new Promise((re, rj) => {
|
|
4164
|
-
initResolve = re;
|
|
4165
|
-
initReject = rj;
|
|
4166
|
-
});
|
|
4167
|
-
var rayburstCli__mf_v__runtimeInit__mf_v__ = {
|
|
4168
|
-
initPromise,
|
|
4169
|
-
initResolve,
|
|
4170
|
-
initReject
|
|
4171
|
-
};
|
|
4172
|
-
|
|
4173
|
-
export { index_cjs$3 as a, init_1 as i, rayburstCli__mf_v__runtimeInit__mf_v__ as r };
|