jscodeshift
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
@babel/core | 7.24.4 | 763.3 kB | MIT | prod peer | 1 1 |
@babel/parser | 7.24.4 | 1.8 MB | MIT | prod | |
@babel/plugin-proposal-class-properties | 7.18.6 | 1.64 kB | MIT | prod | 1 1 |
@babel/plugin-proposal-nullish-coalescing-operator | 7.18.6 | 1.96 kB | MIT | prod | 1 1 |
@babel/plugin-proposal-optional-chaining | 7.21.0 | 8.85 kB | MIT | prod | 1 1 |
@babel/plugin-transform-modules-commonjs | 7.24.1 | 41.43 kB | MIT | prod | 1 1 |
@babel/preset-flow | 7.24.1 | 8.86 kB | MIT | prod | 1 1 |
@babel/preset-typescript | 7.24.1 | 20.98 kB | MIT | prod | 1 1 |
@babel/register | 7.23.7 | 17.36 kB | MIT | prod | 1 1 |
babel-core | 7.0.0-bridge.0 | 864 B | MIT | prod | 1 1 1 |
chalk | 4.1.2 | 11.31 kB | MIT | prod | |
flow-parser | 0.233.0 | 708.72 kB | MIT | prod | |
graceful-fs | 4.2.11 | 9.57 kB | ISC | prod | |
micromatch | 4.0.5 | 14.09 kB | MIT | prod | |
neo-async | 2.6.2 | 37.74 kB | MIT | prod | |
node-dir | 0.1.17 | 6.29 kB | MIT | prod | |
recast | 0.23.6 | 239.37 kB | MIT | prod | |
temp | 0.8.4 | 5.74 kB | MIT | prod | |
write-file-atomic | 2.4.3 | 4.39 kB | ISC | prod |
jscodeshift is a toolkit designed specifically for running codemods across multiple JavaScript or TypeScript files. Essentially, it aids in bulk modification of JavaScript code. Two key features that jscodeshift delivers include a runner, which executes the provided transformation for each file passed to it and a wrapper around Recast, thereby facilitating AST-to-AST code transformation.
Using jscodeshift is simple. A global installation through npm is required first:
$ npm install -g jscodeshift
Once installed, you can run the jscodeshift runner via the CLI with multiple options for customization. For instance, to run a transform, you use the -t
or --transform
option followed by the path to the transform file:
$ jscodeshift -t myTransform.js path-to-your-source-files
If you want to run jscodeshift programmatically in a JS file, the following code can be used as an example:
const {run: jscodeshift} = require('jscodeshift/src/Runner');
const path = require('node:path');
const transformPath = path.resolve('transform.js')
const paths = ['foo.js', 'bar.js'];
const options = {
dry: true,
print: true,
verbose: 1,
// other options...
};
const response = await jscodeshift(transformPath, paths, options);
console.log(response);
In this code example, transformPath
is the path to your JavaScript code transformation script, paths
is an array of file paths you want to transform, and options
is a object for optional parameters.
The documentation for jscodeshift can be found on the project's GitHub page here. The README in the repository provides a comprehensive guide to using jscodeshift, including installation, CLI usage, JS usage, and the jscodeshift API. Users can also find a guide on extending jscodeshift with their own functionalities. Local documentation server can be run using npm run docs
and viewed using npx http-server ./docs
.