Skip to main content

@boost/plugin

build status npm version

Plugin based architecture that supports module loading, custom types, registries, scopes, and more.

import { Registry, Pluggable } from '@boost/plugin';

export interface Renderable<T> extends Pluggable<T> {
render(): string | Promise<string>;
}

const registry = new Registry<Renderable>('boost', 'plugin', {
validate(plugin) {
if (typeof plugin.render !== 'function') {
throw new TypeError('Plugins require a `render()` method.');
}
},
});

const plugin = await registry.load('boost-plugin-example');

Features

  • Custom plugin types and registries.
  • Node module, file path, and configuration file loading strategies.
  • Multiple module name formats: public, scoped public, scoped private.
  • Structural contracts with life cycle events.
  • Factory function pattern for plugin creation.
  • Asynchronous by default.

Installation

yarn add @boost/plugin

Documentation

Index

Type Aliases

Callback

Callback<T>: (value: T) => Promise<void> | void

Type parameters

  • T = unknown

Factory

Factory<T, O>: (options: Partial<O>) => Promise<T> | T

Type parameters

PluginErrorCode

PluginErrorCode: keyof typeof errors

Setting

Setting: Record<string, SourceOptions>

Source

Source: FilePath | ModuleID

SourceOptions

SourceOptions: boolean | object

SourceWithOptions

SourceWithOptions: [Source, SourceOptions]

Variables

constDEFAULT_PRIORITY

DEFAULT_PRIORITY: 100 = 100

constPluginError

PluginError: new (code: FACTORY_REQUIRED | MODULE_NAME_INVALID | MODULE_UNKNOWN_FORMAT | PLUGIN_REQUIRED | PLUGIN_REQUIRED_NAME | REGISTER_REQUIRED | SETTING_UNKNOWN, params?: unknown[]) => Error & ScopedError<FACTORY_REQUIRED | MODULE_NAME_INVALID | MODULE_UNKNOWN_FORMAT | PLUGIN_REQUIRED | PLUGIN_REQUIRED_NAME | REGISTER_REQUIRED | SETTING_UNKNOWN> = ...