CompilerPluginRuntime
CompilerPluginRuntime
CompilerPluginRuntime is a runtime for managing compiler plugins in CommandKit.
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
constructor
(plugins: CompilerPlugin[]) => CompilerPluginRuntime
Creates a new instance of CompilerPluginRuntime.
getPlugins
() =>
Returns the plugins managed by this runtime.
isEmpty
() =>
Checks if there are no plugins registered in this runtime.
registerTemplate
(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
(name: string) =>
Unregisters a template handler for a given name. This method must be called inside the deactivate() method of a plugin.
getTemplate
(name: string) => TemplateHandler | undefined
Retrieves a template handler by its name.
getTemplates
() => 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
(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
() =>
Initializes the plugin runtime by activating all registered plugins. This method should be called once to set up the plugins.
destroy
() =>
Destroys the plugin runtime by deactivating all registered plugins. This method should be called when the runtime is no longer needed.
toJSON
() =>
Converts the plugin runtime to a JSON representation. This is useful for serialization or debugging purposes.