npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

create-codemod-app

v0.0.5

Published

Create Codemod

Downloads

8

Readme

Create Codemod App

This is a CRA (Create React App) style app for creating codemod libraries that function in a similar way to the react-codemod project. In fact, we use a slightly modified version of their codemod runner. As such, this project is licensed under 2 licenses. Everything not in the src/facebook-codemod-runner is under the MIT license, whereas everything in that folder is under the facebook 'BSD+patents' license.

This is a fancy wrapper for jscodeshift which is itself a fancy wrapper for recast.

If you are just getting into codemods, I would highly recommend starting with the AST Explorer sandbox

How to use it.

Much like CRA, you go to the directory you want to create your codemod app in and run

npx create-codemod-app;

You will be prompted to answer some questions about your app, and we will generate everything for you in a directory with the name you chose for the app.

Assuming you called it my-codemod-app, and you chose to generate a codemode called reverse-identifiers, you will now have a directory structure that looks like this:

.
├── bin
│   └── run-codemod.js
├── config
│   └── codemod-config.js
├── package-lock.json
├── package.json
└── transforms
    ├── __testfixtures__
    │   └── reverse-identifiers
    │       ├── case-1.input.js
    │       ├── case-1.output.js
    │       ├── case-2.input.js
    │       └── case-2.output.js
    ├── __tests__
    │   └── reverse-identifiers.js
    └── reverse-identifiers.js

The transforms directory is where all of your codemod transforms will live asjscodeshift relies on it, config/codemod-config.js is where the codemod runner will look for codemods, and the bin/run-codemod.js file is what is run when you call my-codemod-app from anywhere on your machine. All of this is setup for you during the install process (unless you opt out in the prompts).

Unless you are an advanced user, it is recommended only to edit the files in transforms/* and transforms/__test_fixtures/*/* directory.

To add another codemod, simply run npm run generate-codemod

Customizing your codemods

Every time you run npm run generate-codemod you will get new, noop codemod like this:

module.exports = function transformer(file, api) {
  const j = api.jscodeshift;

  return j(file.source)
    .find(j.Identifier)
    .forEach(node => {
      node = node;
    })
    .toSource();
};

Out of the box, you can run my-codemod from any directory and you get facebook's react-codemod cli. This will let you choose which codemods to run.

In the example-codemod-app directory of this repo, you will find a working example that actually reverses all identifiers. This is the 'hello world' example from AST Explorer

Issues and Pull requests

This is a new project and all contributions are welcome.

If you have a bug to report or something is unclear, please feel free to open an issue.

If you would like to add a feature, please open up an issue first to discuss it.

Thanks and happy coding 😊