@module-federation/runtime 0.0.0-next-20231228055514 → 0.0.0-next-20231229074949

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.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() {
@@ -42,7 +41,7 @@ function isRemoteInfoWithEntry(remote) {
42
41
  return typeof remote.entry !== 'undefined';
43
42
  }
44
43
  function isPureRemoteEntry(remote) {
45
- return remote.entry.endsWith('.js');
44
+ return !remote.entry.includes('.json') && remote.entry.includes('.js');
46
45
  }
47
46
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
48
47
  function safeToString(info) {
@@ -87,61 +86,73 @@ 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;
91
89
  // export const nativeGlobal: typeof global = new Function('return this')();
92
90
  const nativeGlobal = new Function('return this')();
91
+ const Global = nativeGlobal;
92
+ function definePropertyGlobalVal(target, key, val) {
93
+ Object.defineProperty(target, key, {
94
+ value: val,
95
+ configurable: false,
96
+ writable: true
97
+ });
98
+ }
99
+ function includeOwnProperty(target, key) {
100
+ return Object.hasOwnProperty.call(target, key);
101
+ }
93
102
  // This section is to prevent encapsulation by certain microfrontend frameworks. Due to reuse policies, sandbox escapes.
94
103
  // The sandbox in the microfrontend does not replicate the value of 'configurable'.
95
104
  // If there is no loading content on the global object, this section defines the loading object.
96
- if (!Object.hasOwnProperty.call(globalThis, '__GLOBAL_LOADING_REMOTE_ENTRY__')) {
97
- Object.defineProperty(globalThis, '__GLOBAL_LOADING_REMOTE_ENTRY__', {
98
- value: {},
99
- configurable: false
100
- });
105
+ if (!includeOwnProperty(globalThis, '__GLOBAL_LOADING_REMOTE_ENTRY__')) {
106
+ definePropertyGlobalVal(globalThis, '__GLOBAL_LOADING_REMOTE_ENTRY__', {});
101
107
  }
102
108
  const globalLoading = globalThis.__GLOBAL_LOADING_REMOTE_ENTRY__;
103
- //
104
- if (nativeGlobal.__VMOK__) {
105
- nativeGlobal.__FEDERATION__ = nativeGlobal.__VMOK__;
106
- } else if (!nativeGlobal.__FEDERATION__) {
107
- nativeGlobal.__FEDERATION__ = {
108
- __GLOBAL_PLUGIN__: [],
109
- __INSTANCES__: [],
110
- moduleInfo: {},
111
- __SHARE__: {},
112
- __MANIFEST_LOADING__: {},
113
- __PRELOADED_MAP__: new Map()
114
- };
115
- nativeGlobal.__VMOK__ = nativeGlobal.__FEDERATION__;
116
- }
117
- var ___GLOBAL_PLUGIN__;
118
- (___GLOBAL_PLUGIN__ = (_nativeGlobal___FEDERATION__ = nativeGlobal.__FEDERATION__).__GLOBAL_PLUGIN__) != null ? ___GLOBAL_PLUGIN__ : _nativeGlobal___FEDERATION__.__GLOBAL_PLUGIN__ = [];
119
- var ___INSTANCES__;
120
- (___INSTANCES__ = (_nativeGlobal___FEDERATION__1 = nativeGlobal.__FEDERATION__).__INSTANCES__) != null ? ___INSTANCES__ : _nativeGlobal___FEDERATION__1.__INSTANCES__ = [];
121
- var _moduleInfo;
122
- (_moduleInfo = (_nativeGlobal___FEDERATION__2 = nativeGlobal.__FEDERATION__).moduleInfo) != null ? _moduleInfo : _nativeGlobal___FEDERATION__2.moduleInfo = {};
123
- var ___SHARE__;
124
- (___SHARE__ = (_nativeGlobal___FEDERATION__3 = nativeGlobal.__FEDERATION__).__SHARE__) != null ? ___SHARE__ : _nativeGlobal___FEDERATION__3.__SHARE__ = {};
125
- var ___MANIFEST_LOADING__;
126
- (___MANIFEST_LOADING__ = (_nativeGlobal___FEDERATION__4 = nativeGlobal.__FEDERATION__).__MANIFEST_LOADING__) != null ? ___MANIFEST_LOADING__ : _nativeGlobal___FEDERATION__4.__MANIFEST_LOADING__ = {};
127
- var ___PRELOADED_MAP__;
128
- (___PRELOADED_MAP__ = (_nativeGlobal___FEDERATION__5 = nativeGlobal.__FEDERATION__).__PRELOADED_MAP__) != null ? ___PRELOADED_MAP__ : _nativeGlobal___FEDERATION__5.__PRELOADED_MAP__ = new Map();
129
- const Global = {
130
- get __FEDERATION__ () {
131
- const globalThisVal = new Function('return globalThis')();
132
- return globalThisVal.__FEDERATION__;
109
+ function setGlobalDefaultVal(target) {
110
+ var _target___FEDERATION__, _target___FEDERATION__1, _target___FEDERATION__2, _target___FEDERATION__3, _target___FEDERATION__4, _target___FEDERATION__5, _target___FEDERATION__6;
111
+ if (includeOwnProperty(target, '__VMOK__') && !includeOwnProperty(target, '__FEDERATION__')) {
112
+ definePropertyGlobalVal(target, '__FEDERATION__', target.__VMOK__);
133
113
  }
134
- };
114
+ if (!includeOwnProperty(target, '__FEDERATION__')) {
115
+ definePropertyGlobalVal(target, '__FEDERATION__', {
116
+ __GLOBAL_PLUGIN__: [],
117
+ __INSTANCES__: [],
118
+ moduleInfo: {},
119
+ __SHARE__: {},
120
+ __MANIFEST_LOADING__: {},
121
+ __SHARE_SCOPE_LOADING__: {},
122
+ __PRELOADED_MAP__: new Map()
123
+ });
124
+ if (!includeOwnProperty(target, '__FEDERATION__')) {
125
+ definePropertyGlobalVal(target, '__VMOK__', target.__FEDERATION__);
126
+ }
127
+ }
128
+ var ___GLOBAL_PLUGIN__;
129
+ (___GLOBAL_PLUGIN__ = (_target___FEDERATION__ = target.__FEDERATION__).__GLOBAL_PLUGIN__) != null ? ___GLOBAL_PLUGIN__ : _target___FEDERATION__.__GLOBAL_PLUGIN__ = [];
130
+ var ___INSTANCES__;
131
+ (___INSTANCES__ = (_target___FEDERATION__1 = target.__FEDERATION__).__INSTANCES__) != null ? ___INSTANCES__ : _target___FEDERATION__1.__INSTANCES__ = [];
132
+ var _moduleInfo;
133
+ (_moduleInfo = (_target___FEDERATION__2 = target.__FEDERATION__).moduleInfo) != null ? _moduleInfo : _target___FEDERATION__2.moduleInfo = {};
134
+ var ___SHARE__;
135
+ (___SHARE__ = (_target___FEDERATION__3 = target.__FEDERATION__).__SHARE__) != null ? ___SHARE__ : _target___FEDERATION__3.__SHARE__ = {};
136
+ var ___MANIFEST_LOADING__;
137
+ (___MANIFEST_LOADING__ = (_target___FEDERATION__4 = target.__FEDERATION__).__MANIFEST_LOADING__) != null ? ___MANIFEST_LOADING__ : _target___FEDERATION__4.__MANIFEST_LOADING__ = {};
138
+ var ___SHARE_SCOPE_LOADING__;
139
+ (___SHARE_SCOPE_LOADING__ = (_target___FEDERATION__5 = target.__FEDERATION__).__SHARE_SCOPE_LOADING__) != null ? ___SHARE_SCOPE_LOADING__ : _target___FEDERATION__5.__SHARE_SCOPE_LOADING__ = {};
140
+ var ___PRELOADED_MAP__;
141
+ (___PRELOADED_MAP__ = (_target___FEDERATION__6 = target.__FEDERATION__).__PRELOADED_MAP__) != null ? ___PRELOADED_MAP__ : _target___FEDERATION__6.__PRELOADED_MAP__ = new Map();
142
+ }
143
+ setGlobalDefaultVal(globalThis);
144
+ setGlobalDefaultVal(nativeGlobal);
135
145
  function resetFederationGlobalInfo() {
136
- nativeGlobal.__FEDERATION__.__GLOBAL_PLUGIN__ = [];
137
- nativeGlobal.__FEDERATION__.__INSTANCES__ = [];
138
- nativeGlobal.__FEDERATION__.moduleInfo = {};
139
- nativeGlobal.__FEDERATION__.__SHARE__ = {};
140
- nativeGlobal.__FEDERATION__.__MANIFEST_LOADING__ = {};
146
+ globalThis.__FEDERATION__.__GLOBAL_PLUGIN__ = [];
147
+ globalThis.__FEDERATION__.__INSTANCES__ = [];
148
+ globalThis.__FEDERATION__.moduleInfo = {};
149
+ globalThis.__FEDERATION__.__SHARE__ = {};
150
+ globalThis.__FEDERATION__.__MANIFEST_LOADING__ = {};
151
+ globalThis.__FEDERATION__.__SHARE_SCOPE_LOADING__ = {};
141
152
  }
142
153
  function getGlobalFederationInstance(name, version) {
143
154
  const buildId = getBuilderId();
144
- return Global.__FEDERATION__.__INSTANCES__.find((GMInstance)=>{
155
+ return globalThis.__FEDERATION__.__INSTANCES__.find((GMInstance)=>{
145
156
  if (buildId && GMInstance.options.id === getBuilderId()) {
146
157
  return true;
147
158
  }
@@ -155,15 +166,15 @@ function getGlobalFederationInstance(name, version) {
155
166
  });
156
167
  }
157
168
  function setGlobalFederationInstance(FederationInstance) {
158
- Global.__FEDERATION__.__INSTANCES__.push(FederationInstance);
169
+ globalThis.__FEDERATION__.__INSTANCES__.push(FederationInstance);
159
170
  }
160
171
  function getGlobalFederationConstructor() {
161
- return Global.__FEDERATION__.__DEBUG_CONSTRUCTOR__;
172
+ return globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__;
162
173
  }
163
174
  function setGlobalFederationConstructor(FederationConstructor) {
164
175
  if (isDebugMode()) {
165
- Global.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
166
- Global.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = '0.0.4';
176
+ globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
177
+ globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = '0.0.4';
167
178
  }
168
179
  }
169
180
  // eslint-disable-next-line @typescript-eslint/ban-types
@@ -178,7 +189,7 @@ function getInfoWithoutType(target, key, getModuleInfoHook) {
178
189
  }
179
190
  return res;
180
191
  }
181
- const getGlobalSnapshot = ()=>Global.__FEDERATION__.moduleInfo;
192
+ const getGlobalSnapshot = ()=>nativeGlobal.__FEDERATION__.moduleInfo;
182
193
  const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot, getModuleInfoHook)=>{
183
194
  // Check if the remote is included in the hostSnapshot
184
195
  const moduleKey = getFMId(moduleInfo);
@@ -196,25 +207,25 @@ const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot, getModuleInfoHo
196
207
  "version"
197
208
  ]);
198
209
  const moduleKeyWithoutVersion = getFMId(resModuleInfo);
199
- const getModuleInfoWithoutVersion = getInfoWithoutType(Global.__FEDERATION__.moduleInfo, moduleKeyWithoutVersion, getModuleInfoHook).value;
210
+ const getModuleInfoWithoutVersion = getInfoWithoutType(nativeGlobal.__FEDERATION__.moduleInfo, moduleKeyWithoutVersion, getModuleInfoHook).value;
200
211
  if ((getModuleInfoWithoutVersion == null ? void 0 : getModuleInfoWithoutVersion.version) === version) {
201
212
  return getModuleInfoWithoutVersion;
202
213
  }
203
214
  }
204
215
  return;
205
216
  };
206
- const getGlobalSnapshotInfoByModuleInfo = (moduleInfo, extraOptions)=>getTargetSnapshotInfoByModuleInfo(moduleInfo, Global.__FEDERATION__.moduleInfo, extraOptions == null ? void 0 : extraOptions.getModuleInfoHook);
217
+ const getGlobalSnapshotInfoByModuleInfo = (moduleInfo, extraOptions)=>getTargetSnapshotInfoByModuleInfo(moduleInfo, nativeGlobal.__FEDERATION__.moduleInfo, extraOptions == null ? void 0 : extraOptions.getModuleInfoHook);
207
218
  const setGlobalSnapshotInfoByModuleInfo = (remoteInfo, moduleDetailInfo)=>{
208
219
  const moduleKey = getFMId(remoteInfo);
209
- Global.__FEDERATION__.moduleInfo[moduleKey] = moduleDetailInfo;
210
- return Global.__FEDERATION__.moduleInfo;
220
+ nativeGlobal.__FEDERATION__.moduleInfo[moduleKey] = moduleDetailInfo;
221
+ return nativeGlobal.__FEDERATION__.moduleInfo;
211
222
  };
212
223
  const addGlobalSnapshot = (moduleInfos)=>{
213
- Global.__FEDERATION__.moduleInfo = _extends$1({}, Global.__FEDERATION__.moduleInfo, moduleInfos);
224
+ nativeGlobal.__FEDERATION__.moduleInfo = _extends$1({}, nativeGlobal.__FEDERATION__.moduleInfo, moduleInfos);
214
225
  return ()=>{
215
226
  const keys = Object.keys(moduleInfos);
216
227
  for (const key of keys){
217
- delete Global.__FEDERATION__.moduleInfo[key];
228
+ delete nativeGlobal.__FEDERATION__.moduleInfo[key];
218
229
  }
219
230
  };
220
231
  };
@@ -231,7 +242,7 @@ const getRemoteEntryExports = (name, globalName)=>{
231
242
  // If a plugin is not registered, it is added to the global plugins.
232
243
  // If a plugin is already registered, a warning message is logged.
233
244
  const registerGlobalPlugins = (plugins)=>{
234
- const { __GLOBAL_PLUGIN__ } = Global.__FEDERATION__;
245
+ const { __GLOBAL_PLUGIN__ } = nativeGlobal.__FEDERATION__;
235
246
  plugins.forEach((plugin)=>{
236
247
  if (__GLOBAL_PLUGIN__.findIndex((p)=>p.name === plugin.name) === -1) {
237
248
  __GLOBAL_PLUGIN__.push(plugin);
@@ -240,9 +251,9 @@ const registerGlobalPlugins = (plugins)=>{
240
251
  }
241
252
  });
242
253
  };
243
- const getGlobalHostPlugins = ()=>Global.__FEDERATION__.__GLOBAL_PLUGIN__;
244
- const getPreloaded = (id)=>Global.__FEDERATION__.__PRELOADED_MAP__.get(id);
245
- const setPreloaded = (id)=>Global.__FEDERATION__.__PRELOADED_MAP__.set(id, true);
254
+ const getGlobalHostPlugins = ()=>nativeGlobal.__FEDERATION__.__GLOBAL_PLUGIN__;
255
+ const getPreloaded = (id)=>globalThis.__FEDERATION__.__PRELOADED_MAP__.get(id);
256
+ const setPreloaded = (id)=>globalThis.__FEDERATION__.__PRELOADED_MAP__.set(id, true);
246
257
 
247
258
  const DEFAULT_SCOPE = 'default';
248
259
  const DEFAULT_REMOTE_TYPE = 'global';
@@ -612,16 +623,14 @@ function formatShare(shareArgs, from) {
612
623
  deps: [],
613
624
  useIn: [],
614
625
  from,
615
- loading: null
616
- }, shareArgs, {
617
- shareConfig: _extends({
626
+ shareConfig: {
618
627
  requiredVersion: `^${shareArgs.version}`,
619
628
  singleton: false,
620
- eager: false,
621
- strictVersion: false
622
- }, shareArgs.shareConfig),
629
+ eager: false
630
+ },
631
+ loading: null
632
+ }, shareArgs, {
623
633
  get,
624
- loaded: 'lib' in shareArgs ? true : undefined,
625
634
  scope: Array.isArray(shareArgs.scope) ? shareArgs.scope : [
626
635
  'default'
627
636
  ],
@@ -638,26 +647,15 @@ function formatShareConfigs(shareArgs, from) {
638
647
  }, {});
639
648
  }
640
649
  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)}`)) {
650
+ if (satisfy(a, `<=${b}`)) {
654
651
  return true;
655
652
  } else {
656
653
  return false;
657
654
  }
658
655
  }
659
- const findVersion = (shareScopeMap, scope, pkgName, cb)=>{
660
- const versions = shareScopeMap[scope][pkgName];
656
+ const findVersion = (scope, pkgName, cb)=>{
657
+ const globalShares = Global.__FEDERATION__.__SHARE__;
658
+ const versions = globalShares[scope][pkgName];
661
659
  const callback = cb || function(prev, cur) {
662
660
  return versionLt(prev, cur);
663
661
  };
@@ -668,22 +666,20 @@ const findVersion = (shareScopeMap, scope, pkgName, cb)=>{
668
666
  if (callback(prev, cur)) {
669
667
  return cur;
670
668
  }
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
669
  return prev;
676
670
  }, 0);
677
671
  };
678
- function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) {
679
- const versions = shareScopeMap[scope][pkgName];
672
+ function findSingletonVersionOrderByVersion(scope, pkgName) {
673
+ const globalShares = Global.__FEDERATION__.__SHARE__;
674
+ const versions = globalShares[scope][pkgName];
680
675
  const callback = function(prev, cur) {
681
676
  return !versions[prev].loaded && versionLt(prev, cur);
682
677
  };
683
- return findVersion(shareScopeMap, scope, pkgName, callback);
678
+ return findVersion(scope, pkgName, callback);
684
679
  }
685
- function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
686
- const versions = shareScopeMap[scope][pkgName];
680
+ function findSingletonVersionOrderByLoaded(scope, pkgName) {
681
+ const globalShares = Global.__FEDERATION__.__SHARE__;
682
+ const versions = globalShares[scope][pkgName];
687
683
  const callback = function(prev, cur) {
688
684
  if (versions[cur].loaded) {
689
685
  if (versions[prev].loaded) {
@@ -697,62 +693,45 @@ function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
697
693
  }
698
694
  return versionLt(prev, cur);
699
695
  };
700
- return findVersion(shareScopeMap, scope, pkgName, callback);
701
- }
702
- function getFindShareFunction(strategy) {
703
- if (strategy === 'loaded-first') {
704
- return findSingletonVersionOrderByLoaded;
705
- }
706
- return findSingletonVersionOrderByVersion;
696
+ return findVersion(scope, pkgName, callback);
707
697
  }
708
698
  // Details about shared resources
709
699
  // TODO: Implement strictVersion for alignment with module federation.
710
- function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare) {
711
- if (!localShareScopeMap) {
712
- return;
713
- }
700
+ function getGlobalShare(pkgName, shareInfo) {
701
+ const globalShares = Global.__FEDERATION__.__SHARE__;
714
702
  const { shareConfig, scope = DEFAULT_SCOPE, strategy } = shareInfo;
715
703
  const scopes = Array.isArray(scope) ? scope : [
716
704
  scope
717
705
  ];
718
706
  for (const sc of scopes){
719
- if (shareConfig && localShareScopeMap[sc] && localShareScopeMap[sc][pkgName]) {
707
+ if (shareConfig && globalShares[sc] && globalShares[sc][pkgName]) {
720
708
  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
- }
709
+ // eslint-disable-next-line max-depth
710
+ if (shareConfig.singleton) {
711
+ const singletonVersion = strategy === 'loaded-first' ? findSingletonVersionOrderByLoaded(sc, pkgName) : findSingletonVersionOrderByVersion(sc, pkgName);
712
+ // eslint-disable-next-line max-depth
713
+ if (typeof requiredVersion === 'string' && !satisfy(singletonVersion, requiredVersion)) {
714
+ 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})`);
715
+ }
716
+ return globalShares[sc][pkgName][singletonVersion];
717
+ } else {
718
+ const maxVersion = findSingletonVersionOrderByLoaded(sc, pkgName);
719
+ // eslint-disable-next-line max-depth
720
+ if (requiredVersion === false || requiredVersion === '*') {
721
+ return globalShares[sc][pkgName][maxVersion];
722
+ }
723
+ // eslint-disable-next-line max-depth
724
+ if (satisfy(maxVersion, requiredVersion)) {
725
+ return globalShares[sc][pkgName][maxVersion];
726
+ }
727
+ // eslint-disable-next-line max-depth
728
+ for (const [versionKey, versionValue] of Object.entries(globalShares[sc][pkgName])){
729
+ // eslint-disable-next-line max-depth
730
+ if (satisfy(versionKey, requiredVersion)) {
731
+ return versionValue;
743
732
  }
744
733
  }
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();
734
+ }
756
735
  }
