@module-federation/runtime 0.0.0-next-20240122073529 → 0.0.0-next-20240123083034

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 { l as getRegisteredShare, t as getGlobalShareScope, G as Global, F as nativeGlobal, H as resetFederationGlobalInfo, A as getGlobalFederationInstance, C as setGlobalFederationInstance, B as getGlobalFederationConstructor, z as setGlobalFederationConstructor, m as getInfoWithoutType, r as getGlobalSnapshot, I as getTargetSnapshotInfoByModuleInfo, p as getGlobalSnapshotInfoByModuleInfo, q as setGlobalSnapshotInfoByModuleInfo, J as addGlobalSnapshot, c as getRemoteEntryExports, E as registerGlobalPlugins, g as getGlobalHostPlugins, n as getPreloaded, o as setPreloaded } from './share.esm.js';
2
2
 
3
3
  const ShareUtils = {
4
4
  getRegisteredShare,
package/dist/index.cjs.js CHANGED
@@ -674,9 +674,9 @@ function splitId(id) {
674
674
  }
675
675
  }
676
676
  // Traverse all nodes in moduleInfo and traverse the entire snapshot
677
- function traverseModuleInfo(globalSnapshot, remoteInfo, traverse, isRoot, memo = {}, remoteSnapshot) {
677
+ function traverseModuleInfo(globalSnapshot, remoteInfo, traverse, isRoot, memo = {}, remoteSnapshot, getModuleInfoHook) {
678
678
  const id = share.getFMId(remoteInfo);
679
- const { value: snapshotValue } = share.getInfoWithoutType(globalSnapshot, id);
679
+ const { value: snapshotValue } = share.getInfoWithoutType(globalSnapshot, id, getModuleInfoHook);
680
680
  const effectiveRemoteSnapshot = remoteSnapshot || snapshotValue;
681
681
  if (effectiveRemoteSnapshot && !sdk.isManifestProvider(effectiveRemoteSnapshot)) {
682
682
  traverse(effectiveRemoteSnapshot, remoteInfo, isRoot);
@@ -692,7 +692,7 @@ function traverseModuleInfo(globalSnapshot, remoteInfo, traverse, isRoot, memo =
692
692
  traverseModuleInfo(globalSnapshot, {
693
693
  name: subRemoteInfo.name,
694
694
  version: remoteValue.matchedVersion
695
- }, traverse, false, memo, undefined);
695
+ }, traverse, false, memo, undefined, getModuleInfoHook);
696
696
  }
697
697
  }
698
698
  }
@@ -773,7 +773,8 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
773
773
  id: assetsInfo.moduleName === '.' ? remoteInfo.name : exposeFullPath,
774
774
  name: remoteInfo.name,
775
775
  remoteSnapshot: moduleInfoSnapshot,
776
- preloadConfig
776
+ preloadConfig,
777
+ origin
777
778
  });
778
779
  const preloaded = share.getPreloaded(exposeFullPath);
779
780
  if (preloaded) {
@@ -792,7 +793,16 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
792
793
  share.setPreloaded(exposeFullPath);
793
794
  }
794
795
  }
