Codemod CLI
Node.js Userland Migrations uses the Codemod CLI to run migration recipes. You don’t need to install anything globally - the CLI can be run directly withnpx.
Running with npx (recommended)
The simplest way to run codemods is usingnpx, which downloads and executes the CLI automatically:
- Requires no installation
- Always uses the latest version of the CLI
- Works in CI/CD environments
- Doesn’t pollute your global npm packages
The first run may take a few seconds while
npx downloads the Codemod CLI. Subsequent runs are faster.Global installation (optional)
If you run codemods frequently, you can install the CLI globally:npx:
Verifying installation
Check that the Codemod CLI is available:Prerequisites
Node.js version
Node.js Userland Migrations requires:- Node.js 18.0.0 or higher (recommended: latest LTS version)
- npm 8.0.0 or higher
Git
While not strictly required, git is strongly recommended:- Review changes with
git diff - Revert migrations with
git reset - Track migration history in your repository
Project setup
Running in an existing project
To run codemods in your project:File types supported
Codemods automatically process these file types:**/*.js- JavaScript files**/*.jsx- React JSX files**/*.ts- TypeScript files**/*.tsx- TypeScript React files**/*.mjs- ES module files**/*.cjs- CommonJS module files**/*.mts- TypeScript ES module files**/*.cts- TypeScript CommonJS files
Files excluded by default
The following directories are automatically excluded:**/node_modules/**- Dependencies**/dist/**- Build output**/build/**- Build output**/.git/**- Git repository data**/coverage/**- Test coverage reports
Configuration
Codemod CLI configuration
You can configure the Codemod CLI behavior with a.codemodrc.json file in your project root:
Configuration options
Configuration options
| Option | Description | Default |
|---|---|---|
include | Glob patterns for files to process | **/*.{js,jsx,ts,tsx,mjs,cjs,mts,cts} |
exclude | Glob patterns for files to skip | **/node_modules/** |
extensions | File extensions to process | [".js", ".jsx", ".ts", ".tsx", ".mjs", ".cjs", ".mts", ".cts"] |
interactive | Enable interactive mode | true |
Command-line options
Override configuration with command-line flags:Development setup
If you want to contribute to Node.js Userland Migrations or run codemods from source:Project structure
The repository is organized as follows:Running recipe tests
Test a specific recipe:CI/CD integration
Running in GitHub Actions
You can run codemods in CI to validate migrations or apply them automatically:.github/workflows/migrate.yml
Running in other CI systems
The same approach works in any CI system that supports Node.js:Troubleshooting
Command not found: codemod
Command not found: codemod
If you get a “command not found” error:
- Ensure you’re using
npx codemodnot justcodemod - If using global installation, reinstall:
npm install -g codemod - Check your PATH includes npm global binaries:
npm config get prefix
Permission denied errors
Permission denied errors
On Unix systems, you may need to adjust permissions:
Out of memory errors
Out of memory errors
For large codebases, you may need to increase Node.js memory:
npx is slow
npx is slow
The first
npx run downloads the CLI. To speed up subsequent runs:- Install globally:
npm install -g codemod - Or use npm cache:
npxwill cache the package after first use
Useful resources
Codemod CLI Reference
Complete CLI documentation and command reference
Workflow Documentation
Learn about workflow files and multi-step migrations
Codemod Studio
Interactive environment for developing codemods
jssg API Reference
JavaScript AST manipulation API documentation
What’s next?
Quick Start
Run your first migration
Browse Recipes
Explore all available migration recipes
How Codemods Work
Understand the technical details
Contributing
Create your own migration recipes