babel-codemod version 2.1.2 (up to 2.1.5) rewrites JavaScript and TypeScript files using Babel plugins, leveraging recast to preserve original formatting with minimal changes. It supports local and remote plugins (e.g., AST Explorer URLs), with optional Prettier output. It includes built-in transpilation via @babel/preset-env and experimental TypeScript support via @babel/preset-typescript. Compared to alternatives like jscodeshift, it uses standard Babel plugins and APIs, reducing the learning curve for Babel users. Active until 2019, now in maintenance mode; requires Node >=6.
npm install babel-codemodVerified import paths — ran on the pinned version, not inferred.
Demonstrates installing babel-codemod and running a Babel plugin on files, including local and remote plugin usage.
Avoid using --remote-plugin with untrusted URLs.
Ensure all plugins are written for Babel 7. Use @babel/plugin-* packages.
Check babel issues for TypeScript support gaps.
Prepare to migrate to official TypeScript compiler if needed.
Ensure .babelrc is present and all referenced presets/plugins are installed locally.
npm install @babel/parser or upgrade to v2.1.2+ that explicitly depends on it.
Use @babel/plugin-* packages for Babel 7, or downgrade to babel-codemod v1.x.
Ensure the plugin exports a function that returns a visitor object.
Create a .babelrc file with the desired plugins/presets, or remove --find-babel-config.