Skip to content

dependabit / plugins/registry/src / PluginLoader

Class: PluginLoader ​

Defined in: packages/plugins/registry/src/loader.ts:48

Validates and optionally initialises plugin instances before they are registered.

Remarks ​

PluginLoader is the recommended way to bring plugins into the registry because it validates metadata and calls initialize atomically.

Use When ​

Loading plugins from dynamic imports, configuration-driven plugin lists, or test fixtures where you want to confirm a plugin satisfies the contract before registering it.

Avoid When ​

You control the plugin class directly and prefer to call new and initialize manually — the overhead of validatePlugin is minimal but the extra abstraction may be unnecessary.

Never ​

  • load calls initialize if autoInitialize is true. If initialize throws, the plugin is not registered — but if the caller has already called PluginRegistry.register, the registry will hold a broken plugin instance. Always call load before register.
  • instantiate creates a new instance and calls load; the returned instance is fully initialised. Calling new PluginClass() directly and registering without going through the loader bypasses metadata validation.

Constructors ​

Constructor ​

ts
new PluginLoader(config?): PluginLoader;

Defined in: packages/plugins/registry/src/loader.ts:51

Parameters ​

ParameterType
configPluginLoaderConfig

Returns ​

PluginLoader

Methods ​

instantiate() ​

ts
instantiate<T, A>(PluginClass, ...args): Promise<T>;

Defined in: packages/plugins/registry/src/loader.ts:109

Instantiate a plugin from a class

Type Parameters ​

Type Parameter
T extends Plugin
A extends unknown[]

Parameters ​

ParameterType
PluginClass(...args) => T
...argsA

Returns ​

Promise<T>


load() ​

ts
load(plugin): Promise<Plugin>;

Defined in: packages/plugins/registry/src/loader.ts:89

Load and validate a plugin

Parameters ​

ParameterType
pluginunknown

Returns ​

Promise<Plugin>


loadMany() ​

ts
loadMany(plugins): Promise<Plugin[]>;

Defined in: packages/plugins/registry/src/loader.ts:102

Load multiple plugins

Parameters ​

ParameterType
pluginsunknown[]

Returns ​

Promise<Plugin[]>


validateMetadata() ​

ts
validateMetadata(metadata): {
  accessMethod: string;
  apiVersion?: string;
  description?: string;
  name: string;
  supportedTypes?: string[];
  version: string;
};

Defined in: packages/plugins/registry/src/loader.ts:61

Validate plugin metadata

Parameters ​

ParameterType
metadataunknown

Returns ​

ts
{
  accessMethod: string;
  apiVersion?: string;
  description?: string;
  name: string;
  supportedTypes?: string[];
  version: string;
}
NameTypeDefined in
accessMethodstringpackages/plugins/registry/src/registry.ts:41
apiVersion?stringpackages/plugins/registry/src/registry.ts:43
description?stringpackages/plugins/registry/src/registry.ts:40
namestringpackages/plugins/registry/src/registry.ts:38
supportedTypes?string[]packages/plugins/registry/src/registry.ts:42
versionstringpackages/plugins/registry/src/registry.ts:39

validatePlugin() ​

ts
validatePlugin(plugin): Plugin;

Defined in: packages/plugins/registry/src/loader.ts:68

Validate plugin structure

Parameters ​

ParameterType
pluginunknown

Returns ​

Plugin

Released under the MIT License.