@module-federation/runtime 0.0.0-next-20231229091919 → 0.0.0-next-20231230034830

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