@module-federation/runtime-core 0.0.0-next-20250708033956 → 0.0.0-next-20250708121428

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.
@@ -1012,8 +1012,16 @@ function matchRemote(remotes, nameOrAlias) {
1012
1012
  return;
1013
1013
  }
1014
1014
 
1015
- function registerPlugins(plugins, hookInstances) {
1015
+ function registerPlugins(plugins, instance) {
1016
1016
  const globalPlugins = getGlobalHostPlugins();
1017
+ const hookInstances = [
1018
+ instance.hooks,
1019
+ instance.remoteHandler.hooks,
1020
+ instance.sharedHandler.hooks,
1021
+ instance.snapshotHandler.hooks,
1022
+ instance.loaderHook,
1023
+ instance.bridgeHook
1024
+ ];
1017
1025
  // Incorporate global plugins
1018
1026
  if (globalPlugins.length > 0) {
1019
1027
  globalPlugins.forEach((plugin)=>{
@@ -1025,7 +1033,7 @@ function registerPlugins(plugins, hookInstances) {
1025
1033
  if (plugins && plugins.length > 0) {
1026
1034
  plugins.forEach((plugin)=>{
1027
1035
  hookInstances.forEach((hookInstance)=>{
1028
- hookInstance.applyPlugin(plugin);
1036
+ hookInstance.applyPlugin(plugin, instance);
1029
1037
  });
1030
1038
  });
1031
1039
  }
@@ -1688,13 +1696,14 @@ class AsyncWaterfallHook extends SyncHook {
1688
1696
  }
1689
1697
 
1690
1698
  class PluginSystem {
1691
- applyPlugin(plugin) {
1699
+ applyPlugin(plugin, instance) {
1692
1700
  assert(isPlainObject(plugin), 'Plugin configuration is invalid.');
1693
1701
  // The plugin's name is mandatory and must be unique
1694
1702
  const pluginName = plugin.name;
1695
1703
  assert(pluginName, 'A name must be provided by the plugin.');
1696
1704
  if (!this.registerPlugins[pluginName]) {
1697
1705
  this.registerPlugins[pluginName] = plugin;
1706
+ plugin.apply == null ? void 0 : plugin.apply.call(plugin, instance);
1698
1707
  Object.keys(this.lifecycle).forEach((key)=>{
1699
1708
  const pluginLife = plugin[key];
1700
1709
  if (pluginLife) {
@@ -1713,17 +1722,6 @@ class PluginSystem {
1713
1722
  }
1714
1723
  });
1715
1724
  }
1716
- // eslint-disable-next-line @typescript-eslint/no-shadow
1717
- inherit({ lifecycle, registerPlugins }) {
1718
- Object.keys(lifecycle).forEach((hookName)=>{
1719
- assert(!this.lifecycle[hookName], `The hook "${hookName}" has a conflict and cannot be inherited.`);
1720
- this.lifecycle[hookName] = lifecycle[hookName];
1721
- });
1722
- Object.keys(registerPlugins).forEach((pluginName)=>{
1723
- assert(!this.registerPlugins[pluginName], `The plugin "${pluginName}" has a conflict and cannot be inherited.`);
1724
- this.applyPlugin(registerPlugins[pluginName]);
1725
- });
1726
- }
1727
1725
  constructor(lifecycle){
1728
1726
  this.registerPlugins = {};
1729
1727
  this.lifecycle = lifecycle;
@@ -3000,14 +2998,7 @@ class FederationHost {
3000
2998
  return optionsRes;
3001
2999
  }
3002
3000
  registerPlugins(plugins) {
3003
- const pluginRes = registerPlugins(plugins, [
3004
- this.hooks,
3005
- this.remoteHandler.hooks,
3006
- this.sharedHandler.hooks,
3007
- this.snapshotHandler.hooks,
3008
- this.loaderHook,
3009
- this.bridgeHook
3010
- ]);
3001
+ const pluginRes = registerPlugins(plugins, this);
3011
3002
  // Merge plugin
3012
3003
  this.options.plugins = this.options.plugins.reduce((res, plugin)=>{
3013
3004
  if (!plugin) return res;
package/dist/index.esm.js CHANGED
@@ -1011,8 +1011,16 @@ function matchRemote(remotes, nameOrAlias) {
1011
1011
  return;
1012
1012
  }
1013
1013
 
1014
- function registerPlugins(plugins, hookInstances) {
1014
+ function registerPlugins(plugins, instance) {
1015
1015
  const globalPlugins = getGlobalHostPlugins();
1016
+ const hookInstances = [
1017
+ instance.hooks,
1018
+ instance.remoteHandler.hooks,
1019
+ instance.sharedHandler.hooks,
1020
+ instance.snapshotHandler.hooks,
1021
+ instance.loaderHook,
1022
+ instance.bridgeHook
1023
+ ];
1016
1024
  // Incorporate global plugins
1017
1025
  if (globalPlugins.length > 0) {
1018
1026
  globalPlugins.forEach((plugin)=>{
@@ -1024,7 +1032,7 @@ function registerPlugins(plugins, hookInstances) {
1024
1032
  if (plugins && plugins.length > 0) {
1025
1033
  plugins.forEach((plugin)=>{
1026
1034
  hookInstances.forEach((hookInstance)=>{
1027
- hookInstance.applyPlugin(plugin);
1035
+ hookInstance.applyPlugin(plugin, instance);
1028
1036
  });
1029
1037
  });
1030
1038
  }
@@ -1687,13 +1695,14 @@ class AsyncWaterfallHook extends SyncHook {
1687
1695
  }
1688
1696
 
1689
1697
  class PluginSystem {
1690
- applyPlugin(plugin) {
1698
+ applyPlugin(plugin, instance) {
1691
1699
  assert(isPlainObject(plugin), 'Plugin configuration is invalid.');
1692
1700
  // The plugin's name is mandatory and must be unique
1693
1701
  const pluginName = plugin.name;
1694
1702
  assert(pluginName, 'A name must be provided by the plugin.');
1695
1703
  if (!this.registerPlugins[pluginName]) {
1696
1704
  this.registerPlugins[pluginName] = plugin;
1705
+ plugin.apply == null ? void 0 : plugin.apply.call(plugin, instance);
1697
1706
  Object.keys(this.lifecycle).forEach((key)=>{
1698
1707
  const pluginLife = plugin[key];
1699
1708
  if (pluginLife) {
@@ -1712,17 +1721,6 @@ class PluginSystem {
1712
1721
  }
1713
1722
  });
1714
1723
  }
1715
- // eslint-disable-next-line @typescript-eslint/no-shadow
1716
- inherit({ lifecycle, registerPlugins }) {
1717
- Object.keys(lifecycle).forEach((hookName)=>{
1718
- assert(!this.lifecycle[hookName], `The hook "${hookName}" has a conflict and cannot be inherited.`);
1719
- this.lifecycle[hookName] = lifecycle[hookName];
1720
- });
1721
- Object.keys(registerPlugins).forEach((pluginName)=>{
1722
- assert(!this.registerPlugins[pluginName], `The plugin "${pluginName}" has a conflict and cannot be inherited.`);
1723
- this.applyPlugin(registerPlugins[pluginName]);
1724
- });
1725
- }
1726
1724
  constructor(lifecycle){
1727
1725
  this.registerPlugins = {};
1728
1726
  this.lifecycle = lifecycle;
@@ -2999,14 +2997,7 @@ class FederationHost {
2999
2997
  return optionsRes;
3000
2998
  }
3001
2999
  registerPlugins(plugins) {
3002
- const pluginRes = registerPlugins(plugins, [
3003
- this.hooks,
3004
- this.remoteHandler.hooks,
3005
- this.sharedHandler.hooks,
3006
- this.snapshotHandler.hooks,
3007
- this.loaderHook,
3008
- this.bridgeHook
3009
- ]);
3000
+ const pluginRes = registerPlugins(plugins, this);
3010
3001
  // Merge plugin
3011
3002
  this.options.plugins = this.options.plugins.reduce((res, plugin)=>{
3012
3003
  if (!plugin) return res;
@@ -30,5 +30,6 @@ type RemoteLifeCycleCyclePartial = Partial<{
30
30
  export type FederationRuntimePlugin = CoreLifeCyclePartial & SnapshotLifeCycleCyclePartial & SharedLifeCycleCyclePartial & RemoteLifeCycleCyclePartial & ModuleLifeCycleCyclePartial & ModuleBridgeLifeCycleCyclePartial & {
31
31
  name: string;
32
32
  version?: string;
33
+ apply?: (instance: FederationHost) => void;
33
34
  };
34
35
  export {};
@@ -1,15 +1,16 @@
1
+ import type { FederationHost } from '../../core';
1
2
  export type Plugin<T extends Record<string, any>> = {
2
3
  [k in keyof T]?: Parameters<T[k]['on']>[0];
3
4
  } & {
4
5
  name: string;
5
6
  version?: string;
7
+ apply?: (instance: FederationHost) => void;
6
8
  };
7
9
  export declare class PluginSystem<T extends Record<string, any>> {
8
10
  lifecycle: T;
9
11
  lifecycleKeys: Array<keyof T>;
10
12
  registerPlugins: Record<string, Plugin<T>>;
11
13
  constructor(lifecycle: T);
12
- applyPlugin(plugin: Plugin<T>): void;
14
+ applyPlugin(plugin: Plugin<T>, instance: FederationHost): void;
13
15
  removePlugin(pluginName: string): void;
14
- inherit<T extends PluginSystem<any>>({ lifecycle, registerPlugins, }: T): void;
15
16
  }
@@ -1,4 +1,3 @@
1
1
  import { FederationHost } from '../core';
2
2
  import { UserOptions } from '../type';
3
- import { Module } from '../module';
4
- export declare function registerPlugins(plugins: UserOptions['plugins'], hookInstances: Array<FederationHost['hooks'] | FederationHost['snapshotHandler']['hooks'] | FederationHost['sharedHandler']['hooks'] | FederationHost['remoteHandler']['hooks'] | Module['host']['loaderHook'] | Module['host']['bridgeHook']>): import("../type").FederationRuntimePlugin[] | undefined;
3
+ export declare function registerPlugins(plugins: UserOptions['plugins'], instance: FederationHost): import("../type").FederationRuntimePlugin[] | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/runtime-core",
3
- "version": "0.0.0-next-20250708033956",
3
+ "version": "0.0.0-next-20250708121428",
4
4
  "type": "module",
5
5
  "author": "zhouxiao <codingzx@gmail.com>",
6
6
  "main": "./dist/index.cjs.cjs",
@@ -52,7 +52,7 @@
52
52
  }
53
53
  },
54
54
  "dependencies": {
55
- "@module-federation/sdk": "0.0.0-next-20250708033956",
56
- "@module-federation/error-codes": "0.0.0-next-20250708033956"
55
+ "@module-federation/sdk": "0.0.0-next-20250708121428",
56
+ "@module-federation/error-codes": "0.0.0-next-20250708121428"
57
57
  }
58
58
  }