react-codemod icon indicating copy to clipboard operation
react-codemod copied to clipboard

package react-codemod with ncc

Open threepointone opened this issue 5 years ago • 1 comments

This would avoid issues like https://github.com/reactjs/react-codemod/issues/249

threepointone avatar Jun 28 '20 07:06 threepointone

Hey @threepointone, I wanted to share CodeshiftCommunity, which could help side-step some of these issues.

It allows you to publish codemods as packages to NPM, the CLI will pull it down and run it in an isolated context.

$ npx @codeshift/cli -p react#error-boundaries path/to/src

Meaning:

  • You always run the latest codemods
  • You don't have to maintain your own CLI implementation
  • You can bundle your own dependencies with the mods

Codeshift allows developers to publish codemods as their own NPM packages or as part of an existing NPM package. We provide a standardized CLI tool that can download and run the latest codemods from any location. This approach has the added benefit of allowing codemods to be published with dependencies, which is not currently possible with most JSCodeshift CLI implementations.

To integrate with this repo, you just need to add a codeshift.config.js.

module.exports = {
  maintainers: ['threepointone'],
  targets: ['react'],
  presets: {
    'React-DOM-to-react-dom-factories': require.resolve('./transforms/React-DOM-to-react-dom-factories.js'),
    'React-PropTypes-to-prop-types': require.resolve('./transforms/React-PropTypes-to-prop-types.js'),
    'ReactNative-View-propTypes': require.resolve('./transforms/ReactNative-View-propTypes.js'),
    'create-element-to-jsx': require.resolve('./transforms/create-element-to-jsx.js'),
    'error-boundaries': require.resolve('./transforms/error-boundaries.js'),
    ...
  },
};

Obviously, no pressure here, thought it might help in the future 👍

danieldelcore avatar Feb 02 '23 00:02 danieldelcore