Yarn strips out duplicate comment keys from package.json
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
When you run yarn upgrade or yarn add ___, Yarn will update the package.json file, but it will remove duplicate "comment" keys.
If the current behavior is a bug, please provide the steps to reproduce.
- Create a
package.jsonfile with the following content:
{
"name": "test",
"version": "1.0.0",
"scripts": {
"//": "This is a comment",
"//": "This is another comment",
},
dependencies: {
"react": "^15.0.0",
}
}
- Run
yarn upgrade react - The
package.jsonfile will become:
{
"name": "test",
"version": "1.0.0",
"scripts": {
"//": "This is a comment",
},
dependencies: {
"react": "^15.3.2",
}
}
What is the expected behavior?
The expected behavior is that the package.json file looks like:
{
"name": "test",
"version": "1.0.0",
"scripts": {
"//": "This is a comment",
"//": "This is another comment",
},
dependencies: {
"react": "^15.3.2",
}
}
I can see why Yarn would strip duplicate keys since they are not really valid, however, I think that "//" is a special case since it is reserved for comments:
That's why the "//" key will never be used by npm for any purpose, and is reserved for comments.
–– https://groups.google.com/forum/#!msg/nodejs/NmL7jdeuw0M/yTqI05DRQrIJ
Please mention your node.js, yarn and operating system version.
- Node: 5.11.0
- Yarn: 0.16.1
- OS: Mac OS Sierra
Not sure if keeping two properties with the same key "//" is a correct json syntax
check http://pro.jsonlint.com/
There's no way we can keep these are we deserialise, modify then serialise package.json to make these changes. We plan on maybe eventually native support for comments to package.json but we'll need to take long considerations on backwards compatibility etc.