@module-federation/runtime 0.0.0-next-20240412182228 → 0.0.0-next-20240415101817

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.
@@ -1,4 +1,4 @@
1
- import { l as getRegisteredShare, u as getGlobalShareScope, G as Global, H as nativeGlobal, I as resetFederationGlobalInfo, B as getGlobalFederationInstance, E as setGlobalFederationInstance, C as getGlobalFederationConstructor, A as setGlobalFederationConstructor, m as getInfoWithoutType, t as getGlobalSnapshot, J as getTargetSnapshotInfoByModuleInfo, p as getGlobalSnapshotInfoByModuleInfo, r as setGlobalSnapshotInfoByModuleInfo, q as addGlobalSnapshot, c as getRemoteEntryExports, F as registerGlobalPlugins, g as getGlobalHostPlugins, n as getPreloaded, o as setPreloaded } from './share.esm.js';
1
+ import { o as getRegisteredShare, v as getGlobalShareScope, G as Global, J as nativeGlobal, K as resetFederationGlobalInfo, E as getGlobalFederationInstance, H as setGlobalFederationInstance, F as getGlobalFederationConstructor, C as setGlobalFederationConstructor, l as getInfoWithoutType, u as getGlobalSnapshot, L as getTargetSnapshotInfoByModuleInfo, q as getGlobalSnapshotInfoByModuleInfo, t as setGlobalSnapshotInfoByModuleInfo, r as addGlobalSnapshot, c as getRemoteEntryExports, I as registerGlobalPlugins, g as getGlobalHostPlugins, m as getPreloaded, n as setPreloaded } from './share.esm.js';
2
2
 
3
3
  const ShareUtils = {
4
4
  getRegisteredShare,
package/dist/index.cjs.js CHANGED
@@ -86,6 +86,7 @@ function registerPlugins$1(plugins, hookInstances) {
86
86
  });
87
87
  });
88
88
  }
89
+ return plugins;
89
90
  }
90
91
 
91
92
  function _extends$5() {
@@ -813,23 +814,33 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
813
814
  }
814
815
  }, true, memo, remoteSnapshot);
