ActionHooks
ActionHooks manages the before$ / after$ lifecycle callbacks that fire
around each activity. You usually configure hooks through the builder’s
withHooks() or
withHooksFile()
methods rather than constructing this class directly — but the constructor is
available when you need to tune options like the hook timeout.
import {ActionHooks} from "@gesslar/actioneer"Constructor
Section titled “Constructor”new ActionHooks({actionKind, hooksFile?, hooks?, hookTimeout?, debug?})| Option | Type | Default | Description |
|---|---|---|---|
actionKind | string | — | Action identifier shared between runner and hooks (the exported hooks class name). |
hooksFile | string (path, Node.js) | — | Path to the hooks module to import. |
hooks | object | — | A pre-instantiated hooks object. |
hookTimeout | number | 1000 | Per-hook timeout in milliseconds. |
debug | function | — | Logger function for diagnostics. |
new ActionHooks({ actionKind: "MyActionHooks", hooksFile: "./hooks.js", hookTimeout: 5000, // 5 seconds debug: console.log,})ActionHooks.new(config, debug)
Section titled “ActionHooks.new(config, debug)”Node.js only. Static async factory that loads and instantiates a hooks class
from a file. Validates that the file exists and exports the named class, then
returns a ready ActionHooks instance.
const hooks = await ActionHooks.new({ actionKind: "MyActionHooks", hooksFile: "./hooks/MyActionHooks.js",}, console.log)Throws a Sass error if the hooks file does not exist. If the file exists but
does not export the named class (or fails to import), .new resolves to null
rather than throwing.
Hook timeout
Section titled “Hook timeout”Each hook must complete within hookTimeout milliseconds (default 1000ms).
If a hook exceeds the timeout, the pipeline throws a Sass error. Raise the
limit via the constructor option above for legitimately slow setup/teardown
work.
Authoring hooks
Section titled “Authoring hooks”Hook classes follow the event$activityName naming convention, with optional
setup and cleanup methods. The full authoring guide — including the
name-normalization rules — lives in Lifecycle Hooks.
export class MyActionHooks { constructor({debug}) { this.debug = debug }
async before$prepare(context) { this.debug("before prepare", context) } async after$prepare(context) { this.debug("after prepare", context) }
async setup(args) { /* once at init */ } async cleanup(args) { /* once at teardown */ }}Nested pipelines
Section titled “Nested pipelines”Hooks configured on a parent builder are automatically propagated to all nested builders, so a single configuration covers the entire pipeline hierarchy. See Nested Pipelines.
Related
Section titled “Related”- Lifecycle Hooks — the full guide with examples.
- ActionBuilder —
withHooks()/withHooksFile().