@pulse-editor/react-api 0.1.1-beta.81 → 0.1.1-beta.83

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
@@ -724,7 +724,9 @@ function generateSnapshotFromManifest(manifest) {
724
724
  return {
725
725
  assets: item.assets,
726
726
  sharedName: item.name,
727
- version: item.version
727
+ version: item.version,
728
+ // @ts-ignore
729
+ usedExports: item.referenceExports || []
728
730
  };
729
731
  }),
730
732
  modules: exposes === null || exposes === void 0 ? void 0 : exposes.map(function (expose) {
@@ -1531,7 +1533,7 @@ var BUILD_001 = 'BUILD-001';
1531
1533
  var BUILD_002 = 'BUILD-002';
1532
1534
  var getDocsUrl = function getDocsUrl(errorCode) {
1533
1535
  var type = errorCode.split('-')[0].toLowerCase();
1534
- return "View the docs to see how to solve: https://module-federation.io/guide/troubleshooting/".concat(type, "/").concat(errorCode);
1536
+ return "View the docs to see how to solve: https://module-federation.io/guide/troubleshooting/".concat(type, "#").concat(errorCode.toLowerCase());
1535
1537
  };
1536
1538
  var getShortErrorMsg = function getShortErrorMsg(errorCode, errorDescMap, args, originalErrorMsg) {
1537
1539
  var msg = ["".concat([errorDescMap[errorCode]], " #").concat(errorCode)];
@@ -1617,7 +1619,7 @@ function getRemoteEntryInfoFromSnapshot(snapshot) {
1617
1619
  type: 'global',
1618
1620
  globalName: ''
1619
1621
  };
1620
- if (isBrowserEnv() || isReactNativeEnv()) {
1622
+ if (isBrowserEnv() || isReactNativeEnv() || !('ssrRemoteEntry' in snapshot)) {
1621
1623
  return 'remoteEntry' in snapshot ? {
1622
1624
  url: snapshot.remoteEntry,
1623
1625
  type: snapshot.remoteEntryType,
@@ -1710,7 +1712,7 @@ function setGlobalFederationConstructor(FederationConstructor) {
1710
1712
  var isDebug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : isDebugMode();
1711
1713
  if (isDebug) {
1712
1714
  CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
1713
- CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.21.6";
1715
+ CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "2.0.1";
1714
1716
  }
1715
1717
  }
1716
1718
  // eslint-disable-next-line @typescript-eslint/ban-types
@@ -2294,7 +2296,7 @@ function satisfy(version, range) {
2294
2296
  return false;
2295
2297
  }
2296
2298
  function formatShare(shareArgs, from, name, shareStrategy) {
2297
- var _shareArgs$version, _shareArgs$scope, _shareArgs$strategy;
2299
+ var _shareArgs$shareConfi, _shareArgs$treeShakin, _shareArgs$version, _shareArgs$scope, _shareArgs$strategy, _shareArgs$treeShakin2, _shareArgs$treeShakin3;
2298
2300
  var get;
2299
2301
  if ('get' in shareArgs) {
2300
2302
  // eslint-disable-next-line prefer-destructuring
@@ -2310,6 +2312,9 @@ function formatShare(shareArgs, from, name, shareStrategy) {
2310
2312
  });
2311
2313
  };
2312
2314
  }
2315
+ if ((_shareArgs$shareConfi = shareArgs.shareConfig) !== null && _shareArgs$shareConfi !== void 0 && _shareArgs$shareConfi.eager && (_shareArgs$treeShakin = shareArgs.treeShaking) !== null && _shareArgs$treeShakin !== void 0 && _shareArgs$treeShakin.mode) {
2316
+ throw new Error('Can not set "eager:true" and "treeShaking" at the same time!');
2317
+ }
2313
2318
  return _objectSpread2(_objectSpread2({
2314
2319
  deps: [],
2315
2320
  useIn: [],
@@ -2326,40 +2331,68 @@ function formatShare(shareArgs, from, name, shareStrategy) {
2326
2331
  loaded: shareArgs !== null && shareArgs !== void 0 && shareArgs.loaded || 'lib' in shareArgs ? true : undefined,
2327
2332
  version: (_shareArgs$version = shareArgs.version) !== null && _shareArgs$version !== void 0 ? _shareArgs$version : '0',
2328
2333
  scope: Array.isArray(shareArgs.scope) ? shareArgs.scope : [(_shareArgs$scope = shareArgs.scope) !== null && _shareArgs$scope !== void 0 ? _shareArgs$scope : 'default'],
2329
- strategy: ((_shareArgs$strategy = shareArgs.strategy) !== null && _shareArgs$strategy !== void 0 ? _shareArgs$strategy : shareStrategy) || 'version-first'
2334
+ strategy: ((_shareArgs$strategy = shareArgs.strategy) !== null && _shareArgs$strategy !== void 0 ? _shareArgs$strategy : shareStrategy) || 'version-first',
2335
+ treeShaking: shareArgs.treeShaking ? _objectSpread2(_objectSpread2({}, shareArgs.treeShaking), {}, {
2336
+ mode: (_shareArgs$treeShakin2 = shareArgs.treeShaking.mode) !== null && _shareArgs$treeShakin2 !== void 0 ? _shareArgs$treeShakin2 : 'server-calc',
2337
+ status: (_shareArgs$treeShakin3 = shareArgs.treeShaking.status) !== null && _shareArgs$treeShakin3 !== void 0 ? _shareArgs$treeShakin3 : 1 /* TreeShakingStatus.UNKNOWN */,
2338
+ useIn: []
2339
+ }) : undefined
2330
2340
  });
2331
2341
  }
2332
- function formatShareConfigs(globalOptions, userOptions) {
2333
- var shareArgs = userOptions.shared || {};
2334
- var from = userOptions.name;
2335
- var shareInfos = Object.keys(shareArgs).reduce(function (res, pkgName) {
2342
+ function formatShareConfigs(prevOptions, newOptions) {
2343
+ var shareArgs = newOptions.shared || {};
2344
+ var from = newOptions.name;
2345
+ var newShareInfos = Object.keys(shareArgs).reduce(function (res, pkgName) {
2336
2346
  var arrayShareArgs = arrayOptions(shareArgs[pkgName]);
2337
2347
  res[pkgName] = res[pkgName] || [];
2338
2348
  arrayShareArgs.forEach(function (shareConfig) {
2339
- res[pkgName].push(formatShare(shareConfig, from, pkgName, userOptions.shareStrategy));
2349
+ res[pkgName].push(formatShare(shareConfig, from, pkgName, newOptions.shareStrategy));
2340
2350
  });
2341
2351
  return res;
2342
2352
  }, {});
2343
- var shared = _objectSpread2({}, globalOptions.shared);
2344
- Object.keys(shareInfos).forEach(function (shareKey) {
2345
- if (!shared[shareKey]) {
2346
- shared[shareKey] = shareInfos[shareKey];
2353
+ var allShareInfos = _objectSpread2({}, prevOptions.shared);
2354
+ Object.keys(newShareInfos).forEach(function (shareKey) {
2355
+ if (!allShareInfos[shareKey]) {
2356
+ allShareInfos[shareKey] = newShareInfos[shareKey];
2347
2357
  } else {
2348
- shareInfos[shareKey].forEach(function (newUserSharedOptions) {
2349
- var isSameVersion = shared[shareKey].find(function (sharedVal) {
2358
+ newShareInfos[shareKey].forEach(function (newUserSharedOptions) {
2359
+ var isSameVersion = allShareInfos[shareKey].find(function (sharedVal) {
2350
2360
  return sharedVal.version === newUserSharedOptions.version;
2351
2361
  });
2352
2362
  if (!isSameVersion) {
2353
- shared[shareKey].push(newUserSharedOptions);
2363
+ allShareInfos[shareKey].push(newUserSharedOptions);
2354
2364
  }
2355
2365
  });
2356
2366
  }
2357
2367
  });
2358
2368
  return {
2359
- shared: shared,
2360
- shareInfos: shareInfos
2369
+ allShareInfos: allShareInfos,
2370
+ newShareInfos: newShareInfos
2361
2371
  };
2362
2372
  }
2373
+ function shouldUseTreeShaking(treeShaking, usedExports) {
2374
+ if (!treeShaking) {
2375
+ return false;
2376
+ }
2377
+ var status = treeShaking.status,
2378
+ mode = treeShaking.mode;
2379
+ if (status === 0 /* TreeShakingStatus.NO_USE */) {
2380
+ return false;
2381
+ }
2382
+ if (status === 2 /* TreeShakingStatus.CALCULATED */) {
2383
+ return true;
2384
+ }
2385
+ if (mode === 'runtime-infer') {
2386
+ if (!usedExports) {
2387
+ return true;
2388
+ }
2389
+ return isMatchUsedExports(treeShaking, usedExports);
2390
+ }
2391
+ return false;
2392
+ }
2393
+ /**
2394
+ * compare version a and b, return true if a is less than b
2395
+ */
2363
2396
  function versionLt(a, b) {
2364
2397
  var transformInvalidVersion = function transformInvalidVersion(version) {
2365
2398
  var isNumberVersion = !Number.isNaN(Number(version));
@@ -2403,19 +2436,80 @@ var isLoaded = function isLoaded(shared) {
2403
2436
  var isLoading = function isLoading(shared) {
2404
2437
  return Boolean(shared.loading);
2405
2438
  };
2406
- function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) {
2439
+ var isMatchUsedExports = function isMatchUsedExports(treeShaking, usedExports) {
2440
+ if (!treeShaking || !usedExports) {
2441
+ return false;
2442
+ }
2443
+ var treeShakingUsedExports = treeShaking.usedExports;
2444
+ if (!treeShakingUsedExports) {
2445
+ return false;
2446
+ }
2447
+ if (usedExports.every(function (e) {
2448
+ return treeShakingUsedExports.includes(e);
2449
+ })) {
2450
+ return true;
2451
+ }
2452
+ return false;
2453
+ };
2454
+ function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName, treeShaking) {
2407
2455
  var versions = shareScopeMap[scope][pkgName];
2456
+ var version = '';
2457
+ var useTreesShaking = shouldUseTreeShaking(treeShaking);
2458
+ // return false means use prev version
2408
2459
  var callback = function callback(prev, cur) {
2460
+ if (useTreesShaking) {
2461
+ if (!versions[prev].treeShaking) {
2462
+ return true;
2463
+ }
2464
+ if (!versions[cur].treeShaking) {
2465
+ return false;
2466
+ }
2467
+ return !isLoaded(versions[prev].treeShaking) && versionLt(prev, cur);
2468
+ }
2409
2469
  return !isLoaded(versions[prev]) && versionLt(prev, cur);
2410
2470
  };
2411
- return findVersion(shareScopeMap[scope][pkgName], callback);
2471
+ if (useTreesShaking) {
2472
+ version = findVersion(shareScopeMap[scope][pkgName], callback);
2473
+ if (version) {
2474
+ return {
2475
+ version: version,
2476
+ useTreesShaking: useTreesShaking
2477
+ };
2478
+ }
2479
+ useTreesShaking = false;
2480
+ }
2481
+ return {
2482
+ version: findVersion(shareScopeMap[scope][pkgName], callback),
2483
+ useTreesShaking: useTreesShaking
2484
+ };
2412
2485
  }
2413
- function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
2486
+ var isLoadingOrLoaded = function isLoadingOrLoaded(shared) {
2487
+ return isLoaded(shared) || isLoading(shared);
2488
+ };
2489
+ function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName, treeShaking) {
2414
2490
  var versions = shareScopeMap[scope][pkgName];
2491
+ var version = '';
2492
+ var useTreesShaking = shouldUseTreeShaking(treeShaking);
2493
+ // return false means use prev version
2415
2494
  var callback = function callback(prev, cur) {
2416
- var isLoadingOrLoaded = function isLoadingOrLoaded(shared) {
2417
- return isLoaded(shared) || isLoading(shared);
2418
- };
2495
+ if (useTreesShaking) {
2496
+ if (!versions[prev].treeShaking) {
2497
+ return true;
2498
+ }
2499
+ if (!versions[cur].treeShaking) {
2500
+ return false;
2501
+ }
2502
+ if (isLoadingOrLoaded(versions[cur].treeShaking)) {
2503
+ if (isLoadingOrLoaded(versions[prev].treeShaking)) {
2504
+ return Boolean(versionLt(prev, cur));
2505
+ } else {
2506
+ return true;
2507
+ }
2508
+ }
2509
+ if (isLoadingOrLoaded(versions[prev].treeShaking)) {
2510
+ return false;
2511
+ }
2512
+ }
2419
2513
  if (isLoadingOrLoaded(versions[cur])) {
2420
2514
  if (isLoadingOrLoaded(versions[prev])) {
2421
2515
  return Boolean(versionLt(prev, cur));
@@ -2428,7 +2522,20 @@ function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
2428
2522
  }
2429
2523
  return versionLt(prev, cur);
2430
2524
  };
2431
- return findVersion(shareScopeMap[scope][pkgName], callback);
2525
+ if (useTreesShaking) {
2526
+ version = findVersion(shareScopeMap[scope][pkgName], callback);
2527
+ if (version) {
2528
+ return {
2529
+ version: version,
2530
+ useTreesShaking: useTreesShaking
2531
+ };
2532
+ }
2533
+ useTreesShaking = false;
2534
+ }
2535
+ return {
2536
+ version: findVersion(shareScopeMap[scope][pkgName], callback),
2537
+ useTreesShaking: useTreesShaking
2538
+ };
2432
2539
  }
2433
2540
  function getFindShareFunction(strategy) {
2434
2541
  if (strategy === 'loaded-first') {
@@ -2443,7 +2550,8 @@ function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare
2443
2550
  var shareConfig = shareInfo.shareConfig,
2444
2551
  _shareInfo$scope = shareInfo.scope,
2445
2552
  scope = _shareInfo$scope === void 0 ? DEFAULT_SCOPE : _shareInfo$scope,
2446
- strategy = shareInfo.strategy;
2553
+ strategy = shareInfo.strategy,
2554
+ treeShaking = shareInfo.treeShaking;
2447
2555
  var scopes = Array.isArray(scope) ? scope : [scope];
2448
2556
  var _iterator3 = _createForOfIteratorHelper(scopes),
2449
2557
  _step3;
@@ -2453,35 +2561,67 @@ function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare
2453
2561
  if (shareConfig && localShareScopeMap[sc] && localShareScopeMap[sc][pkgName]) {
2454
2562
  var requiredVersion = shareConfig.requiredVersion;
2455
2563
  var findShareFunction = getFindShareFunction(strategy);
2456
- var maxOrSingletonVersion = findShareFunction(localShareScopeMap, sc, pkgName);
2457
- //@ts-ignore
2564
+ var _findShareFunction = findShareFunction(localShareScopeMap, sc, pkgName, treeShaking),
2565
+ maxOrSingletonVersion = _findShareFunction.version,
2566
+ useTreesShaking = _findShareFunction.useTreesShaking;
2458
2567
  var defaultResolver = function defaultResolver() {
2568
+ var shared = localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
2459
2569
  if (shareConfig.singleton) {
2460
2570
  if (typeof requiredVersion === 'string' && !satisfy(maxOrSingletonVersion, requiredVersion)) {
2461
- 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, ")");
2571
+ var msg = "Version ".concat(maxOrSingletonVersion, " from ").concat(maxOrSingletonVersion && shared.from, " of shared singleton module ").concat(pkgName, " does not satisfy the requirement of ").concat(shareInfo.from, " which needs ").concat(requiredVersion, ")");
2462
2572
  if (shareConfig.strictVersion) {
2463
2573
  error(msg);
2464
2574
  } else {
2465
2575
  warn(msg);
2466
2576
  }
2467
2577
  }
2468
- return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
2578
+ return {
2579
+ shared: shared,
2580
+ useTreesShaking: useTreesShaking
2581
+ };
2469
2582
  } else {
2470
2583
  if (requiredVersion === false || requiredVersion === '*') {
2471
- return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
2584
+ return {
2585
+ shared: shared,
2586
+ useTreesShaking: useTreesShaking
2587
+ };
2472
2588
  }
2473
2589
  if (satisfy(maxOrSingletonVersion, requiredVersion)) {
2474
- return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
2590
+ return {
2591
+ shared: shared,
2592
+ useTreesShaking: useTreesShaking
2593
+ };
2475
2594
  }
2476
- for (var _i3 = 0, _Object$entries = Object.entries(localShareScopeMap[sc][pkgName]); _i3 < _Object$entries.length; _i3++) {
2477
- var _Object$entries$_i = _slicedToArray(_Object$entries[_i3], 2),
2478
- versionKey = _Object$entries$_i[0],
2479
- versionValue = _Object$entries$_i[1];
2480
- if (satisfy(versionKey, requiredVersion)) {
2481
- return versionValue;
2595
+ var _usedTreeShaking = shouldUseTreeShaking(treeShaking);
2596
+ if (_usedTreeShaking) {
2597
+ for (var _i3 = 0, _Object$entries = Object.entries(localShareScopeMap[sc][pkgName]); _i3 < _Object$entries.length; _i3++) {
2598
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i3], 2),
2599
+ versionKey = _Object$entries$_i[0],
2600
+ versionValue = _Object$entries$_i[1];
2601
+ if (!shouldUseTreeShaking(versionValue.treeShaking, treeShaking === null || treeShaking === void 0 ? void 0 : treeShaking.usedExports)) {
2602
+ continue;
2603
+ }
2604
+ if (satisfy(versionKey, requiredVersion)) {
2605
+ return {
2606
+ shared: versionValue,
2607
+ useTreesShaking: _usedTreeShaking
2608
+ };
2609
+ }
2610
+ }
2611
+ }
2612
+ for (var _i4 = 0, _Object$entries2 = Object.entries(localShareScopeMap[sc][pkgName]); _i4 < _Object$entries2.length; _i4++) {
2613
+ var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i4], 2),
2614
+ _versionKey = _Object$entries2$_i[0],
2615
+ _versionValue = _Object$entries2$_i[1];
2616
+ if (satisfy(_versionKey, requiredVersion)) {
2617
+ return {
2618
+ shared: _versionValue,
2619
+ useTreesShaking: false
2620
+ };
2482
2621
  }
2483
2622
  }
2484
2623
  }
2624
+ return;
2485
2625
  };
2486
2626
  var params = {
2487
2627
  shareScopeMap: localShareScopeMap,
@@ -2489,6 +2629,7 @@ function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare
2489
2629
  pkgName: pkgName,
2490
2630
  version: maxOrSingletonVersion,
2491
2631
  GlobalFederation: Global.__FEDERATION__,
2632
+ shareInfo: shareInfo,
2492
2633
  resolver: defaultResolver
2493
2634
  };
2494
2635
  var resolveShared = resolveShare.emit(params) || params;
@@ -2525,13 +2666,53 @@ function getTargetSharedOptions(options) {
2525
2666
  shareVersionMap[shared.version] = shared;
2526
2667
  });
2527
2668
  var callback = function callback(prev, cur) {
2528
- return !isLoaded(shareVersionMap[prev]) && versionLt(prev, cur);
2669
+ return (
2670
+ // TODO: consider multiple treeShaking shared scenes
2671
+ !isLoaded(shareVersionMap[prev]) && versionLt(prev, cur)
2672
+ );
2529
2673
  };
2530
2674
  var maxVersion = findVersion(shareVersionMap, callback);
2531
2675
  return shareVersionMap[maxVersion];
2532
2676
  };
2533
2677
  var resolver = (_extraOptions$resolve = extraOptions === null || extraOptions === void 0 ? void 0 : extraOptions.resolver) !== null && _extraOptions$resolve !== void 0 ? _extraOptions$resolve : defaultResolver;
2534
- return Object.assign({}, resolver(shareInfos[pkgName]), extraOptions === null || extraOptions === void 0 ? void 0 : extraOptions.customShareInfo);
2678
+ var isPlainObject = function isPlainObject(val) {
2679
+ return val !== null && _typeof(val) === 'object' && !Array.isArray(val);
2680
+ };
2681
+ var _merge = function merge() {
2682
+ var out = {};
2683
+ for (var _len2 = arguments.length, sources = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
2684
+ sources[_key2] = arguments[_key2];
2685
+ }
2686
+ for (var _i5 = 0, _sources = sources; _i5 < _sources.length; _i5++) {
2687
+ var src = _sources[_i5];
2688
+ if (!src) continue;
2689
+ for (var _i6 = 0, _Object$entries3 = Object.entries(src); _i6 < _Object$entries3.length; _i6++) {
2690
+ var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i6], 2),
2691
+ key = _Object$entries3$_i[0],
2692
+ value = _Object$entries3$_i[1];
2693
+ var prev = out[key];
2694
+ if (isPlainObject(prev) && isPlainObject(value)) {
2695
+ out[key] = _merge(prev, value);
2696
+ } else if (value !== undefined) {
2697
+ out[key] = value;
2698
+ }
2699
+ }
2700
+ }
2701
+ return out;
2702
+ };
2703
+ return _merge(resolver(shareInfos[pkgName]), extraOptions === null || extraOptions === void 0 ? void 0 : extraOptions.customShareInfo);
2704
+ }
2705
+ var addUseIn = function addUseIn(shared, from) {
2706
+ if (!shared.useIn) {
2707
+ shared.useIn = [];
2708
+ }
2709
+ addUniqueItem(shared.useIn, from);
2710
+ };
2711
+ function directShare(shared, useTreesShaking) {
2712
+ if (useTreesShaking && shared.treeShaking) {
2713
+ return shared.treeShaking;
2714
+ }
2715
+ return shared;
2535
2716
  }
2536
2717
  function getBuilderId() {
2537
2718
  //@ts-ignore
@@ -2648,13 +2829,13 @@ function loadEsmEntry(_x3) {
2648
2829
  return _loadEsmEntry.apply(this, arguments);
2649
2830
  }
2650
2831
  function _loadEsmEntry() {
2651
- _loadEsmEntry = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee21(_ref) {
2832
+ _loadEsmEntry = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee23(_ref) {
2652
2833
  var entry, remoteEntryExports;
2653
- return _regenerator().w(function (_context21) {
2654
- while (1) switch (_context21.n) {
2834
+ return _regenerator().w(function (_context23) {
2835
+ while (1) switch (_context23.n) {
2655
2836
  case 0:
2656
2837
  entry = _ref.entry, remoteEntryExports = _ref.remoteEntryExports;
2657
- return _context21.a(2, new Promise(function (resolve, reject) {
2838
+ return _context23.a(2, new Promise(function (resolve, reject) {
2658
2839
  try {
2659
2840
  if (!remoteEntryExports) {
2660
2841
  if (typeof FEDERATION_ALLOW_NEW_FUNCTION !== 'undefined') {
@@ -2670,7 +2851,7 @@ function _loadEsmEntry() {
2670
2851
  }
2671
2852
  }));
2672
2853
  }
2673
- }, _callee21);
2854
+ }, _callee23);
2674
2855
  }));
2675
2856
  return _loadEsmEntry.apply(this, arguments);
2676
2857
  }
@@ -2678,13 +2859,13 @@ function loadSystemJsEntry(_x4) {
2678
2859
  return _loadSystemJsEntry.apply(this, arguments);
2679
2860
  }
2680
2861
  function _loadSystemJsEntry() {
2681
- _loadSystemJsEntry = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee22(_ref2) {
2862
+ _loadSystemJsEntry = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee24(_ref2) {
2682
2863
  var entry, remoteEntryExports;
2683
- return _regenerator().w(function (_context22) {
2684
- while (1) switch (_context22.n) {
2864
+ return _regenerator().w(function (_context24) {
2865
+ while (1) switch (_context24.n) {
2685
2866
  case 0:
2686
2867
  entry = _ref2.entry, remoteEntryExports = _ref2.remoteEntryExports;
2687
- return _context22.a(2, new Promise(function (resolve, reject) {
2868
+ return _context24.a(2, new Promise(function (resolve, reject) {
2688
2869
  try {
2689
2870
  if (!remoteEntryExports) {
2690
2871
  //@ts-ignore
@@ -2702,7 +2883,7 @@ function _loadSystemJsEntry() {
2702
2883
  }
2703
2884
  }));
2704
2885
  }
2705
- }, _callee22);
2886
+ }, _callee24);
2706
2887
  }));
2707
2888
  return _loadSystemJsEntry.apply(this, arguments);
2708
2889
  }
@@ -2721,22 +2902,22 @@ function loadEntryScript(_x5) {
2721
2902
  return _loadEntryScript.apply(this, arguments);
2722
2903
  }
2723
2904
  function _loadEntryScript() {
2724
- _loadEntryScript = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee23(_ref3) {
2905
+ _loadEntryScript = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee25(_ref3) {
2725
2906
  var name, globalName, entry, loaderHook, getEntryUrl, _getRemoteEntryExport2, remoteEntryExports, url;
2726
- return _regenerator().w(function (_context23) {
2727
- while (1) switch (_context23.n) {
2907
+ return _regenerator().w(function (_context25) {
2908
+ while (1) switch (_context25.n) {
2728
2909
  case 0:
2729
2910
  name = _ref3.name, globalName = _ref3.globalName, entry = _ref3.entry, loaderHook = _ref3.loaderHook, getEntryUrl = _ref3.getEntryUrl;
2730
2911
  _getRemoteEntryExport2 = getRemoteEntryExports(name, globalName), remoteEntryExports = _getRemoteEntryExport2.entryExports;
2731
2912
  if (!remoteEntryExports) {
2732
- _context23.n = 1;
2913
+ _context25.n = 1;
2733
2914
  break;
2734
2915
  }
2735
- return _context23.a(2, remoteEntryExports);
2916
+ return _context25.a(2, remoteEntryExports);
2736
2917
  case 1:
2737
2918
  // if getEntryUrl is passed, use the getEntryUrl to get the entry url
2738
2919
  url = getEntryUrl ? getEntryUrl(entry) : entry;
2739
- return _context23.a(2, loadScript(url, {
2920
+ return _context25.a(2, loadScript(url, {
2740
2921
  attrs: {},
2741
2922
  createScriptHook: function createScriptHook(url, attrs) {
2742
2923
  var res = loaderHook.lifecycle.createScript.emit({
@@ -2762,7 +2943,7 @@ function _loadEntryScript() {
2762
2943
  throw e;
2763
2944
  }));
2764
2945
  }
2765
- }, _callee23);
2946
+ }, _callee25);
2766
2947
  }));
2767
2948
  return _loadEntryScript.apply(this, arguments);
2768
2949
  }
@@ -2770,28 +2951,28 @@ function loadEntryDom(_x6) {
2770
2951
  return _loadEntryDom.apply(this, arguments);
2771
2952
  }
2772
2953
  function _loadEntryDom() {
2773
- _loadEntryDom = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee24(_ref4) {
2954
+ _loadEntryDom = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee26(_ref4) {
2774
2955
  var remoteInfo, remoteEntryExports, loaderHook, getEntryUrl, entry, globalName, name, type, _t6;
2775
- return _regenerator().w(function (_context24) {
2776
- while (1) switch (_context24.n) {
2956
+ return _regenerator().w(function (_context26) {
2957
+ while (1) switch (_context26.n) {
2777
2958
  case 0:
2778
2959
  remoteInfo = _ref4.remoteInfo, remoteEntryExports = _ref4.remoteEntryExports, loaderHook = _ref4.loaderHook, getEntryUrl = _ref4.getEntryUrl;
2779
2960
  entry = remoteInfo.entry, globalName = remoteInfo.entryGlobalName, name = remoteInfo.name, type = remoteInfo.type;
2780
2961
  _t6 = type;
2781
- _context24.n = _t6 === 'esm' ? 1 : _t6 === 'module' ? 1 : _t6 === 'system' ? 2 : 3;
2962
+ _context26.n = _t6 === 'esm' ? 1 : _t6 === 'module' ? 1 : _t6 === 'system' ? 2 : 3;
2782
2963
  break;
2783
2964
  case 1:
2784
- return _context24.a(2, loadEsmEntry({
2965
+ return _context26.a(2, loadEsmEntry({
2785
2966
  entry: entry,
2786
2967
  remoteEntryExports: remoteEntryExports
2787
2968
  }));
2788
2969
  case 2:
2789
- return _context24.a(2, loadSystemJsEntry({
2970
+ return _context26.a(2, loadSystemJsEntry({
2790
2971
  entry: entry,
2791
2972
  remoteEntryExports: remoteEntryExports
2792
2973
  }));
2793
2974
  case 3:
2794
- return _context24.a(2, loadEntryScript({
2975
+ return _context26.a(2, loadEntryScript({
2795
2976
  entry: entry,
2796
2977
  globalName: globalName,
2797
2978
  name: name,
@@ -2799,9 +2980,9 @@ function _loadEntryDom() {
2799
2980
  getEntryUrl: getEntryUrl
2800
2981
  }));
2801
2982
  case 4:
2802
- return _context24.a(2);
2983
+ return _context26.a(2);
2803
2984
  }
2804
- }, _callee24);
2985
+ }, _callee26);
2805
2986
  }));
2806
2987
  return _loadEntryDom.apply(this, arguments);
2807
2988
  }
@@ -2809,21 +2990,21 @@ function loadEntryNode(_x7) {
2809
2990
  return _loadEntryNode.apply(this, arguments);
2810
2991
  }
2811
2992
  function _loadEntryNode() {
2812
- _loadEntryNode = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee25(_ref5) {
2993
+ _loadEntryNode = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee27(_ref5) {
2813
2994
  var remoteInfo, loaderHook, entry, globalName, name, type, _getRemoteEntryExport3, remoteEntryExports;
2814
- return _regenerator().w(function (_context25) {
2815
- while (1) switch (_context25.n) {
2995
+ return _regenerator().w(function (_context27) {
2996
+ while (1) switch (_context27.n) {
2816
2997
  case 0:
2817
2998
  remoteInfo = _ref5.remoteInfo, loaderHook = _ref5.loaderHook;
2818
2999
  entry = remoteInfo.entry, globalName = remoteInfo.entryGlobalName, name = remoteInfo.name, type = remoteInfo.type;
2819
3000
  _getRemoteEntryExport3 = getRemoteEntryExports(name, globalName), remoteEntryExports = _getRemoteEntryExport3.entryExports;
2820
3001
  if (!remoteEntryExports) {
2821
- _context25.n = 1;
3002
+ _context27.n = 1;
2822
3003
  break;
2823
3004
  }
2824
- return _context25.a(2, remoteEntryExports);
3005
+ return _context27.a(2, remoteEntryExports);
2825
3006
  case 1:
2826
- return _context25.a(2, loadScriptNode(entry, {
3007
+ return _context27.a(2, loadScriptNode(entry, {
2827
3008
  attrs: {
2828
3009
  name: name,
2829
3010
  globalName: globalName,
@@ -2849,7 +3030,7 @@ function _loadEntryNode() {
2849
3030
  throw e;
2850
3031
  }));
2851
3032
  }
2852
- }, _callee25);
3033
+ }, _callee27);
2853
3034
  }));
2854
3035
  return _loadEntryNode.apply(this, arguments);
2855
3036
  }
@@ -2862,18 +3043,18 @@ function getRemoteEntry(_x8) {
2862
3043
  return _getRemoteEntry.apply(this, arguments);
2863
3044
  }
2864
3045
  function _getRemoteEntry() {
2865
- _getRemoteEntry = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee27(params) {
3046
+ _getRemoteEntry = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee29(params) {
2866
3047
  var origin, remoteEntryExports, remoteInfo, getEntryUrl, _params$_inErrorHandl, _inErrorHandling, uniqueKey, loadEntryHook, loaderHook;
2867
- return _regenerator().w(function (_context27) {
2868
- while (1) switch (_context27.n) {
3048
+ return _regenerator().w(function (_context29) {
3049
+ while (1) switch (_context29.n) {
2869
3050
  case 0:
2870
3051
  origin = params.origin, remoteEntryExports = params.remoteEntryExports, remoteInfo = params.remoteInfo, getEntryUrl = params.getEntryUrl, _params$_inErrorHandl = params._inErrorHandling, _inErrorHandling = _params$_inErrorHandl === void 0 ? false : _params$_inErrorHandl;
2871
3052
  uniqueKey = getRemoteEntryUniqueKey(remoteInfo);
2872
3053
  if (!remoteEntryExports) {
2873
- _context27.n = 1;
3054
+ _context29.n = 1;
2874
3055
  break;
2875
3056
  }
2876
- return _context27.a(2, remoteEntryExports);
3057
+ return _context29.a(2, remoteEntryExports);
2877
3058
  case 1:
2878
3059
  if (!globalLoading[uniqueKey]) {
2879
3060
  loadEntryHook = origin.remoteHandler.hooks.lifecycle.loadEntry;
@@ -2898,15 +3079,15 @@ function _getRemoteEntry() {
2898
3079
  loaderHook: loaderHook
2899
3080
  });
2900
3081
  })["catch"](/*#__PURE__*/function () {
2901
- var _ref20 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee26(err) {
3082
+ var _ref25 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee28(err) {
2902
3083
  var uniqueKey, isScriptLoadError, wrappedGetRemoteEntry, RemoteEntryExports;
2903
- return _regenerator().w(function (_context26) {
2904
- while (1) switch (_context26.n) {
3084
+ return _regenerator().w(function (_context28) {
3085
+ while (1) switch (_context28.n) {
2905
3086
  case 0:
2906
3087
  uniqueKey = getRemoteEntryUniqueKey(remoteInfo);
2907
3088
  isScriptLoadError = err instanceof Error && err.message.includes(RUNTIME_008);
2908
3089
  if (!(isScriptLoadError && !_inErrorHandling)) {
2909
- _context26.n = 2;
3090
+ _context28.n = 2;
2910
3091
  break;
2911
3092
  }
2912
3093
  wrappedGetRemoteEntry = function wrappedGetRemoteEntry(params) {
@@ -2914,7 +3095,7 @@ function _getRemoteEntry() {
2914
3095
  _inErrorHandling: true
2915
3096
  }));
2916
3097
  };
2917
- _context26.n = 1;
3098
+ _context28.n = 1;
2918
3099
  return origin.loaderHook.lifecycle.loadEntryError.emit({
2919
3100
  getRemoteEntry: wrappedGetRemoteEntry,
2920
3101
  origin: origin,
@@ -2924,27 +3105,27 @@ function _getRemoteEntry() {
2924
3105
  uniqueKey: uniqueKey
2925
3106
  });
2926
3107
  case 1:
2927
- RemoteEntryExports = _context26.v;
3108
+ RemoteEntryExports = _context28.v;
2928
3109
  if (!RemoteEntryExports) {
2929
- _context26.n = 2;
3110
+ _context28.n = 2;
2930
3111
  break;
2931
3112
  }
2932
- return _context26.a(2, RemoteEntryExports);
3113
+ return _context28.a(2, RemoteEntryExports);
2933
3114
  case 2:
2934
3115
  throw err;
2935
3116
  case 3:
2936
- return _context26.a(2);
3117
+ return _context28.a(2);
2937
3118
  }
2938
- }, _callee26);
3119
+ }, _callee28);
2939
3120
  }));
2940
- return function (_x29) {
2941
- return _ref20.apply(this, arguments);
3121
+ return function (_x31) {
3122
+ return _ref25.apply(this, arguments);
2942
3123
  };
2943
3124
  }());
2944
3125
  }
2945
- return _context27.a(2, globalLoading[uniqueKey]);
3126
+ return _context29.a(2, globalLoading[uniqueKey]);
2946
3127
  }
2947
- }, _callee27);
3128
+ }, _callee29);
2948
3129
  }));
2949
3130
  return _getRemoteEntry.apply(this, arguments);
2950
3131
  }
@@ -3128,12 +3309,43 @@ function preloadAssets(remoteInfo, host, assets) {
3128
3309
  }
3129
3310
  }
3130
3311
  }
3312
+ function createRemoteEntryInitOptions(remoteInfo, hostShareScopeMap) {
3313
+ var localShareScopeMap = hostShareScopeMap;
3314
+ var shareScopeKeys = Array.isArray(remoteInfo.shareScope) ? remoteInfo.shareScope : [remoteInfo.shareScope];
3315
+ if (!shareScopeKeys.length) {
3316
+ shareScopeKeys.push('default');
3317
+ }
3318
+ shareScopeKeys.forEach(function (shareScopeKey) {
3319
+ if (!localShareScopeMap[shareScopeKey]) {
3320
+ localShareScopeMap[shareScopeKey] = {};
3321
+ }
3322
+ });
3323
+ var remoteEntryInitOptions = {
3324
+ version: remoteInfo.version || '',
3325
+ shareScopeKeys: Array.isArray(remoteInfo.shareScope) ? shareScopeKeys : remoteInfo.shareScope || 'default'
3326
+ };
3327
+ // Help to find host instance
3328
+ Object.defineProperty(remoteEntryInitOptions, 'shareScopeMap', {
3329
+ value: localShareScopeMap,
3330
+ // remoteEntryInitOptions will be traversed and assigned during container init, ,so this attribute is not allowed to be traversed
3331
+ enumerable: false
3332
+ });
3333
+ // TODO: compate legacy init params, should use shareScopeMap if exist
3334
+ var shareScope = localShareScopeMap[shareScopeKeys[0]];
3335
+ var initScope = [];
3336
+ return {
3337
+ remoteEntryInitOptions: remoteEntryInitOptions,
3338
+ shareScope: shareScope,
3339
+ initScope: initScope
3340
+ };
3341
+ }
3131
3342
  var Module = /*#__PURE__*/function () {
3132
3343
  function Module(_ref6) {
3133
3344
  var remoteInfo = _ref6.remoteInfo,
3134
3345
  host = _ref6.host;
3135
3346
  _classCallCheck(this, Module);
3136
3347
  this.inited = false;
3348
+ this.initing = false;
3137
3349
  this.lib = undefined;
3138
3350
  this.remoteInfo = remoteInfo;
3139
3351
  this.host = host;
@@ -3172,113 +3384,145 @@ var Module = /*#__PURE__*/function () {
3172
3384
  return getEntry;
3173
3385
  }() // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
3174
3386
  }, {
3175
- key: "get",
3387
+ key: "init",
3176
3388
  value: function () {
3177
- var _get = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(id, expose, options, remoteSnapshot) {
3178
- var _ref7, _ref7$loadFactory, loadFactory, remoteEntryExports, localShareScopeMap, shareScopeKeys, shareScope, initScope, remoteEntryInitOptions, initContainerOptions, moduleFactory, symbolName, wrapModuleFactory, exposeContent;
3179
- return _regenerator().w(function (_context2) {
3180
- while (1) switch (_context2.n) {
3389
+ var _init = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(id, remoteSnapshot) {
3390
+ var _this = this;
3391
+ var remoteEntryExports;
3392
+ return _regenerator().w(function (_context3) {
3393
+ while (1) switch (_context3.p = _context3.n) {
3181
3394
  case 0:
3182
- _ref7 = options || {
3183
- loadFactory: true
3184
- }, _ref7$loadFactory = _ref7.loadFactory, loadFactory = _ref7$loadFactory === void 0 ? true : _ref7$loadFactory; // Get remoteEntry.js
3185
- _context2.n = 1;
3395
+ _context3.n = 1;
3186
3396
  return this.getEntry();
3187
3397
  case 1:
3188
- remoteEntryExports = _context2.v;
3189
- if (this.inited) {
3190
- _context2.n = 4;
3398
+ remoteEntryExports = _context3.v;
3399
+ if (!this.inited) {
3400
+ _context3.n = 2;
3191
3401
  break;
3192
3402
  }
3193
- localShareScopeMap = this.host.shareScopeMap;
3194
- shareScopeKeys = Array.isArray(this.remoteInfo.shareScope) ? this.remoteInfo.shareScope : [this.remoteInfo.shareScope];
3195
- if (!shareScopeKeys.length) {
3196
- shareScopeKeys.push('default');
3197
- }
3198
- shareScopeKeys.forEach(function (shareScopeKey) {
3199
- if (!localShareScopeMap[shareScopeKey]) {
3200
- localShareScopeMap[shareScopeKey] = {};
3201
- }
3202
- });
3203
- // TODO: compate legacy init params, should use shareScopeMap if exist
3204
- shareScope = localShareScopeMap[shareScopeKeys[0]];
3205
- initScope = [];
3206
- remoteEntryInitOptions = {
3207
- version: this.remoteInfo.version || '',
3208
- shareScopeKeys: Array.isArray(this.remoteInfo.shareScope) ? shareScopeKeys : this.remoteInfo.shareScope || 'default'
3209
- }; // Help to find host instance
3210
- Object.defineProperty(remoteEntryInitOptions, 'shareScopeMap', {
3211
- value: localShareScopeMap,
3212
- // remoteEntryInitOptions will be traversed and assigned during container init, ,so this attribute is not allowed to be traversed
3213
- enumerable: false
3214
- });
3215
- _context2.n = 2;
3216
- return this.host.hooks.lifecycle.beforeInitContainer.emit({
3217
- shareScope: shareScope,
3218
- // @ts-ignore shareScopeMap will be set by Object.defineProperty
3219
- remoteEntryInitOptions: remoteEntryInitOptions,
3220
- initScope: initScope,
3221
- remoteInfo: this.remoteInfo,
3222
- origin: this.host
3223
- });
3403
+ return _context3.a(2, remoteEntryExports);
3224
3404
  case 2:
3225
- initContainerOptions = _context2.v;
3226
- if (typeof (remoteEntryExports === null || remoteEntryExports === void 0 ? void 0 : remoteEntryExports.init) === 'undefined') {
3227
- error(getShortErrorMsg(RUNTIME_002, runtimeDescMap, {
3228
- hostName: this.host.name,
3229
- remoteName: this.remoteInfo.name,
3230
- remoteEntryUrl: this.remoteInfo.entry,
3231
- remoteEntryKey: this.remoteInfo.entryGlobalName
3232
- }));
3405
+ if (!this.initPromise) {
3406
+ _context3.n = 4;
3407
+ break;
3233
3408
  }
3234
- _context2.n = 3;
3235
- return remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
3409
+ _context3.n = 3;
3410
+ return this.initPromise;
3236
3411
  case 3:
3237
- _context2.n = 4;
3238
- return this.host.hooks.lifecycle.initContainer.emit(_objectSpread2(_objectSpread2({}, initContainerOptions), {}, {
3239
- id: id,
3240
- remoteSnapshot: remoteSnapshot,
3241
- remoteEntryExports: remoteEntryExports
3242
- }));
3412
+ return _context3.a(2, remoteEntryExports);
3243
3413
  case 4:
3414
+ this.initing = true;
3415
+ this.initPromise = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
3416
+ var _createRemoteEntryIni, remoteEntryInitOptions, shareScope, initScope, initContainerOptions;
3417
+ return _regenerator().w(function (_context2) {
3418
+ while (1) switch (_context2.n) {
3419
+ case 0:
3420
+ _createRemoteEntryIni = createRemoteEntryInitOptions(_this.remoteInfo, _this.host.shareScopeMap), remoteEntryInitOptions = _createRemoteEntryIni.remoteEntryInitOptions, shareScope = _createRemoteEntryIni.shareScope, initScope = _createRemoteEntryIni.initScope;
3421
+ _context2.n = 1;
3422
+ return _this.host.hooks.lifecycle.beforeInitContainer.emit({
3423
+ shareScope: shareScope,
3424
+ // @ts-ignore shareScopeMap will be set by Object.defineProperty
3425
+ remoteEntryInitOptions: remoteEntryInitOptions,
3426
+ initScope: initScope,
3427
+ remoteInfo: _this.remoteInfo,
3428
+ origin: _this.host
3429
+ });
3430
+ case 1:
3431
+ initContainerOptions = _context2.v;
3432
+ if (typeof (remoteEntryExports === null || remoteEntryExports === void 0 ? void 0 : remoteEntryExports.init) === 'undefined') {
3433
+ error(getShortErrorMsg(RUNTIME_002, runtimeDescMap, {
3434
+ hostName: _this.host.name,
3435
+ remoteName: _this.remoteInfo.name,
3436
+ remoteEntryUrl: _this.remoteInfo.entry,
3437
+ remoteEntryKey: _this.remoteInfo.entryGlobalName
3438
+ }));
3439
+ }
3440
+ _context2.n = 2;
3441
+ return remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
3442
+ case 2:
3443
+ _context2.n = 3;
3444
+ return _this.host.hooks.lifecycle.initContainer.emit(_objectSpread2(_objectSpread2({}, initContainerOptions), {}, {
3445
+ id: id,
3446
+ remoteSnapshot: remoteSnapshot,
3447
+ remoteEntryExports: remoteEntryExports
3448
+ }));
3449
+ case 3:
3450
+ _this.inited = true;
3451
+ case 4:
3452
+ return _context2.a(2);
3453
+ }
3454
+ }, _callee2);
3455
+ }))();
3456
+ _context3.p = 5;
3457
+ _context3.n = 6;
3458
+ return this.initPromise;
3459
+ case 6:
3460
+ _context3.p = 6;
3461
+ this.initing = false;
3462
+ this.initPromise = undefined;
3463
+ return _context3.f(6);
3464
+ case 7:
3465
+ return _context3.a(2, remoteEntryExports);
3466
+ }
3467
+ }, _callee3, this, [[5,, 6, 7]]);
3468
+ }));
3469
+ function init(_x9, _x0) {
3470
+ return _init.apply(this, arguments);
3471
+ }
3472
+ return init;
3473
+ }() // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
3474
+ }, {
3475
+ key: "get",
3476
+ value: function () {
3477
+ var _get = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(id, expose, options, remoteSnapshot) {
3478
+ var _ref8, _ref8$loadFactory, loadFactory, remoteEntryExports, moduleFactory, symbolName, wrapModuleFactory, exposeContent;
3479
+ return _regenerator().w(function (_context4) {
3480
+ while (1) switch (_context4.n) {
3481
+ case 0:
3482
+ _ref8 = options || {
3483
+ loadFactory: true
3484
+ }, _ref8$loadFactory = _ref8.loadFactory, loadFactory = _ref8$loadFactory === void 0 ? true : _ref8$loadFactory;
3485
+ _context4.n = 1;
3486
+ return this.init(id, remoteSnapshot);
3487
+ case 1:
3488
+ remoteEntryExports = _context4.v;
3244
3489
  this.lib = remoteEntryExports;
3245
- this.inited = true;
3246
- _context2.n = 5;
3490
+ _context4.n = 2;
3247
3491
  return this.host.loaderHook.lifecycle.getModuleFactory.emit({
3248
3492
  remoteEntryExports: remoteEntryExports,
3249
3493
  expose: expose,
3250
3494
  moduleInfo: this.remoteInfo
3251
3495
  });
3252
- case 5:
3253
- moduleFactory = _context2.v;
3496
+ case 2:
3497
+ moduleFactory = _context4.v;
3254
3498
  if (moduleFactory) {
3255
- _context2.n = 7;
3499
+ _context4.n = 4;
3256
3500
  break;
3257
3501
  }
3258
- _context2.n = 6;
3502
+ _context4.n = 3;
3259
3503
  return remoteEntryExports.get(expose);
3260
- case 6:
3261
- moduleFactory = _context2.v;
3262
- case 7:
3504
+ case 3:
3505
+ moduleFactory = _context4.v;
3506
+ case 4:
3263
3507
  assert(moduleFactory, "".concat(getFMId(this.remoteInfo), " remote don't export ").concat(expose, "."));
3264
3508
  // keep symbol for module name always one format
3265
3509
  symbolName = processModuleAlias(this.remoteInfo.name, expose);
3266
3510
  wrapModuleFactory = this.wraperFactory(moduleFactory, symbolName);
3267
3511
  if (loadFactory) {
3268
- _context2.n = 8;
3512
+ _context4.n = 5;
3269
3513
  break;
3270
3514
  }
3271
- return _context2.a(2, wrapModuleFactory);
3272
- case 8:
3273
- _context2.n = 9;
3515
+ return _context4.a(2, wrapModuleFactory);
3516
+ case 5:
3517
+ _context4.n = 6;
3274
3518
  return wrapModuleFactory();
3275
- case 9:
3276
- exposeContent = _context2.v;
3277
- return _context2.a(2, exposeContent);
3519
+ case 6:
3520
+ exposeContent = _context4.v;
3521
+ return _context4.a(2, exposeContent);
3278
3522
  }
3279
- }, _callee2, this);
3523
+ }, _callee4, this);
3280
3524
  }));
3281
- function get(_x9, _x0, _x1, _x10) {
3525
+ function get(_x1, _x10, _x11, _x12) {
3282
3526
  return _get.apply(this, arguments);
3283
3527
  }
3284
3528
  return get;
@@ -3295,20 +3539,20 @@ var Module = /*#__PURE__*/function () {
3295
3539
  }
3296
3540
  }
3297
3541
  if (moduleFactory instanceof Promise) {
3298
- return /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
3542
+ return /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5() {
3299
3543
  var res;
3300
- return _regenerator().w(function (_context3) {
3301
- while (1) switch (_context3.n) {
3544
+ return _regenerator().w(function (_context5) {
3545
+ while (1) switch (_context5.n) {
3302
3546
  case 0:
3303
- _context3.n = 1;
3547
+ _context5.n = 1;
3304
3548
  return moduleFactory();
3305
3549
  case 1:
3306
- res = _context3.v;
3550
+ res = _context5.v;
3307
3551
  // This parameter is used for bridge debugging
3308
3552
  defineModuleId(res, id);
3309
- return _context3.a(2, res);
3553
+ return _context5.a(2, res);
3310
3554
  }
3311
- }, _callee3);
3555
+ }, _callee5);
3312
3556
  }));
3313
3557
  } else {
3314
3558
  return function () {
@@ -3345,8 +3589,8 @@ var SyncHook = /*#__PURE__*/function () {
3345
3589
  this.on(function wrapper() {
3346
3590
  self.remove(wrapper);
3347
3591
  // eslint-disable-next-line prefer-spread
3348
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
3349
- args[_key2] = arguments[_key2];
3592
+ for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
3593
+ args[_key3] = arguments[_key3];
3350
3594
  }
3351
3595
  return fn.apply(null, args);
3352
3596
  });
@@ -3354,8 +3598,8 @@ var SyncHook = /*#__PURE__*/function () {
3354
3598
  }, {
3355
3599
  key: "emit",
3356
3600
  value: function emit() {
3357
- for (var _len3 = arguments.length, data = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
3358
- data[_key3] = arguments[_key3];
3601
+ for (var _len4 = arguments.length, data = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
3602
+ data[_key4] = arguments[_key4];
3359
3603
  }
3360
3604
  var result;
3361
3605
  if (this.listeners.size > 0) {
@@ -3387,8 +3631,8 @@ var AsyncHook = /*#__PURE__*/function (_SyncHook) {
3387
3631
  return _createClass(AsyncHook, [{
3388
3632
  key: "emit",
3389
3633
  value: function emit() {
3390
- for (var _len4 = arguments.length, data = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
3391
- data[_key4] = arguments[_key4];
3634
+ for (var _len5 = arguments.length, data = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
3635
+ data[_key5] = arguments[_key5];
3392
3636
  }
3393
3637
  var result;
3394
3638
  var ls = Array.from(this.listeners);
@@ -3425,12 +3669,12 @@ function checkReturnData(originalData, returnedData) {
3425
3669
  }
3426
3670
  var SyncWaterfallHook = /*#__PURE__*/function (_SyncHook2) {
3427
3671
  function SyncWaterfallHook(type) {
3428
- var _this;
3672
+ var _this2;
3429
3673
  _classCallCheck(this, SyncWaterfallHook);
3430
- _this = _callSuper(this, SyncWaterfallHook);
3431
- _this.onerror = error;
3432
- _this.type = type;
3433
- return _this;
3674
+ _this2 = _callSuper(this, SyncWaterfallHook);
3675
+ _this2.onerror = error;
3676
+ _this2.type = type;
3677
+ return _this2;
3434
3678
  }
3435
3679
  _inherits(SyncWaterfallHook, _SyncHook2);
3436
3680
  return _createClass(SyncWaterfallHook, [{
@@ -3468,18 +3712,18 @@ var SyncWaterfallHook = /*#__PURE__*/function (_SyncHook2) {
3468
3712
  }(SyncHook);
3469
3713
  var AsyncWaterfallHook = /*#__PURE__*/function (_SyncHook3) {
3470
3714
  function AsyncWaterfallHook(type) {
3471
- var _this2;
3715
+ var _this3;
3472
3716
  _classCallCheck(this, AsyncWaterfallHook);
3473
- _this2 = _callSuper(this, AsyncWaterfallHook);
3474
- _this2.onerror = error;
3475
- _this2.type = type;
3476
- return _this2;
3717
+ _this3 = _callSuper(this, AsyncWaterfallHook);
3718
+ _this3.onerror = error;
3719
+ _this3.type = type;
3720
+ return _this3;
3477
3721
  }
3478
3722
  _inherits(AsyncWaterfallHook, _SyncHook3);
3479
3723
  return _createClass(AsyncWaterfallHook, [{
3480
3724
  key: "emit",
3481
3725
  value: function emit(data) {
3482
- var _this3 = this;
3726
+ var _this4 = this;
3483
3727
  if (!isObject(data)) {
3484
3728
  error("The response data for the \"".concat(this.type, "\" hook must be an object."));
3485
3729
  }
@@ -3488,7 +3732,7 @@ var AsyncWaterfallHook = /*#__PURE__*/function (_SyncHook3) {
3488
3732
  var i = 0;
3489
3733
  var processError = function processError(e) {
3490
3734
  warn(e);
3491
- _this3.onerror(e);
3735
+ _this4.onerror(e);
3492
3736
  return data;
3493
3737
  };
3494
3738
  var _call2 = function call(prevData) {
@@ -3502,7 +3746,7 @@ var AsyncWaterfallHook = /*#__PURE__*/function (_SyncHook3) {
3502
3746
  }
3503
3747
  }
3504
3748
  } else {
3505
- _this3.onerror("A plugin returned an incorrect value for the \"".concat(_this3.type, "\" type."));
3749
+ _this4.onerror("A plugin returned an incorrect value for the \"".concat(_this4.type, "\" type."));
3506
3750
  }
3507
3751
  return data;
3508
3752
  };
@@ -3522,7 +3766,7 @@ var PluginSystem = /*#__PURE__*/function () {
3522
3766
  return _createClass(PluginSystem, [{
3523
3767
  key: "applyPlugin",
3524
3768
  value: function applyPlugin(plugin, instance) {
3525
- var _this4 = this;
3769
+ var _this5 = this;
3526
3770
  assert(isPlainObject(plugin), 'Plugin configuration is invalid.');
3527
3771
  // The plugin's name is mandatory and must be unique
3528
3772
  var pluginName = plugin.name;
@@ -3534,7 +3778,7 @@ var PluginSystem = /*#__PURE__*/function () {
3534
3778
  Object.keys(this.lifecycle).forEach(function (key) {
3535
3779
  var pluginLife = plugin[key];
3536
3780
  if (pluginLife) {
3537
- _this4.lifecycle[key].on(pluginLife);
3781
+ _this5.lifecycle[key].on(pluginLife);
3538
3782
  }
3539
3783
  });
3540
3784
  }
@@ -3542,13 +3786,13 @@ var PluginSystem = /*#__PURE__*/function () {
3542
3786
  }, {
3543
3787
  key: "removePlugin",
3544
3788
  value: function removePlugin(pluginName) {
3545
- var _this5 = this;
3789
+ var _this6 = this;
3546
3790
  assert(pluginName, 'A name is required.');
3547
3791
  var plugin = this.registerPlugins[pluginName];
3548
3792
  assert(plugin, "The plugin \"".concat(pluginName, "\" is not registered."));
3549
3793
  Object.keys(plugin).forEach(function (key) {
3550
3794
  if (key !== 'name') {
3551
- _this5.lifecycle[key].remove(plugin[key]);
3795
+ _this6.lifecycle[key].remove(plugin[key]);
3552
3796
  }
3553
3797
  });
3554
3798
  }
@@ -3573,23 +3817,23 @@ function snapshotPlugin() {
3573
3817
  return {
3574
3818
  name: 'snapshot-plugin',
3575
3819
  afterResolve: function afterResolve(args) {
3576
- return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
3820
+ return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6() {
3577
3821
  var remote, pkgNameOrAlias, expose, origin, remoteInfo, id, _yield$origin$snapsho, remoteSnapshot, globalSnapshot, preloadOptions, assets;
3578
- return _regenerator().w(function (_context4) {
3579
- while (1) switch (_context4.n) {
3822
+ return _regenerator().w(function (_context6) {
3823
+ while (1) switch (_context6.n) {
3580
3824
  case 0:
3581
3825
  remote = args.remote, pkgNameOrAlias = args.pkgNameOrAlias, expose = args.expose, origin = args.origin, remoteInfo = args.remoteInfo, id = args.id;
3582
3826
  if (!(!isRemoteInfoWithEntry(remote) || !isPureRemoteEntry(remote))) {
3583
- _context4.n = 3;
3827
+ _context6.n = 3;
3584
3828
  break;
3585
3829
  }
3586
- _context4.n = 1;
3830
+ _context6.n = 1;
3587
3831
  return origin.snapshotHandler.loadRemoteSnapshotInfo({
3588
3832
  moduleInfo: remote,
3589
3833
  id: id
3590
3834
  });
3591
3835
  case 1:
3592
- _yield$origin$snapsho = _context4.v;
3836
+ _yield$origin$snapsho = _context6.v;
3593
3837
  remoteSnapshot = _yield$origin$snapsho.remoteSnapshot;
3594
3838
  globalSnapshot = _yield$origin$snapsho.globalSnapshot;
3595
3839
  assignRemoteInfo(remoteInfo, remoteSnapshot);
@@ -3604,7 +3848,7 @@ function snapshotPlugin() {
3604
3848
  depsRemote: false
3605
3849
  }
3606
3850
  };
3607
- _context4.n = 2;
3851
+ _context6.n = 2;
3608
3852
  return origin.remoteHandler.hooks.lifecycle.generatePreloadAssets.emit({
3609
3853
  origin: origin,
3610
3854
  preloadOptions: preloadOptions,
@@ -3614,17 +3858,17 @@ function snapshotPlugin() {
3614
3858
  globalSnapshot: globalSnapshot
3615
3859
  });
3616
3860
  case 2:
3617
- assets = _context4.v;
3861
+ assets = _context6.v;
3618
3862
  if (assets) {
3619
3863
  preloadAssets(remoteInfo, origin, assets, false);
3620
3864
  }
3621
- return _context4.a(2, _objectSpread2(_objectSpread2({}, args), {}, {
3865
+ return _context6.a(2, _objectSpread2(_objectSpread2({}, args), {}, {
3622
3866
  remoteSnapshot: remoteSnapshot
3623
3867
  }));
3624
3868
  case 3:
3625
- return _context4.a(2, args);
3869
+ return _context6.a(2, args);
3626
3870
  }
3627
- }, _callee4);
3871
+ }, _callee6);
3628
3872
  }))();
3629
3873
  }
3630
3874
  };
@@ -3663,8 +3907,8 @@ function traverseModuleInfo(globalSnapshot, remoteInfo, traverse, isRoot) {
3663
3907
  traverse(effectiveRemoteSnapshot, remoteInfo, isRoot);
3664
3908
  if (effectiveRemoteSnapshot.remotesInfo) {
3665
3909
  var remoteKeys = Object.keys(effectiveRemoteSnapshot.remotesInfo);
3666
- for (var _i4 = 0, _remoteKeys = remoteKeys; _i4 < _remoteKeys.length; _i4++) {
3667
- var key = _remoteKeys[_i4];
3910
+ for (var _i7 = 0, _remoteKeys = remoteKeys; _i7 < _remoteKeys.length; _i7++) {
3911
+ var key = _remoteKeys[_i7];
3668
3912
  if (memo[key]) {
3669
3913
  continue;
3670
3914
  }
@@ -3784,7 +4028,8 @@ function _generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot,
3784
4028
  }, true, memo, remoteSnapshot);
3785
4029
  if (remoteSnapshot.shared && remoteSnapshot.shared.length > 0) {
3786
4030
  var collectSharedAssets = function collectSharedAssets(shareInfo, snapshotShared) {
3787
- var registeredShared = getRegisteredShare(origin.shareScopeMap, snapshotShared.sharedName, shareInfo, origin.sharedHandler.hooks.lifecycle.resolveShare);
4031
+ var _ref0 = getRegisteredShare(origin.shareScopeMap, snapshotShared.sharedName, shareInfo, origin.sharedHandler.hooks.lifecycle.resolveShare) || {},
4032
+ registeredShared = _ref0.shared;
3788
4033
  // If the global share does not exist, or the lib function does not exist, it means that the shared has not been loaded yet and can be preloaded.
3789
4034
  if (registeredShared && typeof registeredShared.lib === 'function') {
3790
4035
  snapshotShared.assets.js.sync.forEach(function (asset) {
@@ -3832,27 +4077,27 @@ var generatePreloadAssetsPlugin = function generatePreloadAssetsPlugin() {
3832
4077
  return {
3833
4078
  name: 'generate-preload-assets-plugin',
3834
4079
  generatePreloadAssets: function generatePreloadAssets(args) {
3835
- return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5() {
4080
+ return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7() {
3836
4081
  var origin, preloadOptions, remoteInfo, remote, globalSnapshot, remoteSnapshot, assets;
3837
- return _regenerator().w(function (_context5) {
3838
- while (1) switch (_context5.n) {
4082
+ return _regenerator().w(function (_context7) {
4083
+ while (1) switch (_context7.n) {
3839
4084
  case 0:
3840
4085
  origin = args.origin, preloadOptions = args.preloadOptions, remoteInfo = args.remoteInfo, remote = args.remote, globalSnapshot = args.globalSnapshot, remoteSnapshot = args.remoteSnapshot;
3841
4086
  if (isBrowserEnv()) {
3842
- _context5.n = 1;
4087
+ _context7.n = 1;
3843
4088
  break;
3844
4089
  }
3845
- return _context5.a(2, {
4090
+ return _context7.a(2, {
3846
4091
  cssAssets: [],
3847
4092
  jsAssetsWithoutEntry: [],
3848
4093
  entryAssets: []
3849
4094
  });
3850
4095
  case 1:
3851
4096
  if (!(isRemoteInfoWithEntry(remote) && isPureRemoteEntry(remote))) {
3852
- _context5.n = 2;
4097
+ _context7.n = 2;
3853
4098
  break;
3854
4099
  }
3855
- return _context5.a(2, {
4100
+ return _context7.a(2, {
3856
4101
  cssAssets: [],
3857
4102
  jsAssetsWithoutEntry: [],
3858
4103
  entryAssets: [{
@@ -3870,9 +4115,9 @@ var generatePreloadAssetsPlugin = function generatePreloadAssetsPlugin() {
3870
4115
  case 2:
3871
4116
  assignRemoteInfo(remoteInfo, remoteSnapshot);
3872
4117
  assets = _generatePreloadAssets(origin, preloadOptions, remoteInfo, globalSnapshot, remoteSnapshot);
3873
- return _context5.a(2, assets);
4118
+ return _context7.a(2, assets);
3874
4119
  }
3875
- }, _callee5);
4120
+ }, _callee7);
3876
4121
  }))();
3877
4122
  }
3878
4123
  };
@@ -3922,14 +4167,14 @@ var SnapshotHandler = /*#__PURE__*/function () {
3922
4167
  return _createClass(SnapshotHandler, [{
3923
4168
  key: "loadRemoteSnapshotInfo",
3924
4169
  value: function () {
3925
- var _loadRemoteSnapshotInfo = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(_ref9) {
4170
+ var _loadRemoteSnapshotInfo = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(_ref1) {
3926
4171
  var moduleInfo, id, options, hostSnapshot, _hostSnapshot, _this$getGlobalRemote, hostGlobalSnapshot, remoteSnapshot, globalSnapshot, _yield$this$hooks$lif, globalRemoteSnapshot, globalSnapshotRes, mSnapshot, gSnapshot, remoteEntry, moduleSnapshot, _globalSnapshotRes, _yield$this$hooks$lif2, remoteSnapshotRes, _moduleSnapshot, _globalSnapshotRes2, _yield$this$hooks$lif3, _remoteSnapshotRes;
3927
- return _regenerator().w(function (_context6) {
3928
- while (1) switch (_context6.n) {
4172
+ return _regenerator().w(function (_context8) {
4173
+ while (1) switch (_context8.n) {
3929
4174
  case 0:
3930
- moduleInfo = _ref9.moduleInfo, id = _ref9.id, _ref9.expose;
4175
+ moduleInfo = _ref1.moduleInfo, id = _ref1.id, _ref1.expose;
3931
4176
  options = this.HostInstance.options;
3932
- _context6.n = 1;
4177
+ _context8.n = 1;
3933
4178
  return this.hooks.lifecycle.beforeLoadRemoteSnapshot.emit({
3934
4179
  options: options,
3935
4180
  moduleInfo: moduleInfo
@@ -3957,7 +4202,7 @@ var SnapshotHandler = /*#__PURE__*/function () {
3957
4202
  }
3958
4203
  }
3959
4204
  _this$getGlobalRemote = this.getGlobalRemoteInfo(moduleInfo), hostGlobalSnapshot = _this$getGlobalRemote.hostGlobalSnapshot, remoteSnapshot = _this$getGlobalRemote.remoteSnapshot, globalSnapshot = _this$getGlobalRemote.globalSnapshot;
3960
- _context6.n = 2;
4205
+ _context8.n = 2;
3961
4206
  return this.hooks.lifecycle.loadSnapshot.emit({
3962
4207
  options: options,
3963
4208
  moduleInfo: moduleInfo,
@@ -3966,22 +4211,22 @@ var SnapshotHandler = /*#__PURE__*/function () {
3966
4211
  globalSnapshot: globalSnapshot
3967
4212
  });
3968
4213
  case 2:
3969
- _yield$this$hooks$lif = _context6.v;
4214
+ _yield$this$hooks$lif = _context8.v;
3970
4215
  globalRemoteSnapshot = _yield$this$hooks$lif.remoteSnapshot;
3971
4216
  globalSnapshotRes = _yield$this$hooks$lif.globalSnapshot;
3972
4217
  if (!globalRemoteSnapshot) {
3973
- _context6.n = 7;
4218
+ _context8.n = 7;
3974
4219
  break;
3975
4220
  }
3976
4221
  if (!isManifestProvider(globalRemoteSnapshot)) {
3977
- _context6.n = 4;
4222
+ _context8.n = 4;
3978
4223
  break;
3979
4224
  }
3980
4225
  remoteEntry = isBrowserEnv() ? globalRemoteSnapshot.remoteEntry : globalRemoteSnapshot.ssrRemoteEntry || globalRemoteSnapshot.remoteEntry || '';
3981
- _context6.n = 3;
4226
+ _context8.n = 3;
3982
4227
  return this.getManifestJson(remoteEntry, moduleInfo, {});
3983
4228
  case 3:
3984
- moduleSnapshot = _context6.v;
4229
+ moduleSnapshot = _context8.v;
3985
4230
  // eslint-disable-next-line @typescript-eslint/no-shadow
3986
4231
  _globalSnapshotRes = setGlobalSnapshotInfoByModuleInfo(_objectSpread2(_objectSpread2({}, moduleInfo), {}, {
3987
4232
  // The global remote may be overridden
@@ -3990,10 +4235,10 @@ var SnapshotHandler = /*#__PURE__*/function () {
3990
4235
  }), moduleSnapshot);
3991
4236
  mSnapshot = moduleSnapshot;
3992
4237
  gSnapshot = _globalSnapshotRes;
3993
- _context6.n = 6;
4238
+ _context8.n = 6;
3994
4239
  break;
3995
4240
  case 4:
3996
- _context6.n = 5;
4241
+ _context8.n = 5;
3997
4242
  return this.hooks.lifecycle.loadRemoteSnapshot.emit({
3998
4243
  options: this.HostInstance.options,
3999
4244
  moduleInfo: moduleInfo,
@@ -4001,25 +4246,25 @@ var SnapshotHandler = /*#__PURE__*/function () {
4001
4246
  from: 'global'
4002
4247
  });
4003
4248
  case 5:
4004
- _yield$this$hooks$lif2 = _context6.v;
4249
+ _yield$this$hooks$lif2 = _context8.v;
4005
4250
  remoteSnapshotRes = _yield$this$hooks$lif2.remoteSnapshot;
4006
4251
  mSnapshot = remoteSnapshotRes;
4007
4252
  gSnapshot = globalSnapshotRes;
4008
4253
  case 6:
4009
- _context6.n = 11;
4254
+ _context8.n = 11;
4010
4255
  break;
4011
4256
  case 7:
4012
4257
  if (!isRemoteInfoWithEntry(moduleInfo)) {
4013
- _context6.n = 10;
4258
+ _context8.n = 10;
4014
4259
  break;
4015
4260
  }
4016
- _context6.n = 8;
4261
+ _context8.n = 8;
4017
4262
  return this.getManifestJson(moduleInfo.entry, moduleInfo, {});
4018
4263
  case 8:
4019
- _moduleSnapshot = _context6.v;
4264
+ _moduleSnapshot = _context8.v;
4020
4265
  // eslint-disable-next-line @typescript-eslint/no-shadow
4021
4266
  _globalSnapshotRes2 = setGlobalSnapshotInfoByModuleInfo(moduleInfo, _moduleSnapshot);
4022
- _context6.n = 9;
4267
+ _context8.n = 9;
4023
4268
  return this.hooks.lifecycle.loadRemoteSnapshot.emit({
4024
4269
  options: this.HostInstance.options,
4025
4270
  moduleInfo: moduleInfo,
@@ -4027,11 +4272,11 @@ var SnapshotHandler = /*#__PURE__*/function () {
4027
4272
  from: 'global'
4028
4273
  });
4029
4274
  case 9:
4030
- _yield$this$hooks$lif3 = _context6.v;
4275
+ _yield$this$hooks$lif3 = _context8.v;
4031
4276
  _remoteSnapshotRes = _yield$this$hooks$lif3.remoteSnapshot;
4032
4277
  mSnapshot = _remoteSnapshotRes;
4033
4278
  gSnapshot = _globalSnapshotRes2;
4034
- _context6.n = 11;
4279
+ _context8.n = 11;
4035
4280
  break;
4036
4281
  case 10:
4037
4282
  error(getShortErrorMsg(RUNTIME_007, runtimeDescMap, {
@@ -4040,7 +4285,7 @@ var SnapshotHandler = /*#__PURE__*/function () {
4040
4285
  globalSnapshot: JSON.stringify(globalSnapshotRes)
4041
4286
  }));
4042
4287
  case 11:
4043
- _context6.n = 12;
4288
+ _context8.n = 12;
4044
4289
  return this.hooks.lifecycle.afterLoadSnapshot.emit({
4045
4290
  id: id,
4046
4291
  host: this.HostInstance,
@@ -4049,14 +4294,14 @@ var SnapshotHandler = /*#__PURE__*/function () {
4049
4294
  remoteSnapshot: mSnapshot
4050
4295
  });
4051
4296
  case 12:
4052
- return _context6.a(2, {
4297
+ return _context8.a(2, {
4053
4298
  remoteSnapshot: mSnapshot,
4054
4299
  globalSnapshot: gSnapshot
4055
4300
  });
4056
4301
  }
4057
- }, _callee6, this);
4302
+ }, _callee8, this);
4058
4303
  }));
4059
- function loadRemoteSnapshotInfo(_x11) {
4304
+ function loadRemoteSnapshotInfo(_x13) {
4060
4305
  return _loadRemoteSnapshotInfo.apply(this, arguments);
4061
4306
  }
4062
4307
  return loadRemoteSnapshotInfo;
@@ -4069,93 +4314,93 @@ var SnapshotHandler = /*#__PURE__*/function () {
4069
4314
  }, {
4070
4315
  key: "getManifestJson",
4071
4316
  value: function () {
4072
- var _getManifestJson = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(manifestUrl, moduleInfo, extraOptions) {
4073
- var _this6 = this;
4317
+ var _getManifestJson = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(manifestUrl, moduleInfo, extraOptions) {
4318
+ var _this7 = this;
4074
4319
  var getManifest, asyncLoadProcess;
4075
- return _regenerator().w(function (_context9) {
4076
- while (1) switch (_context9.n) {
4320
+ return _regenerator().w(function (_context1) {
4321
+ while (1) switch (_context1.n) {
4077
4322
  case 0:
4078
4323
  getManifest = /*#__PURE__*/function () {
4079
- var _ref0 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7() {
4324
+ var _ref10 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9() {
4080
4325
  var manifestJson, res, _t;
4081
- return _regenerator().w(function (_context7) {
4082
- while (1) switch (_context7.p = _context7.n) {
4326
+ return _regenerator().w(function (_context9) {
4327
+ while (1) switch (_context9.p = _context9.n) {
4083
4328
  case 0:
4084
- manifestJson = _this6.manifestCache.get(manifestUrl);
4329
+ manifestJson = _this7.manifestCache.get(manifestUrl);
4085
4330
  if (!manifestJson) {
4086
- _context7.n = 1;
4331
+ _context9.n = 1;
4087
4332
  break;
4088
4333
  }
4089
- return _context7.a(2, manifestJson);
4334
+ return _context9.a(2, manifestJson);
4090
4335
  case 1:
4091
- _context7.p = 1;
4092
- _context7.n = 2;
4093
- return _this6.loaderHook.lifecycle.fetch.emit(manifestUrl, {});
4336
+ _context9.p = 1;
4337
+ _context9.n = 2;
4338
+ return _this7.loaderHook.lifecycle.fetch.emit(manifestUrl, {});
4094
4339
  case 2:
4095
- res = _context7.v;
4340
+ res = _context9.v;
4096
4341
  if (!(!res || !(res instanceof Response))) {
4097
- _context7.n = 4;
4342
+ _context9.n = 4;
4098
4343
  break;
4099
4344
  }
4100
- _context7.n = 3;
4345
+ _context9.n = 3;
4101
4346
  return fetch(manifestUrl, {});
4102
4347
  case 3:
4103
- res = _context7.v;
4348
+ res = _context9.v;
4104
4349
  case 4:
4105
- _context7.n = 5;
4350
+ _context9.n = 5;
4106
4351
  return res.json();
4107
4352
  case 5:
4108
- manifestJson = _context7.v;
4109
- _context7.n = 8;
4353
+ manifestJson = _context9.v;
4354
+ _context9.n = 8;
4110
4355
  break;
4111
4356
  case 6:
4112
- _context7.p = 6;
4113
- _t = _context7.v;
4114
- _context7.n = 7;
4115
- return _this6.HostInstance.remoteHandler.hooks.lifecycle.errorLoadRemote.emit({
4357
+ _context9.p = 6;
4358
+ _t = _context9.v;
4359
+ _context9.n = 7;
4360
+ return _this7.HostInstance.remoteHandler.hooks.lifecycle.errorLoadRemote.emit({
4116
4361
  id: manifestUrl,
4117
4362
  error: _t,
4118
4363
  from: 'runtime',
4119
4364
  lifecycle: 'afterResolve',
4120
- origin: _this6.HostInstance
4365
+ origin: _this7.HostInstance
4121
4366
  });
4122
4367
  case 7:
4123
- manifestJson = _context7.v;
4368
+ manifestJson = _context9.v;
4124
4369
  if (!manifestJson) {
4125
- delete _this6.manifestLoading[manifestUrl];
4370
+ delete _this7.manifestLoading[manifestUrl];
4126
4371
  error(getShortErrorMsg(RUNTIME_003, runtimeDescMap, {
4127
4372
  manifestUrl: manifestUrl,
4128
4373
  moduleName: moduleInfo.name,
4129
- hostName: _this6.HostInstance.options.name
4374
+ hostName: _this7.HostInstance.options.name
4130
4375
  }, "".concat(_t)));
4131
4376
  }
4132
4377
  case 8:
4133
4378
  assert(manifestJson.metaData && manifestJson.exposes && manifestJson.shared, "".concat(manifestUrl, " is not a federation manifest"));
4134
- _this6.manifestCache.set(manifestUrl, manifestJson);
4135
- return _context7.a(2, manifestJson);
4379
+ _this7.manifestCache.set(manifestUrl, manifestJson);
4380
+ return _context9.a(2, manifestJson);
4136
4381
  }
4137
- }, _callee7, null, [[1, 6]]);
4382
+ }, _callee9, null, [[1, 6]]);
4138
4383
  }));
4139
4384
  return function getManifest() {
4140
- return _ref0.apply(this, arguments);
4385
+ return _ref10.apply(this, arguments);
4141
4386
  };
4142
4387
  }();
4143
4388
  asyncLoadProcess = /*#__PURE__*/function () {
4144
- var _ref1 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8() {
4145
- var manifestJson, remoteSnapshot, _yield$_this6$hooks$l, remoteSnapshotRes;
4146
- return _regenerator().w(function (_context8) {
4147
- while (1) switch (_context8.n) {
4389
+ var _ref11 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0() {
4390
+ var manifestJson, remoteSnapshot, _yield$_this7$hooks$l, remoteSnapshotRes;
4391
+ return _regenerator().w(function (_context0) {
4392
+ while (1) switch (_context0.n) {
4148
4393
  case 0:
4149
- _context8.n = 1;
4394
+ _context0.n = 1;
4150
4395
  return getManifest();
4151
4396
  case 1:
4152
- manifestJson = _context8.v;
4397
+ manifestJson = _context0.v;
4153
4398
  remoteSnapshot = generateSnapshotFromManifest(manifestJson, {
4154
4399
  version: manifestUrl
4155
4400
  });
4156
- _context8.n = 2;
4157
- return _this6.hooks.lifecycle.loadRemoteSnapshot.emit({
4158
- options: _this6.HostInstance.options,
4401
+ _context0.n = 2;
4402
+ return _this7.hooks.lifecycle.loadRemoteSnapshot.emit({
4403
+ options: _this7.HostInstance.options,
4159
4404
  moduleInfo: moduleInfo,
4160
4405
  manifestJson: manifestJson,
4161
4406
  remoteSnapshot: remoteSnapshot,
@@ -4163,14 +4408,14 @@ var SnapshotHandler = /*#__PURE__*/function () {
4163
4408
  from: 'manifest'
4164
4409
  });
4165
4410
  case 2:
4166
- _yield$_this6$hooks$l = _context8.v;
4167
- remoteSnapshotRes = _yield$_this6$hooks$l.remoteSnapshot;
4168
- return _context8.a(2, remoteSnapshotRes);
4411
+ _yield$_this7$hooks$l = _context0.v;
4412
+ remoteSnapshotRes = _yield$_this7$hooks$l.remoteSnapshot;
4413
+ return _context0.a(2, remoteSnapshotRes);
4169
4414
  }
4170
- }, _callee8);
4415
+ }, _callee0);
4171
4416
  }));
4172
4417
  return function asyncLoadProcess() {
4173
- return _ref1.apply(this, arguments);
4418
+ return _ref11.apply(this, arguments);
4174
4419
  };
4175
4420
  }();
4176
4421
  if (!this.manifestLoading[manifestUrl]) {
@@ -4178,11 +4423,11 @@ var SnapshotHandler = /*#__PURE__*/function () {
4178
4423
  return res;
4179
4424
  });
4180
4425
  }
4181
- return _context9.a(2, this.manifestLoading[manifestUrl]);
4426
+ return _context1.a(2, this.manifestLoading[manifestUrl]);
4182
4427
  }
4183
- }, _callee9, this);
4428
+ }, _callee1, this);
4184
4429
  }));
4185
- function getManifestJson(_x12, _x13, _x14) {
4430
+ function getManifestJson(_x14, _x15, _x16) {
4186
4431
  return _getManifestJson.apply(this, arguments);
4187
4432
  }
4188
4433
  return getManifestJson;
@@ -4193,6 +4438,7 @@ var SharedHandler = /*#__PURE__*/function () {
4193
4438
  function SharedHandler(host) {
4194
4439
  _classCallCheck(this, SharedHandler);
4195
4440
  this.hooks = new PluginSystem({
4441
+ beforeRegisterShare: new SyncWaterfallHook('beforeRegisterShare'),
4196
4442
  afterResolve: new AsyncWaterfallHook('afterResolve'),
4197
4443
  beforeLoadShare: new AsyncWaterfallHook('beforeLoadShare'),
4198
4444
  // not used yet
@@ -4210,19 +4456,24 @@ var SharedHandler = /*#__PURE__*/function () {
4210
4456
  return _createClass(SharedHandler, [{
4211
4457
  key: "registerShared",
4212
4458
  value: function registerShared(globalOptions, userOptions) {
4213
- var _this7 = this;
4459
+ var _this8 = this;
4214
4460
  var _formatShareConfigs = formatShareConfigs(globalOptions, userOptions),
4215
- shareInfos = _formatShareConfigs.shareInfos,
4216
- shared = _formatShareConfigs.shared;
4217
- var sharedKeys = Object.keys(shareInfos);
4461
+ newShareInfos = _formatShareConfigs.newShareInfos,
4462
+ allShareInfos = _formatShareConfigs.allShareInfos;
4463
+ var sharedKeys = Object.keys(newShareInfos);
4218
4464
  sharedKeys.forEach(function (sharedKey) {
4219
- var sharedVals = shareInfos[sharedKey];
4465
+ var sharedVals = newShareInfos[sharedKey];
4220
4466
  sharedVals.forEach(function (sharedVal) {
4221
4467
  sharedVal.scope.forEach(function (sc) {
4222
- var _this7$shareScopeMap$;
4223
- var registeredShared = (_this7$shareScopeMap$ = _this7.shareScopeMap[sc]) === null || _this7$shareScopeMap$ === void 0 ? void 0 : _this7$shareScopeMap$[sharedKey];
4468
+ var _this8$shareScopeMap$;
4469
+ _this8.hooks.lifecycle.beforeRegisterShare.emit({
4470
+ origin: _this8.host,
4471
+ pkgName: sharedKey,
4472
+ shared: sharedVal
4473
+ });
4474
+ var registeredShared = (_this8$shareScopeMap$ = _this8.shareScopeMap[sc]) === null || _this8$shareScopeMap$ === void 0 ? void 0 : _this8$shareScopeMap$[sharedKey];
4224
4475
  if (!registeredShared) {
4225
- _this7.setShared({
4476
+ _this8.setShared({
4226
4477
  pkgName: sharedKey,
4227
4478
  lib: sharedVal.lib,
4228
4479
  get: sharedVal.get,
@@ -4235,18 +4486,18 @@ var SharedHandler = /*#__PURE__*/function () {
4235
4486
  });
4236
4487
  });
4237
4488
  return {
4238
- shareInfos: shareInfos,
4239
- shared: shared
4489
+ newShareInfos: newShareInfos,
4490
+ allShareInfos: allShareInfos
4240
4491
  };
4241
4492
  }
4242
4493
  }, {
4243
4494
  key: "loadShare",
4244
4495
  value: function () {
4245
- var _loadShare = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee11(pkgName, extraOptions) {
4246
- var _this8 = this;
4247
- var host, shareOptions, loadShareRes, shareOptionsRes, registeredShared, addUseIn, factory, asyncLoadProcess, loading, _asyncLoadProcess, _loading;
4248
- return _regenerator().w(function (_context11) {
4249
- while (1) switch (_context11.n) {
4496
+ var _loadShare = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee13(pkgName, extraOptions) {
4497
+ var _this9 = this;
4498
+ var host, shareOptions, loadShareRes, shareOptionsRes, _ref13, registeredShared, useTreesShaking, targetShared, factory, asyncLoadProcess, loading, _useTreeShaking, _targetShared, _asyncLoadProcess, _loading;
4499
+ return _regenerator().w(function (_context13) {
4500
+ while (1) switch (_context13.n) {
4250
4501
  case 0:
4251
4502
  host = this.host; // This function performs the following steps:
4252
4503
  // 1. Checks if the currently loaded share already exists, if not, it throws an error
@@ -4258,30 +4509,30 @@ var SharedHandler = /*#__PURE__*/function () {
4258
4509
  shareInfos: host.options.shared
4259
4510
  });
4260
4511
  if (!(shareOptions !== null && shareOptions !== void 0 && shareOptions.scope)) {
4261
- _context11.n = 1;
4512
+ _context13.n = 1;
4262
4513
  break;
4263
4514
  }
4264
- _context11.n = 1;
4515
+ _context13.n = 1;
4265
4516
  return Promise.all(shareOptions.scope.map(/*#__PURE__*/function () {
4266
- var _ref10 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(shareScope) {
4267
- return _regenerator().w(function (_context0) {
4268
- while (1) switch (_context0.n) {
4517
+ var _ref12 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10(shareScope) {
4518
+ return _regenerator().w(function (_context10) {
4519
+ while (1) switch (_context10.n) {
4269
4520
  case 0:
4270
- _context0.n = 1;
4271
- return Promise.all(_this8.initializeSharing(shareScope, {
4521
+ _context10.n = 1;
4522
+ return Promise.all(_this9.initializeSharing(shareScope, {
4272
4523
  strategy: shareOptions.strategy
4273
4524
  }));
4274
4525
  case 1:
4275
- return _context0.a(2);
4526
+ return _context10.a(2);
4276
4527
  }
4277
- }, _callee0);
4528
+ }, _callee10);
4278
4529
  }));
4279
- return function (_x17) {
4280
- return _ref10.apply(this, arguments);
4530
+ return function (_x19) {
4531
+ return _ref12.apply(this, arguments);
4281
4532
  };
4282
4533
  }()));
4283
4534
  case 1:
4284
- _context11.n = 2;
4535
+ _context13.n = 2;
4285
4536
  return this.hooks.lifecycle.beforeLoadShare.emit({
4286
4537
  pkgName: pkgName,
4287
4538
  shareInfo: shareOptions,
@@ -4289,62 +4540,56 @@ var SharedHandler = /*#__PURE__*/function () {
4289
4540
  origin: host
4290
4541
  });
4291
4542
  case 2:
4292
- loadShareRes = _context11.v;
4543
+ loadShareRes = _context13.v;
4293
4544
  shareOptionsRes = loadShareRes.shareInfo; // Assert that shareInfoRes exists, if not, throw an error
4294
4545
  assert(shareOptionsRes, "Cannot find ".concat(pkgName, " Share in the ").concat(host.options.name, ". Please ensure that the ").concat(pkgName, " Share parameters have been injected"));
4295
- // Retrieve from cache
4296
- registeredShared = getRegisteredShare(this.shareScopeMap, pkgName, shareOptionsRes, this.hooks.lifecycle.resolveShare);
4297
- addUseIn = function addUseIn(shared) {
4298
- if (!shared.useIn) {
4299
- shared.useIn = [];
4300
- }
4301
- addUniqueItem(shared.useIn, host.options.name);
4302
- };
4303
- if (!(registeredShared && registeredShared.lib)) {
4304
- _context11.n = 3;
4546
+ _ref13 = getRegisteredShare(this.shareScopeMap, pkgName, shareOptionsRes, this.hooks.lifecycle.resolveShare) || {}, registeredShared = _ref13.shared, useTreesShaking = _ref13.useTreesShaking;
4547
+ if (!registeredShared) {
4548
+ _context13.n = 7;
4305
4549
  break;
4306
4550
  }
4307
- addUseIn(registeredShared);
4308
- return _context11.a(2, registeredShared.lib);
4551
+ targetShared = directShare(registeredShared, useTreesShaking);
4552
+ if (!targetShared.lib) {
4553
+ _context13.n = 3;
4554
+ break;
4555
+ }
4556
+ addUseIn(targetShared, host.options.name);
4557
+ return _context13.a(2, targetShared.lib);
4309
4558
  case 3:
4310
- if (!(registeredShared && registeredShared.loading && !registeredShared.loaded)) {
4311
- _context11.n = 5;
4559
+ if (!(targetShared.loading && !targetShared.loaded)) {
4560
+ _context13.n = 5;
4312
4561
  break;
4313
4562
  }
4314
- _context11.n = 4;
4315
- return registeredShared.loading;
4563
+ _context13.n = 4;
4564
+ return targetShared.loading;
4316
4565
  case 4:
4317
- factory = _context11.v;
4318
- registeredShared.loaded = true;
4319
- if (!registeredShared.lib) {
4320
- registeredShared.lib = factory;
4566
+ factory = _context13.v;
4567
+ targetShared.loaded = true;
4568
+ if (!targetShared.lib) {
4569
+ targetShared.lib = factory;
4321
4570
  }
4322
- addUseIn(registeredShared);
4323
- return _context11.a(2, factory);
4571
+ addUseIn(targetShared, host.options.name);
4572
+ return _context13.a(2, factory);
4324
4573
  case 5:
4325
- if (!registeredShared) {
4326
- _context11.n = 6;
4327
- break;
4328
- }
4329
4574
  asyncLoadProcess = /*#__PURE__*/function () {
4330
- var _ref11 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1() {
4575
+ var _ref14 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee11() {
4331
4576
  var factory;
4332
- return _regenerator().w(function (_context1) {
4333
- while (1) switch (_context1.n) {
4577
+ return _regenerator().w(function (_context11) {
4578
+ while (1) switch (_context11.n) {
4334
4579
  case 0:
4335
- _context1.n = 1;
4336
- return registeredShared.get();
4580
+ _context11.n = 1;
4581
+ return targetShared.get();
4337
4582
  case 1:
4338
- factory = _context1.v;
4339
- addUseIn(registeredShared);
4340
- registeredShared.loaded = true;
4341
- registeredShared.lib = factory;
4342
- return _context1.a(2, factory);
4583
+ factory = _context11.v;
4584
+ addUseIn(targetShared, host.options.name);
4585
+ targetShared.loaded = true;
4586
+ targetShared.lib = factory;
4587
+ return _context11.a(2, factory);
4343
4588
  }
4344
- }, _callee1);
4589
+ }, _callee11);
4345
4590
  }));
4346
4591
  return function asyncLoadProcess() {
4347
- return _ref11.apply(this, arguments);
4592
+ return _ref14.apply(this, arguments);
4348
4593
  };
4349
4594
  }();
4350
4595
  loading = asyncLoadProcess();
@@ -4354,41 +4599,48 @@ var SharedHandler = /*#__PURE__*/function () {
4354
4599
  shared: registeredShared,
4355
4600
  from: host.options.name,
4356
4601
  lib: null,
4357
- loading: loading
4602
+ loading: loading,
4603
+ treeShaking: useTreesShaking ? targetShared : undefined
4358
4604
  });
4359
- return _context11.a(2, loading);
4605
+ return _context13.a(2, loading);
4360
4606
  case 6:
4607
+ _context13.n = 9;
4608
+ break;
4609
+ case 7:
4361
4610
  if (!(extraOptions !== null && extraOptions !== void 0 && extraOptions.customShareInfo)) {
4362
- _context11.n = 7;
4611
+ _context13.n = 8;
4363
4612
  break;
4364
4613
  }
4365
- return _context11.a(2, false);
4366
- case 7:
4614
+ return _context13.a(2, false);
4615
+ case 8:
4616
+ _useTreeShaking = shouldUseTreeShaking(shareOptionsRes.treeShaking);
4617
+ _targetShared = directShare(shareOptionsRes, _useTreeShaking);
4367
4618
  _asyncLoadProcess = /*#__PURE__*/function () {
4368
- var _ref12 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10() {
4369
- var factory, gShared;
4370
- return _regenerator().w(function (_context10) {
4371
- while (1) switch (_context10.n) {
4619
+ var _ref15 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee12() {
4620
+ var factory, _ref16, gShared, gUseTreeShaking, targetGShared;
4621
+ return _regenerator().w(function (_context12) {
4622
+ while (1) switch (_context12.n) {
4372
4623
  case 0:
4373
- _context10.n = 1;
4374
- return shareOptionsRes.get();
4624
+ _context12.n = 1;
4625
+ return _targetShared.get();
4375
4626
  case 1:
4376
- factory = _context10.v;
4377
- shareOptionsRes.lib = factory;
4378
- shareOptionsRes.loaded = true;
4379
- addUseIn(shareOptionsRes);
4380
- gShared = getRegisteredShare(_this8.shareScopeMap, pkgName, shareOptionsRes, _this8.hooks.lifecycle.resolveShare);
4627
+ factory = _context12.v;
4628
+ _targetShared.lib = factory;
4629
+ _targetShared.loaded = true;
4630
+ addUseIn(_targetShared, host.options.name);
4631
+ _ref16 = getRegisteredShare(_this9.shareScopeMap, pkgName, shareOptionsRes, _this9.hooks.lifecycle.resolveShare) || {}, gShared = _ref16.shared, gUseTreeShaking = _ref16.useTreesShaking;
4381
4632
  if (gShared) {
4382
- gShared.lib = factory;
4383
- gShared.loaded = true;
4633
+ targetGShared = directShare(gShared, gUseTreeShaking);
4634
+ targetGShared.lib = factory;
4635
+ targetGShared.loaded = true;
4384
4636
  gShared.from = shareOptionsRes.from;
4385
4637
  }
4386
- return _context10.a(2, factory);
4638
+ return _context12.a(2, factory);
4387
4639
  }
4388
- }, _callee10);
4640
+ }, _callee12);
4389
4641
  }));
4390
4642
  return function _asyncLoadProcess() {
4391
- return _ref12.apply(this, arguments);
4643
+ return _ref15.apply(this, arguments);
4392
4644
  };
4393
4645
  }();
4394
4646
  _loading = _asyncLoadProcess();
@@ -4398,15 +4650,16 @@ var SharedHandler = /*#__PURE__*/function () {
4398
4650
  shared: shareOptionsRes,
4399
4651
  from: host.options.name,
4400
4652
  lib: null,
4401
- loading: _loading
4653
+ loading: _loading,
4654
+ treeShaking: _useTreeShaking ? _targetShared : undefined
4402
4655
  });
4403
- return _context11.a(2, _loading);
4404
- case 8:
4405
- return _context11.a(2);
4656
+ return _context13.a(2, _loading);
4657
+ case 9:
4658
+ return _context13.a(2);
4406
4659
  }
4407
- }, _callee11, this);
4660
+ }, _callee13, this);
4408
4661
  }));
4409
- function loadShare(_x15, _x16) {
4662
+ function loadShare(_x17, _x18) {
4410
4663
  return _loadShare.apply(this, arguments);
4411
4664
  }
4412
4665
  return loadShare;
@@ -4451,43 +4704,37 @@ var SharedHandler = /*#__PURE__*/function () {
4451
4704
  eager = shared.eager;
4452
4705
  scope[name] = scope[name] || {};
4453
4706
  var versions = scope[name];
4454
- var activeVersion = versions[version];
4455
- var activeVersionEager = Boolean(activeVersion && (activeVersion.eager || ((_activeVersion$shareC = activeVersion.shareConfig) === null || _activeVersion$shareC === void 0 ? void 0 : _activeVersion$shareC.eager)));
4456
- if (!activeVersion || activeVersion.strategy !== 'loaded-first' && !activeVersion.loaded && (Boolean(!eager) !== !activeVersionEager ? eager : hostName > activeVersion.from)) {
4707
+ var activeVersion = versions[version] && directShare(versions[version]);
4708
+ var activeVersionEager = Boolean(activeVersion && ('eager' in activeVersion && activeVersion.eager || 'shareConfig' in activeVersion && ((_activeVersion$shareC = activeVersion.shareConfig) === null || _activeVersion$shareC === void 0 ? void 0 : _activeVersion$shareC.eager)));
4709
+ if (!activeVersion || activeVersion.strategy !== 'loaded-first' && !activeVersion.loaded && (Boolean(!eager) !== !activeVersionEager ? eager : hostName > versions[version].from)) {
4457
4710
  versions[version] = shared;
4458
4711
  }
4459
4712
  };
4460
- var initFn = function initFn(mod) {
4461
- return mod && mod.init && mod.init(shareScope[shareScopeName], initScope);
4462
- };
4463
4713
  var initRemoteModule = /*#__PURE__*/function () {
4464
- var _ref13 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee12(key) {
4465
- var _yield$host$remoteHan, module, remoteEntryExports, _t2;
4466
- return _regenerator().w(function (_context12) {
4467
- while (1) switch (_context12.p = _context12.n) {
4714
+ var _ref17 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee14(key) {
4715
+ var _yield$host$remoteHan, module, remoteEntryExports, _remoteEntryExports, _t2;
4716
+ return _regenerator().w(function (_context14) {
4717
+ while (1) switch (_context14.p = _context14.n) {
4468
4718
  case 0:
4469
- _context12.n = 1;
4719
+ _context14.n = 1;
4470
4720
  return host.remoteHandler.getRemoteModuleAndOptions({
4471
4721
  id: key
4472
4722
  });
4473
4723
  case 1:
4474
- _yield$host$remoteHan = _context12.v;
4724
+ _yield$host$remoteHan = _context14.v;
4475
4725
  module = _yield$host$remoteHan.module;
4476
- if (!module.getEntry) {
4477
- _context12.n = 8;
4478
- break;
4479
- }
4480
- _context12.p = 2;
4481
- _context12.n = 3;
4726
+ remoteEntryExports = undefined;
4727
+ _context14.p = 2;
4728
+ _context14.n = 3;
4482
4729
  return module.getEntry();
4483
4730
  case 3:
4484
- remoteEntryExports = _context12.v;
4485
- _context12.n = 6;
4731
+ remoteEntryExports = _context14.v;
4732
+ _context14.n = 6;
4486
4733
  break;
4487
4734
  case 4:
4488
- _context12.p = 4;
4489
- _t2 = _context12.v;
4490
- _context12.n = 5;
4735
+ _context14.p = 4;
4736
+ _t2 = _context14.v;
4737
+ _context14.n = 5;
4491
4738
  return host.remoteHandler.hooks.lifecycle.errorLoadRemote.emit({
4492
4739
  id: key,
4493
4740
  error: _t2,
@@ -4496,23 +4743,25 @@ var SharedHandler = /*#__PURE__*/function () {
4496
4743
  origin: host
4497
4744
  });
4498
4745
  case 5:
4499
- remoteEntryExports = _context12.v;
4746
+ remoteEntryExports = _context14.v;
4500
4747
  case 6:
4501
- if (module.inited) {
4502
- _context12.n = 8;
4748
+ _context14.p = 6;
4749
+ if (!((_remoteEntryExports = remoteEntryExports) !== null && _remoteEntryExports !== void 0 && _remoteEntryExports.init)) {
4750
+ _context14.n = 7;
4503
4751
  break;
4504
4752
  }
4505
- _context12.n = 7;
4506
- return initFn(remoteEntryExports);
4753
+ module.remoteEntryExports = remoteEntryExports;
4754
+ _context14.n = 7;
4755
+ return module.init();
4507
4756
  case 7:
4508
- module.inited = true;
4757
+ return _context14.f(6);
4509
4758
  case 8:
4510
- return _context12.a(2);
4759
+ return _context14.a(2);
4511
4760
  }
4512
- }, _callee12, null, [[2, 4]]);
4761
+ }, _callee14, null, [[2, 4, 6, 8]]);
4513
4762
  }));
4514
- return function initRemoteModule(_x18) {
4515
- return _ref13.apply(this, arguments);
4763
+ return function initRemoteModule(_x20) {
4764
+ return _ref17.apply(this, arguments);
4516
4765
  };
4517
4766
  }();
4518
4767
  Object.keys(host.options.shared).forEach(function (shareName) {
@@ -4540,7 +4789,7 @@ var SharedHandler = /*#__PURE__*/function () {
4540
4789
  }, {
4541
4790
  key: "loadShareSync",
4542
4791
  value: function loadShareSync(pkgName, extraOptions) {
4543
- var _this9 = this;
4792
+ var _this0 = this;
4544
4793
  var host = this.host;
4545
4794
  var shareOptions = getTargetSharedOptions({
4546
4795
  pkgName: pkgName,
@@ -4549,21 +4798,17 @@ var SharedHandler = /*#__PURE__*/function () {
4549
4798
  });
4550
4799
  if (shareOptions !== null && shareOptions !== void 0 && shareOptions.scope) {
4551
4800
  shareOptions.scope.forEach(function (shareScope) {
4552
- _this9.initializeSharing(shareScope, {
4801
+ _this0.initializeSharing(shareScope, {
4553
4802
  strategy: shareOptions.strategy
4554
4803
  });
4555
4804
  });
4556
4805
  }
4557
- var registeredShared = getRegisteredShare(this.shareScopeMap, pkgName, shareOptions, this.hooks.lifecycle.resolveShare);
4558
- var addUseIn = function addUseIn(shared) {
4559
- if (!shared.useIn) {
4560
- shared.useIn = [];
4561
- }
4562
- addUniqueItem(shared.useIn, host.options.name);
4563
- };
4806
+ var _ref18 = getRegisteredShare(this.shareScopeMap, pkgName, shareOptions, this.hooks.lifecycle.resolveShare) || {},
4807
+ registeredShared = _ref18.shared;
4808
+ _ref18.useTreesShaking;
4564
4809
  if (registeredShared) {
4565
4810
  if (typeof registeredShared.lib === 'function') {
4566
- addUseIn(registeredShared);
4811
+ addUseIn(registeredShared, host.options.name);
4567
4812
  if (!registeredShared.loaded) {
4568
4813
  registeredShared.loaded = true;
4569
4814
  if (registeredShared.from === host.options.name) {
@@ -4575,7 +4820,7 @@ var SharedHandler = /*#__PURE__*/function () {
4575
4820
  if (typeof registeredShared.get === 'function') {
4576
4821
  var module = registeredShared.get();
4577
4822
  if (!(module instanceof Promise)) {
4578
- addUseIn(registeredShared);
4823
+ addUseIn(registeredShared, host.options.name);
4579
4824
  this.setShared({
4580
4825
  pkgName: pkgName,
4581
4826
  loaded: true,
@@ -4633,48 +4878,49 @@ var SharedHandler = /*#__PURE__*/function () {
4633
4878
  }
4634
4879
  }, {
4635
4880
  key: "setShared",
4636
- value: function setShared(_ref14) {
4637
- var _this0 = this;
4638
- var pkgName = _ref14.pkgName,
4639
- shared = _ref14.shared,
4640
- from = _ref14.from,
4641
- lib = _ref14.lib,
4642
- loading = _ref14.loading,
4643
- loaded = _ref14.loaded,
4644
- get = _ref14.get;
4881
+ value: function setShared(_ref19) {
4882
+ var _this1 = this;
4883
+ var pkgName = _ref19.pkgName,
4884
+ shared = _ref19.shared,
4885
+ from = _ref19.from,
4886
+ lib = _ref19.lib,
4887
+ loading = _ref19.loading,
4888
+ loaded = _ref19.loaded,
4889
+ get = _ref19.get,
4890
+ treeShaking = _ref19.treeShaking;
4645
4891
  var version = shared.version,
4646
4892
  _shared$scope = shared.scope,
4647
4893
  scope = _shared$scope === void 0 ? 'default' : _shared$scope,
4648
4894
  shareInfo = _objectWithoutProperties(shared, _excluded2);
4649
4895
  var scopes = Array.isArray(scope) ? scope : [scope];
4896
+ var mergeAttrs = function mergeAttrs(shared) {
4897
+ var merge = function merge(s, key, val) {
4898
+ if (val && !s[key]) {
4899
+ s[key] = val;
4900
+ }
4901
+ };
4902
+ var targetShared = treeShaking ? shared.treeShaking : shared;
4903
+ merge(targetShared, 'loaded', loaded);
4904
+ merge(targetShared, 'loading', loading);
4905
+ merge(targetShared, 'get', get);
4906
+ };
4650
4907
  scopes.forEach(function (sc) {
4651
- if (!_this0.shareScopeMap[sc]) {
4652
- _this0.shareScopeMap[sc] = {};
4908
+ if (!_this1.shareScopeMap[sc]) {
4909
+ _this1.shareScopeMap[sc] = {};
4653
4910
  }
4654
- if (!_this0.shareScopeMap[sc][pkgName]) {
4655
- _this0.shareScopeMap[sc][pkgName] = {};
4911
+ if (!_this1.shareScopeMap[sc][pkgName]) {
4912
+ _this1.shareScopeMap[sc][pkgName] = {};
4656
4913
  }
4657
- if (!_this0.shareScopeMap[sc][pkgName][version]) {
4658
- _this0.shareScopeMap[sc][pkgName][version] = _objectSpread2(_objectSpread2({
4914
+ if (!_this1.shareScopeMap[sc][pkgName][version]) {
4915
+ _this1.shareScopeMap[sc][pkgName][version] = _objectSpread2(_objectSpread2({
4659
4916
  version: version,
4660
4917
  scope: [sc]
4661
4918
  }, shareInfo), {}, {
4662
- lib: lib,
4663
- loaded: loaded,
4664
- loading: loading
4919
+ lib: lib
4665
4920
  });
4666
- if (get) {
4667
- _this0.shareScopeMap[sc][pkgName][version].get = get;
4668
- }
4669
- return;
4670
- }
4671
- var registeredShared = _this0.shareScopeMap[sc][pkgName][version];
4672
- if (loading && !registeredShared.loading) {
4673
- registeredShared.loading = loading;
4674
- }
4675
- if (loaded && !registeredShared.loaded) {
4676
- registeredShared.loaded = loaded;
4677
4921
  }
4922
+ var registeredShared = _this1.shareScopeMap[sc][pkgName][version];
4923
+ mergeAttrs(registeredShared);
4678
4924
  if (from && registeredShared.from !== from) {
4679
4925
  registeredShared.from = from;
4680
4926
  }
@@ -4705,6 +4951,7 @@ var RemoteHandler = /*#__PURE__*/function () {
4705
4951
  generatePreloadAssets: new AsyncHook('generatePreloadAssets'),
4706
4952
  // not used yet
4707
4953
  afterPreloadRemote: new AsyncHook(),
4954
+ // TODO: Move to loaderHook
4708
4955
  loadEntry: new AsyncHook()
4709
4956
  });
4710
4957
  this.host = host;
@@ -4713,10 +4960,10 @@ var RemoteHandler = /*#__PURE__*/function () {
4713
4960
  return _createClass(RemoteHandler, [{
4714
4961
  key: "formatAndRegisterRemote",
4715
4962
  value: function formatAndRegisterRemote(globalOptions, userOptions) {
4716
- var _this1 = this;
4963
+ var _this10 = this;
4717
4964
  var userRemotes = userOptions.remotes || [];
4718
4965
  return userRemotes.reduce(function (res, remote) {
4719
- _this1.registerRemote(remote, res, {
4966
+ _this10.registerRemote(remote, res, {
4720
4967
  force: false
4721
4968
  });
4722
4969
  return res;
@@ -4754,37 +5001,37 @@ var RemoteHandler = /*#__PURE__*/function () {
4754
5001
  }, {
4755
5002
  key: "loadRemote",
4756
5003
  value: function () {
4757
- var _loadRemote = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee13(id, options) {
4758
- var host, _ref15, _ref15$loadFactory, loadFactory, _yield$this$getRemote, module, moduleOptions, remoteMatchInfo, pkgNameOrAlias, remote, expose, idRes, remoteSnapshot, moduleOrFactory, moduleWrapper, _ref16, _ref16$from, from, failOver, _t3;
4759
- return _regenerator().w(function (_context13) {
4760
- while (1) switch (_context13.p = _context13.n) {
5004
+ var _loadRemote = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee15(id, options) {
5005
+ var host, _ref20, _ref20$loadFactory, loadFactory, _yield$this$getRemote, module, moduleOptions, remoteMatchInfo, pkgNameOrAlias, remote, expose, idRes, remoteSnapshot, moduleOrFactory, moduleWrapper, _ref21, _ref21$from, from, failOver, _t3;
5006
+ return _regenerator().w(function (_context15) {
5007
+ while (1) switch (_context15.p = _context15.n) {
4761
5008
  case 0:
4762
5009
  host = this.host;
4763
- _context13.p = 1;
4764
- _ref15 = options || {
5010
+ _context15.p = 1;
5011
+ _ref20 = options || {
4765
5012
  loadFactory: true
4766
- }, _ref15$loadFactory = _ref15.loadFactory, loadFactory = _ref15$loadFactory === void 0 ? true : _ref15$loadFactory; // 1. Validate the parameters of the retrieved module. There are two module request methods: pkgName + expose and alias + expose.
5013
+ }, _ref20$loadFactory = _ref20.loadFactory, loadFactory = _ref20$loadFactory === void 0 ? true : _ref20$loadFactory; // 1. Validate the parameters of the retrieved module. There are two module request methods: pkgName + expose and alias + expose.
4767
5014
  // 2. Request the snapshot information of the current host and globally store the obtained snapshot information. The retrieved module information is partially offline and partially online. The online module information will retrieve the modules used online.
4768
5015
  // 3. Retrieve the detailed information of the current module from global (remoteEntry address, expose resource address)
4769
5016
  // 4. After retrieving remoteEntry, call the init of the module, and then retrieve the exported content of the module through get
4770
5017
  // id: pkgName(@federation/app1) + expose(button) = @federation/app1/button
4771
5018
  // id: alias(app1) + expose(button) = app1/button
4772
5019
  // id: alias(app1/utils) + expose(loadash/sort) = app1/utils/loadash/sort
4773
- _context13.n = 2;
5020
+ _context15.n = 2;
4774
5021
  return this.getRemoteModuleAndOptions({
4775
5022
  id: id
4776
5023
  });
4777
5024
  case 2:
4778
- _yield$this$getRemote = _context13.v;
5025
+ _yield$this$getRemote = _context15.v;
4779
5026
  module = _yield$this$getRemote.module;
4780
5027
  moduleOptions = _yield$this$getRemote.moduleOptions;
4781
5028
  remoteMatchInfo = _yield$this$getRemote.remoteMatchInfo;
4782
5029
  pkgNameOrAlias = remoteMatchInfo.pkgNameOrAlias, remote = remoteMatchInfo.remote, expose = remoteMatchInfo.expose, idRes = remoteMatchInfo.id, remoteSnapshot = remoteMatchInfo.remoteSnapshot;
4783
- _context13.n = 3;
5030
+ _context15.n = 3;
4784
5031
  return module.get(idRes, expose, options, remoteSnapshot);
4785
5032
  case 3:
4786
- moduleOrFactory = _context13.v;
4787
- _context13.n = 4;
5033
+ moduleOrFactory = _context15.v;
5034
+ _context15.n = 4;
4788
5035
  return this.hooks.lifecycle.onLoad.emit({
4789
5036
  id: idRes,
4790
5037
  pkgNameOrAlias: pkgNameOrAlias,
@@ -4797,22 +5044,22 @@ var RemoteHandler = /*#__PURE__*/function () {
4797
5044
  origin: host
4798
5045
  });
4799
5046
  case 4:
4800
- moduleWrapper = _context13.v;
5047
+ moduleWrapper = _context15.v;
4801
5048
  this.setIdToRemoteMap(id, remoteMatchInfo);
4802
5049
  if (!(typeof moduleWrapper === 'function')) {
4803
- _context13.n = 5;
5050
+ _context15.n = 5;
4804
5051
  break;
4805
5052
  }
4806
- return _context13.a(2, moduleWrapper);
5053
+ return _context15.a(2, moduleWrapper);
4807
5054
  case 5:
4808
- return _context13.a(2, moduleOrFactory);
5055
+ return _context15.a(2, moduleOrFactory);
4809
5056
  case 6:
4810
- _context13.p = 6;
4811
- _t3 = _context13.v;
4812
- _ref16 = options || {
5057
+ _context15.p = 6;
5058
+ _t3 = _context15.v;
5059
+ _ref21 = options || {
4813
5060
  from: 'runtime'
4814
- }, _ref16$from = _ref16.from, from = _ref16$from === void 0 ? 'runtime' : _ref16$from;
4815
- _context13.n = 7;
5061
+ }, _ref21$from = _ref21.from, from = _ref21$from === void 0 ? 'runtime' : _ref21$from;
5062
+ _context15.n = 7;
4816
5063
  return this.hooks.lifecycle.errorLoadRemote.emit({
4817
5064
  id: id,
4818
5065
  error: _t3,
@@ -4821,18 +5068,18 @@ var RemoteHandler = /*#__PURE__*/function () {
4821
5068
  origin: host
4822
5069
  });
4823
5070
  case 7:
4824
- failOver = _context13.v;
5071
+ failOver = _context15.v;
4825
5072
  if (failOver) {
4826
- _context13.n = 8;
5073
+ _context15.n = 8;
4827
5074
  break;
4828
5075
  }
4829
5076
  throw _t3;
4830
5077
  case 8:
4831
- return _context13.a(2, failOver);
5078
+ return _context15.a(2, failOver);
4832
5079
  }
4833
- }, _callee13, this, [[1, 6]]);
5080
+ }, _callee15, this, [[1, 6]]);
4834
5081
  }));
4835
- function loadRemote(_x19, _x20) {
5082
+ function loadRemote(_x21, _x22) {
4836
5083
  return _loadRemote.apply(this, arguments);
4837
5084
  }
4838
5085
  return loadRemote;
@@ -4840,14 +5087,14 @@ var RemoteHandler = /*#__PURE__*/function () {
4840
5087
  }, {
4841
5088
  key: "preloadRemote",
4842
5089
  value: function () {
4843
- var _preloadRemote = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee15(preloadOptions) {
4844
- var _this10 = this;
5090
+ var _preloadRemote = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee17(preloadOptions) {
5091
+ var _this11 = this;
4845
5092
  var host, preloadOps;
4846
- return _regenerator().w(function (_context15) {
4847
- while (1) switch (_context15.n) {
5093
+ return _regenerator().w(function (_context17) {
5094
+ while (1) switch (_context17.n) {
4848
5095
  case 0:
4849
5096
  host = this.host;
4850
- _context15.n = 1;
5097
+ _context17.n = 1;
4851
5098
  return this.hooks.lifecycle.beforePreloadRemote.emit({
4852
5099
  preloadOps: preloadOptions,
4853
5100
  options: host.options,
@@ -4855,25 +5102,25 @@ var RemoteHandler = /*#__PURE__*/function () {
4855
5102
  });
4856
5103
  case 1:
4857
5104
  preloadOps = formatPreloadArgs(host.options.remotes, preloadOptions);
4858
- _context15.n = 2;
5105
+ _context17.n = 2;
4859
5106
  return Promise.all(preloadOps.map(/*#__PURE__*/function () {
4860
- var _ref17 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee14(ops) {
5107
+ var _ref22 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee16(ops) {
4861
5108
  var remote, remoteInfo, _yield$host$snapshotH, globalSnapshot, remoteSnapshot, assets;
4862
- return _regenerator().w(function (_context14) {
4863
- while (1) switch (_context14.n) {
5109
+ return _regenerator().w(function (_context16) {
5110
+ while (1) switch (_context16.n) {
4864
5111
  case 0:
4865
5112
  remote = ops.remote;
4866
5113
  remoteInfo = getRemoteInfo(remote);
4867
- _context14.n = 1;
5114
+ _context16.n = 1;
4868
5115
  return host.snapshotHandler.loadRemoteSnapshotInfo({
4869
5116
  moduleInfo: remote
4870
5117
  });
4871
5118
  case 1:
4872
- _yield$host$snapshotH = _context14.v;
5119
+ _yield$host$snapshotH = _context16.v;
4873
5120
  globalSnapshot = _yield$host$snapshotH.globalSnapshot;
4874
5121
  remoteSnapshot = _yield$host$snapshotH.remoteSnapshot;
4875
- _context14.n = 2;
4876
- return _this10.hooks.lifecycle.generatePreloadAssets.emit({
5122
+ _context16.n = 2;
5123
+ return _this11.hooks.lifecycle.generatePreloadAssets.emit({
4877
5124
  origin: host,
4878
5125
  preloadOptions: ops,
4879
5126
  remote: remote,
@@ -4882,29 +5129,29 @@ var RemoteHandler = /*#__PURE__*/function () {
4882
5129
  remoteSnapshot: remoteSnapshot
4883
5130
  });
4884
5131
  case 2:
4885
- assets = _context14.v;
5132
+ assets = _context16.v;
4886
5133
  if (assets) {
4887
- _context14.n = 3;
5134
+ _context16.n = 3;
4888
5135
  break;
4889
5136
  }
4890
- return _context14.a(2);
5137
+ return _context16.a(2);
4891
5138
  case 3:
4892
5139
  preloadAssets(remoteInfo, host, assets);
4893
5140
  case 4:
4894
- return _context14.a(2);
5141
+ return _context16.a(2);
4895
5142
  }
4896
- }, _callee14);
5143
+ }, _callee16);
4897
5144
  }));
4898
- return function (_x22) {
4899
- return _ref17.apply(this, arguments);
5145
+ return function (_x24) {
5146
+ return _ref22.apply(this, arguments);
4900
5147
  };
4901
5148
  }()));
4902
5149
  case 2:
4903
- return _context15.a(2);
5150
+ return _context17.a(2);
4904
5151
  }
4905
- }, _callee15, this);
5152
+ }, _callee17, this);
4906
5153
  }));
4907
- function preloadRemote(_x21) {
5154
+ function preloadRemote(_x23) {
4908
5155
  return _preloadRemote.apply(this, arguments);
4909
5156
  }
4910
5157
  return preloadRemote;
@@ -4912,10 +5159,10 @@ var RemoteHandler = /*#__PURE__*/function () {
4912
5159
  }, {
4913
5160
  key: "registerRemotes",
4914
5161
  value: function registerRemotes(remotes, options) {
4915
- var _this11 = this;
5162
+ var _this12 = this;
4916
5163
  var host = this.host;
4917
5164
  remotes.forEach(function (remote) {
4918
- _this11.registerRemote(remote, host.options.remotes, {
5165
+ _this12.registerRemote(remote, host.options.remotes, {
4919
5166
  force: options === null || options === void 0 ? void 0 : options.force
4920
5167
  });
4921
5168
  });
@@ -4923,28 +5170,28 @@ var RemoteHandler = /*#__PURE__*/function () {
4923
5170
  }, {
4924
5171
  key: "getRemoteModuleAndOptions",
4925
5172
  value: function () {
4926
- var _getRemoteModuleAndOptions = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee16(options) {
5173
+ var _getRemoteModuleAndOptions = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee18(options) {
4927
5174
  var host, id, loadRemoteArgs, _loadRemoteArgs, idRes, remoteSplitInfo, rawRemote, remoteInfo, matchInfo, remote, expose, module, moduleOptions, _t4;
4928
- return _regenerator().w(function (_context16) {
4929
- while (1) switch (_context16.p = _context16.n) {
5175
+ return _regenerator().w(function (_context18) {
5176
+ while (1) switch (_context18.p = _context18.n) {
4930
5177
  case 0:
4931
5178
  host = this.host;
4932
5179
  id = options.id;
4933
- _context16.p = 1;
4934
- _context16.n = 2;
5180
+ _context18.p = 1;
5181
+ _context18.n = 2;
4935
5182
  return this.hooks.lifecycle.beforeRequest.emit({
4936
5183
  id: id,
4937
5184
  options: host.options,
4938
5185
  origin: host
4939
5186
  });
4940
5187
  case 2:
4941
- loadRemoteArgs = _context16.v;
4942
- _context16.n = 5;
5188
+ loadRemoteArgs = _context18.v;
5189
+ _context18.n = 5;
4943
5190
  break;
4944
5191
  case 3:
4945
- _context16.p = 3;
4946
- _t4 = _context16.v;
4947
- _context16.n = 4;
5192
+ _context18.p = 3;
5193
+ _t4 = _context18.v;
5194
+ _context18.n = 4;
4948
5195
  return this.hooks.lifecycle.errorLoadRemote.emit({
4949
5196
  id: id,
4950
5197
  options: host.options,
@@ -4954,9 +5201,9 @@ var RemoteHandler = /*#__PURE__*/function () {
4954
5201
  lifecycle: 'beforeRequest'
4955
5202
  });
4956
5203
  case 4:
4957
- loadRemoteArgs = _context16.v;
5204
+ loadRemoteArgs = _context18.v;
4958
5205
  if (loadRemoteArgs) {
4959
- _context16.n = 5;
5206
+ _context18.n = 5;
4960
5207
  break;
4961
5208
  }
4962
5209
  throw _t4;
@@ -4969,7 +5216,7 @@ var RemoteHandler = /*#__PURE__*/function () {
4969
5216
  }));
4970
5217
  rawRemote = remoteSplitInfo.remote;
4971
5218
  remoteInfo = getRemoteInfo(rawRemote);
4972
- _context16.n = 6;
5219
+ _context18.n = 6;
4973
5220
  return host.sharedHandler.hooks.lifecycle.afterResolve.emit(_objectSpread2(_objectSpread2({
4974
5221
  id: idRes
4975
5222
  }, remoteSplitInfo), {}, {
@@ -4978,7 +5225,7 @@ var RemoteHandler = /*#__PURE__*/function () {
4978
5225
  remoteInfo: remoteInfo
4979
5226
  }));
4980
5227
  case 6:
4981
- matchInfo = _context16.v;
5228
+ matchInfo = _context18.v;
4982
5229
  remote = matchInfo.remote, expose = matchInfo.expose;
4983
5230
  assert(remote && expose, "The 'beforeRequest' hook was executed, but it failed to return the correct 'remote' and 'expose' values while loading ".concat(idRes, "."));
4984
5231
  module = host.moduleCache.get(remote.name);
@@ -4990,15 +5237,15 @@ var RemoteHandler = /*#__PURE__*/function () {
4990
5237
  module = new Module(moduleOptions);
4991
5238
  host.moduleCache.set(remote.name, module);
4992
5239
  }
4993
- return _context16.a(2, {
5240
+ return _context18.a(2, {
4994
5241
  module: module,
4995
5242
  moduleOptions: moduleOptions,
4996
5243
  remoteMatchInfo: matchInfo
4997
5244
  });
4998
5245
  }
4999
- }, _callee16, this, [[1, 3]]);
5246
+ }, _callee18, this, [[1, 3]]);
5000
5247
  }));
5001
- function getRemoteModuleAndOptions(_x23) {
5248
+ function getRemoteModuleAndOptions(_x25) {
5002
5249
  return _getRemoteModuleAndOptions.apply(this, arguments);
5003
5250
  }
5004
5251
  return getRemoteModuleAndOptions;
@@ -5063,15 +5310,15 @@ var RemoteHandler = /*#__PURE__*/function () {
5063
5310
  key: "removeRemote",
5064
5311
  value: function removeRemote(remote) {
5065
5312
  try {
5066
- var _host = this.host;
5313
+ var host = this.host;
5067
5314
  var name = remote.name;
5068
- var remoteIndex = _host.options.remotes.findIndex(function (item) {
5315
+ var remoteIndex = host.options.remotes.findIndex(function (item) {
5069
5316
  return item.name === name;
5070
5317
  });
5071
5318
  if (remoteIndex !== -1) {
5072
- _host.options.remotes.splice(remoteIndex, 1);
5319
+ host.options.remotes.splice(remoteIndex, 1);
5073
5320
  }
5074
- var loadedModule = _host.moduleCache.get(remote.name);
5321
+ var loadedModule = host.moduleCache.get(remote.name);
5075
5322
  if (loadedModule) {
5076
5323
  var remoteInfo = loadedModule.remoteInfo;
5077
5324
  var key = remoteInfo.entryGlobalName;
@@ -5088,7 +5335,7 @@ var RemoteHandler = /*#__PURE__*/function () {
5088
5335
  if (globalLoading[remoteEntryUniqueKey]) {
5089
5336
  delete globalLoading[remoteEntryUniqueKey];
5090
5337
  }
5091
- _host.snapshotHandler.manifestCache["delete"](remoteInfo.entry);
5338
+ host.snapshotHandler.manifestCache["delete"](remoteInfo.entry);
5092
5339
  // delete unloaded shared and instance
5093
5340
  var remoteInsId = remoteInfo.buildVersion ? composeKeyWithSeparator(remoteInfo.name, remoteInfo.buildVersion) : remoteInfo.name;
5094
5341
  var remoteInsIndex = CurrentGlobal.__FEDERATION__.__INSTANCES__.findIndex(function (ins) {
@@ -5134,18 +5381,18 @@ var RemoteHandler = /*#__PURE__*/function () {
5134
5381
  remoteIns.shareScopeMap = {};
5135
5382
  delete globalShareScopeMap[remoteInsId];
5136
5383
  }
5137
- needDeleteKeys.forEach(function (_ref18) {
5384
+ needDeleteKeys.forEach(function (_ref23) {
5138
5385
  var _globalShareScopeMap$;
5139
- var _ref19 = _slicedToArray(_ref18, 4),
5140
- insId = _ref19[0],
5141
- shareScope = _ref19[1],
5142
- shareName = _ref19[2],
5143
- shareVersion = _ref19[3];
5386
+ var _ref24 = _slicedToArray(_ref23, 4),
5387
+ insId = _ref24[0],
5388
+ shareScope = _ref24[1],
5389
+ shareName = _ref24[2],
5390
+ shareVersion = _ref24[3];
5144
5391
  (_globalShareScopeMap$ = globalShareScopeMap[insId]) === null || _globalShareScopeMap$ === void 0 || (_globalShareScopeMap$ = _globalShareScopeMap$[shareScope]) === null || _globalShareScopeMap$ === void 0 || (_globalShareScopeMap$ = _globalShareScopeMap$[shareName]) === null || _globalShareScopeMap$ === void 0 || delete _globalShareScopeMap$[shareVersion];
5145
5392
  });
5146
5393
  CurrentGlobal.__FEDERATION__.__INSTANCES__.splice(remoteInsIndex, 1);
5147
5394
  }
5148
- var _getGlobalRemoteInfo2 = _getGlobalRemoteInfo(remote, _host),
5395
+ var _getGlobalRemoteInfo2 = _getGlobalRemoteInfo(remote, host),
5149
5396
  hostGlobalSnapshot = _getGlobalRemoteInfo2.hostGlobalSnapshot;
5150
5397
  if (hostGlobalSnapshot) {
5151
5398
  var remoteKey = hostGlobalSnapshot && 'remotesInfo' in hostGlobalSnapshot && hostGlobalSnapshot.remotesInfo && getInfoWithoutType(hostGlobalSnapshot.remotesInfo, remote.name).key;
@@ -5158,7 +5405,7 @@ var RemoteHandler = /*#__PURE__*/function () {
5158
5405
  }
5159
5406
  }
5160
5407
  }
5161
- _host.moduleCache["delete"](remote.name);
5408
+ host.moduleCache["delete"](remote.name);
5162
5409
  }
5163
5410
  } catch (err) {
5164
5411
  logger.log('removeRemote fail: ', err);
@@ -5178,7 +5425,7 @@ var ModuleFederation = /*#__PURE__*/function () {
5178
5425
  // maybe will change, temporarily for internal use only
5179
5426
  initContainer: new AsyncWaterfallHook('initContainer')
5180
5427
  });
5181
- this.version = "0.21.6";
5428
+ this.version = "2.0.1";
5182
5429
  this.moduleCache = new Map();
5183
5430
  this.loaderHook = new PluginSystem({
5184
5431
  // FIXME: may not be suitable , not open to the public yet
@@ -5226,15 +5473,15 @@ var ModuleFederation = /*#__PURE__*/function () {
5226
5473
  }, {
5227
5474
  key: "loadShare",
5228
5475
  value: function () {
5229
- var _loadShare2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee17(pkgName, extraOptions) {
5230
- return _regenerator().w(function (_context17) {
5231
- while (1) switch (_context17.n) {
5476
+ var _loadShare2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee19(pkgName, extraOptions) {
5477
+ return _regenerator().w(function (_context19) {
5478
+ while (1) switch (_context19.n) {
5232
5479
  case 0:
5233
- return _context17.a(2, this.sharedHandler.loadShare(pkgName, extraOptions));
5480
+ return _context19.a(2, this.sharedHandler.loadShare(pkgName, extraOptions));
5234
5481
  }
5235
- }, _callee17, this);
5482
+ }, _callee19, this);
5236
5483
  }));
5237
- function loadShare(_x24, _x25) {
5484
+ function loadShare(_x26, _x27) {
5238
5485
  return _loadShare2.apply(this, arguments);
5239
5486
  }
5240
5487
  return loadShare;
@@ -5274,15 +5521,15 @@ var ModuleFederation = /*#__PURE__*/function () {
5274
5521
  }, {
5275
5522
  key: "loadRemote",
5276
5523
  value: function () {
5277
- var _loadRemote2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee18(id, options) {
5278
- return _regenerator().w(function (_context18) {
5279
- while (1) switch (_context18.n) {
5524
+ var _loadRemote2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee20(id, options) {
5525
+ return _regenerator().w(function (_context20) {
5526
+ while (1) switch (_context20.n) {
5280
5527
  case 0:
5281
- return _context18.a(2, this.remoteHandler.loadRemote(id, options));
5528
+ return _context20.a(2, this.remoteHandler.loadRemote(id, options));
5282
5529
  }
5283
- }, _callee18, this);
5530
+ }, _callee20, this);
5284
5531
  }));
5285
- function loadRemote(_x26, _x27) {
5532
+ function loadRemote(_x28, _x29) {
5286
5533
  return _loadRemote2.apply(this, arguments);
5287
5534
  }
5288
5535
  return loadRemote;
@@ -5290,15 +5537,15 @@ var ModuleFederation = /*#__PURE__*/function () {
5290
5537
  }, {
5291
5538
  key: "preloadRemote",
5292
5539
  value: function () {
5293
- var _preloadRemote2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee19(preloadOptions) {
5294
- return _regenerator().w(function (_context19) {
5295
- while (1) switch (_context19.n) {
5540
+ var _preloadRemote2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee21(preloadOptions) {
5541
+ return _regenerator().w(function (_context21) {
5542
+ while (1) switch (_context21.n) {
5296
5543
  case 0:
5297
- return _context19.a(2, this.remoteHandler.preloadRemote(preloadOptions));
5544
+ return _context21.a(2, this.remoteHandler.preloadRemote(preloadOptions));
5298
5545
  }
5299
- }, _callee19, this);
5546
+ }, _callee21, this);
5300
5547
  }));
5301
- function preloadRemote(_x28) {
5548
+ function preloadRemote(_x30) {
5302
5549
  return _preloadRemote2.apply(this, arguments);
5303
5550
  }
5304
5551
  return preloadRemote;
@@ -5313,7 +5560,7 @@ var ModuleFederation = /*#__PURE__*/function () {
5313
5560
  key: "formatOptions",
5314
5561
  value: function formatOptions(globalOptions, userOptions) {
5315
5562
  var _formatShareConfigs2 = formatShareConfigs(globalOptions, userOptions),
5316
- shared = _formatShareConfigs2.shared;
5563
+ shared = _formatShareConfigs2.allShareInfos;
5317
5564
  var _this$hooks$lifecycle = this.hooks.lifecycle.beforeInit.emit({
5318
5565
  origin: this,
5319
5566
  userOptions: userOptions,
@@ -5324,7 +5571,7 @@ var ModuleFederation = /*#__PURE__*/function () {
5324
5571
  globalOptionsRes = _this$hooks$lifecycle.options;
5325
5572
  var remotes = this.remoteHandler.formatAndRegisterRemote(globalOptionsRes, userOptionsRes);
5326
5573
  var _this$sharedHandler$r = this.sharedHandler.registerShared(globalOptionsRes, userOptionsRes),
5327
- handledShared = _this$sharedHandler$r.shared;
5574
+ allShareInfos = _this$sharedHandler$r.allShareInfos;
5328
5575
  var plugins = _toConsumableArray(globalOptionsRes.plugins);
5329
5576
  if (userOptionsRes.plugins) {
5330
5577
  userOptionsRes.plugins.forEach(function (plugin) {
@@ -5336,7 +5583,7 @@ var ModuleFederation = /*#__PURE__*/function () {
5336
5583
  var optionsRes = _objectSpread2(_objectSpread2(_objectSpread2({}, globalOptions), userOptions), {}, {
5337
5584
  plugins: plugins,
5338
5585
  remotes: remotes,
5339
- shared: handledShared
5586
+ shared: allShareInfos
5340
5587
  });
5341
5588
  this.hooks.lifecycle.init.emit({
5342
5589
  origin: this,
@@ -5418,10 +5665,6 @@ function useActionEffect(params, deps, isExtReady = true) {
5418
5665
  if (isReady) {
5419
5666
  fetchRemoteOrigin();
5420
5667
  }
5421
- else {
5422
- // Set remote origin to local
5423
- setRemoteOrigin(window.location.origin);
5424
- }
5425
5668
  }, [isReady]);
5426
5669
  // Flush queued commands when isExtReady becomes true
5427
5670
  useEffect(() => {
@@ -5460,17 +5703,33 @@ function useActionEffect(params, deps, isExtReady = true) {
5460
5703
  };
5461
5704
  }
5462
5705
  async function updateAction() {
5463
- if (!remoteOrigin) {
5464
- console.error("Remote origin is not set yet");
5465
- throw new Error("Remote origin is not set yet");
5466
- }
5467
5706
  // Register or update action.
5468
5707
  // This will only pass signature info to the editor.
5469
5708
  // The actual handler is stored in this hook,
5470
5709
  // so the execution happens inside the extension app.
5471
5710
  const { appId, version, actionInfo } = await getActionInfo(params.actionName);
5472
- // Setup handler
5473
- const func = await loadAppAction(actionInfo.name, appId, remoteOrigin, version);
5711
+ let func;
5712
+ if (remoteOrigin) {
5713
+ // Production: load handler from Module Federation remote
5714
+ const loadedFunc = await loadAppActionFromMF(actionInfo.name, appId, remoteOrigin, version);
5715
+ if (!loadedFunc) {
5716
+ console.error(`Failed to load action handler for ${actionInfo.name}`);
5717
+ throw new Error(`Failed to load action handler for ${actionInfo.name}`);
5718
+ }
5719
+ func = loadedFunc;
5720
+ }
5721
+ else {
5722
+ // Preview mode: no MF server, call the skill endpoint via fetch
5723
+ const origin = window.location.origin;
5724
+ func = async (args) => {
5725
+ const response = await fetch(`${origin}/skill/${actionInfo.name}`, {
5726
+ method: "POST",
5727
+ headers: { "Content-Type": "application/json" },
5728
+ body: JSON.stringify(args),
5729
+ });
5730
+ return response.json();
5731
+ };
5732
+ }
5474
5733
  setActionHandler(() => func);
5475
5734
  await imc?.sendMessage(IMCMessageTypeEnum.EditorRegisterAction, {
5476
5735
  name: actionInfo.name,
@@ -5481,7 +5740,7 @@ function useActionEffect(params, deps, isExtReady = true) {
5481
5740
  // Update receiver
5482
5741
  imc?.updateReceiverHandlerMap(getReceiverHandlerMap(func));
5483
5742
  }
5484
- if (isExtReady && remoteOrigin) {
5743
+ if (isExtReady) {
5485
5744
  updateAction();
5486
5745
  }
5487
5746
  }, [
@@ -5569,7 +5828,7 @@ function useActionEffect(params, deps, isExtReady = true) {
5569
5828
  ]);
5570
5829
  return receiverHandlerMap;
5571
5830
  }
5572
- async function loadAppAction(func, appId, remoteOrigin, version) {
5831
+ async function loadAppActionFromMF(func, appId, remoteOrigin, version) {
5573
5832
  // here we assign the return value of the init() function, which can be used to do some more complex
5574
5833
  // things with the module federation runtime
5575
5834
  const instance = createInstance({
@@ -5616,80 +5875,87 @@ function useTheme() {
5616
5875
  }
5617
5876
 
5618
5877
  function c(e, u, c, i) {
5619
- var a = this,
5620
- o = useRef(null),
5878
+ var l = this,
5879
+ a = useRef(null),
5880
+ o = useRef(0),
5621
5881
  f = useRef(0),
5622
- l = useRef(0),
5623
5882
  v = useRef(null),
5624
- m = useRef([]),
5625
- d = useRef(),
5626
- g = useRef(),
5627
- p = useRef(e),
5628
- w = useRef(true);
5629
- p.current = e;
5630
- var s = "undefined" != typeof window,
5631
- x = !u && 0 !== u && s;
5883
+ d = useRef([]),
5884
+ m = useRef(),
5885
+ s = useRef(),
5886
+ g = useRef(e),
5887
+ h = useRef(true),
5888
+ x = useRef(),
5889
+ E = useRef();
5890
+ g.current = e;
5891
+ var b = "undefined" != typeof window,
5892
+ p = !u && 0 !== u && b;
5632
5893
  if ("function" != typeof e) throw new TypeError("Expected a function");
5633
5894
  u = +u || 0;
5634
- var h = !!(c = c || {}).leading,
5635
- y = !("trailing" in c) || !!c.trailing,
5895
+ var y = !!(c = c || {}).leading,
5896
+ w = !("trailing" in c) || !!c.trailing,
5897
+ O = !!c.flushOnExit && w,
5636
5898
  F = "maxWait" in c,
5637
- A = "debounceOnServer" in c && !!c.debounceOnServer,
5638
- D = F ? Math.max(+c.maxWait || 0, u) : null;
5639
- useEffect(function () {
5640
- return w.current = true, function () {
5641
- w.current = false;
5642
- };
5643
- }, []);
5644
- var T = useMemo(function () {
5645
- var r = function r(_r) {
5646
- var n = m.current,
5647
- t = d.current;
5648
- return m.current = d.current = null, f.current = _r, l.current = l.current || _r, g.current = p.current.apply(t, n);
5649
- },
5650
- n = function n(r, _n) {
5651
- x && cancelAnimationFrame(v.current), v.current = x ? requestAnimationFrame(r) : setTimeout(r, _n);
5652
- },
5653
- t = function t(r) {
5654
- if (!w.current) return false;
5655
- var n = r - o.current;
5656
- return !o.current || n >= u || n < 0 || F && r - f.current >= D;
5657
- },
5658
- e = function e(n) {
5659
- return v.current = null, y && m.current ? r(n) : (m.current = d.current = null, g.current);
5660
- },
5661
- c = function r() {
5662
- var c = Date.now();
5663
- if (h && l.current === f.current && T(), t(c)) return e(c);
5664
- if (w.current) {
5665
- var i = u - (c - o.current),
5666
- a = F ? Math.min(i, D - (c - f.current)) : i;
5667
- n(r, a);
5668
- }
5669
- },
5670
- T = function T() {
5671
- },
5672
- W = function W() {
5673
- if (s || A) {
5674
- var e = Date.now(),
5675
- i = t(e);
5676
- if (m.current = [].slice.call(arguments), d.current = a, o.current = e, i) {
5677
- if (!v.current && w.current) return f.current = o.current, n(c, u), h ? r(o.current) : g.current;
5678
- if (F) return n(c, u), r(o.current);
5899
+ L = "debounceOnServer" in c && !!c.debounceOnServer,
5900
+ A = F ? Math.max(+c.maxWait || 0, u) : null,
5901
+ D = useMemo(function () {
5902
+ var r = function r(_r) {
5903
+ var n = d.current,
5904
+ t = m.current;
5905
+ return d.current = m.current = null, o.current = _r, f.current = f.current || _r, s.current = g.current.apply(t, n);
5906
+ },
5907
+ n = function n(r, _n) {
5908
+ p && cancelAnimationFrame(v.current), v.current = p ? requestAnimationFrame(r) : setTimeout(r, _n);
5909
+ },
5910
+ t = function t(r) {
5911
+ if (!h.current) return false;
5912
+ var n = r - a.current;
5913
+ return !a.current || n >= u || n < 0 || F && r - o.current >= A;
5914
+ },
5915
+ e = function e(n) {
5916
+ return v.current = null, w && d.current ? r(n) : (d.current = m.current = null, s.current);
5917
+ },
5918
+ c = function r() {
5919
+ var c = Date.now();
5920
+ if (y && f.current === o.current && D(), t(c)) return e(c);
5921
+ if (h.current) {
5922
+ var i = u - (c - a.current),
5923
+ l = F ? Math.min(i, A - (c - o.current)) : i;
5924
+ n(r, l);
5679
5925
  }
5680
- return v.current || n(c, u), g.current;
5681
- }
5682
- };
5683
- return W.cancel = function () {
5684
- var r = v.current;
5685
- r && (x ? cancelAnimationFrame(v.current) : clearTimeout(v.current)), f.current = 0, m.current = o.current = d.current = v.current = null;
5686
- }, W.isPending = function () {
5687
- return !!v.current;
5688
- }, W.flush = function () {
5689
- return v.current ? e(Date.now()) : g.current;
5690
- }, W;
5691
- }, [h, F, u, D, y, x, s, A, i]);
5692
- return T;
5926
+ },
5927
+ D = function D() {
5928
+ },
5929
+ S = function S() {
5930
+ if (b || L) {
5931
+ var e,
5932
+ i = Date.now(),
5933
+ f = t(i);
5934
+ if (d.current = [].slice.call(arguments), m.current = l, a.current = i, O && !x.current && (x.current = function () {
5935
+ var r;
5936
+ "hidden" === (null == (r = global.document) ? void 0 : r.visibilityState) && E.current.flush();
5937
+ }, null == (e = global.document) || null == e.addEventListener || e.addEventListener("visibilitychange", x.current)), f) {
5938
+ if (!v.current && h.current) return o.current = a.current, n(c, u), y ? r(a.current) : s.current;
5939
+ if (F) return n(c, u), r(a.current);
5940
+ }
5941
+ return v.current || n(c, u), s.current;
5942
+ }
5943
+ };
5944
+ return S.cancel = function () {
5945
+ var r = v.current;
5946
+ r && (p ? cancelAnimationFrame(v.current) : clearTimeout(v.current)), o.current = 0, d.current = a.current = m.current = v.current = null;
5947
+ }, S.isPending = function () {
5948
+ return !!v.current;
5949
+ }, S.flush = function () {
5950
+ return v.current ? e(Date.now()) : s.current;
5951
+ }, S;
5952
+ }, [y, F, u, A, w, O, p, b, L, i]);
5953
+ return E.current = D, useEffect(function () {
5954
+ return h.current = true, function () {
5955
+ var r;
5956
+ O && E.current.flush(), x.current && (null == (r = global.document) || null == r.removeEventListener || r.removeEventListener("visibilitychange", x.current), x.current = null), h.current = false;
5957
+ };
5958
+ }, [O]), D;
5693
5959
  }
5694
5960
 
5695
5961
  /**