@module-federation/runtime 0.0.0-next-20240402191904 → 0.0.0-next-20240403002421

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/README.md CHANGED
@@ -325,6 +325,48 @@ registerRemotes([
325
325
  ]);
326
326
  ```
327
327
 
328
+ ### registerPlugins
329
+
330
+ - Type: `registerPlugins(plugins: Array<FederationRuntimePlugin>): void`
331
+ - Used to register remotes after init .
332
+
333
+ - Type
334
+
335
+ ```typescript
336
+ import type { FederationRuntimePlugin } from '@module-federation/runtime';
337
+
338
+ function registerPlugins(plugins: Array<FederationRuntimePlugin>) {}
339
+ ```
340
+
341
+ - Details:
342
+ Allows plugins to be registered dynamically or lazily. Lazy plugins will be called after normal runtime plugins.
343
+ Similar function as registerRemote, but for runtime plugins.
344
+ * Example
345
+
346
+ ```ts
347
+ import { init, registerPlugins } from '@module-federation/runtime';
348
+
349
+ init({
350
+ name: '@demo/register-new-remotes',
351
+ remotes: [
352
+ {
353
+ name: '@demo/sub1',
354
+ entry: 'http://localhost:2001/mf-manifest.json',
355
+ }
356
+ ],
357
+ plugins: [
358
+ //normal/eager runtime plugins
359
+ ]
360
+ });
361
+
362
+ import('./runtime-plugin').then(plugin => {
363
+ registerPlugins([
364
+ //more plugins loaded lazyily or dynamically
365
+ plugin
366
+ ]);
367
+ })
368
+ ```
369
+
328
370
  ## hooks
329
371
 
330
372
  Lifecycle hooks for FederationHost interaction.
package/dist/index.cjs.js CHANGED
@@ -69,7 +69,7 @@ function matchRemote(remotes, nameOrAlias) {
69
69
  return;
70
70
  }
71
71
 
72
- function registerPlugins(plugins, hookInstances) {
72
+ function registerPlugins$1(plugins, hookInstances) {
73
73
  const globalPlugins = share.getGlobalHostPlugins();
74
74
  // Incorporate global plugins
75
75
  if (globalPlugins.length > 0) {
@@ -1527,7 +1527,7 @@ class FederationHost {
1527
1527
  return optionsRes;
1528
1528
  }
1529
1529
  registerPlugins(plugins) {
1530
- registerPlugins(plugins, [
1530
+ registerPlugins$1(plugins, [
1531
1531
  this.hooks,
1532
1532
  this.snapshotHandler.hooks,
1533
1533
  this.loaderHook
@@ -1738,6 +1738,11 @@ function registerRemotes(...args) {
1738
1738
  // eslint-disable-next-line prefer-spread
1739
1739
  return FederationInstance.registerRemotes.apply(FederationInstance, args);
1740
1740
  }
1741
+ function registerPlugins(...args) {
1742
+ share.assert(FederationInstance, 'Please call init first');
1743
+ // eslint-disable-next-line prefer-spread
1744
+ return FederationInstance.registerPlugins.apply(FederationInstance, args);
1745
+ }
1741
1746
  // Inject for debug
1742
1747
  share.setGlobalFederationConstructor(FederationHost);
1743
1748
 
@@ -1758,4 +1763,5 @@ exports.loadRemote = loadRemote;
1758
1763
  exports.loadShare = loadShare;
1759
1764
  exports.loadShareSync = loadShareSync;
1760
1765
  exports.preloadRemote = preloadRemote;
1766
+ exports.registerPlugins = registerPlugins;
1761
1767
  exports.registerRemotes = registerRemotes;
package/dist/index.esm.js CHANGED
@@ -67,7 +67,7 @@ function matchRemote(remotes, nameOrAlias) {
67
67
  return;
68
68
  }
69
69
 
70
- function registerPlugins(plugins, hookInstances) {
70
+ function registerPlugins$1(plugins, hookInstances) {
71
71
  const globalPlugins = getGlobalHostPlugins();
72
72
  // Incorporate global plugins
73
73
  if (globalPlugins.length > 0) {
@@ -1525,7 +1525,7 @@ class FederationHost {
1525
1525
  return optionsRes;
1526
1526
  }
1527
1527
  registerPlugins(plugins) {
1528
- registerPlugins(plugins, [
1528
+ registerPlugins$1(plugins, [
1529
1529
  this.hooks,
1530
1530
  this.snapshotHandler.hooks,
1531
1531
  this.loaderHook
@@ -1736,7 +1736,12 @@ function registerRemotes(...args) {
1736
1736
  // eslint-disable-next-line prefer-spread
1737
1737
  return FederationInstance.registerRemotes.apply(FederationInstance, args);
1738
1738
  }
1739
+ function registerPlugins(...args) {
1740
+ assert(FederationInstance, 'Please call init first');
1741
+ // eslint-disable-next-line prefer-spread
1742
+ return FederationInstance.registerPlugins.apply(FederationInstance, args);
1743
+ }
1739
1744
  // Inject for debug
1740
1745
  setGlobalFederationConstructor(FederationHost);
1741
1746
 
1742
- export { FederationHost, getRemoteEntry, getRemoteInfo, init, loadRemote, loadShare, loadShareSync, preloadRemote, registerRemotes };
1747
+ export { FederationHost, getRemoteEntry, getRemoteInfo, init, loadRemote, loadShare, loadShareSync, preloadRemote, registerPlugins, registerRemotes };
@@ -153,7 +153,7 @@ export declare class FederationHost {
153
153
  initializeSharing(shareScopeName?: string, strategy?: Shared['strategy']): Array<Promise<void>>;
154
154
  initShareScopeMap(scopeName: string, shareScope: ShareScopeMap[string]): void;
155
155
  private formatOptions;
156
- private registerPlugins;
156
+ registerPlugins(plugins: UserOptions['plugins']): void;
157
157
  private setShared;
158
158
  private removeRemote;
159
159
  private registerRemote;
@@ -12,3 +12,4 @@ export declare function loadShare(...args: Parameters<FederationHost['loadShare'
12
12
  export declare function loadShareSync(...args: Parameters<FederationHost['loadShareSync']>): ReturnType<FederationHost['loadShareSync']>;
13
13
  export declare function preloadRemote(...args: Parameters<FederationHost['preloadRemote']>): ReturnType<FederationHost['preloadRemote']>;
14
14
  export declare function registerRemotes(...args: Parameters<FederationHost['registerRemotes']>): ReturnType<FederationHost['registerRemotes']>;
15
+ export declare function registerPlugins(...args: Parameters<FederationHost['registerPlugins']>): ReturnType<FederationHost['registerRemotes']>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/runtime",
3
- "version": "0.0.0-next-20240402191904",
3
+ "version": "0.0.0-next-20240403002421",
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.0-next-20240402191904"
48
+ "@module-federation/sdk": "0.0.0-next-20240403002421"
49
49
  }
50
50
  }