简体   繁体   English

npm依赖项不在package.json中-由于缺少注释?

[英]npm dependencies not in package.json - due to missing comments?

I am wondering, if there is a way of using comments for my package.json dependencies. 我想知道,是否有一种方法可以对我的package.json依赖项使用注释。

Right now we have a bigger package.json file and we get more and more lost about the dependencies and there they come from. 现在,我们有一个更大的package.json文件,我们越来越依赖于依赖项,而依赖项正是从那里来的。 On other languages (not javascript) we can easily add comments. 在其他语言(不是javascript)上,我们可以轻松添加评论。 But since JSON is not supporting comments, this gets really tough for us. 但是由于JSON不支持注释,因此对我们来说真的很难。

Is there a optional file format for package.json to define our dependencies? package.json是否有可选的文件格式来定义我们的依赖关系? If not, how can we manage to create a package.json with comments? 如果没有,我们如何管理带有注释的package.json?

Far more I am wondering, why node/NPM forces developers NOT to document, by choosing a fileformat which makes it impossible to document?!? 我想知道的是,为什么节点/ NPM通过选择无法记录的文件格式来迫使开发人员不记录?!

Hope someone can help us out of the dark... 希望有人可以帮助我们摆脱困境...

I had the same problem earlier on this year. 今年年初,我遇到了同样的问题。 I've just solved that problem with writing some basic script like this 我刚刚通过写一些像这样的基本脚本解决了这个问题

#!/usr/local/bin/python

import os

os.rename("package.json", "package_M.json")

with open("package_M.json") as f:
    with open("package.json", "a") as tmp_p:
        for line in f:
            if "//" not in line:
                tmp_p.write(line)
os.system('npm install')
os.remove("package.json")
os.rename("package_M.json", "package.json")

I know it something like "Hacking" but it works for me :) 我知道它像“黑客”,但对我有用:)
Hope it will help ! 希望对您有所帮助!

I did not understand your title, why would some dependencies would fail to get installed to package.json . 我不明白您的标题,为什么有些依赖项无法安装到package.json The only explanation would be forgotten --save flag upon npm i . 唯一的解释会被遗忘--save在标志npm i

Moving onwards, 继续前进,

Is there a optional file format for package.json to define our dependencies? package.json是否有可选的文件格式来定义我们的依赖关系?

No. 没有。

If not, how can we manage to create a package.json with comments? 如果没有,我们如何管理带有注释的package.json?

See the original question that this question duplicates: How do I add comments to package.json for npm install? 请参阅该问题重复的原始问题: 如何为npm安装向package.json添加注释? there are some recipes there. 那里有一些食谱。 Personally, I don't want to put comments in package.json s, but I do use comments in my JSON's. 就个人而言,我不想在package.json注释,但是我确实在JSON中使用注释。 I simply add dummy fields like "widt__comment___(value_below_is_capped_to_660_||_false_will_be_set_to_660_too)": false, . 我只添加了诸如"widt__comment___(value_below_is_capped_to_660_||_false_will_be_set_to_660_too)": false,伪字段"widt__comment___(value_below_is_capped_to_660_||_false_will_be_set_to_660_too)": false, I omit the last letter and it appears on top when JSONs are sorted (next field would be width , so its comment starts with widt_ ). 我忽略了最后一个字母,当对JSON进行排序时,它出现在顶部(下一个字段为width ,因此其注释以widt_ )。

why node/NPM forces developers NOT to document, by choosing a fileformat which makes it impossible to document? 为什么节点/ NPM通过选择一种无法记录的文件格式来迫使开发人员不记录?

package.json will have to be reliably parsed and rendered back, what limits the possible formats' choices. package.json将必须可靠地解析呈现回去,这限制了可能格式的选择。 JSON is very reliable, old format, with very strict, known rules on its parsing and rendering. JSON是一种非常可靠的旧格式,在解析和呈现方面具有非常严格的已知规则。 JSON is also covered by standards RFC 7159 and ECMA-404. RFC 7159和ECMA-404标准也涵盖了JSON。 TOML is not covered by any. TOML不包含任何内容。 YAML is not covered by any standards either. YAML也不受任何标准覆盖。 By the way, TOML is still on v0.x which is not even considered stable as per Semver. 顺便说一句,TOML仍然是其上没有考虑按Semver 稳定 v0.x。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM