Description
- I'd be willing to implement this feature
- This feature can already be implemented through a plugin
Describe the user story
As a package author I want to put comments in my package manifests, e.g.
{
"peerDependencies": {
"@angular/compiler-cli": "^8.0.0",
// Keep this in sync with the version required by @angular/compiler-cli
"typescript": "~3.4.7"
}
}
See also: yarnpkg/yarn#178 and others.
Describe the solution you'd like
Parse the package manifests using JSON5 or another library that parses JSON with comments
Describe the drawbacks of your solution
-
The package.json becomes unparseable by other package managers like
npm
or tools that don't support the extended JSON syntax.That's a big downside due to the number of tools that parse package.json files (e.g. every tool that can be configured from within the package manifest) but as it's completely optional I personally don't think this is a blocker.
-
We'd need to clean this up at publish time (but we already do this, so that shouldn't matter much)
-
Writing the package manifest to disk becomes a lot more complicated: do we remove comments on the line before a removed dependency? do we move comments around if we sort the dependencies?
An easy solution would be to say "we just write JSON, i.e. without comments, so it's up to you to ensure the comments remain" which might be a good MVP to start with but it doesn't seem like a good idea for the long run.
Describe alternatives you've considered
Adding comments out of place, e.g.
{
"//": "Keep typescript in sync with the dependency listed in @angular/compiler-cli",
"peerDependencies": {
"@angular/compiler-cli": "^8.0.0",
"typescript": "~3.4.7"
}
}
but this dirties the package manifest: these extra values can get published and they require changes if more comments are added (no duplicate keys are allowed, so you'd have to use // <counter>
instead)