Skip to content

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"
new ActionHooks({actionKind, hooksFile?, hooks?, hookTimeout?, debug?})
OptionTypeDefaultDescription
actionKindstringAction identifier shared between runner and hooks (the exported hooks class name).
hooksFilestring (path, Node.js)Path to the hooks module to import.
hooksobjectA pre-instantiated hooks object.
hookTimeoutnumber1000Per-hook timeout in milliseconds.
debugfunctionLogger function for diagnostics.
new ActionHooks({
actionKind: "MyActionHooks",
hooksFile: "./hooks.js",
hookTimeout: 5000, // 5 seconds
debug: console.log,
})

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.

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.

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 */ }
}

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.