@module-federation/runtime 0.6.16 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { g as getRegisteredShare, a as getGlobalShareScope, G as Global, n as nativeGlobal, r as resetFederationGlobalInfo, b as getGlobalFederationInstance, s as setGlobalFederationInstance, c as getGlobalFederationConstructor, d as setGlobalFederationConstructor, e as getInfoWithoutType, f as getGlobalSnapshot, h as getTargetSnapshotInfoByModuleInfo, i as getGlobalSnapshotInfoByModuleInfo, j as setGlobalSnapshotInfoByModuleInfo, k as addGlobalSnapshot, l as getRemoteEntryExports, m as registerGlobalPlugins, o as getGlobalHostPlugins, p as getPreloaded, q as setPreloaded } from './share.esm.js';
1
+ import { g as getRegisteredShare, a as getGlobalShareScope, G as Global, n as nativeGlobal, r as resetFederationGlobalInfo, b as getGlobalFederationInstance, s as setGlobalFederationInstance, c as getGlobalFederationConstructor, d as setGlobalFederationConstructor, e as getInfoWithoutType, f as getGlobalSnapshot, h as getTargetSnapshotInfoByModuleInfo, i as getGlobalSnapshotInfoByModuleInfo, j as setGlobalSnapshotInfoByModuleInfo, k as addGlobalSnapshot, l as getRemoteEntryExports, m as registerGlobalPlugins, o as getGlobalHostPlugins, p as getPreloaded, q as setPreloaded } from './share.esm.mjs';
2
2
 
3
3
  const ShareUtils = {
4
4
  getRegisteredShare,
package/dist/index.cjs.js CHANGED
@@ -124,7 +124,7 @@ async function loadSystemJsEntry({ entry, remoteEntryExports }) {
124
124
  }
125
125
  });
126
126
  }
