A codemod package is compatible with Codemod platform when it:

  1. uses a supported codemod engine

  2. has a valid .codemodrc.json configuration file in its root directory

  3. has a valid codemod package structure.

The .codemodrc.json configuration file allows Codemod platform to better understand information about your codemod, as well as bring an enhanced running experience.

The structure of the codemod package can vary based on the codemod engine used. This document explains the requirements for a valid codemod package for each of the supported codemod engines.

Supported codemod engines

Codemod platform currently supports the following codemod engines: ast-grep, jscodeshift, ts-morph, and wokflow.

.codemodrc.json reference

The .codemodrc.json configuration file includes several metafields that can be used to help Codemod platform understand more information about your codemod package.

name
string
required

Specifies the slugified name of the codemod published to the codemod registry.

version
string
required

Specifies the current codemod version. Should follow the SemVer scheme.

The version field must be bumped every time the codemod is published.

private
boolean
default: "false"

Can be used to set the codemod visibility to private.

By default, when a codemod is published without a namespace, visibility will be set as public. If a codemod is published under a namespace, such as @codemod/my-codemod, visibility will be set as private.

engine
string
required

Specifies the engine used to run the codemod. Can be any of:

  • ast-grep

  • jscodeshift

  • ts-morph

  • workflow

  • recipe (requires additional names field, which is an ordered array of codemod names that will be executed)

include
glob pattern array

Can be used to override the default glob pattern for files that will be processed by the codemod.

applicability
object

The applicability field is an object with from and to keys that are both arrays of tuples. This field can be used to specify the dependencies and versions this codemod is made for.

Specifying the applicability criteria of your codemod helps:

  1. Reduce false positives

  2. Proactively recommend the codemod to users who might need it

  3. Improve codemod performance, as it will only process projects that make sense

  4. Allow daisy-chaining codemods (e.g., migrating from v1 to v3 by combining v1-to-v2 and v2-to-v3 codemods)

Each tuple consists of three elements:

  1. a library name

  2. a comparison operator (<, >, <=, >=, =)

  3. a version number (SemVer compatible)

deps
array of strings

Can be used to specify dependencies to be installed after successful a codemod run. You can also specify a package to be removed by prepending it with a - sign. Each dependency should be a string in one of the following formats:

  • package-name@version

  • -package-name

  • package-name

arguments
array of objects

If your codemod requires arguments, you can specify them in this field.

meta
object

Specifies additional information about your codemod for discoverability purposes.

entry
string

Can be used to specify custom entrypoint path of the codemod.

By default, the entrypoint path is determined by the engine. JavaScript engines use src/index.{js,ts} path and ast-grep uses **/rule.yaml patterns.

Codemod package structure

Below, you can find the required codemod package structure for each codemod engine supported by Codemod platform.

├── dist
│   ├── index.cjs # built codemod file. when someone runs your codemod, this file will be executed.
├── src
│   ├── index.ts # the default path for the codemod's entry point file.
│   ├── ...
│   package.json
├── .codemodrc.json # contains the codemod configuration
└── README.md # contains a short description and examples, such as in the example at the bottom of this page

Codemod package examples

Next steps

Building a codemod package ->

Get started with building a codemod package.