v0.3.20
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 callsregisterMethods
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');