workflow.ts, and check that the result and its tests are the same. You need Node.js 22.18 or later and Git.
1. The 1.x package
This package is whatcodemod init --project-type ast-grep-js makes on 1.x, shortened: a workflow.yaml with one js-ast-grep step, a transform that turns var into const, and a fixture test.
workflow.yaml
scripts/codemod.ts
codemod.yaml points at the workflow with path: workflow.yaml, and tests/fixtures/ holds an input.js and an expected.js. Put the package in a Git repository, and next to it a small project to run it on:
app/src/index.ts
2. Run it on 2.0 as it is
workflow.yaml to TypeScript in memory and ran that. The package didn’t change. Registry packages run the same way: npx codemod@next @org/my-1x-package. The compatibility path supports legacy metrics and workflow state without rewriting the source.
Undo the change: (cd app && git checkout -- .).
3. Preview the conversion
In the package directory:step, the js-ast-grep step became forEachFile with the same files, and the transform is imported and called for each file. Your transform doesn’t change.
4. Convert
latest tag, which is 1.x.
git status shows what it did: workflow.ts added, workflow.yaml removed (keep it with --keep-yaml), and codemod.yaml now says path: workflow.ts.
5. Check it
workflow.ts like any workflow: add steps, return a report, or test the whole workflow.
1.x’s
codemod init writes npx codemod@latest jssg test in package.json, and @latest is the 1.x CLI. Change it to codemod jssg test, and add codemod as a dev dependency, so the tests run with the CLI the package uses.Transforms that read files
1.x transforms often read the target withfs, directly or through a helper library. An upgraded workflow’s transforms keep what they had on 1.x, inside the target: fs reads files, writes them (replacing a file that is there) and deletes them with unlinkSync. The writes and deletes are part of the step’s diff. That allowance comes from a line of the generated file:
fs; a license comment above it is fine. A workflow.ts without it, such as one you write yourself, refuses fs. Moving the transforms to codemod/files is optional; once they no longer import fs, you can delete the line.
What upgrade can’t convert for you
upgrade lists anything it can’t translate exactly, and leaves a // codemod upgrade: comment where it was. The common ones:
- Transforms that use
codemod:metrics: return the counts instead. See Upgrade from 1.x. - Transforms that call
getStateorsetState: pass values between steps instead. runtime: dockerorruntime: podman: 2.0 refuses the workflow before running any steps. Keep running it with 1.x, or explicitly invoke the container from ashellstep when you port it.- Transforms that import
child_process: an upgraded workflow’s transforms can’t start processes.upgraderefuses the package (see below); move the commands to ashellstep first.
upgrade also refuses, and writes nothing, when:
- A workflow file is a symbolic link. Upgrade the file it points to, and point
codemod.yamlat that file. A transform that is a symbolic link is refused too: put the file itself in its place. - A transform, or a file of the package it imports, imports
child_process. Its calls would fail only when they run, afterworkflow.yamlis gone, so the package stays onworkflow.yaml. - A file it would change is one its steps don’t select, such as a transform a
.gitignoreignores. - Two workflows would become the same
.tsfile, or names that differ only in letter case (Build.yamlandbuild.yaml), which would overwrite each other on macOS and Windows. - A support file it would add, such as
__codemod_v1/metrics.ts, already exists with other contents. - A transform would not load in 2.0. Before writing,
upgradeloads every transform the newworkflow.tsimports, as the workflow’s steps will. When one fails, it names the transform and the import that stopped it, for examplescripts/codemod.ts does not load in 2.0: it imports 'node:net', which 2.0 workflows don't provide, and the package stays onworkflow.yaml. A transform that imports a package that isn’t installed can’t be checked:upgradesays so and converts the package anyway. Install the package’s dependencies first to have it checked.
2.
See Migrate from workflow.yaml for how every YAML feature maps to TypeScript.