@module-federation/webpack-bundler-runtime 1.0.0-canary.1

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