parse error for trailing comma in tsconfig.json
According to this issue on typescript repo, trailing commas in tsconfig are legal (like comments) https://github.com/microsoft/TypeScript/issues/20384#issuecomment-348552936
Example:
{
"extends": "@tsconfig/svelte/tsconfig.json",
"include": ["src/**/*"],
"exclude": ["node_modules"], // <- here
}
Comments are stripped here, but the comma is not, resulting in an error. https://github.com/TypeStrong/tsconfig/blob/3d0586d30a85e1098d4a966e6b563d58abc42620/src/tsconfig.ts#L187
Makes sense, related to https://github.com/TypeStrong/tsconfig/issues/28. Happy to accept a PR here, but would likely mean trying to implement a custom JSON parser. I'd recommend using typescript directly where possible.
I see 2 possible implementations
- after stripping comments with https://github.com/sindresorhus/strip-json-comments use a similar implementation to strip the dangling commas before passing it to JSON.parse ~~2) get nasty and use eval, trying to safeguard against nefarious input~~ edit: removed some code that looked like it could work but i don't want to leave it here as it is too dangerous
an optional peerdependency on typescript and using its native functions before resorting to a custom implementation would be better. In my case i ran into this in vite, which uses esbuild so there is no typescript by default.
Have you thought about using the jsonc-parser package to read the config files ? https://www.npmjs.com/package/jsonc-parser