You can build a codemod package using three different ways:

  • Build with Codemod Studio
  • Scaffold a package with Codemod CLI

By building a codemod with Codemod Studio, your codemod package will automatically have the required package structure.

If you build a codemod from scratch or a previously built codemod, you will have to scaffold a valid codemod package using Codemod CLI.

Building with Codemod Studio

To learn how to build codemods with Codemod Studio, please refer to the detailed Codemod Studio usage guide.

Scaffolding a codemod package

Scaffolding a codemod package allows you to either:

  1. manually write your own codemod
  2. turn an existing codemod into a Codemod-compatible package.

To scaffold a new codemod package, you should:

1

Verify codemod engine compatibility

Verify that the existing codemod is built by one of the supported codemod engines.

2

Initialize codemod package

Initialize a Codemod-compatible package by running:

codemod init
3

Update transform file content

For jscodeshift/ts-morph/workflow codemods:

Update the content inside the src/index.ts file with the content of your codemod’s transform file.

For ast-grep codemods:

Update the content inside the src/rule.yaml file with the content of your ast-grep rule.

4

Update package configuration file

Add information about your codemod to the .codemodrc.json configuration file. Refer to .codemodrc.json reference here.

Next steps

Publishing your codemod ->

Get started with publishing your codemod to Codemod Registry.