@module-federation/runtime 0.0.0-next-20240117093010 → 0.0.0-next-20240119073703

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.
@@ -14,7 +14,10 @@ const GlobalUtils = {
14
14
  setGlobalFederationInstance: share.setGlobalFederationInstance,
15
15
  getGlobalFederationConstructor: share.getGlobalFederationConstructor,
16
16
  setGlobalFederationConstructor: share.setGlobalFederationConstructor,
17
+ getInfoWithoutType: share.getInfoWithoutType,
17
18
  getGlobalSnapshot: share.getGlobalSnapshot,
19
+ getTargetSnapshotInfoByModuleInfo: share.getTargetSnapshotInfoByModuleInfo,
20
+ getGlobalSnapshotInfoByModuleInfo: share.getGlobalSnapshotInfoByModuleInfo,
18
21
  setGlobalSnapshotInfoByModuleInfo: share.setGlobalSnapshotInfoByModuleInfo,
19
22
  addGlobalSnapshot: share.addGlobalSnapshot,
20
23
  getRemoteEntryExports: share.getRemoteEntryExports,
@@ -1,4 +1,4 @@
1
- import { n 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, q as getGlobalSnapshot, p as setGlobalSnapshotInfoByModuleInfo, o as addGlobalSnapshot, c as getRemoteEntryExports, E as registerGlobalPlugins, g as getGlobalHostPlugins, l as getPreloaded, m as setPreloaded } from './share.esm.js';
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';
2
2
 
3
3
  const ShareUtils = {
4
4
  getRegisteredShare,
@@ -12,7 +12,10 @@ const GlobalUtils = {
12
12
  setGlobalFederationInstance,
13
13
  getGlobalFederationConstructor,
14
14
  setGlobalFederationConstructor,
15
+ getInfoWithoutType,
15
16
  getGlobalSnapshot,
17
+ getTargetSnapshotInfoByModuleInfo,
18
+ getGlobalSnapshotInfoByModuleInfo,
16
19
  setGlobalSnapshotInfoByModuleInfo,
17
20
  addGlobalSnapshot,
18
21
  getRemoteEntryExports,
package/dist/index.cjs.js CHANGED
@@ -214,7 +214,6 @@ let Module = class Module {
214
214
  remoteInfo: this.remoteInfo,
215
215
  remoteEntryExports: this.remoteEntryExports,
216
216
  createScriptHook: (url)=>{
217
- console.log('xxxxxxx', this.host.loaderHook);
218
217
  const res = this.host.loaderHook.lifecycle.createScript.emit({
219
218
  url
220
219
  });
@@ -675,9 +674,9 @@ function splitId(id) {
675
674
  }
676
675
  }
677
676
  // Traverse all nodes in moduleInfo and traverse the entire snapshot
678
- function traverseModuleInfo(globalSnapshot, remoteInfo, traverse, isRoot, memo = {}, getSnapshotInfoWithHook, remoteSnapshot) {
677
+ function traverseModuleInfo(globalSnapshot, remoteInfo, traverse, isRoot, memo = {}, remoteSnapshot) {
679
678
  const id = share.getFMId(remoteInfo);
680
- const { value: snapshotValue } = getSnapshotInfoWithHook.getInfoWithoutTypeWithHook(globalSnapshot, id);
679
+ const { value: snapshotValue } = share.getInfoWithoutType(globalSnapshot, id);
681
680
  const effectiveRemoteSnapshot = remoteSnapshot || snapshotValue;
682
681
  if (effectiveRemoteSnapshot && !sdk.isManifestProvider(effectiveRemoteSnapshot)) {
683
682
  traverse(effectiveRemoteSnapshot, remoteInfo, isRoot);
@@ -693,7 +692,7 @@ function traverseModuleInfo(globalSnapshot, remoteInfo, traverse, isRoot, memo =
693
692
  traverseModuleInfo(globalSnapshot, {
694
693
  name: subRemoteInfo.name,
695
694
  version: remoteValue.matchedVersion
696
- }, traverse, false, memo, getSnapshotInfoWithHook, undefined);
695
+ }, traverse, false, memo, undefined);
697
696
  }
698
697
  }
699
698
  }
@@ -793,7 +792,7 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
793
792
  share.setPreloaded(exposeFullPath);
794
793
  }
795
794
  }
796
- }, true, memo, origin.snapshotHandler.getSnapshotInfoHandler, remoteSnapshot);
795
+ }, true, memo, remoteSnapshot);
797
796
  if (remoteSnapshot.shared) {
798
797
  remoteSnapshot.shared.forEach((shared)=>{
799
798
  var _options_shared;
@@ -890,7 +889,7 @@ class SnapshotHandler {
890
889
  options,
891
890
  moduleInfo
892
891
  });
893
- let hostSnapshot = this.getSnapshotInfoHandler.getGlobalSnapshotInfoByModuleInfo({
892
+ let hostSnapshot = share.getGlobalSnapshotInfoByModuleInfo({
894
893
  name: this.HostInstance.options.name,
895
894
  version: this.HostInstance.options.version
896
895
  });
@@ -906,7 +905,7 @@ class SnapshotHandler {
906
905
  }
907
906
  // 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.
908
907
  // 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.
909
- if (hostSnapshot && 'remotesInfo' in hostSnapshot && !this.getSnapshotInfoHandler.getInfoWithoutTypeWithHook(hostSnapshot.remotesInfo, moduleInfo.name).value) {
908
+ if (hostSnapshot && 'remotesInfo' in hostSnapshot && !share.getInfoWithoutType(hostSnapshot.remotesInfo, moduleInfo.name).value) {
910
909
  if ('version' in moduleInfo || 'entry' in moduleInfo) {
911
910
  hostSnapshot.remotesInfo = _extends$1({}, hostSnapshot == null ? void 0 : hostSnapshot.remotesInfo, {
912
911
  [moduleInfo.name]: {
@@ -928,7 +927,11 @@ class SnapshotHandler {
928
927
  if (sdk.isManifestProvider(globalRemoteSnapshot)) {
929
928
  const moduleSnapshot = await this.getManifestJson(globalRemoteSnapshot.remoteEntry, moduleInfo, {});
930
929
  // eslint-disable-next-line @typescript-eslint/no-shadow
931
- const globalSnapshotRes = share.setGlobalSnapshotInfoByModuleInfo(_extends$1({}, moduleInfo), moduleSnapshot);
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);
932
935
  return {
933
936
  remoteSnapshot: moduleSnapshot,
934
937
  globalSnapshot: globalSnapshotRes
@@ -972,17 +975,17 @@ class SnapshotHandler {
972
975
  }
973
976
  }
974
977
  getGlobalRemoteInfo(moduleInfo) {
975
- const hostGlobalSnapshot = this.getSnapshotInfoHandler.getGlobalSnapshotInfoByModuleInfo({
978
+ const hostGlobalSnapshot = share.getGlobalSnapshotInfoByModuleInfo({
976
979
  name: this.HostInstance.options.name,
977
980
  version: this.HostInstance.options.version
978
981
  });
979
982
  // get remote detail info from global
980
- const globalRemoteInfo = hostGlobalSnapshot && 'remotesInfo' in hostGlobalSnapshot && hostGlobalSnapshot.remotesInfo && this.getSnapshotInfoHandler.getInfoWithoutTypeWithHook(hostGlobalSnapshot.remotesInfo, moduleInfo.name).value;
983
+ const globalRemoteInfo = hostGlobalSnapshot && 'remotesInfo' in hostGlobalSnapshot && hostGlobalSnapshot.remotesInfo && share.getInfoWithoutType(hostGlobalSnapshot.remotesInfo, moduleInfo.name).value;
981
984
  if (globalRemoteInfo && globalRemoteInfo.matchedVersion) {
982
985
  return {
983
986
  hostGlobalSnapshot,
984
987
  globalSnapshot: share.getGlobalSnapshot(),
985
- remoteSnapshot: this.getSnapshotInfoHandler.getGlobalSnapshotInfoByModuleInfo({
988
+ remoteSnapshot: share.getGlobalSnapshotInfoByModuleInfo({
986
989
  name: moduleInfo.name,
987
990
  version: globalRemoteInfo.matchedVersion
988
991
  })
@@ -991,7 +994,7 @@ class SnapshotHandler {
991
994
  return {
992
995
  hostGlobalSnapshot: undefined,
993
996
  globalSnapshot: share.getGlobalSnapshot(),
994
- remoteSnapshot: this.getSnapshotInfoHandler.getGlobalSnapshotInfoByModuleInfo({
997
+ remoteSnapshot: share.getGlobalSnapshotInfoByModuleInfo({
995
998
  name: moduleInfo.name,
996
999
  version: 'version' in moduleInfo ? moduleInfo.version : undefined
997
1000
  })
@@ -1049,7 +1052,6 @@ class SnapshotHandler {
1049
1052
  this.manifestLoading = share.Global.__FEDERATION__.__MANIFEST_LOADING__;
1050
1053
  this.HostInstance = HostInstance;
1051
1054
  this.loaderHook = HostInstance.loaderHook;
1052
- this.getSnapshotInfoHandler = new share.GetSnapshotInfoWithHook(this.loaderHook);
1053
1055
  }
1054
1056
  }
1055
1057
 
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 getPreloaded, m as setPreloaded, n as getRegisteredShare, o as addGlobalSnapshot, p as setGlobalSnapshotInfoByModuleInfo, q as getGlobalSnapshot, G as Global, r as GetSnapshotInfoWithHook, 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';
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';
3
3
  import { composeKeyWithSeparator, loadScriptNode, loadScript, createScript, getResourceUrl, isManifestProvider, generateSnapshotFromManifest } from '@module-federation/sdk';
4
4
  export { loadScript } from '@module-federation/sdk';
5
5
 
@@ -212,7 +212,6 @@ let Module = class Module {
212
212
  remoteInfo: this.remoteInfo,
213
213
  remoteEntryExports: this.remoteEntryExports,
214
214
  createScriptHook: (url)=>{
215
- console.log('xxxxxxx', this.host.loaderHook);
216
215
  const res = this.host.loaderHook.lifecycle.createScript.emit({
217
216
  url
218
217
  });
@@ -673,9 +672,9 @@ function splitId(id) {
673
672
  }
674
673
  }
675
674
  // Traverse all nodes in moduleInfo and traverse the entire snapshot
676
- function traverseModuleInfo(globalSnapshot, remoteInfo, traverse, isRoot, memo = {}, getSnapshotInfoWithHook, remoteSnapshot) {
675
+ function traverseModuleInfo(globalSnapshot, remoteInfo, traverse, isRoot, memo = {}, remoteSnapshot) {
677
676
  const id = getFMId(remoteInfo);
678
- const { value: snapshotValue } = getSnapshotInfoWithHook.getInfoWithoutTypeWithHook(globalSnapshot, id);
677
+ const { value: snapshotValue } = getInfoWithoutType(globalSnapshot, id);
679
678
  const effectiveRemoteSnapshot = remoteSnapshot || snapshotValue;
680
679
  if (effectiveRemoteSnapshot && !isManifestProvider(effectiveRemoteSnapshot)) {
681
680
  traverse(effectiveRemoteSnapshot, remoteInfo, isRoot);
@@ -691,7 +690,7 @@ function traverseModuleInfo(globalSnapshot, remoteInfo, traverse, isRoot, memo =
691
690
  traverseModuleInfo(globalSnapshot, {
692
691
  name: subRemoteInfo.name,
693
692
  version: remoteValue.matchedVersion
694
- }, traverse, false, memo, getSnapshotInfoWithHook, undefined);
693
+ }, traverse, false, memo, undefined);
695
694
  }
696
695
  }
697
696
  }
@@ -791,7 +790,7 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
791
790
  setPreloaded(exposeFullPath);
792
791
  }
793
792
  }
794
- }, true, memo, origin.snapshotHandler.getSnapshotInfoHandler, remoteSnapshot);
793
+ }, true, memo, remoteSnapshot);
795
794
  if (remoteSnapshot.shared) {
796
795
  remoteSnapshot.shared.forEach((shared)=>{
797
796
  var _options_shared;
@@ -888,7 +887,7 @@ class SnapshotHandler {
888
887
  options,
889
888
  moduleInfo
890
889
  });
891
- let hostSnapshot = this.getSnapshotInfoHandler.getGlobalSnapshotInfoByModuleInfo({
890
+ let hostSnapshot = getGlobalSnapshotInfoByModuleInfo({
892
891
  name: this.HostInstance.options.name,
893
892
  version: this.HostInstance.options.version
894
893
  });
@@ -904,7 +903,7 @@ class SnapshotHandler {
904
903
  }
905
904
  // 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.
906
905
  // 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.
907
- if (hostSnapshot && 'remotesInfo' in hostSnapshot && !this.getSnapshotInfoHandler.getInfoWithoutTypeWithHook(hostSnapshot.remotesInfo, moduleInfo.name).value) {
906
+ if (hostSnapshot && 'remotesInfo' in hostSnapshot && !getInfoWithoutType(hostSnapshot.remotesInfo, moduleInfo.name).value) {
908
907
  if ('version' in moduleInfo || 'entry' in moduleInfo) {
909
908
  hostSnapshot.remotesInfo = _extends$1({}, hostSnapshot == null ? void 0 : hostSnapshot.remotesInfo, {
910
909
  [moduleInfo.name]: {
@@ -926,7 +925,11 @@ class SnapshotHandler {
926
925
  if (isManifestProvider(globalRemoteSnapshot)) {
927
926
  const moduleSnapshot = await this.getManifestJson(globalRemoteSnapshot.remoteEntry, moduleInfo, {});
928
927
  // eslint-disable-next-line @typescript-eslint/no-shadow
929
- const globalSnapshotRes = setGlobalSnapshotInfoByModuleInfo(_extends$1({}, moduleInfo), moduleSnapshot);
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);
930
933
  return {
931
934
  remoteSnapshot: moduleSnapshot,
932
935
  globalSnapshot: globalSnapshotRes
@@ -970,17 +973,17 @@ class SnapshotHandler {
970
973
  }
971
974
  }
972
975
  getGlobalRemoteInfo(moduleInfo) {
973
- const hostGlobalSnapshot = this.getSnapshotInfoHandler.getGlobalSnapshotInfoByModuleInfo({
976
+ const hostGlobalSnapshot = getGlobalSnapshotInfoByModuleInfo({
974
977
  name: this.HostInstance.options.name,
975
978
  version: this.HostInstance.options.version
976
979
  });
977
980
  // get remote detail info from global
978
- const globalRemoteInfo = hostGlobalSnapshot && 'remotesInfo' in hostGlobalSnapshot && hostGlobalSnapshot.remotesInfo && this.getSnapshotInfoHandler.getInfoWithoutTypeWithHook(hostGlobalSnapshot.remotesInfo, moduleInfo.name).value;
981
+ const globalRemoteInfo = hostGlobalSnapshot && 'remotesInfo' in hostGlobalSnapshot && hostGlobalSnapshot.remotesInfo && getInfoWithoutType(hostGlobalSnapshot.remotesInfo, moduleInfo.name).value;
979
982
  if (globalRemoteInfo && globalRemoteInfo.matchedVersion) {
980
983
  return {
981
984
  hostGlobalSnapshot,
982
985
  globalSnapshot: getGlobalSnapshot(),
983
- remoteSnapshot: this.getSnapshotInfoHandler.getGlobalSnapshotInfoByModuleInfo({
986
+ remoteSnapshot: getGlobalSnapshotInfoByModuleInfo({
984
987
  name: moduleInfo.name,
985
988
  version: globalRemoteInfo.matchedVersion
986
989
  })
@@ -989,7 +992,7 @@ class SnapshotHandler {
989
992
  return {
990
993
  hostGlobalSnapshot: undefined,
991
994
  globalSnapshot: getGlobalSnapshot(),
992
- remoteSnapshot: this.getSnapshotInfoHandler.getGlobalSnapshotInfoByModuleInfo({
995
+ remoteSnapshot: getGlobalSnapshotInfoByModuleInfo({
993
996
  name: moduleInfo.name,
994
997
  version: 'version' in moduleInfo ? moduleInfo.version : undefined
995
998
  })
@@ -1047,7 +1050,6 @@ class SnapshotHandler {
1047
1050
  this.manifestLoading = Global.__FEDERATION__.__MANIFEST_LOADING__;
1048
1051
  this.HostInstance = HostInstance;
1049
1052
  this.loaderHook = HostInstance.loaderHook;
1050
- this.getSnapshotInfoHandler = new GetSnapshotInfoWithHook(this.loaderHook);
1051
1053
  }
1052
1054
  }
1053
1055
 
package/dist/share.cjs.js CHANGED
@@ -176,55 +176,61 @@ function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebug
176
176
  }
177
177
  // eslint-disable-next-line @typescript-eslint/ban-types
178
178
  function getInfoWithoutType(target, key) {
179
- return {
180
- value: target[key],
181
- key: key
182
- };
183
- }
184
- class GetSnapshotInfoWithHook {
185
- getInfoWithoutTypeWithHook(target, key) {
186
- let res = getInfoWithoutType(target, key);
187
- const hookRes = this.loaderHook.lifecycle.getModuleInfo.emit({
188
- target,
189
- key
190
- });
191
- if (hookRes && !(hookRes instanceof Promise)) {
192
- res = hookRes || res;
193
- }
194
- return res;
195
- }
196
- getTargetSnapshotInfoByModuleInfo(moduleInfo, snapshot) {
197
- // Check if the remote is included in the hostSnapshot
198
- const moduleKey = getFMId(moduleInfo);
199
- const getModuleInfo = this.getInfoWithoutTypeWithHook(snapshot, moduleKey).value;
200
- // The remoteSnapshot might not include a version
201
- if (getModuleInfo && !getModuleInfo.version && 'version' in moduleInfo && moduleInfo['version']) {
202
- getModuleInfo.version = moduleInfo['version'];
203
- }
204
- if (getModuleInfo) {
205
- return getModuleInfo;
206
- }
207
- // If the remote is not included in the hostSnapshot, deploy a micro app snapshot
208
- if ('version' in moduleInfo && moduleInfo['version']) {
209
- const { version } = moduleInfo, resModuleInfo = _object_without_properties_loose(moduleInfo, [
210
- "version"
211
- ]);
212
- const moduleKeyWithoutVersion = getFMId(resModuleInfo);
213
- const getModuleInfoWithoutVersion = this.getInfoWithoutTypeWithHook(nativeGlobal.__FEDERATION__.moduleInfo, moduleKeyWithoutVersion).value;
214
- if ((getModuleInfoWithoutVersion == null ? void 0 : getModuleInfoWithoutVersion.version) === version) {
215
- return getModuleInfoWithoutVersion;
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 (let 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
+ }
216
198
  }
199
+ return {
200
+ value: undefined,
201
+ key: key
202
+ };
217
203
  }
218
- return;
219
- }
220
- getGlobalSnapshotInfoByModuleInfo(moduleInfo) {
221
- return this.getTargetSnapshotInfoByModuleInfo(moduleInfo, nativeGlobal.__FEDERATION__.moduleInfo);
222
- }
223
- constructor(loaderHook){
224
- this.loaderHook = loaderHook;
204
+ } else {
205
+ throw new Error('key must be string');
225
206
  }
226
207
  }
227
208
  const getGlobalSnapshot = ()=>nativeGlobal.__FEDERATION__.moduleInfo;
209
+ const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot)=>{
210
+ // Check if the remote is included in the hostSnapshot
211
+ const moduleKey = getFMId(moduleInfo);
212
+ const getModuleInfo = getInfoWithoutType(snapshot, moduleKey).value;
213
+ // The remoteSnapshot might not include a version
214
+ if (getModuleInfo && !getModuleInfo.version && 'version' in moduleInfo && moduleInfo['version']) {
215
+ getModuleInfo.version = moduleInfo['version'];
216
+ }
217
+ if (getModuleInfo) {
218
+ return getModuleInfo;
219
+ }
220
+ // If the remote is not included in the hostSnapshot, deploy a micro app snapshot
221
+ if ('version' in moduleInfo && moduleInfo['version']) {
222
+ const { version } = moduleInfo, resModuleInfo = _object_without_properties_loose(moduleInfo, [
223
+ "version"
224
+ ]);
225
+ const moduleKeyWithoutVersion = getFMId(resModuleInfo);
226
+ const getModuleInfoWithoutVersion = getInfoWithoutType(nativeGlobal.__FEDERATION__.moduleInfo, moduleKeyWithoutVersion).value;
227
+ if ((getModuleInfoWithoutVersion == null ? void 0 : getModuleInfoWithoutVersion.version) === version) {
228
+ return getModuleInfoWithoutVersion;
229
+ }
230
+ }
231
+ return;
232
+ };
233
+ const getGlobalSnapshotInfoByModuleInfo = (moduleInfo)=>getTargetSnapshotInfoByModuleInfo(moduleInfo, nativeGlobal.__FEDERATION__.moduleInfo);
228
234
  const setGlobalSnapshotInfoByModuleInfo = (remoteInfo, moduleDetailInfo)=>{
229
235
  const moduleKey = getFMId(remoteInfo);
230
236
  nativeGlobal.__FEDERATION__.moduleInfo[moduleKey] = moduleDetailInfo;
@@ -784,7 +790,6 @@ function getGlobalShareScope() {
784
790
 
785
791
  exports.DEFAULT_REMOTE_TYPE = DEFAULT_REMOTE_TYPE;
786
792
  exports.DEFAULT_SCOPE = DEFAULT_SCOPE;
787
- exports.GetSnapshotInfoWithHook = GetSnapshotInfoWithHook;
788
793
  exports.Global = Global;
789
794
  exports.addGlobalSnapshot = addGlobalSnapshot;
790
795
  exports.addUniqueItem = addUniqueItem;
@@ -798,9 +803,12 @@ exports.getGlobalFederationInstance = getGlobalFederationInstance;
798
803
  exports.getGlobalHostPlugins = getGlobalHostPlugins;
799
804
  exports.getGlobalShareScope = getGlobalShareScope;
800
805
  exports.getGlobalSnapshot = getGlobalSnapshot;
806
+ exports.getGlobalSnapshotInfoByModuleInfo = getGlobalSnapshotInfoByModuleInfo;
807
+ exports.getInfoWithoutType = getInfoWithoutType;
801
808
  exports.getPreloaded = getPreloaded;
802
809
  exports.getRegisteredShare = getRegisteredShare;
803
810
  exports.getRemoteEntryExports = getRemoteEntryExports;
811
+ exports.getTargetSnapshotInfoByModuleInfo = getTargetSnapshotInfoByModuleInfo;
804
812
  exports.globalLoading = globalLoading;
805
813
  exports.isBrowserEnv = isBrowserEnv;
806
814
  exports.isObject = isObject;
package/dist/share.esm.js CHANGED
@@ -174,55 +174,61 @@ function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebug
174
174
  }
175
175
  // eslint-disable-next-line @typescript-eslint/ban-types
176
176
  function getInfoWithoutType(target, key) {
177
- return {
178
- value: target[key],
179
- key: key
180
- };
181
- }
182
- class GetSnapshotInfoWithHook {
183
- getInfoWithoutTypeWithHook(target, key) {
184
- let res = getInfoWithoutType(target, key);
185
- const hookRes = this.loaderHook.lifecycle.getModuleInfo.emit({
186
- target,
187
- key
188
- });
189
- if (hookRes && !(hookRes instanceof Promise)) {
190
- res = hookRes || res;
191
- }
192
- return res;
193
- }
194
- getTargetSnapshotInfoByModuleInfo(moduleInfo, snapshot) {
195
- // Check if the remote is included in the hostSnapshot
196
- const moduleKey = getFMId(moduleInfo);
197
- const getModuleInfo = this.getInfoWithoutTypeWithHook(snapshot, moduleKey).value;
198
- // The remoteSnapshot might not include a version
199
- if (getModuleInfo && !getModuleInfo.version && 'version' in moduleInfo && moduleInfo['version']) {
200
- getModuleInfo.version = moduleInfo['version'];
201
- }
202
- if (getModuleInfo) {
203
- return getModuleInfo;
204
- }
205
- // If the remote is not included in the hostSnapshot, deploy a micro app snapshot
206
- if ('version' in moduleInfo && moduleInfo['version']) {
207
- const { version } = moduleInfo, resModuleInfo = _object_without_properties_loose(moduleInfo, [
208
- "version"
209
- ]);
210
- const moduleKeyWithoutVersion = getFMId(resModuleInfo);
211
- const getModuleInfoWithoutVersion = this.getInfoWithoutTypeWithHook(nativeGlobal.__FEDERATION__.moduleInfo, moduleKeyWithoutVersion).value;
212
- if ((getModuleInfoWithoutVersion == null ? void 0 : getModuleInfoWithoutVersion.version) === version) {
213
- return getModuleInfoWithoutVersion;
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 (let 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
+ }
214
196
  }
197
+ return {
198
+ value: undefined,
199
+ key: key
200
+ };
215
201
  }
216
- return;
217
- }
218
- getGlobalSnapshotInfoByModuleInfo(moduleInfo) {
219
- return this.getTargetSnapshotInfoByModuleInfo(moduleInfo, nativeGlobal.__FEDERATION__.moduleInfo);
220
- }
221
- constructor(loaderHook){
222
- this.loaderHook = loaderHook;
202
+ } else {
203
+ throw new Error('key must be string');
223
204
  }
224
205
  }
225
206
  const getGlobalSnapshot = ()=>nativeGlobal.__FEDERATION__.moduleInfo;
207
+ const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot)=>{
208
+ // Check if the remote is included in the hostSnapshot
209
+ const moduleKey = getFMId(moduleInfo);
210
+ const getModuleInfo = getInfoWithoutType(snapshot, moduleKey).value;
211
+ // The remoteSnapshot might not include a version
212
+ if (getModuleInfo && !getModuleInfo.version && 'version' in moduleInfo && moduleInfo['version']) {
213
+ getModuleInfo.version = moduleInfo['version'];
214
+ }
215
+ if (getModuleInfo) {
216
+ return getModuleInfo;
217
+ }
218
+ // If the remote is not included in the hostSnapshot, deploy a micro app snapshot
219
+ if ('version' in moduleInfo && moduleInfo['version']) {
220
+ const { version } = moduleInfo, resModuleInfo = _object_without_properties_loose(moduleInfo, [
221
+ "version"
222
+ ]);
223
+ const moduleKeyWithoutVersion = getFMId(resModuleInfo);
224
+ const getModuleInfoWithoutVersion = getInfoWithoutType(nativeGlobal.__FEDERATION__.moduleInfo, moduleKeyWithoutVersion).value;
225
+ if ((getModuleInfoWithoutVersion == null ? void 0 : getModuleInfoWithoutVersion.version) === version) {
226
+ return getModuleInfoWithoutVersion;
227
+ }
228
+ }
229
+ return;
230
+ };
231
+ const getGlobalSnapshotInfoByModuleInfo = (moduleInfo)=>getTargetSnapshotInfoByModuleInfo(moduleInfo, nativeGlobal.__FEDERATION__.moduleInfo);
226
232
  const setGlobalSnapshotInfoByModuleInfo = (remoteInfo, moduleDetailInfo)=>{
227
233
  const moduleKey = getFMId(remoteInfo);
228
234
  nativeGlobal.__FEDERATION__.moduleInfo[moduleKey] = moduleDetailInfo;
@@ -780,4 +786,4 @@ function getGlobalShareScope() {
780
786
  return Global.__FEDERATION__.__SHARE__;
781
787
  }
782
788
 
783
- 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, 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, getPreloaded as l, setPreloaded as m, getRegisteredShare as n, addGlobalSnapshot as o, setGlobalSnapshotInfoByModuleInfo as p, getGlobalSnapshot as q, GetSnapshotInfoWithHook 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 };
789
+ 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 };
@@ -24,17 +24,13 @@ export declare function getGlobalFederationInstance(name: string, version: strin
24
24
  export declare function setGlobalFederationInstance(FederationInstance: FederationHost): void;
25
25
  export declare function getGlobalFederationConstructor(): typeof FederationHost | undefined;
26
26
  export declare function setGlobalFederationConstructor(FederationConstructor: typeof FederationHost | undefined, isDebug?: boolean): void;
27
- export declare class GetSnapshotInfoWithHook {
28
- loaderHook: FederationHost['loaderHook'];
29
- constructor(loaderHook: FederationHost['loaderHook']);
30
- getInfoWithoutTypeWithHook<T extends object>(target: T, key: keyof T): {
31
- value: T[keyof T] | undefined;
32
- key: string;
33
- };
34
- getTargetSnapshotInfoByModuleInfo(moduleInfo: Optional<Remote, 'alias'>, snapshot: GlobalModuleInfo): import("@module-federation/sdk").PureConsumerModuleInfo | import("@module-federation/sdk").ManifestProvider | undefined;
35
- getGlobalSnapshotInfoByModuleInfo(moduleInfo: Optional<Remote, 'alias'>): import("@module-federation/sdk").PureConsumerModuleInfo | import("@module-federation/sdk").ManifestProvider | undefined;
36
- }
27
+ export declare function getInfoWithoutType<T extends object>(target: T, key: keyof T): {
28
+ value: T[keyof T] | undefined;
29
+ key: string;
30
+ };
37
31
  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;
38
34
  export declare const setGlobalSnapshotInfoByModuleInfo: (remoteInfo: Remote, moduleDetailInfo: GlobalModuleInfo[string]) => GlobalModuleInfo;
39
35
  export declare const addGlobalSnapshot: (moduleInfos: GlobalModuleInfo) => (() => void);
40
36
  export declare const getRemoteEntryExports: (name: string, globalName: string | undefined) => {
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { resetFederationGlobalInfo, getGlobalFederationInstance, setGlobalFederationInstance, getGlobalFederationConstructor, setGlobalFederationConstructor, getGlobalSnapshot, setGlobalSnapshotInfoByModuleInfo, addGlobalSnapshot, getRemoteEntryExports, registerGlobalPlugins, getGlobalHostPlugins, getPreloaded, setPreloaded, Global } from './global';
2
+ import { resetFederationGlobalInfo, getGlobalFederationInstance, setGlobalFederationInstance, getGlobalFederationConstructor, setGlobalFederationConstructor, getInfoWithoutType, getGlobalSnapshot, getTargetSnapshotInfoByModuleInfo, getGlobalSnapshotInfoByModuleInfo, setGlobalSnapshotInfoByModuleInfo, addGlobalSnapshot, getRemoteEntryExports, registerGlobalPlugins, getGlobalHostPlugins, getPreloaded, setPreloaded, Global } from './global';
3
3
  import { getRegisteredShare, getGlobalShareScope } from './utils/share';
4
4
  interface IShareUtils {
5
5
  getRegisteredShare: typeof getRegisteredShare;
@@ -13,7 +13,10 @@ interface IGlobalUtils {
13
13
  setGlobalFederationInstance: typeof setGlobalFederationInstance;
14
14
  getGlobalFederationConstructor: typeof getGlobalFederationConstructor;
15
15
  setGlobalFederationConstructor: typeof setGlobalFederationConstructor;
16
+ getInfoWithoutType: typeof getInfoWithoutType;
16
17
  getGlobalSnapshot: typeof getGlobalSnapshot;
18
+ getTargetSnapshotInfoByModuleInfo: typeof getTargetSnapshotInfoByModuleInfo;
19
+ getGlobalSnapshotInfoByModuleInfo: typeof getGlobalSnapshotInfoByModuleInfo;
17
20
  setGlobalSnapshotInfoByModuleInfo: typeof setGlobalSnapshotInfoByModuleInfo;
18
21
  addGlobalSnapshot: typeof addGlobalSnapshot;
19
22
  getRemoteEntryExports: typeof getRemoteEntryExports;
@@ -1,6 +1,6 @@
1
1
  import { GlobalModuleInfo, Manifest, ModuleInfo } from '@module-federation/sdk';
2
2
  import { Options, Remote } from '../../type';
3
- import { getGlobalSnapshot, GetSnapshotInfoWithHook } from '../../global';
3
+ import { getGlobalSnapshot } from '../../global';
4
4
  import { PluginSystem, AsyncHook, AsyncWaterfallHook } from '../../utils/hooks';
5
5
  import { FederationHost } from '../../core';
6
6
  export declare class SnapshotHandler {
@@ -30,7 +30,6 @@ export declare class SnapshotHandler {
30
30
  }>;
31
31
  loaderHook: FederationHost['loaderHook'];
32
32
  manifestLoading: Record<string, Promise<ModuleInfo>>;
33
- getSnapshotInfoHandler: GetSnapshotInfoWithHook;
34
33
  constructor(HostInstance: FederationHost);
35
34
  loadSnapshot(moduleInfo: Remote): Promise<{
36
35
  remoteSnapshot: GlobalModuleInfo[string] | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/runtime",
3
- "version": "0.0.0-next-20240117093010",
3
+ "version": "0.0.0-next-20240119073703",
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-20240117093010"
48
+ "@module-federation/sdk": "0.0.0-next-20240119073703"
49
49
  }
50
50
  }