In
workflow.ts, per-file logic is a forEachFile callback, inline or imported from its file: jssg(...) is not part of the workflow API. A jssg transform file ((root, options) => ...) is what codemod jssg run and codemod jssg test run, and what workflow.yaml’s js-ast-grep steps run; there it gets options.params and options.matrixValues as below. A callback gets the same values as variables it captures.Parameters and Configuration
Parameters make your codemods flexible and reusable by allowing you to pass configuration values at runtime. This enables you to create codemods that adapt their behavior based on user input or different execution contexts.Enterprise Features: In the Codemod app, parameters are configured through a visual UI.
options.params.
Matrix Strategy Integration
Matrix strategies enable you to run the same codemod with different configurations or to split large codebases into manageable chunks for parallel processing. Matrix values are particularly useful for:- Sharding: Distributing work across multiple processes or machines
- Multi-variant transforms: Running the same logic with different parameters
- Team-based processing: Applying different rules based on team ownership
Accessing Matrix Values
Access matrix values viaoptions.matrixValues:
options.matrixValues is only defined when your workflow uses a matrix strategy. Otherwise it is undefined.Passing matrix values
Inworkflow.ts, a callback gets a shard’s values as variables. A common pattern is one step per shard:
workflow.ts
Parameters vs matrix values: in a jssg transform,
options.params holds run parameters, while options.matrixValues holds a matrix node’s values. In workflow.yaml, matrix values come from a node’s matrix strategy; see the workflow.yaml reference.Passing Values Between Steps
Workflows have no shared state. A callback gets values as the variables it captures and reports what it found by returning it; a later step gets those values the same way.getState, setState, unsetState and acquireLock were removed from codemod/workflow. Importing them is a build error that names what replaced them.Collect, then apply
A step that needs something found across the repository runs after a step that finds it. Files are processed in parallel, so a value gathered and read inside one step depends on file order; two steps do not.Runtime Hooks
Thecodemod/runtime module lets a codemod send structured execution signals to the engine without relying on console.log parsing.
- show meaningful progress in workflow task logs
- warn without failing the task
- improve watchdog diagnostics by naming the active unit or file
- fail the current step explicitly instead of returning a generic exception
- stop cooperatively when the task has been canceled
API Reference
Emits a structured progress event. Progress updates appear in task logs and refresh the step heartbeat so long-running transforms can prove they are still alive.
Emits a non-fatal warning event. Warnings are appended to task logs but do not change task state.
Overrides the current logical execution unit for diagnostics. For file-based transforms, this is usually the relative file path.
Fails the current file or unit immediately. The runtime currently treats this as terminal for the running task.
Fails the current step immediately. This is always terminal for the running task.
Returns
true if the current task has been canceled. Use it to stop long-running work cooperatively.Example: Report progress and fail explicitly
codemod.ts
When to use hooks vs exceptions
- Use
runtime.progress(...)andruntime.warn(...)for structured observability. - Use
runtime.failStep(...)when the codemod has decided the task should stop immediately. - Plain thrown errors still fail the task if they escape the codemod, but hooks give better logs and clearer intent.
- The engine’s idle timeout is only a backstop for silent hangs. Hooks are the preferred way to report semantic failures.