Overview
Takin is the underlying framework that drives all MorJS build tooling. It provides:- A plugin system based on tapable hooks.
- Automatic configuration file loading, validation (via zod), and filtering.
- Multi-config support: run one command across multiple configurations in parallel.
- An extensible
Runnerclass whose hooks and methods can be augmented by plugins.
| Property | Value |
|---|---|
| Package | @morjs/takin |
| License | MIT |
| Default export | takin(name: string): Takin factory function |
Installation
Quick start
Takin class
constructor
The CLI name used in log prefixes and runner identification.
use
Registers plugins with the Takin instance. Plugins are applied to every Runner that is started.
Array of plugin instances (objects implementing the
Plugin interface), plugin factories, or [plugin, options] tuples.run
Executes a command. Internally:
- Fires
hooks.initialize. - Loads and filters user config (fires
hooks.configLoadedandhooks.configFiltered). - Creates one
Runnerper filtered config and runs it.
Command to run. If omitted, the command is parsed from
process.argv.User configurations to run against. If omitted, Takin loads
mor.config.ts (or equivalent) from the current working directory.Initial key-value context passed into every
Runner. Accessible via runner.context.reload
Stops all running Runner instances, resets configuration, and re-runs the last command with the same arguments.
TakinHooks
Hooks available on every Takin instance.
Fires after
takin.run() is called but before any configuration is loaded. Use this to register additional plugins or modify the Takin instance.Preparatory stage run by an isolated
Runner. Use this to modify RunnerOptions before the main runners are started.Fires after the user configuration file is loaded from disk. Not fired when
userConfigs is passed directly to run(). Use this to post-process or validate the loaded config.Fires after configs are filtered by active targets / names. The hook receives the current filtered array and must return the final array to use.
Allows replacing or sub-classing the
Runner class used for each configuration. Tap this hook and return a Runner subclass to add custom properties or methods.Plugin interface
Unique plugin identifier used in log output and deduplication checks.
Plugin version string. Used for debug logging.
Execution order relative to other plugins.
'pre'— runs before all normal plugins.'post'— runs after all normal plugins.- Omitted — normal order.
Called once when the plugin is registered with
takin.use(). Use this to register additional plugins or hook into TakinHooks.Called once per
Runner execution. All runner.hooks taps should happen here.PluginEnforceTypes
Runner class
The command execution unit. One Runner instance is created per filtered user configuration.
RunnerHooks
All hooks available inside a plugin’s apply(runner) method.
| Hook | Type | Description |
|---|---|---|
initialize | SyncHook<Runner> | Fires after all plugins are applied |
cli | SyncHook<Cli> | Build the CLI command tree |
matchedCommand | AsyncSeriesHook<CommandOptions> | A CLI command has been matched |
loadConfig | AsyncSeriesHook<CommandOptions> | Load the user config file |
modifyUserConfig | AsyncSeriesWaterfallHook<[UserConfig, CommandOptions]> | Modify the resolved user config |
registerUserConfig | AsyncSeriesWaterfallHook<[AnyZodObject, Zod]> | Register config validation schema |
shouldRun | SyncBailHook<Runner, boolean | undefined> | Return false to abort execution |
shouldValidateUserConfig | SyncBailHook<Runner, boolean | undefined> | Return false to skip config validation |
userConfigValidated | AsyncSeriesHook<UserConfig> | Config validated; safe to read runner.userConfig |
beforeRun | AsyncSeriesHook<Runner> | Just before the command action fires |
run | HookMap<AsyncParallelHook<CommandOptions>> | Per-command action hooks (run.for('command:build')) |
done | AsyncParallelHook<Runner> | Runner completed successfully |
failed | AsyncSeriesHook<Error> | Runner threw an unhandled error |
shutdown | AsyncSeriesHook<Runner> | Runner is being shut down (used by reload()) |
RunnerOptions
Extending Runner
Use hooks.extendRunner to add typed properties and methods to the Runner class: