codemodsquad / astx

Super powerful structural search and replace for JavaScript and TypeScript to automate your refactoring
MIT License
92 stars 6 forks source link

is the CLI supposed to read ts-config.json and or babel configs? #11

Closed danielo515 closed 1 year ago

danielo515 commented 2 years ago

Hello Today I tried running the cli on a typescript project, and I'm getting type errors on some features that are not the standard. For example imports rather than requires, type imports, etc. Is the cli supposed to find the ts-config.json/babelrc ? If not, is it possible to provide it? I took a look at the code and doesn't seem to be an option for this.

Regards

jedwards1211 commented 2 years ago

It parses ts and js with babel so it finds the babel config and uses it (right now it doesn't look at ts config at all). Can you tell me what version of astx you're using and what the parse problem you have?

danielo515 commented 2 years ago

Version is 1.2.3 (wow, looks like a joke)

Most of my errors are this:

==========================================
src/spring/components/Separator/index.ts
==========================================
SyntaxError: Unexpected token (1:13)

where the line that fails looks like this:

export { default } from './Separator';

I'm runing it through npx, maybe that is the problem

jedwards1211 commented 2 years ago

would it be possible for you to try with ^2.0.0-beta.6? The breaking changes are here: https://github.com/codemodsquad/astx/releases/tag/v2.0.0-beta.1

danielo515 commented 2 years ago

Checking the mentioned version. This is the command I ran:

npx astx@2.0.0-beta.6 --parser typescript -f '{ keyPrefix: $a, $$b}' src

Here are some issues It raises:

==========================================
src/types/StrictOmit.ts
==========================================
SyntaxError: This experimental syntax requires enabling one of the following parser plugin(s): "flow", "typescript". (7:7)

Triggered by export type StrictOmit<T, K extends keyof T> = T extends any ? Pick<T, Exclude<keyof T, K>> : never;

==========================================
src/types/changelog.ts
==========================================
SyntaxError: Missing semicolon. (3:4)

Code that triggers this: type fieldName = Field;

Worth noting that all my files are correctly parsed by typescript, eslint, babel and other tools that read code, so I know my config is fine

jedwards1211 commented 2 years ago

okay can you share the file and your package.json deps related to typescript/babel with me?

danielo515 commented 2 years ago

I'll try to trim them down and then share

jedwards1211 commented 2 years ago

@danielo515 I just did a major important refactor, could you try with 2.0.0-beta.11 and let me know if you still have issues? (Note, --parser typescript wasn't a valid option anyway, and even jscodeshift actually parses TS with babel.) This refactor theoretically enables me to support TypeScript's own parser, though I don't know if I'll ever try to tackle that...

Now even if it fails to resolve local babel config, it should configure the parser for TS by default on .ts files. Which should have been happening anyway, but I think --parser typescript may have overridden my code to automatically configure a babel parser.

Also you should be able to pass --parser babel --parser-options '{"plugins": ["typescript"]}' etc now, though I haven't much tested doing that via the CLI. Eventually I want to support storing that kind of configuration in a package.json key.

danielo515 commented 2 years ago

Will try to reproduce it. It was failing in a company repo and I no longer have access to it, but this tool is valuable, so I will be using it in other projects.

El jue., 1 sept. 2022 19:01, Andy Edwards @.***> escribió:

@danielo515 https://github.com/danielo515 I just did a major important refactor, could you try with 2.0.0-beta.11 and let me know if you still have issues? That refactor theoretically enables me to support TypeScript's own parser, though I don't know if I'll ever try to tackle that...

— Reply to this email directly, view it on GitHub https://github.com/codemodsquad/astx/issues/11#issuecomment-1234547109, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARKJWOXDM3TYKAOL2UTMFDV4DOQHANCNFSM5SBIW5IQ . You are receiving this because you were mentioned.Message ID: @.***>

jedwards1211 commented 2 years ago

cool! Pretty soon I hope to finally implement a VSCode extension, now that I got that big refactor done

danielo515 commented 2 years ago

Glad to hear it! I will maye try to build a neovim plugin on top of it. It is not as fancy as VSCode, but the development is much, much easier and faster

On Thu, Sep 1, 2022 at 8:45 PM Andy Edwards @.***> wrote:

cool! Pretty soon I hope to finally implement a VSCode extension, now that I got that big refactor done

— Reply to this email directly, view it on GitHub https://github.com/codemodsquad/astx/issues/11#issuecomment-1234651765, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARKJWOXB5JYSD3ZTPWHW7TV4D2S7ANCNFSM5SBIW5IQ . You are receiving this because you were mentioned.Message ID: @.***>

--

https://danielorodriguez.com

jedwards1211 commented 1 year ago

I'm going to close this and open a separate feature request