@module-federation/runtime 0.1.19 → 0.1.20

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
@@ -264,14 +264,14 @@ let Module = class Module {
264
264
  version: this.remoteInfo.version || ''
265
265
  };
266
266
  // Help to find host instance
267
- Object.defineProperty(remoteEntryInitOptions, 'hostId', {
268
- value: this.host.options.id || this.host.name,
267
+ Object.defineProperty(remoteEntryInitOptions, 'shareScopeMap', {
268
+ value: localShareScopeMap,
269
269
  // remoteEntryInitOptions will be traversed and assigned during container init, ,so this attribute is not allowed to be traversed
270
270
  enumerable: false
271
271
  });
272
272
  const initContainerOptions = await this.host.hooks.lifecycle.beforeInitContainer.emit({
273
273
  shareScope,
274
- // @ts-ignore hostId will be set by Object.defineProperty
274
+ // @ts-ignore shareScopeMap will be set by Object.defineProperty
275
275
  remoteEntryInitOptions,
276
276
  initScope,
277
277
  remoteInfo: this.remoteInfo,
@@ -296,7 +296,7 @@ let Module = class Module {
296
296
  }
297
297
  wraperFactory(moduleFactory, id) {
298
298
  function defineModuleId(res, id) {
299
- if (res && typeof res === 'object' && !Object.getOwnPropertyDescriptor(res, Symbol.for('mf_module_id'))) {
299
+ if (res && typeof res === 'object' && Object.isExtensible(res) && !Object.getOwnPropertyDescriptor(res, Symbol.for('mf_module_id'))) {
300
300
  Object.defineProperty(res, Symbol.for('mf_module_id'), {
301
301
  value: id,
302
302
  enumerable: false
@@ -1481,13 +1481,15 @@ class SharedHandler {
1481
1481
  2. The ${pkgName} share was not registered with the 'lib' attribute.\n
1482
1482
  `);
1483
1483
  }
1484
- initShareScopeMap(scopeName, shareScope) {
1484
+ initShareScopeMap(scopeName, shareScope, extraOptions = {}) {
1485
1485
  const { host } = this;
1486
1486
  this.shareScopeMap[scopeName] = shareScope;
1487
1487
  this.hooks.lifecycle.initContainerShareScopeMap.emit({
1488
1488
  shareScope,
1489
1489
  options: host.options,
1490
- origin: host
1490
+ origin: host,
1491
+ scopeName,
1492
+ hostShareScopeMap: extraOptions.hostShareScopeMap
1491
1493
  });
1492
1494
  }
1493
1495
  setShared({ pkgName, shared, from, lib, loading, loaded, get }) {
@@ -1538,7 +1540,7 @@ class SharedHandler {
1538
1540
  loadShare: new AsyncHook(),
1539
1541
  resolveShare: new SyncWaterfallHook('resolveShare'),
1540
1542
  // maybe will change, temporarily for internal use only
1541
- initContainerShareScopeMap: new AsyncWaterfallHook('initContainer')
1543
+ initContainerShareScopeMap: new SyncWaterfallHook('initContainerShareScopeMap')
1542
1544
  });
1543
1545
  this.host = host;
1544
1546
  this.shareScopeMap = {};
@@ -1717,6 +1719,7 @@ class RemoteHandler {
1717
1719
  };
1718
1720
  }
1719
1721
  registerRemote(remote, targetRemotes, options) {
1722
+ const { host } = this;
1720
1723
  const normalizeRemote = ()=>{
1721
1724
  if (remote.alias) {
1722
1725
  // Validate if alias equals the prefix of remote.name and remote.alias, if so, throw an error
@@ -1744,6 +1747,10 @@ class RemoteHandler {
1744
1747
  if (!registeredRemote) {
1745
1748
  normalizeRemote();
1746
1749
  targetRemotes.push(remote);
1750
+ this.hooks.lifecycle.registerRemote.emit({
1751
+ remote,
1752
+ origin: host
1753
+ });
1747
1754
  } else {
1748
1755
  const messages = [
1749
1756
  `The remote "${remote.name}" is already registered.`,
@@ -1754,6 +1761,10 @@ class RemoteHandler {
1754
1761
  this.removeRemote(registeredRemote);
1755
1762
  normalizeRemote();
1756
1763
  targetRemotes.push(remote);
1764
+ this.hooks.lifecycle.registerRemote.emit({
1765
+ remote,
1766
+ origin: host
1767
+ });
1757
1768
  }
1758
1769
  sdk.warn(messages.join(' '));
1759
1770
  }
@@ -1838,6 +1849,7 @@ class RemoteHandler {
1838
1849
  }
1839
1850
  constructor(host){
1840
1851
  this.hooks = new PluginSystem({
1852
+ registerRemote: new SyncWaterfallHook('registerRemote'),
1841
1853
  beforeRequest: new AsyncWaterfallHook('beforeRequest'),
1842
1854
  onLoad: new AsyncHook('onLoad'),
1843
1855
  handlePreloadModule: new SyncHook('handlePreloadModule'),
@@ -1907,8 +1919,8 @@ class FederationHost {
1907
1919
  async preloadRemote(preloadOptions) {
1908
1920
  return this.remoteHandler.preloadRemote(preloadOptions);
1909
1921
  }
1910
- initShareScopeMap(scopeName, shareScope) {
1911
- this.sharedHandler.initShareScopeMap(scopeName, shareScope);
1922
+ initShareScopeMap(scopeName, shareScope, extraOptions = {}) {
1923
+ this.sharedHandler.initShareScopeMap(scopeName, shareScope, extraOptions);
1912
1924
  }
1913
1925
  formatOptions(globalOptions, userOptions) {
1914
1926
  const { shared } = share.formatShareConfigs(globalOptions, userOptions);
@@ -1970,7 +1982,7 @@ class FederationHost {
1970
1982
  // maybe will change, temporarily for internal use only
1971
1983
  initContainer: new AsyncWaterfallHook('initContainer')
1972
1984
  });
1973
- this.version = "0.1.19";
1985
+ this.version = "0.1.20";
1974
1986
  this.moduleCache = new Map();
1975
1987
  this.loaderHook = new PluginSystem({
1976
1988
  // FIXME: may not be suitable , not open to the public yet
package/dist/index.esm.js CHANGED
@@ -262,14 +262,14 @@ let Module = class Module {
262
262
  version: this.remoteInfo.version || ''
263
263
  };
264
264
  // Help to find host instance
265
- Object.defineProperty(remoteEntryInitOptions, 'hostId', {
266
- value: this.host.options.id || this.host.name,
265
+ Object.defineProperty(remoteEntryInitOptions, 'shareScopeMap', {
266
+ value: localShareScopeMap,
267
267
  // remoteEntryInitOptions will be traversed and assigned during container init, ,so this attribute is not allowed to be traversed
268
268
  enumerable: false
269
269
  });
270
270
  const initContainerOptions = await this.host.hooks.lifecycle.beforeInitContainer.emit({
271
271
  shareScope,
272
- // @ts-ignore hostId will be set by Object.defineProperty
272
+ // @ts-ignore shareScopeMap will be set by Object.defineProperty
273
273
  remoteEntryInitOptions,
274
274
  initScope,
275
275
  remoteInfo: this.remoteInfo,
@@ -294,7 +294,7 @@ let Module = class Module {
294
294
  }
295
295
  wraperFactory(moduleFactory, id) {
296
296
  function defineModuleId(res, id) {
297
- if (res && typeof res === 'object' && !Object.getOwnPropertyDescriptor(res, Symbol.for('mf_module_id'))) {
297
+ if (res && typeof res === 'object' && Object.isExtensible(res) && !Object.getOwnPropertyDescriptor(res, Symbol.for('mf_module_id'))) {
298
298
  Object.defineProperty(res, Symbol.for('mf_module_id'), {
299
299
  value: id,
300
300
  enumerable: false
@@ -1479,13 +1479,15 @@ class SharedHandler {
1479
1479
  2. The ${pkgName} share was not registered with the 'lib' attribute.\n
1480
1480
  `);
1481
1481
  }
1482
- initShareScopeMap(scopeName, shareScope) {
1482
+ initShareScopeMap(scopeName, shareScope, extraOptions = {}) {
1483
1483
  const { host } = this;
1484
1484
  this.shareScopeMap[scopeName] = shareScope;
1485
1485
  this.hooks.lifecycle.initContainerShareScopeMap.emit({
1486
1486
  shareScope,
1487
1487
  options: host.options,
1488
- origin: host
1488
+ origin: host,
1489
+ scopeName,
1490
+ hostShareScopeMap: extraOptions.hostShareScopeMap
1489
1491
  });
1490
1492
  }
1491
1493
  setShared({ pkgName, shared, from, lib, loading, loaded, get }) {
@@ -1536,7 +1538,7 @@ class SharedHandler {
1536
1538
  loadShare: new AsyncHook(),
1537
1539
  resolveShare: new SyncWaterfallHook('resolveShare'),
1538
1540
  // maybe will change, temporarily for internal use only
1539
- initContainerShareScopeMap: new AsyncWaterfallHook('initContainer')
1541
+ initContainerShareScopeMap: new SyncWaterfallHook('initContainerShareScopeMap')
1540
1542
  });
1541
1543
  this.host = host;
1542
1544
  this.shareScopeMap = {};
@@ -1715,6 +1717,7 @@ class RemoteHandler {
1715
1717
  };
1716
1718
  }
1717
1719
  registerRemote(remote, targetRemotes, options) {
1720
+ const { host } = this;
1718
1721
  const normalizeRemote = ()=>{
1719
1722
  if (remote.alias) {
1720
1723
  // Validate if alias equals the prefix of remote.name and remote.alias, if so, throw an error
@@ -1742,6 +1745,10 @@ class RemoteHandler {
1742
1745
  if (!registeredRemote) {
1743
1746
  normalizeRemote();
1744
1747
  targetRemotes.push(remote);
1748
+ this.hooks.lifecycle.registerRemote.emit({
1749
+ remote,
1750
+ origin: host
1751
+ });
1745
1752
  } else {
1746
1753
  const messages = [
1747
1754
  `The remote "${remote.name}" is already registered.`,
@@ -1752,6 +1759,10 @@ class RemoteHandler {
1752
1759
  this.removeRemote(registeredRemote);
1753
1760
  normalizeRemote();
1754
1761
  targetRemotes.push(remote);
1762
+ this.hooks.lifecycle.registerRemote.emit({
1763
+ remote,
1764
+ origin: host
1765
+ });
1755
1766
  }
1756
1767
  warn$1(messages.join(' '));
1757
1768
  }
@@ -1836,6 +1847,7 @@ class RemoteHandler {
1836
1847
  }
1837
1848
  constructor(host){
1838
1849
  this.hooks = new PluginSystem({
1850
+ registerRemote: new SyncWaterfallHook('registerRemote'),
1839
1851
  beforeRequest: new AsyncWaterfallHook('beforeRequest'),
1840
1852
  onLoad: new AsyncHook('onLoad'),
1841
1853
  handlePreloadModule: new SyncHook('handlePreloadModule'),
@@ -1905,8 +1917,8 @@ class FederationHost {
1905
1917
  async preloadRemote(preloadOptions) {
1906
1918
  return this.remoteHandler.preloadRemote(preloadOptions);
1907
1919
  }
1908
- initShareScopeMap(scopeName, shareScope) {
1909
- this.sharedHandler.initShareScopeMap(scopeName, shareScope);
1920
+ initShareScopeMap(scopeName, shareScope, extraOptions = {}) {
1921
+ this.sharedHandler.initShareScopeMap(scopeName, shareScope, extraOptions);
1910
1922
  }
1911
1923
  formatOptions(globalOptions, userOptions) {
1912
1924
  const { shared } = formatShareConfigs(globalOptions, userOptions);
@@ -1968,7 +1980,7 @@ class FederationHost {
1968
1980
  // maybe will change, temporarily for internal use only
1969
1981
  initContainer: new AsyncWaterfallHook('initContainer')
1970
1982
  });
1971
- this.version = "0.1.19";
1983
+ this.version = "0.1.20";
1972
1984
  this.moduleCache = new Map();
1973
1985
  this.loaderHook = new PluginSystem({
1974
1986
  // 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.19",
3
+ "version": "0.1.20",
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.19";
193
+ globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.1.20";
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.19";
191
+ globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.1.20";
192
192
  }
193
193
  }
194
194
  // eslint-disable-next-line @typescript-eslint/ban-types
@@ -74,7 +74,9 @@ export declare class FederationHost {
74
74
  from: 'build' | 'runtime';
75
75
  }): Promise<T | null>;
76
76
  preloadRemote(preloadOptions: Array<PreloadRemoteArgs>): Promise<void>;
77
- initShareScopeMap(scopeName: string, shareScope: ShareScopeMap[string]): void;
77
+ initShareScopeMap(scopeName: string, shareScope: ShareScopeMap[string], extraOptions?: {
78
+ hostShareScopeMap?: ShareScopeMap;
79
+ }): void;
78
80
  private formatOptions;
79
81
  registerPlugins(plugins: UserOptions['plugins']): void;
80
82
  registerRemotes(remotes: Remote[], options?: {
@@ -1,7 +1,7 @@
1
1
  import { type ModuleInfo, type GlobalModuleInfo } from '@module-federation/sdk';
2
2
  import { Options, UserOptions, PreloadAssets, PreloadOptions, PreloadRemoteArgs, Remote, RemoteInfo } from '../type';
3
3
  import { FederationHost } from '../core';
4
- import { PluginSystem, AsyncHook, AsyncWaterfallHook, SyncHook } from '../utils/hooks';
4
+ import { PluginSystem, AsyncHook, AsyncWaterfallHook, SyncHook, SyncWaterfallHook } from '../utils/hooks';
5
5
  import { Module, ModuleOptions } from '../module';
6
6
  export interface LoadRemoteMatch {
7
7
  id: string;
@@ -16,6 +16,10 @@ export interface LoadRemoteMatch {
16
16
  export declare class RemoteHandler {
17
17
  host: FederationHost;
18
18
  hooks: PluginSystem<{
19
+ registerRemote: SyncWaterfallHook<{
20
+ remote: Remote;
21
+ origin: FederationHost;
22
+ }>;
19
23
  beforeRequest: AsyncWaterfallHook<{
20
24
  id: string;
21
25
  options: Options;
@@ -23,10 +23,12 @@ export declare class SharedHandler {
23
23
  GlobalFederation: Federation;
24
24
  resolver: () => Shared | undefined;
25
25
  }>;
26
- initContainerShareScopeMap: AsyncWaterfallHook<{
26
+ initContainerShareScopeMap: SyncWaterfallHook<{
27
27
  shareScope: ShareScopeMap[string];
28
28
  options: Options;
29
29
  origin: FederationHost;
30
+ scopeName: string;
31
+ hostShareScopeMap?: ShareScopeMap | undefined;
30
32
  }>;
31
33
  }>;
32
34
  constructor(host: FederationHost);
@@ -50,7 +52,9 @@ export declare class SharedHandler {
50
52
  customShareInfo?: Partial<Shared>;
51
53
  resolver?: (sharedOptions: ShareInfos[string]) => Shared;
52
54
  }): () => T | never;
53
- initShareScopeMap(scopeName: string, shareScope: ShareScopeMap[string]): void;
55
+ initShareScopeMap(scopeName: string, shareScope: ShareScopeMap[string], extraOptions?: {
56
+ hostShareScopeMap?: ShareScopeMap;
57
+ }): void;
54
58
  private setShared;
55
59
  private _setGlobalShareScopeMap;
56
60
  }
@@ -94,7 +94,7 @@ export type LoadModuleOptions = {
94
94
  };
95
95
  export type RemoteEntryInitOptions = {
96
96
  version: string;
97
- hostId: string;
97
+ shareScopeMap: ShareScopeMap;
98
98
  };
99
99
  export type InitScope = Array<Record<string, never>>;
100
100
  export type RemoteEntryExports = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/runtime",
3
- "version": "0.1.19",
3
+ "version": "0.1.20",
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.19"
48
+ "@module-federation/sdk": "0.1.20"
49
49
  }
50
50
  }