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 (you should really follow him):
Are there any plans to make it possible for package.json to contain comments? I can understand the implications but i.e., I would like to write the reason why I had to lock a package to a specific version (hello, TypeScript)
And I was a bit confused... It's a JSON, I can do whatever I want with it! So I've put together some code just to run an npm install
on it...
{
"name": "napolux-frontend",
"version": "1.0.0",
"description": "it's a test",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "MIT",
"devDependencies": {
"@babel/core": "^7.2.2",
"@babel/preset-env": "^7.3.1",
"babel-polyfill": "^6.26.0",
"gulp": "^4.0.0",
"gulp-babel": "^8.0.0",
"gulp-rename": "^1.4.0",
"gulp-uglify": "^3.0.1"
},
"dependencies": {
"jquery": "^3.3.1"
},
"comments": {
"dependencies": "we use jQuery because of reasons",
"repository": "our beloved repo",
"license": "we love MIT, so why not",
"devDependencies": {
"@babel/core": "it's @ version 7.2.2 because of...",
"gulp-rename": "why not"
}
}
}
It works! It's not the best possible solution, for sure no inline comments for example, but if you maintain the structure of your comments
section very close to the one of package.json
it will be definetely readable!
This post originally appeared on https://coding.napolux.com, but was brought to dev.to for your reading pleasure ❤.
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!