@compiled/codemods
TypeScript icon, indicating that this package has built-in type declarations

0.9.4 • Public • Published

codemods

Codemods for easy migration from styled components and emotion.

Usage

Codemods in this repository can be run with the CodeshiftCommunity tooling.

# Transform single file
npx @codeshift/cli --packages @compiled/codemods /Project/path/to/file

# Transform multiple files
npx @codeshift/cli --packages @compiled/codemods /Project/**/*.tsx

Available codemods

  1. styled-components-to-compiled
  2. emotion-to-compiled
  3. styled-components-inner-ref-to-ref

Plugins

Codemods support a simple plugin system where supported implementations can be overridden. The CodemodPlugin interface lists all the supported methods to be re-implemented. See the following example:

import type { API, FileInfo, Options } from 'jscodeshift';
import type { CodemodPlugin } from '@compiled/codemods';

const ExampleCodemodPlugin: CodemodPlugin = {
  name: 'example-codemod-plugin',
  create: (fileInfo: FileInfo, { jscodeshift: j }: API, options: Options) => ({
    visitor: {
      program({ program }) {
        j(program)
          .find(j.ImportDeclaration)
          .at(-1)
          .get()
          .insertAfter(
            j.importDeclaration(
              [j.importSpecifier(j.identifier('getFeatureFlag'))],
              j.literal('./feature-flags')
            )
          );
      },
    },
  }),
};

export default ExampleCodemodPlugin;

Package Sidebar

Install

npm i @compiled/codemods

Weekly Downloads

85

Version

0.9.4

License

Apache-2.0

Unpacked Size

192 kB

Total Files

71

Last publish

Collaborators

  • jlane2
  • monica.olejniczak
  • jackbrown
  • madou