815
816
  if (remoteSnapshot.shared) {
816
- remoteSnapshot.shared.forEach((shared)=>{
817
- var _options_shared;
818
- const shareInfo = (_options_shared = options.shared) == null ? void 0 : _options_shared[shared.sharedName];
819
- // When data is downgraded, the shared configuration may be different.
820
- if (!shareInfo) {
821
- return;
822
- }
823
- const registeredShared = share.getRegisteredShare(origin.shareScopeMap, shared.sharedName, shareInfo, origin.hooks.lifecycle.resolveShare);
817
+ const collectSharedAssets = (shareInfo, snapshotShared)=>{
818
+ const registeredShared = share.getRegisteredShare(origin.shareScopeMap, snapshotShared.sharedName, shareInfo, origin.hooks.lifecycle.resolveShare);
824
819
  // 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.
825
820
  if (registeredShared && typeof registeredShared.lib === 'function') {
826
- shared.assets.js.sync.forEach((asset)=>{
821
+ snapshotShared.assets.js.sync.forEach((asset)=>{
827
822
  loadedSharedJsAssets.add(asset);
828
823
  });
829
- shared.assets.css.sync.forEach((asset)=>{
824
+ snapshotShared.assets.css.sync.forEach((asset)=>{
830
825
  loadedSharedCssAssets.add(asset);
831
826
  });
832
827
  }
828
+ };
829
+ remoteSnapshot.shared.forEach((shared)=>{
830
+ var _options_shared;
831
+ const shareInfos = (_options_shared = options.shared) == null ? void 0 : _options_shared[shared.sharedName];
832
+ if (!shareInfos) {
833
+ return;
834
+ }
835
+ // if no version, preload all shared
836
+ const sharedOptions = shared.version ? shareInfos.find((s)=>s.version === shared.version) : shareInfos;
837
+ if (!sharedOptions) {
838
+ return;
839
+ }
840
+ const arrayShareInfo = share.arrayOptions(sharedOptions);
841
+ arrayShareInfo.forEach((s)=>{
842
+ collectSharedAssets(s, shared);
843
+ });
833
844
  });
834
845
  }
835
846
  const needPreloadJsAssets = jsAssets.filter((asset)=>!loadedSharedJsAssets.has(asset));
@@ -1114,13 +1125,16 @@ class FederationHost {
1114
1125
  this.options = options;
1115
1126
  return options;
1116
1127
  }
1117
- async loadShare(pkgName, customShareInfo) {
1118
- var _this_options_shared;
1128
+ async loadShare(pkgName, extraOptions) {
1119
1129
  // This function performs the following steps:
1120
1130
  // 1. Checks if the currently loaded share already exists, if not, it throws an error
1121
1131
  // 2. Searches globally for a matching share, if found, it uses it directly
1122
1132
  // 3. If not found, it retrieves it from the current share and stores the obtained share globally.
1123
- const shareInfo = Object.assign({}, (_this_options_shared = this.options.shared) == null ? void 0 : _this_options_shared[pkgName], customShareInfo);
1133
+ const shareInfo = share.getTargetSharedOptions({
1134
+ pkgName,
1135
+ extraOptions,
1136
+ shareInfos: this.options.shared
1137
+ });
1124
1138
  if (shareInfo == null ? void 0 : shareInfo.scope) {
1125
1139
  await Promise.all(shareInfo.scope.map(async (shareScope)=>{
1126
1140
  await Promise.all(this.initializeSharing(shareScope, shareInfo.strategy));
@@ -1179,7 +1193,7 @@ class FederationHost {
1179
1193
  });
1180
1194
  return loading;
1181
1195
  } else {
1182
- if (customShareInfo) {
1196
+ if (extraOptions == null ? void 0 : extraOptions.customShareInfo) {
1183
1197
  return false;
1184
1198
  }
1185
1199
  const asyncLoadProcess = async ()=>{
@@ -1210,9 +1224,12 @@ class FederationHost {
1210
1224
  // 1. If the loaded shared already exists globally, then it will be reused
1211
1225
  // 2. If lib exists in local shared, it will be used directly
1212
1226
  // 3. If the local get returns something other than Promise, then it will be used directly
1213
- loadShareSync(pkgName, customShareInfo) {
1214
- var _this_options_shared;
1215
- const shareInfo = Object.assign({}, (_this_options_shared = this.options.shared) == null ? void 0 : _this_options_shared[pkgName], customShareInfo);
1227
+ loadShareSync(pkgName, extraOptions) {
1228
+ const shareInfo = share.getTargetSharedOptions({
1229
+ pkgName,
1230
+ extraOptions,
1231
+ shareInfos: this.options.shared
1232
+ });
1216
1233
  if (shareInfo == null ? void 0 : shareInfo.scope) {
1217
1234
  shareInfo.scope.forEach((shareScope)=>{
1218
1235
  this.initializeSharing(shareScope, shareInfo.strategy);
@@ -1451,10 +1468,12 @@ class FederationHost {
1451
1468
  }
1452
1469
  };
1453
1470
  Object.keys(this.options.shared).forEach((shareName)=>{
1454
- const shared = this.options.shared[shareName];
1455
- if (shared.scope.includes(shareScopeName)) {
1456
- register(shareName, shared);
1457
- }
1471
+ const sharedArr = this.options.shared[shareName];
1472
+ sharedArr.forEach((shared)=>{
1473
+ if (shared.scope.includes(shareScopeName)) {
1474
+ register(shareName, shared);
1475
+ }
1476
+ });
1458
1477
  });
1459
1478
  if (strategy === 'version-first') {
1460
1479
  this.options.remotes.forEach((remote)=>{
@@ -1475,7 +1494,19 @@ class FederationHost {
1475
1494
  }
1476
1495
  formatOptions(globalOptions, userOptions) {
1477
1496
  const formatShareOptions = share.formatShareConfigs(userOptions.shared || {}, userOptions.name);
1478
- const shared = _extends({}, globalOptions.shared, formatShareOptions);
1497
+ const shared = _extends({}, globalOptions.shared);
1498
+ Object.keys(formatShareOptions).forEach((shareKey)=>{
1499
+ if (!shared[shareKey]) {
1500
+ shared[shareKey] = formatShareOptions[shareKey];
1501
+ } else {
1502
+ formatShareOptions[shareKey].forEach((newUserSharedOptions)=>{
1503
+ const isSameVersion = shared[shareKey].find((sharedVal)=>sharedVal.version === newUserSharedOptions.version);
1504
+ if (!isSameVersion) {
1505
+ shared[shareKey].push(newUserSharedOptions);
1506
+ }
1507
+ });
1508
+ }
1509
+ });
1479
1510
  const { userOptions: userOptionsRes, options: globalOptionsRes } = this.hooks.lifecycle.beforeInit.emit({
1480
1511
  origin: this,
1481
1512
  userOptions,
@@ -1492,18 +1523,20 @@ class FederationHost {
1492
1523
  // register shared in shareScopeMap
1493
1524
  const sharedKeys = Object.keys(formatShareOptions);
1494
1525
  sharedKeys.forEach((sharedKey)=>{
1495
- const sharedVal = formatShareOptions[sharedKey];
1496
- const registeredShared = share.getRegisteredShare(this.shareScopeMap, sharedKey, sharedVal, this.hooks.lifecycle.resolveShare);
1497
- if (!registeredShared && sharedVal && sharedVal.lib) {
1498
- this.setShared({
1499
- pkgName: sharedKey,
1500
- lib: sharedVal.lib,
1501
- get: sharedVal.get,
1502
- loaded: true,
1503
- shared: sharedVal,
1504
- from: userOptions.name
1505
- });
1506
- }
1526
+ const sharedVals = formatShareOptions[sharedKey];
1527
+ sharedVals.forEach((sharedVal)=>{
1528
+ const registeredShared = share.getRegisteredShare(this.shareScopeMap, sharedKey, sharedVal, this.hooks.lifecycle.resolveShare);
1529
+ if (!registeredShared && sharedVal && sharedVal.lib) {
1530
+ this.setShared({
1531
+ pkgName: sharedKey,
1532
+ lib: sharedVal.lib,
1533
+ get: sharedVal.get,
1534
+ loaded: true,
1535
+ shared: sharedVal,
1536
+ from: userOptions.name
1537
+ });
1538
+ }
1539
+ });
1507
1540
  });
1508
1541
  const plugins = [
1509
1542
  ...globalOptionsRes.plugins
@@ -1527,11 +1560,18 @@ class FederationHost {
1527
1560
  return optionsRes;
1528
1561
  }
1529
1562
  registerPlugins(plugins) {
1530
- registerPlugins$1(plugins, [
1563
+ const pluginRes = registerPlugins$1(plugins, [
1531
1564
  this.hooks,
1532
1565
  this.snapshotHandler.hooks,
1533
1566
  this.loaderHook
1534
1567
  ]);
1568
+ // Merge plugin
1569
+ this.options.plugins = this.options.plugins.reduce((res, plugin)=>{
1570
+ if (res && !res.find((item)=>item.name === plugin.name)) {
1571
+ res.push(plugin);
1572
+ }
1573
+ return res;
1574
+ }, pluginRes || []);
1535
1575
  }
1536
1576
  setShared({ pkgName, shared, from, lib, loading, loaded, get }) {
1537
1577
  const { version, scope = 'default' } = shared, shareInfo = _object_without_properties_loose(shared, [
@@ -1658,7 +1698,7 @@ class FederationHost {
1658
1698
  // not used yet
1659
1699
  afterPreloadRemote: new AsyncHook()
1660
1700
  });
1661
- this.version = "0.1.3";
1701
+ this.version = "0.1.5";
1662
1702
  this.moduleCache = new Map();
1663
1703
  this.loaderHook = new PluginSystem({
1664
1704
  // FIXME: may not be suitable , not open to the public yet
package/dist/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
- import { g as getGlobalHostPlugins, a as globalLoading, D as DEFAULT_REMOTE_TYPE, b as DEFAULT_SCOPE, c as getRemoteEntryExports, d as assert, s as safeToString, e as getFMId, i as isObject, f as error, w as warn, h as isPlainObject, j as isRemoteInfoWithEntry, k as isPureRemoteEntry, l as getRegisteredShare, m as getInfoWithoutType, n as getPreloaded, o as setPreloaded, p as getGlobalSnapshotInfoByModuleInfo, q as addGlobalSnapshot, r as setGlobalSnapshotInfoByModuleInfo, t as getGlobalSnapshot, G as Global, u as getGlobalShareScope, v as formatShareConfigs, x as getBuilderId, y as isBrowserEnv, z as addUniqueItem, A as setGlobalFederationConstructor, B as getGlobalFederationInstance, C as getGlobalFederationConstructor, E as setGlobalFederationInstance } from './share.esm.js';
2
- export { F as registerGlobalPlugins } from './share.esm.js';
1
+ import { g as getGlobalHostPlugins, a as globalLoading, D as DEFAULT_REMOTE_TYPE, b as DEFAULT_SCOPE, c as getRemoteEntryExports, d as assert, s as safeToString, e as getFMId, i as isObject, f as error, w as warn, h as isPlainObject, j as isRemoteInfoWithEntry, k as isPureRemoteEntry, l as getInfoWithoutType, m as getPreloaded, n as setPreloaded, o as getRegisteredShare, p as arrayOptions, q as getGlobalSnapshotInfoByModuleInfo, r as addGlobalSnapshot, t as setGlobalSnapshotInfoByModuleInfo, u as getGlobalSnapshot, G as Global, v as getGlobalShareScope, x as getTargetSharedOptions, y as formatShareConfigs, z as getBuilderId, A as isBrowserEnv, B as addUniqueItem, C as setGlobalFederationConstructor, E as getGlobalFederationInstance, F as getGlobalFederationConstructor, H as setGlobalFederationInstance } from './share.esm.js';
2
+ export { I as registerGlobalPlugins } from './share.esm.js';
3
3
  import { loadScriptNode, loadScript, composeKeyWithSeparator, createLink, getResourceUrl, isManifestProvider, generateSnapshotFromManifest } from '@module-federation/sdk';
4
4
  export { loadScript, loadScriptNode } from '@module-federation/sdk';
5
5
 
@@ -84,6 +84,7 @@ function registerPlugins$1(plugins, hookInstances) {
84
84
  });
85
85
  });
86
86
  }
87
+ return plugins;
87
88
  }
88
89
 
89
90
  function _extends$5() {
@@ -811,23 +812,33 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
811
812
  }
812
813
  }, true, memo, remoteSnapshot);
813
814
  if (remoteSnapshot.shared) {
814
- remoteSnapshot.shared.forEach((shared)=>{
815
- var _options_shared;
816
- const shareInfo = (_options_shared = options.shared) == null ? void 0 : _options_shared[shared.sharedName];
817
- // When data is downgraded, the shared configuration may be different.
818
- if (!shareInfo) {
819
- return;
820
- }
821
- const registeredShared = getRegisteredShare(origin.shareScopeMap, shared.sharedName, shareInfo, origin.hooks.lifecycle.resolveShare);
815
+ const collectSharedAssets = (shareInfo, snapshotShared)=>{
816
+ const registeredShared = getRegisteredShare(origin.shareScopeMap, snapshotShared.sharedName, shareInfo, origin.hooks.lifecycle.resolveShare);
822
817
  // 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.
823
818
  if (registeredShared && typeof registeredShared.lib === 'function') {
824
- shared.assets.js.sync.forEach((asset)=>{
819
+ snapshotShared.assets.js.sync.forEach((asset)=>{
825
820
  loadedSharedJsAssets.add(asset);
826
821
  });
827
- shared.assets.css.sync.forEach((asset)=>{
822
+ snapshotShared.assets.css.sync.forEach((asset)=>{
828
823
  loadedSharedCssAssets.add(asset);
829
824
  });
830
825
  }
826
+ };
827
+ remoteSnapshot.shared.forEach((shared)=>{
828
+ var _options_shared;
829
+ const shareInfos = (_options_shared = options.shared) == null ? void 0 : _options_shared[shared.sharedName];
830
+ if (!shareInfos) {
831
+ return;
832
+ }
833
+ // if no version, preload all shared
834
+ const sharedOptions = shared.version ? shareInfos.find((s)=>s.version === shared.version) : shareInfos;
835
+ if (!sharedOptions) {
836
+ return;
837
+ }
838
+ const arrayShareInfo = arrayOptions(sharedOptions);
839
+ arrayShareInfo.forEach((s)=>{
840
+ collectSharedAssets(s, shared);
841
+ });
831
842
  });
832
843
  }
833
844
  const needPreloadJsAssets = jsAssets.filter((asset)=>!loadedSharedJsAssets.has(asset));
@@ -1112,13 +1123,16 @@ class FederationHost {
1112
1123
  this.options = options;
1113
1124
  return options;
1114
1125
  }
1115
- async loadShare(pkgName, customShareInfo) {
1116
- var _this_options_shared;
1126
+ async loadShare(pkgName, extraOptions) {
1117
1127
  // This function performs the following steps:
1118
1128
  // 1. Checks if the currently loaded share already exists, if not, it throws an error
1119
1129
  // 2. Searches globally for a matching share, if found, it uses it directly
1120
1130
  // 3. If not found, it retrieves it from the current share and stores the obtained share globally.
1121
- const shareInfo = Object.assign({}, (_this_options_shared = this.options.shared) == null ? void 0 : _this_options_shared[pkgName], customShareInfo);
1131
+ const shareInfo = getTargetSharedOptions({
1132
+ pkgName,
1133
+ extraOptions,
1134
+ shareInfos: this.options.shared
1135
+ });
1122
1136
  if (shareInfo == null ? void 0 : shareInfo.scope) {
1123
1137
  await Promise.all(shareInfo.scope.map(async (shareScope)=>{
1124
1138
  await Promise.all(this.initializeSharing(shareScope, shareInfo.strategy));
@@ -1177,7 +1191,7 @@ class FederationHost {
1177
1191
  });
1178
1192
  return loading;
1179
1193
  } else {
1180
- if (customShareInfo) {
1194
+ if (extraOptions == null ? void 0 : extraOptions.customShareInfo) {
1181
1195
  return false;
1182
1196
  }
1183
1197
  const asyncLoadProcess = async ()=>{
@@ -1208,9 +1222,12 @@ class FederationHost {
1208
1222
  // 1. If the loaded shared already exists globally, then it will be reused
1209
1223
  // 2. If lib exists in local shared, it will be used directly
1210
1224
  // 3. If the local get returns something other than Promise, then it will be used directly
1211
- loadShareSync(pkgName, customShareInfo) {
1212
- var _this_options_shared;
1213
- const shareInfo = Object.assign({}, (_this_options_shared = this.options.shared) == null ? void 0 : _this_options_shared[pkgName], customShareInfo);
1225
+ loadShareSync(pkgName, extraOptions) {
1226
+ const shareInfo = getTargetSharedOptions({
1227
+ pkgName,
1228
+ extraOptions,
1229
+ shareInfos: this.options.shared
1230
+ });
1214
1231
  if (shareInfo == null ? void 0 : shareInfo.scope) {
1215
1232
  shareInfo.scope.forEach((shareScope)=>{
1216
1233
  this.initializeSharing(shareScope, shareInfo.strategy);
@@ -1449,10 +1466,12 @@ class FederationHost {
1449
1466
  }
1450
1467
  };
1451
1468
  Object.keys(this.options.shared).forEach((shareName)=>{
1452
- const shared = this.options.shared[shareName];
1453
- if (shared.scope.includes(shareScopeName)) {
1454
- register(shareName, shared);
1455
- }
1469
+ const sharedArr = this.options.shared[shareName];
1470
+ sharedArr.forEach((shared)=>{
1471
+ if (shared.scope.includes(shareScopeName)) {
1472
+ register(shareName, shared);
1473
+ }
1474
+ });
1456
1475
  });
1457
1476
  if (strategy === 'version-first') {
1458
1477
  this.options.remotes.forEach((remote)=>{
@@ -1473,7 +1492,19 @@ class FederationHost {
1473
1492
  }
1474
1493
  formatOptions(globalOptions, userOptions) {
1475
1494
  const formatShareOptions = formatShareConfigs(userOptions.shared || {}, userOptions.name);
1476
- const shared = _extends({}, globalOptions.shared, formatShareOptions);
1495
+ const shared = _extends({}, globalOptions.shared);
1496
+ Object.keys(formatShareOptions).forEach((shareKey)=>{
1497
+ if (!shared[shareKey]) {
1498
+ shared[shareKey] = formatShareOptions[shareKey];
1499
+ } else {
1500
+ formatShareOptions[shareKey].forEach((newUserSharedOptions)=>{
1501
+ const isSameVersion = shared[shareKey].find((sharedVal)=>sharedVal.version === newUserSharedOptions.version);
1502
+ if (!isSameVersion) {
1503
+ shared[shareKey].push(newUserSharedOptions);
1504
+ }
1505
+ });
1506
+ }
1507
+ });
1477
1508
  const { userOptions: userOptionsRes, options: globalOptionsRes } = this.hooks.lifecycle.beforeInit.emit({
1478
1509
  origin: this,
1479
1510
  userOptions,
@@ -1490,18 +1521,20 @@ class FederationHost {
1490
1521
  // register shared in shareScopeMap
1491
1522
  const sharedKeys = Object.keys(formatShareOptions);
1492
1523
  sharedKeys.forEach((sharedKey)=>{
1493
- const sharedVal = formatShareOptions[sharedKey];
1494
- const registeredShared = getRegisteredShare(this.shareScopeMap, sharedKey, sharedVal, this.hooks.lifecycle.resolveShare);
1495
- if (!registeredShared && sharedVal && sharedVal.lib) {
1496
- this.setShared({
1497
- pkgName: sharedKey,
1498
- lib: sharedVal.lib,
1499
- get: sharedVal.get,
1500
- loaded: true,
1501
- shared: sharedVal,
1502
- from: userOptions.name
1503
- });
1504
- }
1524
+ const sharedVals = formatShareOptions[sharedKey];
1525
+ sharedVals.forEach((sharedVal)=>{
1526
+ const registeredShared = getRegisteredShare(this.shareScopeMap, sharedKey, sharedVal, this.hooks.lifecycle.resolveShare);
1527
+ if (!registeredShared && sharedVal && sharedVal.lib) {
1528
+ this.setShared({
1529
+ pkgName: sharedKey,
1530
+ lib: sharedVal.lib,
1531
+ get: sharedVal.get,
1532
+ loaded: true,
1533
+ shared: sharedVal,
1534
+ from: userOptions.name
1535
+ });
1536
+ }
1537
+ });
1505
1538
  });
1506
1539
  const plugins = [
1507
1540
  ...globalOptionsRes.plugins
@@ -1525,11 +1558,18 @@ class FederationHost {
1525
1558
  return optionsRes;
1526
1559
  }
1527
1560
  registerPlugins(plugins) {
1528
- registerPlugins$1(plugins, [
1561
+ const pluginRes = registerPlugins$1(plugins, [
1529
1562
  this.hooks,
1530
1563
  this.snapshotHandler.hooks,
1531
1564
  this.loaderHook
1532
1565
  ]);
1566
+ // Merge plugin
1567
+ this.options.plugins = this.options.plugins.reduce((res, plugin)=>{
1568
+ if (res && !res.find((item)=>item.name === plugin.name)) {
1569
+ res.push(plugin);
1570
+ }
1571
+ return res;
1572
+ }, pluginRes || []);
1533
1573
  }
1534
1574
  setShared({ pkgName, shared, from, lib, loading, loaded, get }) {
1535
1575
  const { version, scope = 'default' } = shared, shareInfo = _object_without_properties_loose(shared, [
@@ -1656,7 +1696,7 @@ class FederationHost {
1656
1696
  // not used yet
1657
1697
  afterPreloadRemote: new AsyncHook()
1658
1698
  });
1659
- this.version = "0.1.3";
1699
+ this.version = "0.1.5";
1660
1700
  this.moduleCache = new Map();
1661
1701
  this.loaderHook = new PluginSystem({
1662
1702
  // FIXME: may not be suitable , not open to the public yet
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/runtime",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "author": "zhouxiao <codingzx@gmail.com>",
5
5
  "main": "./index.cjs.js",
6
6
  "module": "./index.esm.js",
package/dist/share.cjs.js CHANGED
@@ -71,6 +71,11 @@ const objectToString = Object.prototype.toString;
71
71
  function isPlainObject(val) {
72
72
  return objectToString.call(val) === '[object Object]';
73
73
  }
74
+ function arrayOptions(options) {
75
+ return Array.isArray(options) ? options : [
76
+ options
77
+ ];
78
+ }
74
79
 
75
80
  function _extends$1() {
76
81
  _extends$1 = Object.assign || function(target) {
@@ -185,7 +190,7 @@ function getGlobalFederationConstructor() {
185
190
  function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
186
191
  if (isDebug) {
187
192
  globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
188
- globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.1.3";
193
+ globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.1.5";
189
194
  }
190
195
  }
191
196
  // eslint-disable-next-line @typescript-eslint/ban-types
@@ -674,7 +679,11 @@ function formatShareConfigs(shareArgs, from) {
674
679
  return {};
675
680
  }
676
681
  return Object.keys(shareArgs).reduce((res, pkgName)=>{
677
- res[pkgName] = formatShare(shareArgs[pkgName], from);
682
+ const arrayShareArgs = arrayOptions(shareArgs[pkgName]);
683
+ res[pkgName] = res[pkgName] || [];
684
+ arrayShareArgs.forEach((shareConfig)=>{
685
+ res[pkgName].push(formatShare(shareConfig, from));
686
+ });
678
687
  return res;
679
688
  }, {});
680
689
  }
@@ -697,12 +706,11 @@ function versionLt(a, b) {
697
706
  return false;
698
707
  }
699
708
  }
700
- const findVersion = (shareScopeMap, scope, pkgName, cb)=>{
701
- const versions = shareScopeMap[scope][pkgName];
709
+ const findVersion = (shareVersionMap, cb)=>{
702
710
  const callback = cb || function(prev, cur) {
703
711
  return versionLt(prev, cur);
704
712
  };
705
- return Object.keys(versions).reduce((prev, cur)=>{
713
+ return Object.keys(shareVersionMap).reduce((prev, cur)=>{
706
714
  if (!prev) {
707
715
  return cur;
708
716
  }
@@ -724,7 +732,7 @@ function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) {
724
732
  const callback = function(prev, cur) {
725
733
  return !isLoaded(versions[prev]) && versionLt(prev, cur);
726
734
  };
727
- return findVersion(shareScopeMap, scope, pkgName, callback);
735
+ return findVersion(shareScopeMap[scope][pkgName], callback);
728
736
  }
729
737
  function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
730
738
  const versions = shareScopeMap[scope][pkgName];
@@ -741,7 +749,7 @@ function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
741
749
  }
742
750
  return versionLt(prev, cur);
743
751
  };
744
- return findVersion(shareScopeMap, scope, pkgName, callback);
752
+ return findVersion(shareScopeMap[scope][pkgName], callback);
745
753
  }
746
754
  function getFindShareFunction(strategy) {
747
755
  if (strategy === 'loaded-first') {
@@ -804,12 +812,33 @@ function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare
804
812
  function getGlobalShareScope() {
805
813
  return Global.__FEDERATION__.__SHARE__;
806
814
  }
815
+ function getTargetSharedOptions(options) {
816
+ const { pkgName, extraOptions, shareInfos } = options;
817
+ const defaultResolver = (sharedOptions)=>{
818
+ if (!sharedOptions) {
819
+ return undefined;
820
+ }
821
+ const shareVersionMap = {};
822
+ sharedOptions.forEach((shared)=>{
823
+ shareVersionMap[shared.version] = shared;
824
+ });
825
+ const callback = function(prev, cur) {
826
+ return !isLoaded(shareVersionMap[prev]) && versionLt(prev, cur);
827
+ };
828
+ const maxVersion = findVersion(shareVersionMap, callback);
829
+ return shareVersionMap[maxVersion];
830
+ };
831
+ var _extraOptions_resolver;
832
+ const resolver = (_extraOptions_resolver = extraOptions == null ? void 0 : extraOptions.resolver) != null ? _extraOptions_resolver : defaultResolver;
833
+ return Object.assign({}, resolver(shareInfos[pkgName]), extraOptions == null ? void 0 : extraOptions.customShareInfo);
834
+ }
807
835
 
808
836
  exports.DEFAULT_REMOTE_TYPE = DEFAULT_REMOTE_TYPE;
809
837
  exports.DEFAULT_SCOPE = DEFAULT_SCOPE;
810
838
  exports.Global = Global;
811
839
  exports.addGlobalSnapshot = addGlobalSnapshot;
812
840
  exports.addUniqueItem = addUniqueItem;
841
+ exports.arrayOptions = arrayOptions;
813
842
  exports.assert = assert;
814
843
  exports.error = error;
815
844
  exports.formatShareConfigs = formatShareConfigs;
@@ -825,6 +854,7 @@ exports.getInfoWithoutType = getInfoWithoutType;
825
854
  exports.getPreloaded = getPreloaded;
826
855
  exports.getRegisteredShare = getRegisteredShare;
827
856
  exports.getRemoteEntryExports = getRemoteEntryExports;
857
+ exports.getTargetSharedOptions = getTargetSharedOptions;
828
858
  exports.getTargetSnapshotInfoByModuleInfo = getTargetSnapshotInfoByModuleInfo;
829
859
  exports.globalLoading = globalLoading;
830
860
  exports.isBrowserEnv = isBrowserEnv;
package/dist/share.esm.js CHANGED
@@ -69,6 +69,11 @@ const objectToString = Object.prototype.toString;
69
69
  function isPlainObject(val) {
70
70
  return objectToString.call(val) === '[object Object]';
71
71
  }
72
+ function arrayOptions(options) {
73
+ return Array.isArray(options) ? options : [
74
+ options
75
+ ];
76
+ }
72
77
 
73
78
  function _extends$1() {
74
79
  _extends$1 = Object.assign || function(target) {
@@ -183,7 +188,7 @@ function getGlobalFederationConstructor() {
183
188
  function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
184
189
  if (isDebug) {
185
190
  globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
186
- globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.1.3";
191
+ globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.1.5";
187
192
  }
188
193
  }
189
194
  // eslint-disable-next-line @typescript-eslint/ban-types
@@ -672,7 +677,11 @@ function formatShareConfigs(shareArgs, from) {
672
677
  return {};
673
678
  }
674
679
  return Object.keys(shareArgs).reduce((res, pkgName)=>{
675
- res[pkgName] = formatShare(shareArgs[pkgName], from);
680
+ const arrayShareArgs = arrayOptions(shareArgs[pkgName]);
681
+ res[pkgName] = res[pkgName] || [];
682
+ arrayShareArgs.forEach((shareConfig)=>{
683
+ res[pkgName].push(formatShare(shareConfig, from));
684
+ });
676
685
  return res;
677
686
  }, {});
678
687
  }
@@ -695,12 +704,11 @@ function versionLt(a, b) {
695
704
  return false;
696
705
  }
697
706
  }
698
- const findVersion = (shareScopeMap, scope, pkgName, cb)=>{
699
- const versions = shareScopeMap[scope][pkgName];
707
+ const findVersion = (shareVersionMap, cb)=>{
700
708
  const callback = cb || function(prev, cur) {
701
709
  return versionLt(prev, cur);
702
710
  };
703
- return Object.keys(versions).reduce((prev, cur)=>{
711
+ return Object.keys(shareVersionMap).reduce((prev, cur)=>{
704
712
  if (!prev) {
705
713
  return cur;
706
714
  }
@@ -722,7 +730,7 @@ function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) {
722
730
  const callback = function(prev, cur) {
723
731
  return !isLoaded(versions[prev]) && versionLt(prev, cur);
724
732
  };
725
- return findVersion(shareScopeMap, scope, pkgName, callback);
733
+ return findVersion(shareScopeMap[scope][pkgName], callback);
726
734
  }
727
735
  function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
728
736
  const versions = shareScopeMap[scope][pkgName];
@@ -739,7 +747,7 @@ function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
739
747
  }
740
748
  return versionLt(prev, cur);
741
749
  };
742
- return findVersion(shareScopeMap, scope, pkgName, callback);
750
+ return findVersion(shareScopeMap[scope][pkgName], callback);
743
751
  }
744
752
  function getFindShareFunction(strategy) {
745
753
  if (strategy === 'loaded-first') {
@@ -802,5 +810,25 @@ function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare
802
810
  function getGlobalShareScope() {
803
811
  return Global.__FEDERATION__.__SHARE__;
804
812
  }
813
+ function getTargetSharedOptions(options) {
814
+ const { pkgName, extraOptions, shareInfos } = options;
815
+ const defaultResolver = (sharedOptions)=>{
816
+ if (!sharedOptions) {
817
+ return undefined;
818
+ }
819
+ const shareVersionMap = {};
820
+ sharedOptions.forEach((shared)=>{
821
+ shareVersionMap[shared.version] = shared;
822
+ });
823
+ const callback = function(prev, cur) {
824
+ return !isLoaded(shareVersionMap[prev]) && versionLt(prev, cur);
825
+ };
826
+ const maxVersion = findVersion(shareVersionMap, callback);
827
+ return shareVersionMap[maxVersion];
828
+ };
829
+ var _extraOptions_resolver;
830
+ const resolver = (_extraOptions_resolver = extraOptions == null ? void 0 : extraOptions.resolver) != null ? _extraOptions_resolver : defaultResolver;
831
+ return Object.assign({}, resolver(shareInfos[pkgName]), extraOptions == null ? void 0 : extraOptions.customShareInfo);
832
+ }
805
833
 
806
- export { setGlobalFederationConstructor as A, getGlobalFederationInstance as B, getGlobalFederationConstructor as C, DEFAULT_REMOTE_TYPE as D, setGlobalFederationInstance as E, registerGlobalPlugins as F, Global as G, nativeGlobal as H, resetFederationGlobalInfo as I, getTargetSnapshotInfoByModuleInfo as J, globalLoading as a, DEFAULT_SCOPE as b, getRemoteEntryExports as c, assert as d, getFMId as e, error as f, getGlobalHostPlugins as g, isPlainObject as h, isObject as i, isRemoteInfoWithEntry as j, isPureRemoteEntry as k, getRegisteredShare as l, getInfoWithoutType as m, getPreloaded as n, setPreloaded as o, getGlobalSnapshotInfoByModuleInfo as p, addGlobalSnapshot as q, setGlobalSnapshotInfoByModuleInfo as r, safeToString as s, getGlobalSnapshot as t, getGlobalShareScope as u, formatShareConfigs as v, warn as w, getBuilderId as x, isBrowserEnv as y, addUniqueItem as z };
834
+ export { isBrowserEnv as A, addUniqueItem as B, setGlobalFederationConstructor as C, DEFAULT_REMOTE_TYPE as D, getGlobalFederationInstance as E, getGlobalFederationConstructor as F, Global as G, setGlobalFederationInstance as H, registerGlobalPlugins as I, nativeGlobal as J, resetFederationGlobalInfo as K, getTargetSnapshotInfoByModuleInfo as L, globalLoading as a, DEFAULT_SCOPE as b, getRemoteEntryExports as c, assert as d, getFMId as e, error as f, getGlobalHostPlugins as g, isPlainObject as h, isObject as i, isRemoteInfoWithEntry as j, isPureRemoteEntry as k, getInfoWithoutType as l, getPreloaded as m, setPreloaded as n, getRegisteredShare as o, arrayOptions as p, getGlobalSnapshotInfoByModuleInfo as q, addGlobalSnapshot as r, safeToString as s, setGlobalSnapshotInfoByModuleInfo as t, getGlobalSnapshot as u, getGlobalShareScope as v, warn as w, getTargetSharedOptions as x, formatShareConfigs as y, getBuilderId as z };
@@ -136,8 +136,14 @@ export declare class FederationHost {
136
136
  constructor(userOptions: UserOptions);
137
137
  private _setGlobalShareScopeMap;
138
138
  initOptions(userOptions: UserOptions): Options;
139
- loadShare<T>(pkgName: string, customShareInfo?: Partial<Shared>): Promise<false | (() => T | undefined)>;
140
- loadShareSync<T>(pkgName: string, customShareInfo?: Partial<Shared>): () => T | never;
139
+ loadShare<T>(pkgName: string, extraOptions?: {
140
+ customShareInfo?: Partial<Shared>;
141
+ resolver?: (sharedOptions: ShareInfos[string]) => Shared;
142
+ }): Promise<false | (() => T | undefined)>;
143
+ loadShareSync<T>(pkgName: string, extraOptions?: {
144
+ customShareInfo?: Partial<Shared>;
145
+ resolver?: (sharedOptions: ShareInfos[string]) => Shared;
146
+ }): () => T | never;
141
147
  initRawContainer(name: string, url: string, container: RemoteEntryExports): Module;
142
148
  private _getRemoteModuleAndOptions;
143
149
  loadRemote<T>(id: string, options?: {