757
736
  }
758
737
  }
@@ -760,4 +739,4 @@ function getGlobalShareScope() {
760
739
  return Global.__FEDERATION__.__SHARE__;
761
740
  }
762
741
 
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 };
742
+ 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, Remote, Shared, ShareInfos, UserOptions, RemoteInfo } 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;
@@ -53,8 +52,6 @@ export declare class FederationHost {
53
52
  errorLoadRemote: AsyncHook<[{
54
53
  id: string;
55
54
  error: unknown;
56
- from: 'build' | 'runtime';
57
- origin: FederationHost;
58
55
  }], void>;
59
56
  beforeLoadShare: AsyncWaterfallHook<{
60
57
  pkgName: string;
@@ -63,14 +60,6 @@ export declare class FederationHost {
63
60
  origin: FederationHost;
64
61
  }>;
65
62
  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
63
  beforePreloadRemote: AsyncHook<{
75
64
  preloadOps: Array<PreloadRemoteArgs>;
76
65
  options: Options;
@@ -90,12 +79,10 @@ export declare class FederationHost {
90
79
  origin: FederationHost;
91
80
  }, false | void | Promise<false | void>>;
92
81
  }>;
93
- releaseNumber: string;
94
82
  version: string;
95
83
  name: string;
96
84
  moduleCache: Map<string, Module>;
97
85
  snapshotHandler: SnapshotHandler;
98
- shareScopeMap: ShareScopeMap;
99
86
  loaderHook: PluginSystem<{
100
87
  getModuleInfo: SyncHook<[{
101
88
  target: Record<string, any>;
@@ -109,15 +96,16 @@ export declare class FederationHost {
109
96
  }], void | HTMLScriptElement>;
110
97
  fetch: AsyncHook<[string, RequestInit], false | void | Promise<Response>>;
111
98
  }>;
99
+ loadingShare: {
100
+ [key: string]: Promise<any>;
101
+ };
112
102
  constructor(userOptions: UserOptions);
113
- private _setGlobalShareScopeMap;
114
103
  initOptions(userOptions: UserOptions): Options;
115
104
  loadShare<T>(pkgName: string, customShareInfo?: Partial<Shared>): Promise<false | (() => T | undefined)>;
116
105
  loadShareSync<T>(pkgName: string): () => T | never;
117
106
  private _getRemoteModuleAndOptions;
118
107
  loadRemote<T>(id: string, options?: {
119
108
  loadFactory?: boolean;
120
- from: 'build' | 'runtime';
121
109
  }): Promise<T | null>;
122
110
  preloadRemote(preloadOptions: Array<PreloadRemoteArgs>): Promise<void>;
123
111
  /**
@@ -125,8 +113,7 @@ export declare class FederationHost {
125
113
  * It accepts one argument, the name of the share scope.
126
114
  * If the share scope does not exist, it creates one.
127
115
  */
128
- initializeSharing(shareScopeName?: string, strategy?: Shared['strategy']): Array<Promise<void>>;
129
- initShareScopeMap(scopeName: string, shareScope: ShareScopeMap[string]): void;
116
+ initializeSharing(shareScopeName?: string): boolean | Promise<boolean>;
130
117
  private formatOptions;
131
118
  private registerPlugins;
132
119
  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,18 +9,17 @@ 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;
18
+ export declare const Global: typeof globalThis;
17
19
  declare global {
18
20
  var __FEDERATION__: Federation, __VMOK__: Federation, __GLOBAL_LOADING_REMOTE_ENTRY__: Record<string, undefined | Promise<RemoteEntryExports | void>>;
19
21
  }
20
22
  export declare const globalLoading: Record<string, Promise<void | RemoteEntryExports> | undefined>;
21
- export declare const Global: {
22
- readonly __FEDERATION__: Federation;
23
- };
24
23
  export declare function resetFederationGlobalInfo(): void;
25
24
  export declare function getGlobalFederationInstance(name: string, version: string | undefined): FederationHost | undefined;
26
25
  export declare function setGlobalFederationInstance(FederationInstance: FederationHost): void;
@@ -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,5 +1,5 @@
1
1
  import { FederationHost } from '../core';
2
- import { RemoteEntryExports, Options, Remote, ShareInfos, RemoteInfo, ShareScopeMap } from '../type';
2
+ import { RemoteEntryExports, Options, Remote, ShareInfos, RemoteInfo } from '../type';
3
3
  export type ModuleOptions = ConstructorParameters<typeof Module>[0];
4
4
  type HostInfo = Remote;
5
5
  declare class Module {
@@ -10,14 +10,12 @@ declare class Module {
10
10
  remoteEntryExports?: RemoteEntryExports;
11
11
  lib: RemoteEntryExports | undefined;
12
12
  loaderHook: FederationHost['loaderHook'];
13
- shareScopeMap: ShareScopeMap;
14
- constructor({ hostInfo, remoteInfo, shared, loaderHook, shareScopeMap, }: {
13
+ constructor({ hostInfo, remoteInfo, shared, loaderHook, }: {
15
14
  hostInfo: HostInfo;
16
15
  remoteInfo: RemoteInfo;
17
16
  shared: ShareInfos;
18
17
  plugins: Options['plugins'];
19
18
  loaderHook: FederationHost['loaderHook'];
20
- shareScopeMap: ShareScopeMap;
21
19
  });
22
20
  getEntry(): Promise<RemoteEntryExports>;
23
21
  get(expose: string, options?: {
@@ -29,7 +29,6 @@ export interface SharedConfig {
29
29
  singleton?: boolean;
30
30
  requiredVersion: false | string;
31
31
  eager?: boolean;
32
- strictVersion?: boolean;
33
32
  }
34
33
  type SharedBaseArgs = {
35
34
  version: string;
@@ -58,16 +57,13 @@ export type Shared = {
58
57
  eager?: boolean;
59
58
  strategy: 'version-first' | 'loaded-first';
60
59
  };
61
- export type ShareScopeMap = {
60
+ export type GlobalShareScope = {
62
61
  [scope: string]: {
63
62
  [pkgName: string]: {
64
63
  [sharedVersion: string]: Shared;
65
64
  };
66
65
  };
67
66
  };
68
- export type GlobalShareScopeMap = {
69
- [instanceName: string]: ShareScopeMap;
70
- };
71
67
  export type ShareInfos = {
72
68
  [pkgName: string]: Shared;
73
69
  };
@@ -93,6 +89,6 @@ export type RemoteEntryInitOptions = {
93
89
  };
94
90
  export type RemoteEntryExports = {
95
91
  get: (id: string) => () => Promise<Module>;
96
- init: (shareScope: ShareScopeMap[string], initScope?: Array<Record<string, any>>, remoteEntryInitOPtions?: RemoteEntryInitOptions) => void;
92
+ init: (shareScope: GlobalShareScope[string], initScope?: Array<Record<string, never>>, remoteEntryInitOPtions?: RemoteEntryInitOptions) => void;
97
93
  };
98
94
  export {};
@@ -1,16 +1,7 @@
1
- import { Federation } from '../global';
2
- import { GlobalShareScopeMap, Shared, ShareArgs, ShareInfos, ShareScopeMap } from '../type';
3
- import { SyncWaterfallHook } from './hooks';
1
+ import { GlobalShareScope, Shared, ShareArgs, ShareInfos } from '../type';
4
2
  export declare function formatShare(shareArgs: ShareArgs, from: string): Shared;
5
3
  export declare function formatShareConfigs(shareArgs: {
6
4
  [pkgName: string]: ShareArgs;
7
5
  }, from: string): ShareInfos;
8
- export declare function getRegisteredShare(localShareScopeMap: ShareScopeMap, pkgName: string, shareInfo: ShareInfos[keyof ShareInfos], resolveShare: SyncWaterfallHook<{
9
- shareScopeMap: ShareScopeMap;
10
- scope: string;
11
- pkgName: string;
12
- version: string;
13
- GlobalFederation: Federation;
14
- resolver: () => Shared | undefined;
15
- }>): Shared | void;
16
- export declare function getGlobalShareScope(): GlobalShareScopeMap;
6
+ export declare function getGlobalShare(pkgName: string, shareInfo: ShareInfos[keyof ShareInfos]): Shared | void;
7
+ export declare function getGlobalShareScope(): GlobalShareScope;
@@ -0,0 +1 @@
1
+ export * from "./src/type/index";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/runtime",
3
- "version": "0.0.0-next-20231228055514",
3
+ "version": "0.0.0-next-20231229074949",
4
4
  "author": "zhouxiao <codingzx@gmail.com>",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.esm.js",
@@ -39,12 +39,12 @@
39
39
  "helpers": [
40
40
  "./dist/helpers.cjs.d.ts"
41
41
  ],
42
- "types": [
43
- "./dist/types.cjs.d.ts"
42
+ "type": [
43
+ "./dist/type.cjs.d.ts"
44
44
  ]
45
45
  }
46
46
  },
47
47
  "dependencies": {
48
- "@module-federation/sdk": "0.0.0-next-20231228055514"
48
+ "@module-federation/sdk": "0.0.0-next-20231229074949"
49
49
  }
50
50
  }
@@ -1 +0,0 @@
1
- export * from "./src/types";
File without changes
File without changes