Skip to content

Instantly share code, notes, and snippets.

@b2l
b2l / absolute-to-relative.js
Created April 3, 2019 14:16 — forked from tibdex/absolute-to-relative.js
jscodeshift codemod to change imports of internal modules using absolute path to relative path
/**
* This codemod expects 2 CLI arguments:
* - packageDir: the path of the directory containing the package.json. It's used to detect whether a path points
* to a dependency or an internal module.
* - rootDirs: root directory paths separated by a comma if you have more than one root.
* Let's say that you have two files:
* - src/component.js
* - src/index.js containing the import "import Component from 'component.js';"
* To have the transformation successfully working you need to call jscodeshift with the "--rootDirs ./src" argument.
*/