@brickkit/cli/workflows
Load and build the `"use workflow"` and `"use step"` files of a Brick application, for tests and scripts that run workflows without `brick dev`.
@brickkit/cli/workflows exports 5 names: 5 functions.
import { buildAppWorkflows, buildWorkflows, registerWorkflowTransform } from "@brickkit/cli/workflows";Functions
| Function | Description |
|---|---|
buildAppWorkflows | Build the workflow bundle an app needs, if it has workflow listeners. |
buildWorkflows | Build the bundle that runs an app's workflows: flow.mjs and manifest.json in <root>/.well-known/workflow/v1, from every file under root marked `"use wo… |
registerWorkflowTransform | Make files marked "use workflow" or "use step" load as workflows and steps. |
shipWorkflows | What brick build ships: the workflow bundle, built from the project and copied to <outdir>/.well-known/workflow/v1, where the compiled server reads it. |
workflowTransformPlugin | The plugin that turns "use workflow" and "use step" files into workflows and steps. |
buildAppWorkflows
function buildAppWorkflows(
app: BrickApp,
options: { reuse?: boolean } = {},
): Promise<boolean>Build the workflow bundle an app needs, if it has workflow listeners.
Parameters
| Name | Type | Description |
|---|---|---|
app | BrickApp | The loaded app. |
options? | { reuse?: boolean } default {} | reuse: keep the last bundle when its sources have not changed. |
Returns Promise<boolean> — Whether the app has a bundle, built now or kept from the last build.
Source: packages/cli/src/workflows.ts:469
buildWorkflows
function buildWorkflows(
options: { root?: string; reuse?: boolean } = {},
): Promise<boolean>Build the bundle that runs an app's workflows: flow.mjs and manifest.json
in <root>/.well-known/workflow/v1, from every file under root marked
"use workflow" or "use step".
brick dev and brick start call it before events start. Call it in a script
or test before starting events.
Parameters
| Name | Type | Description |
|---|---|---|
options? | { root?: string; reuse?: boolean } default {} | root: the project root. Default: the working directory. reuse: keep the bundle of the last build when nothing it was built from has changed, which saves about a second on each reload of brick dev. Default: false, always build. |
Returns Promise<boolean> — Whether it built the bundle; false when it kept the last one.
Throws
- When
@workflow/buildersis not installed in the project.
Source: packages/cli/src/workflows.ts:387
registerWorkflowTransform
function registerWorkflowTransform(
root: string = process.cwd(),
): Promise<boolean>Make files marked "use workflow" or "use step" load as workflows and steps.
A workflow function gets the workflowId that defineListener({ workflow })
needs, and a step registers itself so the runtime can run it in this process.
brick dev, brick start and brick worker call it before they load the app.
Call it in a script or test before importing the files, with the project root.
It does nothing, and returns false, when the Workflow SDK and its builders are
not installed in the project. Each root gets ids relative to itself; a file
under no registered root uses the first one.
Parameters
| Name | Type | Description |
|---|---|---|
root? | string default process.cwd() | The project root, where the SDK is installed. Default: the working directory. |
Returns Promise<boolean> — Whether the transform is active.
Source: packages/cli/src/workflows.ts:155
shipWorkflows
function shipWorkflows(
root: string,
outdir: string,
required: boolean,
): Promise<boolean>What brick build ships: the workflow bundle, built from the project and
copied to <outdir>/.well-known/workflow/v1, where the compiled server reads
it. brick build calls it when the bundle holds a "use workflow" function, or
the loaded app runs workflows.
Parameters
| Name | Type | Description |
|---|---|---|
root | string | The project root. |
outdir | string | Where the compiled server is written. |
required | boolean | The loaded app runs workflows, so the SDK must be installed. |
Returns Promise<boolean> — Whether a bundle was shipped: it holds a workflow, or one is required.
Source: packages/cli/src/workflows.ts:508
workflowTransformPlugin
function workflowTransformPlugin(
root: string = process.cwd(),
onDirective?: () => void,
): Promise<BunPlugin | undefined>The plugin that turns "use workflow" and "use step" files into workflows and
steps. registerWorkflowTransform installs it for the running process;
brick build hands it to Bun.build.
Parameters
| Name | Type | Description |
|---|---|---|
root? | string default process.cwd() | The project root, where the SDK is installed. Default: the working directory. |
onDirective? | () => void | Called for each file it loads that holds a "use workflow" function. |
Returns Promise<BunPlugin \| undefined> — The plugin, or undefined when the Workflow SDK and its builders are not
installed in the project.
Source: packages/cli/src/workflows.ts:82