When you're bored, you usually have your best ideas. While wasting some time on twitter this morning I met a legit question coming from @caludio ...
For further actions, you may consider blocking this person and/or reporting abuse
The convention I have started using is the following:
Note: For the
dependencies
,devDependencies
, etc sections, the comment annotations can't be added directly above the individual package dependencies inside the configuration object sincenpm
is expecting the key to be the name of an npm package. Hence the reason for the@comment dependencies
.Note: In certain contexts, such as in the
scripts
object, some editors/IDEs may complain about the array. In thescripts
context, VS Code expects a string for the value -- not an array.A top-level comment annotation can also be added similar to what Francesco presented.
However, I like keeping the comment as close as possible to what it applies to.
I have changed a few things in how I add comments to package.json. Here is an example of the new convention I am following:
I really like this idea; it should be a standard. Let's discuss and vote up in npm / cli / issues / #677
I think you might wanna keep things like this in a separate place, like Github issues, or maybe just some file. But I don’t think
package.json
is a good place.It’s the best place: right next (oh, well, as close as possible with a file format that was not made for writing configuration) to where you do the thing. You don’t want anybody (even your future self), to think “Oh, look, someone bumped babel/preset-env to 7.3 but forgot to do the same with babel/core”. And that’s what people are going to think, not “Oh, look, babel/preset-env is on 7.3, but babel/core is on 7.2, let’s walk through all the GitHub issues to see if it’s intentional or not.”
Why do you think
package.json
is not a good place for comments about things inpackage.json
?I just feel most people wouldn’t be looking for this kind of information in
package.json
. But if you wanna put stuff in there then sure go ahead.Could be. But having them in the same file makes them super close to the packages and their definitions.
Agree, I think this is the preference of most people
Yeah I guess. Everyone has their own preferences.
This could be an interesting discussion which discussed the extending the package json file, such as using JSON5, YAML, HJSON instead of just plain JSON.
npm.community/t/support-package-js...
And most of these syntax standards support comments out of box. Love to see further result. Thank you for starting the discussion @napolux
Thanks for this - it's a solution to a problem I've had a couple of times while teaching, but it never occurred to me to try this!