@module-federation/webpack-bundler-runtime 0.0.0-next-20240822101913 → 0.0.0-next-20240824225724

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.
@@ -0,0 +1,4799 @@
1
+ 'use strict';
2
+
3
+ var _async_to_generator = require('@swc/helpers/_/_async_to_generator');
4
+ var _class_call_check = require('@swc/helpers/_/_class_call_check');
5
+ var _create_class = require('@swc/helpers/_/_create_class');
6
+ var _define_property = require('@swc/helpers/_/_define_property');
7
+ var _inherits = require('@swc/helpers/_/_inherits');
8
+ var _instanceof = require('@swc/helpers/_/_instanceof');
9
+ var _sliced_to_array = require('@swc/helpers/_/_sliced_to_array');
10
+ var _to_consumable_array = require('@swc/helpers/_/_to_consumable_array');
11
+ var _type_of = require('@swc/helpers/_/_type_of');
12
+ var _create_super = require('@swc/helpers/_/_create_super');
13
+ var _ts_generator = require('@swc/helpers/_/_ts_generator');
14
+ var _extends = require('@swc/helpers/_/_extends');
15
+ var _object_without_properties_loose = require('@swc/helpers/_/_object_without_properties_loose');
16
+ require('@swc/helpers/_/_to_array');
17
+ var _object_spread = require('@swc/helpers/_/_object_spread');
18
+
19
+ var MANIFEST_EXT = '.json';
20
+ var BROWSER_LOG_KEY = 'FEDERATION_DEBUG';
21
+ var BROWSER_LOG_VALUE = '1';
22
+ var NameTransformSymbol = {
23
+ AT: '@',
24
+ HYPHEN: '-',
25
+ SLASH: '/'
26
+ };
27
+ var _obj;
28
+ var NameTransformMap = (_obj = {}, _define_property._(_obj, NameTransformSymbol.AT, 'scope_'), _define_property._(_obj, NameTransformSymbol.HYPHEN, '_'), _define_property._(_obj, NameTransformSymbol.SLASH, '__'), _obj);
29
+ var _obj1;
30
+ var EncodedNameTransformMap = (_obj1 = {}, _define_property._(_obj1, NameTransformMap[NameTransformSymbol.AT], NameTransformSymbol.AT), _define_property._(_obj1, NameTransformMap[NameTransformSymbol.HYPHEN], NameTransformSymbol.HYPHEN), _define_property._(_obj1, NameTransformMap[NameTransformSymbol.SLASH], NameTransformSymbol.SLASH), _obj1);
31
+ var SEPARATOR = ':';
32
+ var ENCODE_NAME_PREFIX = 'ENCODE_NAME_PREFIX';
33
+ Object.freeze({
34
+ __proto__: null
35
+ });
36
+ Object.freeze({
37
+ __proto__: null
38
+ });
39
+ Object.freeze({
40
+ __proto__: null
41
+ });
42
+ Object.freeze({
43
+ __proto__: null
44
+ });
45
+ function isBrowserEnv() {
46
+ return typeof window !== 'undefined';
47
+ }
48
+ function isDebugMode() {
49
+ if (typeof process !== 'undefined' && process.env && process.env['FEDERATION_DEBUG']) {
50
+ return Boolean(process.env['FEDERATION_DEBUG']);
51
+ }
52
+ return typeof FEDERATION_DEBUG !== 'undefined' && Boolean(FEDERATION_DEBUG);
53
+ }
54
+ var DEBUG_LOG = '[ FEDERATION DEBUG ]';
55
+ function safeGetLocalStorageItem() {
56
+ try {
57
+ if (typeof window !== 'undefined' && window.localStorage) {
58
+ return localStorage.getItem(BROWSER_LOG_KEY) === BROWSER_LOG_VALUE;
59
+ }
60
+ } catch (error1) {
61
+ return typeof document !== 'undefined';
62
+ }
63
+ return false;
64
+ }
65
+ var Logger = function() {
66
+ function Logger1(identifier) {
67
+ _class_call_check._(this, Logger1);
68
+ this.enable = false;
69
+ this.identifier = identifier || DEBUG_LOG;
70
+ if (isBrowserEnv() && safeGetLocalStorageItem()) {
71
+ this.enable = true;
72
+ } else if (isDebugMode()) {
73
+ this.enable = true;
74
+ }
75
+ }
76
+ _create_class._(Logger1, [
77
+ {
78
+ key: "info",
79
+ value: function info(msg, info) {
80
+ if (this.enable) {
81
+ var argsToString = safeToString(info) || '';
82
+ if (isBrowserEnv()) {
83
+ console.info("%c ".concat(this.identifier, ": ").concat(msg, " ").concat(argsToString), 'color:#3300CC');
84
+ } else {
85
+ console.info('\x1b[34m%s', "".concat(this.identifier, ": ").concat(msg, " ").concat(argsToString ? "\n".concat(argsToString) : ''));
86
+ }
87
+ }
88
+ }
89
+ },
90
+ {
91
+ key: "logOriginalInfo",
92
+ value: function logOriginalInfo() {
93
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
94
+ args[_key] = arguments[_key];
95
+ }
96
+ if (this.enable) {
97
+ if (isBrowserEnv()) {
98
+ var _console;
99
+ console.info("%c ".concat(this.identifier, ": OriginalInfo"), 'color:#3300CC');
100
+ (_console = console).log.apply(_console, _to_consumable_array._(args));
101
+ } else {
102
+ var _console1;
103
+ console.info("%c ".concat(this.identifier, ": OriginalInfo"), 'color:#3300CC');
104
+ (_console1 = console).log.apply(_console1, _to_consumable_array._(args));
105
+ }
106
+ }
107
+ }
108
+ }
109
+ ]);
110
+ return Logger1;
111
+ }();
112
+ var LOG_CATEGORY$1 = '[ Federation Runtime ]';
113
+ new Logger();
114
+ var composeKeyWithSeparator = function composeKeyWithSeparator1() {
115
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
116
+ args[_key] = arguments[_key];
117
+ }
118
+ if (!args.length) {
119
+ return '';
120
+ }
121
+ return args.reduce(function(sum, cur) {
122
+ if (!cur) {
123
+ return sum;
124
+ }
125
+ if (!sum) {
126
+ return cur;
127
+ }
128
+ return "".concat(sum).concat(SEPARATOR).concat(cur);
129
+ }, '');
130
+ };
131
+ var decodeName = function decodeName1(name, prefix, withExt) {
132
+ try {
133
+ var decodedName = name;
134
+ if (prefix) {
135
+ if (!decodedName.startsWith(prefix)) {
136
+ return decodedName;
137
+ }
138
+ decodedName = decodedName.replace(new RegExp(prefix, 'g'), '');
139
+ }
140
+ decodedName = decodedName.replace(new RegExp("".concat(NameTransformMap[NameTransformSymbol.AT]), 'g'), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.AT]]).replace(new RegExp("".concat(NameTransformMap[NameTransformSymbol.SLASH]), 'g'), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.SLASH]]).replace(new RegExp("".concat(NameTransformMap[NameTransformSymbol.HYPHEN]), 'g'), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.HYPHEN]]);
141
+ if (withExt) {
142
+ decodedName = decodedName.replace('.js', '');
143
+ }
144
+ return decodedName;
145
+ } catch (err) {
146
+ throw err;
147
+ }
148
+ };
149
+ var getResourceUrl = function(module, sourceUrl) {
150
+ if ('getPublicPath' in module) {
151
+ var publicPath;
152
+ if (!module.getPublicPath.startsWith('function')) {
153
+ publicPath = new Function(module.getPublicPath)();
154
+ } else {
155
+ publicPath = new Function('return ' + module.getPublicPath)()();
156
+ }
157
+ return "".concat(publicPath).concat(sourceUrl);
158
+ } else if ('publicPath' in module) {
159
+ return "".concat(module.publicPath).concat(sourceUrl);
160
+ } else {
161
+ console.warn('Cannot get resource URL. If in debug mode, please ignore.', module, sourceUrl);
162
+ return '';
163
+ }
164
+ };
165
+ var warn$1 = function(msg) {
166
+ console.warn("".concat(LOG_CATEGORY$1, ": ").concat(msg));
167
+ };
168
+ function safeToString(info) {
169
+ try {
170
+ return JSON.stringify(info, null, 2);
171
+ } catch (e) {
172
+ return '';
173
+ }
174
+ }
175
+ var simpleJoinRemoteEntry = function(rPath, rName) {
176
+ if (!rPath) {
177
+ return rName;
178
+ }
179
+ var transformPath = function(str) {
180
+ if (str === '.') {
181
+ return '';
182
+ }
183
+ if (str.startsWith('./')) {
184
+ return str.replace('./', '');
185
+ }
186
+ if (str.startsWith('/')) {
187
+ var strWithoutSlash = str.slice(1);
188
+ if (strWithoutSlash.endsWith('/')) {
189
+ return strWithoutSlash.slice(0, -1);
190
+ }
191
+ return strWithoutSlash;
192
+ }
193
+ return str;
194
+ };
195
+ var transformedPath = transformPath(rPath);
196
+ if (!transformedPath) {
197
+ return rName;
198
+ }
199
+ if (transformedPath.endsWith('/')) {
200
+ return "".concat(transformedPath).concat(rName);
201
+ }
202
+ return "".concat(transformedPath, "/").concat(rName);
203
+ };
204
+ function inferAutoPublicPath(url) {
205
+ return url.replace(/#.*$/, '').replace(/\?.*$/, '').replace(/\/[^\/]+$/, '/');
206
+ }
207
+ function generateSnapshotFromManifest(manifest) {
208
+ var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
209
+ var _manifest_metaData, _manifest_metaData1;
210
+ 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;
211
+ var remoteSnapshot;
212
+ var getPublicPath = function() {
213
+ if ('publicPath' in manifest.metaData) {
214
+ if (manifest.metaData.publicPath === 'auto' && version) {
215
+ return inferAutoPublicPath(version);
216
+ }
217
+ return manifest.metaData.publicPath;
218
+ } else {
219
+ return manifest.metaData.getPublicPath;
220
+ }
221
+ };
222
+ var overridesKeys = Object.keys(overrides);
223
+ var remotesInfo = {};
224
+ if (!Object.keys(remotes).length) {
225
+ var _manifest_remotes;
226
+ remotesInfo = ((_manifest_remotes = manifest.remotes) == null ? void 0 : _manifest_remotes.reduce(function(res, next) {
227
+ var matchedVersion;
228
+ var name = next.federationContainerName;
229
+ if (overridesKeys.includes(name)) {
230
+ matchedVersion = overrides[name];
231
+ } else {
232
+ if ('version' in next) {
233
+ matchedVersion = next.version;
234
+ } else {
235
+ matchedVersion = next.entry;
236
+ }
237
+ }
238
+ res[name] = {
239
+ matchedVersion: matchedVersion
240
+ };
241
+ return res;
242
+ }, {})) || {};
243
+ }
244
+ Object.keys(remotes).forEach(function(key) {
245
+ return remotesInfo[key] = {
246
+ matchedVersion: overridesKeys.includes(key) ? overrides[key] : remotes[key]
247
+ };
248
+ });
249
+ var _manifest_metaData2 = manifest.metaData, _manifest_metaData_remoteEntry = _manifest_metaData2.remoteEntry, remoteEntryPath = _manifest_metaData_remoteEntry.path, remoteEntryName = _manifest_metaData_remoteEntry.name, remoteEntryType = _manifest_metaData_remoteEntry.type, remoteTypes = _manifest_metaData2.types, buildVersion = _manifest_metaData2.buildInfo.buildVersion, globalName = _manifest_metaData2.globalName, ssrRemoteEntry = _manifest_metaData2.ssrRemoteEntry;
250
+ var exposes = manifest.exposes;
251
+ var basicRemoteSnapshot = {
252
+ version: version ? version : '',
253
+ buildVersion: buildVersion,
254
+ globalName: globalName,
255
+ remoteEntry: simpleJoinRemoteEntry(remoteEntryPath, remoteEntryName),
256
+ remoteEntryType: remoteEntryType,
257
+ remoteTypes: simpleJoinRemoteEntry(remoteTypes.path, remoteTypes.name),
258
+ remoteTypesZip: remoteTypes.zip || '',
259
+ remoteTypesAPI: remoteTypes.api || '',
260
+ remotesInfo: remotesInfo,
261
+ shared: manifest == null ? void 0 : manifest.shared.map(function(item) {
262
+ return {
263
+ assets: item.assets,
264
+ sharedName: item.name,
265
+ version: item.version
266
+ };
267
+ }),
268
+ modules: exposes == null ? void 0 : exposes.map(function(expose) {
269
+ return {
270
+ moduleName: expose.name,
271
+ modulePath: expose.path,
272
+ assets: expose.assets
273
+ };
274
+ })
275
+ };
276
+ if ((_manifest_metaData = manifest.metaData) == null ? void 0 : _manifest_metaData.prefetchInterface) {
277
+ var prefetchInterface = manifest.metaData.prefetchInterface;
278
+ basicRemoteSnapshot = _extends._({}, basicRemoteSnapshot, {
279
+ prefetchInterface: prefetchInterface
280
+ });
281
+ }
282
+ if ((_manifest_metaData1 = manifest.metaData) == null ? void 0 : _manifest_metaData1.prefetchEntry) {
283
+ var _manifest_metaData_prefetchEntry = manifest.metaData.prefetchEntry, path = _manifest_metaData_prefetchEntry.path, name = _manifest_metaData_prefetchEntry.name, type = _manifest_metaData_prefetchEntry.type;
284
+ basicRemoteSnapshot = _extends._({}, basicRemoteSnapshot, {
285
+ prefetchEntry: simpleJoinRemoteEntry(path, name),
286
+ prefetchEntryType: type
287
+ });
288
+ }
289
+ if ('publicPath' in manifest.metaData) {
290
+ remoteSnapshot = _extends._({}, basicRemoteSnapshot, {
291
+ publicPath: getPublicPath()
292
+ });
293
+ } else {
294
+ remoteSnapshot = _extends._({}, basicRemoteSnapshot, {
295
+ getPublicPath: getPublicPath()
296
+ });
297
+ }
298
+ if (ssrRemoteEntry) {
299
+ var fullSSRRemoteEntry = simpleJoinRemoteEntry(ssrRemoteEntry.path, ssrRemoteEntry.name);
300
+ remoteSnapshot.ssrRemoteEntry = fullSSRRemoteEntry;
301
+ remoteSnapshot.ssrRemoteEntryType = 'commonjs-module';
302
+ }
303
+ return remoteSnapshot;
304
+ }
305
+ function isManifestProvider(moduleInfo) {
306
+ if ('remoteEntry' in moduleInfo && moduleInfo.remoteEntry.includes(MANIFEST_EXT)) {
307
+ return true;
308
+ } else {
309
+ return false;
310
+ }
311
+ }
312
+ function safeWrapper(callback, disableWarn) {
313
+ return _safeWrapper.apply(this, arguments);
314
+ }
315
+ function _safeWrapper() {
316
+ _safeWrapper = _async_to_generator._(function(callback, disableWarn) {
317
+ var res, e;
318
+ return _ts_generator._(this, function(_state) {
319
+ switch(_state.label){
320
+ case 0:
321
+ _state.trys.push([
322
+ 0,
323
+ 2,
324
+ ,
325
+ 3
326
+ ]);
327
+ return [
328
+ 4,
329
+ callback()
330
+ ];
331
+ case 1:
332
+ res = _state.sent();
333
+ return [
334
+ 2,
335
+ res
336
+ ];
337
+ case 2:
338
+ e = _state.sent();
339
+ !disableWarn && warn$1(e);
340
+ return [
341
+ 2
342
+ ];
343
+ case 3:
344
+ return [
345
+ 2
346
+ ];
347
+ }
348
+ });
349
+ });
350
+ return _safeWrapper.apply(this, arguments);
351
+ }
352
+ function isStaticResourcesEqual(url1, url2) {
353
+ var REG_EXP = /^(https?:)?\/\//i;
354
+ var relativeUrl1 = url1.replace(REG_EXP, '').replace(/\/$/, '');
355
+ var relativeUrl2 = url2.replace(REG_EXP, '').replace(/\/$/, '');
356
+ return relativeUrl1 === relativeUrl2;
357
+ }
358
+ function createScript(info) {
359
+ var script = null;
360
+ var needAttach = true;
361
+ var timeout = 20000;
362
+ var timeoutId;
363
+ var scripts = document.getElementsByTagName('script');
364
+ for(var i = 0; i < scripts.length; i++){
365
+ var s = scripts[i];
366
+ var scriptSrc = s.getAttribute('src');
367
+ if (scriptSrc && isStaticResourcesEqual(scriptSrc, info.url)) {
368
+ script = s;
369
+ needAttach = false;
370
+ break;
371
+ }
372
+ }
373
+ if (!script) {
374
+ script = document.createElement('script');
375
+ script.type = 'text/javascript';
376
+ script.src = info.url;
377
+ var createScriptRes = undefined;
378
+ if (info.createScriptHook) {
379
+ createScriptRes = info.createScriptHook(info.url, info.attrs);
380
+ if (_instanceof._(createScriptRes, HTMLScriptElement)) {
381
+ script = createScriptRes;
382
+ } else if ((typeof createScriptRes === "undefined" ? "undefined" : _type_of._(createScriptRes)) === 'object') {
383
+ if ('script' in createScriptRes && createScriptRes.script) {
384
+ script = createScriptRes.script;
385
+ }
386
+ if ('timeout' in createScriptRes && createScriptRes.timeout) {
387
+ timeout = createScriptRes.timeout;
388
+ }
389
+ }
390
+ }
391
+ var attrs = info.attrs;
392
+ if (attrs && !createScriptRes) {
393
+ Object.keys(attrs).forEach(function(name) {
394
+ if (script) {
395
+ if (name === 'async' || name === 'defer') {
396
+ script[name] = attrs[name];
397
+ } else if (!script.getAttribute(name)) {
398
+ script.setAttribute(name, attrs[name]);
399
+ }
400
+ }
401
+ });
402
+ }
403
+ }
404
+ var onScriptComplete = function(prev, event) {
405
+ var _info_cb;
406
+ clearTimeout(timeoutId);
407
+ if (script) {
408
+ script.onerror = null;
409
+ script.onload = null;
410
+ safeWrapper(function() {
411
+ var _info_needDeleteScript = info.needDeleteScript, needDeleteScript = _info_needDeleteScript === void 0 ? true : _info_needDeleteScript;
412
+ if (needDeleteScript) {
413
+ (script == null ? void 0 : script.parentNode) && script.parentNode.removeChild(script);
414
+ }
415
+ });
416
+ if (prev) {
417
+ var _info_cb1;
418
+ var res = prev(event);
419
+ info == null ? void 0 : (_info_cb1 = info.cb) == null ? void 0 : _info_cb1.call(info);
420
+ return res;
421
+ }
422
+ }
423
+ info == null ? void 0 : (_info_cb = info.cb) == null ? void 0 : _info_cb.call(info);
424
+ };
425
+ script.onerror = onScriptComplete.bind(null, script.onerror);
426
+ script.onload = onScriptComplete.bind(null, script.onload);
427
+ timeoutId = setTimeout(function() {
428
+ onScriptComplete(null, new Error('Remote script "'.concat(info.url, '" time-outed.')));
429
+ }, timeout);
430
+ return {
431
+ script: script,
432
+ needAttach: needAttach
433
+ };
434
+ }
435
+ function createLink(info) {
436
+ var link = null;
437
+ var needAttach = true;
438
+ var links = document.getElementsByTagName('link');
439
+ for(var i = 0; i < links.length; i++){
440
+ var l = links[i];
441
+ var linkHref = l.getAttribute('href');
442
+ var linkRef = l.getAttribute('ref');
443
+ if (linkHref && isStaticResourcesEqual(linkHref, info.url) && linkRef === info.attrs['ref']) {
444
+ link = l;
445
+ needAttach = false;
446
+ break;
447
+ }
448
+ }
449
+ if (!link) {
450
+ link = document.createElement('link');
451
+ link.setAttribute('href', info.url);
452
+ var createLinkRes = undefined;
453
+ var attrs = info.attrs;
454
+ if (info.createLinkHook) {
455
+ createLinkRes = info.createLinkHook(info.url, attrs);
456
+ if (_instanceof._(createLinkRes, HTMLLinkElement)) {
457
+ link = createLinkRes;
458
+ }
459
+ }
460
+ if (attrs && !createLinkRes) {
461
+ Object.keys(attrs).forEach(function(name) {
462
+ if (link && !link.getAttribute(name)) {
463
+ link.setAttribute(name, attrs[name]);
464
+ }
465
+ });
466
+ }
467
+ }
468
+ var onLinkComplete = function(prev, event) {
469
+ if (link) {
470
+ link.onerror = null;
471
+ link.onload = null;
472
+ safeWrapper(function() {
473
+ var _info_needDeleteLink = info.needDeleteLink, needDeleteLink = _info_needDeleteLink === void 0 ? true : _info_needDeleteLink;
474
+ if (needDeleteLink) {
475
+ (link == null ? void 0 : link.parentNode) && link.parentNode.removeChild(link);
476
+ }
477
+ });
478
+ if (prev) {
479
+ var res = prev(event);
480
+ info.cb();
481
+ return res;
482
+ }
483
+ }
484
+ info.cb();
485
+ };
486
+ link.onerror = onLinkComplete.bind(null, link.onerror);
487
+ link.onload = onLinkComplete.bind(null, link.onload);
488
+ return {
489
+ link: link,
490
+ needAttach: needAttach
491
+ };
492
+ }
493
+ function loadScript(url, info) {
494
+ var _info_attrs = info.attrs, attrs = _info_attrs === void 0 ? {} : _info_attrs, createScriptHook = info.createScriptHook;
495
+ return new Promise(function(resolve, _reject) {
496
+ var _createScript = createScript({
497
+ url: url,
498
+ cb: resolve,
499
+ attrs: _extends._({
500
+ fetchpriority: 'high'
501
+ }, attrs),
502
+ createScriptHook: createScriptHook,
503
+ needDeleteScript: true
504
+ }), script = _createScript.script, needAttach = _createScript.needAttach;
505
+ needAttach && document.head.appendChild(script);
506
+ });
507
+ }
508
+ function importNodeModule(name) {
509
+ if (!name) {
510
+ throw new Error('import specifier is required');
511
+ }
512
+ var importModule = new Function('name', "return import(name)");
513
+ return importModule(name).then(function(res) {
514
+ return res;
515
+ }).catch(function(error1) {
516
+ console.error("Error importing module ".concat(name, ":"), error1);
517
+ throw error1;
518
+ });
519
+ }
520
+ var loadNodeFetch = function() {
521
+ var _ref = _async_to_generator._(function() {
522
+ var fetchModule;
523
+ return _ts_generator._(this, function(_state) {
524
+ switch(_state.label){
525
+ case 0:
526
+ return [
527
+ 4,
528
+ importNodeModule('node-fetch')
529
+ ];
530
+ case 1:
531
+ fetchModule = _state.sent();
532
+ return [
533
+ 2,
534
+ fetchModule.default || fetchModule
535
+ ];
536
+ }
537
+ });
538
+ });
539
+ return function loadNodeFetch1() {
540
+ return _ref.apply(this, arguments);
541
+ };
542
+ }();
543
+ var lazyLoaderHookFetch = function() {
544
+ var _ref = _async_to_generator._(function(input, init) {
545
+ var loaderHooks, hook, res, fetchFunction, _tmp;
546
+ return _ts_generator._(this, function(_state) {
547
+ switch(_state.label){
548
+ case 0:
549
+ loaderHooks = __webpack_require__.federation.instance.loaderHook;
550
+ hook = function(url, init) {
551
+ return loaderHooks.lifecycle.fetch.emit(url, init);
552
+ };
553
+ return [
554
+ 4,
555
+ hook(input, init || {})
556
+ ];
557
+ case 1:
558
+ res = _state.sent();
559
+ if (!(!res || !_instanceof._(res, Response))) return [
560
+ 3,
561
+ 5
562
+ ];
563
+ if (!(typeof fetch === 'undefined')) return [
564
+ 3,
565
+ 3
566
+ ];
567
+ return [
568
+ 4,
569
+ loadNodeFetch()
570
+ ];
571
+ case 2:
572
+ _tmp = _state.sent();
573
+ return [
574
+ 3,
575
+ 4
576
+ ];
577
+ case 3:
578
+ _tmp = fetch;
579
+ _state.label = 4;
580
+ case 4:
581
+ fetchFunction = _tmp;
582
+ return [
583
+ 2,
584
+ fetchFunction(input, init || {})
585
+ ];
586
+ case 5:
587
+ return [
588
+ 2,
589
+ res
590
+ ];
591
+ }
592
+ });
593
+ });
594
+ return function lazyLoaderHookFetch1(input, init) {
595
+ return _ref.apply(this, arguments);
596
+ };
597
+ }();
598
+ function createScriptNode(url, cb, attrs, createScriptHook) {
599
+ if (createScriptHook) {
600
+ var hookResult = createScriptHook(url);
601
+ if (hookResult && (typeof hookResult === "undefined" ? "undefined" : _type_of._(hookResult)) === 'object' && 'url' in hookResult) {
602
+ url = hookResult.url;
603
+ }
604
+ }
605
+ var urlObj;
606
+ try {
607
+ urlObj = new URL(url);
608
+ } catch (e) {
609
+ console.error('Error constructing URL:', e);
610
+ cb(new Error("Invalid URL: ".concat(e)));
611
+ return;
612
+ }
613
+ var getFetch = function() {
614
+ var _ref = _async_to_generator._(function() {
615
+ var loaderHooks;
616
+ return _ts_generator._(this, function(_state) {
617
+ if (typeof __webpack_require__ !== 'undefined') {
618
+ try {
619
+ loaderHooks = __webpack_require__.federation.instance.loaderHook;
620
+ if (loaderHooks.lifecycle.fetch) {
621
+ return [
622
+ 2,
623
+ lazyLoaderHookFetch
624
+ ];
625
+ }
626
+ } catch (e) {
627
+ console.warn('federation.instance.loaderHook.lifecycle.fetch failed:', e);
628
+ }
629
+ }
630
+ return [
631
+ 2,
632
+ typeof fetch === 'undefined' ? loadNodeFetch() : fetch
633
+ ];
634
+ });
635
+ });
636
+ return function getFetch() {
637
+ return _ref.apply(this, arguments);
638
+ };
639
+ }();
640
+ var handleScriptFetch = function() {
641
+ var _ref = _async_to_generator._(function(f, urlObj) {
642
+ var _vm_constants, res, data, _ref, path, vm, scriptContext, urlDirname, filename, _vm_constants_USE_MAIN_CONTEXT_DEFAULT_LOADER, script, exportedInterface, container, e;
643
+ return _ts_generator._(this, function(_state) {
644
+ switch(_state.label){
645
+ case 0:
646
+ _state.trys.push([
647
+ 0,
648
+ 4,
649
+ ,
650
+ 5
651
+ ]);
652
+ return [
653
+ 4,
654
+ f(urlObj.href)
655
+ ];
656
+ case 1:
657
+ res = _state.sent();
658
+ return [
659
+ 4,
660
+ res.text()
661
+ ];
662
+ case 2:
663
+ data = _state.sent();
664
+ return [
665
+ 4,
666
+ Promise.all([
667
+ importNodeModule('path'),
668
+ importNodeModule('vm')
669
+ ])
670
+ ];
671
+ case 3:
672
+ _ref = _sliced_to_array._.apply(void 0, [
673
+ _state.sent(),
674
+ 2
675
+ ]), path = _ref[0], vm = _ref[1];
676
+ scriptContext = {
677
+ exports: {},
678
+ module: {
679
+ exports: {}
680
+ }
681
+ };
682
+ urlDirname = urlObj.pathname.split('/').slice(0, -1).join('/');
683
+ filename = path.basename(urlObj.pathname);
684
+ script = new vm.Script("(function(exports, module, require, __dirname, __filename) {".concat(data, "\n})"), {
685
+ filename: filename,
686
+ importModuleDynamically: (_vm_constants_USE_MAIN_CONTEXT_DEFAULT_LOADER = (_vm_constants = vm.constants) == null ? void 0 : _vm_constants.USE_MAIN_CONTEXT_DEFAULT_LOADER) != null ? _vm_constants_USE_MAIN_CONTEXT_DEFAULT_LOADER : importNodeModule
687
+ });
688
+ script.runInThisContext()(scriptContext.exports, scriptContext.module, eval('require'), urlDirname, filename);
689
+ exportedInterface = scriptContext.module.exports || scriptContext.exports;
690
+ if (attrs && exportedInterface && attrs['globalName']) {
691
+ container = exportedInterface[attrs['globalName']] || exportedInterface;
692
+ cb(undefined, container);
693
+ return [
694
+ 2
695
+ ];
696
+ }
697
+ cb(undefined, exportedInterface);
698
+ return [
699
+ 3,
700
+ 5
701
+ ];
702
+ case 4:
703
+ e = _state.sent();
704
+ cb(_instanceof._(e, Error) ? e : new Error("Script execution error: ".concat(e)));
705
+ return [
706
+ 3,
707
+ 5
708
+ ];
709
+ case 5:
710
+ return [
711
+ 2
712
+ ];
713
+ }
714
+ });
715
+ });
716
+ return function handleScriptFetch(f, urlObj) {
717
+ return _ref.apply(this, arguments);
718
+ };
719
+ }();
720
+ getFetch().then(function(f) {
721
+ return handleScriptFetch(f, urlObj);
722
+ }).catch(function(err) {
723
+ cb(err);
724
+ });
725
+ }
726
+ function loadScriptNode(url, info) {
727
+ return new Promise(function(resolve, reject) {
728
+ createScriptNode(url, function(error1, scriptContext) {
729
+ if (error1) {
730
+ reject(error1);
731
+ } else {
732
+ var _info_attrs, _info_attrs1;
733
+ var remoteEntryKey = (info == null ? void 0 : (_info_attrs = info.attrs) == null ? void 0 : _info_attrs['globalName']) || "__FEDERATION_".concat(info == null ? void 0 : (_info_attrs1 = info.attrs) == null ? void 0 : _info_attrs1['name'], ":custom__");
734
+ var entryExports = globalThis[remoteEntryKey] = scriptContext;
735
+ resolve(entryExports);
736
+ }
737
+ }, info.attrs, info.createScriptHook);
738
+ });
739
+ }
740
+
741
+ function getBuilderId() {
742
+ return typeof FEDERATION_BUILD_IDENTIFIER !== 'undefined' ? FEDERATION_BUILD_IDENTIFIER : '';
743
+ }
744
+ var LOG_CATEGORY = '[ Federation Runtime ]';
745
+ function assert(condition, msg) {
746
+ if (!condition) {
747
+ error(msg);
748
+ }
749
+ }
750
+ function error(msg) {
751
+ if (_instanceof._(msg, Error)) {
752
+ msg.message = "".concat(LOG_CATEGORY, ": ").concat(msg.message);
753
+ throw msg;
754
+ }
755
+ throw new Error("".concat(LOG_CATEGORY, ": ").concat(msg));
756
+ }
757
+ function warn(msg) {
758
+ if (_instanceof._(msg, Error)) {
759
+ msg.message = "".concat(LOG_CATEGORY, ": ").concat(msg.message);
760
+ console.warn(msg);
761
+ } else {
762
+ console.warn("".concat(LOG_CATEGORY, ": ").concat(msg));
763
+ }
764
+ }
765
+ function addUniqueItem(arr, item) {
766
+ if (arr.findIndex(function(name) {
767
+ return name === item;
768
+ }) === -1) {
769
+ arr.push(item);
770
+ }
771
+ return arr;
772
+ }
773
+ function getFMId(remoteInfo) {
774
+ if ('version' in remoteInfo && remoteInfo.version) {
775
+ return "".concat(remoteInfo.name, ":").concat(remoteInfo.version);
776
+ } else if ('entry' in remoteInfo && remoteInfo.entry) {
777
+ return "".concat(remoteInfo.name, ":").concat(remoteInfo.entry);
778
+ } else {
779
+ return "".concat(remoteInfo.name);
780
+ }
781
+ }
782
+ function isRemoteInfoWithEntry(remote) {
783
+ return typeof remote.entry !== 'undefined';
784
+ }
785
+ function isPureRemoteEntry(remote) {
786
+ return !remote.entry.includes('.json') && remote.entry.includes('.js');
787
+ }
788
+ function isObject(val) {
789
+ return val && (typeof val === "undefined" ? "undefined" : _type_of._(val)) === 'object';
790
+ }
791
+ var objectToString = Object.prototype.toString;
792
+ function isPlainObject(val) {
793
+ return objectToString.call(val) === '[object Object]';
794
+ }
795
+ function arrayOptions(options) {
796
+ return Array.isArray(options) ? options : [
797
+ options
798
+ ];
799
+ }
800
+ function getRemoteEntryInfoFromSnapshot(snapshot) {
801
+ var defaultRemoteEntryInfo = {
802
+ url: '',
803
+ type: 'global',
804
+ globalName: ''
805
+ };
806
+ if (isBrowserEnv()) {
807
+ return 'remoteEntry' in snapshot ? {
808
+ url: snapshot.remoteEntry,
809
+ type: snapshot.remoteEntryType,
810
+ globalName: snapshot.globalName
811
+ } : defaultRemoteEntryInfo;
812
+ }
813
+ if ('ssrRemoteEntry' in snapshot) {
814
+ return {
815
+ url: snapshot.ssrRemoteEntry || defaultRemoteEntryInfo.url,
816
+ type: snapshot.ssrRemoteEntryType || defaultRemoteEntryInfo.type,
817
+ globalName: snapshot.globalName
818
+ };
819
+ }
820
+ return defaultRemoteEntryInfo;
821
+ }
822
+ var nativeGlobal = function() {
823
+ try {
824
+ return new Function('return this')();
825
+ } catch (e) {
826
+ return globalThis;
827
+ }
828
+ }();
829
+ var Global = nativeGlobal;
830
+ function definePropertyGlobalVal(target, key, val) {
831
+ Object.defineProperty(target, key, {
832
+ value: val,
833
+ configurable: false,
834
+ writable: true
835
+ });
836
+ }
837
+ function includeOwnProperty(target, key) {
838
+ return Object.hasOwnProperty.call(target, key);
839
+ }
840
+ if (!includeOwnProperty(globalThis, '__GLOBAL_LOADING_REMOTE_ENTRY__')) {
841
+ definePropertyGlobalVal(globalThis, '__GLOBAL_LOADING_REMOTE_ENTRY__', {});
842
+ }
843
+ var globalLoading = globalThis.__GLOBAL_LOADING_REMOTE_ENTRY__;
844
+ function setGlobalDefaultVal(target) {
845
+ var _target___FEDERATION__, _target___FEDERATION__1, _target___FEDERATION__2, _target___FEDERATION__3, _target___FEDERATION__4, _target___FEDERATION__5;
846
+ if (includeOwnProperty(target, '__VMOK__') && !includeOwnProperty(target, '__FEDERATION__')) {
847
+ definePropertyGlobalVal(target, '__FEDERATION__', target.__VMOK__);
848
+ }
849
+ if (!includeOwnProperty(target, '__FEDERATION__')) {
850
+ definePropertyGlobalVal(target, '__FEDERATION__', {
851
+ __GLOBAL_PLUGIN__: [],
852
+ __INSTANCES__: [],
853
+ moduleInfo: {},
854
+ __SHARE__: {},
855
+ __MANIFEST_LOADING__: {},
856
+ __PRELOADED_MAP__: new Map()
857
+ });
858
+ definePropertyGlobalVal(target, '__VMOK__', target.__FEDERATION__);
859
+ }
860
+ var ___GLOBAL_PLUGIN__;
861
+ (___GLOBAL_PLUGIN__ = (_target___FEDERATION__ = target.__FEDERATION__).__GLOBAL_PLUGIN__) != null ? ___GLOBAL_PLUGIN__ : _target___FEDERATION__.__GLOBAL_PLUGIN__ = [];
862
+ var ___INSTANCES__;
863
+ (___INSTANCES__ = (_target___FEDERATION__1 = target.__FEDERATION__).__INSTANCES__) != null ? ___INSTANCES__ : _target___FEDERATION__1.__INSTANCES__ = [];
864
+ var _moduleInfo;
865
+ (_moduleInfo = (_target___FEDERATION__2 = target.__FEDERATION__).moduleInfo) != null ? _moduleInfo : _target___FEDERATION__2.moduleInfo = {};
866
+ var ___SHARE__;
867
+ (___SHARE__ = (_target___FEDERATION__3 = target.__FEDERATION__).__SHARE__) != null ? ___SHARE__ : _target___FEDERATION__3.__SHARE__ = {};
868
+ var ___MANIFEST_LOADING__;
869
+ (___MANIFEST_LOADING__ = (_target___FEDERATION__4 = target.__FEDERATION__).__MANIFEST_LOADING__) != null ? ___MANIFEST_LOADING__ : _target___FEDERATION__4.__MANIFEST_LOADING__ = {};
870
+ var ___PRELOADED_MAP__;
871
+ (___PRELOADED_MAP__ = (_target___FEDERATION__5 = target.__FEDERATION__).__PRELOADED_MAP__) != null ? ___PRELOADED_MAP__ : _target___FEDERATION__5.__PRELOADED_MAP__ = new Map();
872
+ }
873
+ setGlobalDefaultVal(globalThis);
874
+ setGlobalDefaultVal(nativeGlobal);
875
+ function getGlobalFederationInstance(name, version) {
876
+ var buildId = getBuilderId();
877
+ return globalThis.__FEDERATION__.__INSTANCES__.find(function(GMInstance) {
878
+ if (buildId && GMInstance.options.id === getBuilderId()) {
879
+ return true;
880
+ }
881
+ if (GMInstance.options.name === name && !GMInstance.options.version && !version) {
882
+ return true;
883
+ }
884
+ if (GMInstance.options.name === name && version && GMInstance.options.version === version) {
885
+ return true;
886
+ }
887
+ return false;
888
+ });
889
+ }
890
+ function setGlobalFederationInstance(FederationInstance) {
891
+ globalThis.__FEDERATION__.__INSTANCES__.push(FederationInstance);
892
+ }
893
+ function getGlobalFederationConstructor() {
894
+ return globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__;
895
+ }
896
+ function setGlobalFederationConstructor(FederationConstructor) {
897
+ var isDebug = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : isDebugMode();
898
+ if (isDebug) {
899
+ globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
900
+ globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.5.1";
901
+ }
902
+ }
903
+ function getInfoWithoutType(target, key) {
904
+ if (typeof key === 'string') {
905
+ var keyRes = target[key];
906
+ if (keyRes) {
907
+ return {
908
+ value: target[key],
909
+ key: key
910
+ };
911
+ } else {
912
+ var targetKeys = Object.keys(target);
913
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
914
+ try {
915
+ for(var _iterator = targetKeys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
916
+ var targetKey = _step.value;
917
+ var _targetKey_split = _sliced_to_array._(targetKey.split(':'), 2), targetTypeOrName = _targetKey_split[0], _ = _targetKey_split[1];
918
+ var nKey = "".concat(targetTypeOrName, ":").concat(key);
919
+ var typeWithKeyRes = target[nKey];
920
+ if (typeWithKeyRes) {
921
+ return {
922
+ value: typeWithKeyRes,
923
+ key: nKey
924
+ };
925
+ }
926
+ }
927
+ } catch (err) {
928
+ _didIteratorError = true;
929
+ _iteratorError = err;
930
+ } finally{
931
+ try {
932
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
933
+ _iterator.return();
934
+ }
935
+ } finally{
936
+ if (_didIteratorError) {
937
+ throw _iteratorError;
938
+ }
939
+ }
940
+ }
941
+ return {
942
+ value: undefined,
943
+ key: key
944
+ };
945
+ }
946
+ } else {
947
+ throw new Error('key must be string');
948
+ }
949
+ }
950
+ var getGlobalSnapshot = function() {
951
+ return nativeGlobal.__FEDERATION__.moduleInfo;
952
+ };
953
+ var getTargetSnapshotInfoByModuleInfo = function(moduleInfo, snapshot) {
954
+ var moduleKey = getFMId(moduleInfo);
955
+ var getModuleInfo = getInfoWithoutType(snapshot, moduleKey).value;
956
+ if (getModuleInfo && !getModuleInfo.version && 'version' in moduleInfo && moduleInfo['version']) {
957
+ getModuleInfo.version = moduleInfo['version'];
958
+ }
959
+ if (getModuleInfo) {
960
+ return getModuleInfo;
961
+ }
962
+ if ('version' in moduleInfo && moduleInfo['version']) {
963
+ var version = moduleInfo.version, resModuleInfo = _object_without_properties_loose._(moduleInfo, [
964
+ "version"
965
+ ]);
966
+ var moduleKeyWithoutVersion = getFMId(resModuleInfo);
967
+ var getModuleInfoWithoutVersion = getInfoWithoutType(nativeGlobal.__FEDERATION__.moduleInfo, moduleKeyWithoutVersion).value;
968
+ if ((getModuleInfoWithoutVersion == null ? void 0 : getModuleInfoWithoutVersion.version) === version) {
969
+ return getModuleInfoWithoutVersion;
970
+ }
971
+ }
972
+ return;
973
+ };
974
+ var getGlobalSnapshotInfoByModuleInfo = function(moduleInfo) {
975
+ return getTargetSnapshotInfoByModuleInfo(moduleInfo, nativeGlobal.__FEDERATION__.moduleInfo);
976
+ };
977
+ var setGlobalSnapshotInfoByModuleInfo = function(remoteInfo, moduleDetailInfo) {
978
+ var moduleKey = getFMId(remoteInfo);
979
+ nativeGlobal.__FEDERATION__.moduleInfo[moduleKey] = moduleDetailInfo;
980
+ return nativeGlobal.__FEDERATION__.moduleInfo;
981
+ };
982
+ var addGlobalSnapshot = function(moduleInfos) {
983
+ nativeGlobal.__FEDERATION__.moduleInfo = _extends._({}, nativeGlobal.__FEDERATION__.moduleInfo, moduleInfos);
984
+ return function() {
985
+ var keys = Object.keys(moduleInfos);
986
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
987
+ try {
988
+ for(var _iterator = keys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
989
+ var key = _step.value;
990
+ delete nativeGlobal.__FEDERATION__.moduleInfo[key];
991
+ }
992
+ } catch (err) {
993
+ _didIteratorError = true;
994
+ _iteratorError = err;
995
+ } finally{
996
+ try {
997
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
998
+ _iterator.return();
999
+ }
1000
+ } finally{
1001
+ if (_didIteratorError) {
1002
+ throw _iteratorError;
1003
+ }
1004
+ }
1005
+ }
1006
+ };
1007
+ };
1008
+ var getRemoteEntryExports = function(name, globalName) {
1009
+ var remoteEntryKey = globalName || "__FEDERATION_".concat(name, ":custom__");
1010
+ var entryExports = globalThis[remoteEntryKey];
1011
+ return {
1012
+ remoteEntryKey: remoteEntryKey,
1013
+ entryExports: entryExports
1014
+ };
1015
+ };
1016
+ var registerGlobalPlugins = function(plugins) {
1017
+ var __GLOBAL_PLUGIN__ = nativeGlobal.__FEDERATION__.__GLOBAL_PLUGIN__;
1018
+ plugins.forEach(function(plugin) {
1019
+ if (__GLOBAL_PLUGIN__.findIndex(function(p) {
1020
+ return p.name === plugin.name;
1021
+ }) === -1) {
1022
+ __GLOBAL_PLUGIN__.push(plugin);
1023
+ } else {
1024
+ warn("The plugin ".concat(plugin.name, " has been registered."));
1025
+ }
1026
+ });
1027
+ };
1028
+ var getGlobalHostPlugins = function() {
1029
+ return nativeGlobal.__FEDERATION__.__GLOBAL_PLUGIN__;
1030
+ };
1031
+ var getPreloaded = function(id) {
1032
+ return globalThis.__FEDERATION__.__PRELOADED_MAP__.get(id);
1033
+ };
1034
+ var setPreloaded = function(id) {
1035
+ return globalThis.__FEDERATION__.__PRELOADED_MAP__.set(id, true);
1036
+ };
1037
+ var DEFAULT_SCOPE = 'default';
1038
+ var DEFAULT_REMOTE_TYPE = 'global';
1039
+ var buildIdentifier = '[0-9A-Za-z-]+';
1040
+ var build = "(?:\\+(".concat(buildIdentifier, "(?:\\.").concat(buildIdentifier, ")*))");
1041
+ var numericIdentifier = '0|[1-9]\\d*';
1042
+ var numericIdentifierLoose = '[0-9]+';
1043
+ var nonNumericIdentifier = '\\d*[a-zA-Z-][a-zA-Z0-9-]*';
1044
+ var preReleaseIdentifierLoose = "(?:".concat(numericIdentifierLoose, "|").concat(nonNumericIdentifier, ")");
1045
+ var preReleaseLoose = "(?:-?(".concat(preReleaseIdentifierLoose, "(?:\\.").concat(preReleaseIdentifierLoose, ")*))");
1046
+ var preReleaseIdentifier = "(?:".concat(numericIdentifier, "|").concat(nonNumericIdentifier, ")");
1047
+ var preRelease = "(?:-(".concat(preReleaseIdentifier, "(?:\\.").concat(preReleaseIdentifier, ")*))");
1048
+ var xRangeIdentifier = "".concat(numericIdentifier, "|x|X|\\*");
1049
+ var xRangePlain = "[v=\\s]*(".concat(xRangeIdentifier, ")(?:\\.(").concat(xRangeIdentifier, ")(?:\\.(").concat(xRangeIdentifier, ")(?:").concat(preRelease, ")?").concat(build, "?)?)?");
1050
+ var hyphenRange = "^\\s*(".concat(xRangePlain, ")\\s+-\\s+(").concat(xRangePlain, ")\\s*$");
1051
+ var mainVersionLoose = "(".concat(numericIdentifierLoose, ")\\.(").concat(numericIdentifierLoose, ")\\.(").concat(numericIdentifierLoose, ")");
1052
+ var loosePlain = "[v=\\s]*".concat(mainVersionLoose).concat(preReleaseLoose, "?").concat(build, "?");
1053
+ var gtlt = '((?:<|>)?=?)';
1054
+ var comparatorTrim = "(\\s*)".concat(gtlt, "\\s*(").concat(loosePlain, "|").concat(xRangePlain, ")");
1055
+ var loneTilde = '(?:~>?)';
1056
+ var tildeTrim = "(\\s*)".concat(loneTilde, "\\s+");
1057
+ var loneCaret = '(?:\\^)';
1058
+ var caretTrim = "(\\s*)".concat(loneCaret, "\\s+");
1059
+ var star = '(<|>)?=?\\s*\\*';
1060
+ var caret = "^".concat(loneCaret).concat(xRangePlain, "$");
1061
+ var mainVersion = "(".concat(numericIdentifier, ")\\.(").concat(numericIdentifier, ")\\.(").concat(numericIdentifier, ")");
1062
+ var fullPlain = "v?".concat(mainVersion).concat(preRelease, "?").concat(build, "?");
1063
+ var tilde = "^".concat(loneTilde).concat(xRangePlain, "$");
1064
+ var xRange = "^".concat(gtlt, "\\s*").concat(xRangePlain, "$");
1065
+ var comparator = "^".concat(gtlt, "\\s*(").concat(fullPlain, ")$|^$");
1066
+ var gte0 = '^\\s*>=\\s*0.0.0\\s*$';
1067
+ function parseRegex(source) {
1068
+ return new RegExp(source);
1069
+ }
1070
+ function isXVersion(version) {
1071
+ return !version || version.toLowerCase() === 'x' || version === '*';
1072
+ }
1073
+ function pipe() {
1074
+ for(var _len = arguments.length, fns = new Array(_len), _key = 0; _key < _len; _key++){
1075
+ fns[_key] = arguments[_key];
1076
+ }
1077
+ return function(x) {
1078
+ return fns.reduce(function(v, f) {
1079
+ return f(v);
1080
+ }, x);
1081
+ };
1082
+ }
1083
+ function extractComparator(comparatorString) {
1084
+ return comparatorString.match(parseRegex(comparator));
1085
+ }
1086
+ function combineVersion(major, minor, patch, preRelease) {
1087
+ var mainVersion = "".concat(major, ".").concat(minor, ".").concat(patch);
1088
+ if (preRelease) {
1089
+ return "".concat(mainVersion, "-").concat(preRelease);
1090
+ }
1091
+ return mainVersion;
1092
+ }
1093
+ function parseHyphen(range) {
1094
+ return range.replace(parseRegex(hyphenRange), function(_range, from, fromMajor, fromMinor, fromPatch, _fromPreRelease, _fromBuild, to, toMajor, toMinor, toPatch, toPreRelease) {
1095
+ if (isXVersion(fromMajor)) {
1096
+ from = '';
1097
+ } else if (isXVersion(fromMinor)) {
1098
+ from = ">=".concat(fromMajor, ".0.0");
1099
+ } else if (isXVersion(fromPatch)) {
1100
+ from = ">=".concat(fromMajor, ".").concat(fromMinor, ".0");
1101
+ } else {
1102
+ from = ">=".concat(from);
1103
+ }
1104
+ if (isXVersion(toMajor)) {
1105
+ to = '';
1106
+ } else if (isXVersion(toMinor)) {
1107
+ to = "<".concat(Number(toMajor) + 1, ".0.0-0");
1108
+ } else if (isXVersion(toPatch)) {
1109
+ to = "<".concat(toMajor, ".").concat(Number(toMinor) + 1, ".0-0");
1110
+ } else if (toPreRelease) {
1111
+ to = "<=".concat(toMajor, ".").concat(toMinor, ".").concat(toPatch, "-").concat(toPreRelease);
1112
+ } else {
1113
+ to = "<=".concat(to);
1114
+ }
1115
+ return "".concat(from, " ").concat(to).trim();
1116
+ });
1117
+ }
1118
+ function parseComparatorTrim(range) {
1119
+ return range.replace(parseRegex(comparatorTrim), '$1$2$3');
1120
+ }
1121
+ function parseTildeTrim(range) {
1122
+ return range.replace(parseRegex(tildeTrim), '$1~');
1123
+ }
1124
+ function parseCaretTrim(range) {
1125
+ return range.replace(parseRegex(caretTrim), '$1^');
1126
+ }
1127
+ function parseCarets(range) {
1128
+ return range.trim().split(/\s+/).map(function(rangeVersion) {
1129
+ return rangeVersion.replace(parseRegex(caret), function(_, major, minor, patch, preRelease) {
1130
+ if (isXVersion(major)) {
1131
+ return '';
1132
+ } else if (isXVersion(minor)) {
1133
+ return ">=".concat(major, ".0.0 <").concat(Number(major) + 1, ".0.0-0");
1134
+ } else if (isXVersion(patch)) {
1135
+ if (major === '0') {
1136
+ return ">=".concat(major, ".").concat(minor, ".0 <").concat(major, ".").concat(Number(minor) + 1, ".0-0");
1137
+ } else {
1138
+ return ">=".concat(major, ".").concat(minor, ".0 <").concat(Number(major) + 1, ".0.0-0");
1139
+ }
1140
+ } else if (preRelease) {
1141
+ if (major === '0') {
1142
+ if (minor === '0') {
1143
+ return ">=".concat(major, ".").concat(minor, ".").concat(patch, "-").concat(preRelease, " <").concat(major, ".").concat(minor, ".").concat(Number(patch) + 1, "-0");
1144
+ } else {
1145
+ return ">=".concat(major, ".").concat(minor, ".").concat(patch, "-").concat(preRelease, " <").concat(major, ".").concat(Number(minor) + 1, ".0-0");
1146
+ }
1147
+ } else {
1148
+ return ">=".concat(major, ".").concat(minor, ".").concat(patch, "-").concat(preRelease, " <").concat(Number(major) + 1, ".0.0-0");
1149
+ }
1150
+ } else {
1151
+ if (major === '0') {
1152
+ if (minor === '0') {
1153
+ return ">=".concat(major, ".").concat(minor, ".").concat(patch, " <").concat(major, ".").concat(minor, ".").concat(Number(patch) + 1, "-0");
1154
+ } else {
1155
+ return ">=".concat(major, ".").concat(minor, ".").concat(patch, " <").concat(major, ".").concat(Number(minor) + 1, ".0-0");
1156
+ }
1157
+ }
1158
+ return ">=".concat(major, ".").concat(minor, ".").concat(patch, " <").concat(Number(major) + 1, ".0.0-0");
1159
+ }
1160
+ });
1161
+ }).join(' ');
1162
+ }
1163
+ function parseTildes(range) {
1164
+ return range.trim().split(/\s+/).map(function(rangeVersion) {
1165
+ return rangeVersion.replace(parseRegex(tilde), function(_, major, minor, patch, preRelease) {
1166
+ if (isXVersion(major)) {
1167
+ return '';
1168
+ } else if (isXVersion(minor)) {
1169
+ return ">=".concat(major, ".0.0 <").concat(Number(major) + 1, ".0.0-0");
1170
+ } else if (isXVersion(patch)) {
1171
+ return ">=".concat(major, ".").concat(minor, ".0 <").concat(major, ".").concat(Number(minor) + 1, ".0-0");
1172
+ } else if (preRelease) {
1173
+ return ">=".concat(major, ".").concat(minor, ".").concat(patch, "-").concat(preRelease, " <").concat(major, ".").concat(Number(minor) + 1, ".0-0");
1174
+ }
1175
+ return ">=".concat(major, ".").concat(minor, ".").concat(patch, " <").concat(major, ".").concat(Number(minor) + 1, ".0-0");
1176
+ });
1177
+ }).join(' ');
1178
+ }
1179
+ function parseXRanges(range) {
1180
+ return range.split(/\s+/).map(function(rangeVersion) {
1181
+ return rangeVersion.trim().replace(parseRegex(xRange), function(ret, gtlt, major, minor, patch, preRelease) {
1182
+ var isXMajor = isXVersion(major);
1183
+ var isXMinor = isXMajor || isXVersion(minor);
1184
+ var isXPatch = isXMinor || isXVersion(patch);
1185
+ if (gtlt === '=' && isXPatch) {
1186
+ gtlt = '';
1187
+ }
1188
+ preRelease = '';
1189
+ if (isXMajor) {
1190
+ if (gtlt === '>' || gtlt === '<') {
1191
+ return '<0.0.0-0';
1192
+ } else {
1193
+ return '*';
1194
+ }
1195
+ } else if (gtlt && isXPatch) {
1196
+ if (isXMinor) {
1197
+ minor = 0;
1198
+ }
1199
+ patch = 0;
1200
+ if (gtlt === '>') {
1201
+ gtlt = '>=';
1202
+ if (isXMinor) {
1203
+ major = Number(major) + 1;
1204
+ minor = 0;
1205
+ patch = 0;
1206
+ } else {
1207
+ minor = Number(minor) + 1;
1208
+ patch = 0;
1209
+ }
1210
+ } else if (gtlt === '<=') {
1211
+ gtlt = '<';
1212
+ if (isXMinor) {
1213
+ major = Number(major) + 1;
1214
+ } else {
1215
+ minor = Number(minor) + 1;
1216
+ }
1217
+ }
1218
+ if (gtlt === '<') {
1219
+ preRelease = '-0';
1220
+ }
1221
+ return "".concat(gtlt + major, ".").concat(minor, ".").concat(patch).concat(preRelease);
1222
+ } else if (isXMinor) {
1223
+ return ">=".concat(major, ".0.0").concat(preRelease, " <").concat(Number(major) + 1, ".0.0-0");
1224
+ } else if (isXPatch) {
1225
+ return ">=".concat(major, ".").concat(minor, ".0").concat(preRelease, " <").concat(major, ".").concat(Number(minor) + 1, ".0-0");
1226
+ }
1227
+ return ret;
1228
+ });
1229
+ }).join(' ');
1230
+ }
1231
+ function parseStar(range) {
1232
+ return range.trim().replace(parseRegex(star), '');
1233
+ }
1234
+ function parseGTE0(comparatorString) {
1235
+ return comparatorString.trim().replace(parseRegex(gte0), '');
1236
+ }
1237
+ function compareAtom(rangeAtom, versionAtom) {
1238
+ rangeAtom = Number(rangeAtom) || rangeAtom;
1239
+ versionAtom = Number(versionAtom) || versionAtom;
1240
+ if (rangeAtom > versionAtom) {
1241
+ return 1;
1242
+ }
1243
+ if (rangeAtom === versionAtom) {
1244
+ return 0;
1245
+ }
1246
+ return -1;
1247
+ }
1248
+ function comparePreRelease(rangeAtom, versionAtom) {
1249
+ var rangePreRelease = rangeAtom.preRelease;
1250
+ var versionPreRelease = versionAtom.preRelease;
1251
+ if (rangePreRelease === undefined && Boolean(versionPreRelease)) {
1252
+ return 1;
1253
+ }
1254
+ if (Boolean(rangePreRelease) && versionPreRelease === undefined) {
1255
+ return -1;
1256
+ }
1257
+ if (rangePreRelease === undefined && versionPreRelease === undefined) {
1258
+ return 0;
1259
+ }
1260
+ for(var i = 0, n = rangePreRelease.length; i <= n; i++){
1261
+ var rangeElement = rangePreRelease[i];
1262
+ var versionElement = versionPreRelease[i];
1263
+ if (rangeElement === versionElement) {
1264
+ continue;
1265
+ }
1266
+ if (rangeElement === undefined && versionElement === undefined) {
1267
+ return 0;
1268
+ }
1269
+ if (!rangeElement) {
1270
+ return 1;
1271
+ }
1272
+ if (!versionElement) {
1273
+ return -1;
1274
+ }
1275
+ return compareAtom(rangeElement, versionElement);
1276
+ }
1277
+ return 0;
1278
+ }
1279
+ function compareVersion(rangeAtom, versionAtom) {
1280
+ return compareAtom(rangeAtom.major, versionAtom.major) || compareAtom(rangeAtom.minor, versionAtom.minor) || compareAtom(rangeAtom.patch, versionAtom.patch) || comparePreRelease(rangeAtom, versionAtom);
1281
+ }
1282
+ function eq(rangeAtom, versionAtom) {
1283
+ return rangeAtom.version === versionAtom.version;
1284
+ }
1285
+ function compare(rangeAtom, versionAtom) {
1286
+ switch(rangeAtom.operator){
1287
+ case '':
1288
+ case '=':
1289
+ return eq(rangeAtom, versionAtom);
1290
+ case '>':
1291
+ return compareVersion(rangeAtom, versionAtom) < 0;
1292
+ case '>=':
1293
+ return eq(rangeAtom, versionAtom) || compareVersion(rangeAtom, versionAtom) < 0;
1294
+ case '<':
1295
+ return compareVersion(rangeAtom, versionAtom) > 0;
1296
+ case '<=':
1297
+ return eq(rangeAtom, versionAtom) || compareVersion(rangeAtom, versionAtom) > 0;
1298
+ case undefined:
1299
+ {
1300
+ return true;
1301
+ }
1302
+ default:
1303
+ return false;
1304
+ }
1305
+ }
1306
+ function parseComparatorString(range) {
1307
+ return pipe(parseCarets, parseTildes, parseXRanges, parseStar)(range);
1308
+ }
1309
+ function parseRange(range) {
1310
+ return pipe(parseHyphen, parseComparatorTrim, parseTildeTrim, parseCaretTrim)(range.trim()).split(/\s+/).join(' ');
1311
+ }
1312
+ function satisfy(version, range) {
1313
+ if (!version) {
1314
+ return false;
1315
+ }
1316
+ var parsedRange = parseRange(range);
1317
+ var parsedComparator = parsedRange.split(' ').map(function(rangeVersion) {
1318
+ return parseComparatorString(rangeVersion);
1319
+ }).join(' ');
1320
+ var comparators = parsedComparator.split(/\s+/).map(function(comparator) {
1321
+ return parseGTE0(comparator);
1322
+ });
1323
+ var extractedVersion = extractComparator(version);
1324
+ if (!extractedVersion) {
1325
+ return false;
1326
+ }
1327
+ var _extractedVersion = _sliced_to_array._(extractedVersion, 7), versionOperator = _extractedVersion[1], versionMajor = _extractedVersion[3], versionMinor = _extractedVersion[4], versionPatch = _extractedVersion[5], versionPreRelease = _extractedVersion[6];
1328
+ var versionAtom = {
1329
+ operator: versionOperator,
1330
+ version: combineVersion(versionMajor, versionMinor, versionPatch, versionPreRelease),
1331
+ major: versionMajor,
1332
+ minor: versionMinor,
1333
+ patch: versionPatch,
1334
+ preRelease: versionPreRelease == null ? void 0 : versionPreRelease.split('.')
1335
+ };
1336
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1337
+ try {
1338
+ for(var _iterator = comparators[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1339
+ var comparator = _step.value;
1340
+ var extractedComparator = extractComparator(comparator);
1341
+ if (!extractedComparator) {
1342
+ return false;
1343
+ }
1344
+ var _extractedComparator = _sliced_to_array._(extractedComparator, 7), rangeOperator = _extractedComparator[1], rangeMajor = _extractedComparator[3], rangeMinor = _extractedComparator[4], rangePatch = _extractedComparator[5], rangePreRelease = _extractedComparator[6];
1345
+ var rangeAtom = {
1346
+ operator: rangeOperator,
1347
+ version: combineVersion(rangeMajor, rangeMinor, rangePatch, rangePreRelease),
1348
+ major: rangeMajor,
1349
+ minor: rangeMinor,
1350
+ patch: rangePatch,
1351
+ preRelease: rangePreRelease == null ? void 0 : rangePreRelease.split('.')
1352
+ };
1353
+ if (!compare(rangeAtom, versionAtom)) {
1354
+ return false;
1355
+ }
1356
+ }
1357
+ } catch (err) {
1358
+ _didIteratorError = true;
1359
+ _iteratorError = err;
1360
+ } finally{
1361
+ try {
1362
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1363
+ _iterator.return();
1364
+ }
1365
+ } finally{
1366
+ if (_didIteratorError) {
1367
+ throw _iteratorError;
1368
+ }
1369
+ }
1370
+ }
1371
+ return true;
1372
+ }
1373
+ function formatShare(shareArgs, from, name, shareStrategy) {
1374
+ var get;
1375
+ if ('get' in shareArgs) {
1376
+ get = shareArgs.get;
1377
+ } else if ('lib' in shareArgs) {
1378
+ get = function() {
1379
+ return Promise.resolve(shareArgs.lib);
1380
+ };
1381
+ } else {
1382
+ get = function() {
1383
+ return Promise.resolve(function() {
1384
+ throw new Error("Can not get shared '".concat(name, "'!"));
1385
+ });
1386
+ };
1387
+ }
1388
+ if (shareArgs.strategy) {
1389
+ warn('"shared.strategy is deprecated, please set in initOptions.shareStrategy instead!"');
1390
+ }
1391
+ var _shareArgs_version, _shareArgs_scope, _shareArgs_strategy;
1392
+ return _extends._({
1393
+ deps: [],
1394
+ useIn: [],
1395
+ from: from,
1396
+ loading: null
1397
+ }, shareArgs, {
1398
+ shareConfig: _extends._({
1399
+ requiredVersion: "^".concat(shareArgs.version),
1400
+ singleton: false,
1401
+ eager: false,
1402
+ strictVersion: false
1403
+ }, shareArgs.shareConfig),
1404
+ get: get,
1405
+ loaded: (shareArgs == null ? void 0 : shareArgs.loaded) || 'lib' in shareArgs ? true : undefined,
1406
+ version: (_shareArgs_version = shareArgs.version) != null ? _shareArgs_version : '0',
1407
+ scope: Array.isArray(shareArgs.scope) ? shareArgs.scope : [
1408
+ (_shareArgs_scope = shareArgs.scope) != null ? _shareArgs_scope : 'default'
1409
+ ],
1410
+ strategy: ((_shareArgs_strategy = shareArgs.strategy) != null ? _shareArgs_strategy : shareStrategy) || 'version-first'
1411
+ });
1412
+ }
1413
+ function formatShareConfigs(globalOptions, userOptions) {
1414
+ var shareArgs = userOptions.shared || {};
1415
+ var from = userOptions.name;
1416
+ var shareInfos = Object.keys(shareArgs).reduce(function(res, pkgName) {
1417
+ var arrayShareArgs = arrayOptions(shareArgs[pkgName]);
1418
+ res[pkgName] = res[pkgName] || [];
1419
+ arrayShareArgs.forEach(function(shareConfig) {
1420
+ res[pkgName].push(formatShare(shareConfig, from, pkgName, userOptions.shareStrategy));
1421
+ });
1422
+ return res;
1423
+ }, {});
1424
+ var shared = _extends._({}, globalOptions.shared);
1425
+ Object.keys(shareInfos).forEach(function(shareKey) {
1426
+ if (!shared[shareKey]) {
1427
+ shared[shareKey] = shareInfos[shareKey];
1428
+ } else {
1429
+ shareInfos[shareKey].forEach(function(newUserSharedOptions) {
1430
+ var isSameVersion = shared[shareKey].find(function(sharedVal) {
1431
+ return sharedVal.version === newUserSharedOptions.version;
1432
+ });
1433
+ if (!isSameVersion) {
1434
+ shared[shareKey].push(newUserSharedOptions);
1435
+ }
1436
+ });
1437
+ }
1438
+ });
1439
+ return {
1440
+ shared: shared,
1441
+ shareInfos: shareInfos
1442
+ };
1443
+ }
1444
+ function versionLt(a, b) {
1445
+ var transformInvalidVersion = function(version) {
1446
+ var isNumberVersion = !Number.isNaN(Number(version));
1447
+ if (isNumberVersion) {
1448
+ var splitArr = version.split('.');
1449
+ var validVersion = version;
1450
+ for(var i = 0; i < 3 - splitArr.length; i++){
1451
+ validVersion += '.0';
1452
+ }
1453
+ return validVersion;
1454
+ }
1455
+ return version;
1456
+ };
1457
+ if (satisfy(transformInvalidVersion(a), "<=".concat(transformInvalidVersion(b)))) {
1458
+ return true;
1459
+ } else {
1460
+ return false;
1461
+ }
1462
+ }
1463
+ var findVersion = function(shareVersionMap, cb) {
1464
+ var callback = cb || function(prev, cur) {
1465
+ return versionLt(prev, cur);
1466
+ };
1467
+ return Object.keys(shareVersionMap).reduce(function(prev, cur) {
1468
+ if (!prev) {
1469
+ return cur;
1470
+ }
1471
+ if (callback(prev, cur)) {
1472
+ return cur;
1473
+ }
1474
+ if (prev === '0') {
1475
+ return cur;
1476
+ }
1477
+ return prev;
1478
+ }, 0);
1479
+ };
1480
+ var isLoaded = function(shared) {
1481
+ return Boolean(shared.loaded) || typeof shared.lib === 'function';
1482
+ };
1483
+ function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) {
1484
+ var versions = shareScopeMap[scope][pkgName];
1485
+ var callback = function callback(prev, cur) {
1486
+ return !isLoaded(versions[prev]) && versionLt(prev, cur);
1487
+ };
1488
+ return findVersion(shareScopeMap[scope][pkgName], callback);
1489
+ }
1490
+ function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
1491
+ var versions = shareScopeMap[scope][pkgName];
1492
+ var callback = function callback(prev, cur) {
1493
+ if (isLoaded(versions[cur])) {
1494
+ if (isLoaded(versions[prev])) {
1495
+ return Boolean(versionLt(prev, cur));
1496
+ } else {
1497
+ return true;
1498
+ }
1499
+ }
1500
+ if (isLoaded(versions[prev])) {
1501
+ return false;
1502
+ }
1503
+ return versionLt(prev, cur);
1504
+ };
1505
+ return findVersion(shareScopeMap[scope][pkgName], callback);
1506
+ }
1507
+ function getFindShareFunction(strategy) {
1508
+ if (strategy === 'loaded-first') {
1509
+ return findSingletonVersionOrderByLoaded;
1510
+ }
1511
+ return findSingletonVersionOrderByVersion;
1512
+ }
1513
+ function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare) {
1514
+ if (!localShareScopeMap) {
1515
+ return;
1516
+ }
1517
+ var shareConfig = shareInfo.shareConfig, _shareInfo_scope = shareInfo.scope, scope = _shareInfo_scope === void 0 ? DEFAULT_SCOPE : _shareInfo_scope, strategy = shareInfo.strategy;
1518
+ var scopes = Array.isArray(scope) ? scope : [
1519
+ scope
1520
+ ];
1521
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1522
+ try {
1523
+ var _loop = function() {
1524
+ var sc = _step.value;
1525
+ if (shareConfig && localShareScopeMap[sc] && localShareScopeMap[sc][pkgName]) {
1526
+ var requiredVersion = shareConfig.requiredVersion;
1527
+ var findShareFunction = getFindShareFunction(strategy);
1528
+ var maxOrSingletonVersion = findShareFunction(localShareScopeMap, sc, pkgName);
1529
+ var defaultResolver = function() {
1530
+ if (shareConfig.singleton) {
1531
+ if (typeof requiredVersion === 'string' && !satisfy(maxOrSingletonVersion, requiredVersion)) {
1532
+ var msg = "Version ".concat(maxOrSingletonVersion, " from ").concat(maxOrSingletonVersion && localShareScopeMap[sc][pkgName][maxOrSingletonVersion].from, " of shared singleton module ").concat(pkgName, " does not satisfy the requirement of ").concat(shareInfo.from, " which needs ").concat(requiredVersion, ")");
1533
+ if (shareConfig.strictVersion) {
1534
+ error(msg);
1535
+ } else {
1536
+ warn(msg);
1537
+ }
1538
+ }
1539
+ return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
1540
+ } else {
1541
+ if (requiredVersion === false || requiredVersion === '*') {
1542
+ return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
1543
+ }
1544
+ if (satisfy(maxOrSingletonVersion, requiredVersion)) {
1545
+ return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
1546
+ }
1547
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1548
+ try {
1549
+ for(var _iterator = Object.entries(localShareScopeMap[sc][pkgName])[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1550
+ var _step_value = _sliced_to_array._(_step.value, 2), versionKey = _step_value[0], versionValue = _step_value[1];
1551
+ if (satisfy(versionKey, requiredVersion)) {
1552
+ return versionValue;
1553
+ }
1554
+ }
1555
+ } catch (err) {
1556
+ _didIteratorError = true;
1557
+ _iteratorError = err;
1558
+ } finally{
1559
+ try {
1560
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1561
+ _iterator.return();
1562
+ }
1563
+ } finally{
1564
+ if (_didIteratorError) {
1565
+ throw _iteratorError;
1566
+ }
1567
+ }
1568
+ }
1569
+ }
1570
+ };
1571
+ var params = {
1572
+ shareScopeMap: localShareScopeMap,
1573
+ scope: sc,
1574
+ pkgName: pkgName,
1575
+ version: maxOrSingletonVersion,
1576
+ GlobalFederation: Global.__FEDERATION__,
1577
+ resolver: defaultResolver
1578
+ };
1579
+ var resolveShared = resolveShare.emit(params) || params;
1580
+ return {
1581
+ v: resolveShared.resolver()
1582
+ };
1583
+ }
1584
+ };
1585
+ for(var _iterator = scopes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1586
+ var _ret = _loop();
1587
+ if (_type_of._(_ret) === "object") return _ret.v;
1588
+ }
1589
+ } catch (err) {
1590
+ _didIteratorError = true;
1591
+ _iteratorError = err;
1592
+ } finally{
1593
+ try {
1594
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1595
+ _iterator.return();
1596
+ }
1597
+ } finally{
1598
+ if (_didIteratorError) {
1599
+ throw _iteratorError;
1600
+ }
1601
+ }
1602
+ }
1603
+ }
1604
+ function getGlobalShareScope() {
1605
+ return Global.__FEDERATION__.__SHARE__;
1606
+ }
1607
+ function getTargetSharedOptions(options) {
1608
+ var pkgName = options.pkgName, extraOptions = options.extraOptions, shareInfos = options.shareInfos;
1609
+ var defaultResolver = function(sharedOptions) {
1610
+ if (!sharedOptions) {
1611
+ return undefined;
1612
+ }
1613
+ var shareVersionMap = {};
1614
+ sharedOptions.forEach(function(shared) {
1615
+ shareVersionMap[shared.version] = shared;
1616
+ });
1617
+ var callback = function callback(prev, cur) {
1618
+ return !isLoaded(shareVersionMap[prev]) && versionLt(prev, cur);
1619
+ };
1620
+ var maxVersion = findVersion(shareVersionMap, callback);
1621
+ return shareVersionMap[maxVersion];
1622
+ };
1623
+ var _extraOptions_resolver;
1624
+ var resolver = (_extraOptions_resolver = extraOptions == null ? void 0 : extraOptions.resolver) != null ? _extraOptions_resolver : defaultResolver;
1625
+ return Object.assign({}, resolver(shareInfos[pkgName]), extraOptions == null ? void 0 : extraOptions.customShareInfo);
1626
+ }
1627
+
1628
+ function matchRemoteWithNameAndExpose(remotes, id) {
1629
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1630
+ try {
1631
+ for(var _iterator = remotes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1632
+ var remote = _step.value;
1633
+ var isNameMatched = id.startsWith(remote.name);
1634
+ var expose = id.replace(remote.name, '');
1635
+ if (isNameMatched) {
1636
+ if (expose.startsWith('/')) {
1637
+ var pkgNameOrAlias = remote.name;
1638
+ expose = ".".concat(expose);
1639
+ return {
1640
+ pkgNameOrAlias: pkgNameOrAlias,
1641
+ expose: expose,
1642
+ remote: remote
1643
+ };
1644
+ } else if (expose === '') {
1645
+ return {
1646
+ pkgNameOrAlias: remote.name,
1647
+ expose: '.',
1648
+ remote: remote
1649
+ };
1650
+ }
1651
+ }
1652
+ var isAliasMatched = remote.alias && id.startsWith(remote.alias);
1653
+ var exposeWithAlias = remote.alias && id.replace(remote.alias, '');
1654
+ if (remote.alias && isAliasMatched) {
1655
+ if (exposeWithAlias && exposeWithAlias.startsWith('/')) {
1656
+ var pkgNameOrAlias1 = remote.alias;
1657
+ exposeWithAlias = ".".concat(exposeWithAlias);
1658
+ return {
1659
+ pkgNameOrAlias: pkgNameOrAlias1,
1660
+ expose: exposeWithAlias,
1661
+ remote: remote
1662
+ };
1663
+ } else if (exposeWithAlias === '') {
1664
+ return {
1665
+ pkgNameOrAlias: remote.alias,
1666
+ expose: '.',
1667
+ remote: remote
1668
+ };
1669
+ }
1670
+ }
1671
+ }
1672
+ } catch (err) {
1673
+ _didIteratorError = true;
1674
+ _iteratorError = err;
1675
+ } finally{
1676
+ try {
1677
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1678
+ _iterator.return();
1679
+ }
1680
+ } finally{
1681
+ if (_didIteratorError) {
1682
+ throw _iteratorError;
1683
+ }
1684
+ }
1685
+ }
1686
+ return;
1687
+ }
1688
+ function matchRemote(remotes, nameOrAlias) {
1689
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1690
+ try {
1691
+ for(var _iterator = remotes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1692
+ var remote = _step.value;
1693
+ var isNameMatched = nameOrAlias === remote.name;
1694
+ if (isNameMatched) {
1695
+ return remote;
1696
+ }
1697
+ var isAliasMatched = remote.alias && nameOrAlias === remote.alias;
1698
+ if (isAliasMatched) {
1699
+ return remote;
1700
+ }
1701
+ }
1702
+ } catch (err) {
1703
+ _didIteratorError = true;
1704
+ _iteratorError = err;
1705
+ } finally{
1706
+ try {
1707
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1708
+ _iterator.return();
1709
+ }
1710
+ } finally{
1711
+ if (_didIteratorError) {
1712
+ throw _iteratorError;
1713
+ }
1714
+ }
1715
+ }
1716
+ return;
1717
+ }
1718
+ function registerPlugins$1(plugins, hookInstances) {
1719
+ var globalPlugins = getGlobalHostPlugins();
1720
+ if (globalPlugins.length > 0) {
1721
+ globalPlugins.forEach(function(plugin) {
1722
+ if (plugins == null ? void 0 : plugins.find(function(item) {
1723
+ return item.name !== plugin.name;
1724
+ })) {
1725
+ plugins.push(plugin);
1726
+ }
1727
+ });
1728
+ }
1729
+ if (plugins && plugins.length > 0) {
1730
+ plugins.forEach(function(plugin) {
1731
+ hookInstances.forEach(function(hookInstance) {
1732
+ hookInstance.applyPlugin(plugin);
1733
+ });
1734
+ });
1735
+ }
1736
+ return plugins;
1737
+ }
1738
+ function loadEsmEntry(_) {
1739
+ return _loadEsmEntry.apply(this, arguments);
1740
+ }
1741
+ function _loadEsmEntry() {
1742
+ _loadEsmEntry = _async_to_generator._(function(param) {
1743
+ var entry, remoteEntryExports;
1744
+ return _ts_generator._(this, function(_state) {
1745
+ entry = param.entry, remoteEntryExports = param.remoteEntryExports;
1746
+ return [
1747
+ 2,
1748
+ new Promise(function(resolve, reject) {
1749
+ try {
1750
+ if (!remoteEntryExports) {
1751
+ new Function('callbacks', 'import("'.concat(entry, '").then(callbacks[0]).catch(callbacks[1])'))([
1752
+ resolve,
1753
+ reject
1754
+ ]);
1755
+ } else {
1756
+ resolve(remoteEntryExports);
1757
+ }
1758
+ } catch (e) {
1759
+ reject(e);
1760
+ }
1761
+ })
1762
+ ];
1763
+ });
1764
+ });
1765
+ return _loadEsmEntry.apply(this, arguments);
1766
+ }
1767
+ function loadSystemJsEntry(_) {
1768
+ return _loadSystemJsEntry.apply(this, arguments);
1769
+ }
1770
+ function _loadSystemJsEntry() {
1771
+ _loadSystemJsEntry = _async_to_generator._(function(param) {
1772
+ var entry, remoteEntryExports;
1773
+ return _ts_generator._(this, function(_state) {
1774
+ entry = param.entry, remoteEntryExports = param.remoteEntryExports;
1775
+ return [
1776
+ 2,
1777
+ new Promise(function(resolve, reject) {
1778
+ try {
1779
+ if (!remoteEntryExports) {
1780
+ new Function('callbacks', 'System.import("'.concat(entry, '").then(callbacks[0]).catch(callbacks[1])'))([
1781
+ resolve,
1782
+ reject
1783
+ ]);
1784
+ } else {
1785
+ resolve(remoteEntryExports);
1786
+ }
1787
+ } catch (e) {
1788
+ reject(e);
1789
+ }
1790
+ })
1791
+ ];
1792
+ });
1793
+ });
1794
+ return _loadSystemJsEntry.apply(this, arguments);
1795
+ }
1796
+ function loadEntryScript(_) {
1797
+ return _loadEntryScript.apply(this, arguments);
1798
+ }
1799
+ function _loadEntryScript() {
1800
+ _loadEntryScript = _async_to_generator._(function(param) {
1801
+ var name, globalName, entry, createScriptHook, _getRemoteEntryExports, remoteEntryExports;
1802
+ return _ts_generator._(this, function(_state) {
1803
+ name = param.name, globalName = param.globalName, entry = param.entry, createScriptHook = param.createScriptHook;
1804
+ _getRemoteEntryExports = getRemoteEntryExports(name, globalName), remoteEntryExports = _getRemoteEntryExports.entryExports;
1805
+ if (remoteEntryExports) {
1806
+ return [
1807
+ 2,
1808
+ remoteEntryExports
1809
+ ];
1810
+ }
1811
+ return [
1812
+ 2,
1813
+ loadScript(entry, {
1814
+ attrs: {},
1815
+ createScriptHook: function(url, attrs) {
1816
+ var res = createScriptHook.emit({
1817
+ url: url,
1818
+ attrs: attrs
1819
+ });
1820
+ if (!res) return;
1821
+ if (_instanceof._(res, HTMLScriptElement)) {
1822
+ return res;
1823
+ }
1824
+ if ('script' in res || 'timeout' in res) {
1825
+ return res;
1826
+ }
1827
+ return;
1828
+ }
1829
+ }).then(function() {
1830
+ var _getRemoteEntryExports = getRemoteEntryExports(name, globalName), remoteEntryKey = _getRemoteEntryExports.remoteEntryKey, entryExports = _getRemoteEntryExports.entryExports;
1831
+ assert(entryExports, "\n Unable to use the ".concat(name, "'s '").concat(entry, "' URL with ").concat(remoteEntryKey, "'s globalName to get remoteEntry exports.\n Possible reasons could be:\n\n 1. '").concat(entry, "' is not the correct URL, or the remoteEntry resource or name is incorrect.\n\n 2. ").concat(remoteEntryKey, " cannot be used to get remoteEntry exports in the window object.\n "));
1832
+ return entryExports;
1833
+ }).catch(function(e) {
1834
+ throw e;
1835
+ })
1836
+ ];
1837
+ });
1838
+ });
1839
+ return _loadEntryScript.apply(this, arguments);
1840
+ }
1841
+ function loadEntryDom(_) {
1842
+ return _loadEntryDom.apply(this, arguments);
1843
+ }
1844
+ function _loadEntryDom() {
1845
+ _loadEntryDom = _async_to_generator._(function(param) {
1846
+ var remoteInfo, remoteEntryExports, createScriptHook, entry, globalName, name, type;
1847
+ return _ts_generator._(this, function(_state) {
1848
+ remoteInfo = param.remoteInfo, remoteEntryExports = param.remoteEntryExports, createScriptHook = param.createScriptHook;
1849
+ entry = remoteInfo.entry, globalName = remoteInfo.entryGlobalName, name = remoteInfo.name, type = remoteInfo.type;
1850
+ switch(type){
1851
+ case 'esm':
1852
+ case 'module':
1853
+ return [
1854
+ 2,
1855
+ loadEsmEntry({
1856
+ entry: entry,
1857
+ remoteEntryExports: remoteEntryExports
1858
+ })
1859
+ ];
1860
+ case 'system':
1861
+ return [
1862
+ 2,
1863
+ loadSystemJsEntry({
1864
+ entry: entry,
1865
+ remoteEntryExports: remoteEntryExports
1866
+ })
1867
+ ];
1868
+ default:
1869
+ return [
1870
+ 2,
1871
+ loadEntryScript({
1872
+ entry: entry,
1873
+ globalName: globalName,
1874
+ name: name,
1875
+ createScriptHook: createScriptHook
1876
+ })
1877
+ ];
1878
+ }
1879
+ return [
1880
+ 2
1881
+ ];
1882
+ });
1883
+ });
1884
+ return _loadEntryDom.apply(this, arguments);
1885
+ }
1886
+ function loadEntryNode(_) {
1887
+ return _loadEntryNode.apply(this, arguments);
1888
+ }
1889
+ function _loadEntryNode() {
1890
+ _loadEntryNode = _async_to_generator._(function(param) {
1891
+ var remoteInfo, createScriptHook, entry, globalName, name, _getRemoteEntryExports, remoteEntryExports;
1892
+ return _ts_generator._(this, function(_state) {
1893
+ remoteInfo = param.remoteInfo, createScriptHook = param.createScriptHook;
1894
+ entry = remoteInfo.entry, globalName = remoteInfo.entryGlobalName, name = remoteInfo.name;
1895
+ _getRemoteEntryExports = getRemoteEntryExports(name, globalName), remoteEntryExports = _getRemoteEntryExports.entryExports;
1896
+ if (remoteEntryExports) {
1897
+ return [
1898
+ 2,
1899
+ remoteEntryExports
1900
+ ];
1901
+ }
1902
+ return [
1903
+ 2,
1904
+ loadScriptNode(entry, {
1905
+ attrs: {
1906
+ name: name,
1907
+ globalName: globalName
1908
+ },
1909
+ createScriptHook: function(url, attrs) {
1910
+ var res = createScriptHook.emit({
1911
+ url: url,
1912
+ attrs: attrs
1913
+ });
1914
+ if (!res) return;
1915
+ if ('url' in res) {
1916
+ return res;
1917
+ }
1918
+ return;
1919
+ }
1920
+ }).then(function() {
1921
+ var _getRemoteEntryExports = getRemoteEntryExports(name, globalName), remoteEntryKey = _getRemoteEntryExports.remoteEntryKey, entryExports = _getRemoteEntryExports.entryExports;
1922
+ assert(entryExports, "\n Unable to use the ".concat(name, "'s '").concat(entry, "' URL with ").concat(remoteEntryKey, "'s globalName to get remoteEntry exports.\n Possible reasons could be:\n\n 1. '").concat(entry, "' is not the correct URL, or the remoteEntry resource or name is incorrect.\n\n 2. ").concat(remoteEntryKey, " cannot be used to get remoteEntry exports in the window object.\n "));
1923
+ return entryExports;
1924
+ }).catch(function(e) {
1925
+ throw e;
1926
+ })
1927
+ ];
1928
+ });
1929
+ });
1930
+ return _loadEntryNode.apply(this, arguments);
1931
+ }
1932
+ function getRemoteEntryUniqueKey(remoteInfo) {
1933
+ var entry = remoteInfo.entry, name = remoteInfo.name;
1934
+ return composeKeyWithSeparator(name, entry);
1935
+ }
1936
+ function getRemoteEntry(_) {
1937
+ return _getRemoteEntry.apply(this, arguments);
1938
+ }
1939
+ function _getRemoteEntry() {
1940
+ _getRemoteEntry = _async_to_generator._(function(param) {
1941
+ var origin, remoteEntryExports, remoteInfo, uniqueKey, loadEntryHook, createScriptHook;
1942
+ return _ts_generator._(this, function(_state) {
1943
+ origin = param.origin, remoteEntryExports = param.remoteEntryExports, remoteInfo = param.remoteInfo;
1944
+ uniqueKey = getRemoteEntryUniqueKey(remoteInfo);
1945
+ if (remoteEntryExports) {
1946
+ return [
1947
+ 2,
1948
+ remoteEntryExports
1949
+ ];
1950
+ }
1951
+ if (!globalLoading[uniqueKey]) {
1952
+ loadEntryHook = origin.remoteHandler.hooks.lifecycle.loadEntry;
1953
+ if (loadEntryHook.listeners.size) {
1954
+ globalLoading[uniqueKey] = loadEntryHook.emit({
1955
+ createScriptHook: origin.loaderHook.lifecycle.createScript,
1956
+ remoteInfo: remoteInfo,
1957
+ remoteEntryExports: remoteEntryExports
1958
+ }).then(function(res) {
1959
+ return res || undefined;
1960
+ });
1961
+ } else {
1962
+ createScriptHook = origin.loaderHook.lifecycle.createScript;
1963
+ if (!isBrowserEnv()) {
1964
+ globalLoading[uniqueKey] = loadEntryNode({
1965
+ remoteInfo: remoteInfo,
1966
+ createScriptHook: createScriptHook
1967
+ });
1968
+ } else {
1969
+ globalLoading[uniqueKey] = loadEntryDom({
1970
+ remoteInfo: remoteInfo,
1971
+ remoteEntryExports: remoteEntryExports,
1972
+ createScriptHook: createScriptHook
1973
+ });
1974
+ }
1975
+ }
1976
+ }
1977
+ return [
1978
+ 2,
1979
+ globalLoading[uniqueKey]
1980
+ ];
1981
+ });
1982
+ });
1983
+ return _getRemoteEntry.apply(this, arguments);
1984
+ }
1985
+ function getRemoteInfo(remote) {
1986
+ return _extends._({}, remote, {
1987
+ entry: 'entry' in remote ? remote.entry : '',
1988
+ type: remote.type || DEFAULT_REMOTE_TYPE,
1989
+ entryGlobalName: remote.entryGlobalName || remote.name,
1990
+ shareScope: remote.shareScope || DEFAULT_SCOPE
1991
+ });
1992
+ }
1993
+ var Module = function() {
1994
+ function Module(param) {
1995
+ var remoteInfo = param.remoteInfo, host = param.host;
1996
+ _class_call_check._(this, Module);
1997
+ this.inited = false;
1998
+ this.lib = undefined;
1999
+ this.remoteInfo = remoteInfo;
2000
+ this.host = host;
2001
+ }
2002
+ _create_class._(Module, [
2003
+ {
2004
+ key: "getEntry",
2005
+ value: function getEntry() {
2006
+ var _this = this;
2007
+ return _async_to_generator._(function() {
2008
+ var remoteEntryExports;
2009
+ return _ts_generator._(this, function(_state) {
2010
+ switch(_state.label){
2011
+ case 0:
2012
+ if (_this.remoteEntryExports) {
2013
+ return [
2014
+ 2,
2015
+ _this.remoteEntryExports
2016
+ ];
2017
+ }
2018
+ return [
2019
+ 4,
2020
+ getRemoteEntry({
2021
+ origin: _this.host,
2022
+ remoteInfo: _this.remoteInfo,
2023
+ remoteEntryExports: _this.remoteEntryExports
2024
+ })
2025
+ ];
2026
+ case 1:
2027
+ remoteEntryExports = _state.sent();
2028
+ assert(remoteEntryExports, "remoteEntryExports is undefined \n ".concat(safeToString(_this.remoteInfo)));
2029
+ _this.remoteEntryExports = remoteEntryExports;
2030
+ return [
2031
+ 2,
2032
+ _this.remoteEntryExports
2033
+ ];
2034
+ }
2035
+ });
2036
+ })();
2037
+ }
2038
+ },
2039
+ {
2040
+ key: "get",
2041
+ value: function get(id, expose, options) {
2042
+ var _this = this;
2043
+ return _async_to_generator._(function() {
2044
+ var _ref, _ref_loadFactory, loadFactory, remoteEntryExports, localShareScopeMap, remoteShareScope, shareScope, initScope, remoteEntryInitOptions, initContainerOptions, moduleFactory, wrapModuleFactory, exposeContent;
2045
+ return _ts_generator._(this, function(_state) {
2046
+ switch(_state.label){
2047
+ case 0:
2048
+ _ref = options || {
2049
+ loadFactory: true
2050
+ }, _ref_loadFactory = _ref.loadFactory, loadFactory = _ref_loadFactory === void 0 ? true : _ref_loadFactory;
2051
+ return [
2052
+ 4,
2053
+ _this.getEntry()
2054
+ ];
2055
+ case 1:
2056
+ remoteEntryExports = _state.sent();
2057
+ if (!!_this.inited) return [
2058
+ 3,
2059
+ 5
2060
+ ];
2061
+ localShareScopeMap = _this.host.shareScopeMap;
2062
+ remoteShareScope = _this.remoteInfo.shareScope || 'default';
2063
+ if (!localShareScopeMap[remoteShareScope]) {
2064
+ localShareScopeMap[remoteShareScope] = {};
2065
+ }
2066
+ shareScope = localShareScopeMap[remoteShareScope];
2067
+ initScope = [];
2068
+ remoteEntryInitOptions = {
2069
+ version: _this.remoteInfo.version || ''
2070
+ };
2071
+ Object.defineProperty(remoteEntryInitOptions, 'shareScopeMap', {
2072
+ value: localShareScopeMap,
2073
+ enumerable: false
2074
+ });
2075
+ return [
2076
+ 4,
2077
+ _this.host.hooks.lifecycle.beforeInitContainer.emit({
2078
+ shareScope: shareScope,
2079
+ remoteEntryInitOptions: remoteEntryInitOptions,
2080
+ initScope: initScope,
2081
+ remoteInfo: _this.remoteInfo,
2082
+ origin: _this.host
2083
+ })
2084
+ ];
2085
+ case 2:
2086
+ initContainerOptions = _state.sent();
2087
+ if (typeof (remoteEntryExports == null ? void 0 : remoteEntryExports.init) === 'undefined') {
2088
+ console.error('The remote entry interface does not contain "init"', '\n', 'Ensure the name of this remote is not reserved or in use. Check if anything already exists on window[nameOfRemote]', '\n', 'Ensure that window[nameOfRemote] is returning a {get,init} object.');
2089
+ }
2090
+ return [
2091
+ 4,
2092
+ remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions)
2093
+ ];
2094
+ case 3:
2095
+ _state.sent();
2096
+ return [
2097
+ 4,
2098
+ _this.host.hooks.lifecycle.initContainer.emit(_extends._({}, initContainerOptions, {
2099
+ remoteEntryExports: remoteEntryExports
2100
+ }))
2101
+ ];
2102
+ case 4:
2103
+ _state.sent();
2104
+ _state.label = 5;
2105
+ case 5:
2106
+ _this.lib = remoteEntryExports;
2107
+ _this.inited = true;
2108
+ return [
2109
+ 4,
2110
+ remoteEntryExports.get(expose)
2111
+ ];
2112
+ case 6:
2113
+ moduleFactory = _state.sent();
2114
+ assert(moduleFactory, "".concat(getFMId(_this.remoteInfo), " remote don't export ").concat(expose, "."));
2115
+ wrapModuleFactory = _this.wraperFactory(moduleFactory, id);
2116
+ if (!loadFactory) {
2117
+ return [
2118
+ 2,
2119
+ wrapModuleFactory
2120
+ ];
2121
+ }
2122
+ return [
2123
+ 4,
2124
+ wrapModuleFactory()
2125
+ ];
2126
+ case 7:
2127
+ exposeContent = _state.sent();
2128
+ return [
2129
+ 2,
2130
+ exposeContent
2131
+ ];
2132
+ }
2133
+ });
2134
+ })();
2135
+ }
2136
+ },
2137
+ {
2138
+ key: "wraperFactory",
2139
+ value: function wraperFactory(moduleFactory, id) {
2140
+ function defineModuleId(res, id) {
2141
+ if (res && (typeof res === "undefined" ? "undefined" : _type_of._(res)) === 'object' && Object.isExtensible(res) && !Object.getOwnPropertyDescriptor(res, Symbol.for('mf_module_id'))) {
2142
+ Object.defineProperty(res, Symbol.for('mf_module_id'), {
2143
+ value: id,
2144
+ enumerable: false
2145
+ });
2146
+ }
2147
+ }
2148
+ if (_instanceof._(moduleFactory, Promise)) {
2149
+ return _async_to_generator._(function() {
2150
+ var res;
2151
+ return _ts_generator._(this, function(_state) {
2152
+ switch(_state.label){
2153
+ case 0:
2154
+ return [
2155
+ 4,
2156
+ moduleFactory()
2157
+ ];
2158
+ case 1:
2159
+ res = _state.sent();
2160
+ defineModuleId(res, id);
2161
+ return [
2162
+ 2,
2163
+ res
2164
+ ];
2165
+ }
2166
+ });
2167
+ });
2168
+ } else {
2169
+ return function() {
2170
+ var res = moduleFactory();
2171
+ defineModuleId(res, id);
2172
+ return res;
2173
+ };
2174
+ }
2175
+ }
2176
+ }
2177
+ ]);
2178
+ return Module;
2179
+ }();
2180
+ var SyncHook = function() {
2181
+ function SyncHook(type) {
2182
+ _class_call_check._(this, SyncHook);
2183
+ this.type = '';
2184
+ this.listeners = new Set();
2185
+ if (type) {
2186
+ this.type = type;
2187
+ }
2188
+ }
2189
+ _create_class._(SyncHook, [
2190
+ {
2191
+ key: "on",
2192
+ value: function on(fn) {
2193
+ if (typeof fn === 'function') {
2194
+ this.listeners.add(fn);
2195
+ }
2196
+ }
2197
+ },
2198
+ {
2199
+ key: "once",
2200
+ value: function once(fn) {
2201
+ var self = this;
2202
+ this.on(function wrapper() {
2203
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
2204
+ args[_key] = arguments[_key];
2205
+ }
2206
+ self.remove(wrapper);
2207
+ return fn.apply(null, args);
2208
+ });
2209
+ }
2210
+ },
2211
+ {
2212
+ key: "emit",
2213
+ value: function emit() {
2214
+ for(var _len = arguments.length, data = new Array(_len), _key = 0; _key < _len; _key++){
2215
+ data[_key] = arguments[_key];
2216
+ }
2217
+ var result;
2218
+ if (this.listeners.size > 0) {
2219
+ this.listeners.forEach(function(fn) {
2220
+ result = fn.apply(void 0, _to_consumable_array._(data));
2221
+ });
2222
+ }
2223
+ return result;
2224
+ }
2225
+ },
2226
+ {
2227
+ key: "remove",
2228
+ value: function remove(fn) {
2229
+ this.listeners.delete(fn);
2230
+ }
2231
+ },
2232
+ {
2233
+ key: "removeAll",
2234
+ value: function removeAll() {
2235
+ this.listeners.clear();
2236
+ }
2237
+ }
2238
+ ]);
2239
+ return SyncHook;
2240
+ }();
2241
+ var AsyncHook = function(SyncHook) {
2242
+ _inherits._(AsyncHook, SyncHook);
2243
+ var _super = _create_super._(AsyncHook);
2244
+ function AsyncHook() {
2245
+ _class_call_check._(this, AsyncHook);
2246
+ return _super.apply(this, arguments);
2247
+ }
2248
+ _create_class._(AsyncHook, [
2249
+ {
2250
+ key: "emit",
2251
+ value: function emit() {
2252
+ for(var _len = arguments.length, data = new Array(_len), _key = 0; _key < _len; _key++){
2253
+ data[_key] = arguments[_key];
2254
+ }
2255
+ var result;
2256
+ var ls = Array.from(this.listeners);
2257
+ if (ls.length > 0) {
2258
+ var i = 0;
2259
+ var call = function(prev) {
2260
+ if (prev === false) {
2261
+ return false;
2262
+ } else if (i < ls.length) {
2263
+ return Promise.resolve(ls[i++].apply(null, data)).then(call);
2264
+ } else {
2265
+ return prev;
2266
+ }
2267
+ };
2268
+ result = call();
2269
+ }
2270
+ return Promise.resolve(result);
2271
+ }
2272
+ }
2273
+ ]);
2274
+ return AsyncHook;
2275
+ }(SyncHook);
2276
+ function checkReturnData(originalData, returnedData) {
2277
+ if (!isObject(returnedData)) {
2278
+ return false;
2279
+ }
2280
+ if (originalData !== returnedData) {
2281
+ for(var key in originalData){
2282
+ if (!(key in returnedData)) {
2283
+ return false;
2284
+ }
2285
+ }
2286
+ }
2287
+ return true;
2288
+ }
2289
+ var SyncWaterfallHook = function(SyncHook) {
2290
+ _inherits._(SyncWaterfallHook, SyncHook);
2291
+ var _super = _create_super._(SyncWaterfallHook);
2292
+ function SyncWaterfallHook(type) {
2293
+ _class_call_check._(this, SyncWaterfallHook);
2294
+ var _this;
2295
+ _this = _super.call(this);
2296
+ _this.onerror = error;
2297
+ _this.type = type;
2298
+ return _this;
2299
+ }
2300
+ _create_class._(SyncWaterfallHook, [
2301
+ {
2302
+ key: "emit",
2303
+ value: function emit(data) {
2304
+ if (!isObject(data)) {
2305
+ error('The data for the "'.concat(this.type, '" hook should be an object.'));
2306
+ }
2307
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
2308
+ try {
2309
+ for(var _iterator = this.listeners[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2310
+ var fn = _step.value;
2311
+ try {
2312
+ var tempData = fn(data);
2313
+ if (checkReturnData(data, tempData)) {
2314
+ data = tempData;
2315
+ } else {
2316
+ this.onerror('A plugin returned an unacceptable value for the "'.concat(this.type, '" type.'));
2317
+ break;
2318
+ }
2319
+ } catch (e) {
2320
+ warn(e);
2321
+ this.onerror(e);
2322
+ }
2323
+ }
2324
+ } catch (err) {
2325
+ _didIteratorError = true;
2326
+ _iteratorError = err;
2327
+ } finally{
2328
+ try {
2329
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
2330
+ _iterator.return();
2331
+ }
2332
+ } finally{
2333
+ if (_didIteratorError) {
2334
+ throw _iteratorError;
2335
+ }
2336
+ }
2337
+ }
2338
+ return data;
2339
+ }
2340
+ }
2341
+ ]);
2342
+ return SyncWaterfallHook;
2343
+ }(SyncHook);
2344
+ var AsyncWaterfallHook = function(SyncHook) {
2345
+ _inherits._(AsyncWaterfallHook, SyncHook);
2346
+ var _super = _create_super._(AsyncWaterfallHook);
2347
+ function AsyncWaterfallHook(type) {
2348
+ _class_call_check._(this, AsyncWaterfallHook);
2349
+ var _this;
2350
+ _this = _super.call(this);
2351
+ _this.onerror = error;
2352
+ _this.type = type;
2353
+ return _this;
2354
+ }
2355
+ _create_class._(AsyncWaterfallHook, [
2356
+ {
2357
+ key: "emit",
2358
+ value: function emit(data) {
2359
+ var _this = this;
2360
+ if (!isObject(data)) {
2361
+ error('The response data for the "'.concat(this.type, '" hook must be an object.'));
2362
+ }
2363
+ var ls = Array.from(this.listeners);
2364
+ if (ls.length > 0) {
2365
+ var i = 0;
2366
+ var processError = function(e) {
2367
+ warn(e);
2368
+ _this.onerror(e);
2369
+ return data;
2370
+ };
2371
+ var call = function(prevData) {
2372
+ if (checkReturnData(data, prevData)) {
2373
+ data = prevData;
2374
+ if (i < ls.length) {
2375
+ try {
2376
+ return Promise.resolve(ls[i++](data)).then(call, processError);
2377
+ } catch (e) {
2378
+ return processError(e);
2379
+ }
2380
+ }
2381
+ } else {
2382
+ _this.onerror('A plugin returned an incorrect value for the "'.concat(_this.type, '" type.'));
2383
+ }
2384
+ return data;
2385
+ };
2386
+ return Promise.resolve(call(data));
2387
+ }
2388
+ return Promise.resolve(data);
2389
+ }
2390
+ }
2391
+ ]);
2392
+ return AsyncWaterfallHook;
2393
+ }(SyncHook);
2394
+ var PluginSystem = function() {
2395
+ function PluginSystem(lifecycle) {
2396
+ _class_call_check._(this, PluginSystem);
2397
+ this.registerPlugins = {};
2398
+ this.lifecycle = lifecycle;
2399
+ this.lifecycleKeys = Object.keys(lifecycle);
2400
+ }
2401
+ _create_class._(PluginSystem, [
2402
+ {
2403
+ key: "applyPlugin",
2404
+ value: function applyPlugin(plugin) {
2405
+ var _this = this;
2406
+ assert(isPlainObject(plugin), 'Plugin configuration is invalid.');
2407
+ var pluginName = plugin.name;
2408
+ assert(pluginName, 'A name must be provided by the plugin.');
2409
+ if (!this.registerPlugins[pluginName]) {
2410
+ this.registerPlugins[pluginName] = plugin;
2411
+ Object.keys(this.lifecycle).forEach(function(key) {
2412
+ var pluginLife = plugin[key];
2413
+ if (pluginLife) {
2414
+ _this.lifecycle[key].on(pluginLife);
2415
+ }
2416
+ });
2417
+ }
2418
+ }
2419
+ },
2420
+ {
2421
+ key: "removePlugin",
2422
+ value: function removePlugin(pluginName) {
2423
+ var _this = this;
2424
+ assert(pluginName, 'A name is required.');
2425
+ var plugin = this.registerPlugins[pluginName];
2426
+ assert(plugin, 'The plugin "'.concat(pluginName, '" is not registered.'));
2427
+ Object.keys(plugin).forEach(function(key) {
2428
+ if (key !== 'name') {
2429
+ _this.lifecycle[key].remove(plugin[key]);
2430
+ }
2431
+ });
2432
+ }
2433
+ },
2434
+ {
2435
+ key: "inherit",
2436
+ value: function inherit(param) {
2437
+ var _this = this;
2438
+ var lifecycle = param.lifecycle, registerPlugins = param.registerPlugins;
2439
+ Object.keys(lifecycle).forEach(function(hookName) {
2440
+ assert(!_this.lifecycle[hookName], 'The hook "'.concat(hookName, '" has a conflict and cannot be inherited.'));
2441
+ _this.lifecycle[hookName] = lifecycle[hookName];
2442
+ });
2443
+ Object.keys(registerPlugins).forEach(function(pluginName) {
2444
+ assert(!_this.registerPlugins[pluginName], 'The plugin "'.concat(pluginName, '" has a conflict and cannot be inherited.'));
2445
+ _this.applyPlugin(registerPlugins[pluginName]);
2446
+ });
2447
+ }
2448
+ }
2449
+ ]);
2450
+ return PluginSystem;
2451
+ }();
2452
+ function defaultPreloadArgs(preloadConfig) {
2453
+ return _extends._({
2454
+ resourceCategory: 'sync',
2455
+ share: true,
2456
+ depsRemote: true,
2457
+ prefetchInterface: false
2458
+ }, preloadConfig);
2459
+ }
2460
+ function formatPreloadArgs(remotes, preloadArgs) {
2461
+ return preloadArgs.map(function(args) {
2462
+ var remoteInfo = matchRemote(remotes, args.nameOrAlias);
2463
+ assert(remoteInfo, "Unable to preload ".concat(args.nameOrAlias, " as it is not included in ").concat(!remoteInfo && safeToString({
2464
+ remoteInfo: remoteInfo,
2465
+ remotes: remotes
2466
+ })));
2467
+ return {
2468
+ remote: remoteInfo,
2469
+ preloadConfig: defaultPreloadArgs(args)
2470
+ };
2471
+ });
2472
+ }
2473
+ function normalizePreloadExposes(exposes) {
2474
+ if (!exposes) {
2475
+ return [];
2476
+ }
2477
+ return exposes.map(function(expose) {
2478
+ if (expose === '.') {
2479
+ return expose;
2480
+ }
2481
+ if (expose.startsWith('./')) {
2482
+ return expose.replace('./', '');
2483
+ }
2484
+ return expose;
2485
+ });
2486
+ }
2487
+ function preloadAssets(remoteInfo, host, assets) {
2488
+ var useLinkPreload = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : true;
2489
+ var cssAssets = assets.cssAssets, jsAssetsWithoutEntry = assets.jsAssetsWithoutEntry, entryAssets = assets.entryAssets;
2490
+ if (host.options.inBrowser) {
2491
+ entryAssets.forEach(function(asset) {
2492
+ var moduleInfo = asset.moduleInfo;
2493
+ var module = host.moduleCache.get(remoteInfo.name);
2494
+ if (module) {
2495
+ getRemoteEntry({
2496
+ origin: host,
2497
+ remoteInfo: moduleInfo,
2498
+ remoteEntryExports: module.remoteEntryExports
2499
+ });
2500
+ } else {
2501
+ getRemoteEntry({
2502
+ origin: host,
2503
+ remoteInfo: moduleInfo,
2504
+ remoteEntryExports: undefined
2505
+ });
2506
+ }
2507
+ });
2508
+ if (useLinkPreload) {
2509
+ var defaultAttrs = {
2510
+ rel: 'preload',
2511
+ as: 'style',
2512
+ crossorigin: 'anonymous'
2513
+ };
2514
+ cssAssets.forEach(function(cssUrl) {
2515
+ var _createLink = createLink({
2516
+ url: cssUrl,
2517
+ cb: function() {},
2518
+ attrs: defaultAttrs,
2519
+ createLinkHook: function(url, attrs) {
2520
+ var res = host.loaderHook.lifecycle.createLink.emit({
2521
+ url: url,
2522
+ attrs: attrs
2523
+ });
2524
+ if (_instanceof._(res, HTMLLinkElement)) {
2525
+ return res;
2526
+ }
2527
+ return;
2528
+ }
2529
+ }), cssEl = _createLink.link, needAttach = _createLink.needAttach;
2530
+ needAttach && document.head.appendChild(cssEl);
2531
+ });
2532
+ } else {
2533
+ var defaultAttrs1 = {
2534
+ rel: 'stylesheet',
2535
+ type: 'text/css'
2536
+ };
2537
+ cssAssets.forEach(function(cssUrl) {
2538
+ var _createLink = createLink({
2539
+ url: cssUrl,
2540
+ cb: function() {},
2541
+ attrs: defaultAttrs1,
2542
+ createLinkHook: function(url, attrs) {
2543
+ var res = host.loaderHook.lifecycle.createLink.emit({
2544
+ url: url,
2545
+ attrs: attrs
2546
+ });
2547
+ if (_instanceof._(res, HTMLLinkElement)) {
2548
+ return res;
2549
+ }
2550
+ return;
2551
+ },
2552
+ needDeleteLink: false
2553
+ }), cssEl = _createLink.link, needAttach = _createLink.needAttach;
2554
+ needAttach && document.head.appendChild(cssEl);
2555
+ });
2556
+ }
2557
+ if (useLinkPreload) {
2558
+ var defaultAttrs2 = {
2559
+ rel: 'preload',
2560
+ as: 'script',
2561
+ crossorigin: 'anonymous'
2562
+ };
2563
+ jsAssetsWithoutEntry.forEach(function(jsUrl) {
2564
+ var _createLink = createLink({
2565
+ url: jsUrl,
2566
+ cb: function() {},
2567
+ attrs: defaultAttrs2,
2568
+ createLinkHook: function(url, attrs) {
2569
+ var res = host.loaderHook.lifecycle.createLink.emit({
2570
+ url: url,
2571
+ attrs: attrs
2572
+ });
2573
+ if (_instanceof._(res, HTMLLinkElement)) {
2574
+ return res;
2575
+ }
2576
+ return;
2577
+ }
2578
+ }), linkEl = _createLink.link, needAttach = _createLink.needAttach;
2579
+ needAttach && document.head.appendChild(linkEl);
2580
+ });
2581
+ } else {
2582
+ var defaultAttrs3 = {
2583
+ fetchpriority: 'high',
2584
+ type: (remoteInfo == null ? void 0 : remoteInfo.type) === 'module' ? 'module' : 'text/javascript'
2585
+ };
2586
+ jsAssetsWithoutEntry.forEach(function(jsUrl) {
2587
+ var _createScript = createScript({
2588
+ url: jsUrl,
2589
+ cb: function() {},
2590
+ attrs: defaultAttrs3,
2591
+ createScriptHook: function(url, attrs) {
2592
+ var res = host.loaderHook.lifecycle.createScript.emit({
2593
+ url: url,
2594
+ attrs: attrs
2595
+ });
2596
+ if (_instanceof._(res, HTMLScriptElement)) {
2597
+ return res;
2598
+ }
2599
+ return;
2600
+ },
2601
+ needDeleteScript: true
2602
+ }), scriptEl = _createScript.script, needAttach = _createScript.needAttach;
2603
+ needAttach && document.head.appendChild(scriptEl);
2604
+ });
2605
+ }
2606
+ }
2607
+ }
2608
+ function assignRemoteInfo(remoteInfo, remoteSnapshot) {
2609
+ var remoteEntryInfo = getRemoteEntryInfoFromSnapshot(remoteSnapshot);
2610
+ if (!remoteEntryInfo.url) {
2611
+ error("The attribute remoteEntry of ".concat(remoteInfo.name, " must not be undefined."));
2612
+ }
2613
+ var entryUrl = getResourceUrl(remoteSnapshot, remoteEntryInfo.url);
2614
+ if (!isBrowserEnv() && !entryUrl.startsWith('http')) {
2615
+ entryUrl = "https:".concat(entryUrl);
2616
+ }
2617
+ remoteInfo.type = remoteEntryInfo.type;
2618
+ remoteInfo.entryGlobalName = remoteEntryInfo.globalName;
2619
+ remoteInfo.entry = entryUrl;
2620
+ remoteInfo.version = remoteSnapshot.version;
2621
+ remoteInfo.buildVersion = remoteSnapshot.buildVersion;
2622
+ }
2623
+ function snapshotPlugin() {
2624
+ return {
2625
+ name: 'snapshot-plugin',
2626
+ afterResolve: function afterResolve(args) {
2627
+ return _async_to_generator._(function() {
2628
+ var remote, pkgNameOrAlias, expose, origin, remoteInfo, _ref, remoteSnapshot, globalSnapshot, preloadOptions, assets;
2629
+ return _ts_generator._(this, function(_state) {
2630
+ switch(_state.label){
2631
+ case 0:
2632
+ remote = args.remote, pkgNameOrAlias = args.pkgNameOrAlias, expose = args.expose, origin = args.origin, remoteInfo = args.remoteInfo;
2633
+ if (!(!isRemoteInfoWithEntry(remote) || !isPureRemoteEntry(remote))) return [
2634
+ 3,
2635
+ 3
2636
+ ];
2637
+ return [
2638
+ 4,
2639
+ origin.snapshotHandler.loadRemoteSnapshotInfo(remote)
2640
+ ];
2641
+ case 1:
2642
+ _ref = _state.sent(), remoteSnapshot = _ref.remoteSnapshot, globalSnapshot = _ref.globalSnapshot;
2643
+ assignRemoteInfo(remoteInfo, remoteSnapshot);
2644
+ preloadOptions = {
2645
+ remote: remote,
2646
+ preloadConfig: {
2647
+ nameOrAlias: pkgNameOrAlias,
2648
+ exposes: [
2649
+ expose
2650
+ ],
2651
+ resourceCategory: 'sync',
2652
+ share: false,
2653
+ depsRemote: false
2654
+ }
2655
+ };
2656
+ return [
2657
+ 4,
2658
+ origin.remoteHandler.hooks.lifecycle.generatePreloadAssets.emit({
2659
+ origin: origin,
2660
+ preloadOptions: preloadOptions,
2661
+ remoteInfo: remoteInfo,
2662
+ remote: remote,
2663
+ remoteSnapshot: remoteSnapshot,
2664
+ globalSnapshot: globalSnapshot
2665
+ })
2666
+ ];
2667
+ case 2:
2668
+ assets = _state.sent();
2669
+ if (assets) {
2670
+ preloadAssets(remoteInfo, origin, assets, false);
2671
+ }
2672
+ return [
2673
+ 2,
2674
+ _extends._({}, args, {
2675
+ remoteSnapshot: remoteSnapshot
2676
+ })
2677
+ ];
2678
+ case 3:
2679
+ return [
2680
+ 2,
2681
+ args
2682
+ ];
2683
+ }
2684
+ });
2685
+ })();
2686
+ }
2687
+ };
2688
+ }
2689
+ function splitId(id) {
2690
+ var splitInfo = id.split(':');
2691
+ if (splitInfo.length === 1) {
2692
+ return {
2693
+ name: splitInfo[0],
2694
+ version: undefined
2695
+ };
2696
+ } else if (splitInfo.length === 2) {
2697
+ return {
2698
+ name: splitInfo[0],
2699
+ version: splitInfo[1]
2700
+ };
2701
+ } else {
2702
+ return {
2703
+ name: splitInfo[1],
2704
+ version: splitInfo[2]
2705
+ };
2706
+ }
2707
+ }
2708
+ function traverseModuleInfo(globalSnapshot, remoteInfo, traverse, isRoot) {
2709
+ var memo = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : {}, remoteSnapshot = arguments.length > 5 ? arguments[5] : void 0;
2710
+ var id = getFMId(remoteInfo);
2711
+ var _getInfoWithoutType = getInfoWithoutType(globalSnapshot, id), snapshotValue = _getInfoWithoutType.value;
2712
+ var effectiveRemoteSnapshot = remoteSnapshot || snapshotValue;
2713
+ if (effectiveRemoteSnapshot && !isManifestProvider(effectiveRemoteSnapshot)) {
2714
+ traverse(effectiveRemoteSnapshot, remoteInfo, isRoot);
2715
+ if (effectiveRemoteSnapshot.remotesInfo) {
2716
+ var remoteKeys = Object.keys(effectiveRemoteSnapshot.remotesInfo);
2717
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
2718
+ try {
2719
+ for(var _iterator = remoteKeys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2720
+ var key = _step.value;
2721
+ if (memo[key]) {
2722
+ continue;
2723
+ }
2724
+ memo[key] = true;
2725
+ var subRemoteInfo = splitId(key);
2726
+ var remoteValue = effectiveRemoteSnapshot.remotesInfo[key];
2727
+ traverseModuleInfo(globalSnapshot, {
2728
+ name: subRemoteInfo.name,
2729
+ version: remoteValue.matchedVersion
2730
+ }, traverse, false, memo, undefined);
2731
+ }
2732
+ } catch (err) {
2733
+ _didIteratorError = true;
2734
+ _iteratorError = err;
2735
+ } finally{
2736
+ try {
2737
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
2738
+ _iterator.return();
2739
+ }
2740
+ } finally{
2741
+ if (_didIteratorError) {
2742
+ throw _iteratorError;
2743
+ }
2744
+ }
2745
+ }
2746
+ }
2747
+ }
2748
+ }
2749
+ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, remoteSnapshot) {
2750
+ var cssAssets = [];
2751
+ var jsAssets = [];
2752
+ var entryAssets = [];
2753
+ var loadedSharedJsAssets = new Set();
2754
+ var loadedSharedCssAssets = new Set();
2755
+ var options = origin.options;
2756
+ var rootPreloadConfig = preloadOptions.preloadConfig;
2757
+ var depsRemote = rootPreloadConfig.depsRemote;
2758
+ var memo = {};
2759
+ traverseModuleInfo(globalSnapshot, remote, function(moduleInfoSnapshot, remoteInfo, isRoot) {
2760
+ var handleAssets = function handleAssets(assets) {
2761
+ var assetsRes = assets.map(function(asset) {
2762
+ return getResourceUrl(moduleInfoSnapshot, asset);
2763
+ });
2764
+ if (preloadConfig.filter) {
2765
+ return assetsRes.filter(preloadConfig.filter);
2766
+ }
2767
+ return assetsRes;
2768
+ };
2769
+ var preloadConfig;
2770
+ if (isRoot) {
2771
+ preloadConfig = rootPreloadConfig;
2772
+ } else {
2773
+ if (Array.isArray(depsRemote)) {
2774
+ var findPreloadConfig = depsRemote.find(function(remoteConfig) {
2775
+ if (remoteConfig.nameOrAlias === remoteInfo.name || remoteConfig.nameOrAlias === remoteInfo.alias) {
2776
+ return true;
2777
+ }
2778
+ return false;
2779
+ });
2780
+ if (!findPreloadConfig) {
2781
+ return;
2782
+ }
2783
+ preloadConfig = defaultPreloadArgs(findPreloadConfig);
2784
+ } else if (depsRemote === true) {
2785
+ preloadConfig = rootPreloadConfig;
2786
+ } else {
2787
+ return;
2788
+ }
2789
+ }
2790
+ var remoteEntryUrl = getResourceUrl(moduleInfoSnapshot, getRemoteEntryInfoFromSnapshot(moduleInfoSnapshot).url);
2791
+ if (remoteEntryUrl) {
2792
+ entryAssets.push({
2793
+ name: remoteInfo.name,
2794
+ moduleInfo: {
2795
+ name: remoteInfo.name,
2796
+ entry: remoteEntryUrl,
2797
+ type: 'remoteEntryType' in moduleInfoSnapshot ? moduleInfoSnapshot.remoteEntryType : 'global',
2798
+ entryGlobalName: 'globalName' in moduleInfoSnapshot ? moduleInfoSnapshot.globalName : remoteInfo.name,
2799
+ shareScope: '',
2800
+ version: 'version' in moduleInfoSnapshot ? moduleInfoSnapshot.version : undefined
2801
+ },
2802
+ url: remoteEntryUrl
2803
+ });
2804
+ }
2805
+ var moduleAssetsInfo = 'modules' in moduleInfoSnapshot ? moduleInfoSnapshot.modules : [];
2806
+ var normalizedPreloadExposes = normalizePreloadExposes(preloadConfig.exposes);
2807
+ if (normalizedPreloadExposes.length && 'modules' in moduleInfoSnapshot) {
2808
+ var _moduleInfoSnapshot_modules;
2809
+ moduleAssetsInfo = moduleInfoSnapshot == null ? void 0 : (_moduleInfoSnapshot_modules = moduleInfoSnapshot.modules) == null ? void 0 : _moduleInfoSnapshot_modules.reduce(function(assets, moduleAssetInfo) {
2810
+ if ((normalizedPreloadExposes == null ? void 0 : normalizedPreloadExposes.indexOf(moduleAssetInfo.moduleName)) !== -1) {
2811
+ assets.push(moduleAssetInfo);
2812
+ }
2813
+ return assets;
2814
+ }, []);
2815
+ }
2816
+ if (moduleAssetsInfo) {
2817
+ var assetsLength = moduleAssetsInfo.length;
2818
+ for(var index = 0; index < assetsLength; index++){
2819
+ var assetsInfo = moduleAssetsInfo[index];
2820
+ var exposeFullPath = "".concat(remoteInfo.name, "/").concat(assetsInfo.moduleName);
2821
+ origin.remoteHandler.hooks.lifecycle.handlePreloadModule.emit({
2822
+ id: assetsInfo.moduleName === '.' ? remoteInfo.name : exposeFullPath,
2823
+ name: remoteInfo.name,
2824
+ remoteSnapshot: moduleInfoSnapshot,
2825
+ preloadConfig: preloadConfig,
2826
+ remote: remoteInfo,
2827
+ origin: origin
2828
+ });
2829
+ var preloaded = getPreloaded(exposeFullPath);
2830
+ if (preloaded) {
2831
+ continue;
2832
+ }
2833
+ if (preloadConfig.resourceCategory === 'all') {
2834
+ var _cssAssets, _cssAssets1, _jsAssets, _jsAssets1;
2835
+ (_cssAssets = cssAssets).push.apply(_cssAssets, _to_consumable_array._(handleAssets(assetsInfo.assets.css.async)));
2836
+ (_cssAssets1 = cssAssets).push.apply(_cssAssets1, _to_consumable_array._(handleAssets(assetsInfo.assets.css.sync)));
2837
+ (_jsAssets = jsAssets).push.apply(_jsAssets, _to_consumable_array._(handleAssets(assetsInfo.assets.js.async)));
2838
+ (_jsAssets1 = jsAssets).push.apply(_jsAssets1, _to_consumable_array._(handleAssets(assetsInfo.assets.js.sync)));
2839
+ } else if (preloadConfig.resourceCategory = 'sync') {
2840
+ var _cssAssets2, _jsAssets2;
2841
+ (_cssAssets2 = cssAssets).push.apply(_cssAssets2, _to_consumable_array._(handleAssets(assetsInfo.assets.css.sync)));
2842
+ (_jsAssets2 = jsAssets).push.apply(_jsAssets2, _to_consumable_array._(handleAssets(assetsInfo.assets.js.sync)));
2843
+ }
2844
+ setPreloaded(exposeFullPath);
2845
+ }
2846
+ }
2847
+ }, true, memo, remoteSnapshot);
2848
+ if (remoteSnapshot.shared) {
2849
+ var collectSharedAssets = function(shareInfo, snapshotShared) {
2850
+ var registeredShared = getRegisteredShare(origin.shareScopeMap, snapshotShared.sharedName, shareInfo, origin.sharedHandler.hooks.lifecycle.resolveShare);
2851
+ if (registeredShared && typeof registeredShared.lib === 'function') {
2852
+ snapshotShared.assets.js.sync.forEach(function(asset) {
2853
+ loadedSharedJsAssets.add(asset);
2854
+ });
2855
+ snapshotShared.assets.css.sync.forEach(function(asset) {
2856
+ loadedSharedCssAssets.add(asset);
2857
+ });
2858
+ }
2859
+ };
2860
+ remoteSnapshot.shared.forEach(function(shared) {
2861
+ var _options_shared;
2862
+ var shareInfos = (_options_shared = options.shared) == null ? void 0 : _options_shared[shared.sharedName];
2863
+ if (!shareInfos) {
2864
+ return;
2865
+ }
2866
+ var sharedOptions = shared.version ? shareInfos.find(function(s) {
2867
+ return s.version === shared.version;
2868
+ }) : shareInfos;
2869
+ if (!sharedOptions) {
2870
+ return;
2871
+ }
2872
+ var arrayShareInfo = arrayOptions(sharedOptions);
2873
+ arrayShareInfo.forEach(function(s) {
2874
+ collectSharedAssets(s, shared);
2875
+ });
2876
+ });
2877
+ }
2878
+ var needPreloadJsAssets = jsAssets.filter(function(asset) {
2879
+ return !loadedSharedJsAssets.has(asset);
2880
+ });
2881
+ var needPreloadCssAssets = cssAssets.filter(function(asset) {
2882
+ return !loadedSharedCssAssets.has(asset);
2883
+ });
2884
+ return {
2885
+ cssAssets: needPreloadCssAssets,
2886
+ jsAssetsWithoutEntry: needPreloadJsAssets,
2887
+ entryAssets: entryAssets
2888
+ };
2889
+ }
2890
+ var generatePreloadAssetsPlugin = function generatePreloadAssetsPlugin() {
2891
+ return {
2892
+ name: 'generate-preload-assets-plugin',
2893
+ generatePreloadAssets: function generatePreloadAssets1(args) {
2894
+ return _async_to_generator._(function() {
2895
+ var origin, preloadOptions, remoteInfo, remote, globalSnapshot, remoteSnapshot, assets;
2896
+ return _ts_generator._(this, function(_state) {
2897
+ origin = args.origin, preloadOptions = args.preloadOptions, remoteInfo = args.remoteInfo, remote = args.remote, globalSnapshot = args.globalSnapshot, remoteSnapshot = args.remoteSnapshot;
2898
+ if (isRemoteInfoWithEntry(remote) && isPureRemoteEntry(remote)) {
2899
+ return [
2900
+ 2,
2901
+ {
2902
+ cssAssets: [],
2903
+ jsAssetsWithoutEntry: [],
2904
+ entryAssets: [
2905
+ {
2906
+ name: remote.name,
2907
+ url: remote.entry,
2908
+ moduleInfo: {
2909
+ name: remoteInfo.name,
2910
+ entry: remote.entry,
2911
+ type: 'global',
2912
+ entryGlobalName: '',
2913
+ shareScope: ''
2914
+ }
2915
+ }
2916
+ ]
2917
+ }
2918
+ ];
2919
+ }
2920
+ assignRemoteInfo(remoteInfo, remoteSnapshot);
2921
+ assets = generatePreloadAssets(origin, preloadOptions, remoteInfo, globalSnapshot, remoteSnapshot);
2922
+ return [
2923
+ 2,
2924
+ assets
2925
+ ];
2926
+ });
2927
+ })();
2928
+ }
2929
+ };
2930
+ };
2931
+ function getGlobalRemoteInfo(moduleInfo, origin) {
2932
+ var hostGlobalSnapshot = getGlobalSnapshotInfoByModuleInfo({
2933
+ name: origin.options.name,
2934
+ version: origin.options.version
2935
+ });
2936
+ var globalRemoteInfo = hostGlobalSnapshot && 'remotesInfo' in hostGlobalSnapshot && hostGlobalSnapshot.remotesInfo && getInfoWithoutType(hostGlobalSnapshot.remotesInfo, moduleInfo.name).value;
2937
+ if (globalRemoteInfo && globalRemoteInfo.matchedVersion) {
2938
+ return {
2939
+ hostGlobalSnapshot: hostGlobalSnapshot,
2940
+ globalSnapshot: getGlobalSnapshot(),
2941
+ remoteSnapshot: getGlobalSnapshotInfoByModuleInfo({
2942
+ name: moduleInfo.name,
2943
+ version: globalRemoteInfo.matchedVersion
2944
+ })
2945
+ };
2946
+ }
2947
+ return {
2948
+ hostGlobalSnapshot: undefined,
2949
+ globalSnapshot: getGlobalSnapshot(),
2950
+ remoteSnapshot: getGlobalSnapshotInfoByModuleInfo({
2951
+ name: moduleInfo.name,
2952
+ version: 'version' in moduleInfo ? moduleInfo.version : undefined
2953
+ })
2954
+ };
2955
+ }
2956
+ var SnapshotHandler = function() {
2957
+ function SnapshotHandler(HostInstance) {
2958
+ _class_call_check._(this, SnapshotHandler);
2959
+ this.loadingHostSnapshot = null;
2960
+ this.manifestCache = new Map();
2961
+ this.hooks = new PluginSystem({
2962
+ beforeLoadRemoteSnapshot: new AsyncHook('beforeLoadRemoteSnapshot'),
2963
+ loadSnapshot: new AsyncWaterfallHook('loadGlobalSnapshot'),
2964
+ loadRemoteSnapshot: new AsyncWaterfallHook('loadRemoteSnapshot')
2965
+ });
2966
+ this.manifestLoading = Global.__FEDERATION__.__MANIFEST_LOADING__;
2967
+ this.HostInstance = HostInstance;
2968
+ this.loaderHook = HostInstance.loaderHook;
2969
+ }
2970
+ _create_class._(SnapshotHandler, [
2971
+ {
2972
+ key: "loadSnapshot",
2973
+ value: function loadSnapshot(moduleInfo) {
2974
+ var _this = this;
2975
+ return _async_to_generator._(function() {
2976
+ var options, _this_getGlobalRemoteInfo, hostGlobalSnapshot, remoteSnapshot, globalSnapshot, _ref, globalRemoteSnapshot, globalSnapshotRes;
2977
+ return _ts_generator._(this, function(_state) {
2978
+ switch(_state.label){
2979
+ case 0:
2980
+ options = _this.HostInstance.options;
2981
+ _this_getGlobalRemoteInfo = _this.getGlobalRemoteInfo(moduleInfo), hostGlobalSnapshot = _this_getGlobalRemoteInfo.hostGlobalSnapshot, remoteSnapshot = _this_getGlobalRemoteInfo.remoteSnapshot, globalSnapshot = _this_getGlobalRemoteInfo.globalSnapshot;
2982
+ return [
2983
+ 4,
2984
+ _this.hooks.lifecycle.loadSnapshot.emit({
2985
+ options: options,
2986
+ moduleInfo: moduleInfo,
2987
+ hostGlobalSnapshot: hostGlobalSnapshot,
2988
+ remoteSnapshot: remoteSnapshot,
2989
+ globalSnapshot: globalSnapshot
2990
+ })
2991
+ ];
2992
+ case 1:
2993
+ _ref = _state.sent(), globalRemoteSnapshot = _ref.remoteSnapshot, globalSnapshotRes = _ref.globalSnapshot;
2994
+ return [
2995
+ 2,
2996
+ {
2997
+ remoteSnapshot: globalRemoteSnapshot,
2998
+ globalSnapshot: globalSnapshotRes
2999
+ }
3000
+ ];
3001
+ }
3002
+ });
3003
+ })();
3004
+ }
3005
+ },
3006
+ {
3007
+ key: "loadRemoteSnapshotInfo",
3008
+ value: function loadRemoteSnapshotInfo(moduleInfo) {
3009
+ var _this = this;
3010
+ return _async_to_generator._(function() {
3011
+ var options, hostSnapshot, _this_getGlobalRemoteInfo, hostGlobalSnapshot, remoteSnapshot, globalSnapshot, _ref, globalRemoteSnapshot, globalSnapshotRes, remoteEntry, moduleSnapshot, globalSnapshotRes1, _ref1, remoteSnapshotRes, moduleSnapshot1, globalSnapshotRes2, _ref2, remoteSnapshotRes1;
3012
+ return _ts_generator._(this, function(_state) {
3013
+ switch(_state.label){
3014
+ case 0:
3015
+ options = _this.HostInstance.options;
3016
+ return [
3017
+ 4,
3018
+ _this.hooks.lifecycle.beforeLoadRemoteSnapshot.emit({
3019
+ options: options,
3020
+ moduleInfo: moduleInfo
3021
+ })
3022
+ ];
3023
+ case 1:
3024
+ _state.sent();
3025
+ hostSnapshot = getGlobalSnapshotInfoByModuleInfo({
3026
+ name: _this.HostInstance.options.name,
3027
+ version: _this.HostInstance.options.version
3028
+ });
3029
+ if (!hostSnapshot) {
3030
+ hostSnapshot = {
3031
+ version: _this.HostInstance.options.version || '',
3032
+ remoteEntry: '',
3033
+ remotesInfo: {}
3034
+ };
3035
+ addGlobalSnapshot(_define_property._({}, _this.HostInstance.options.name, hostSnapshot));
3036
+ }
3037
+ if (hostSnapshot && 'remotesInfo' in hostSnapshot && !getInfoWithoutType(hostSnapshot.remotesInfo, moduleInfo.name).value) {
3038
+ if ('version' in moduleInfo || 'entry' in moduleInfo) {
3039
+ hostSnapshot.remotesInfo = _extends._({}, hostSnapshot == null ? void 0 : hostSnapshot.remotesInfo, _define_property._({}, moduleInfo.name, {
3040
+ matchedVersion: 'version' in moduleInfo ? moduleInfo.version : moduleInfo.entry
3041
+ }));
3042
+ }
3043
+ }
3044
+ _this_getGlobalRemoteInfo = _this.getGlobalRemoteInfo(moduleInfo), hostGlobalSnapshot = _this_getGlobalRemoteInfo.hostGlobalSnapshot, remoteSnapshot = _this_getGlobalRemoteInfo.remoteSnapshot, globalSnapshot = _this_getGlobalRemoteInfo.globalSnapshot;
3045
+ return [
3046
+ 4,
3047
+ _this.hooks.lifecycle.loadSnapshot.emit({
3048
+ options: options,
3049
+ moduleInfo: moduleInfo,
3050
+ hostGlobalSnapshot: hostGlobalSnapshot,
3051
+ remoteSnapshot: remoteSnapshot,
3052
+ globalSnapshot: globalSnapshot
3053
+ })
3054
+ ];
3055
+ case 2:
3056
+ _ref = _state.sent(), globalRemoteSnapshot = _ref.remoteSnapshot, globalSnapshotRes = _ref.globalSnapshot;
3057
+ if (!globalRemoteSnapshot) return [
3058
+ 3,
3059
+ 7
3060
+ ];
3061
+ if (!isManifestProvider(globalRemoteSnapshot)) return [
3062
+ 3,
3063
+ 4
3064
+ ];
3065
+ remoteEntry = isBrowserEnv() ? globalRemoteSnapshot.remoteEntry : globalRemoteSnapshot.ssrRemoteEntry || globalRemoteSnapshot.remoteEntry || '';
3066
+ return [
3067
+ 4,
3068
+ _this.getManifestJson(remoteEntry, moduleInfo, {})
3069
+ ];
3070
+ case 3:
3071
+ moduleSnapshot = _state.sent();
3072
+ globalSnapshotRes1 = setGlobalSnapshotInfoByModuleInfo(_extends._({}, moduleInfo, {
3073
+ entry: remoteEntry
3074
+ }), moduleSnapshot);
3075
+ return [
3076
+ 2,
3077
+ {
3078
+ remoteSnapshot: moduleSnapshot,
3079
+ globalSnapshot: globalSnapshotRes1
3080
+ }
3081
+ ];
3082
+ case 4:
3083
+ return [
3084
+ 4,
3085
+ _this.hooks.lifecycle.loadRemoteSnapshot.emit({
3086
+ options: _this.HostInstance.options,
3087
+ moduleInfo: moduleInfo,
3088
+ remoteSnapshot: globalRemoteSnapshot,
3089
+ from: 'global'
3090
+ })
3091
+ ];
3092
+ case 5:
3093
+ _ref1 = _state.sent(), remoteSnapshotRes = _ref1.remoteSnapshot;
3094
+ return [
3095
+ 2,
3096
+ {
3097
+ remoteSnapshot: remoteSnapshotRes,
3098
+ globalSnapshot: globalSnapshotRes
3099
+ }
3100
+ ];
3101
+ case 6:
3102
+ return [
3103
+ 3,
3104
+ 11
3105
+ ];
3106
+ case 7:
3107
+ if (!isRemoteInfoWithEntry(moduleInfo)) return [
3108
+ 3,
3109
+ 10
3110
+ ];
3111
+ return [
3112
+ 4,
3113
+ _this.getManifestJson(moduleInfo.entry, moduleInfo, {})
3114
+ ];
3115
+ case 8:
3116
+ moduleSnapshot1 = _state.sent();
3117
+ globalSnapshotRes2 = setGlobalSnapshotInfoByModuleInfo(moduleInfo, moduleSnapshot1);
3118
+ return [
3119
+ 4,
3120
+ _this.hooks.lifecycle.loadRemoteSnapshot.emit({
3121
+ options: _this.HostInstance.options,
3122
+ moduleInfo: moduleInfo,
3123
+ remoteSnapshot: moduleSnapshot1,
3124
+ from: 'global'
3125
+ })
3126
+ ];
3127
+ case 9:
3128
+ _ref2 = _state.sent(), remoteSnapshotRes1 = _ref2.remoteSnapshot;
3129
+ return [
3130
+ 2,
3131
+ {
3132
+ remoteSnapshot: remoteSnapshotRes1,
3133
+ globalSnapshot: globalSnapshotRes2
3134
+ }
3135
+ ];
3136
+ case 10:
3137
+ 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 "));
3138
+ _state.label = 11;
3139
+ case 11:
3140
+ return [
3141
+ 2
3142
+ ];
3143
+ }
3144
+ });
3145
+ })();
3146
+ }
3147
+ },
3148
+ {
3149
+ key: "getGlobalRemoteInfo",
3150
+ value: function getGlobalRemoteInfo1(moduleInfo) {
3151
+ return getGlobalRemoteInfo(moduleInfo, this.HostInstance);
3152
+ }
3153
+ },
3154
+ {
3155
+ key: "getManifestJson",
3156
+ value: function getManifestJson(manifestUrl, moduleInfo, extraOptions) {
3157
+ var _this = this;
3158
+ return _async_to_generator._(function() {
3159
+ var getManifest, asyncLoadProcess;
3160
+ return _ts_generator._(this, function(_state) {
3161
+ getManifest = function() {
3162
+ var _ref = _async_to_generator._(function() {
3163
+ var manifestJson, res, err;
3164
+ return _ts_generator._(this, function(_state) {
3165
+ switch(_state.label){
3166
+ case 0:
3167
+ manifestJson = _this.manifestCache.get(manifestUrl);
3168
+ if (manifestJson) {
3169
+ return [
3170
+ 2,
3171
+ manifestJson
3172
+ ];
3173
+ }
3174
+ _state.label = 1;
3175
+ case 1:
3176
+ _state.trys.push([
3177
+ 1,
3178
+ 6,
3179
+ ,
3180
+ 7
3181
+ ]);
3182
+ return [
3183
+ 4,
3184
+ _this.loaderHook.lifecycle.fetch.emit(manifestUrl, {})
3185
+ ];
3186
+ case 2:
3187
+ res = _state.sent();
3188
+ if (!(!res || !_instanceof._(res, Response))) return [
3189
+ 3,
3190
+ 4
3191
+ ];
3192
+ return [
3193
+ 4,
3194
+ fetch(manifestUrl, {})
3195
+ ];
3196
+ case 3:
3197
+ res = _state.sent();
3198
+ _state.label = 4;
3199
+ case 4:
3200
+ return [
3201
+ 4,
3202
+ res.json()
3203
+ ];
3204
+ case 5:
3205
+ manifestJson = _state.sent();
3206
+ assert(manifestJson.metaData && manifestJson.exposes && manifestJson.shared, "".concat(manifestUrl, " is not a federation manifest"));
3207
+ _this.manifestCache.set(manifestUrl, manifestJson);
3208
+ return [
3209
+ 2,
3210
+ manifestJson
3211
+ ];
3212
+ case 6:
3213
+ err = _state.sent();
3214
+ delete _this.manifestLoading[manifestUrl];
3215
+ 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));
3216
+ return [
3217
+ 3,
3218
+ 7
3219
+ ];
3220
+ case 7:
3221
+ return [
3222
+ 2
3223
+ ];
3224
+ }
3225
+ });
3226
+ });
3227
+ return function getManifest() {
3228
+ return _ref.apply(this, arguments);
3229
+ };
3230
+ }();
3231
+ asyncLoadProcess = function() {
3232
+ var _ref = _async_to_generator._(function() {
3233
+ var manifestJson, remoteSnapshot, _ref, remoteSnapshotRes;
3234
+ return _ts_generator._(this, function(_state) {
3235
+ switch(_state.label){
3236
+ case 0:
3237
+ return [
3238
+ 4,
3239
+ getManifest()
3240
+ ];
3241
+ case 1:
3242
+ manifestJson = _state.sent();
3243
+ remoteSnapshot = generateSnapshotFromManifest(manifestJson, {
3244
+ version: manifestUrl
3245
+ });
3246
+ return [
3247
+ 4,
3248
+ _this.hooks.lifecycle.loadRemoteSnapshot.emit({
3249
+ options: _this.HostInstance.options,
3250
+ moduleInfo: moduleInfo,
3251
+ manifestJson: manifestJson,
3252
+ remoteSnapshot: remoteSnapshot,
3253
+ manifestUrl: manifestUrl,
3254
+ from: 'manifest'
3255
+ })
3256
+ ];
3257
+ case 2:
3258
+ _ref = _state.sent(), remoteSnapshotRes = _ref.remoteSnapshot;
3259
+ return [
3260
+ 2,
3261
+ remoteSnapshotRes
3262
+ ];
3263
+ }
3264
+ });
3265
+ });
3266
+ return function asyncLoadProcess() {
3267
+ return _ref.apply(this, arguments);
3268
+ };
3269
+ }();
3270
+ if (!_this.manifestLoading[manifestUrl]) {
3271
+ _this.manifestLoading[manifestUrl] = asyncLoadProcess().then(function(res) {
3272
+ return res;
3273
+ });
3274
+ }
3275
+ return [
3276
+ 2,
3277
+ _this.manifestLoading[manifestUrl]
3278
+ ];
3279
+ });
3280
+ })();
3281
+ }
3282
+ }
3283
+ ]);
3284
+ return SnapshotHandler;
3285
+ }();
3286
+ var SharedHandler = function() {
3287
+ function SharedHandler(host) {
3288
+ _class_call_check._(this, SharedHandler);
3289
+ this.hooks = new PluginSystem({
3290
+ afterResolve: new AsyncWaterfallHook('afterResolve'),
3291
+ beforeLoadShare: new AsyncWaterfallHook('beforeLoadShare'),
3292
+ loadShare: new AsyncHook(),
3293
+ resolveShare: new SyncWaterfallHook('resolveShare'),
3294
+ initContainerShareScopeMap: new SyncWaterfallHook('initContainerShareScopeMap')
3295
+ });
3296
+ this.host = host;
3297
+ this.shareScopeMap = {};
3298
+ this._setGlobalShareScopeMap(host.options);
3299
+ }
3300
+ _create_class._(SharedHandler, [
3301
+ {
3302
+ key: "registerShared",
3303
+ value: function registerShared(globalOptions, userOptions) {
3304
+ var _this = this;
3305
+ var _formatShareConfigs = formatShareConfigs(globalOptions, userOptions), shareInfos = _formatShareConfigs.shareInfos, shared = _formatShareConfigs.shared;
3306
+ var sharedKeys = Object.keys(shareInfos);
3307
+ sharedKeys.forEach(function(sharedKey) {
3308
+ var sharedVals = shareInfos[sharedKey];
3309
+ sharedVals.forEach(function(sharedVal) {
3310
+ var registeredShared = getRegisteredShare(_this.shareScopeMap, sharedKey, sharedVal, _this.hooks.lifecycle.resolveShare);
3311
+ if (!registeredShared && sharedVal && sharedVal.lib) {
3312
+ _this.setShared({
3313
+ pkgName: sharedKey,
3314
+ lib: sharedVal.lib,
3315
+ get: sharedVal.get,
3316
+ loaded: true,
3317
+ shared: sharedVal,
3318
+ from: userOptions.name
3319
+ });
3320
+ }
3321
+ });
3322
+ });
3323
+ return {
3324
+ shareInfos: shareInfos,
3325
+ shared: shared
3326
+ };
3327
+ }
3328
+ },
3329
+ {
3330
+ key: "loadShare",
3331
+ value: function loadShare(pkgName, extraOptions) {
3332
+ var _this = this;
3333
+ return _async_to_generator._(function() {
3334
+ var host, shareInfo, loadShareRes, shareInfoRes, registeredShared, addUseIn, factory, asyncLoadProcess, loading, asyncLoadProcess1, loading1;
3335
+ return _ts_generator._(this, function(_state) {
3336
+ switch(_state.label){
3337
+ case 0:
3338
+ host = _this.host;
3339
+ shareInfo = getTargetSharedOptions({
3340
+ pkgName: pkgName,
3341
+ extraOptions: extraOptions,
3342
+ shareInfos: host.options.shared
3343
+ });
3344
+ if (!(shareInfo == null ? void 0 : shareInfo.scope)) return [
3345
+ 3,
3346
+ 2
3347
+ ];
3348
+ return [
3349
+ 4,
3350
+ Promise.all(shareInfo.scope.map(function() {
3351
+ var _ref = _async_to_generator._(function(shareScope) {
3352
+ return _ts_generator._(this, function(_state) {
3353
+ switch(_state.label){
3354
+ case 0:
3355
+ return [
3356
+ 4,
3357
+ Promise.all(_this.initializeSharing(shareScope, shareInfo.strategy))
3358
+ ];
3359
+ case 1:
3360
+ _state.sent();
3361
+ return [
3362
+ 2
3363
+ ];
3364
+ }
3365
+ });
3366
+ });
3367
+ return function(shareScope) {
3368
+ return _ref.apply(this, arguments);
3369
+ };
3370
+ }()))
3371
+ ];
3372
+ case 1:
3373
+ _state.sent();
3374
+ _state.label = 2;
3375
+ case 2:
3376
+ return [
3377
+ 4,
3378
+ _this.hooks.lifecycle.beforeLoadShare.emit({
3379
+ pkgName: pkgName,
3380
+ shareInfo: shareInfo,
3381
+ shared: host.options.shared,
3382
+ origin: host
3383
+ })
3384
+ ];
3385
+ case 3:
3386
+ loadShareRes = _state.sent();
3387
+ shareInfoRes = loadShareRes.shareInfo;
3388
+ assert(shareInfoRes, "Cannot find ".concat(pkgName, " Share in the ").concat(host.options.name, ". Please ensure that the ").concat(pkgName, " Share parameters have been injected"));
3389
+ registeredShared = getRegisteredShare(_this.shareScopeMap, pkgName, shareInfoRes, _this.hooks.lifecycle.resolveShare);
3390
+ addUseIn = function(shared) {
3391
+ if (!shared.useIn) {
3392
+ shared.useIn = [];
3393
+ }
3394
+ addUniqueItem(shared.useIn, host.options.name);
3395
+ };
3396
+ if (!(registeredShared && registeredShared.lib)) return [
3397
+ 3,
3398
+ 4
3399
+ ];
3400
+ addUseIn(registeredShared);
3401
+ return [
3402
+ 2,
3403
+ registeredShared.lib
3404
+ ];
3405
+ case 4:
3406
+ if (!(registeredShared && registeredShared.loading && !registeredShared.loaded)) return [
3407
+ 3,
3408
+ 6
3409
+ ];
3410
+ return [
3411
+ 4,
3412
+ registeredShared.loading
3413
+ ];
3414
+ case 5:
3415
+ factory = _state.sent();
3416
+ registeredShared.loaded = true;
3417
+ if (!registeredShared.lib) {
3418
+ registeredShared.lib = factory;
3419
+ }
3420
+ addUseIn(registeredShared);
3421
+ return [
3422
+ 2,
3423
+ factory
3424
+ ];
3425
+ case 6:
3426
+ if (registeredShared) {
3427
+ asyncLoadProcess = function() {
3428
+ var _ref = _async_to_generator._(function() {
3429
+ var factory, gShared;
3430
+ return _ts_generator._(this, function(_state) {
3431
+ switch(_state.label){
3432
+ case 0:
3433
+ return [
3434
+ 4,
3435
+ registeredShared.get()
3436
+ ];
3437
+ case 1:
3438
+ factory = _state.sent();
3439
+ shareInfoRes.lib = factory;
3440
+ shareInfoRes.loaded = true;
3441
+ addUseIn(shareInfoRes);
3442
+ gShared = getRegisteredShare(_this.shareScopeMap, pkgName, shareInfoRes, _this.hooks.lifecycle.resolveShare);
3443
+ if (gShared) {
3444
+ gShared.lib = factory;
3445
+ gShared.loaded = true;
3446
+ }
3447
+ return [
3448
+ 2,
3449
+ factory
3450
+ ];
3451
+ }
3452
+ });
3453
+ });
3454
+ return function asyncLoadProcess() {
3455
+ return _ref.apply(this, arguments);
3456
+ };
3457
+ }();
3458
+ loading = asyncLoadProcess();
3459
+ _this.setShared({
3460
+ pkgName: pkgName,
3461
+ loaded: false,
3462
+ shared: registeredShared,
3463
+ from: host.options.name,
3464
+ lib: null,
3465
+ loading: loading
3466
+ });
3467
+ return [
3468
+ 2,
3469
+ loading
3470
+ ];
3471
+ } else {
3472
+ if (extraOptions == null ? void 0 : extraOptions.customShareInfo) {
3473
+ return [
3474
+ 2,
3475
+ false
3476
+ ];
3477
+ }
3478
+ asyncLoadProcess1 = function() {
3479
+ var _ref = _async_to_generator._(function() {
3480
+ var factory, gShared;
3481
+ return _ts_generator._(this, function(_state) {
3482
+ switch(_state.label){
3483
+ case 0:
3484
+ return [
3485
+ 4,
3486
+ shareInfoRes.get()
3487
+ ];
3488
+ case 1:
3489
+ factory = _state.sent();
3490
+ shareInfoRes.lib = factory;
3491
+ shareInfoRes.loaded = true;
3492
+ addUseIn(shareInfoRes);
3493
+ gShared = getRegisteredShare(_this.shareScopeMap, pkgName, shareInfoRes, _this.hooks.lifecycle.resolveShare);
3494
+ if (gShared) {
3495
+ gShared.lib = factory;
3496
+ gShared.loaded = true;
3497
+ }
3498
+ return [
3499
+ 2,
3500
+ factory
3501
+ ];
3502
+ }
3503
+ });
3504
+ });
3505
+ return function asyncLoadProcess1() {
3506
+ return _ref.apply(this, arguments);
3507
+ };
3508
+ }();
3509
+ loading1 = asyncLoadProcess1();
3510
+ _this.setShared({
3511
+ pkgName: pkgName,
3512
+ loaded: false,
3513
+ shared: shareInfoRes,
3514
+ from: host.options.name,
3515
+ lib: null,
3516
+ loading: loading1
3517
+ });
3518
+ return [
3519
+ 2,
3520
+ loading1
3521
+ ];
3522
+ }
3523
+ case 7:
3524
+ return [
3525
+ 2
3526
+ ];
3527
+ }
3528
+ });
3529
+ })();
3530
+ }
3531
+ },
3532
+ {
3533
+ key: "initializeSharing",
3534
+ value: function initializeSharing() {
3535
+ var shareScopeName = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : DEFAULT_SCOPE, strategy = arguments.length > 1 ? arguments[1] : void 0;
3536
+ var host = this.host;
3537
+ var shareScope = this.shareScopeMap;
3538
+ var hostName = host.options.name;
3539
+ if (!shareScope[shareScopeName]) {
3540
+ shareScope[shareScopeName] = {};
3541
+ }
3542
+ var scope = shareScope[shareScopeName];
3543
+ var register = function(name, shared) {
3544
+ var _activeVersion_shareConfig;
3545
+ var version = shared.version, eager = shared.eager;
3546
+ scope[name] = scope[name] || {};
3547
+ var versions = scope[name];
3548
+ var activeVersion = versions[version];
3549
+ var activeVersionEager = Boolean(activeVersion && (activeVersion.eager || ((_activeVersion_shareConfig = activeVersion.shareConfig) == null ? void 0 : _activeVersion_shareConfig.eager)));
3550
+ if (!activeVersion || activeVersion.strategy !== 'loaded-first' && !activeVersion.loaded && (Boolean(!eager) !== !activeVersionEager ? eager : hostName > activeVersion.from)) {
3551
+ versions[version] = shared;
3552
+ }
3553
+ };
3554
+ var promises = [];
3555
+ var initFn = function(mod) {
3556
+ return mod && mod.init && mod.init(shareScope[shareScopeName]);
3557
+ };
3558
+ var initRemoteModule = function() {
3559
+ var _ref = _async_to_generator._(function(key) {
3560
+ var module, entry;
3561
+ return _ts_generator._(this, function(_state) {
3562
+ switch(_state.label){
3563
+ case 0:
3564
+ return [
3565
+ 4,
3566
+ host.remoteHandler.getRemoteModuleAndOptions({
3567
+ id: key
3568
+ })
3569
+ ];
3570
+ case 1:
3571
+ module = _state.sent().module;
3572
+ if (!module.getEntry) return [
3573
+ 3,
3574
+ 3
3575
+ ];
3576
+ return [
3577
+ 4,
3578
+ module.getEntry()
3579
+ ];
3580
+ case 2:
3581
+ entry = _state.sent();
3582
+ if (!module.inited) {
3583
+ initFn(entry);
3584
+ module.inited = true;
3585
+ }
3586
+ _state.label = 3;
3587
+ case 3:
3588
+ return [
3589
+ 2
3590
+ ];
3591
+ }
3592
+ });
3593
+ });
3594
+ return function initRemoteModule(key) {
3595
+ return _ref.apply(this, arguments);
3596
+ };
3597
+ }();
3598
+ Object.keys(host.options.shared).forEach(function(shareName) {
3599
+ var sharedArr = host.options.shared[shareName];
3600
+ sharedArr.forEach(function(shared) {
3601
+ if (shared.scope.includes(shareScopeName)) {
3602
+ register(shareName, shared);
3603
+ }
3604
+ });
3605
+ });
3606
+ if (host.options.shareStrategy === 'version-first' || strategy === 'version-first') {
3607
+ host.options.remotes.forEach(function(remote) {
3608
+ if (remote.shareScope === shareScopeName) {
3609
+ promises.push(initRemoteModule(remote.name));
3610
+ }
3611
+ });
3612
+ }
3613
+ return promises;
3614
+ }
3615
+ },
3616
+ {
3617
+ key: "loadShareSync",
3618
+ value: function loadShareSync(pkgName, extraOptions) {
3619
+ var _this = this;
3620
+ var host = this.host;
3621
+ var shareInfo = getTargetSharedOptions({
3622
+ pkgName: pkgName,
3623
+ extraOptions: extraOptions,
3624
+ shareInfos: host.options.shared
3625
+ });
3626
+ if (shareInfo == null ? void 0 : shareInfo.scope) {
3627
+ shareInfo.scope.forEach(function(shareScope) {
3628
+ _this.initializeSharing(shareScope, shareInfo.strategy);
3629
+ });
3630
+ }
3631
+ var registeredShared = getRegisteredShare(this.shareScopeMap, pkgName, shareInfo, this.hooks.lifecycle.resolveShare);
3632
+ var addUseIn = function(shared) {
3633
+ if (!shared.useIn) {
3634
+ shared.useIn = [];
3635
+ }
3636
+ addUniqueItem(shared.useIn, host.options.name);
3637
+ };
3638
+ if (registeredShared) {
3639
+ if (typeof registeredShared.lib === 'function') {
3640
+ addUseIn(registeredShared);
3641
+ if (!registeredShared.loaded) {
3642
+ registeredShared.loaded = true;
3643
+ if (registeredShared.from === host.options.name) {
3644
+ shareInfo.loaded = true;
3645
+ }
3646
+ }
3647
+ return registeredShared.lib;
3648
+ }
3649
+ if (typeof registeredShared.get === 'function') {
3650
+ var module = registeredShared.get();
3651
+ if (!_instanceof._(module, Promise)) {
3652
+ addUseIn(registeredShared);
3653
+ this.setShared({
3654
+ pkgName: pkgName,
3655
+ loaded: true,
3656
+ from: host.options.name,
3657
+ lib: module,
3658
+ shared: registeredShared
3659
+ });
3660
+ return module;
3661
+ }
3662
+ }
3663
+ }
3664
+ if (shareInfo.lib) {
3665
+ if (!shareInfo.loaded) {
3666
+ shareInfo.loaded = true;
3667
+ }
3668
+ return shareInfo.lib;
3669
+ }
3670
+ if (shareInfo.get) {
3671
+ var module1 = shareInfo.get();
3672
+ if (_instanceof._(module1, Promise)) {
3673
+ throw new Error("\n The loadShareSync function was unable to load ".concat(pkgName, ". The ").concat(pkgName, " could not be found in ").concat(host.options.name, ".\n Possible reasons for failure: \n\n 1. The ").concat(pkgName, " share was registered with the 'get' attribute, but loadShare was not used beforehand.\n\n 2. The ").concat(pkgName, " share was not registered with the 'lib' attribute.\n\n "));
3674
+ }
3675
+ shareInfo.lib = module1;
3676
+ this.setShared({
3677
+ pkgName: pkgName,
3678
+ loaded: true,
3679
+ from: host.options.name,
3680
+ lib: shareInfo.lib,
3681
+ shared: shareInfo
3682
+ });
3683
+ return shareInfo.lib;
3684
+ }
3685
+ throw new Error("\n The loadShareSync function was unable to load ".concat(pkgName, ". The ").concat(pkgName, " could not be found in ").concat(host.options.name, ".\n Possible reasons for failure: \n\n 1. The ").concat(pkgName, " share was registered with the 'get' attribute, but loadShare was not used beforehand.\n\n 2. The ").concat(pkgName, " share was not registered with the 'lib' attribute.\n\n "));
3686
+ }
3687
+ },
3688
+ {
3689
+ key: "initShareScopeMap",
3690
+ value: function initShareScopeMap(scopeName, shareScope) {
3691
+ var extraOptions = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
3692
+ var host = this.host;
3693
+ this.shareScopeMap[scopeName] = shareScope;
3694
+ this.hooks.lifecycle.initContainerShareScopeMap.emit({
3695
+ shareScope: shareScope,
3696
+ options: host.options,
3697
+ origin: host,
3698
+ scopeName: scopeName,
3699
+ hostShareScopeMap: extraOptions.hostShareScopeMap
3700
+ });
3701
+ }
3702
+ },
3703
+ {
3704
+ key: "setShared",
3705
+ value: function setShared(param) {
3706
+ var _this = this;
3707
+ var pkgName = param.pkgName, shared = param.shared; param.from; var lib = param.lib, loading = param.loading, loaded = param.loaded, get = param.get;
3708
+ var version = shared.version, _shared_scope = shared.scope, scope = _shared_scope === void 0 ? 'default' : _shared_scope, shareInfo = _object_without_properties_loose._(shared, [
3709
+ "version",
3710
+ "scope"
3711
+ ]);
3712
+ var scopes = Array.isArray(scope) ? scope : [
3713
+ scope
3714
+ ];
3715
+ scopes.forEach(function(sc) {
3716
+ if (!_this.shareScopeMap[sc]) {
3717
+ _this.shareScopeMap[sc] = {};
3718
+ }
3719
+ if (!_this.shareScopeMap[sc][pkgName]) {
3720
+ _this.shareScopeMap[sc][pkgName] = {};
3721
+ }
3722
+ if (_this.shareScopeMap[sc][pkgName][version]) {
3723
+ return;
3724
+ }
3725
+ _this.shareScopeMap[sc][pkgName][version] = _extends._({
3726
+ version: version,
3727
+ scope: [
3728
+ 'default'
3729
+ ]
3730
+ }, shareInfo, {
3731
+ lib: lib,
3732
+ loaded: loaded,
3733
+ loading: loading
3734
+ });
3735
+ if (get) {
3736
+ _this.shareScopeMap[sc][pkgName][version].get = get;
3737
+ }
3738
+ });
3739
+ }
3740
+ },
3741
+ {
3742
+ key: "_setGlobalShareScopeMap",
3743
+ value: function _setGlobalShareScopeMap(hostOptions) {
3744
+ var globalShareScopeMap = getGlobalShareScope();
3745
+ var identifier = hostOptions.id || hostOptions.name;
3746
+ if (identifier && !globalShareScopeMap[identifier]) {
3747
+ globalShareScopeMap[identifier] = this.shareScopeMap;
3748
+ }
3749
+ }
3750
+ }
3751
+ ]);
3752
+ return SharedHandler;
3753
+ }();
3754
+ var RemoteHandler = function() {
3755
+ function RemoteHandler(host) {
3756
+ _class_call_check._(this, RemoteHandler);
3757
+ this.hooks = new PluginSystem({
3758
+ beforeRegisterRemote: new SyncWaterfallHook('beforeRegisterRemote'),
3759
+ registerRemote: new SyncWaterfallHook('registerRemote'),
3760
+ beforeRequest: new AsyncWaterfallHook('beforeRequest'),
3761
+ onLoad: new AsyncHook('onLoad'),
3762
+ handlePreloadModule: new SyncHook('handlePreloadModule'),
3763
+ errorLoadRemote: new AsyncHook('errorLoadRemote'),
3764
+ beforePreloadRemote: new AsyncHook('beforePreloadRemote'),
3765
+ generatePreloadAssets: new AsyncHook('generatePreloadAssets'),
3766
+ afterPreloadRemote: new AsyncHook(),
3767
+ loadEntry: new AsyncHook()
3768
+ });
3769
+ this.host = host;
3770
+ this.idToRemoteMap = {};
3771
+ }
3772
+ _create_class._(RemoteHandler, [
3773
+ {
3774
+ key: "formatAndRegisterRemote",
3775
+ value: function formatAndRegisterRemote(globalOptions, userOptions) {
3776
+ var _this = this;
3777
+ var userRemotes = userOptions.remotes || [];
3778
+ return userRemotes.reduce(function(res, remote) {
3779
+ _this.registerRemote(remote, res, {
3780
+ force: false
3781
+ });
3782
+ return res;
3783
+ }, globalOptions.remotes);
3784
+ }
3785
+ },
3786
+ {
3787
+ key: "setIdToRemoteMap",
3788
+ value: function setIdToRemoteMap(id, remoteMatchInfo) {
3789
+ var remote = remoteMatchInfo.remote, expose = remoteMatchInfo.expose;
3790
+ var name = remote.name, alias = remote.alias;
3791
+ this.idToRemoteMap[id] = {
3792
+ name: remote.name,
3793
+ expose: expose
3794
+ };
3795
+ if (alias && id.startsWith(name)) {
3796
+ var idWithAlias = id.replace(name, alias);
3797
+ this.idToRemoteMap[idWithAlias] = {
3798
+ name: remote.name,
3799
+ expose: expose
3800
+ };
3801
+ return;
3802
+ }
3803
+ if (alias && id.startsWith(alias)) {
3804
+ var idWithName = id.replace(alias, name);
3805
+ this.idToRemoteMap[idWithName] = {
3806
+ name: remote.name,
3807
+ expose: expose
3808
+ };
3809
+ }
3810
+ }
3811
+ },
3812
+ {
3813
+ key: "loadRemote",
3814
+ value: function loadRemote(id, options) {
3815
+ var _this = this;
3816
+ return _async_to_generator._(function() {
3817
+ var host, _ref, _ref_loadFactory, loadFactory, _ref1, module, moduleOptions, remoteMatchInfo, pkgNameOrAlias, remote, expose, idRes, moduleOrFactory, moduleWrapper, error, _ref2, _ref_from, from, failOver;
3818
+ return _ts_generator._(this, function(_state) {
3819
+ switch(_state.label){
3820
+ case 0:
3821
+ host = _this.host;
3822
+ _state.label = 1;
3823
+ case 1:
3824
+ _state.trys.push([
3825
+ 1,
3826
+ 5,
3827
+ ,
3828
+ 7
3829
+ ]);
3830
+ _ref = options || {
3831
+ loadFactory: true
3832
+ }, _ref_loadFactory = _ref.loadFactory, loadFactory = _ref_loadFactory === void 0 ? true : _ref_loadFactory;
3833
+ return [
3834
+ 4,
3835
+ _this.getRemoteModuleAndOptions({
3836
+ id: id
3837
+ })
3838
+ ];
3839
+ case 2:
3840
+ _ref1 = _state.sent(), module = _ref1.module, moduleOptions = _ref1.moduleOptions, remoteMatchInfo = _ref1.remoteMatchInfo;
3841
+ pkgNameOrAlias = remoteMatchInfo.pkgNameOrAlias, remote = remoteMatchInfo.remote, expose = remoteMatchInfo.expose, idRes = remoteMatchInfo.id;
3842
+ return [
3843
+ 4,
3844
+ module.get(idRes, expose, options)
3845
+ ];
3846
+ case 3:
3847
+ moduleOrFactory = _state.sent();
3848
+ return [
3849
+ 4,
3850
+ _this.hooks.lifecycle.onLoad.emit({
3851
+ id: idRes,
3852
+ pkgNameOrAlias: pkgNameOrAlias,
3853
+ expose: expose,
3854
+ exposeModule: loadFactory ? moduleOrFactory : undefined,
3855
+ exposeModuleFactory: loadFactory ? undefined : moduleOrFactory,
3856
+ remote: remote,
3857
+ options: moduleOptions,
3858
+ moduleInstance: module,
3859
+ origin: host
3860
+ })
3861
+ ];
3862
+ case 4:
3863
+ moduleWrapper = _state.sent();
3864
+ _this.setIdToRemoteMap(id, remoteMatchInfo);
3865
+ if (typeof moduleWrapper === 'function') {
3866
+ return [
3867
+ 2,
3868
+ moduleWrapper
3869
+ ];
3870
+ }
3871
+ return [
3872
+ 2,
3873
+ moduleOrFactory
3874
+ ];
3875
+ case 5:
3876
+ error = _state.sent();
3877
+ _ref2 = options || {
3878
+ from: 'runtime'
3879
+ }, _ref_from = _ref2.from, from = _ref_from === void 0 ? 'runtime' : _ref_from;
3880
+ return [
3881
+ 4,
3882
+ _this.hooks.lifecycle.errorLoadRemote.emit({
3883
+ id: id,
3884
+ error: error,
3885
+ from: from,
3886
+ lifecycle: 'onLoad',
3887
+ origin: host
3888
+ })
3889
+ ];
3890
+ case 6:
3891
+ failOver = _state.sent();
3892
+ if (!failOver) {
3893
+ throw error;
3894
+ }
3895
+ return [
3896
+ 2,
3897
+ failOver
3898
+ ];
3899
+ case 7:
3900
+ return [
3901
+ 2
3902
+ ];
3903
+ }
3904
+ });
3905
+ })();
3906
+ }
3907
+ },
3908
+ {
3909
+ key: "preloadRemote",
3910
+ value: function preloadRemote(preloadOptions) {
3911
+ var _this = this;
3912
+ return _async_to_generator._(function() {
3913
+ var host, preloadOps;
3914
+ return _ts_generator._(this, function(_state) {
3915
+ switch(_state.label){
3916
+ case 0:
3917
+ host = _this.host;
3918
+ return [
3919
+ 4,
3920
+ _this.hooks.lifecycle.beforePreloadRemote.emit({
3921
+ preloadOps: preloadOptions,
3922
+ options: host.options,
3923
+ origin: host
3924
+ })
3925
+ ];
3926
+ case 1:
3927
+ _state.sent();
3928
+ preloadOps = formatPreloadArgs(host.options.remotes, preloadOptions);
3929
+ return [
3930
+ 4,
3931
+ Promise.all(preloadOps.map(function() {
3932
+ var _ref = _async_to_generator._(function(ops) {
3933
+ var remote, remoteInfo, _ref, globalSnapshot, remoteSnapshot, assets;
3934
+ return _ts_generator._(this, function(_state) {
3935
+ switch(_state.label){
3936
+ case 0:
3937
+ remote = ops.remote;
3938
+ remoteInfo = getRemoteInfo(remote);
3939
+ return [
3940
+ 4,
3941
+ host.snapshotHandler.loadRemoteSnapshotInfo(remote)
3942
+ ];
3943
+ case 1:
3944
+ _ref = _state.sent(), globalSnapshot = _ref.globalSnapshot, remoteSnapshot = _ref.remoteSnapshot;
3945
+ return [
3946
+ 4,
3947
+ _this.hooks.lifecycle.generatePreloadAssets.emit({
3948
+ origin: host,
3949
+ preloadOptions: ops,
3950
+ remote: remote,
3951
+ remoteInfo: remoteInfo,
3952
+ globalSnapshot: globalSnapshot,
3953
+ remoteSnapshot: remoteSnapshot
3954
+ })
3955
+ ];
3956
+ case 2:
3957
+ assets = _state.sent();
3958
+ if (!assets) {
3959
+ return [
3960
+ 2
3961
+ ];
3962
+ }
3963
+ preloadAssets(remoteInfo, host, assets);
3964
+ return [
3965
+ 2
3966
+ ];
3967
+ }
3968
+ });
3969
+ });
3970
+ return function(ops) {
3971
+ return _ref.apply(this, arguments);
3972
+ };
3973
+ }()))
3974
+ ];
3975
+ case 2:
3976
+ _state.sent();
3977
+ return [
3978
+ 2
3979
+ ];
3980
+ }
3981
+ });
3982
+ })();
3983
+ }
3984
+ },
3985
+ {
3986
+ key: "registerRemotes",
3987
+ value: function registerRemotes(remotes, options) {
3988
+ var _this = this;
3989
+ var host = this.host;
3990
+ remotes.forEach(function(remote) {
3991
+ _this.registerRemote(remote, host.options.remotes, {
3992
+ force: options == null ? void 0 : options.force
3993
+ });
3994
+ });
3995
+ }
3996
+ },
3997
+ {
3998
+ key: "getRemoteModuleAndOptions",
3999
+ value: function getRemoteModuleAndOptions(options) {
4000
+ var _this = this;
4001
+ return _async_to_generator._(function() {
4002
+ var host, id, loadRemoteArgs, error, idRes, remoteSplitInfo, rawRemote, remoteInfo, matchInfo, remote, expose, module, moduleOptions;
4003
+ return _ts_generator._(this, function(_state) {
4004
+ switch(_state.label){
4005
+ case 0:
4006
+ host = _this.host;
4007
+ id = options.id;
4008
+ _state.label = 1;
4009
+ case 1:
4010
+ _state.trys.push([
4011
+ 1,
4012
+ 3,
4013
+ ,
4014
+ 5
4015
+ ]);
4016
+ return [
4017
+ 4,
4018
+ _this.hooks.lifecycle.beforeRequest.emit({
4019
+ id: id,
4020
+ options: host.options,
4021
+ origin: host
4022
+ })
4023
+ ];
4024
+ case 2:
4025
+ loadRemoteArgs = _state.sent();
4026
+ return [
4027
+ 3,
4028
+ 5
4029
+ ];
4030
+ case 3:
4031
+ error = _state.sent();
4032
+ return [
4033
+ 4,
4034
+ _this.hooks.lifecycle.errorLoadRemote.emit({
4035
+ id: id,
4036
+ options: host.options,
4037
+ origin: host,
4038
+ from: 'runtime',
4039
+ error: error,
4040
+ lifecycle: 'beforeRequest'
4041
+ })
4042
+ ];
4043
+ case 4:
4044
+ loadRemoteArgs = _state.sent();
4045
+ if (!loadRemoteArgs) {
4046
+ throw error;
4047
+ }
4048
+ return [
4049
+ 3,
4050
+ 5
4051
+ ];
4052
+ case 5:
4053
+ idRes = loadRemoteArgs.id;
4054
+ remoteSplitInfo = matchRemoteWithNameAndExpose(host.options.remotes, idRes);
4055
+ assert(remoteSplitInfo, "\n Unable to locate ".concat(idRes, " in ").concat(host.options.name, ". Potential reasons for failure include:\n\n 1. ").concat(idRes, " was not included in the 'remotes' parameter of ").concat(host.options.name || 'the host', ".\n\n 2. ").concat(idRes, " could not be found in the 'remotes' of ").concat(host.options.name, " with either 'name' or 'alias' attributes.\n 3. ").concat(idRes, " is not online, injected, or loaded.\n 4. ").concat(idRes, " cannot be accessed on the expected.\n 5. The 'beforeRequest' hook was provided but did not return the correct 'remoteInfo' when attempting to load ").concat(idRes, ".\n "));
4056
+ rawRemote = remoteSplitInfo.remote;
4057
+ remoteInfo = getRemoteInfo(rawRemote);
4058
+ return [
4059
+ 4,
4060
+ host.sharedHandler.hooks.lifecycle.afterResolve.emit(_extends._({
4061
+ id: idRes
4062
+ }, remoteSplitInfo, {
4063
+ options: host.options,
4064
+ origin: host,
4065
+ remoteInfo: remoteInfo
4066
+ }))
4067
+ ];
4068
+ case 6:
4069
+ matchInfo = _state.sent();
4070
+ remote = matchInfo.remote, expose = matchInfo.expose;
4071
+ assert(remote && expose, "The 'beforeRequest' hook was executed, but it failed to return the correct 'remote' and 'expose' values while loading ".concat(idRes, "."));
4072
+ module = host.moduleCache.get(remote.name);
4073
+ moduleOptions = {
4074
+ host: host,
4075
+ remoteInfo: remoteInfo
4076
+ };
4077
+ if (!module) {
4078
+ module = new Module(moduleOptions);
4079
+ host.moduleCache.set(remote.name, module);
4080
+ }
4081
+ return [
4082
+ 2,
4083
+ {
4084
+ module: module,
4085
+ moduleOptions: moduleOptions,
4086
+ remoteMatchInfo: matchInfo
4087
+ }
4088
+ ];
4089
+ }
4090
+ });
4091
+ })();
4092
+ }
4093
+ },
4094
+ {
4095
+ key: "registerRemote",
4096
+ value: function registerRemote(remote, targetRemotes, options) {
4097
+ var host = this.host;
4098
+ var normalizeRemote = function() {
4099
+ if (remote.alias) {
4100
+ var findEqual = targetRemotes.find(function(item) {
4101
+ var _item_alias;
4102
+ return remote.alias && (item.name.startsWith(remote.alias) || ((_item_alias = item.alias) == null ? void 0 : _item_alias.startsWith(remote.alias)));
4103
+ });
4104
+ 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"));
4105
+ }
4106
+ if ('entry' in remote) {
4107
+ if (isBrowserEnv() && !remote.entry.startsWith('http')) {
4108
+ remote.entry = new URL(remote.entry, window.location.origin).href;
4109
+ }
4110
+ }
4111
+ if (!remote.shareScope) {
4112
+ remote.shareScope = DEFAULT_SCOPE;
4113
+ }
4114
+ if (!remote.type) {
4115
+ remote.type = DEFAULT_REMOTE_TYPE;
4116
+ }
4117
+ };
4118
+ this.hooks.lifecycle.beforeRegisterRemote.emit({
4119
+ remote: remote,
4120
+ origin: host
4121
+ });
4122
+ var registeredRemote = targetRemotes.find(function(item) {
4123
+ return item.name === remote.name;
4124
+ });
4125
+ if (!registeredRemote) {
4126
+ normalizeRemote();
4127
+ targetRemotes.push(remote);
4128
+ this.hooks.lifecycle.registerRemote.emit({
4129
+ remote: remote,
4130
+ origin: host
4131
+ });
4132
+ } else {
4133
+ var messages = [
4134
+ 'The remote "'.concat(remote.name, '" is already registered.'),
4135
+ (options == null ? void 0 : options.force) ? 'Hope you have known that OVERRIDE it may have some unexpected errors' : 'If you want to merge the remote, you can set "force: true".'
4136
+ ];
4137
+ if (options == null ? void 0 : options.force) {
4138
+ this.removeRemote(registeredRemote);
4139
+ normalizeRemote();
4140
+ targetRemotes.push(remote);
4141
+ this.hooks.lifecycle.registerRemote.emit({
4142
+ remote: remote,
4143
+ origin: host
4144
+ });
4145
+ }
4146
+ warn$1(messages.join(' '));
4147
+ }
4148
+ }
4149
+ },
4150
+ {
4151
+ key: "removeRemote",
4152
+ value: function removeRemote(remote) {
4153
+ try {
4154
+ var host = this.host;
4155
+ var name = remote.name;
4156
+ var remoteIndex = host.options.remotes.findIndex(function(item) {
4157
+ return item.name === name;
4158
+ });
4159
+ if (remoteIndex !== -1) {
4160
+ host.options.remotes.splice(remoteIndex, 1);
4161
+ }
4162
+ var loadedModule = host.moduleCache.get(remote.name);
4163
+ if (loadedModule) {
4164
+ var remoteInfo = loadedModule.remoteInfo;
4165
+ var key = remoteInfo.entryGlobalName;
4166
+ if (globalThis[key]) {
4167
+ var _Object_getOwnPropertyDescriptor;
4168
+ if ((_Object_getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor(globalThis, key)) == null ? void 0 : _Object_getOwnPropertyDescriptor.configurable) {
4169
+ delete globalThis[key];
4170
+ } else {
4171
+ globalThis[key] = undefined;
4172
+ }
4173
+ }
4174
+ var remoteEntryUniqueKey = getRemoteEntryUniqueKey(loadedModule.remoteInfo);
4175
+ if (globalLoading[remoteEntryUniqueKey]) {
4176
+ delete globalLoading[remoteEntryUniqueKey];
4177
+ }
4178
+ host.snapshotHandler.manifestCache.delete(remoteInfo.entry);
4179
+ var remoteInsId = remoteInfo.buildVersion ? composeKeyWithSeparator(remoteInfo.name, remoteInfo.buildVersion) : remoteInfo.name;
4180
+ var remoteInsIndex = globalThis.__FEDERATION__.__INSTANCES__.findIndex(function(ins) {
4181
+ if (remoteInfo.buildVersion) {
4182
+ return ins.options.id === remoteInsId;
4183
+ } else {
4184
+ return ins.name === remoteInsId;
4185
+ }
4186
+ });
4187
+ if (remoteInsIndex !== -1) {
4188
+ var remoteIns = globalThis.__FEDERATION__.__INSTANCES__[remoteInsIndex];
4189
+ remoteInsId = remoteIns.options.id || remoteInsId;
4190
+ var globalShareScopeMap = getGlobalShareScope();
4191
+ var isAllSharedNotUsed = true;
4192
+ var needDeleteKeys = [];
4193
+ Object.keys(globalShareScopeMap).forEach(function(instId) {
4194
+ var shareScopeMap = globalShareScopeMap[instId];
4195
+ shareScopeMap && Object.keys(shareScopeMap).forEach(function(shareScope) {
4196
+ var shareScopeVal = shareScopeMap[shareScope];
4197
+ shareScopeVal && Object.keys(shareScopeVal).forEach(function(shareName) {
4198
+ var sharedPkgs = shareScopeVal[shareName];
4199
+ sharedPkgs && Object.keys(sharedPkgs).forEach(function(shareVersion) {
4200
+ var shared = sharedPkgs[shareVersion];
4201
+ if (shared && (typeof shared === "undefined" ? "undefined" : _type_of._(shared)) === 'object' && shared.from === remoteInfo.name) {
4202
+ if (shared.loaded || shared.loading) {
4203
+ shared.useIn = shared.useIn.filter(function(usedHostName) {
4204
+ return usedHostName !== remoteInfo.name;
4205
+ });
4206
+ if (shared.useIn.length) {
4207
+ isAllSharedNotUsed = false;
4208
+ } else {
4209
+ needDeleteKeys.push([
4210
+ instId,
4211
+ shareScope,
4212
+ shareName,
4213
+ shareVersion
4214
+ ]);
4215
+ }
4216
+ } else {
4217
+ needDeleteKeys.push([
4218
+ instId,
4219
+ shareScope,
4220
+ shareName,
4221
+ shareVersion
4222
+ ]);
4223
+ }
4224
+ }
4225
+ });
4226
+ });
4227
+ });
4228
+ });
4229
+ if (isAllSharedNotUsed) {
4230
+ remoteIns.shareScopeMap = {};
4231
+ delete globalShareScopeMap[remoteInsId];
4232
+ }
4233
+ needDeleteKeys.forEach(function(param) {
4234
+ var _param = _sliced_to_array._(param, 4), insId = _param[0], shareScope = _param[1], shareName = _param[2], shareVersion = _param[3];
4235
+ var _globalShareScopeMap_insId_shareScope_shareName, _globalShareScopeMap_insId_shareScope, _globalShareScopeMap_insId;
4236
+ (_globalShareScopeMap_insId = globalShareScopeMap[insId]) == null ? true : (_globalShareScopeMap_insId_shareScope = _globalShareScopeMap_insId[shareScope]) == null ? true : (_globalShareScopeMap_insId_shareScope_shareName = _globalShareScopeMap_insId_shareScope[shareName]) == null ? true : delete _globalShareScopeMap_insId_shareScope_shareName[shareVersion];
4237
+ });
4238
+ globalThis.__FEDERATION__.__INSTANCES__.splice(remoteInsIndex, 1);
4239
+ }
4240
+ var hostGlobalSnapshot = getGlobalRemoteInfo(remote, host).hostGlobalSnapshot;
4241
+ if (hostGlobalSnapshot) {
4242
+ var remoteKey = hostGlobalSnapshot && 'remotesInfo' in hostGlobalSnapshot && hostGlobalSnapshot.remotesInfo && getInfoWithoutType(hostGlobalSnapshot.remotesInfo, remote.name).key;
4243
+ if (remoteKey) {
4244
+ delete hostGlobalSnapshot.remotesInfo[remoteKey];
4245
+ if (Boolean(Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey])) {
4246
+ delete Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey];
4247
+ }
4248
+ }
4249
+ }
4250
+ host.moduleCache.delete(remote.name);
4251
+ }
4252
+ } catch (err) {
4253
+ console.log('removeRemote fail: ', err);
4254
+ }
4255
+ }
4256
+ }
4257
+ ]);
4258
+ return RemoteHandler;
4259
+ }();
4260
+ var FederationHost = function() {
4261
+ function FederationHost(userOptions) {
4262
+ _class_call_check._(this, FederationHost);
4263
+ this.hooks = new PluginSystem({
4264
+ beforeInit: new SyncWaterfallHook('beforeInit'),
4265
+ init: new SyncHook(),
4266
+ beforeInitContainer: new AsyncWaterfallHook('beforeInitContainer'),
4267
+ initContainer: new AsyncWaterfallHook('initContainer')
4268
+ });
4269
+ this.version = "0.5.1";
4270
+ this.moduleCache = new Map();
4271
+ this.loaderHook = new PluginSystem({
4272
+ getModuleInfo: new SyncHook(),
4273
+ createScript: new SyncHook(),
4274
+ createLink: new SyncHook(),
4275
+ fetch: new AsyncHook()
4276
+ });
4277
+ var defaultOptions = {
4278
+ id: getBuilderId(),
4279
+ name: userOptions.name,
4280
+ plugins: [
4281
+ snapshotPlugin(),
4282
+ generatePreloadAssetsPlugin()
4283
+ ],
4284
+ remotes: [],
4285
+ shared: {},
4286
+ inBrowser: isBrowserEnv()
4287
+ };
4288
+ this.name = userOptions.name;
4289
+ this.options = defaultOptions;
4290
+ this.snapshotHandler = new SnapshotHandler(this);
4291
+ this.sharedHandler = new SharedHandler(this);
4292
+ this.remoteHandler = new RemoteHandler(this);
4293
+ this.shareScopeMap = this.sharedHandler.shareScopeMap;
4294
+ this.registerPlugins(_to_consumable_array._(defaultOptions.plugins).concat(_to_consumable_array._(userOptions.plugins || [])));
4295
+ this.options = this.formatOptions(defaultOptions, userOptions);
4296
+ }
4297
+ _create_class._(FederationHost, [
4298
+ {
4299
+ key: "initOptions",
4300
+ value: function initOptions(userOptions) {
4301
+ this.registerPlugins(userOptions.plugins);
4302
+ var options = this.formatOptions(this.options, userOptions);
4303
+ this.options = options;
4304
+ return options;
4305
+ }
4306
+ },
4307
+ {
4308
+ key: "loadShare",
4309
+ value: function loadShare(pkgName, extraOptions) {
4310
+ var _this = this;
4311
+ return _async_to_generator._(function() {
4312
+ return _ts_generator._(this, function(_state) {
4313
+ return [
4314
+ 2,
4315
+ _this.sharedHandler.loadShare(pkgName, extraOptions)
4316
+ ];
4317
+ });
4318
+ })();
4319
+ }
4320
+ },
4321
+ {
4322
+ key: "loadShareSync",
4323
+ value: function loadShareSync(pkgName, extraOptions) {
4324
+ return this.sharedHandler.loadShareSync(pkgName, extraOptions);
4325
+ }
4326
+ },
4327
+ {
4328
+ key: "initializeSharing",
4329
+ value: function initializeSharing() {
4330
+ var shareScopeName = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : DEFAULT_SCOPE, strategy = arguments.length > 1 ? arguments[1] : void 0;
4331
+ return this.sharedHandler.initializeSharing(shareScopeName, strategy);
4332
+ }
4333
+ },
4334
+ {
4335
+ key: "initRawContainer",
4336
+ value: function initRawContainer(name, url, container) {
4337
+ var remoteInfo = getRemoteInfo({
4338
+ name: name,
4339
+ entry: url
4340
+ });
4341
+ var module = new Module({
4342
+ host: this,
4343
+ remoteInfo: remoteInfo
4344
+ });
4345
+ module.remoteEntryExports = container;
4346
+ this.moduleCache.set(name, module);
4347
+ return module;
4348
+ }
4349
+ },
4350
+ {
4351
+ key: "loadRemote",
4352
+ value: function loadRemote(id, options) {
4353
+ var _this = this;
4354
+ return _async_to_generator._(function() {
4355
+ return _ts_generator._(this, function(_state) {
4356
+ return [
4357
+ 2,
4358
+ _this.remoteHandler.loadRemote(id, options)
4359
+ ];
4360
+ });
4361
+ })();
4362
+ }
4363
+ },
4364
+ {
4365
+ key: "preloadRemote",
4366
+ value: function preloadRemote(preloadOptions) {
4367
+ var _this = this;
4368
+ return _async_to_generator._(function() {
4369
+ return _ts_generator._(this, function(_state) {
4370
+ return [
4371
+ 2,
4372
+ _this.remoteHandler.preloadRemote(preloadOptions)
4373
+ ];
4374
+ });
4375
+ })();
4376
+ }
4377
+ },
4378
+ {
4379
+ key: "initShareScopeMap",
4380
+ value: function initShareScopeMap(scopeName, shareScope) {
4381
+ var extraOptions = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
4382
+ this.sharedHandler.initShareScopeMap(scopeName, shareScope, extraOptions);
4383
+ }
4384
+ },
4385
+ {
4386
+ key: "formatOptions",
4387
+ value: function formatOptions(globalOptions, userOptions) {
4388
+ var shared = formatShareConfigs(globalOptions, userOptions).shared;
4389
+ var _this_hooks_lifecycle_beforeInit_emit = this.hooks.lifecycle.beforeInit.emit({
4390
+ origin: this,
4391
+ userOptions: userOptions,
4392
+ options: globalOptions,
4393
+ shareInfo: shared
4394
+ }), userOptionsRes = _this_hooks_lifecycle_beforeInit_emit.userOptions, globalOptionsRes = _this_hooks_lifecycle_beforeInit_emit.options;
4395
+ var remotes = this.remoteHandler.formatAndRegisterRemote(globalOptionsRes, userOptionsRes);
4396
+ var _this_sharedHandler_registerShared = this.sharedHandler.registerShared(globalOptionsRes, userOptionsRes), handledShared = _this_sharedHandler_registerShared.shared;
4397
+ var plugins = _to_consumable_array._(globalOptionsRes.plugins);
4398
+ if (userOptionsRes.plugins) {
4399
+ userOptionsRes.plugins.forEach(function(plugin) {
4400
+ if (!plugins.includes(plugin)) {
4401
+ plugins.push(plugin);
4402
+ }
4403
+ });
4404
+ }
4405
+ var optionsRes = _extends._({}, globalOptions, userOptions, {
4406
+ plugins: plugins,
4407
+ remotes: remotes,
4408
+ shared: handledShared
4409
+ });
4410
+ this.hooks.lifecycle.init.emit({
4411
+ origin: this,
4412
+ options: optionsRes
4413
+ });
4414
+ return optionsRes;
4415
+ }
4416
+ },
4417
+ {
4418
+ key: "registerPlugins",
4419
+ value: function registerPlugins(plugins) {
4420
+ var pluginRes = registerPlugins$1(plugins, [
4421
+ this.hooks,
4422
+ this.remoteHandler.hooks,
4423
+ this.sharedHandler.hooks,
4424
+ this.snapshotHandler.hooks,
4425
+ this.loaderHook
4426
+ ]);
4427
+ this.options.plugins = this.options.plugins.reduce(function(res, plugin) {
4428
+ if (!plugin) return res;
4429
+ if (res && !res.find(function(item) {
4430
+ return item.name === plugin.name;
4431
+ })) {
4432
+ res.push(plugin);
4433
+ }
4434
+ return res;
4435
+ }, pluginRes || []);
4436
+ }
4437
+ },
4438
+ {
4439
+ key: "registerRemotes",
4440
+ value: function registerRemotes(remotes, options) {
4441
+ return this.remoteHandler.registerRemotes(remotes, options);
4442
+ }
4443
+ }
4444
+ ]);
4445
+ return FederationHost;
4446
+ }();
4447
+ var FederationInstance = null;
4448
+ function init(options) {
4449
+ var instance = getGlobalFederationInstance(options.name, options.version);
4450
+ if (!instance) {
4451
+ var FederationConstructor = getGlobalFederationConstructor() || FederationHost;
4452
+ FederationInstance = new FederationConstructor(options);
4453
+ setGlobalFederationInstance(FederationInstance);
4454
+ return FederationInstance;
4455
+ } else {
4456
+ instance.initOptions(options);
4457
+ if (!FederationInstance) {
4458
+ FederationInstance = instance;
4459
+ }
4460
+ return instance;
4461
+ }
4462
+ }
4463
+ function loadRemote() {
4464
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
4465
+ args[_key] = arguments[_key];
4466
+ }
4467
+ assert(FederationInstance, 'Please call init first');
4468
+ var loadRemote1 = FederationInstance.loadRemote;
4469
+ return loadRemote1.apply(FederationInstance, args);
4470
+ }
4471
+ function loadShare() {
4472
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
4473
+ args[_key] = arguments[_key];
4474
+ }
4475
+ assert(FederationInstance, 'Please call init first');
4476
+ var loadShare1 = FederationInstance.loadShare;
4477
+ return loadShare1.apply(FederationInstance, args);
4478
+ }
4479
+ function loadShareSync() {
4480
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
4481
+ args[_key] = arguments[_key];
4482
+ }
4483
+ assert(FederationInstance, 'Please call init first');
4484
+ var loadShareSync1 = FederationInstance.loadShareSync;
4485
+ return loadShareSync1.apply(FederationInstance, args);
4486
+ }
4487
+ function preloadRemote() {
4488
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
4489
+ args[_key] = arguments[_key];
4490
+ }
4491
+ assert(FederationInstance, 'Please call init first');
4492
+ return FederationInstance.preloadRemote.apply(FederationInstance, args);
4493
+ }
4494
+ function registerRemotes() {
4495
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
4496
+ args[_key] = arguments[_key];
4497
+ }
4498
+ assert(FederationInstance, 'Please call init first');
4499
+ return FederationInstance.registerRemotes.apply(FederationInstance, args);
4500
+ }
4501
+ function registerPlugins() {
4502
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
4503
+ args[_key] = arguments[_key];
4504
+ }
4505
+ assert(FederationInstance, 'Please call init first');
4506
+ return FederationInstance.registerPlugins.apply(FederationInstance, args);
4507
+ }
4508
+ function getInstance() {
4509
+ return FederationInstance;
4510
+ }
4511
+ setGlobalFederationConstructor(FederationHost);
4512
+
4513
+ var runtime = /*#__PURE__*/Object.freeze({
4514
+ __proto__: null,
4515
+ FederationHost: FederationHost,
4516
+ getInstance: getInstance,
4517
+ getRemoteEntry: getRemoteEntry,
4518
+ getRemoteInfo: getRemoteInfo,
4519
+ init: init,
4520
+ loadRemote: loadRemote,
4521
+ loadShare: loadShare,
4522
+ loadShareSync: loadShareSync,
4523
+ preloadRemote: preloadRemote,
4524
+ registerPlugins: registerPlugins,
4525
+ registerRemotes: registerRemotes,
4526
+ registerGlobalPlugins: registerGlobalPlugins,
4527
+ loadScript: loadScript,
4528
+ loadScriptNode: loadScriptNode
4529
+ });
4530
+
4531
+ function attachShareScopeMap(webpackRequire) {
4532
+ if (!webpackRequire.S || webpackRequire.federation.hasAttachShareScopeMap || !webpackRequire.federation.instance || !webpackRequire.federation.instance.shareScopeMap) {
4533
+ return;
4534
+ }
4535
+ webpackRequire.S = webpackRequire.federation.instance.shareScopeMap;
4536
+ webpackRequire.federation.hasAttachShareScopeMap = true;
4537
+ }
4538
+
4539
+ var FEDERATION_SUPPORTED_TYPES = [
4540
+ 'script'
4541
+ ];
4542
+
4543
+ function remotes(options) {
4544
+ var chunkId = options.chunkId, promises = options.promises, chunkMapping = options.chunkMapping, idToExternalAndNameMapping = options.idToExternalAndNameMapping, webpackRequire = options.webpackRequire, idToRemoteMap = options.idToRemoteMap;
4545
+ attachShareScopeMap(webpackRequire);
4546
+ if (webpackRequire.o(chunkMapping, chunkId)) {
4547
+ chunkMapping[chunkId].forEach(function(id) {
4548
+ var getScope = webpackRequire.R;
4549
+ if (!getScope) {
4550
+ getScope = [];
4551
+ }
4552
+ var data = idToExternalAndNameMapping[id];
4553
+ var remoteInfos = idToRemoteMap[id];
4554
+ if (getScope.indexOf(data) >= 0) {
4555
+ return;
4556
+ }
4557
+ getScope.push(data);
4558
+ if (data.p) {
4559
+ return promises.push(data.p);
4560
+ }
4561
+ var onError = function(error) {
4562
+ if (!error) {
4563
+ error = new Error('Container missing');
4564
+ }
4565
+ if (typeof error.message === 'string') {
4566
+ error.message += '\nwhile loading "'.concat(data[1], '" from ').concat(data[2]);
4567
+ }
4568
+ webpackRequire.m[id] = function() {
4569
+ throw error;
4570
+ };
4571
+ data.p = 0;
4572
+ };
4573
+ var handleFunction = function(fn, arg1, arg2, d, next, first) {
4574
+ try {
4575
+ var promise = fn(arg1, arg2);
4576
+ if (promise && promise.then) {
4577
+ var p = promise.then(function(result) {
4578
+ return next(result, d);
4579
+ }, onError);
4580
+ if (first) {
4581
+ promises.push(data.p = p);
4582
+ } else {
4583
+ return p;
4584
+ }
4585
+ } else {
4586
+ return next(promise, d, first);
4587
+ }
4588
+ } catch (error) {
4589
+ onError(error);
4590
+ }
4591
+ };
4592
+ var onExternal = function(external, _, first) {
4593
+ return external ? handleFunction(webpackRequire.I, data[0], 0, external, onInitialized, first) : onError();
4594
+ };
4595
+ var onInitialized = function(_, external, first) {
4596
+ return handleFunction(external.get, data[1], getScope, 0, onFactory, first);
4597
+ };
4598
+ var onFactory = function(factory) {
4599
+ data.p = 1;
4600
+ webpackRequire.m[id] = function(module) {
4601
+ module.exports = factory();
4602
+ };
4603
+ };
4604
+ var onRemoteLoaded = function() {
4605
+ try {
4606
+ var remoteName = decodeName(remoteInfos[0].name, ENCODE_NAME_PREFIX);
4607
+ var remoteModuleName = remoteName + data[1].slice(1);
4608
+ return webpackRequire.federation.instance.loadRemote(remoteModuleName, {
4609
+ loadFactory: false,
4610
+ from: 'build'
4611
+ });
4612
+ } catch (error) {
4613
+ onError(error);
4614
+ }
4615
+ };
4616
+ var useRuntimeLoad = remoteInfos.length === 1 && FEDERATION_SUPPORTED_TYPES.includes(remoteInfos[0].externalType) && remoteInfos[0].name;
4617
+ if (useRuntimeLoad) {
4618
+ handleFunction(onRemoteLoaded, data[2], 0, 0, onFactory, 1);
4619
+ } else {
4620
+ handleFunction(webpackRequire, data[2], 0, 0, onExternal, 1);
4621
+ }
4622
+ });
4623
+ }
4624
+ }
4625
+
4626
+ function consumes(options) {
4627
+ var chunkId = options.chunkId, promises = options.promises, chunkMapping = options.chunkMapping, installedModules = options.installedModules, moduleToHandlerMapping = options.moduleToHandlerMapping, webpackRequire = options.webpackRequire;
4628
+ attachShareScopeMap(webpackRequire);
4629
+ if (webpackRequire.o(chunkMapping, chunkId)) {
4630
+ chunkMapping[chunkId].forEach(function(id) {
4631
+ if (webpackRequire.o(installedModules, id)) {
4632
+ return promises.push(installedModules[id]);
4633
+ }
4634
+ var onFactory = function(factory) {
4635
+ installedModules[id] = 0;
4636
+ webpackRequire.m[id] = function(module) {
4637
+ delete webpackRequire.c[id];
4638
+ module.exports = factory();
4639
+ };
4640
+ };
4641
+ var onError = function(error) {
4642
+ delete installedModules[id];
4643
+ webpackRequire.m[id] = function(module) {
4644
+ delete webpackRequire.c[id];
4645
+ throw error;
4646
+ };
4647
+ };
4648
+ try {
4649
+ var federationInstance = webpackRequire.federation.instance;
4650
+ if (!federationInstance) {
4651
+ throw new Error('Federation instance not found!');
4652
+ }
4653
+ var _moduleToHandlerMapping_id = moduleToHandlerMapping[id], shareKey = _moduleToHandlerMapping_id.shareKey, getter = _moduleToHandlerMapping_id.getter, shareInfo = _moduleToHandlerMapping_id.shareInfo;
4654
+ var promise = federationInstance.loadShare(shareKey, {
4655
+ customShareInfo: shareInfo
4656
+ }).then(function(factory) {
4657
+ if (factory === false) {
4658
+ return getter();
4659
+ }
4660
+ return factory;
4661
+ });
4662
+ if (promise.then) {
4663
+ promises.push(installedModules[id] = promise.then(onFactory).catch(onError));
4664
+ } else {
4665
+ onFactory(promise);
4666
+ }
4667
+ } catch (e) {
4668
+ onError(e);
4669
+ }
4670
+ });
4671
+ }
4672
+ }
4673
+
4674
+ function initializeSharing(param) {
4675
+ var shareScopeName = param.shareScopeName, webpackRequire = param.webpackRequire, initPromises = param.initPromises, initTokens = param.initTokens, initScope = param.initScope;
4676
+ if (!initScope) initScope = [];
4677
+ var initToken = initTokens[shareScopeName];
4678
+ if (!initToken) initToken = initTokens[shareScopeName] = {};
4679
+ if (initScope.indexOf(initToken) >= 0) return;
4680
+ initScope.push(initToken);
4681
+ var promise = initPromises[shareScopeName];
4682
+ if (promise) return promise;
4683
+ var warn = function(msg) {
4684
+ return typeof console !== 'undefined' && console.warn && console.warn(msg);
4685
+ };
4686
+ var initExternal = function(id) {
4687
+ var handleError = function(err) {
4688
+ return warn('Initialization of sharing external failed: ' + err);
4689
+ };
4690
+ try {
4691
+ var module = webpackRequire(id);
4692
+ if (!module) return;
4693
+ var initFn = function(module) {
4694
+ return module && module.init && module.init(webpackRequire.S[shareScopeName], initScope);
4695
+ };
4696
+ if (module.then) return promises.push(module.then(initFn, handleError));
4697
+ var initResult = initFn(module);
4698
+ if (initResult && typeof initResult !== 'boolean' && initResult.then) return promises.push(initResult['catch'](handleError));
4699
+ } catch (err) {
4700
+ handleError(err);
4701
+ }
4702
+ };
4703
+ var promises = webpackRequire.federation.instance.initializeSharing(shareScopeName);
4704
+ attachShareScopeMap(webpackRequire);
4705
+ var bundlerRuntimeRemotesOptions = webpackRequire.federation.bundlerRuntimeOptions.remotes;
4706
+ if (bundlerRuntimeRemotesOptions) {
4707
+ Object.keys(bundlerRuntimeRemotesOptions.idToRemoteMap).forEach(function(moduleId) {
4708
+ var info = bundlerRuntimeRemotesOptions.idToRemoteMap[moduleId];
4709
+ var externalModuleId = bundlerRuntimeRemotesOptions.idToExternalAndNameMapping[moduleId][2];
4710
+ if (info.length > 1) {
4711
+ initExternal(externalModuleId);
4712
+ } else if (info.length === 1) {
4713
+ var remoteInfo = info[0];
4714
+ if (!FEDERATION_SUPPORTED_TYPES.includes(remoteInfo.externalType)) {
4715
+ initExternal(externalModuleId);
4716
+ }
4717
+ }
4718
+ });
4719
+ }
4720
+ if (!promises.length) {
4721
+ return initPromises[shareScopeName] = true;
4722
+ }
4723
+ return initPromises[shareScopeName] = Promise.all(promises).then(function() {
4724
+ return initPromises[shareScopeName] = true;
4725
+ });
4726
+ }
4727
+
4728
+ function handleInitialConsumes(options) {
4729
+ var moduleId = options.moduleId, moduleToHandlerMapping = options.moduleToHandlerMapping, webpackRequire = options.webpackRequire;
4730
+ var federationInstance = webpackRequire.federation.instance;
4731
+ if (!federationInstance) {
4732
+ throw new Error('Federation instance not found!');
4733
+ }
4734
+ var _moduleToHandlerMapping_moduleId = moduleToHandlerMapping[moduleId], shareKey = _moduleToHandlerMapping_moduleId.shareKey, shareInfo = _moduleToHandlerMapping_moduleId.shareInfo;
4735
+ try {
4736
+ return federationInstance.loadShareSync(shareKey, {
4737
+ customShareInfo: shareInfo
4738
+ });
4739
+ } catch (err) {
4740
+ console.error('loadShareSync failed! The function should not be called unless you set "eager:true". If you do not set it, and encounter this issue, you can check whether an async boundary is implemented.');
4741
+ console.error('The original error message is as follows: ');
4742
+ throw err;
4743
+ }
4744
+ }
4745
+ function installInitialConsumes(options) {
4746
+ var moduleToHandlerMapping = options.moduleToHandlerMapping, webpackRequire = options.webpackRequire, installedModules = options.installedModules, initialConsumes = options.initialConsumes;
4747
+ initialConsumes.forEach(function(id) {
4748
+ webpackRequire.m[id] = function(module) {
4749
+ installedModules[id] = 0;
4750
+ delete webpackRequire.c[id];
4751
+ var factory = handleInitialConsumes({
4752
+ moduleId: id,
4753
+ moduleToHandlerMapping: moduleToHandlerMapping,
4754
+ webpackRequire: webpackRequire
4755
+ });
4756
+ if (typeof factory !== 'function') {
4757
+ throw new Error("Shared module is not available for eager consumption: ".concat(id));
4758
+ }
4759
+ module.exports = factory();
4760
+ };
4761
+ });
4762
+ }
4763
+
4764
+ function initContainerEntry(options) {
4765
+ var webpackRequire = options.webpackRequire, shareScope = options.shareScope, initScope = options.initScope, shareScopeKey = options.shareScopeKey, remoteEntryInitOptions = options.remoteEntryInitOptions;
4766
+ if (!webpackRequire.S) return;
4767
+ if (!webpackRequire.federation || !webpackRequire.federation.instance || !webpackRequire.federation.initOptions) return;
4768
+ var federationInstance = webpackRequire.federation.instance;
4769
+ var name = shareScopeKey || 'default';
4770
+ federationInstance.initOptions(_object_spread._({
4771
+ name: webpackRequire.federation.initOptions.name,
4772
+ remotes: []
4773
+ }, remoteEntryInitOptions));
4774
+ federationInstance.initShareScopeMap(name, shareScope, {
4775
+ hostShareScopeMap: (remoteEntryInitOptions === null || remoteEntryInitOptions === void 0 ? void 0 : remoteEntryInitOptions.shareScopeMap) || {}
4776
+ });
4777
+ if (webpackRequire.federation.attachShareScopeMap) {
4778
+ webpackRequire.federation.attachShareScopeMap(webpackRequire);
4779
+ }
4780
+ return webpackRequire.I(name, initScope);
4781
+ }
4782
+
4783
+ var federation = {
4784
+ runtime: runtime,
4785
+ instance: undefined,
4786
+ initOptions: undefined,
4787
+ bundlerRuntime: {
4788
+ remotes: remotes,
4789
+ consumes: consumes,
4790
+ I: initializeSharing,
4791
+ S: {},
4792
+ installInitialConsumes: installInitialConsumes,
4793
+ initContainerEntry: initContainerEntry
4794
+ },
4795
+ attachShareScopeMap: attachShareScopeMap,
4796
+ bundlerRuntimeOptions: {}
4797
+ };
4798
+
4799
+ module.exports = federation;