Skip to main content
Version: 1.2

CompilerPluginRuntime

CompilerPluginRuntime

CompilerPluginRuntime is a runtime for managing compiler plugins in CommandKit.

Signature
class CompilerPluginRuntime {
public readonly name = 'CompilerPluginRuntime';
constructor(plugins: CompilerPlugin[])
getPlugins() => ;
isEmpty() => ;
registerTemplate(name: string, handler: TemplateHandler) => ;
unregisterTemplate(name: string) => ;
getTemplate(name: string) => TemplateHandler | undefined;
getTemplates() => Map<string, TemplateHandler>;
transform(code: string, id: string) => Promise<{ code: string; map: string | null }>;
init() => ;
destroy() => ;
toJSON() => ;
}

name

property

constructor

method
(plugins: CompilerPlugin[]) => CompilerPluginRuntime

Creates a new instance of CompilerPluginRuntime.

getPlugins

method
() =>

Returns the plugins managed by this runtime.

isEmpty

method
() =>

Checks if there are no plugins registered in this runtime.

registerTemplate

method
(name: string, handler: TemplateHandler) =>

Registers a template handler for a given name. This method must be called inside the activate() method of a plugin.

unregisterTemplate

method
(name: string) =>

Unregisters a template handler for a given name. This method must be called inside the deactivate() method of a plugin.

getTemplate

method
(name: string) => TemplateHandler | undefined

Retrieves a template handler by its name.

getTemplates

method
() => Map<string, TemplateHandler>

Returns a map of all registered templates with their handlers. The keys are the template names and the values are the template handlers.

transform

method
(code: string, id: string) => Promise<{ code: string; map: string | null }>

Transforms the given code using all registered plugins. Each plugin's transform method is called in sequence, allowing them to modify the code.

init

method
() =>

Initializes the plugin runtime by activating all registered plugins. This method should be called once to set up the plugins.

destroy

method
() =>

Destroys the plugin runtime by deactivating all registered plugins. This method should be called when the runtime is no longer needed.

toJSON

method
() =>

Converts the plugin runtime to a JSON representation. This is useful for serialization or debugging purposes.