@module-federation/runtime 0.0.0-next-20240102063242 → 0.0.0-next-20240103032717

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/share.cjs.js CHANGED
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  function getBuilderId() {
4
- //@ts-ignore
5
4
  return typeof FEDERATION_BUILD_IDENTIFIER !== 'undefined' ? FEDERATION_BUILD_IDENTIFIER : '';
6
5
  }
7
6
  function isDebugMode() {
@@ -89,7 +88,7 @@ function _object_without_properties_loose(source, excluded) {
89
88
  }
90
89
  return target;
91
90
  }
92
- var _nativeGlobal___FEDERATION__, _nativeGlobal___FEDERATION__1, _nativeGlobal___FEDERATION__2, _nativeGlobal___FEDERATION__3, _nativeGlobal___FEDERATION__4, _nativeGlobal___FEDERATION__5;
91
+ var _nativeGlobal___FEDERATION__, _nativeGlobal___FEDERATION__1, _nativeGlobal___FEDERATION__2, _nativeGlobal___FEDERATION__3, _nativeGlobal___FEDERATION__4, _nativeGlobal___FEDERATION__5, _nativeGlobal___FEDERATION__6;
93
92
  // export const nativeGlobal: typeof global = new Function('return this')();
94
93
  const nativeGlobal = new Function('return this')();
95
94
  // This section is to prevent encapsulation by certain microfrontend frameworks. Due to reuse policies, sandbox escapes.
@@ -112,6 +111,7 @@ if (nativeGlobal.__VMOK__) {
112
111
  moduleInfo: {},
113
112
  __SHARE__: {},
114
113
  __MANIFEST_LOADING__: {},
114
+ __SHARE_SCOPE_LOADING__: {},
115
115
  __PRELOADED_MAP__: new Map()
116
116
  };
117
117
  nativeGlobal.__VMOK__ = nativeGlobal.__FEDERATION__;
@@ -126,8 +126,10 @@ var ___SHARE__;
126
126
  (___SHARE__ = (_nativeGlobal___FEDERATION__3 = nativeGlobal.__FEDERATION__).__SHARE__) != null ? ___SHARE__ : _nativeGlobal___FEDERATION__3.__SHARE__ = {};
127
127
  var ___MANIFEST_LOADING__;
128
128
  (___MANIFEST_LOADING__ = (_nativeGlobal___FEDERATION__4 = nativeGlobal.__FEDERATION__).__MANIFEST_LOADING__) != null ? ___MANIFEST_LOADING__ : _nativeGlobal___FEDERATION__4.__MANIFEST_LOADING__ = {};
129
+ var ___SHARE_SCOPE_LOADING__;
130
+ (___SHARE_SCOPE_LOADING__ = (_nativeGlobal___FEDERATION__5 = nativeGlobal.__FEDERATION__).__SHARE_SCOPE_LOADING__) != null ? ___SHARE_SCOPE_LOADING__ : _nativeGlobal___FEDERATION__5.__SHARE_SCOPE_LOADING__ = {};
129
131
  var ___PRELOADED_MAP__;
130
- (___PRELOADED_MAP__ = (_nativeGlobal___FEDERATION__5 = nativeGlobal.__FEDERATION__).__PRELOADED_MAP__) != null ? ___PRELOADED_MAP__ : _nativeGlobal___FEDERATION__5.__PRELOADED_MAP__ = new Map();
132
+ (___PRELOADED_MAP__ = (_nativeGlobal___FEDERATION__6 = nativeGlobal.__FEDERATION__).__PRELOADED_MAP__) != null ? ___PRELOADED_MAP__ : _nativeGlobal___FEDERATION__6.__PRELOADED_MAP__ = new Map();
131
133
  const Global = {
132
134
  get __FEDERATION__ () {
133
135
  const globalThisVal = new Function('return globalThis')();
@@ -140,6 +142,7 @@ function resetFederationGlobalInfo() {
140
142
  nativeGlobal.__FEDERATION__.moduleInfo = {};
141
143
  nativeGlobal.__FEDERATION__.__SHARE__ = {};
142
144
  nativeGlobal.__FEDERATION__.__MANIFEST_LOADING__ = {};
145
+ nativeGlobal.__FEDERATION__.__SHARE_SCOPE_LOADING__ = {};
143
146
  }
144
147
  function getGlobalFederationInstance(name, version) {
145
148
  const buildId = getBuilderId();
@@ -147,7 +150,7 @@ function getGlobalFederationInstance(name, version) {
147
150
  if (buildId && GMInstance.options.id === getBuilderId()) {
148
151
  return true;
149
152
  }
150
- if (GMInstance.options.name === name && !version) {
153
+ if (GMInstance.options.name === name && !GMInstance.options.version && !version) {
151
154
  return true;
152
155
  }
153
156
  if (GMInstance.options.name === name && version && GMInstance.options.version === version) {
@@ -614,16 +617,14 @@ function formatShare(shareArgs, from) {
614
617
  deps: [],
615
618
  useIn: [],
616
619
  from,
617
- loading: null
618
- }, shareArgs, {
619
- shareConfig: _extends({
620
+ shareConfig: {
620
621
  requiredVersion: `^${shareArgs.version}`,
621
622
  singleton: false,
622
- eager: false,
623
- strictVersion: false
624
- }, shareArgs.shareConfig),
623
+ eager: false
624
+ },
625
+ loading: null
626
+ }, shareArgs, {
625
627
  get,
626
- loaded: 'lib' in shareArgs ? true : undefined,
627
628
  scope: Array.isArray(shareArgs.scope) ? shareArgs.scope : [
628
629
  'default'
629
630
  ],
@@ -640,26 +641,15 @@ function formatShareConfigs(shareArgs, from) {
640
641
  }, {});
641
642
  }
642
643
  function versionLt(a, b) {
643
- const transformInvalidVersion = (version)=>{
644
- const isNumberVersion = !Number.isNaN(Number(version));
645
- if (isNumberVersion) {
646
- const splitArr = version.split('.');
647
- let validVersion = version;
648
- for(let i = 0; i < 3 - splitArr.length; i++){
649
- validVersion += '.0';
650
- }
651
- return validVersion;
652
- }
653
- return version;
654
- };
655
- if (satisfy(transformInvalidVersion(a), `<=${transformInvalidVersion(b)}`)) {
644
+ if (satisfy(a, `<=${b}`)) {
656
645
  return true;
657
646
  } else {
658
647
  return false;
659
648
  }
660
649
  }
661
- const findVersion = (shareScopeMap, scope, pkgName, cb)=>{
662
- const versions = shareScopeMap[scope][pkgName];
650
+ const findVersion = (scope, pkgName, cb)=>{
651
+ const globalShares = Global.__FEDERATION__.__SHARE__;
652
+ const versions = globalShares[scope][pkgName];
663
653
  const callback = cb || function(prev, cur) {
664
654
  return versionLt(prev, cur);
665
655
  };
@@ -670,22 +660,20 @@ const findVersion = (shareScopeMap, scope, pkgName, cb)=>{
670
660
  if (callback(prev, cur)) {
671
661
  return cur;
672
662
  }
673
- // default version is '0' https://github.com/webpack/webpack/blob/main/lib/sharing/ProvideSharedModule.js#L136
674
- if (prev === '0') {
675
- return cur;
676
- }
677
663
  return prev;
678
664
  }, 0);
679
665
  };
680
- function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) {
681
- const versions = shareScopeMap[scope][pkgName];
666
+ function findSingletonVersionOrderByVersion(scope, pkgName) {
667
+ const globalShares = Global.__FEDERATION__.__SHARE__;
668
+ const versions = globalShares[scope][pkgName];
682
669
  const callback = function(prev, cur) {
683
670
  return !versions[prev].loaded && versionLt(prev, cur);
684
671
  };
685
- return findVersion(shareScopeMap, scope, pkgName, callback);
672
+ return findVersion(scope, pkgName, callback);
686
673
  }
687
- function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
688
- const versions = shareScopeMap[scope][pkgName];
674
+ function findSingletonVersionOrderByLoaded(scope, pkgName) {
675
+ const globalShares = Global.__FEDERATION__.__SHARE__;
676
+ const versions = globalShares[scope][pkgName];
689
677
  const callback = function(prev, cur) {
690
678
  if (versions[cur].loaded) {
691
679
  if (versions[prev].loaded) {
@@ -699,62 +687,45 @@ function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
699
687
  }
700
688
  return versionLt(prev, cur);
701
689
  };
702
- return findVersion(shareScopeMap, scope, pkgName, callback);
703
- }
704
- function getFindShareFunction(strategy) {
705
- if (strategy === 'loaded-first') {
706
- return findSingletonVersionOrderByLoaded;
707
- }
708
- return findSingletonVersionOrderByVersion;
690
+ return findVersion(scope, pkgName, callback);
709
691
  }
710
692
  // Details about shared resources
711
693
  // TODO: Implement strictVersion for alignment with module federation.
712
- function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare) {
713
- if (!localShareScopeMap) {
714
- return;
715
- }
694
+ function getGlobalShare(pkgName, shareInfo) {
695
+ const globalShares = Global.__FEDERATION__.__SHARE__;
716
696
  const { shareConfig, scope = DEFAULT_SCOPE, strategy } = shareInfo;
717
697
  const scopes = Array.isArray(scope) ? scope : [
718
698
  scope
719
699
  ];
720
700
  for (const sc of scopes){
721
- if (shareConfig && localShareScopeMap[sc] && localShareScopeMap[sc][pkgName]) {
701
+ if (shareConfig && globalShares[sc] && globalShares[sc][pkgName]) {
722
702
  const { requiredVersion } = shareConfig;
723
- const findShareFunction = getFindShareFunction(strategy);
724
- const maxOrSingletonVersion = findShareFunction(localShareScopeMap, sc, pkgName);
725
- //@ts-ignore
726
- const defaultResolver = ()=>{
727
- if (shareConfig.singleton) {
728
- if (typeof requiredVersion === 'string' && !satisfy(maxOrSingletonVersion, requiredVersion)) {
729
- const msg = `Version ${maxOrSingletonVersion} from ${maxOrSingletonVersion && localShareScopeMap[sc][pkgName][maxOrSingletonVersion].from} of shared singleton module ${pkgName} does not satisfy the requirement of ${shareInfo.from} which needs ${requiredVersion})`;
730
- if (shareConfig.strictVersion) {
731
- error(msg);
732
- } else {
733
- warn(msg);
734
- }
735
- }
736
- return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
737
- } else {
738
- if (requiredVersion === false || requiredVersion === '*') {
739
- return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
740
- }
741
- for (const [versionKey, versionValue] of Object.entries(localShareScopeMap[sc][pkgName])){
742
- if (satisfy(versionKey, requiredVersion)) {
743
- return versionValue;
744
- }
703
+ // eslint-disable-next-line max-depth
704
+ if (shareConfig.singleton) {
705
+ const singletonVersion = strategy === 'loaded-first' ? findSingletonVersionOrderByLoaded(sc, pkgName) : findSingletonVersionOrderByVersion(sc, pkgName);
706
+ // eslint-disable-next-line max-depth
707
+ if (typeof requiredVersion === 'string' && !satisfy(singletonVersion, requiredVersion)) {
708
+ warn(`Version ${singletonVersion} from ${singletonVersion && globalShares[sc][pkgName][singletonVersion].from} of shared singleton module ${pkgName} does not satisfy the requirement of ${shareInfo.from} which needs ${requiredVersion})`);
709
+ }
710
+ return globalShares[sc][pkgName][singletonVersion];
711
+ } else {
712
+ const maxVersion = findSingletonVersionOrderByLoaded(sc, pkgName);
713
+ // eslint-disable-next-line max-depth
714
+ if (requiredVersion === false || requiredVersion === '*') {
715
+ return globalShares[sc][pkgName][maxVersion];
716
+ }
717
+ // eslint-disable-next-line max-depth
718
+ if (satisfy(maxVersion, requiredVersion)) {
719
+ return globalShares[sc][pkgName][maxVersion];
720
+ }
721
+ // eslint-disable-next-line max-depth
722
+ for (const [versionKey, versionValue] of Object.entries(globalShares[sc][pkgName])){
723
+ // eslint-disable-next-line max-depth
724
+ if (satisfy(versionKey, requiredVersion)) {
725
+ return versionValue;
745
726
  }
746
727
  }
747
- };
748
- const params = {
749
- shareScopeMap: localShareScopeMap,
750
- scope: sc,
751
- pkgName,
752
- version: maxOrSingletonVersion,
753
- GlobalFederation: Global.__FEDERATION__,
754
- resolver: defaultResolver
755
- };
756
- const resolveShared = resolveShare.emit(params) || params;
757
- return resolveShared.resolver();
728
+ }
758
729
  }
759
730
  }
760
731
  }
@@ -775,12 +746,12 @@ exports.getFMId = getFMId;
775
746
  exports.getGlobalFederationConstructor = getGlobalFederationConstructor;
776
747
  exports.getGlobalFederationInstance = getGlobalFederationInstance;
777
748
  exports.getGlobalHostPlugins = getGlobalHostPlugins;
749
+ exports.getGlobalShare = getGlobalShare;
778
750
  exports.getGlobalShareScope = getGlobalShareScope;
779
751
  exports.getGlobalSnapshot = getGlobalSnapshot;
780
752
  exports.getGlobalSnapshotInfoByModuleInfo = getGlobalSnapshotInfoByModuleInfo;
781
753
  exports.getInfoWithoutType = getInfoWithoutType;
782
754
  exports.getPreloaded = getPreloaded;
783
- exports.getRegisteredShare = getRegisteredShare;
784
755
  exports.getRemoteEntryExports = getRemoteEntryExports;
785
756
  exports.getTargetSnapshotInfoByModuleInfo = getTargetSnapshotInfoByModuleInfo;
786
757
  exports.globalLoading = globalLoading;
package/dist/share.esm.js CHANGED
@@ -1,5 +1,4 @@
1
1
  function getBuilderId() {
2
- //@ts-ignore
3
2
  return typeof FEDERATION_BUILD_IDENTIFIER !== 'undefined' ? FEDERATION_BUILD_IDENTIFIER : '';
4
3
  }
5
4
  function isDebugMode() {
@@ -87,7 +86,7 @@ function _object_without_properties_loose(source, excluded) {
87
86
  }
88
87
  return target;
89
88
  }
90
- var _nativeGlobal___FEDERATION__, _nativeGlobal___FEDERATION__1, _nativeGlobal___FEDERATION__2, _nativeGlobal___FEDERATION__3, _nativeGlobal___FEDERATION__4, _nativeGlobal___FEDERATION__5;
89
+ var _nativeGlobal___FEDERATION__, _nativeGlobal___FEDERATION__1, _nativeGlobal___FEDERATION__2, _nativeGlobal___FEDERATION__3, _nativeGlobal___FEDERATION__4, _nativeGlobal___FEDERATION__5, _nativeGlobal___FEDERATION__6;
91
90
  // export const nativeGlobal: typeof global = new Function('return this')();
92
91
  const nativeGlobal = new Function('return this')();
93
92
  // This section is to prevent encapsulation by certain microfrontend frameworks. Due to reuse policies, sandbox escapes.
@@ -110,6 +109,7 @@ if (nativeGlobal.__VMOK__) {
110
109
  moduleInfo: {},
111
110
  __SHARE__: {},
112
111
  __MANIFEST_LOADING__: {},
112
+ __SHARE_SCOPE_LOADING__: {},
113
113
  __PRELOADED_MAP__: new Map()
114
114
  };
115
115
  nativeGlobal.__VMOK__ = nativeGlobal.__FEDERATION__;
@@ -124,8 +124,10 @@ var ___SHARE__;
124
124
  (___SHARE__ = (_nativeGlobal___FEDERATION__3 = nativeGlobal.__FEDERATION__).__SHARE__) != null ? ___SHARE__ : _nativeGlobal___FEDERATION__3.__SHARE__ = {};
125
125
  var ___MANIFEST_LOADING__;
126
126
  (___MANIFEST_LOADING__ = (_nativeGlobal___FEDERATION__4 = nativeGlobal.__FEDERATION__).__MANIFEST_LOADING__) != null ? ___MANIFEST_LOADING__ : _nativeGlobal___FEDERATION__4.__MANIFEST_LOADING__ = {};
127
+ var ___SHARE_SCOPE_LOADING__;
128
+ (___SHARE_SCOPE_LOADING__ = (_nativeGlobal___FEDERATION__5 = nativeGlobal.__FEDERATION__).__SHARE_SCOPE_LOADING__) != null ? ___SHARE_SCOPE_LOADING__ : _nativeGlobal___FEDERATION__5.__SHARE_SCOPE_LOADING__ = {};
127
129
  var ___PRELOADED_MAP__;
128
- (___PRELOADED_MAP__ = (_nativeGlobal___FEDERATION__5 = nativeGlobal.__FEDERATION__).__PRELOADED_MAP__) != null ? ___PRELOADED_MAP__ : _nativeGlobal___FEDERATION__5.__PRELOADED_MAP__ = new Map();
130
+ (___PRELOADED_MAP__ = (_nativeGlobal___FEDERATION__6 = nativeGlobal.__FEDERATION__).__PRELOADED_MAP__) != null ? ___PRELOADED_MAP__ : _nativeGlobal___FEDERATION__6.__PRELOADED_MAP__ = new Map();
129
131
  const Global = {
130
132
  get __FEDERATION__ () {
131
133
  const globalThisVal = new Function('return globalThis')();
@@ -138,6 +140,7 @@ function resetFederationGlobalInfo() {
138
140
  nativeGlobal.__FEDERATION__.moduleInfo = {};
139
141
  nativeGlobal.__FEDERATION__.__SHARE__ = {};
140
142
  nativeGlobal.__FEDERATION__.__MANIFEST_LOADING__ = {};
143
+ nativeGlobal.__FEDERATION__.__SHARE_SCOPE_LOADING__ = {};
141
144
  }
142
145
  function getGlobalFederationInstance(name, version) {
143
146
  const buildId = getBuilderId();
@@ -145,7 +148,7 @@ function getGlobalFederationInstance(name, version) {
145
148
  if (buildId && GMInstance.options.id === getBuilderId()) {
146
149
  return true;
147
150
  }
148
- if (GMInstance.options.name === name && !version) {
151
+ if (GMInstance.options.name === name && !GMInstance.options.version && !version) {
149
152
  return true;
150
153
  }
151
154
  if (GMInstance.options.name === name && version && GMInstance.options.version === version) {
@@ -612,16 +615,14 @@ function formatShare(shareArgs, from) {
612
615
  deps: [],
613
616
  useIn: [],
614
617
  from,
615
- loading: null
616
- }, shareArgs, {
617
- shareConfig: _extends({
618
+ shareConfig: {
618
619
  requiredVersion: `^${shareArgs.version}`,
619
620
  singleton: false,
620
- eager: false,
621
- strictVersion: false
622
- }, shareArgs.shareConfig),
621
+ eager: false
622
+ },
623
+ loading: null
624
+ }, shareArgs, {
623
625
  get,
624
- loaded: 'lib' in shareArgs ? true : undefined,
625
626
  scope: Array.isArray(shareArgs.scope) ? shareArgs.scope : [
626
627
  'default'
627
628
  ],
@@ -638,26 +639,15 @@ function formatShareConfigs(shareArgs, from) {
638
639
  }, {});
639
640
  }
640
641
  function versionLt(a, b) {
641
- const transformInvalidVersion = (version)=>{
642
- const isNumberVersion = !Number.isNaN(Number(version));
643
- if (isNumberVersion) {
644
- const splitArr = version.split('.');
645
- let validVersion = version;
646
- for(let i = 0; i < 3 - splitArr.length; i++){
647
- validVersion += '.0';
648
- }
649
- return validVersion;
650
- }
651
- return version;
652
- };
653
- if (satisfy(transformInvalidVersion(a), `<=${transformInvalidVersion(b)}`)) {
642
+ if (satisfy(a, `<=${b}`)) {
654
643
  return true;
655
644
  } else {
656
645
  return false;
657
646
  }
658
647
  }
659
- const findVersion = (shareScopeMap, scope, pkgName, cb)=>{
660
- const versions = shareScopeMap[scope][pkgName];
648
+ const findVersion = (scope, pkgName, cb)=>{
649
+ const globalShares = Global.__FEDERATION__.__SHARE__;
650
+ const versions = globalShares[scope][pkgName];
661
651
  const callback = cb || function(prev, cur) {
662
652
  return versionLt(prev, cur);
663
653
  };
@@ -668,22 +658,20 @@ const findVersion = (shareScopeMap, scope, pkgName, cb)=>{
668
658
  if (callback(prev, cur)) {
669
659
  return cur;
670
660
  }
671
- // default version is '0' https://github.com/webpack/webpack/blob/main/lib/sharing/ProvideSharedModule.js#L136
672
- if (prev === '0') {
673
- return cur;
674
- }
675
661
  return prev;
676
662
  }, 0);
677
663
  };
678
- function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) {
679
- const versions = shareScopeMap[scope][pkgName];
664
+ function findSingletonVersionOrderByVersion(scope, pkgName) {
665
+ const globalShares = Global.__FEDERATION__.__SHARE__;
666
+ const versions = globalShares[scope][pkgName];
680
667
  const callback = function(prev, cur) {
681
668
  return !versions[prev].loaded && versionLt(prev, cur);
682
669
  };
683
- return findVersion(shareScopeMap, scope, pkgName, callback);
670
+ return findVersion(scope, pkgName, callback);
684
671
  }
685
- function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
686
- const versions = shareScopeMap[scope][pkgName];
672
+ function findSingletonVersionOrderByLoaded(scope, pkgName) {
673
+ const globalShares = Global.__FEDERATION__.__SHARE__;
674
+ const versions = globalShares[scope][pkgName];
687
675
  const callback = function(prev, cur) {
688
676
  if (versions[cur].loaded) {
689
677
  if (versions[prev].loaded) {
@@ -697,62 +685,45 @@ function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
697
685
  }
698
686
  return versionLt(prev, cur);
699
687
  };
700
- return findVersion(shareScopeMap, scope, pkgName, callback);
701
- }
702
- function getFindShareFunction(strategy) {
703
- if (strategy === 'loaded-first') {
704
- return findSingletonVersionOrderByLoaded;
705
- }
706
- return findSingletonVersionOrderByVersion;
688
+ return findVersion(scope, pkgName, callback);
707
689
  }
708
690
  // Details about shared resources
709
691
  // TODO: Implement strictVersion for alignment with module federation.
710
- function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare) {
711
- if (!localShareScopeMap) {
712
- return;
713
- }
692
+ function getGlobalShare(pkgName, shareInfo) {
693
+ const globalShares = Global.__FEDERATION__.__SHARE__;
714
694
  const { shareConfig, scope = DEFAULT_SCOPE, strategy } = shareInfo;
715
695
  const scopes = Array.isArray(scope) ? scope : [
716
696
  scope
717
697
  ];
718
698
  for (const sc of scopes){
719
- if (shareConfig && localShareScopeMap[sc] && localShareScopeMap[sc][pkgName]) {
699
+ if (shareConfig && globalShares[sc] && globalShares[sc][pkgName]) {
720
700
  const { requiredVersion } = shareConfig;
721
- const findShareFunction = getFindShareFunction(strategy);
722
- const maxOrSingletonVersion = findShareFunction(localShareScopeMap, sc, pkgName);
723
- //@ts-ignore
724
- const defaultResolver = ()=>{
725
- if (shareConfig.singleton) {
726
- if (typeof requiredVersion === 'string' && !satisfy(maxOrSingletonVersion, requiredVersion)) {
727
- const msg = `Version ${maxOrSingletonVersion} from ${maxOrSingletonVersion && localShareScopeMap[sc][pkgName][maxOrSingletonVersion].from} of shared singleton module ${pkgName} does not satisfy the requirement of ${shareInfo.from} which needs ${requiredVersion})`;
728
- if (shareConfig.strictVersion) {
729
- error(msg);
730
- } else {
731
- warn(msg);
732
- }
733
- }
734
- return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
735
- } else {
736
- if (requiredVersion === false || requiredVersion === '*') {
737
- return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
738
- }
739
- for (const [versionKey, versionValue] of Object.entries(localShareScopeMap[sc][pkgName])){
740
- if (satisfy(versionKey, requiredVersion)) {
741
- return versionValue;
742
- }
701
+ // eslint-disable-next-line max-depth
702
+ if (shareConfig.singleton) {
703
+ const singletonVersion = strategy === 'loaded-first' ? findSingletonVersionOrderByLoaded(sc, pkgName) : findSingletonVersionOrderByVersion(sc, pkgName);
704
+ // eslint-disable-next-line max-depth
705
+ if (typeof requiredVersion === 'string' && !satisfy(singletonVersion, requiredVersion)) {
706
+ warn(`Version ${singletonVersion} from ${singletonVersion && globalShares[sc][pkgName][singletonVersion].from} of shared singleton module ${pkgName} does not satisfy the requirement of ${shareInfo.from} which needs ${requiredVersion})`);
707
+ }
708
+ return globalShares[sc][pkgName][singletonVersion];
709
+ } else {
710
+ const maxVersion = findSingletonVersionOrderByLoaded(sc, pkgName);
711
+ // eslint-disable-next-line max-depth
712
+ if (requiredVersion === false || requiredVersion === '*') {
713
+ return globalShares[sc][pkgName][maxVersion];
714
+ }
715
+ // eslint-disable-next-line max-depth
716
+ if (satisfy(maxVersion, requiredVersion)) {
717
+ return globalShares[sc][pkgName][maxVersion];
718
+ }
719
+ // eslint-disable-next-line max-depth
720
+ for (const [versionKey, versionValue] of Object.entries(globalShares[sc][pkgName])){
721
+ // eslint-disable-next-line max-depth
722
+ if (satisfy(versionKey, requiredVersion)) {
723
+ return versionValue;
743
724
  }
744
725
  }
745
- };
746
- const params = {
747
- shareScopeMap: localShareScopeMap,
748
- scope: sc,
749
- pkgName,
750
- version: maxOrSingletonVersion,
751
- GlobalFederation: Global.__FEDERATION__,
752
- resolver: defaultResolver
753
- };
754
- const resolveShared = resolveShare.emit(params) || params;
755
- return resolveShared.resolver();
726
+ }
756
727
  }
757
728
  }
758
729
  }
@@ -760,4 +731,4 @@ function getGlobalShareScope() {
760
731
  return Global.__FEDERATION__.__SHARE__;
761
732
  }
762
733
 
763
- export { getGlobalFederationInstance as A, getGlobalFederationConstructor as B, setGlobalFederationInstance as C, DEFAULT_REMOTE_TYPE as D, registerGlobalPlugins as E, nativeGlobal as F, Global as G, resetFederationGlobalInfo as H, getTargetSnapshotInfoByModuleInfo as I, addGlobalSnapshot as J, DEFAULT_SCOPE as a, globalLoading 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, setGlobalSnapshotInfoByModuleInfo as q, getGlobalSnapshot as r, safeToString as s, getGlobalShareScope as t, addUniqueItem as u, formatShareConfigs as v, warn as w, isBrowserEnv as x, getBuilderId as y, setGlobalFederationConstructor as z };
734
+ export { getGlobalFederationInstance as A, getGlobalFederationConstructor as B, setGlobalFederationInstance as C, DEFAULT_REMOTE_TYPE as D, registerGlobalPlugins as E, nativeGlobal as F, Global as G, resetFederationGlobalInfo as H, getTargetSnapshotInfoByModuleInfo as I, addGlobalSnapshot as J, DEFAULT_SCOPE as a, globalLoading 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, getGlobalShare as l, getInfoWithoutType as m, getPreloaded as n, setPreloaded as o, getGlobalSnapshotInfoByModuleInfo as p, setGlobalSnapshotInfoByModuleInfo as q, getGlobalSnapshot as r, safeToString as s, addUniqueItem as t, formatShareConfigs as u, isBrowserEnv as v, warn as w, getGlobalShareScope as x, getBuilderId as y, setGlobalFederationConstructor as z };
@@ -1,8 +1,7 @@
1
1
  import type { ModuleInfo, GlobalModuleInfo } from '@module-federation/sdk';
2
- import { Options, PreloadAssets, PreloadOptions, PreloadRemoteArgs, Remote, Shared, ShareInfos, UserOptions, RemoteInfo, ShareScopeMap } from './type';
2
+ import { Options, PreloadAssets, PreloadOptions, PreloadRemoteArgs, RemoteEntryExports, Remote, Shared, ShareInfos, UserOptions, RemoteInfo, GlobalShareScope, InitScope, RemoteEntryInitOptions } from './type';
3
3
  import { Module, ModuleOptions } from './module';
4
4
  import { AsyncHook, AsyncWaterfallHook, PluginSystem, SyncHook, SyncWaterfallHook } from './utils/hooks';
5
- import { Federation } from './global';
6
5
  import { SnapshotHandler } from './plugins/snapshot/SnapshotHandler';
7
6
  interface LoadRemoteMatch {
8
7
  id: string;
@@ -33,6 +32,21 @@ export declare class FederationHost {
33
32
  origin: FederationHost;
34
33
  }>;
35
34
  afterResolve: AsyncWaterfallHook<LoadRemoteMatch>;
35
+ beforeInitContainer: AsyncWaterfallHook<{
36
+ shareScope: GlobalShareScope[string];
37
+ initScope: InitScope;
38
+ remoteEntryInitOptions: RemoteEntryInitOptions;
39
+ remoteInfo: RemoteInfo;
40
+ origin: FederationHost;
41
+ }>;
42
+ initContainer: AsyncWaterfallHook<{
43
+ shareScope: GlobalShareScope[string];
44
+ initScope: InitScope;
45
+ remoteEntryInitOptions: RemoteEntryInitOptions;
46
+ remoteInfo: RemoteInfo;
47
+ remoteEntryExports: RemoteEntryExports;
48
+ origin: FederationHost;
49
+ }>;
36
50
  onLoad: AsyncHook<[{
37
51
  id: string;
38
52
  expose: string;
@@ -53,8 +67,6 @@ export declare class FederationHost {
53
67
  errorLoadRemote: AsyncHook<[{
54
68
  id: string;
55
69
  error: unknown;
56
- from: 'build' | 'runtime';
57
- origin: FederationHost;
58
70
  }], void>;
59
71
  beforeLoadShare: AsyncWaterfallHook<{
60
72
  pkgName: string;
@@ -63,14 +75,6 @@ export declare class FederationHost {
63
75
  origin: FederationHost;
64
76
  }>;
65
77
  loadShare: AsyncHook<[FederationHost, string, ShareInfos], false | void | Promise<false | void>>;
66
- resolveShare: SyncWaterfallHook<{
67
- shareScopeMap: ShareScopeMap;
68
- scope: string;
69
- pkgName: string;
70
- version: string;
71
- GlobalFederation: Federation;
72
- resolver: () => Shared | undefined;
73
- }>;
74
78
  beforePreloadRemote: AsyncHook<{
75
79
  preloadOps: Array<PreloadRemoteArgs>;
76
80
  options: Options;
@@ -90,12 +94,10 @@ export declare class FederationHost {
90
94
  origin: FederationHost;
91
95
  }, false | void | Promise<false | void>>;
92
96
  }>;
93
- releaseNumber: string;
94
97
  version: string;
95
98
  name: string;
96
99
  moduleCache: Map<string, Module>;
97
100
  snapshotHandler: SnapshotHandler;
98
- shareScopeMap: ShareScopeMap;
99
101
  loaderHook: PluginSystem<{
100
102
  getModuleInfo: SyncHook<[{
101
103
  target: Record<string, any>;
@@ -109,15 +111,16 @@ export declare class FederationHost {
109
111
  }], void | HTMLScriptElement>;
110
112
  fetch: AsyncHook<[string, RequestInit], false | void | Promise<Response>>;
111
113
  }>;
114
+ loadingShare: {
115
+ [key: string]: Promise<any>;
116
+ };
112
117
  constructor(userOptions: UserOptions);
113
- private _setGlobalShareScopeMap;
114
118
  initOptions(userOptions: UserOptions): Options;
115
119
  loadShare<T>(pkgName: string, customShareInfo?: Partial<Shared>): Promise<false | (() => T | undefined)>;
116
120
  loadShareSync<T>(pkgName: string): () => T | never;
117
121
  private _getRemoteModuleAndOptions;
118
122
  loadRemote<T>(id: string, options?: {
119
123
  loadFactory?: boolean;
120
- from: 'build' | 'runtime';
121
124
  }): Promise<T | null>;
122
125
  preloadRemote(preloadOptions: Array<PreloadRemoteArgs>): Promise<void>;
123
126
  /**
@@ -125,8 +128,7 @@ export declare class FederationHost {
125
128
  * It accepts one argument, the name of the share scope.
126
129
  * If the share scope does not exist, it creates one.
127
130
  */
128
- initializeSharing(shareScopeName?: string, strategy?: Shared['strategy']): Array<Promise<void>>;
129
- initShareScopeMap(scopeName: string, shareScope: ShareScopeMap[string]): void;
131
+ initializeSharing(shareScopeName?: string): boolean | Promise<boolean>;
130
132
  private formatOptions;
131
133
  private registerPlugins;
132
134
  private setShared;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { FederationHost } from './core';
3
- import { RemoteEntryExports, GlobalShareScopeMap, Remote, Optional } from './type';
3
+ import { RemoteEntryExports, GlobalShareScope, Remote, Optional } from './type';
4
4
  import { GlobalModuleInfo, ModuleInfo } from '@module-federation/sdk';
5
5
  import { FederationRuntimePlugin } from './type/plugin';
6
6
  export interface Federation {
@@ -9,8 +9,9 @@ export interface Federation {
9
9
  moduleInfo: GlobalModuleInfo;
10
10
  __DEBUG_CONSTRUCTOR__?: typeof FederationHost;
11
11
  __INSTANCES__: Array<FederationHost>;
12
- __SHARE__: GlobalShareScopeMap;
12
+ __SHARE__: GlobalShareScope;
13
13
  __MANIFEST_LOADING__: Record<string, Promise<ModuleInfo>>;
14
+ __SHARE_SCOPE_LOADING__: Record<string, boolean | Promise<boolean>>;
14
15
  __PRELOADED_MAP__: Map<string, boolean>;
15
16
  }
16
17
  export declare const nativeGlobal: typeof global;
@@ -1,8 +1,8 @@
1
1
  /// <reference types="node" />
2
2
  import { resetFederationGlobalInfo, getGlobalFederationInstance, setGlobalFederationInstance, getGlobalFederationConstructor, setGlobalFederationConstructor, getInfoWithoutType, getGlobalSnapshot, getTargetSnapshotInfoByModuleInfo, getGlobalSnapshotInfoByModuleInfo, setGlobalSnapshotInfoByModuleInfo, addGlobalSnapshot, getRemoteEntryExports, registerGlobalPlugins, getGlobalHostPlugins, getPreloaded, setPreloaded } from './global';
3
- import { getRegisteredShare, getGlobalShareScope } from './utils/share';
3
+ import { getGlobalShare, getGlobalShareScope } from './utils/share';
4
4
  interface IShareUtils {
5
- getRegisteredShare: typeof getRegisteredShare;
5
+ getGlobalShare: typeof getGlobalShare;
6
6
  getGlobalShareScope: typeof getGlobalShareScope;
7
7
  }
8
8
  interface IGlobalUtils {
@@ -2,7 +2,6 @@ import { FederationHost } from './core';
2
2
  import { UserOptions } from './type';
3
3
  export { FederationHost } from './core';
4
4
  export { registerGlobalPlugins } from './global';
5
- export { loadScript } from '@module-federation/sdk';
6
5
  export type { Federation } from './global';
7
6
  export declare function init(options: UserOptions): FederationHost;
8
7
  export declare function loadRemote(...args: Parameters<FederationHost['loadRemote']>): ReturnType<FederationHost['loadRemote']>;
@@ -1,23 +1,15 @@
1
1
  import { FederationHost } from '../core';
2
- import { RemoteEntryExports, Options, Remote, ShareInfos, RemoteInfo, ShareScopeMap } from '../type';
2
+ import { RemoteEntryExports, RemoteInfo } from '../type';
3
3
  export type ModuleOptions = ConstructorParameters<typeof Module>[0];
4
- type HostInfo = Remote;
5
4
  declare class Module {
6
- hostInfo: HostInfo;
7
5
  remoteInfo: RemoteInfo;
8
6
  inited: boolean;
9
- shared: ShareInfos;
10
7
  remoteEntryExports?: RemoteEntryExports;
11
8
  lib: RemoteEntryExports | undefined;
12
- loaderHook: FederationHost['loaderHook'];
13
- shareScopeMap: ShareScopeMap;
14
- constructor({ hostInfo, remoteInfo, shared, loaderHook, shareScopeMap, }: {
15
- hostInfo: HostInfo;
9
+ host: FederationHost;
10
+ constructor({ remoteInfo, host, }: {
16
11
  remoteInfo: RemoteInfo;
17
- shared: ShareInfos;
18
- plugins: Options['plugins'];
19
- loaderHook: FederationHost['loaderHook'];
20
- shareScopeMap: ShareScopeMap;
12
+ host: FederationHost;
21
13
  });
22
14
  getEntry(): Promise<RemoteEntryExports>;
23
15
  get(expose: string, options?: {