gpt4 book ai didi

node.js - 将自定义元数据或配置添加到 package.json,是否有效?

转载 作者:IT老高 更新时间:2023-10-28 21:50:50 26 4
gpt4 key购买 nike

我见过(不记得在哪里)一个 package.json 文件,其中包含以下划线开头的自定义键:

{
"name": "application-name"
, "version": "0.0.1"
, "private": true
, "dependencies": {
"express": "2.4.7"
, "jade": ">= 0.0.1"
}
, "_random": true
}

你可以这样做吗?它仍然有效吗?如果允许,是否有任何有关规则的文档?

谢谢!

最佳答案

tl;dr:

  • 是的,您可以将自定义条目添加到 package.json
  • 选择一个键名:
    • 尚未定义(详情如下)
    • 未保留以供将来使用(详情如下)
    • 避免前缀 _$
    • 最好使用一个单个顶级键在其中嵌套您的自定义条目

例如,如果您拥有域 example.org,您可以按如下方式存储自定义 random 键,在反向域的顶级键中-name 符号用 _ 代替 .,如果适用,-(见评论) (例如,org_example):

{
"name": "application-name"
, "version": "0.0.1"
, "private": true
, "dependencies": {
"express": "2.4.7"
, "jade": ">= 0.0.1"
}
, "org_example": {
"random": true
}
}

要读取此类自定义属性,请使用以下技术:

require("./package.json").org_example.random // -> true

npmpackage.json 文件格式大多符合 CommonJS package specification :

至于选择自定义键:CommonJS package specification状态(强调我的):

The following fields are reserved for future expansion: build, default, email, external, files, imports, maintainer, paths, platform, require, summary, test, using, downloads, uid.

Extensions to the package descriptor specification should strive to avoid collisions for future standard names by name-spacing their properties with innocuous names that do not have meanings relevant to general package management.

The following fields are reserved for package registries to use at their discretion: id, type.All properties beginning with _ or $ are also reserved for package registries to use at their discretion.

关于node.js - 将自定义元数据或配置添加到 package.json,是否有效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10065564/

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