facebook / facebook/jscodeshift
Request: Support codemods published to npm
- Dominant language
- JavaScript
- Stars
- 10k
- Forks
- 498
- PR merge metrics
- No merged PRs in 30d
Description
Right now, there are 2 ways that a developer can run a codemod:
1. Copy the codemod to their local machine, and pass the file path in with `-t`
2. Provide a URI to a remote `.js` file (with the caveat that the script must be entirely self contained).
I'd like to propose a 3rd option: being able to `npm install -g` a codemod.
I can think of 2 different options for how this would work.
1. A developer passes in the name of the globally-installed transform (either with `-t` or a new flag)
2. `jscodeshift` can look for all globally-installed modules matching a specific prefix, and present the developer with a list of available transforms when one is not explicitly provided on the command line (this is how the `yo` CLI works for `yeoman`).
I think the major benefit here would be that it then becomes easier to author + distribute a codemod that is not entirely self-contained. Right now, if I wanted to publish a codemod that uses `require` for modules other than node built-ins, a consumer of my codemod needs to:
1. Clone the repository
2. Run `npm install`
3. Navigate to their project
4. Specify the exact path to my codemod's entry point with the cloned repository
Another benefit is discoverability: If the docs encourage users to publish to `npm` with specific tags, it will make searching for available transforms much less of a struggle.
This is work I'd definitely be willing to contribute, but wanted to elicit feedback before taking that work on.
Contributor guide
Assessment
This issue has not been assessed yet.