-
Notifications
You must be signed in to change notification settings - Fork 507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tsdx silently fails parsing of tsconfig files containing comments, trailing commas, etc. that TSC accepts #483
Comments
Awesome description and investigation @justingrant !! I haven't read through the CRA issues/code (don't have time right now, will check later), but your reasoning and that solution according to it make sense to me. Would you like to add a PR(s) for this and #484 ? I actually wrote that |
Hi @agilgur5 - Thanks! I don't think I'll have time to PR this problem in the near future-- very busy month ahead for me and I was lucky to have time over this weekend to report some issues. Sorry I can't help more, but at least I wanted to record the problem before I got sucked into other tasks on Monday. |
No worries -- figured I'd ask since you've done a lot of the investigation toward the solution already! And always good to encourage contributors in general in OSS 🙂 I'll make sure to add you to allcontributors for bugs and ideas if somebody else (probably me) PRs that |
Merged in #489 as I'm now a collaborator. Turns out that |
@allcontributors please add @justingrant for bugs, ideas |
I've put up a pull request to add @justingrant! 🎉 |
Current Behavior
tsc
supports tsconfig.json files that contain comments, trailing commas, and other features beyond standard JSON.Current tsdx, however, parses tsconfig.json using
fs.readJson
which ends up calling JSON.parse which will throw an exception if faced with comments, trailing commas, and other non-standard JSON content. Making things worse, the exception is silently ignored, which makes it really hard to figure out why config settings are being ignored. I had to step through tsdx code to figure out what was going on.tsdx/src/createRollupConfig.ts
Lines 46 to 49 in 4f6de10
Luckily this JSON is only used once in tsdx (only in createRollupConfig.ts) and that JSON is only currently used for one setting:
esModuleInterop
. But #468 is about to use it too for processingdeclarationDir
.BTW, tsdx is in good company with this problem: Create React App had the same problem.
There's also an extends feature in tsconfig which allows configuration inheritance across multiple tsconfig files. This isn't supported by tsdx either. See #484.
Expected behavior
Suggested solution(s)
For 1) Luckily, the nice people in TypeScript-land have exported their tsconfig parser. From facebook/create-react-app#6865 (comment):
Note that there are a whole set of parse functions defined. Hopefully one of those would meet tsdx's needs. Ideally it'd also support the
extends
keyword in tsconfig.json which is also currently unsupported by tsdx.for 2) I'd suggest white-listing ignorable exceptions (e.g. file not found?) and reporting the rest to the user. In particular, any syntax errors should be reported to the user and should fail the build.
Additional context
Your environment
The text was updated successfully, but these errors were encountered: