styled-components / styled-components-codemods

Automatic codemods to upgrade your styled-components code to newer versions.
MIT License
52 stars 5 forks source link

No changes to files after running against files containing `.extend` #11

Open patreeceeo opened 5 years ago

patreeceeo commented 5 years ago

Maybe I'm missing something very obvious, but when I use this codemod as described in the README against files using the .extend API, those files remain unchanged.

image

NPM version: 6.10.2 Node version: v8.12.0 OS: macOS 10.13.6

Would you need any other information?

Thanks for making this!

patreeceeo commented 5 years ago

Seems that the root cause is that I'm using Typescript:

Encountered an error while processing ../resources-ui/src/app/components/Buttons/Button/index.tsx:
Error: Cannot combine flow and typescript plugins.
    at validatePlugins (/Users/patrick.canfield/Code/styled-components-codemods/node_modules/@babel/parser/lib/index.js:6080:11)
    at getParser (/Users/patrick.canfield/Code/styled-components-codemods/node_modules/@babel/parser/lib/index.js:11323:5)
    at parse (/Users/patrick.canfield/Code/styled-components-codemods/node_modules/@babel/parser/lib/index.js:11306:12)
    at Object.parse (/Users/patrick.canfield/Code/styled-components-codemods/node_modules/babel-codemod/src/RecastPlugin.ts:14:16)
    at Object.parse (/Users/patrick.canfield/Code/styled-components-codemods/node_modules/recast/lib/parser.js:28:30)
    at parse (/Users/patrick.canfield/Code/styled-components-codemods/node_modules/babel-codemod/src/RecastPlugin.ts:11:17)
    at parser (/Users/patrick.canfield/Code/styled-components-codemods/node_modules/@babel/core/lib/transformation/normalize-file.js:163:23)
    at normalizeFile (/Users/patrick.canfield/Code/styled-components-codemods/node_modules/@babel/core/lib/transformation/normalize-file.js:138:11)
    at runSync (/Users/patrick.canfield/Code/styled-components-codemods/node_modules/@babel/core/lib/transformation/index.js:44:43)
    at runAsync (/Users/patrick.canfield/Code/styled-components-codemods/node_modules/@babel/core/lib/transformation/index.js:35:14)
1 file(s), 0 modified, 1 errors

If I just remove L9 from src/v4/common.js, which adds the flow plugin, it works as expected.

patreeceeo commented 5 years ago

Why is the flow plugin included? Can it be not included by default unless, say, the user passes a --with-flow flag or something?

BretCameron commented 4 years ago

I can second that the codemod doesn't work with TypeScript, but removing flow fixes this. It would be good to make this plugin optional.

danieldunderfelt commented 2 years ago

I'm trying to run this against a plain JS codebase with npx, no changes for .extend. If I install the codemods in the project and run with yarn, it works!