Skip to main content

Authoring

There are currently three approaches to authoring and publishing a codeshift package. Which one to use depends on your particular use case.

  1. Contribute to the public registry
  2. Add codeshift to an existing package
  3. Create a stand-alone codeshift package

1. Contribute to the public registry

The public registry is the public directory of codemods hosted and published directly from this repository, visible here. This directory can be compared to and treated the same as the Typescript type definition registry: DefinitelyTyped.

Please see the Contribution guide for more information.

Use this method if you want:

  • Your codemods to be open source
  • Build tooling, dependency management and project setup to be handled for you
  • The community to help maintain and contribute to your codemods
  • Documentation to be automatically generated and available on the Registry page

Do not use this method if:

  • Your codemods target a closed source package/repository
  • Your codemods are generic in that they do not target any particular package
  • Your codemods should be close sourced or contain sensitive data

2. Add codeshift to an existing package

For existing npm packages (like react), you have the option to expose codemods directly from the package by simply creating a codeshift.config.js at either the root, /src or /codemods directory. Given that the config and codemod files are then published and available on NPM, codeshift will be able to find and run codemods using the --package flag.

Use this method if you want:

  • Open or closed sourced packages
  • To get up and running with an existing package with very little overhead
  • Control over where and how your codeshift package is hosted
  • Control over tooling, dependencies and techstack
  • To remove a previously created jscodeshift cli wrapper and instead use the generic codeshift cli

Do not use this method if:

  • You want docs to be automatically generated and available on the Registry page

3. Create a stand-alone codeshift package

Codeshift packages can be created as a stand-alone package.

Please see the External Packages guide for more information.

Use this method if you want:

  • Open or closed sourced packages
  • Control over where and how your codeshift package is hosted
  • Control over tooling, dependencies and techstack
  • The option to create completely generic codemods that don't target specific packages

Do not use this method if:

  • Your codemods target a closed source package/repository