gpt4 book ai didi

comments - 如何向 npm install 的 package.json 添加注释?

转载 作者:行者123 更新时间:2023-12-03 03:57:44 26 4
gpt4 key购买 nike

我有一个简单的 package.json 文件,我想添加一条注释。有没有办法做到这一点,或者有什么技巧可以做到这一点?

{
"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 中断时不起作用。我也尝试过//样式注释。

最佳答案

最近在 Node.js mailing list 上对此进行了讨论.

根据创建 npm 的 Isaac Schlueter 的说法:

... the "//" key will never be used by npm for any purpose, and is reserved for comments ... If you want to use a multiple line comment, you can use either an array, or multiple "//" keys.

当使用常用工具(npm、yarn 等)时,多个 "//" 键将被删除。这仍然存在:

{ "//": [
"first line",
"second line" ] }

这将无法生存:

{ "//": "this is the first line of a comment",
"//": "this is the second line of the comment" }

One must be aware that "//" can only be used at the root of the package.json object. For example

{ 
"//": "comment!",
"dependencies": {...}
}

is valid but

{ 
"dependencies": {
"//": "comment?"
}
}

is invalid.

-- @david_p comment

关于comments - 如何向 npm install 的 package.json 添加注释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14221579/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com