jscodeshift
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
async | 1.5.2 | 38.01 kB | MIT | prod | |
babel-core | 5.8.38 | 897.36 kB | MIT | prod | 1 14 3 5 |
babel-preset-es2015 | 6.24.1 | 2.25 kB | MIT | prod | 1 5 2 |
babel-register | 6.26.0 | 4.24 kB | MIT | prod | 1 3 |
babylon | 6.18.0 | 67.62 kB | MIT | prod | |
colors | 1.4.0 | 11 kB | MIT | prod | |
es6-promise | 3.3.1 | 42.52 kB | MIT | prod | |
flow-parser | 0.235.1 | 709.37 kB | MIT | prod | |
lodash | 4.17.21 | 311.49 kB | MIT | prod | |
micromatch | 2.3.11 | 14.28 kB | MIT | prod | 1 2 |
node-dir | 0.1.8 | 4.78 kB | MIT | prod | |
nomnom | 1.8.1 | 10.17 kB | UNKNOWN | prod | 2 1 |
recast | 0.11.23 | 39.17 kB | MIT | prod | |
temp | 0.8.4 | 5.74 kB | MIT | 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
.