我有一个简单的包裹。json文件,我想添加一个评论。有办法做到这一点吗,或者有什么hack可以做到这一点吗?
{
"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 */
}
}
上面的示例注释在npm崩溃时不起作用。我还尝试了// style注释。
用于npm的包。我发现了两种方法(在阅读这段对话后):
"devDependencies": {
"del-comment": [
"some-text"
],
"del": "^5.1.0 ! inner comment",
"envify-comment": [
"some-text"
],
"envify": "4.1.0 ! inner comment"
}
但是在更新或重新安装带有“——save”或“——save-dev”的包时,会出现“^4.1.0 !”注释”中相应的地方将被删除。所有这些都将打破npm审计。
受这条线索的启发,下面是我们正在使用的:
{
"//dependencies": {
"crypto-exchange": "Unified exchange API"
},
"dependencies": {
"crypto-exchange": "^2.3.3"
},
"//devDependencies": {
"chai": "Assertions",
"mocha": "Unit testing framwork",
"sinon": "Spies, Stubs, Mocks",
"supertest": "Test requests"
},
"devDependencies": {
"chai": "^4.1.2",
"mocha": "^4.0.1",
"sinon": "^4.1.3",
"supertest": "^3.0.0"
}
}
最近在Node.js邮件列表中讨论了这个问题。
根据创建npm的Isaac Schlueter的说法:
... "//"键永远不会被NPM用于任何目的,它是为注释保留的…如果想使用多行注释,可以使用数组或多个“//”键。
当使用你常用的工具(npm, yarn等)时,多个“//”键将被移除。这生存:
{ "//": [
"first line",
"second line" ] }
这将不复存在:
{ "//": "this is the first line of a comment",
"//": "this is the second line of the comment" }
必须注意,"//"只能在包的根目录下使用。json对象。例如
{
“/ /”:“评论!”
“依赖”:{…}
}
是有效的但是
{
“依赖”:{
“/ /”:“评论?”
}
}
是无效的。
——@david_p评论