/codemods

Primary LanguageJavaScript

JS codemods

Preview code AST of the target code using AST explorer. To interactively test and update codemods might be helpful to use ndb.

ndb npx jscodeshift -t ./transforms/something.js --extensions=ts --parser=tsx ./src/**/*container.ts

Usage

  1. yarn
  2. npx jscodeshift -t ./transforms/[transform].js [files]
  3. Review changes via git diff. Keep what you want, throw it out if you don't. Magic!

Option flags

When executing codemods, you can configure options like so:

npx jscodeshift -t node_modules/5to6-codemod/transforms/[transform].js [files] --key=value

Recast options

Transforms will automatically distinguish and pass through Recast config keys via jscodeshift. Official documentation for Recast's configuration can be found here. The following Recast keys are supported:

  • esprima
  • inputSourceMap
  • lineTerminator
  • quote
  • range
  • reuseWhitespace
  • sourceFileName
  • sourceMapName
  • sourceRoot
  • tabWidth
  • tolerant
  • trailingComma
  • useTabs
  • wrapColumn

Known issues

Some TS features might not work because latest release of jscodeshift is not yet published to NPM. facebook/jscodeshift#330