Skip to content

CodeMod

Created: 2018-08-06 15:57:15 -0700 Modified: 2018-08-13 13:40:53 -0700

I had to use Yarn to install this, which meant I had to stop pointing at Sinopia and start pointing at the official NPM repository:

  1. npm config set registry https://registry.npmjs.org/
  2. yarn global add jscodeshift
  3. Make a directory where you want codemod to reside (e.g. C:tools )
  4. Run their other setup steps like “git clone”
  5. Set the registry back to normal: npm config set registry http://104.42.195.223:4873/

I wanted to convert “.bind” to arrow functions in React, so I used this CodeMod.

  1. First, navigate to a directory that has a package.json containing React (or maybe a subfolder of this would work too).
  2. Despite installing jscodeshift globally, Windows doesn’t let me just use “jscodeshift” because Yarn’s global bin folder isn’t automatically in my PATH. I found the folder by doing “yarn global bin”: C:Usersagd13 _000scooppersistyarnbinbin
  3. C:/Users/agd13_000/scoop/persist/yarn/bin/bin/jscodeshift -t C:/tools/react-codemod/transforms/manual-bind-to-arrow.js D:/Code/BotLand/botland/packages/client/public/javascripts/react_and_redux/containers/blueprintandscripteditor.js