workflow.ts). Packages written for 1.x, with a workflow.yaml, keep running: you don’t have to change them. This page lists what changes for the people who run codemods and for the people who write them.
Codemod 2.0 is published on npm under the
next tag, and latest is still 1.x. Run 2.0 with npx codemod@next, or pin a version such as npx codemod@2.0.0.If you run codemods
Running 1.x packages
Run a 1.x registry or local package withworkflow.yaml without converting it:
fs: reads, writes (a write replaces a file that is there, as on 1.x) and unlinkSync, all part of the step’s diff. It does not rewrite the package. Use workflow upgrade only when you want to convert the source to workflow.ts.
A few 1.x features run differently. The full list is in What behaves differently. The ones you are most likely to notice:
- Steps with
runtime: dockerorruntime: podmanare refused. The CLI refuses the workflow before running any steps and names the node or template. Usecodemod run --v1 <package>if the workflow needs the 1.x runner. - Semantic analysis is on by default in
js-ast-grepsteps, sodefinition()andreferences()now return results in workflows. $STATE_OUTPUTSin shell steps needs a POSIX shell. On Windows, a workflow that uses it fails before any step runs.- Registry packages need
--approveto run shell steps unattended. In CI or with--no-interactive, a registry package’srun:step (and its agent, HTTP and pull request steps) stops the run until you pass--approveor the kind it needs, such as--approve=shell. The message names it. Local packages are trusted as before. - Shell steps run in the target directory, not the directory you ran the CLI from.
definition()follows re-exports to the file that declares a symbol, so a transform that rewrites imports from it can write different imports than on 1.x.
Commands and flags that changed
New in 2.0:
workflow status --format json, workflow list --format json, workflow inspect, workflow attach, workflow send, workflow upgrade, --approve on workflow run, --control stdio, and --managed-git for git steps. See the CLI reference.
Exit codes
2.0 tells you how a run ended with its exit code. A script that only checked for0 keeps working, but it can now tell a run that is waiting for someone apart from one that failed.
See Exit codes for the details.
Resuming runs
- Resume a run by its id:
codemod workflow resume --id <id>. Find the id in the run’s output or withcodemod workflow list. - Runs started by the 1.x CLI can’t be resumed by 2.0. Finish them with 1.x, or start them again with 2.0.
- Each run records the CLI version that started it. Resume with the same version when you can: if finished steps no longer match,
workflow resumerefuses unless you pass--forceto run those steps again. - Only one run at a time can work on a repository. Starting a second run on a target while another run is working on it fails with an error that names the other run.
- Runs are saved under your data directory (
~/Library/Application Support/codemod/runson macOS). SetCODEMOD_RUN_STORE_DIRto keep them somewhere else.
Telemetry
The CLI sends anonymous usage data, as 1.x did. Turn it off with--disable-analytics, DISABLE_ANALYTICS=1, or DO_NOT_TRACK=1. See Telemetry.
If you write codemods
Yourworkflow.yaml package keeps working and you can keep publishing it. When you want TypeScript workflows, tests that run the whole workflow, and step results you can pass around, convert it:
--dry-run shows the changes as a diff and writes nothing. The upgrade checks every package before it writes anything: when one can’t be upgraded, it names every problem, writes nothing and exits with code 2. It refuses workflow files that are symbolic links, two workflows whose new files would differ only in letter case, and a package whose transforms would not load in 2.0, naming the transform and the import that stopped it.
Upgraded transforms keep 1.x fs inside the target (reads, writes that replace a file, and unlinkSync), so helpers that read or update package.json keep working. That holds while the line upgrade writes, // Generated from workflow.yaml by `codemod workflow upgrade`., is among the comments workflow.ts starts with; hand-written workflows use codemod/files instead. A transform that imports child_process is not upgraded: move its commands to a shell step first.
If the upgrade itself won’t run, workflow upgrade --legacy uses the earlier translator without the workflow engine: it writes the files directly, and with --dry-run it prints the generated TypeScript instead of a diff. It doesn’t take --format.
Upgrade a 1.x package walks through it, and Migrate from workflow.yaml shows how each YAML feature maps to TypeScript.
Metrics are now return values
1.x YAML runs still supportcodemod:metrics and useMetricAtom. In a TypeScript workflow, return what you counted from the callback, then add it up with a reducer:
Output: … in the text output and output in workflow status --format json. See Build a report that fails CI and Metrics.
Fail the run with fail()
To fail the whole run and keep a report, call fail() from the workflow body. The run ends as failed, keeps its output, and the CLI exits 2:
failStep() from codemod/runtime still exists: it fails the step it is called in, and the error ends the run unless the workflow catches it. Use fail() when you want CI to see a report.
Callbacks don’t reach the outside world
forEachFile callbacks, function steps and reducers only compute: they can read files inside the target but cannot write through fs. They return values or use the file API to edit the current file. They can’t call fetch, start processes with child_process, or set environment variables. Do that with steps the run can show, ask about and replay:
Workflow runs still accept
--allow-fetch, --allow-fs and --allow-child-process, but warn and ignore them. Capability declarations in codemod.yaml do not change what callbacks can do. Standalone codemod jssg run and codemod jssg test still use capability flags.
runtime: docker
2.0 does not automatically run steps in containers. A workflow.yaml with runtime: docker or runtime: podman is refused before any step runs, and workflow upgrade reports it. Keep running the original package with 1.x, or explicitly invoke the container from a shell step when porting the workflow.
Other changes
- Import modules as
codemod/workflow,codemod/ast-grepand so on. Thecodemod:spelling still works. - In TypeScript workflows,
getState,setStateand$STATE_OUTPUTSare replaced by passing step results to later steps. See Values between steps. - A parameter you declare as
stringarrives as a string, even when it looks like a number (--param version=19gives"19"). 1.x parsed it as JSON. - Add
codemodas a dev dependency (npm install --save-dev codemod@next) so your editor knows the workflow types.