127
- async function loadEntryScript({ name, globalName, entry, createScriptHook }) {
127
+ async function loadEntryScript({ name, globalName, entry, loaderHook }) {
128
128
  const { entryExports: remoteEntryExports } = share.getRemoteEntryExports(name, globalName);
129
129
  if (remoteEntryExports) {
130
130
  return remoteEntryExports;
@@ -132,7 +132,7 @@ async function loadEntryScript({ name, globalName, entry, createScriptHook }) {
132
132
  return sdk.loadScript(entry, {
133
133
  attrs: {},
134
134
  createScriptHook: (url, attrs)=>{
135
- const res = createScriptHook.emit({
135
+ const res = loaderHook.lifecycle.createScript.emit({
136
136
  url,
137
137
  attrs
138
138
  });
@@ -157,7 +157,7 @@ async function loadEntryScript({ name, globalName, entry, createScriptHook }) {
157
157
  throw e;
158
158
  });
159
159
  }
160
- async function loadEntryDom({ remoteInfo, remoteEntryExports, createScriptHook }) {
160
+ async function loadEntryDom({ remoteInfo, remoteEntryExports, loaderHook }) {
161
161
  const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
162
162
  switch(type){
163
163
  case 'esm':
@@ -176,11 +176,11 @@ async function loadEntryDom({ remoteInfo, remoteEntryExports, createScriptHook }
176
176
  entry,
177
177
  globalName,
178
178
  name,
179
- createScriptHook
179
+ loaderHook
180
180
  });
181
181
  }
182
182
  }
183
- async function loadEntryNode({ remoteInfo, createScriptHook }) {
183
+ async function loadEntryNode({ remoteInfo, loaderHook }) {
184
184
  const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
185
185
  const { entryExports: remoteEntryExports } = share.getRemoteEntryExports(name, globalName);
186
186
  if (remoteEntryExports) {
@@ -192,16 +192,18 @@ async function loadEntryNode({ remoteInfo, createScriptHook }) {
192
192
  globalName,
193
193
  type
194
194
  },
195
- createScriptHook: (url, attrs)=>{
196
- const res = createScriptHook.emit({
197
- url,
198
- attrs
199
- });
200
- if (!res) return;
201
- if ('url' in res) {
202
- return res;
195
+ loaderHook: {
196
+ createScriptHook: (url, attrs = {})=>{
197
+ const res = loaderHook.lifecycle.createScript.emit({
198
+ url,
199
+ attrs
200
+ });
201
+ if (!res) return;
202
+ if ('url' in res) {
203
+ return res;
204
+ }
205
+ return;
203
206
  }
204
- return;
205
207
  }
206
208
  }).then(()=>{
207
209
  const { remoteEntryKey, entryExports } = share.getRemoteEntryExports(name, globalName);
@@ -226,9 +228,10 @@ async function getRemoteEntry({ origin, remoteEntryExports, remoteInfo }) {
226
228
  }
227
229
  if (!share.globalLoading[uniqueKey]) {
228
230
  const loadEntryHook = origin.remoteHandler.hooks.lifecycle.loadEntry;
229
- const createScriptHook = origin.loaderHook.lifecycle.createScript;
231
+ origin.loaderHook.lifecycle.createScript;
232
+ const loaderHook = origin.loaderHook;
230
233
  share.globalLoading[uniqueKey] = loadEntryHook.emit({
231
- createScriptHook,
234
+ loaderHook,
232
235
  remoteInfo,
233
236
  remoteEntryExports
234
237
  }).then((res)=>{
@@ -238,10 +241,10 @@ async function getRemoteEntry({ origin, remoteEntryExports, remoteInfo }) {
238
241
  return sdk.isBrowserEnv() ? loadEntryDom({
239
242
  remoteInfo,
240
243
  remoteEntryExports,
241
- createScriptHook
244
+ loaderHook
242
245
  }) : loadEntryNode({
243
246
  remoteInfo,
244
- createScriptHook
247
+ loaderHook
245
248
  });
246
249
  });
247
250
  }
@@ -1782,13 +1785,13 @@ class RemoteHandler {
1782
1785
  if (loadedModule) {
1783
1786
  const remoteInfo = loadedModule.remoteInfo;
1784
1787
  const key = remoteInfo.entryGlobalName;
1785
- if (globalThis[key]) {
1788
+ if (share.CurrentGlobal[key]) {
1786
1789
  var _Object_getOwnPropertyDescriptor;
1787
- if ((_Object_getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor(globalThis, key)) == null ? void 0 : _Object_getOwnPropertyDescriptor.configurable) {
1788
- delete globalThis[key];
1790
+ if ((_Object_getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor(share.CurrentGlobal, key)) == null ? void 0 : _Object_getOwnPropertyDescriptor.configurable) {
1791
+ delete share.CurrentGlobal[key];
1789
1792
  } else {
1790
1793
  // @ts-ignore
1791
- globalThis[key] = undefined;
1794
+ share.CurrentGlobal[key] = undefined;
1792
1795
  }
1793
1796
  }
1794
1797
  const remoteEntryUniqueKey = getRemoteEntryUniqueKey(loadedModule.remoteInfo);
@@ -1798,7 +1801,7 @@ class RemoteHandler {
1798
1801
  host.snapshotHandler.manifestCache.delete(remoteInfo.entry);
1799
1802
  // delete unloaded shared and instance
1800
1803
  let remoteInsId = remoteInfo.buildVersion ? sdk.composeKeyWithSeparator(remoteInfo.name, remoteInfo.buildVersion) : remoteInfo.name;
1801
- const remoteInsIndex = globalThis.__FEDERATION__.__INSTANCES__.findIndex((ins)=>{
1804
+ const remoteInsIndex = share.CurrentGlobal.__FEDERATION__.__INSTANCES__.findIndex((ins)=>{
1802
1805
  if (remoteInfo.buildVersion) {
1803
1806
  return ins.options.id === remoteInsId;
1804
1807
  } else {
@@ -1806,7 +1809,7 @@ class RemoteHandler {
1806
1809
  }
1807
1810
  });
1808
1811
  if (remoteInsIndex !== -1) {
1809
- const remoteIns = globalThis.__FEDERATION__.__INSTANCES__[remoteInsIndex];
1812
+ const remoteIns = share.CurrentGlobal.__FEDERATION__.__INSTANCES__[remoteInsIndex];
1810
1813
  remoteInsId = remoteIns.options.id || remoteInsId;
1811
1814
  const globalShareScopeMap = share.getGlobalShareScope();
1812
1815
  let isAllSharedNotUsed = true;
@@ -1853,7 +1856,7 @@ class RemoteHandler {
1853
1856
  var _globalShareScopeMap_insId_shareScope_shareName, _globalShareScopeMap_insId_shareScope, _globalShareScopeMap_insId;
1854
1857
  (_globalShareScopeMap_insId = globalShareScopeMap[insId]) == null ? true : (_globalShareScopeMap_insId_shareScope = _globalShareScopeMap_insId[shareScope]) == null ? true : (_globalShareScopeMap_insId_shareScope_shareName = _globalShareScopeMap_insId_shareScope[shareName]) == null ? true : delete _globalShareScopeMap_insId_shareScope_shareName[shareVersion];
1855
1858
  });
1856
- globalThis.__FEDERATION__.__INSTANCES__.splice(remoteInsIndex, 1);
1859
+ share.CurrentGlobal.__FEDERATION__.__INSTANCES__.splice(remoteInsIndex, 1);
1857
1860
  }
1858
1861
  const { hostGlobalSnapshot } = getGlobalRemoteInfo(remote, host);
1859
1862
  if (hostGlobalSnapshot) {
@@ -1996,7 +1999,7 @@ class FederationHost {
1996
1999
  // maybe will change, temporarily for internal use only
1997
2000
  initContainer: new AsyncWaterfallHook('initContainer')
1998
2001
  });
1999
- this.version = "0.6.16";
2002
+ this.version = "0.7.1";
2000
2003
  this.moduleCache = new Map();
2001
2004
  this.loaderHook = new PluginSystem({
2002
2005
  // FIXME: may not be suitable , not open to the public yet
@@ -1,8 +1,8 @@
1
- import { a as _extends, _ as _object_without_properties_loose } from './polyfills.esm.js';
1
+ import { a as _extends, _ as _object_without_properties_loose } from './polyfills.esm.mjs';
2
2
  import { isBrowserEnv, loadScriptNode, composeKeyWithSeparator, loadScript, safeToString, createLink, createScript, getResourceUrl, isManifestProvider, generateSnapshotFromManifest, warn as warn$1 } from '@module-federation/sdk';
3
3
  export { loadScript, loadScriptNode } from '@module-federation/sdk';
4
- import { o as getGlobalHostPlugins, t as globalLoading, D as DEFAULT_REMOTE_TYPE, u as DEFAULT_SCOPE, l as getRemoteEntryExports, v as assert, w as error, x as getFMId, y as isObject, z as warn, A as isPlainObject, B as isRemoteInfoWithEntry, C as isPureRemoteEntry, E as getRemoteEntryInfoFromSnapshot, e as getInfoWithoutType, p as getPreloaded, q as setPreloaded, g as getRegisteredShare, F as arrayOptions, i as getGlobalSnapshotInfoByModuleInfo, k as addGlobalSnapshot, j as setGlobalSnapshotInfoByModuleInfo, G as Global, f as getGlobalSnapshot, H as formatShareConfigs, I as getTargetSharedOptions, a as getGlobalShareScope, J as addUniqueItem, K as logger, L as getBuilderId, d as setGlobalFederationConstructor, b as getGlobalFederationInstance, c as getGlobalFederationConstructor, s as setGlobalFederationInstance } from './share.esm.js';
5
- export { m as registerGlobalPlugins } from './share.esm.js';
4
+ import { o as getGlobalHostPlugins, t as globalLoading, D as DEFAULT_REMOTE_TYPE, u as DEFAULT_SCOPE, l as getRemoteEntryExports, v as assert, w as error, x as getFMId, y as isObject, z as warn, A as isPlainObject, B as isRemoteInfoWithEntry, C as isPureRemoteEntry, E as getRemoteEntryInfoFromSnapshot, e as getInfoWithoutType, p as getPreloaded, q as setPreloaded, g as getRegisteredShare, F as arrayOptions, i as getGlobalSnapshotInfoByModuleInfo, k as addGlobalSnapshot, j as setGlobalSnapshotInfoByModuleInfo, G as Global, f as getGlobalSnapshot, H as formatShareConfigs, I as getTargetSharedOptions, a as getGlobalShareScope, J as addUniqueItem, K as CurrentGlobal, L as logger, M as getBuilderId, d as setGlobalFederationConstructor, b as getGlobalFederationInstance, c as getGlobalFederationConstructor, s as setGlobalFederationInstance } from './share.esm.mjs';
5
+ export { m as registerGlobalPlugins } from './share.esm.mjs';
6
6
  import { getShortErrorMsg, RUNTIME_001, runtimeDescMap, RUNTIME_002, RUNTIME_007, RUNTIME_003, RUNTIME_005, RUNTIME_006, RUNTIME_004 } from '@module-federation/error-codes';
7
7
 
8
8
  // Function to match a remote with its name and expose
@@ -124,7 +124,7 @@ async function loadSystemJsEntry({ entry, remoteEntryExports }) {
124
124
  }
125
125
  });
126
126
  }
127
- async function loadEntryScript({ name, globalName, entry, createScriptHook }) {
127
+ async function loadEntryScript({ name, globalName, entry, loaderHook }) {
128
128
  const { entryExports: remoteEntryExports } = getRemoteEntryExports(name, globalName);
129
129
  if (remoteEntryExports) {
130
130
  return remoteEntryExports;
@@ -132,7 +132,7 @@ async function loadEntryScript({ name, globalName, entry, createScriptHook }) {
132
132
  return loadScript(entry, {
133
133
  attrs: {},
134
134
  createScriptHook: (url, attrs)=>{
135
- const res = createScriptHook.emit({
135
+ const res = loaderHook.lifecycle.createScript.emit({
136
136
  url,
137
137
  attrs
138
138
  });
@@ -157,7 +157,7 @@ async function loadEntryScript({ name, globalName, entry, createScriptHook }) {
157
157
  throw e;
158
158
  });
159
159
  }
160
- async function loadEntryDom({ remoteInfo, remoteEntryExports, createScriptHook }) {
160
+ async function loadEntryDom({ remoteInfo, remoteEntryExports, loaderHook }) {
161
161
  const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
162
162
  switch(type){
163
163
  case 'esm':
@@ -176,11 +176,11 @@ async function loadEntryDom({ remoteInfo, remoteEntryExports, createScriptHook }
176
176
  entry,
177
177
  globalName,
178
178
  name,
179
- createScriptHook
179
+ loaderHook
180
180
  });
181
181
  }
182
182
  }
183
- async function loadEntryNode({ remoteInfo, createScriptHook }) {
183
+ async function loadEntryNode({ remoteInfo, loaderHook }) {
184
184
  const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
185
185
  const { entryExports: remoteEntryExports } = getRemoteEntryExports(name, globalName);
186
186
  if (remoteEntryExports) {
@@ -192,16 +192,18 @@ async function loadEntryNode({ remoteInfo, createScriptHook }) {
192
192
  globalName,
193
193
  type
194
194
  },
195
- createScriptHook: (url, attrs)=>{
196
- const res = createScriptHook.emit({
197
- url,
198
- attrs
199
- });
200
- if (!res) return;
201
- if ('url' in res) {
202
- return res;
195
+ loaderHook: {
196
+ createScriptHook: (url, attrs = {})=>{
197
+ const res = loaderHook.lifecycle.createScript.emit({
198
+ url,
199
+ attrs
200
+ });
201
+ if (!res) return;
202
+ if ('url' in res) {
203
+ return res;
204
+ }
205
+ return;
203
206
  }
204
- return;
205
207
  }
206
208
  }).then(()=>{
207
209
  const { remoteEntryKey, entryExports } = getRemoteEntryExports(name, globalName);
@@ -226,9 +228,10 @@ async function getRemoteEntry({ origin, remoteEntryExports, remoteInfo }) {
226
228
  }
227
229
  if (!globalLoading[uniqueKey]) {
228
230
  const loadEntryHook = origin.remoteHandler.hooks.lifecycle.loadEntry;
229
- const createScriptHook = origin.loaderHook.lifecycle.createScript;
231
+ origin.loaderHook.lifecycle.createScript;
232
+ const loaderHook = origin.loaderHook;
230
233
  globalLoading[uniqueKey] = loadEntryHook.emit({
231
- createScriptHook,
234
+ loaderHook,
232
235
  remoteInfo,
233
236
  remoteEntryExports
234
237
  }).then((res)=>{
@@ -238,10 +241,10 @@ async function getRemoteEntry({ origin, remoteEntryExports, remoteInfo }) {
238
241
  return isBrowserEnv() ? loadEntryDom({
239
242
  remoteInfo,
240
243
  remoteEntryExports,
241
- createScriptHook
244
+ loaderHook
242
245
  }) : loadEntryNode({
243
246
  remoteInfo,
244
- createScriptHook
247
+ loaderHook
245
248
  });
246
249
  });
247
250
  }
@@ -1782,13 +1785,13 @@ class RemoteHandler {
1782
1785
  if (loadedModule) {
1783
1786
  const remoteInfo = loadedModule.remoteInfo;
1784
1787
  const key = remoteInfo.entryGlobalName;
1785
- if (globalThis[key]) {
1788
+ if (CurrentGlobal[key]) {
1786
1789
  var _Object_getOwnPropertyDescriptor;
1787
- if ((_Object_getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor(globalThis, key)) == null ? void 0 : _Object_getOwnPropertyDescriptor.configurable) {
1788
- delete globalThis[key];
1790
+ if ((_Object_getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor(CurrentGlobal, key)) == null ? void 0 : _Object_getOwnPropertyDescriptor.configurable) {
1791
+ delete CurrentGlobal[key];
1789
1792
  } else {
1790
1793
  // @ts-ignore
1791
- globalThis[key] = undefined;
1794
+ CurrentGlobal[key] = undefined;
1792
1795
  }
1793
1796
  }
1794
1797
  const remoteEntryUniqueKey = getRemoteEntryUniqueKey(loadedModule.remoteInfo);
@@ -1798,7 +1801,7 @@ class RemoteHandler {
1798
1801
  host.snapshotHandler.manifestCache.delete(remoteInfo.entry);
1799
1802
  // delete unloaded shared and instance
1800
1803
  let remoteInsId = remoteInfo.buildVersion ? composeKeyWithSeparator(remoteInfo.name, remoteInfo.buildVersion) : remoteInfo.name;
1801
- const remoteInsIndex = globalThis.__FEDERATION__.__INSTANCES__.findIndex((ins)=>{
1804
+ const remoteInsIndex = CurrentGlobal.__FEDERATION__.__INSTANCES__.findIndex((ins)=>{
1802
1805
  if (remoteInfo.buildVersion) {
1803
1806
  return ins.options.id === remoteInsId;
1804
1807
  } else {
@@ -1806,7 +1809,7 @@ class RemoteHandler {
1806
1809
  }
1807
1810
  });
1808
1811
  if (remoteInsIndex !== -1) {
1809
- const remoteIns = globalThis.__FEDERATION__.__INSTANCES__[remoteInsIndex];
1812
+ const remoteIns = CurrentGlobal.__FEDERATION__.__INSTANCES__[remoteInsIndex];
1810
1813
  remoteInsId = remoteIns.options.id || remoteInsId;
1811
1814
  const globalShareScopeMap = getGlobalShareScope();
1812
1815
  let isAllSharedNotUsed = true;
@@ -1853,7 +1856,7 @@ class RemoteHandler {
1853
1856
  var _globalShareScopeMap_insId_shareScope_shareName, _globalShareScopeMap_insId_shareScope, _globalShareScopeMap_insId;
1854
1857
  (_globalShareScopeMap_insId = globalShareScopeMap[insId]) == null ? true : (_globalShareScopeMap_insId_shareScope = _globalShareScopeMap_insId[shareScope]) == null ? true : (_globalShareScopeMap_insId_shareScope_shareName = _globalShareScopeMap_insId_shareScope[shareName]) == null ? true : delete _globalShareScopeMap_insId_shareScope_shareName[shareVersion];
1855
1858
  });
1856
- globalThis.__FEDERATION__.__INSTANCES__.splice(remoteInsIndex, 1);
1859
+ CurrentGlobal.__FEDERATION__.__INSTANCES__.splice(remoteInsIndex, 1);
1857
1860
  }
1858
1861
  const { hostGlobalSnapshot } = getGlobalRemoteInfo(remote, host);
1859
1862
  if (hostGlobalSnapshot) {
@@ -1996,7 +1999,7 @@ class FederationHost {
1996
1999
  // maybe will change, temporarily for internal use only
1997
2000
  initContainer: new AsyncWaterfallHook('initContainer')
1998
2001
  });
1999
- this.version = "0.6.16";
2002
+ this.version = "0.7.1";
2000
2003
  this.moduleCache = new Map();
2001
2004
  this.loaderHook = new PluginSystem({
2002
2005
  // FIXME: may not be suitable , not open to the public yet
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/runtime",
3
- "version": "0.6.16",
3
+ "version": "0.7.1",
4
4
  "author": "zhouxiao <codingzx@gmail.com>",
5
5
  "main": "./index.cjs.js",
6
6
  "module": "./index.esm.js",
@@ -16,22 +16,22 @@
16
16
  "exports": {
17
17
  ".": {
18
18
  "types": "./dist/index.cjs.d.ts",
19
- "import": "./dist/index.esm.js",
19
+ "import": "./dist/index.esm.mjs",
20
20
  "require": "./dist/index.cjs.js"
21
21
  },
22
22
  "./helpers": {
23
23
  "types": "./dist/helpers.cjs.d.ts",
24
- "import": "./dist/helpers.esm.js",
24
+ "import": "./dist/helpers.esm.mjs",
25
25
  "require": "./dist/helpers.cjs.js"
26
26
  },
27
27
  "./types": {
28
28
  "types": "./dist/types.cjs.d.ts",
29
- "import": "./dist/types.esm.js",
29
+ "import": "./dist/types.esm.mjs",
30
30
  "require": "./dist/types.cjs.js"
31
31
  },
32
32
  "./embedded": {
33
33
  "types": "./dist/embedded.cjs.d.ts",
34
- "import": "./dist/embedded.esm.js",
34
+ "import": "./dist/embedded.esm.mjs",
35
35
  "require": "./dist/embedded.cjs.js"
36
36
  },
37
37
  "./*": "./*"
package/dist/share.cjs.js CHANGED
@@ -90,11 +90,14 @@ function getRemoteEntryInfoFromSnapshot(snapshot) {
90
90
  return defaultRemoteEntryInfo;
91
91
  }
92
92
 
93
+ const CurrentGlobal = typeof globalThis === 'object' ? globalThis : window;
93
94
  const nativeGlobal = (()=>{
94
95
  try {
95
- return new Function('return this')();
96
+ // get real window (incase of sandbox)
97
+ return document.defaultView;
96
98
  } catch (e) {
97
- return globalThis;
99
+ // node env
100
+ return CurrentGlobal;
98
101
  }
99
102
  })();
100
103
  const Global = nativeGlobal;
@@ -111,10 +114,10 @@ function includeOwnProperty(target, key) {
111
114
  // This section is to prevent encapsulation by certain microfrontend frameworks. Due to reuse policies, sandbox escapes.
112
115
  // The sandbox in the microfrontend does not replicate the value of 'configurable'.
113
116
  // If there is no loading content on the global object, this section defines the loading object.
114
- if (!includeOwnProperty(globalThis, '__GLOBAL_LOADING_REMOTE_ENTRY__')) {
115
- definePropertyGlobalVal(globalThis, '__GLOBAL_LOADING_REMOTE_ENTRY__', {});
117
+ if (!includeOwnProperty(CurrentGlobal, '__GLOBAL_LOADING_REMOTE_ENTRY__')) {
118
+ definePropertyGlobalVal(CurrentGlobal, '__GLOBAL_LOADING_REMOTE_ENTRY__', {});
116
119
  }
117
- const globalLoading = globalThis.__GLOBAL_LOADING_REMOTE_ENTRY__;
120
+ const globalLoading = CurrentGlobal.__GLOBAL_LOADING_REMOTE_ENTRY__;
118
121
  function setGlobalDefaultVal(target) {
119
122
  var _target___FEDERATION__, _target___FEDERATION__1, _target___FEDERATION__2, _target___FEDERATION__3, _target___FEDERATION__4, _target___FEDERATION__5;
120
123
  if (includeOwnProperty(target, '__VMOK__') && !includeOwnProperty(target, '__FEDERATION__')) {
@@ -144,18 +147,21 @@ function setGlobalDefaultVal(target) {
144
147
  var ___PRELOADED_MAP__;
145
148
  (___PRELOADED_MAP__ = (_target___FEDERATION__5 = target.__FEDERATION__).__PRELOADED_MAP__) != null ? ___PRELOADED_MAP__ : _target___FEDERATION__5.__PRELOADED_MAP__ = new Map();
146
149
  }
147
- setGlobalDefaultVal(globalThis);
150
+ setGlobalDefaultVal(CurrentGlobal);
148
151
  setGlobalDefaultVal(nativeGlobal);
149
152
  function resetFederationGlobalInfo() {
150
- globalThis.__FEDERATION__.__GLOBAL_PLUGIN__ = [];
151
- globalThis.__FEDERATION__.__INSTANCES__ = [];
152
- globalThis.__FEDERATION__.moduleInfo = {};
153
- globalThis.__FEDERATION__.__SHARE__ = {};
154
- globalThis.__FEDERATION__.__MANIFEST_LOADING__ = {};
153
+ CurrentGlobal.__FEDERATION__.__GLOBAL_PLUGIN__ = [];
154
+ CurrentGlobal.__FEDERATION__.__INSTANCES__ = [];
155
+ CurrentGlobal.__FEDERATION__.moduleInfo = {};
156
+ CurrentGlobal.__FEDERATION__.__SHARE__ = {};
157
+ CurrentGlobal.__FEDERATION__.__MANIFEST_LOADING__ = {};
158
+ Object.keys(globalLoading).forEach((key)=>{
159
+ delete globalLoading[key];
160
+ });
155
161
  }
156
162
  function getGlobalFederationInstance(name, version) {
157
163
  const buildId = getBuilderId();
158
- return globalThis.__FEDERATION__.__INSTANCES__.find((GMInstance)=>{
164
+ return CurrentGlobal.__FEDERATION__.__INSTANCES__.find((GMInstance)=>{
159
165
  if (buildId && GMInstance.options.id === getBuilderId()) {
160
166
  return true;
161
167
  }
@@ -169,15 +175,15 @@ function getGlobalFederationInstance(name, version) {
169
175
  });
170
176
  }
171
177
  function setGlobalFederationInstance(FederationInstance) {
172
- globalThis.__FEDERATION__.__INSTANCES__.push(FederationInstance);
178
+ CurrentGlobal.__FEDERATION__.__INSTANCES__.push(FederationInstance);
173
179
  }
174
180
  function getGlobalFederationConstructor() {
175
- return globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__;
181
+ return CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR__;
176
182
  }
177
183
  function setGlobalFederationConstructor(FederationConstructor, isDebug = sdk.isDebugMode()) {
178
184
  if (isDebug) {
179
- globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
180
- globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.6.16";
185
+ CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
186
+ CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.7.1";
181
187
  }
182
188
  }
183
189
  // eslint-disable-next-line @typescript-eslint/ban-types
@@ -253,7 +259,7 @@ const addGlobalSnapshot = (moduleInfos)=>{
253
259
  };
254
260
  const getRemoteEntryExports = (name, globalName)=>{
255
261
  const remoteEntryKey = globalName || `__FEDERATION_${name}:custom__`;
256
- const entryExports = globalThis[remoteEntryKey];
262
+ const entryExports = CurrentGlobal[remoteEntryKey];
257
263
  return {
258
264
  remoteEntryKey,
259
265
  entryExports
@@ -274,8 +280,8 @@ const registerGlobalPlugins = (plugins)=>{
274
280
  });
275
281
  };
276
282
  const getGlobalHostPlugins = ()=>nativeGlobal.__FEDERATION__.__GLOBAL_PLUGIN__;
277
- const getPreloaded = (id)=>globalThis.__FEDERATION__.__PRELOADED_MAP__.get(id);
278
- const setPreloaded = (id)=>globalThis.__FEDERATION__.__PRELOADED_MAP__.set(id, true);
283
+ const getPreloaded = (id)=>CurrentGlobal.__FEDERATION__.__PRELOADED_MAP__.get(id);
284
+ const setPreloaded = (id)=>CurrentGlobal.__FEDERATION__.__PRELOADED_MAP__.set(id, true);
279
285
 
280
286
  const DEFAULT_SCOPE = 'default';
281
287
  const DEFAULT_REMOTE_TYPE = 'global';
@@ -763,6 +769,9 @@ const findVersion = (shareVersionMap, cb)=>{
763
769
  const isLoaded = (shared)=>{
764
770
  return Boolean(shared.loaded) || typeof shared.lib === 'function';
765
771
  };
772
+ const isLoading = (shared)=>{
773
+ return Boolean(shared.loading);
774
+ };
766
775
  function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) {
767
776
  const versions = shareScopeMap[scope][pkgName];
768
777
  const callback = function(prev, cur) {
@@ -773,14 +782,17 @@ function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) {
773
782
  function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
774
783
  const versions = shareScopeMap[scope][pkgName];
775
784
  const callback = function(prev, cur) {
776
- if (isLoaded(versions[cur])) {
777
- if (isLoaded(versions[prev])) {
785
+ const isLoadingOrLoaded = (shared)=>{
786
+ return isLoaded(shared) || isLoading(shared);
787
+ };
788
+ if (isLoadingOrLoaded(versions[cur])) {
789
+ if (isLoadingOrLoaded(versions[prev])) {
778
790
  return Boolean(versionLt(prev, cur));
779
791
  } else {
780
792
  return true;
781
793
  }
782
794
  }
783
- if (isLoaded(versions[prev])) {
795
+ if (isLoadingOrLoaded(versions[prev])) {
784
796
  return false;
785
797
  }
786
798
  return versionLt(prev, cur);
@@ -869,6 +881,7 @@ function getTargetSharedOptions(options) {
869
881
  return Object.assign({}, resolver(shareInfos[pkgName]), extraOptions == null ? void 0 : extraOptions.customShareInfo);
870
882
  }
871
883
 
884
+ exports.CurrentGlobal = CurrentGlobal;
872
885
  exports.DEFAULT_REMOTE_TYPE = DEFAULT_REMOTE_TYPE;
873
886
  exports.DEFAULT_SCOPE = DEFAULT_SCOPE;
874
887
  exports.Global = Global;
@@ -1,4 +1,4 @@
1
- import { _ as _object_without_properties_loose, a as _extends } from './polyfills.esm.js';
1
+ import { _ as _object_without_properties_loose, a as _extends } from './polyfills.esm.mjs';
2
2
  import { createLogger, isBrowserEnv, isDebugMode } from '@module-federation/sdk';
3
3
 
4
4
  function getBuilderId() {
@@ -88,11 +88,14 @@ function getRemoteEntryInfoFromSnapshot(snapshot) {
88
88
  return defaultRemoteEntryInfo;
89
89
  }
90
90
 
91
+ const CurrentGlobal = typeof globalThis === 'object' ? globalThis : window;
91
92
  const nativeGlobal = (()=>{
92
93
  try {
93
- return new Function('return this')();
94
+ // get real window (incase of sandbox)
95
+ return document.defaultView;
94
96
  } catch (e) {
95
- return globalThis;
97
+ // node env
98
+ return CurrentGlobal;
96
99
  }
97
100
  })();
98
101
  const Global = nativeGlobal;
@@ -109,10 +112,10 @@ function includeOwnProperty(target, key) {
109
112
  // This section is to prevent encapsulation by certain microfrontend frameworks. Due to reuse policies, sandbox escapes.
110
113
  // The sandbox in the microfrontend does not replicate the value of 'configurable'.
111
114
  // If there is no loading content on the global object, this section defines the loading object.
112
- if (!includeOwnProperty(globalThis, '__GLOBAL_LOADING_REMOTE_ENTRY__')) {
113
- definePropertyGlobalVal(globalThis, '__GLOBAL_LOADING_REMOTE_ENTRY__', {});
115
+ if (!includeOwnProperty(CurrentGlobal, '__GLOBAL_LOADING_REMOTE_ENTRY__')) {
116
+ definePropertyGlobalVal(CurrentGlobal, '__GLOBAL_LOADING_REMOTE_ENTRY__', {});
114
117
  }
115
- const globalLoading = globalThis.__GLOBAL_LOADING_REMOTE_ENTRY__;
118
+ const globalLoading = CurrentGlobal.__GLOBAL_LOADING_REMOTE_ENTRY__;
116
119
  function setGlobalDefaultVal(target) {
117
120
  var _target___FEDERATION__, _target___FEDERATION__1, _target___FEDERATION__2, _target___FEDERATION__3, _target___FEDERATION__4, _target___FEDERATION__5;
118
121
  if (includeOwnProperty(target, '__VMOK__') && !includeOwnProperty(target, '__FEDERATION__')) {
@@ -142,18 +145,21 @@ function setGlobalDefaultVal(target) {
142
145
  var ___PRELOADED_MAP__;
143
146
  (___PRELOADED_MAP__ = (_target___FEDERATION__5 = target.__FEDERATION__).__PRELOADED_MAP__) != null ? ___PRELOADED_MAP__ : _target___FEDERATION__5.__PRELOADED_MAP__ = new Map();
144
147
  }
145
- setGlobalDefaultVal(globalThis);
148
+ setGlobalDefaultVal(CurrentGlobal);
146
149
  setGlobalDefaultVal(nativeGlobal);
147
150
  function resetFederationGlobalInfo() {
148
- globalThis.__FEDERATION__.__GLOBAL_PLUGIN__ = [];
149
- globalThis.__FEDERATION__.__INSTANCES__ = [];
150
- globalThis.__FEDERATION__.moduleInfo = {};
151
- globalThis.__FEDERATION__.__SHARE__ = {};
152
- globalThis.__FEDERATION__.__MANIFEST_LOADING__ = {};
151
+ CurrentGlobal.__FEDERATION__.__GLOBAL_PLUGIN__ = [];
152
+ CurrentGlobal.__FEDERATION__.__INSTANCES__ = [];
153
+ CurrentGlobal.__FEDERATION__.moduleInfo = {};
154
+ CurrentGlobal.__FEDERATION__.__SHARE__ = {};
155
+ CurrentGlobal.__FEDERATION__.__MANIFEST_LOADING__ = {};
156
+ Object.keys(globalLoading).forEach((key)=>{
157
+ delete globalLoading[key];
158
+ });
153
159
  }
154
160
  function getGlobalFederationInstance(name, version) {
155
161
  const buildId = getBuilderId();
156
- return globalThis.__FEDERATION__.__INSTANCES__.find((GMInstance)=>{
162
+ return CurrentGlobal.__FEDERATION__.__INSTANCES__.find((GMInstance)=>{
157
163
  if (buildId && GMInstance.options.id === getBuilderId()) {
158
164
  return true;
159
165
  }
@@ -167,15 +173,15 @@ function getGlobalFederationInstance(name, version) {
167
173
  });
168
174
  }
169
175
  function setGlobalFederationInstance(FederationInstance) {
170
- globalThis.__FEDERATION__.__INSTANCES__.push(FederationInstance);
176
+ CurrentGlobal.__FEDERATION__.__INSTANCES__.push(FederationInstance);
171
177
  }
172
178
  function getGlobalFederationConstructor() {
173
- return globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__;
179
+ return CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR__;
174
180
  }
175
181
  function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
176
182
  if (isDebug) {
177
- globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
178
- globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.6.16";
183
+ CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
184
+ CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.7.1";
179
185
  }
180
186
  }
181
187
  // eslint-disable-next-line @typescript-eslint/ban-types
@@ -251,7 +257,7 @@ const addGlobalSnapshot = (moduleInfos)=>{
251
257
  };
252
258
  const getRemoteEntryExports = (name, globalName)=>{
253
259
  const remoteEntryKey = globalName || `__FEDERATION_${name}:custom__`;
254
- const entryExports = globalThis[remoteEntryKey];
260
+ const entryExports = CurrentGlobal[remoteEntryKey];
255
261
  return {
256
262
  remoteEntryKey,
257
263
  entryExports
@@ -272,8 +278,8 @@ const registerGlobalPlugins = (plugins)=>{
272
278
  });
273
279
  };
274
280
  const getGlobalHostPlugins = ()=>nativeGlobal.__FEDERATION__.__GLOBAL_PLUGIN__;
275
- const getPreloaded = (id)=>globalThis.__FEDERATION__.__PRELOADED_MAP__.get(id);
276
- const setPreloaded = (id)=>globalThis.__FEDERATION__.__PRELOADED_MAP__.set(id, true);
281
+ const getPreloaded = (id)=>CurrentGlobal.__FEDERATION__.__PRELOADED_MAP__.get(id);
282
+ const setPreloaded = (id)=>CurrentGlobal.__FEDERATION__.__PRELOADED_MAP__.set(id, true);
277
283
 
278
284
  const DEFAULT_SCOPE = 'default';
279
285
  const DEFAULT_REMOTE_TYPE = 'global';
@@ -761,6 +767,9 @@ const findVersion = (shareVersionMap, cb)=>{
761
767
  const isLoaded = (shared)=>{
762
768
  return Boolean(shared.loaded) || typeof shared.lib === 'function';
763
769
  };
770
+ const isLoading = (shared)=>{
771
+ return Boolean(shared.loading);
772
+ };
764
773
  function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) {
765
774
  const versions = shareScopeMap[scope][pkgName];
766
775
  const callback = function(prev, cur) {
@@ -771,14 +780,17 @@ function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) {
771
780
  function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
772
781
  const versions = shareScopeMap[scope][pkgName];
773
782
  const callback = function(prev, cur) {
774
- if (isLoaded(versions[cur])) {
775
- if (isLoaded(versions[prev])) {
783
+ const isLoadingOrLoaded = (shared)=>{
784
+ return isLoaded(shared) || isLoading(shared);
785
+ };
786
+ if (isLoadingOrLoaded(versions[cur])) {
787
+ if (isLoadingOrLoaded(versions[prev])) {
776
788
  return Boolean(versionLt(prev, cur));
777
789
  } else {
778
790
  return true;
779
791
  }
780
792
  }
781
- if (isLoaded(versions[prev])) {
793
+ if (isLoadingOrLoaded(versions[prev])) {
782
794
  return false;
783
795
  }
784
796
  return versionLt(prev, cur);
@@ -867,4 +879,4 @@ function getTargetSharedOptions(options) {
867
879
  return Object.assign({}, resolver(shareInfos[pkgName]), extraOptions == null ? void 0 : extraOptions.customShareInfo);
868
880
  }
869
881
 
870
- export { isPlainObject as A, isRemoteInfoWithEntry as B, isPureRemoteEntry as C, DEFAULT_REMOTE_TYPE as D, getRemoteEntryInfoFromSnapshot as E, arrayOptions as F, Global as G, formatShareConfigs as H, getTargetSharedOptions as I, addUniqueItem as J, logger as K, getBuilderId as L, getGlobalShareScope as a, getGlobalFederationInstance as b, getGlobalFederationConstructor as c, setGlobalFederationConstructor as d, getInfoWithoutType as e, getGlobalSnapshot as f, getRegisteredShare as g, getTargetSnapshotInfoByModuleInfo as h, getGlobalSnapshotInfoByModuleInfo as i, setGlobalSnapshotInfoByModuleInfo as j, addGlobalSnapshot as k, getRemoteEntryExports as l, registerGlobalPlugins as m, nativeGlobal as n, getGlobalHostPlugins as o, getPreloaded as p, setPreloaded as q, resetFederationGlobalInfo as r, setGlobalFederationInstance as s, globalLoading as t, DEFAULT_SCOPE as u, assert as v, error as w, getFMId as x, isObject as y, warn as z };
882
+ export { isPlainObject as A, isRemoteInfoWithEntry as B, isPureRemoteEntry as C, DEFAULT_REMOTE_TYPE as D, getRemoteEntryInfoFromSnapshot as E, arrayOptions as F, Global as G, formatShareConfigs as H, getTargetSharedOptions as I, addUniqueItem as J, CurrentGlobal as K, logger as L, getBuilderId as M, getGlobalShareScope as a, getGlobalFederationInstance as b, getGlobalFederationConstructor as c, setGlobalFederationConstructor as d, getInfoWithoutType as e, getGlobalSnapshot as f, getRegisteredShare as g, getTargetSnapshotInfoByModuleInfo as h, getGlobalSnapshotInfoByModuleInfo as i, setGlobalSnapshotInfoByModuleInfo as j, addGlobalSnapshot as k, getRemoteEntryExports as l, registerGlobalPlugins as m, nativeGlobal as n, getGlobalHostPlugins as o, getPreloaded as p, setPreloaded as q, resetFederationGlobalInfo as r, setGlobalFederationInstance as s, globalLoading as t, DEFAULT_SCOPE as u, assert as v, error as w, getFMId as x, isObject as y, warn as z };
@@ -12,6 +12,7 @@ export interface Federation {
12
12
  __MANIFEST_LOADING__: Record<string, Promise<ModuleInfo>>;
13
13
  __PRELOADED_MAP__: Map<string, boolean>;
14
14
  }
15
+ export declare const CurrentGlobal: typeof globalThis;
15
16
  export declare const nativeGlobal: typeof global;
16
17
  export declare const Global: typeof globalThis;
17
18
  declare global {
@@ -79,7 +79,7 @@ export declare class RemoteHandler {
79
79
  origin: FederationHost;
80
80
  }, false | void | Promise<false | void>>;
81
81
  loadEntry: AsyncHook<[{
82
- createScriptHook: FederationHost["loaderHook"]["lifecycle"]["createScript"];
82
+ loaderHook: FederationHost["loaderHook"];
83
83
  remoteInfo: RemoteInfo;
84
84
  remoteEntryExports?: RemoteEntryExports;
85
85
  }], Promise<RemoteEntryExports>>;
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@module-federation/runtime",
3
- "version": "0.6.16",
3
+ "version": "0.7.1",
4
4
  "author": "zhouxiao <codingzx@gmail.com>",
5
5
  "main": "./dist/index.cjs.js",
6
- "module": "./dist/index.esm.js",
6
+ "module": "./dist/index.esm.mjs",
7
7
  "types": "./dist/index.cjs.d.ts",
8
8
  "license": "MIT",
9
9
  "publishConfig": {
@@ -16,22 +16,22 @@
16
16
  "exports": {
17
17
  ".": {
18
18
  "types": "./dist/index.cjs.d.ts",
19
- "import": "./dist/index.esm.js",
19
+ "import": "./dist/index.esm.mjs",
20
20
  "require": "./dist/index.cjs.js"
21
21
  },
22
22
  "./helpers": {
23
23
  "types": "./dist/helpers.cjs.d.ts",
24
- "import": "./dist/helpers.esm.js",
24
+ "import": "./dist/helpers.esm.mjs",
25
25
  "require": "./dist/helpers.cjs.js"
26
26
  },
27
27
  "./types": {
28
28
  "types": "./dist/types.cjs.d.ts",
29
- "import": "./dist/types.esm.js",
29
+ "import": "./dist/types.esm.mjs",
30
30
  "require": "./dist/types.cjs.js"
31
31
  },
32
32
  "./embedded": {
33
33
  "types": "./dist/embedded.cjs.d.ts",
34
- "import": "./dist/embedded.esm.js",
34
+ "import": "./dist/embedded.esm.mjs",
35
35
  "require": "./dist/embedded.cjs.js"
36
36
  },
37
37
  "./*": "./*"
@@ -50,7 +50,7 @@
50
50
  }
51
51
  },
52
52
  "dependencies": {
53
- "@module-federation/sdk": "0.6.16",
54
- "@module-federation/error-codes": "0.6.14"
53
+ "@module-federation/sdk": "0.7.1",
54
+ "@module-federation/error-codes": "0.7.1"
55
55
  }
56
56
  }
File without changes
File without changes
File without changes