A codemod package is compatible with Codemod platform when it:
.codemodrc.json
configuration file in its root directoryThe .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.
Codemod platform currently supports the following codemod engines: jscodeshift, ts-morph, and ast-grep (recommended).
.codemodrc.json
referenceThe .codemodrc.json
configuration file includes several metafields that can be used to help Codemod platform understand more information about your codemod package.
Specifies the slugified name of the codemod published to the codemod registry.
We recommend using the following naming convention for better codemod discoverability:
Optionally, you can specify an organization’s namespace for your codemod:
To create an organization namespace, contact us message us on the Slack community.
Specifies the current codemod version. Should follow the SemVer scheme.
The version field must be bumped every time the codemod is published.
Can be used to set the codemod visibility to private
.
If a codemod is published under an organization’s namespace, such as @codemod/my-codemod
, visibility will default to private
unless explicitly specified.
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)Can be used to override the default glob pattern for files that will be processed by the codemod.
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:
Each tuple consists of three elements:
<
, >
, <=
, >=
, =
)Can be used to specify dependencies to be installed after a successful 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
If your codemod requires arguments, you can specify them in this field.
Specifies additional information about your codemod for discoverability purposes.
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.
Below, you can find the required codemod package structure for each codemod engine supported by Codemod platform.
Codemod recipes are a collection of codemods that are run in consecutive order. Codemod recipes allow you to daisy-chain a set of codemods that help with a large-scope migration.
Unlike JavaScript and ast-grep codemods, recipes do not inlcude input files in .codemodrc.json
. To specify codemods that should be run by the recipe, simply add the codemod names under the names
field.
An example of a valid jscodeshift React codemod package.
An example of a valid ast-grep Python codemod package.
An example of a valid React migration recipe package.
Get started with building a codemod package.