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