codemodsquad/astx

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

danielo515 opened this issue · 11 comments

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

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?

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

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

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

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

I'll try to trim them down and then share

@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.

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

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