pnpm / meta-updater

MIT License
54 stars 6 forks source link

Support JSON with comments (tsconfig) #11

Open jonaskello opened 9 months ago

jonaskello commented 9 months ago

The tsconfig.json file supports comments. When I tried to use this package to sync tsconfig.json with package.json I got an error message for existing tsconfig.json files:

❯ p meta-updater
ERROR: Error while processing /xxx/tsconfig.json: Expected property name or '}' in JSON at position 4
ERROR: Error while processing /xxx/tsconfig.json: Expected property name or '}' in JSON

I think this is because those files have comments. Perhaps JSON could be parsed with JSON5 instead to allow for this?

jonaskello commented 9 months ago

I realised that using JSON5 you would still loose the comments when writing the file back. In order to preserve the comments we would probably need to use something like momoa.

https://github.com/hjson allows roundtrip of comments.

b0o commented 7 months ago

I'm running into this issue. Did you find a solution?

jonaskello commented 7 months ago

@b0o Unfortunately not yet. We ended up just stripping the comments from all tsconfig.json files.