Skip to content

Releases: facebook/jscodeshift

v0.3.26

18 Jul 10:21

Choose a tag to compare

New

  • Return value of Runner.run includes elapsed time and stats collected via stats method ( #128, @iamdustan).
  • jscodeshift --version also prints the used recast version ( #131, @keyanzhang)

Fixes

  • renameTo ignores Identifiers that are not variable references ( #125, Robby Nevels)
  • Transformers / codemods can use experimental features ( >= stage 1) and flow type annotations again (28eb515). This was a regressions.

v0.3.25

23 Jun 00:57

Choose a tag to compare

Fixed

  • testUtils supports custom parsers (e5fb37d)
  • testUtils also passes a stub for the stats method to the transformer (e5fb37d)

v0.3.24

22 Jun 20:27

Choose a tag to compare

Fixed

  • Fixed stats output in dry run. Thanks @gaearon for noticing.

v0.3.23

22 Jun 18:08

Choose a tag to compare

Fixed

  • Fixes an issue with using jscodeshift inside jest unit tests ( #122 )

v0.3.22

20 Jun 23:18

Choose a tag to compare

Fixed: jscodeshift installation

Seems like npm cannot handle local files (#120) :-/

v0.3.21

20 Jun 20:40

Choose a tag to compare

New: Choose your parser

Problem: jscodeshift uses Babel v5 to parse source files. Since Babel v5 doesn't get updated anymore, jscodeshift is unable to parse files that contain more modern flow type annotation.

To solve this, jscodeshift now supports three parsers, babel v5, babylon and flow, and even allows you to pass your own. Babel v5 still stays the default parser, but we will likely use another parser (babylon or flow) as default in the future. Having the option to pass a custom parser allows us to experiment which works best with jscodeshift/recast.

How to choose a parser

CLI

--parser allows you specify one of the built-in parsers from the command line: --parser=babelv5, --parser=babylon, --parser=flow.

API

jscodeshift now accepts a second argument that is directly passed to recast's parse method. This allows you to load your own parser, as long as it is compatible with recast:

jscodeshift(source, {parser: require('myParser')})

Transformer

The value of the parser export of the transformer is used as parser. The value can either be the name of one of the built-in parsers (babel, babylon, flow) or an object that can be directly passed to recast.parse.

Examples:

export const parser = 'flow';
// or
export {default as parser} from 'myParser';

This allows transformers to specify their own parser (as long as it is compatible with ESTree / recast), making them a bit more independent from jscodeshift's internals.


jscodeshift --version now also lists the versions of the built-in parsers

$ jscodeshift --version
jscodeshift: 0.3.21
 - babel: 5.8.38
 - babylon: 6.8.1
 - flow: 0.26.0

Reinstalling jscodeshift is probably the simplest way for now to update the built-in parsers.

v0.3.20

24 Apr 05:56

Choose a tag to compare

New

  • --ignore-pattern and --ignore-file command line arguments, which allow you to specify paths to ignore when using jscodeshift to traverse over a dictionary ( #107 , @chrisdarroch )

  • jscodeshift.use which you can pass a plugin too. A plugin would a function that accepts a jscodeshift instance and calls registerMethods on it. This allows plugins to be decoupled form jscodeshift. In addition, if .use is called with the same plugin multiple times, subsequent calls are ignored.

    Example:

    function myPlugin(jscodeshift) {
      jscodeshift.registerMethods({
        myExtension() { ... },
      }, jscodeshift.Identifier);
    }
    
    jscodeshift.use(myPlugin);

    ( #108 , @jamestalmage )

  • Better registerMethods method! Until now, it was impossible to register two methods with the same name, even if it was attached to different types (and therefore, conceptually, different collections). @jamestalmage changed this in #110 and and now it's possible to register such methods if the types are not super- or sub-types.

    Example:

    jscodeshift.registerMethods({
      rename() { ... },
    }, j.Identifier);
    
    jscodeshift.registerMethods({
      rename() { ... },
    }, j.VariableDeclarator);
  • Unit tests for transforms: @Daniel15 added helper methods to make writing unit tests easier ( #104 ) . See the readme and the example for more information.

    This results in a directory structure like this:

      /MyTransform.js
      /__tests__/MyTransform-test.js
      /__testfixtures__/MyTransform.input.js
      /__testfixtures__/MyTransform.output.js
    

    To define a test, use defineTest from the testUtils module:

      jest.autoMockOff();
      const defineTest = require('jscodeshift/dist/testUtils').defineTest;
      defineTest(__dirname, 'MyTransform');
    

v0.3.19

27 Mar 07:00

Choose a tag to compare

Fixes

  • Fixed hanging worker processes under certain conditions (we weren't able to find out the exact reasons but it looks like it involves processing at least 75 files) ( #102 ).
  • Added missing line breaks to CLI output.

Internals

  • Switched to jest 0.9.2.

v0.3.18

18 Mar 22:45

Choose a tag to compare

Fixes

Fixed log output ( #101 )

v0.3.17

17 Mar 23:19

Choose a tag to compare

Fixes

Both jscodeshift -t ... foo and jscodeshift -t ... foo/ work now ( #100 )