Plugins

The plugin system provides hooks for intercepting module resolution, loading, code transformation, shell commands, and lifecycle events. All types are exported from the main jiki package.

JikiPlugin

The interface every plugin must implement.

interface JikiPlugin {
  name: string;
  setup(hooks: PluginHooks): void;
}
PropertyTypeDescription
namestringHuman-readable name used in error messages
setup(hooks: PluginHooks) => voidCalled once during container construction

PluginHooks

Passed to setup(). Use it to register hooks.

hooks.onResolve(filter, callback)

Intercept module resolution. First matching callback that returns a result wins.

hooks.onResolve(filter: RegExp, callback: OnResolveCallback): void;

OnResolveArgs

PropertyTypeDescription
pathstringRaw module specifier (e.g. "./foo")
resolveDirstringDirectory the import originates from

OnResolveResult

PropertyTypeDescription
pathstringResolved absolute path

Return null or undefined to pass through to the next hook or the default resolver.

hooks.onLoad(filter, callback)

Intercept module loading. First matching callback that returns contents wins.

hooks.onLoad(filter: RegExp, callback: OnLoadCallback): void;

OnLoadArgs

PropertyTypeDescription
pathstringFully-resolved module path

OnLoadResult

PropertyTypeDescription
contentsstringSource code to use instead of reading VFS

Return null or undefined to fall through to VFS.

hooks.onTransform(filter, callback)

Transform source code. Runs as a pipeline — every matching callback executes in registration order.

hooks.onTransform(filter: RegExp, callback: OnTransformCallback): void;

OnTransformArgs

PropertyTypeDescription
pathstringFully-resolved file path
contentsstringSource code after previous transforms

OnTransformResult

PropertyTypeDescription
contentsstringTransformed source code

Return null or undefined to skip this transform step.

hooks.onCommand(name, handler)

Register a custom shell command.

hooks.onCommand(name: string, handler: CommandHandler): void;

The handler receives (args: string[], ctx: ShellContext) and returns a ShellResult ({ stdout, stderr, exitCode }).

hooks.onInstall(callback)

Called after packages are installed.

hooks.onInstall(callback: (packages: string[]) => void): void;

hooks.onBoot(callback)

Called after the container is fully initialised via container.init().

hooks.onBoot(callback: () => void): void;

PluginRegistry

Internal registry managing all hooks for a container. Exposed as container.plugins.

Property / MethodDescription
hasPluginstrue if any hooks are registered
resolveHookCountNumber of registered resolve hooks
loadHookCountNumber of registered load hooks
transformHookCountNumber of registered transform hooks
register(plugin)Register a plugin’s hooks
runResolve(path, dir)Execute resolve hooks (first-match-wins)
runLoad(path)Execute load hooks (first-match-wins)
runTransform(path, code)Execute transform pipeline
runInstall(packages)Notify install hooks
runBoot()Notify boot hooks

registerPlugin()

Register a plugin on an existing container after construction.

import { boot, registerPlugin } from "@run0/jiki";

const container = boot();
registerPlugin(container, myPlugin);

Imports

import {
  boot,
  registerPlugin,
  PluginRegistry,
  type JikiPlugin,
  type PluginHooks,
  type OnResolveArgs,
  type OnResolveResult,
  type OnLoadArgs,
  type OnLoadResult,
  type OnTransformArgs,
  type OnTransformResult,
  type OnInstallCallback,
  type OnBootCallback,
} from "@run0/jiki";