question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Request: Support codemods published to npm

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:6
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
danieldelcorecommented, Jun 1, 2021

Hey folks, I’m working on a project based on jscodeshift that acts as a community registry for codemods.

The way it works in a nutshell is:

  1. Create a codemod and push it to the repo
  2. We’ll bundle and publish it to npm
  3. You can then run the codemod via our custom CLI npx @codeshift/cli --packages mypackage@14 path/to/src

If you want to publish your codemods you can get started by reading the Authoring and the Contribution guides.

The project is called CodeshiftCommunity, if you’re interested 😄 It’s early days, but would be keen to see what you all think about it/ if you find it useful 😄

1reaction
nickmccurdycommented, Dec 8, 2016

I’m in favor of changing jscodeshift’s CLI to look for npm packages of transforms automatically, especially since it could theoretically be done without any changes to the existing transforms. As long as they’re published on npm, jscodeshift could locate them locally or in the package repository and just provide abstractions for running specific transforms. I think it would also be useful to have an option for running all of a package’s transforms together, since many pck have related transforms that are meant to be run together. Perhaps something like jscodeshift --package NAME could run all transforms, with the -t flag modified to support locating the file by its name only (file instead of .../transforms/file.js).

That being said, I do think that the custom CLi feature could be very useful, though for what I would want I would find the package-based approach more convenient since I wouldn’t have to modify as much existing code or publish new packages.

I would be interested in working on this, I just wanted to post my ideas first and see if anyone else has progress or similar ideas.

Read more comments on GitHub >

github_iconTop Results From Across the Web

jscodeshift - npm
A toolkit for JavaScript codemods. Latest version: 0.14.0, last published: 3 months ago. Start using jscodeshift in your project by running ...
Read more >
@backstage/codemods - npm
A collection of codemods for use with Backstage projects. They are intended to improve and simplify large scale refactoring, upgrades of code to ......
Read more >
gatsby-codemods - npm
A collection of codemod scripts for use with JSCodeshift that help migrate to newer versions of Gatsby.. Latest version: 4.3.0, ...
Read more >
refactoring-codemods - npm
Quest for IDE refactoring support within JavaScript via js-codemods. Latest version: 0.3.4, last published: 4 years ago.
Read more >
react-codemod - npm
Latest version: 5.4.3, last published: 2 years ago. Start using react-codemod in your project ... npx react-codemod error-boundaries <path> ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found