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

calypso-codemods

v0.1.5

Published

jscodeshift transforms used to upgrade calypso code

Downloads

4

Readme

Calypso Codemods

Build Status

What are codemods?

Code modification scripts, also known as codemods, are transformation scripts that can simultaneously modify multiple files with precision and reliability. Codemods were popularized by Facebook's engineering team and depends greatly on Facebook's jscodeshift library, which wraps over a library named recast (author of which is associated with the Meteor project).

Getting started

Install calypso-codemods using npm or yarn:

npm install -g calypso-codemods
yarn add global calypso-codemods

Now you can run codemods using the following cli:

calypso-codemods transformation-name[,second-name,third-name] target [additional targets]

For example, if I wanted to run the commonjs-exports transformation on client/devdocs/, I can do the following:

calypso-codemods commonjs-exports client/devdocs/

Do you want to target files individually? We can do that, too!

calypso-codemods commonjs-exports client/devdocs/a.js client/devdocs/b.js client/devdocs/c.js

How about chaining codemods on multiple directories?

calypso-codemods commonjs-imports,commonjs-exports,named-export-from-default client/blocks/ client/components/

List of available transformations

5to6-codemod scripts (docs)

  • commonjs-exports

    • This codemod converts module.exports to export and export default.
  • commonjs-imports

    • This transformation converts occurrences of require( '...' ) to import ... from '...' occurring at the top level scope. It will ignore CommonJS imports inside block statements, like conditionals or function definitions.
  • commonjs-imports-hoist

    • This transformation hoists all occurrences of require( '...' ) inside if, loop, and function blocks. This can cause breakage! Use with caution.
  • named-exports-from-default

    • This transformation generates named exports given a default export { ... }. This can be useful in transitioning away from namespace imports (import * as blah from 'blah') to named imports (import named from 'blah').

React scripts (docs)

  • react-create-class

    • This transformation converts instances of React.createClass to use React.Component instead.
  • react-proptypes

    • This transformation converts instances of React.PropTypes to use prop-types instead.

Local scripts

  • combine-reducer-with-persistence

    • This transformation converts combineReducers imports to use combineReducersWithPersistence.
  • combine-state-utils-imports

    • This transformation combines state/utils imports.
  • i18n-mixin-to-localize

    • This transformation converts the following: - this.translate to this.props.translate - this.moment to this.props.moment - this.numberFormat to this.props.numberFormat
      • If any of the above conversions is performed, this transformation will wrap the React.createClass instance with a localize() higher-order component.
  • merge-lodash-imports

    • This transformation merges multiple named lodash imports into one
  • modular-lodash-no-more

    • This transformation converts modular lodash imports to ES2015-style imports
  • modular-lodash-requires-no-more

    • This transformation converts modular lodash requires to ES2015-style imports
  • rename-combine-reducers

    • This transformation converts combineReducersWithPersistence imports to use combineReducers from 'state/utils'
  • sort-imports

    • This transformation adds import comment blocks and sorts them as necessary.
    • Note: It only needs to be run twice because of a bug where in certain cases an extra newline is added on the first run. The second run removes the extra newline.

Contributing codemods

Write the transform

Write your transform using the standard jscodeshift api and place it in the transforms directory. You can look at the current directory for inspiration.

Add some tests!

calypso-codemods uses jest snapshots to maintain its tests. in order to easily add tests for a new transform, follow these steps:

  1. add a directory to tests with the exact same name as the added transform.
  2. add a file named codemod.spec.js with this as its contents contents:
test_folder(__dirname);
  1. add any input files to the folder that you wish to be tested

  2. run npm test or yarn test. if the tests fail, its usually because a snapshot would be modified and behavior has changed. If you've verified that the updated snapshots look correct, then you can update the snapshots with: yarn test -- -u.

  3. make sure to commit any modified snapshots and include it in your pull request