I’ve got a simple package.json file and I want to add a comment. Is there a way to do this, or are there any hacks to make this work?
{
"name": "My Project",
"version": "0.0.1",
"private": true,
"dependencies": {
"express": "3.x",
"mongoose": "3.x"
},
"devDependencies" : {
"should": "*"
/* "mocha": "*" not needed as should be globally installed */
}
}
The example comment above doesn’t work as npm breaks. I’ve also tried // style comments.
After wasting an hour on complex and hacky solutions, I’ve found both simple and valid solution for commenting my bulky dependencies section in package.json
. Just like this:
{
"name": "package name",
"version": "1.0",
"description": "package description",
"scripts": {
"start": "npm install && node server.js"
},
"scriptsComments": {
"start": "Runs development build on a local server configured by server.js"
},
"dependencies": {
"ajv": "^5.2.2"
},
"dependenciesComments": {
"ajv": "JSON-Schema Validator for validation of API data"
}
}
When sorted the same way, it’s now very easy for me to track these pairs of dependencies/comments either in Git commit diffs or in an editor while working with file package.json
.
And no extra tools are involved, just plain and valid JSON.