Skip to content

jscodeshift

A toolkit for running automated code-rewriting scripts (codemods) across many JavaScript or TypeScript files.

Stars
10k
Forks
503
Licence
MIT
Language
JavaScript
Last update
9 days ago
Type
Dev tool

What it is

jscodeshift lets you write a small transform script that automatically changes source code, then runs that script across many files at once. It includes a runner that applies the transform to each file and reports how many were changed, plus a wrapper around the recast library that offers a jQuery-like way to search and edit the code's syntax tree. It is aimed at large codebases where the same change needs to be made in many places.

  • Renaming a variable or function across every file in a project
  • Running a transform in dry-run mode to count how often a construct appears
  • Applying a custom transform to a set of files with the jscodeshift CLI
  • Debugging a codemod in VSCode using the documented debugger setup

Great for

  • Engineers migrating a large JavaScript or TypeScript codebase to a new API or syntax
  • Teams that need the same mechanical refactor applied consistently across many files
  • Developers who want a dry run to see how many files a change would affect before committing to it
  • Maintainers writing reusable codemods to share with other projects

Not ideal for

  • People who only need to edit a handful of files by hand, since writing a transform is more work than the edit itself
  • Users who want a ready-made app with a graphical interface; the README describes a command-line toolkit
  • Those unfamiliar with abstract syntax trees, since the README says understanding recast and ASTs is needed to use the API well
Step-by-step guide: how to use jscodeshiftInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    Install with a package manager

    You'll need: Node.js and npm

    Install globally from npm

    $ npm install -g jscodeshift
  2. 2

    Run it

    • Install the jscodeshift package globally with npm.
    • Write a transform.js file that exports a function taking fileInfo, api, and options.
    • Run jscodeshift -t transform.js path/to/files, optionally with --dry and --print to preview changes.
    • Read the summary at the end to see how many files were changed, unmodified, or skipped.
  3. 3

    Get the most out of it

    • Use --dry and --print to preview changes before writing files to disk
    • Use -v 1 or -v 2 for more detail on the transformation process
    • Use the stats function in dry runs to count how often a construct appears
    • Export a parser setting from your transform to choose babel, flow, ts, tsx, or a custom parser

Downloads

Strengths

  • Runs one transform over many files and summarizes the results (ok, unmodified, skipped, errors)
  • Built on recast, which tries to preserve the original code style as much as possible
  • Supports multiple parsers, including babel, flow, ts, and tsx

Trade-offs

  • Writing a transform requires understanding ASTs and the jscodeshift/recast API, which has a learning curve
  • The README is truncated here, so detailed API documentation is only referenced via the external website

Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.