Class: Registry

Registry

Plugins are loaded and maintained in memory by the registry. The Registry class can find and load plugins from the filesystem, resolve plugin dependencies, order plugins such that their dependencies are all met, and initialize plugins. This process is called bootstrapping and it is the beginning of the plugin lifecycle.

A single registry instance is created by the Host constructor, which is then used in a variety of ways.

Instantiating:

let registry = new Registry({ ... })

Storing and querying plugins:

registry.set(<name>, new Plugin({ ... }))
registry.get(<name>)
registry.del(<name>)

registry.filter({ type: '<type>' })
registry.filter(plugin => <boolean-expr>)

Bootstrapping:

registry
  .glob()
  .require()
  .resolve()
  .prioritize()
  .initialize()

Plugin registration:

module.exports = function (<registry>) {
  <registry>.plugin(<name>, <metadata>).initializer(<callback>)
}

This module requires Plugin and PluginCollection.

Constructor

new Registry(options)

Initialize a Registry instance.

Parameters:
Name Type Description
options Object

Options object

Source:

Methods

del(name) → {Plugin}

Remove a plugin from the registry.

Parameters:
Name Type Description
name string

Name of the plugin

Source:
Returns:
Type
Plugin

filter(predicate) → {PluginCollection}

Query the registry for plugins matching a predicate

Parameters:
Name Type Description
predicate Object | function

Description or function for matching plugins

Source:
Returns:
Type
PluginCollection
Examples

Object predicate

registry.filter({ enabled: true })

Function predicate

registry.filter(plugin => !!plugin.name.match(regexp))

get(name) → {Plugin}

Retrieve a plugin from the registry.

Parameters:
Name Type Description
name string

name of the plugin

Source:
Returns:
Type
Plugin

glob()

Search the configured directories for plugin index files.

Source:

initialize()

Iterate over prioritized plugins and invoke initializer methods.

Source:

plugin(name, metadata) → {Plugin}

Register or retrieve a plugin from the injector with a name and metadata object.

Parameters:
Name Type Description
name string

Plugin name

metadata Object

Plugin metadata

Source:
Returns:
Type
Plugin

prioritize()

Given a list of plugins with dependencies, sort the list such that all dependencies can be met by iterating over the list.

Source:

require()

Load plugins to the registry without initializing them.

Source:

resolve()

Resolves and validates dependencies and dependents of all plugins.

Source:

satisfy()

Given a list of plugins without dependencies and a list of plugins with dependencies, return a list of plugins such that no plugins appear before their dependencies.

Source:

set(name, plugin) → {Plugin}

Set a plugin on the registry.

Parameters:
Name Type Description
name string

Name of the plugin

plugin Plugin

Name of the plugin

Source:
Returns:
Type
Plugin