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.23.7 | 180.62 kB | MIT | prod peer | 1 1 |
@babel/parser | 7.23.6 | 408.1 kB | MIT | prod | |
@babel/plugin-proposal-class-properties | 7.18.6 | 1.64 kB | MIT | prod | 1 1 |
@babel/plugin-proposal-object-rest-spread | 7.20.7 | 16.49 kB | MIT | prod | 1 1 |
@babel/preset-env | 7.23.8 | 32.96 kB | MIT | prod | 1 1 |
@babel/preset-flow | 7.23.3 | 3.02 kB | MIT | prod | 1 1 |
@babel/preset-typescript | 7.23.3 | 5.88 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 |
colors | 1.4.0 | 11 kB | MIT | prod | |
flow-parser | 0.226.0 | 169.33 kB | MIT | prod | |
graceful-fs | 4.2.11 | 9.57 kB | ISC | prod | |
micromatch | 3.1.10 | 18.81 kB | MIT | prod | 4 |
neo-async | 2.6.2 | 37.74 kB | MIT | prod | |
node-dir | 0.1.17 | 6.29 kB | MIT | prod | |
recast | 0.18.10 | 50.32 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
.