@module-federation/runtime 0.0.5 → 0.0.7

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.
@@ -7,6 +7,7 @@ const ShareUtils = {
7
7
  getGlobalShareScope: share.getGlobalShareScope
8
8
  };
9
9
  const GlobalUtils = {
10
+ Global: share.Global,
10
11
  nativeGlobal: share.nativeGlobal,
11
12
  resetFederationGlobalInfo: share.resetFederationGlobalInfo,
12
13
  getGlobalFederationInstance: share.getGlobalFederationInstance,
@@ -1,10 +1,11 @@
1
- import { l as getGlobalShare, x as getGlobalShareScope, F as nativeGlobal, H as resetFederationGlobalInfo, A as getGlobalFederationInstance, C as setGlobalFederationInstance, B as getGlobalFederationConstructor, z as setGlobalFederationConstructor, m as getInfoWithoutType, r as getGlobalSnapshot, I as getTargetSnapshotInfoByModuleInfo, p as getGlobalSnapshotInfoByModuleInfo, q as setGlobalSnapshotInfoByModuleInfo, J as addGlobalSnapshot, c as getRemoteEntryExports, E as registerGlobalPlugins, g as getGlobalHostPlugins, n as getPreloaded, o as setPreloaded } from './share.esm.js';
1
+ import { l as getGlobalShare, x as getGlobalShareScope, G as Global, F as nativeGlobal, H as resetFederationGlobalInfo, A as getGlobalFederationInstance, C as setGlobalFederationInstance, B as getGlobalFederationConstructor, z as setGlobalFederationConstructor, m as getInfoWithoutType, r as getGlobalSnapshot, I as getTargetSnapshotInfoByModuleInfo, p as getGlobalSnapshotInfoByModuleInfo, q as setGlobalSnapshotInfoByModuleInfo, J as addGlobalSnapshot, c as getRemoteEntryExports, E as registerGlobalPlugins, g as getGlobalHostPlugins, n as getPreloaded, o as setPreloaded } from './share.esm.js';
2
2
 
3
3
  const ShareUtils = {
4
4
  getGlobalShare,
5
5
  getGlobalShareScope
6
6
  };
7
7
  const GlobalUtils = {
8
+ Global,
8
9
  nativeGlobal,
9
10
  resetFederationGlobalInfo,
10
11
  getGlobalFederationInstance,
package/dist/index.cjs.js CHANGED
@@ -82,7 +82,7 @@ function registerPlugins(plugins, hookInstances) {
82
82
  if (plugins && plugins.length > 0) {
83
83
  plugins.forEach((plugin)=>{
84
84
  hookInstances.forEach((hookInstance)=>{
85
- hookInstance.usePlugin(plugin);
85
+ hookInstance.applyPlugin(plugin);
86
86
  });
87
87
  });
88
88
  }
@@ -191,7 +191,7 @@ let Module = class Module {
191
191
  remoteInfo: this.remoteInfo,
192
192
  remoteEntryExports: this.remoteEntryExports,
193
193
  createScriptHook: (url)=>{
194
- const res = this.loaderHook.lifecycle.createScript.emit({
194
+ const res = this.host.loaderHook.lifecycle.createScript.emit({
195
195
  url
196
196
  });
197
197
  if (res instanceof HTMLScriptElement) {
@@ -218,20 +218,21 @@ let Module = class Module {
218
218
  globalShareScope[remoteShareScope] = {};
219
219
  }
220
220
  const shareScope = globalShareScope[remoteShareScope];
221
- // TODO: compat logic , it could be moved after providing startup hooks
221
+ const initScope = [];
222
222
  const remoteEntryInitOptions = {
223
- version: this.remoteInfo.version || '',
224
- // @ts-ignore it will be passed by startup hooks
225
- region: this.hostInfo.region
223
+ version: this.remoteInfo.version || ''
226
224
  };
227
- remoteEntryExports.init(shareScope, [], remoteEntryInitOptions);
228
- const federationInstance = share.Global.__FEDERATION__.__INSTANCES__.find((i)=>i.options.id === sdk.composeKeyWithSeparator(this.remoteInfo.name, this.remoteInfo.buildVersion));
229
- if (federationInstance) {
230
- federationInstance.initOptions(_extends$4({}, remoteEntryInitOptions, {
231
- remotes: [],
232
- name: this.remoteInfo.name
233
- }));
234
- }
225
+ const initContainerOptions = await this.host.hooks.lifecycle.beforeInitContainer.emit({
226
+ shareScope,
227
+ remoteEntryInitOptions,
228
+ initScope,
229
+ remoteInfo: this.remoteInfo,
230
+ origin: this.host
231
+ });
232
+ remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
233
+ await this.host.hooks.lifecycle.initContainer.emit(_extends$4({}, initContainerOptions, {
234
+ remoteEntryExports
235
+ }));
235
236
  }
236
237
  this.lib = remoteEntryExports;
237
238
  this.inited = true;
@@ -244,15 +245,11 @@ let Module = class Module {
244
245
  const exposeContent = await moduleFactory();
245
246
  return exposeContent;
246
247
  }
247
- // loading: Record<string, undefined | Promise<RemoteEntryExports | void>> = {};
248
- constructor({ hostInfo, remoteInfo, shared, loaderHook }){
248
+ constructor({ remoteInfo, host }){
249
249
  this.inited = false;
250
- this.shared = {};
251
250
  this.lib = undefined;
252
- this.hostInfo = hostInfo;
253
251
  this.remoteInfo = remoteInfo;
254
- this.shared = shared;
255
- this.loaderHook = loaderHook;
252
+ this.host = host;
256
253
  }
257
254
  };
258
255
 
@@ -400,7 +397,7 @@ class AsyncWaterfallHook extends SyncHook {
400
397
  }
401
398
 
402
399
  class PluginSystem {
403
- usePlugin(plugin) {
400
+ applyPlugin(plugin) {
404
401
  share.assert(share.isPlainObject(plugin), 'Plugin configuration is invalid.');
405
402
  // The plugin's name is mandatory and must be unique
406
403
  const pluginName = plugin.name;
@@ -433,7 +430,7 @@ class PluginSystem {
433
430
  });
434
431
  Object.keys(registerPlugins).forEach((pluginName)=>{
435
432
  share.assert(!this.registerPlugins[pluginName], `The plugin "${pluginName}" has a conflict and cannot be inherited.`);
436
- this.usePlugin(registerPlugins[pluginName]);
433
+ this.applyPlugin(registerPlugins[pluginName]);
437
434
  });
438
435
  }
439
436
  constructor(lifecycle){
@@ -1267,14 +1264,8 @@ class FederationHost {
1267
1264
  share.assert(remote && expose, `The 'beforeRequest' hook was executed, but it failed to return the correct 'remote' and 'expose' values while loading ${idRes}.`);
1268
1265
  let module = this.moduleCache.get(remote.name);
1269
1266
  const moduleOptions = {
1270
- hostInfo: {
1271
- name: this.options.name,
1272
- version: this.options.version || 'custom'
1273
- },
1274
- remoteInfo,
1275
- shared: this.options.shared || {},
1276
- plugins: this.options.plugins,
1277
- loaderHook: this.loaderHook
1267
+ host: this,
1268
+ remoteInfo
1278
1269
  };
1279
1270
  if (!module) {
1280
1271
  module = new Module(moduleOptions);
@@ -1529,6 +1520,8 @@ class FederationHost {
1529
1520
  init: new SyncHook(),
1530
1521
  beforeRequest: new AsyncWaterfallHook('beforeRequest'),
1531
1522
  afterResolve: new AsyncWaterfallHook('afterResolve'),
1523
+ beforeInitContainer: new AsyncWaterfallHook('beforeInitContainer'),
1524
+ initContainer: new AsyncWaterfallHook('initContainer'),
1532
1525
  onLoad: new AsyncHook('onLoad'),
1533
1526
  handlePreloadModule: new SyncHook('handlePreloadModule'),
1534
1527
  errorLoadRemote: new AsyncHook('errorLoadRemote'),
@@ -1538,7 +1531,7 @@ class FederationHost {
1538
1531
  generatePreloadAssets: new AsyncHook('generatePreloadAssets'),
1539
1532
  afterPreloadRemote: new AsyncHook()
1540
1533
  });
1541
- this.version = '0.0.5';
1534
+ this.version = '0.0.7';
1542
1535
  this.moduleCache = new Map();
1543
1536
  this.loaderHook = new PluginSystem({
1544
1537
  // FIXME: may not be suitable
package/dist/index.esm.js CHANGED
@@ -79,7 +79,7 @@ function registerPlugins(plugins, hookInstances) {
79
79
  if (plugins && plugins.length > 0) {
80
80
  plugins.forEach((plugin)=>{
81
81
  hookInstances.forEach((hookInstance)=>{
82
- hookInstance.usePlugin(plugin);
82
+ hookInstance.applyPlugin(plugin);
83
83
  });
84
84
  });
85
85
  }
@@ -188,7 +188,7 @@ let Module = class Module {
188
188
  remoteInfo: this.remoteInfo,
189
189
  remoteEntryExports: this.remoteEntryExports,
190
190
  createScriptHook: (url)=>{
191
- const res = this.loaderHook.lifecycle.createScript.emit({
191
+ const res = this.host.loaderHook.lifecycle.createScript.emit({
192
192
  url
193
193
  });
194
194
  if (res instanceof HTMLScriptElement) {
@@ -215,20 +215,21 @@ let Module = class Module {
215
215
  globalShareScope[remoteShareScope] = {};
216
216
  }
217
217
  const shareScope = globalShareScope[remoteShareScope];
218
- // TODO: compat logic , it could be moved after providing startup hooks
218
+ const initScope = [];
219
219
  const remoteEntryInitOptions = {
220
- version: this.remoteInfo.version || '',
221
- // @ts-ignore it will be passed by startup hooks
222
- region: this.hostInfo.region
220
+ version: this.remoteInfo.version || ''
223
221
  };
224
- remoteEntryExports.init(shareScope, [], remoteEntryInitOptions);
225
- const federationInstance = Global.__FEDERATION__.__INSTANCES__.find((i)=>i.options.id === composeKeyWithSeparator(this.remoteInfo.name, this.remoteInfo.buildVersion));
226
- if (federationInstance) {
227
- federationInstance.initOptions(_extends$4({}, remoteEntryInitOptions, {
228
- remotes: [],
229
- name: this.remoteInfo.name
230
- }));
231
- }
222
+ const initContainerOptions = await this.host.hooks.lifecycle.beforeInitContainer.emit({
223
+ shareScope,
224
+ remoteEntryInitOptions,
225
+ initScope,
226
+ remoteInfo: this.remoteInfo,
227
+ origin: this.host
228
+ });
229
+ remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
230
+ await this.host.hooks.lifecycle.initContainer.emit(_extends$4({}, initContainerOptions, {
231
+ remoteEntryExports
232
+ }));
232
233
  }
233
234
  this.lib = remoteEntryExports;
234
235
  this.inited = true;
@@ -241,15 +242,11 @@ let Module = class Module {
241
242
  const exposeContent = await moduleFactory();
242
243
  return exposeContent;
243
244
  }
244
- // loading: Record<string, undefined | Promise<RemoteEntryExports | void>> = {};
245
- constructor({ hostInfo, remoteInfo, shared, loaderHook }){
245
+ constructor({ remoteInfo, host }){
246
246
  this.inited = false;
247
- this.shared = {};
248
247
  this.lib = undefined;
249
- this.hostInfo = hostInfo;
250
248
  this.remoteInfo = remoteInfo;
251
- this.shared = shared;
252
- this.loaderHook = loaderHook;
249
+ this.host = host;
253
250
  }
254
251
  };
255
252
 
@@ -397,7 +394,7 @@ class AsyncWaterfallHook extends SyncHook {
397
394
  }
398
395
 
399
396
  class PluginSystem {
400
- usePlugin(plugin) {
397
+ applyPlugin(plugin) {
401
398
  assert(isPlainObject(plugin), 'Plugin configuration is invalid.');
402
399
  // The plugin's name is mandatory and must be unique
403
400
  const pluginName = plugin.name;
@@ -430,7 +427,7 @@ class PluginSystem {
430
427
  });
431
428
  Object.keys(registerPlugins).forEach((pluginName)=>{
432
429
  assert(!this.registerPlugins[pluginName], `The plugin "${pluginName}" has a conflict and cannot be inherited.`);
433
- this.usePlugin(registerPlugins[pluginName]);
430
+ this.applyPlugin(registerPlugins[pluginName]);
434
431
  });
435
432
  }
436
433
  constructor(lifecycle){
@@ -1264,14 +1261,8 @@ class FederationHost {
1264
1261
  assert(remote && expose, `The 'beforeRequest' hook was executed, but it failed to return the correct 'remote' and 'expose' values while loading ${idRes}.`);
1265
1262
  let module = this.moduleCache.get(remote.name);
1266
1263
  const moduleOptions = {
1267
- hostInfo: {
1268
- name: this.options.name,
1269
- version: this.options.version || 'custom'
1270
- },
1271
- remoteInfo,
1272
- shared: this.options.shared || {},
1273
- plugins: this.options.plugins,
1274
- loaderHook: this.loaderHook
1264
+ host: this,
1265
+ remoteInfo
1275
1266
  };
1276
1267
  if (!module) {
1277
1268
  module = new Module(moduleOptions);
@@ -1526,6 +1517,8 @@ class FederationHost {
1526
1517
  init: new SyncHook(),
1527
1518
  beforeRequest: new AsyncWaterfallHook('beforeRequest'),
1528
1519
  afterResolve: new AsyncWaterfallHook('afterResolve'),
1520
+ beforeInitContainer: new AsyncWaterfallHook('beforeInitContainer'),
1521
+ initContainer: new AsyncWaterfallHook('initContainer'),
1529
1522
  onLoad: new AsyncHook('onLoad'),
1530
1523
  handlePreloadModule: new SyncHook('handlePreloadModule'),
1531
1524
  errorLoadRemote: new AsyncHook('errorLoadRemote'),
@@ -1535,7 +1528,7 @@ class FederationHost {
1535
1528
  generatePreloadAssets: new AsyncHook('generatePreloadAssets'),
1536
1529
  afterPreloadRemote: new AsyncHook()
1537
1530
  });
1538
- this.version = '0.0.5';
1531
+ this.version = '0.0.7';
1539
1532
  this.moduleCache = new Map();
1540
1533
  this.loaderHook = new PluginSystem({
1541
1534
  // FIXME: may not be suitable
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/runtime",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "author": "zhouxiao <codingzx@gmail.com>",
5
5
  "main": "./index.cjs.js",
6
6
  "module": "./index.esm.js",
package/dist/share.cjs.js CHANGED
@@ -88,69 +88,75 @@ function _object_without_properties_loose(source, excluded) {
88
88
  }
89
89
  return target;
90
90
  }
91
- var _nativeGlobal___FEDERATION__, _nativeGlobal___FEDERATION__1, _nativeGlobal___FEDERATION__2, _nativeGlobal___FEDERATION__3, _nativeGlobal___FEDERATION__4, _nativeGlobal___FEDERATION__5, _nativeGlobal___FEDERATION__6;
92
91
  // export const nativeGlobal: typeof global = new Function('return this')();
93
92
  const nativeGlobal = new Function('return this')();
93
+ const Global = nativeGlobal;
94
+ function definePropertyGlobalVal(target, key, val) {
95
+ Object.defineProperty(target, key, {
96
+ value: val,
97
+ configurable: false,
98
+ writable: true
99
+ });
100
+ }
101
+ function includeOwnProperty(target, key) {
102
+ return Object.hasOwnProperty.call(target, key);
103
+ }
94
104
  // This section is to prevent encapsulation by certain microfrontend frameworks. Due to reuse policies, sandbox escapes.
95
105
  // The sandbox in the microfrontend does not replicate the value of 'configurable'.
96
106
  // If there is no loading content on the global object, this section defines the loading object.
97
- if (!Object.hasOwnProperty.call(globalThis, '__GLOBAL_LOADING_REMOTE_ENTRY__')) {
98
- Object.defineProperty(globalThis, '__GLOBAL_LOADING_REMOTE_ENTRY__', {
99
- value: {},
100
- configurable: false
101
- });
107
+ if (!includeOwnProperty(globalThis, '__GLOBAL_LOADING_REMOTE_ENTRY__')) {
108
+ definePropertyGlobalVal(globalThis, '__GLOBAL_LOADING_REMOTE_ENTRY__', {});
102
109
  }
103
110
  const globalLoading = globalThis.__GLOBAL_LOADING_REMOTE_ENTRY__;
104
- //
105
- if (nativeGlobal.__VMOK__) {
106
- nativeGlobal.__FEDERATION__ = nativeGlobal.__VMOK__;
107
- } else if (!nativeGlobal.__FEDERATION__) {
108
- nativeGlobal.__FEDERATION__ = {
109
- __GLOBAL_PLUGIN__: [],
110
- __INSTANCES__: [],
111
- moduleInfo: {},
112
- __SHARE__: {},
113
- __MANIFEST_LOADING__: {},
114
- __SHARE_SCOPE_LOADING__: {},
115
- __PRELOADED_MAP__: new Map()
116
- };
117
- nativeGlobal.__VMOK__ = nativeGlobal.__FEDERATION__;
118
- }
119
- var ___GLOBAL_PLUGIN__;
120
- (___GLOBAL_PLUGIN__ = (_nativeGlobal___FEDERATION__ = nativeGlobal.__FEDERATION__).__GLOBAL_PLUGIN__) != null ? ___GLOBAL_PLUGIN__ : _nativeGlobal___FEDERATION__.__GLOBAL_PLUGIN__ = [];
121
- var ___INSTANCES__;
122
- (___INSTANCES__ = (_nativeGlobal___FEDERATION__1 = nativeGlobal.__FEDERATION__).__INSTANCES__) != null ? ___INSTANCES__ : _nativeGlobal___FEDERATION__1.__INSTANCES__ = [];
123
- var _moduleInfo;
124
- (_moduleInfo = (_nativeGlobal___FEDERATION__2 = nativeGlobal.__FEDERATION__).moduleInfo) != null ? _moduleInfo : _nativeGlobal___FEDERATION__2.moduleInfo = {};
125
- var ___SHARE__;
126
- (___SHARE__ = (_nativeGlobal___FEDERATION__3 = nativeGlobal.__FEDERATION__).__SHARE__) != null ? ___SHARE__ : _nativeGlobal___FEDERATION__3.__SHARE__ = {};
127
- var ___MANIFEST_LOADING__;
128
- (___MANIFEST_LOADING__ = (_nativeGlobal___FEDERATION__4 = nativeGlobal.__FEDERATION__).__MANIFEST_LOADING__) != null ? ___MANIFEST_LOADING__ : _nativeGlobal___FEDERATION__4.__MANIFEST_LOADING__ = {};
129
- var ___SHARE_SCOPE_LOADING__;
130
- (___SHARE_SCOPE_LOADING__ = (_nativeGlobal___FEDERATION__5 = nativeGlobal.__FEDERATION__).__SHARE_SCOPE_LOADING__) != null ? ___SHARE_SCOPE_LOADING__ : _nativeGlobal___FEDERATION__5.__SHARE_SCOPE_LOADING__ = {};
131
- var ___PRELOADED_MAP__;
132
- (___PRELOADED_MAP__ = (_nativeGlobal___FEDERATION__6 = nativeGlobal.__FEDERATION__).__PRELOADED_MAP__) != null ? ___PRELOADED_MAP__ : _nativeGlobal___FEDERATION__6.__PRELOADED_MAP__ = new Map();
133
- const Global = {
134
- get __FEDERATION__ () {
135
- const globalThisVal = new Function('return globalThis')();
136
- return globalThisVal.__FEDERATION__;
111
+ function setGlobalDefaultVal(target) {
112
+ var _target___FEDERATION__, _target___FEDERATION__1, _target___FEDERATION__2, _target___FEDERATION__3, _target___FEDERATION__4, _target___FEDERATION__5, _target___FEDERATION__6;
113
+ if (includeOwnProperty(target, '__VMOK__') && !includeOwnProperty(target, '__FEDERATION__')) {
114
+ definePropertyGlobalVal(target, '__FEDERATION__', target.__VMOK__);
137
115
  }
138
- };
116
+ if (!includeOwnProperty(target, '__FEDERATION__')) {
117
+ definePropertyGlobalVal(target, '__FEDERATION__', {
118
+ __GLOBAL_PLUGIN__: [],
119
+ __INSTANCES__: [],
120
+ moduleInfo: {},
121
+ __SHARE__: {},
122
+ __MANIFEST_LOADING__: {},
123
+ __SHARE_SCOPE_LOADING__: {},
124
+ __PRELOADED_MAP__: new Map()
125
+ });
126
+ definePropertyGlobalVal(target, '__VMOK__', target.__FEDERATION__);
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);
139
145
  function resetFederationGlobalInfo() {
140
- nativeGlobal.__FEDERATION__.__GLOBAL_PLUGIN__ = [];
141
- nativeGlobal.__FEDERATION__.__INSTANCES__ = [];
142
- nativeGlobal.__FEDERATION__.moduleInfo = {};
143
- nativeGlobal.__FEDERATION__.__SHARE__ = {};
144
- nativeGlobal.__FEDERATION__.__MANIFEST_LOADING__ = {};
145
- nativeGlobal.__FEDERATION__.__SHARE_SCOPE_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__ = {};
146
152
  }
147
153
  function getGlobalFederationInstance(name, version) {
148
154
  const buildId = getBuilderId();
149
- return Global.__FEDERATION__.__INSTANCES__.find((GMInstance)=>{
155
+ return globalThis.__FEDERATION__.__INSTANCES__.find((GMInstance)=>{
150
156
  if (buildId && GMInstance.options.id === getBuilderId()) {
151
157
  return true;
152
158
  }
153
- if (GMInstance.options.name === name && !version) {
159
+ if (GMInstance.options.name === name && !GMInstance.options.version && !version) {
154
160
  return true;
155
161
  }
156
162
  if (GMInstance.options.name === name && version && GMInstance.options.version === version) {
@@ -160,15 +166,15 @@ function getGlobalFederationInstance(name, version) {
160
166
  });
161
167
  }
162
168
  function setGlobalFederationInstance(FederationInstance) {
163
- Global.__FEDERATION__.__INSTANCES__.push(FederationInstance);
169
+ globalThis.__FEDERATION__.__INSTANCES__.push(FederationInstance);
164
170
  }
165
171
  function getGlobalFederationConstructor() {
166
- return Global.__FEDERATION__.__DEBUG_CONSTRUCTOR__;
172
+ return globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__;
167
173
  }
168
174
  function setGlobalFederationConstructor(FederationConstructor) {
169
175
  if (isDebugMode()) {
170
- Global.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
171
- Global.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = '0.0.5';
176
+ globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
177
+ globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = '0.0.7';
172
178
  }
173
179
  }
174
180
  // eslint-disable-next-line @typescript-eslint/ban-types
@@ -183,7 +189,7 @@ function getInfoWithoutType(target, key, getModuleInfoHook) {
183
189
  }
184
190
  return res;
185
191
  }
186
- const getGlobalSnapshot = ()=>Global.__FEDERATION__.moduleInfo;
192
+ const getGlobalSnapshot = ()=>nativeGlobal.__FEDERATION__.moduleInfo;
187
193
  const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot, getModuleInfoHook)=>{
188
194
  // Check if the remote is included in the hostSnapshot
189
195
  const moduleKey = getFMId(moduleInfo);
@@ -201,25 +207,25 @@ const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot, getModuleInfoHo
201
207
  "version"
202
208
  ]);
203
209
  const moduleKeyWithoutVersion = getFMId(resModuleInfo);
204
- const getModuleInfoWithoutVersion = getInfoWithoutType(Global.__FEDERATION__.moduleInfo, moduleKeyWithoutVersion, getModuleInfoHook).value;
210
+ const getModuleInfoWithoutVersion = getInfoWithoutType(nativeGlobal.__FEDERATION__.moduleInfo, moduleKeyWithoutVersion, getModuleInfoHook).value;
205
211
  if ((getModuleInfoWithoutVersion == null ? void 0 : getModuleInfoWithoutVersion.version) === version) {
206
212
  return getModuleInfoWithoutVersion;
207
213
  }
208
214
  }
209
215
  return;
210
216
  };
211
- 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);
212
218
  const setGlobalSnapshotInfoByModuleInfo = (remoteInfo, moduleDetailInfo)=>{
213
219
  const moduleKey = getFMId(remoteInfo);
214
- Global.__FEDERATION__.moduleInfo[moduleKey] = moduleDetailInfo;
215
- return Global.__FEDERATION__.moduleInfo;
220
+ nativeGlobal.__FEDERATION__.moduleInfo[moduleKey] = moduleDetailInfo;
221
+ return nativeGlobal.__FEDERATION__.moduleInfo;
216
222
  };
217
223
  const addGlobalSnapshot = (moduleInfos)=>{
218
- Global.__FEDERATION__.moduleInfo = _extends$1({}, Global.__FEDERATION__.moduleInfo, moduleInfos);
224
+ nativeGlobal.__FEDERATION__.moduleInfo = _extends$1({}, nativeGlobal.__FEDERATION__.moduleInfo, moduleInfos);
219
225
  return ()=>{
220
226
  const keys = Object.keys(moduleInfos);
221
227
  for (const key of keys){
222
- delete Global.__FEDERATION__.moduleInfo[key];
228
+ delete nativeGlobal.__FEDERATION__.moduleInfo[key];
223
229
  }
224
230
  };
225
231
  };
@@ -236,7 +242,7 @@ const getRemoteEntryExports = (name, globalName)=>{
236
242
  // If a plugin is not registered, it is added to the global plugins.
237
243
  // If a plugin is already registered, a warning message is logged.
238
244
  const registerGlobalPlugins = (plugins)=>{
239
- const { __GLOBAL_PLUGIN__ } = Global.__FEDERATION__;
245
+ const { __GLOBAL_PLUGIN__ } = nativeGlobal.__FEDERATION__;
240
246
  plugins.forEach((plugin)=>{
241
247
  if (__GLOBAL_PLUGIN__.findIndex((p)=>p.name === plugin.name) === -1) {
242
248
  __GLOBAL_PLUGIN__.push(plugin);
@@ -245,9 +251,9 @@ const registerGlobalPlugins = (plugins)=>{
245
251
  }
246
252
  });
247
253
  };
248
- const getGlobalHostPlugins = ()=>Global.__FEDERATION__.__GLOBAL_PLUGIN__;
249
- const getPreloaded = (id)=>Global.__FEDERATION__.__PRELOADED_MAP__.get(id);
250
- 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);
251
257
 
252
258
  const DEFAULT_SCOPE = 'default';
253
259
  const DEFAULT_REMOTE_TYPE = 'global';
package/dist/share.esm.js CHANGED
@@ -86,69 +86,75 @@ function _object_without_properties_loose(source, excluded) {
86
86
  }
87
87
  return target;
88
88
  }
89
- var _nativeGlobal___FEDERATION__, _nativeGlobal___FEDERATION__1, _nativeGlobal___FEDERATION__2, _nativeGlobal___FEDERATION__3, _nativeGlobal___FEDERATION__4, _nativeGlobal___FEDERATION__5, _nativeGlobal___FEDERATION__6;
90
89
  // export const nativeGlobal: typeof global = new Function('return this')();
91
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
+ }
92
102
  // This section is to prevent encapsulation by certain microfrontend frameworks. Due to reuse policies, sandbox escapes.
93
103
  // The sandbox in the microfrontend does not replicate the value of 'configurable'.
94
104
  // If there is no loading content on the global object, this section defines the loading object.
95
- if (!Object.hasOwnProperty.call(globalThis, '__GLOBAL_LOADING_REMOTE_ENTRY__')) {
96
- Object.defineProperty(globalThis, '__GLOBAL_LOADING_REMOTE_ENTRY__', {
97
- value: {},
98
- configurable: false
99
- });
105
+ if (!includeOwnProperty(globalThis, '__GLOBAL_LOADING_REMOTE_ENTRY__')) {
106
+ definePropertyGlobalVal(globalThis, '__GLOBAL_LOADING_REMOTE_ENTRY__', {});
100
107
  }
101
108
  const globalLoading = globalThis.__GLOBAL_LOADING_REMOTE_ENTRY__;
102
- //
103
- if (nativeGlobal.__VMOK__) {
104
- nativeGlobal.__FEDERATION__ = nativeGlobal.__VMOK__;
105
- } else if (!nativeGlobal.__FEDERATION__) {
106
- nativeGlobal.__FEDERATION__ = {
107
- __GLOBAL_PLUGIN__: [],
108
- __INSTANCES__: [],
109
- moduleInfo: {},
110
- __SHARE__: {},
111
- __MANIFEST_LOADING__: {},
112
- __SHARE_SCOPE_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 ___SHARE_SCOPE_LOADING__;
128
- (___SHARE_SCOPE_LOADING__ = (_nativeGlobal___FEDERATION__5 = nativeGlobal.__FEDERATION__).__SHARE_SCOPE_LOADING__) != null ? ___SHARE_SCOPE_LOADING__ : _nativeGlobal___FEDERATION__5.__SHARE_SCOPE_LOADING__ = {};
129
- var ___PRELOADED_MAP__;
130
- (___PRELOADED_MAP__ = (_nativeGlobal___FEDERATION__6 = nativeGlobal.__FEDERATION__).__PRELOADED_MAP__) != null ? ___PRELOADED_MAP__ : _nativeGlobal___FEDERATION__6.__PRELOADED_MAP__ = new Map();
131
- const Global = {
132
- get __FEDERATION__ () {
133
- const globalThisVal = new Function('return globalThis')();
134
- 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__);
135
113
  }
136
- };
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__);
125
+ }
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);
137
143
  function resetFederationGlobalInfo() {
138
- nativeGlobal.__FEDERATION__.__GLOBAL_PLUGIN__ = [];
139
- nativeGlobal.__FEDERATION__.__INSTANCES__ = [];
140
- nativeGlobal.__FEDERATION__.moduleInfo = {};
141
- nativeGlobal.__FEDERATION__.__SHARE__ = {};
142
- nativeGlobal.__FEDERATION__.__MANIFEST_LOADING__ = {};
143
- nativeGlobal.__FEDERATION__.__SHARE_SCOPE_LOADING__ = {};
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__ = {};
144
150
  }
145
151
  function getGlobalFederationInstance(name, version) {
146
152
  const buildId = getBuilderId();
147
- return Global.__FEDERATION__.__INSTANCES__.find((GMInstance)=>{
153
+ return globalThis.__FEDERATION__.__INSTANCES__.find((GMInstance)=>{
148
154
  if (buildId && GMInstance.options.id === getBuilderId()) {
149
155
  return true;
150
156
  }
151
- if (GMInstance.options.name === name && !version) {
157
+ if (GMInstance.options.name === name && !GMInstance.options.version && !version) {
152
158
  return true;
153
159
  }
154
160
  if (GMInstance.options.name === name && version && GMInstance.options.version === version) {
@@ -158,15 +164,15 @@ function getGlobalFederationInstance(name, version) {
158
164
  });
159
165
  }
160
166
  function setGlobalFederationInstance(FederationInstance) {
161
- Global.__FEDERATION__.__INSTANCES__.push(FederationInstance);
167
+ globalThis.__FEDERATION__.__INSTANCES__.push(FederationInstance);
162
168
  }
163
169
  function getGlobalFederationConstructor() {
164
- return Global.__FEDERATION__.__DEBUG_CONSTRUCTOR__;
170
+ return globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__;
165
171
  }
166
172
  function setGlobalFederationConstructor(FederationConstructor) {
167
173
  if (isDebugMode()) {
168
- Global.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
169
- Global.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = '0.0.5';
174
+ globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
175
+ globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = '0.0.7';
170
176
  }
171
177
  }
172
178
  // eslint-disable-next-line @typescript-eslint/ban-types
@@ -181,7 +187,7 @@ function getInfoWithoutType(target, key, getModuleInfoHook) {
181
187
  }
182
188
  return res;
183
189
  }
184
- const getGlobalSnapshot = ()=>Global.__FEDERATION__.moduleInfo;
190
+ const getGlobalSnapshot = ()=>nativeGlobal.__FEDERATION__.moduleInfo;
185
191
  const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot, getModuleInfoHook)=>{
186
192
  // Check if the remote is included in the hostSnapshot
187
193
  const moduleKey = getFMId(moduleInfo);
@@ -199,25 +205,25 @@ const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot, getModuleInfoHo
199
205
  "version"
200
206
  ]);
201
207
  const moduleKeyWithoutVersion = getFMId(resModuleInfo);
202
- const getModuleInfoWithoutVersion = getInfoWithoutType(Global.__FEDERATION__.moduleInfo, moduleKeyWithoutVersion, getModuleInfoHook).value;
208
+ const getModuleInfoWithoutVersion = getInfoWithoutType(nativeGlobal.__FEDERATION__.moduleInfo, moduleKeyWithoutVersion, getModuleInfoHook).value;
203
209
  if ((getModuleInfoWithoutVersion == null ? void 0 : getModuleInfoWithoutVersion.version) === version) {
204
210
  return getModuleInfoWithoutVersion;
205
211
  }
206
212
  }
207
213
  return;
208
214
  };
209
- const getGlobalSnapshotInfoByModuleInfo = (moduleInfo, extraOptions)=>getTargetSnapshotInfoByModuleInfo(moduleInfo, Global.__FEDERATION__.moduleInfo, extraOptions == null ? void 0 : extraOptions.getModuleInfoHook);
215
+ const getGlobalSnapshotInfoByModuleInfo = (moduleInfo, extraOptions)=>getTargetSnapshotInfoByModuleInfo(moduleInfo, nativeGlobal.__FEDERATION__.moduleInfo, extraOptions == null ? void 0 : extraOptions.getModuleInfoHook);
210
216
  const setGlobalSnapshotInfoByModuleInfo = (remoteInfo, moduleDetailInfo)=>{
211
217
  const moduleKey = getFMId(remoteInfo);
212
- Global.__FEDERATION__.moduleInfo[moduleKey] = moduleDetailInfo;
213
- return Global.__FEDERATION__.moduleInfo;
218
+ nativeGlobal.__FEDERATION__.moduleInfo[moduleKey] = moduleDetailInfo;
219
+ return nativeGlobal.__FEDERATION__.moduleInfo;
214
220
  };
215
221
  const addGlobalSnapshot = (moduleInfos)=>{
216
- Global.__FEDERATION__.moduleInfo = _extends$1({}, Global.__FEDERATION__.moduleInfo, moduleInfos);
222
+ nativeGlobal.__FEDERATION__.moduleInfo = _extends$1({}, nativeGlobal.__FEDERATION__.moduleInfo, moduleInfos);
217
223
  return ()=>{
218
224
  const keys = Object.keys(moduleInfos);
219
225
  for (const key of keys){
220
- delete Global.__FEDERATION__.moduleInfo[key];
226
+ delete nativeGlobal.__FEDERATION__.moduleInfo[key];
221
227
  }
222
228
  };
223
229
  };
@@ -234,7 +240,7 @@ const getRemoteEntryExports = (name, globalName)=>{
234
240
  // If a plugin is not registered, it is added to the global plugins.
235
241
  // If a plugin is already registered, a warning message is logged.
236
242
  const registerGlobalPlugins = (plugins)=>{
237
- const { __GLOBAL_PLUGIN__ } = Global.__FEDERATION__;
243
+ const { __GLOBAL_PLUGIN__ } = nativeGlobal.__FEDERATION__;
238
244
  plugins.forEach((plugin)=>{
239
245
  if (__GLOBAL_PLUGIN__.findIndex((p)=>p.name === plugin.name) === -1) {
240
246
  __GLOBAL_PLUGIN__.push(plugin);
@@ -243,9 +249,9 @@ const registerGlobalPlugins = (plugins)=>{
243
249
  }
244
250
  });
245
251
  };
246
- const getGlobalHostPlugins = ()=>Global.__FEDERATION__.__GLOBAL_PLUGIN__;
247
- const getPreloaded = (id)=>Global.__FEDERATION__.__PRELOADED_MAP__.get(id);
248
- const setPreloaded = (id)=>Global.__FEDERATION__.__PRELOADED_MAP__.set(id, true);
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);
249
255
 
250
256
  const DEFAULT_SCOPE = 'default';
251
257
  const DEFAULT_REMOTE_TYPE = 'global';
@@ -1,5 +1,5 @@
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, RemoteEntryExports, Remote, Shared, ShareInfos, UserOptions, RemoteInfo, GlobalShareScope, InitScope, RemoteEntryInitOptions } from './type';
3
3
  import { Module, ModuleOptions } from './module';
4
4
  import { AsyncHook, AsyncWaterfallHook, PluginSystem, SyncHook, SyncWaterfallHook } from './utils/hooks';
5
5
  import { SnapshotHandler } from './plugins/snapshot/SnapshotHandler';
@@ -32,6 +32,21 @@ export declare class FederationHost {
32
32
  origin: FederationHost;
33
33
  }>;
34
34
  afterResolve: AsyncWaterfallHook<LoadRemoteMatch>;
35
+ beforeInitContainer: AsyncWaterfallHook<{
36
+ shareScope: GlobalShareScope[string];
37
+ initScope: InitScope;
38
+ remoteEntryInitOptions: RemoteEntryInitOptions;
39
+ remoteInfo: RemoteInfo;
40
+ origin: FederationHost;
41
+ }>;
42
+ initContainer: AsyncWaterfallHook<{
43
+ shareScope: GlobalShareScope[string];
44
+ initScope: InitScope;
45
+ remoteEntryInitOptions: RemoteEntryInitOptions;
46
+ remoteInfo: RemoteInfo;
47
+ remoteEntryExports: RemoteEntryExports;
48
+ origin: FederationHost;
49
+ }>;
35
50
  onLoad: AsyncHook<[{
36
51
  id: string;
37
52
  expose: string;
@@ -15,13 +15,11 @@ export interface Federation {
15
15
  __PRELOADED_MAP__: Map<string, boolean>;
16
16
  }
17
17
  export declare const nativeGlobal: typeof global;
18
+ export declare const Global: typeof globalThis;
18
19
  declare global {
19
20
  var __FEDERATION__: Federation, __VMOK__: Federation, __GLOBAL_LOADING_REMOTE_ENTRY__: Record<string, undefined | Promise<RemoteEntryExports | void>>;
20
21
  }
21
22
  export declare const globalLoading: Record<string, Promise<void | RemoteEntryExports> | undefined>;
22
- export declare const Global: {
23
- readonly __FEDERATION__: Federation;
24
- };
25
23
  export declare function resetFederationGlobalInfo(): void;
26
24
  export declare function getGlobalFederationInstance(name: string, version: string | undefined): FederationHost | undefined;
27
25
  export declare function setGlobalFederationInstance(FederationInstance: FederationHost): void;
@@ -1,11 +1,12 @@
1
1
  /// <reference types="node" />
2
- import { resetFederationGlobalInfo, getGlobalFederationInstance, setGlobalFederationInstance, getGlobalFederationConstructor, setGlobalFederationConstructor, getInfoWithoutType, getGlobalSnapshot, getTargetSnapshotInfoByModuleInfo, getGlobalSnapshotInfoByModuleInfo, setGlobalSnapshotInfoByModuleInfo, addGlobalSnapshot, getRemoteEntryExports, registerGlobalPlugins, getGlobalHostPlugins, getPreloaded, setPreloaded } 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 { getGlobalShare, getGlobalShareScope } from './utils/share';
4
4
  interface IShareUtils {
5
5
  getGlobalShare: typeof getGlobalShare;
6
6
  getGlobalShareScope: typeof getGlobalShareScope;
7
7
  }
8
8
  interface IGlobalUtils {
9
+ Global: typeof Global;
9
10
  nativeGlobal: typeof global;
10
11
  resetFederationGlobalInfo: typeof resetFederationGlobalInfo;
11
12
  getGlobalFederationInstance: typeof getGlobalFederationInstance;
@@ -1,21 +1,15 @@
1
1
  import { FederationHost } from '../core';
2
- import { RemoteEntryExports, Options, Remote, ShareInfos, RemoteInfo } from '../type';
2
+ import { RemoteEntryExports, RemoteInfo } from '../type';
3
3
  export type ModuleOptions = ConstructorParameters<typeof Module>[0];
4
- type HostInfo = Remote;
5
4
  declare class Module {
6
- hostInfo: HostInfo;
7
5
  remoteInfo: RemoteInfo;
8
6
  inited: boolean;
9
- shared: ShareInfos;
10
7
  remoteEntryExports?: RemoteEntryExports;
11
8
  lib: RemoteEntryExports | undefined;
12
- loaderHook: FederationHost['loaderHook'];
13
- constructor({ hostInfo, remoteInfo, shared, loaderHook, }: {
14
- hostInfo: HostInfo;
9
+ host: FederationHost;
10
+ constructor({ remoteInfo, host, }: {
15
11
  remoteInfo: RemoteInfo;
16
- shared: ShareInfos;
17
- plugins: Options['plugins'];
18
- loaderHook: FederationHost['loaderHook'];
12
+ host: FederationHost;
19
13
  });
20
14
  getEntry(): Promise<RemoteEntryExports>;
21
15
  get(expose: string, options?: {
@@ -87,8 +87,9 @@ export type LoadModuleOptions = {
87
87
  export type RemoteEntryInitOptions = {
88
88
  version: string;
89
89
  };
90
+ export type InitScope = Array<Record<string, never>>;
90
91
  export type RemoteEntryExports = {
91
92
  get: (id: string) => () => Promise<Module>;
92
- init: (shareScope: GlobalShareScope[string], initScope?: Array<Record<string, never>>, remoteEntryInitOPtions?: RemoteEntryInitOptions) => void;
93
+ init: (shareScope: GlobalShareScope[string], initScope?: InitScope, remoteEntryInitOPtions?: RemoteEntryInitOptions) => void;
93
94
  };
94
95
  export {};
@@ -9,7 +9,7 @@ type SnapshotLifeCycle = SnapshotHandler['hooks']['lifecycle'];
9
9
  type SnapshotLifeCycleCyclePartial = Partial<{
10
10
  [k in keyof SnapshotLifeCycle]: Parameters<SnapshotLifeCycle[k]['on']>[0];
11
11
  }>;
12
- type ModuleLifeCycle = Module['loaderHook']['lifecycle'];
12
+ type ModuleLifeCycle = Module['host']['loaderHook']['lifecycle'];
13
13
  type ModuleLifeCycleCyclePartial = Partial<{
14
14
  [k in keyof ModuleLifeCycle]: Parameters<ModuleLifeCycle[k]['on']>[0];
15
15
  }>;
@@ -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,4 +1,4 @@
1
1
  import { FederationHost } from '../core';
2
2
  import { UserOptions } from '../type';
3
3
  import { Module } from '../module';
4
- export declare function registerPlugins(plugins: UserOptions['plugins'], hookInstances: Array<FederationHost['hooks'] | FederationHost['snapshotHandler']['hooks'] | Module['loaderHook']>): void;
4
+ export declare function registerPlugins(plugins: UserOptions['plugins'], hookInstances: Array<FederationHost['hooks'] | FederationHost['snapshotHandler']['hooks'] | Module['host']['loaderHook']>): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/runtime",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
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.5"
48
+ "@module-federation/sdk": "0.0.7"
49
49
  }
50
50
  }