tsdx silently fails parsing of tsconfig files containing comments, trailing commas, etc. that TSC accepts
See original GitHub issueCurrent 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.
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 processing declarationDir
.
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
- tsdx should accept the same tsconfig.json syntax that does.
- Syntax errors (or other unexpected errors) reading tsconfig.json should not be silently ignored.
Suggested solution(s)
For 1) Luckily, the nice people in TypeScript-land have exported their tsconfig parser. From https://github.com/facebook/create-react-app/issues/6865#issuecomment-485962203:
Unfortunately it looks like typescript uses a hand-written parser. I traced it down to parseJsonText which is defined in src/compiler/parser.ts. Ahahaha.
If we’re allowed to hook into the typescript package, it looks like they provide public access to their parse function.
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
Software | Version(s) |
---|---|
TSDX | tsdx@0.12.3 |
TypeScript | typescript@3.7.5 |
Browser | n/a (this is a build issue) |
npm/Yarn | yarn@1.21.1 |
Node | v12.13.1 |
Operating System | MacOS Catalina 10.15.2 |
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:6 (1 by maintainers)
Top GitHub Comments
@allcontributors please add @justingrant for bugs, ideas
@agilgur5
I’ve put up a pull request to add @justingrant! 🎉