795
- }, true, memo, remoteSnapshot);
796
+ }, true, memo, remoteSnapshot, (target, key)=>{
797
+ const res = origin.loaderHook.lifecycle.getModuleInfo.emit({
798
+ target,
799
+ key
800
+ });
801
+ if (res && !(res instanceof Promise)) {
802
+ return res;
803
+ }
804
+ return;
805
+ });
796
806
  if (remoteSnapshot.shared) {
797
807
  remoteSnapshot.shared.forEach((shared)=>{
798
808
  var _options_shared;
@@ -885,27 +895,37 @@ class SnapshotHandler {
885
895
  // eslint-disable-next-line max-lines-per-function
886
896
  async loadRemoteSnapshotInfo(moduleInfo) {
887
897
  const { options } = this.HostInstance;
898
+ const hostSnapshot = share.getGlobalSnapshotInfoByModuleInfo({
899
+ name: this.HostInstance.options.name,
900
+ version: this.HostInstance.options.version
901
+ }, {
902
+ getModuleInfoHook: (target, key)=>{
903
+ const res = this.HostInstance.loaderHook.lifecycle.getModuleInfo.emit({
904
+ target,
905
+ key
906
+ });
907
+ if (res && !(res instanceof Promise)) {
908
+ return res;
909
+ }
910
+ return;
911
+ }
912
+ });
888
913
  await this.hooks.lifecycle.beforeLoadRemoteSnapshot.emit({
889
914
  options,
890
915
  moduleInfo
891
916
  });
892
- let hostSnapshot = share.getGlobalSnapshotInfoByModuleInfo({
893
- name: this.HostInstance.options.name,
894
- version: this.HostInstance.options.version
895
- });
896
- if (!hostSnapshot) {
897
- hostSnapshot = {
898
- version: this.HostInstance.options.version || '',
899
- remoteEntry: '',
900
- remotesInfo: {}
901
- };
902
- share.addGlobalSnapshot({
903
- [this.HostInstance.options.name]: hostSnapshot
904
- });
905
- }
906
917
  // In dynamic loadRemote scenarios, incomplete remotesInfo delivery may occur. In such cases, the remotesInfo in the host needs to be completed in the snapshot at runtime.
907
918
  // This ensures the snapshot's integrity and helps the chrome plugin correctly identify all producer modules, ensuring that proxyable producer modules will not be missing.
908
- if (hostSnapshot && 'remotesInfo' in hostSnapshot && !share.getInfoWithoutType(hostSnapshot.remotesInfo, moduleInfo.name).value) {
919
+ if (hostSnapshot && 'remotesInfo' in hostSnapshot && !share.getInfoWithoutType(hostSnapshot.remotesInfo, moduleInfo.name, (target, key)=>{
920
+ const res = this.HostInstance.loaderHook.lifecycle.getModuleInfo.emit({
921
+ target,
922
+ key
923
+ });
924
+ if (res && !(res instanceof Promise)) {
925
+ return res;
926
+ }
927
+ return;
928
+ }).value) {
909
929
  if ('version' in moduleInfo || 'entry' in moduleInfo) {
910
930
  hostSnapshot.remotesInfo = _extends$1({}, hostSnapshot == null ? void 0 : hostSnapshot.remotesInfo, {
911
931
  [moduleInfo.name]: {
@@ -927,11 +947,7 @@ class SnapshotHandler {
927
947
  if (sdk.isManifestProvider(globalRemoteSnapshot)) {
928
948
  const moduleSnapshot = await this.getManifestJson(globalRemoteSnapshot.remoteEntry, moduleInfo, {});
929
949
  // eslint-disable-next-line @typescript-eslint/no-shadow
930
- const globalSnapshotRes = share.setGlobalSnapshotInfoByModuleInfo(_extends$1({}, moduleInfo, {
931
- // The global remote may be overridden
932
- // Therefore, set the snapshot key to the global address of the actual request
933
- entry: globalRemoteSnapshot.remoteEntry
934
- }), moduleSnapshot);
950
+ const globalSnapshotRes = share.setGlobalSnapshotInfoByModuleInfo(_extends$1({}, moduleInfo), moduleSnapshot);
935
951
  return {
936
952
  remoteSnapshot: moduleSnapshot,
937
953
  globalSnapshot: globalSnapshotRes
@@ -978,9 +994,29 @@ class SnapshotHandler {
978
994
  const hostGlobalSnapshot = share.getGlobalSnapshotInfoByModuleInfo({
979
995
  name: this.HostInstance.options.name,
980
996
  version: this.HostInstance.options.version
997
+ }, {
998
+ getModuleInfoHook: (target, key)=>{
999
+ const res = this.HostInstance.loaderHook.lifecycle.getModuleInfo.emit({
1000
+ target,
1001
+ key
1002
+ });
1003
+ if (res && !(res instanceof Promise)) {
1004
+ return res;
1005
+ }
1006
+ return;
1007
+ }
981
1008
  });
982
1009
  // get remote detail info from global
983
- const globalRemoteInfo = hostGlobalSnapshot && 'remotesInfo' in hostGlobalSnapshot && hostGlobalSnapshot.remotesInfo && share.getInfoWithoutType(hostGlobalSnapshot.remotesInfo, moduleInfo.name).value;
1010
+ const globalRemoteInfo = hostGlobalSnapshot && 'remotesInfo' in hostGlobalSnapshot && hostGlobalSnapshot.remotesInfo && share.getInfoWithoutType(hostGlobalSnapshot.remotesInfo, moduleInfo.name, (target, key)=>{
1011
+ const res = this.HostInstance.loaderHook.lifecycle.getModuleInfo.emit({
1012
+ target,
1013
+ key
1014
+ });
1015
+ if (res && !(res instanceof Promise)) {
1016
+ return res;
1017
+ }
1018
+ return;
1019
+ }).value;
984
1020
  if (globalRemoteInfo && globalRemoteInfo.matchedVersion) {
985
1021
  return {
986
1022
  hostGlobalSnapshot,
@@ -988,6 +1024,17 @@ class SnapshotHandler {
988
1024
  remoteSnapshot: share.getGlobalSnapshotInfoByModuleInfo({
989
1025
  name: moduleInfo.name,
990
1026
  version: globalRemoteInfo.matchedVersion
1027
+ }, {
1028
+ getModuleInfoHook: (target, key)=>{
1029
+ const res = this.HostInstance.loaderHook.lifecycle.getModuleInfo.emit({
1030
+ target,
1031
+ key
1032
+ });
1033
+ if (res && !(res instanceof Promise)) {
1034
+ return res;
1035
+ }
1036
+ return;
1037
+ }
991
1038
  })
992
1039
  };
993
1040
  }
@@ -997,6 +1044,17 @@ class SnapshotHandler {
997
1044
  remoteSnapshot: share.getGlobalSnapshotInfoByModuleInfo({
998
1045
  name: moduleInfo.name,
999
1046
  version: 'version' in moduleInfo ? moduleInfo.version : undefined
1047
+ }, {
1048
+ getModuleInfoHook: (target, key)=>{
1049
+ const res = this.HostInstance.loaderHook.lifecycle.getModuleInfo.emit({
1050
+ target,
1051
+ key
1052
+ });
1053
+ if (res && !(res instanceof Promise)) {
1054
+ return res;
1055
+ }
1056
+ return;
1057
+ }
1000
1058
  })
1001
1059
  };
1002
1060
  }
@@ -1662,6 +1720,8 @@ Object.defineProperty(exports, 'loadScript', {
1662
1720
  get: function () { return sdk.loadScript; }
1663
1721
  });
1664
1722
  exports.FederationHost = FederationHost;
1723
+ exports.getRemoteEntry = getRemoteEntry;
1724
+ exports.getRemoteInfo = getRemoteInfo;
1665
1725
  exports.init = init;
1666
1726
  exports.loadRemote = loadRemote;
1667
1727
  exports.loadShare = loadShare;
package/dist/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
- import { g as getGlobalHostPlugins, D as DEFAULT_REMOTE_TYPE, a as DEFAULT_SCOPE, b as globalLoading, 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 isBrowserEnv, y as getBuilderId, 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 getRegisteredShare, m as getInfoWithoutType, n as getPreloaded, o as setPreloaded, p as getGlobalSnapshotInfoByModuleInfo, q as setGlobalSnapshotInfoByModuleInfo, r as getGlobalSnapshot, G as Global, t as getGlobalShareScope, u as formatShareConfigs, v as isBrowserEnv, x as getBuilderId, y as addUniqueItem, z as setGlobalFederationConstructor, A as getGlobalFederationInstance, B as getGlobalFederationConstructor, C as setGlobalFederationInstance } from './share.esm.js';
2
+ export { E as registerGlobalPlugins } from './share.esm.js';
3
3
  import { composeKeyWithSeparator, loadScriptNode, loadScript, createScript, getResourceUrl, isManifestProvider, generateSnapshotFromManifest } from '@module-federation/sdk';
4
4
  export { loadScript } from '@module-federation/sdk';
5
5
 
@@ -672,9 +672,9 @@ function splitId(id) {
672
672
  }
673
673
  }
674
674
  // Traverse all nodes in moduleInfo and traverse the entire snapshot
675
- function traverseModuleInfo(globalSnapshot, remoteInfo, traverse, isRoot, memo = {}, remoteSnapshot) {
675
+ function traverseModuleInfo(globalSnapshot, remoteInfo, traverse, isRoot, memo = {}, remoteSnapshot, getModuleInfoHook) {
676
676
  const id = getFMId(remoteInfo);
677
- const { value: snapshotValue } = getInfoWithoutType(globalSnapshot, id);
677
+ const { value: snapshotValue } = getInfoWithoutType(globalSnapshot, id, getModuleInfoHook);
678
678
  const effectiveRemoteSnapshot = remoteSnapshot || snapshotValue;
679
679
  if (effectiveRemoteSnapshot && !isManifestProvider(effectiveRemoteSnapshot)) {
680
680
  traverse(effectiveRemoteSnapshot, remoteInfo, isRoot);
@@ -690,7 +690,7 @@ function traverseModuleInfo(globalSnapshot, remoteInfo, traverse, isRoot, memo =
690
690
  traverseModuleInfo(globalSnapshot, {
691
691
  name: subRemoteInfo.name,
692
692
  version: remoteValue.matchedVersion
693
- }, traverse, false, memo, undefined);
693
+ }, traverse, false, memo, undefined, getModuleInfoHook);
694
694
  }
695
695
  }
696
696
  }
@@ -771,7 +771,8 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
771
771
  id: assetsInfo.moduleName === '.' ? remoteInfo.name : exposeFullPath,
772
772
  name: remoteInfo.name,
773
773
  remoteSnapshot: moduleInfoSnapshot,
774
- preloadConfig
774
+ preloadConfig,
775
+ origin
775
776
  });
776
777
  const preloaded = getPreloaded(exposeFullPath);
777
778
  if (preloaded) {
@@ -790,7 +791,16 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
790
791
  setPreloaded(exposeFullPath);
791
792
  }
792
793
  }
793
- }, true, memo, remoteSnapshot);
794
+ }, true, memo, remoteSnapshot, (target, key)=>{
795
+ const res = origin.loaderHook.lifecycle.getModuleInfo.emit({
796
+ target,
797
+ key
798
+ });
799
+ if (res && !(res instanceof Promise)) {
800
+ return res;
801
+ }
802
+ return;
803
+ });
794
804
  if (remoteSnapshot.shared) {
795
805
  remoteSnapshot.shared.forEach((shared)=>{
796
806
  var _options_shared;
@@ -883,27 +893,37 @@ class SnapshotHandler {
883
893
  // eslint-disable-next-line max-lines-per-function
884
894
  async loadRemoteSnapshotInfo(moduleInfo) {
885
895
  const { options } = this.HostInstance;
896
+ const hostSnapshot = getGlobalSnapshotInfoByModuleInfo({
897
+ name: this.HostInstance.options.name,
898
+ version: this.HostInstance.options.version
899
+ }, {
900
+ getModuleInfoHook: (target, key)=>{
901
+ const res = this.HostInstance.loaderHook.lifecycle.getModuleInfo.emit({
902
+ target,
903
+ key
904
+ });
905
+ if (res && !(res instanceof Promise)) {
906
+ return res;
907
+ }
908
+ return;
909
+ }
910
+ });
886
911
  await this.hooks.lifecycle.beforeLoadRemoteSnapshot.emit({
887
912
  options,
888
913
  moduleInfo
889
914
  });
890
- let hostSnapshot = getGlobalSnapshotInfoByModuleInfo({
891
- name: this.HostInstance.options.name,
892
- version: this.HostInstance.options.version
893
- });
894
- if (!hostSnapshot) {
895
- hostSnapshot = {
896
- version: this.HostInstance.options.version || '',
897
- remoteEntry: '',
898
- remotesInfo: {}
899
- };
900
- addGlobalSnapshot({
901
- [this.HostInstance.options.name]: hostSnapshot
902
- });
903
- }
904
915
  // In dynamic loadRemote scenarios, incomplete remotesInfo delivery may occur. In such cases, the remotesInfo in the host needs to be completed in the snapshot at runtime.
905
916
  // This ensures the snapshot's integrity and helps the chrome plugin correctly identify all producer modules, ensuring that proxyable producer modules will not be missing.
906
- if (hostSnapshot && 'remotesInfo' in hostSnapshot && !getInfoWithoutType(hostSnapshot.remotesInfo, moduleInfo.name).value) {
917
+ if (hostSnapshot && 'remotesInfo' in hostSnapshot && !getInfoWithoutType(hostSnapshot.remotesInfo, moduleInfo.name, (target, key)=>{
918
+ const res = this.HostInstance.loaderHook.lifecycle.getModuleInfo.emit({
919
+ target,
920
+ key
921
+ });
922
+ if (res && !(res instanceof Promise)) {
923
+ return res;
924
+ }
925
+ return;
926
+ }).value) {
907
927
  if ('version' in moduleInfo || 'entry' in moduleInfo) {
908
928
  hostSnapshot.remotesInfo = _extends$1({}, hostSnapshot == null ? void 0 : hostSnapshot.remotesInfo, {
909
929
  [moduleInfo.name]: {
@@ -925,11 +945,7 @@ class SnapshotHandler {
925
945
  if (isManifestProvider(globalRemoteSnapshot)) {
926
946
  const moduleSnapshot = await this.getManifestJson(globalRemoteSnapshot.remoteEntry, moduleInfo, {});
927
947
  // eslint-disable-next-line @typescript-eslint/no-shadow
928
- const globalSnapshotRes = setGlobalSnapshotInfoByModuleInfo(_extends$1({}, moduleInfo, {
929
- // The global remote may be overridden
930
- // Therefore, set the snapshot key to the global address of the actual request
931
- entry: globalRemoteSnapshot.remoteEntry
932
- }), moduleSnapshot);
948
+ const globalSnapshotRes = setGlobalSnapshotInfoByModuleInfo(_extends$1({}, moduleInfo), moduleSnapshot);
933
949
  return {
934
950
  remoteSnapshot: moduleSnapshot,
935
951
  globalSnapshot: globalSnapshotRes
@@ -976,9 +992,29 @@ class SnapshotHandler {
976
992
  const hostGlobalSnapshot = getGlobalSnapshotInfoByModuleInfo({
977
993
  name: this.HostInstance.options.name,
978
994
  version: this.HostInstance.options.version
995
+ }, {
996
+ getModuleInfoHook: (target, key)=>{
997
+ const res = this.HostInstance.loaderHook.lifecycle.getModuleInfo.emit({
998
+ target,
999
+ key
1000
+ });
1001
+ if (res && !(res instanceof Promise)) {
1002
+ return res;
1003
+ }
1004
+ return;
1005
+ }
979
1006
  });
980
1007
  // get remote detail info from global
981
- const globalRemoteInfo = hostGlobalSnapshot && 'remotesInfo' in hostGlobalSnapshot && hostGlobalSnapshot.remotesInfo && getInfoWithoutType(hostGlobalSnapshot.remotesInfo, moduleInfo.name).value;
1008
+ const globalRemoteInfo = hostGlobalSnapshot && 'remotesInfo' in hostGlobalSnapshot && hostGlobalSnapshot.remotesInfo && getInfoWithoutType(hostGlobalSnapshot.remotesInfo, moduleInfo.name, (target, key)=>{
1009
+ const res = this.HostInstance.loaderHook.lifecycle.getModuleInfo.emit({
1010
+ target,
1011
+ key
1012
+ });
1013
+ if (res && !(res instanceof Promise)) {
1014
+ return res;
1015
+ }
1016
+ return;
1017
+ }).value;
982
1018
  if (globalRemoteInfo && globalRemoteInfo.matchedVersion) {
983
1019
  return {
984
1020
  hostGlobalSnapshot,
@@ -986,6 +1022,17 @@ class SnapshotHandler {
986
1022
  remoteSnapshot: getGlobalSnapshotInfoByModuleInfo({
987
1023
  name: moduleInfo.name,
988
1024
  version: globalRemoteInfo.matchedVersion
1025
+ }, {
1026
+ getModuleInfoHook: (target, key)=>{
1027
+ const res = this.HostInstance.loaderHook.lifecycle.getModuleInfo.emit({
1028
+ target,
1029
+ key
1030
+ });
1031
+ if (res && !(res instanceof Promise)) {
1032
+ return res;
1033
+ }
1034
+ return;
1035
+ }
989
1036
  })
990
1037
  };
991
1038
  }
@@ -995,6 +1042,17 @@ class SnapshotHandler {
995
1042
  remoteSnapshot: getGlobalSnapshotInfoByModuleInfo({
996
1043
  name: moduleInfo.name,
997
1044
  version: 'version' in moduleInfo ? moduleInfo.version : undefined
1045
+ }, {
1046
+ getModuleInfoHook: (target, key)=>{
1047
+ const res = this.HostInstance.loaderHook.lifecycle.getModuleInfo.emit({
1048
+ target,
1049
+ key
1050
+ });
1051
+ if (res && !(res instanceof Promise)) {
1052
+ return res;
1053
+ }
1054
+ return;
1055
+ }
998
1056
  })
999
1057
  };
1000
1058
  }
@@ -1654,4 +1712,4 @@ function preloadRemote(...args) {
1654
1712
  // Inject for debug
1655
1713
  setGlobalFederationConstructor(FederationHost);
1656
1714
 
1657
- export { FederationHost, init, loadRemote, loadShare, loadShareSync, preloadRemote };
1715
+ export { FederationHost, getRemoteEntry, getRemoteInfo, init, loadRemote, loadShare, loadShareSync, preloadRemote };
package/dist/share.cjs.js CHANGED
@@ -168,48 +168,29 @@ function setGlobalFederationInstance(FederationInstance) {
168
168
  function getGlobalFederationConstructor() {
169
169
  return globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__;
170
170
  }
171
- function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
172
- if (isDebug) {
171
+ function setGlobalFederationConstructor(FederationConstructor) {
172
+ if (isDebugMode()) {
173
173
  globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
174
174
  globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.0.9";
175
175
  }
176
176
  }
177
177
  // eslint-disable-next-line @typescript-eslint/ban-types
178
- function getInfoWithoutType(target, key) {
179
- if (typeof key === 'string') {
180
- const keyRes = target[key];
181
- if (keyRes) {
182
- return {
183
- value: target[key],
184
- key: key
185
- };
186
- } else {
187
- const targetKeys = Object.keys(target);
188
- for (const targetKey of targetKeys){
189
- const [targetTypeOrName, _] = targetKey.split(':');
190
- const nKey = `${targetTypeOrName}:${key}`;
191
- const typeWithKeyRes = target[nKey];
192
- if (typeWithKeyRes) {
193
- return {
194
- value: typeWithKeyRes,
195
- key: nKey
196
- };
197
- }
198
- }
199
- return {
200
- value: undefined,
201
- key: key
202
- };
203
- }
204
- } else {
205
- throw new Error('key must be string');
178
+ function getInfoWithoutType(target, key, getModuleInfoHook) {
179
+ let res = {
180
+ value: target[key],
181
+ key: key
182
+ };
183
+ if (getModuleInfoHook) {
184
+ const hookRes = getModuleInfoHook(target, key);
185
+ res = hookRes || res;
206
186
  }
187
+ return res;
207
188
  }
208
189
  const getGlobalSnapshot = ()=>nativeGlobal.__FEDERATION__.moduleInfo;
209
- const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot)=>{
190
+ const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot, getModuleInfoHook)=>{
210
191
  // Check if the remote is included in the hostSnapshot
211
192
  const moduleKey = getFMId(moduleInfo);
212
- const getModuleInfo = getInfoWithoutType(snapshot, moduleKey).value;
193
+ const getModuleInfo = getInfoWithoutType(snapshot, moduleKey, getModuleInfoHook).value;
213
194
  // The remoteSnapshot might not include a version
214
195
  if (getModuleInfo && !getModuleInfo.version && 'version' in moduleInfo && moduleInfo['version']) {
215
196
  getModuleInfo.version = moduleInfo['version'];
@@ -223,14 +204,14 @@ const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot)=>{
223
204
  "version"
224
205
  ]);
225
206
  const moduleKeyWithoutVersion = getFMId(resModuleInfo);
226
- const getModuleInfoWithoutVersion = getInfoWithoutType(nativeGlobal.__FEDERATION__.moduleInfo, moduleKeyWithoutVersion).value;
207
+ const getModuleInfoWithoutVersion = getInfoWithoutType(nativeGlobal.__FEDERATION__.moduleInfo, moduleKeyWithoutVersion, getModuleInfoHook).value;
227
208
  if ((getModuleInfoWithoutVersion == null ? void 0 : getModuleInfoWithoutVersion.version) === version) {
228
209
  return getModuleInfoWithoutVersion;
229
210
  }
230
211
  }
231
212
  return;
232
213
  };
233
- const getGlobalSnapshotInfoByModuleInfo = (moduleInfo)=>getTargetSnapshotInfoByModuleInfo(moduleInfo, nativeGlobal.__FEDERATION__.moduleInfo);
214
+ const getGlobalSnapshotInfoByModuleInfo = (moduleInfo, extraOptions)=>getTargetSnapshotInfoByModuleInfo(moduleInfo, nativeGlobal.__FEDERATION__.moduleInfo, extraOptions == null ? void 0 : extraOptions.getModuleInfoHook);
234
215
  const setGlobalSnapshotInfoByModuleInfo = (remoteInfo, moduleDetailInfo)=>{
235
216
  const moduleKey = getFMId(remoteInfo);
236
217
  nativeGlobal.__FEDERATION__.moduleInfo[moduleKey] = moduleDetailInfo;
package/dist/share.esm.js CHANGED
@@ -166,48 +166,29 @@ function setGlobalFederationInstance(FederationInstance) {
166
166
  function getGlobalFederationConstructor() {
167
167
  return globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__;
168
168
  }
169
- function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
170
- if (isDebug) {
169
+ function setGlobalFederationConstructor(FederationConstructor) {
170
+ if (isDebugMode()) {
171
171
  globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
172
172
  globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.0.9";
173
173
  }
174
174
  }
175
175
  // eslint-disable-next-line @typescript-eslint/ban-types
176
- function getInfoWithoutType(target, key) {
177
- if (typeof key === 'string') {
178
- const keyRes = target[key];
179
- if (keyRes) {
180
- return {
181
- value: target[key],
182
- key: key
183
- };
184
- } else {
185
- const targetKeys = Object.keys(target);
186
- for (const targetKey of targetKeys){
187
- const [targetTypeOrName, _] = targetKey.split(':');
188
- const nKey = `${targetTypeOrName}:${key}`;
189
- const typeWithKeyRes = target[nKey];
190
- if (typeWithKeyRes) {
191
- return {
192
- value: typeWithKeyRes,
193
- key: nKey
194
- };
195
- }
196
- }
197
- return {
198
- value: undefined,
199
- key: key
200
- };
201
- }
202
- } else {
203
- throw new Error('key must be string');
176
+ function getInfoWithoutType(target, key, getModuleInfoHook) {
177
+ let res = {
178
+ value: target[key],
179
+ key: key
180
+ };
181
+ if (getModuleInfoHook) {
182
+ const hookRes = getModuleInfoHook(target, key);
183
+ res = hookRes || res;
204
184
  }
185
+ return res;
205
186
  }
206
187
  const getGlobalSnapshot = ()=>nativeGlobal.__FEDERATION__.moduleInfo;
207
- const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot)=>{
188
+ const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot, getModuleInfoHook)=>{
208
189
  // Check if the remote is included in the hostSnapshot
209
190
  const moduleKey = getFMId(moduleInfo);
210
- const getModuleInfo = getInfoWithoutType(snapshot, moduleKey).value;
191
+ const getModuleInfo = getInfoWithoutType(snapshot, moduleKey, getModuleInfoHook).value;
211
192
  // The remoteSnapshot might not include a version
212
193
  if (getModuleInfo && !getModuleInfo.version && 'version' in moduleInfo && moduleInfo['version']) {
213
194
  getModuleInfo.version = moduleInfo['version'];
@@ -221,14 +202,14 @@ const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot)=>{
221
202
  "version"
222
203
  ]);
223
204
  const moduleKeyWithoutVersion = getFMId(resModuleInfo);
224
- const getModuleInfoWithoutVersion = getInfoWithoutType(nativeGlobal.__FEDERATION__.moduleInfo, moduleKeyWithoutVersion).value;
205
+ const getModuleInfoWithoutVersion = getInfoWithoutType(nativeGlobal.__FEDERATION__.moduleInfo, moduleKeyWithoutVersion, getModuleInfoHook).value;
225
206
  if ((getModuleInfoWithoutVersion == null ? void 0 : getModuleInfoWithoutVersion.version) === version) {
226
207
  return getModuleInfoWithoutVersion;
227
208
  }
228
209
  }
229
210
  return;
230
211
  };
231
- const getGlobalSnapshotInfoByModuleInfo = (moduleInfo)=>getTargetSnapshotInfoByModuleInfo(moduleInfo, nativeGlobal.__FEDERATION__.moduleInfo);
212
+ const getGlobalSnapshotInfoByModuleInfo = (moduleInfo, extraOptions)=>getTargetSnapshotInfoByModuleInfo(moduleInfo, nativeGlobal.__FEDERATION__.moduleInfo, extraOptions == null ? void 0 : extraOptions.getModuleInfoHook);
232
213
  const setGlobalSnapshotInfoByModuleInfo = (remoteInfo, moduleDetailInfo)=>{
233
214
  const moduleKey = getFMId(remoteInfo);
234
215
  nativeGlobal.__FEDERATION__.moduleInfo[moduleKey] = moduleDetailInfo;
@@ -789,4 +770,4 @@ function getGlobalShareScope() {
789
770
  return Global.__FEDERATION__.__SHARE__;
790
771
  }
791
772
 
792
- 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, 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, addGlobalSnapshot as q, setGlobalSnapshotInfoByModuleInfo as r, safeToString as s, getGlobalSnapshot as t, getGlobalShareScope as u, formatShareConfigs as v, warn as w, isBrowserEnv as x, getBuilderId as y, addUniqueItem as z };
773
+ 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, 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, setGlobalSnapshotInfoByModuleInfo as q, getGlobalSnapshot as r, safeToString as s, getGlobalShareScope as t, formatShareConfigs as u, isBrowserEnv as v, warn as w, getBuilderId as x, addUniqueItem as y, setGlobalFederationConstructor as z };
@@ -69,6 +69,7 @@ export declare class FederationHost {
69
69
  name: string;
70
70
  remoteSnapshot: ModuleInfo;
71
71
  preloadConfig: PreloadRemoteArgs;
72
+ origin: FederationHost;
72
73
  }, void>;
73
74
  errorLoadRemote: AsyncHook<[{
74
75
  id: string;
@@ -23,14 +23,25 @@ export declare function resetFederationGlobalInfo(): void;
23
23
  export declare function getGlobalFederationInstance(name: string, version: string | undefined): FederationHost | undefined;
24
24
  export declare function setGlobalFederationInstance(FederationInstance: FederationHost): void;
25
25
  export declare function getGlobalFederationConstructor(): typeof FederationHost | undefined;
26
- export declare function setGlobalFederationConstructor(FederationConstructor: typeof FederationHost | undefined, isDebug?: boolean): void;
27
- export declare function getInfoWithoutType<T extends object>(target: T, key: keyof T): {
26
+ export declare function setGlobalFederationConstructor(FederationConstructor: typeof FederationHost): void;
27
+ export declare function getInfoWithoutType<T extends object>(target: T, key: keyof T, getModuleInfoHook?: (target: any, key: string | number | symbol) => {
28
+ value: any | undefined;
29
+ key: string;
30
+ } | void): {
28
31
  value: T[keyof T] | undefined;
29
32
  key: string;
30
33
  };
31
34
  export declare const getGlobalSnapshot: () => GlobalModuleInfo;
32
- export declare const getTargetSnapshotInfoByModuleInfo: (moduleInfo: Optional<Remote, 'alias'>, snapshot: GlobalModuleInfo) => GlobalModuleInfo[string] | undefined;
33
- export declare const getGlobalSnapshotInfoByModuleInfo: (moduleInfo: Optional<Remote, 'alias'>) => GlobalModuleInfo[string] | undefined;
35
+ export declare const getTargetSnapshotInfoByModuleInfo: (moduleInfo: Optional<Remote, 'alias'>, snapshot: GlobalModuleInfo, getModuleInfoHook?: ((target: any, key: string | number | symbol) => void | {
36
+ value: any | undefined;
37
+ key: string;
38
+ }) | undefined) => GlobalModuleInfo[string] | undefined;
39
+ export declare const getGlobalSnapshotInfoByModuleInfo: (moduleInfo: Optional<Remote, 'alias'>, extraOptions?: {
40
+ getModuleInfoHook?: ((target: any, key: string | number | symbol) => void | {
41
+ value: any | undefined;
42
+ key: string;
43
+ }) | undefined;
44
+ } | undefined) => GlobalModuleInfo[string] | undefined;
34
45
  export declare const setGlobalSnapshotInfoByModuleInfo: (remoteInfo: Remote, moduleDetailInfo: GlobalModuleInfo[string]) => GlobalModuleInfo;
35
46
  export declare const addGlobalSnapshot: (moduleInfos: GlobalModuleInfo) => (() => void);
36
47
  export declare const getRemoteEntryExports: (name: string, globalName: string | undefined) => {
@@ -2,6 +2,7 @@ import { FederationHost } from './core';
2
2
  import { UserOptions, FederationRuntimePlugin } from './type';
3
3
  export { FederationHost } from './core';
4
4
  export { registerGlobalPlugins } from './global';
5
+ export { getRemoteEntry, getRemoteInfo } from './utils';
5
6
  export { loadScript } from '@module-federation/sdk';
6
7
  export type { Federation } from './global';
7
8
  export type { FederationRuntimePlugin };
@@ -38,12 +38,12 @@ type SharedBaseArgs = {
38
38
  deps?: Array<string>;
39
39
  strategy?: 'version-first' | 'loaded-first';
40
40
  };
41
- export type SharedGetter = (() => () => Module) | (() => Promise<() => Module>);
42
41
  export type ShareArgs = (SharedBaseArgs & {
43
- get: SharedGetter;
42
+ get: () => () => Module | Promise<() => Module>;
44
43
  }) | (SharedBaseArgs & {
45
44
  lib: () => Module;
46
45
  });
46
+ export type SharedGetter = () => () => Promise<() => Module> | Module;
47
47
  export type Shared = {
48
48
  version: string;
49
49
  get: SharedGetter;
@@ -3,3 +3,4 @@ export * from './tool';
3
3
  export * from './manifest';
4
4
  export * from './logger';
5
5
  export * from './plugin';
6
+ export * from './load';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/runtime",
3
- "version": "0.0.0-next-20240122073529",
3
+ "version": "0.0.0-next-20240123083034",
4
4
  "author": "zhouxiao <codingzx@gmail.com>",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.esm.js",
@@ -45,6 +45,6 @@
45
45
  }
46
46
  },
47
47
  "dependencies": {
48
- "@module-federation/sdk": "0.0.0-next-20240122073529"
48
+ "@module-federation/sdk": "0.0.0-next-20240123083034"
49
49
  }
50
50
  }