@module-federation/runtime 0.1.15 → 0.1.17

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/index.cjs.js CHANGED
@@ -243,7 +243,7 @@ let Module = class Module {
243
243
  return this.remoteEntryExports;
244
244
  }
245
245
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
246
- async get(expose, options) {
246
+ async get(id, expose, options) {
247
247
  const { loadFactory = true } = options || {
248
248
  loadFactory: true
249
249
  };
@@ -284,12 +284,38 @@ let Module = class Module {
284
284
  // get exposeGetter
285
285
  const moduleFactory = await remoteEntryExports.get(expose);
286
286
  share.assert(moduleFactory, `${share.getFMId(this.remoteInfo)} remote don't export ${expose}.`);
287
+ const wrapModuleFactory = this.wraperFactory(moduleFactory, id);
287
288
  if (!loadFactory) {
288
- return moduleFactory;
289
+ return wrapModuleFactory;
289
290
  }
290
- const exposeContent = await moduleFactory();
291
+ const exposeContent = await wrapModuleFactory();
291
292
  return exposeContent;
292
293
  }
294
+ wraperFactory(moduleFactory, id) {
295
+ function defineModuleId(res, id) {
296
+ if (res && typeof res === 'object' && !Object.getOwnPropertyDescriptor(res, Symbol.for('mf_module_id'))) {
297
+ Object.defineProperty(res, Symbol.for('mf_module_id'), {
298
+ value: id,
299
+ enumerable: false
300
+ });
301
+ }
302
+ }
303
+ if (moduleFactory instanceof Promise) {
304
+ return async ()=>{
305
+ const res = await moduleFactory();
306
+ // This parameter is used for bridge debugging
307
+ defineModuleId(res, id);
308
+ return res;
309
+ };
310
+ } else {
311
+ return ()=>{
312
+ const res = moduleFactory();
313
+ // This parameter is used for bridge debugging
314
+ defineModuleId(res, id);
315
+ return res;
316
+ };
317
+ }
318
+ }
293
319
  constructor({ remoteInfo, host }){
294
320
  this.inited = false;
295
321
  this.lib = undefined;
@@ -1500,7 +1526,7 @@ class RemoteHandler {
1500
1526
  id
1501
1527
  });
1502
1528
  const { pkgNameOrAlias, remote, expose, id: idRes } = remoteMatchInfo;
1503
- const moduleOrFactory = await module.get(expose, options);
1529
+ const moduleOrFactory = await module.get(idRes, expose, options);
1504
1530
  const moduleWrapper = await this.hooks.lifecycle.onLoad.emit({
1505
1531
  id: idRes,
1506
1532
  pkgNameOrAlias,
@@ -1537,7 +1563,7 @@ class RemoteHandler {
1537
1563
  async preloadRemote(preloadOptions) {
1538
1564
  const { host } = this;
1539
1565
  await this.hooks.lifecycle.beforePreloadRemote.emit({
1540
- preloadOptions,
1566
+ preloadOps: preloadOptions,
1541
1567
  options: host.options,
1542
1568
  origin: host
1543
1569
  });
@@ -1678,9 +1704,10 @@ class RemoteHandler {
1678
1704
  }
1679
1705
  const loadedModule = host.moduleCache.get(remote.name);
1680
1706
  if (loadedModule) {
1707
+ var _Object_getOwnPropertyDescriptor;
1681
1708
  const remoteInfo = loadedModule.remoteInfo;
1682
1709
  const key = remoteInfo.entryGlobalName;
1683
- if (globalThis[key]) {
1710
+ if (globalThis[key] && ((_Object_getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor(globalThis, key)) == null ? void 0 : _Object_getOwnPropertyDescriptor.configurable)) {
1684
1711
  delete globalThis[key];
1685
1712
  }
1686
1713
  const remoteEntryUniqueKey = getRemoteEntryUniqueKey(loadedModule.remoteInfo);
@@ -1752,7 +1779,7 @@ class RemoteHandler {
1752
1779
  onLoad: new AsyncHook('onLoad'),
1753
1780
  handlePreloadModule: new SyncHook('handlePreloadModule'),
1754
1781
  errorLoadRemote: new AsyncHook('errorLoadRemote'),
1755
- beforePreloadRemote: new AsyncHook(),
1782
+ beforePreloadRemote: new AsyncHook('beforePreloadRemote'),
1756
1783
  generatePreloadAssets: new AsyncHook('generatePreloadAssets'),
1757
1784
  // not used yet
1758
1785
  afterPreloadRemote: new AsyncHook()
@@ -1880,7 +1907,7 @@ class FederationHost {
1880
1907
  // maybe will change, temporarily for internal use only
1881
1908
  initContainer: new AsyncWaterfallHook('initContainer')
1882
1909
  });
1883
- this.version = "0.1.15";
1910
+ this.version = "0.1.17";
1884
1911
  this.moduleCache = new Map();
1885
1912
  this.loaderHook = new PluginSystem({
1886
1913
  // FIXME: may not be suitable , not open to the public yet
package/dist/index.esm.js CHANGED
@@ -241,7 +241,7 @@ let Module = class Module {
241
241
  return this.remoteEntryExports;
242
242
  }
243
243
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
244
- async get(expose, options) {
244
+ async get(id, expose, options) {
245
245
  const { loadFactory = true } = options || {
246
246
  loadFactory: true
247
247
  };
@@ -282,12 +282,38 @@ let Module = class Module {
282
282
  // get exposeGetter
283
283
  const moduleFactory = await remoteEntryExports.get(expose);
284
284
  assert(moduleFactory, `${getFMId(this.remoteInfo)} remote don't export ${expose}.`);
285
+ const wrapModuleFactory = this.wraperFactory(moduleFactory, id);
285
286
  if (!loadFactory) {
286
- return moduleFactory;
287
+ return wrapModuleFactory;
287
288
  }
288
- const exposeContent = await moduleFactory();
289
+ const exposeContent = await wrapModuleFactory();
289
290
  return exposeContent;
290
291
  }
292
+ wraperFactory(moduleFactory, id) {
293
+ function defineModuleId(res, id) {
294
+ if (res && typeof res === 'object' && !Object.getOwnPropertyDescriptor(res, Symbol.for('mf_module_id'))) {
295
+ Object.defineProperty(res, Symbol.for('mf_module_id'), {
296
+ value: id,
297
+ enumerable: false
298
+ });
299
+ }
300
+ }
301
+ if (moduleFactory instanceof Promise) {
302
+ return async ()=>{
303
+ const res = await moduleFactory();
304
+ // This parameter is used for bridge debugging
305
+ defineModuleId(res, id);
306
+ return res;
307
+ };
308
+ } else {
309
+ return ()=>{
310
+ const res = moduleFactory();
311
+ // This parameter is used for bridge debugging
312
+ defineModuleId(res, id);
313
+ return res;
314
+ };
315
+ }
316
+ }
291
317
  constructor({ remoteInfo, host }){
292
318
  this.inited = false;
293
319
  this.lib = undefined;
@@ -1498,7 +1524,7 @@ class RemoteHandler {
1498
1524
  id
1499
1525
  });
1500
1526
  const { pkgNameOrAlias, remote, expose, id: idRes } = remoteMatchInfo;
1501
- const moduleOrFactory = await module.get(expose, options);
1527
+ const moduleOrFactory = await module.get(idRes, expose, options);
1502
1528
  const moduleWrapper = await this.hooks.lifecycle.onLoad.emit({
1503
1529
  id: idRes,
1504
1530
  pkgNameOrAlias,
@@ -1535,7 +1561,7 @@ class RemoteHandler {
1535
1561
  async preloadRemote(preloadOptions) {
1536
1562
  const { host } = this;
1537
1563
  await this.hooks.lifecycle.beforePreloadRemote.emit({
1538
- preloadOptions,
1564
+ preloadOps: preloadOptions,
1539
1565
  options: host.options,
1540
1566
  origin: host
1541
1567
  });
@@ -1676,9 +1702,10 @@ class RemoteHandler {
1676
1702
  }
1677
1703
  const loadedModule = host.moduleCache.get(remote.name);
1678
1704
  if (loadedModule) {
1705
+ var _Object_getOwnPropertyDescriptor;
1679
1706
  const remoteInfo = loadedModule.remoteInfo;
1680
1707
  const key = remoteInfo.entryGlobalName;
1681
- if (globalThis[key]) {
1708
+ if (globalThis[key] && ((_Object_getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor(globalThis, key)) == null ? void 0 : _Object_getOwnPropertyDescriptor.configurable)) {
1682
1709
  delete globalThis[key];
1683
1710
  }
1684
1711
  const remoteEntryUniqueKey = getRemoteEntryUniqueKey(loadedModule.remoteInfo);
@@ -1750,7 +1777,7 @@ class RemoteHandler {
1750
1777
  onLoad: new AsyncHook('onLoad'),
1751
1778
  handlePreloadModule: new SyncHook('handlePreloadModule'),
1752
1779
  errorLoadRemote: new AsyncHook('errorLoadRemote'),
1753
- beforePreloadRemote: new AsyncHook(),
1780
+ beforePreloadRemote: new AsyncHook('beforePreloadRemote'),
1754
1781
  generatePreloadAssets: new AsyncHook('generatePreloadAssets'),
1755
1782
  // not used yet
1756
1783
  afterPreloadRemote: new AsyncHook()
@@ -1878,7 +1905,7 @@ class FederationHost {
1878
1905
  // maybe will change, temporarily for internal use only
1879
1906
  initContainer: new AsyncWaterfallHook('initContainer')
1880
1907
  });
1881
- this.version = "0.1.15";
1908
+ this.version = "0.1.17";
1882
1909
  this.moduleCache = new Map();
1883
1910
  this.loaderHook = new PluginSystem({
1884
1911
  // 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.1.15",
3
+ "version": "0.1.17",
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
@@ -190,7 +190,7 @@ function getGlobalFederationConstructor() {
190
190
  function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
191
191
  if (isDebug) {
192
192
  globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
193
- globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.1.15";
193
+ globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.1.17";
194
194
  }
195
195
  }
196
196
  // eslint-disable-next-line @typescript-eslint/ban-types
package/dist/share.esm.js CHANGED
@@ -188,7 +188,7 @@ function getGlobalFederationConstructor() {
188
188
  function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
189
189
  if (isDebug) {
190
190
  globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
191
- globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.1.15";
191
+ globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.1.17";
192
192
  }
193
193
  }
194
194
  // eslint-disable-next-line @typescript-eslint/ban-types
@@ -12,8 +12,9 @@ declare class Module {
12
12
  host: FederationHost;
13
13
  });
14
14
  getEntry(): Promise<RemoteEntryExports>;
15
- get(expose: string, options?: {
15
+ get(id: string, expose: string, options?: {
16
16
  loadFactory?: boolean;
17
17
  }): Promise<any>;
18
+ private wraperFactory;
18
19
  }
19
20
  export { Module };
@@ -48,11 +48,11 @@ export declare class RemoteHandler {
48
48
  lifecycle: 'onLoad' | 'beforeRequest';
49
49
  origin: FederationHost;
50
50
  }], unknown>;
51
- beforePreloadRemote: AsyncHook<{
51
+ beforePreloadRemote: AsyncHook<[{
52
52
  preloadOps: Array<PreloadRemoteArgs>;
53
53
  options: Options;
54
54
  origin: FederationHost;
55
- }, false | void | Promise<false | void>>;
55
+ }], false | void | Promise<false | void>>;
56
56
  generatePreloadAssets: AsyncHook<[{
57
57
  origin: FederationHost;
58
58
  preloadOptions: PreloadOptions[number];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/runtime",
3
- "version": "0.1.15",
3
+ "version": "0.1.17",
4
4
  "author": "zhouxiao <codingzx@gmail.com>",
5
5
  "main": "./dist/index.cjs.js",
6
6
  "module": "./dist/index.esm.js",
@@ -45,6 +45,6 @@
45
45
  }
46
46
  },
47
47
  "dependencies": {
48
- "@module-federation/sdk": "0.1.15"
48
+ "@module-federation/sdk": "0.1.17"
49
49
  }
50
50
  }