yarn icon indicating copy to clipboard operation
yarn copied to clipboard

Yarn strips out duplicate comment keys from package.json

Open imontiel opened this issue 10 years ago • 2 comments

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.

  1. Create a package.json file with the following content:
{
  "name": "test",
  "version": "1.0.0",
  "scripts": {
    "//": "This is a comment",
    "//": "This is another comment",
  },
  dependencies: {
    "react": "^15.0.0",
  }
}
  1. Run yarn upgrade react
  2. The package.json file 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

imontiel avatar Nov 03 '16 22:11 imontiel

Not sure if keeping two properties with the same key "//" is a correct json syntax

check http://pro.jsonlint.com/

KhaledMohamedP avatar Nov 04 '16 04:11 KhaledMohamedP

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.

sebmck avatar Nov 04 '16 10:11 sebmck