如何发布包的 Node-API 版本以及非 Node-API 版本
¥How to publish a Node-API version of a package alongside a non-Node-API version
使用包 iotivity-node
说明以下步骤:
¥The following steps are illustrated using the package iotivity-node
:
-
首先,发布非 Node-API 版本:
¥First, publish the non-Node-API version:
-
更新
package.json
中的版本。对于iotivity-node
,版本变为1.2.0-2
。¥Update the version in
package.json
. Foriotivity-node
, the version becomes1.2.0-2
. -
检查发布清单(确保测试/演示/文档正常)
¥Go through the release checklist (ensure tests/demos/docs are OK)
-
npm publish
-
-
然后,发布 Node-API 版本:
¥Then, publish the Node-API version:
-
更新
package.json
中的版本。在iotivity-node
的情况下,版本变为1.2.0-3
。对于版本控制,我们建议遵循 semver.org 描述的预发布版本方案,例如1.2.0-napi
。¥Update the version in
package.json
. In the case ofiotivity-node
, the version becomes1.2.0-3
. For versioning, we recommend following the pre-release version scheme as described by semver.org e.g.1.2.0-napi
. -
检查发布清单(确保测试/演示/文档正常)
¥Go through the release checklist (ensure tests/demos/docs are OK)
-
npm publish --tag n-api
-
在此示例中,使用 n-api
标记版本已确保,尽管版本 1.2.0-3 晚于非 Node-API 发布的版本(1.2.0-2),但如果有人选择通过简单地运行 npm install iotivity-node
来安装 iotivity-node
,它将不会被安装。默认情况下,这将安装非 Node-API 版本。用户必须运行 npm install iotivity-node@n-api
才能接收 Node-API 版本。有关使用 npm 标签的更多信息,请查看 "使用 dist-tags"。
¥In this example, tagging the release with n-api
has ensured that, although
version 1.2.0-3 is later than the non-Node-API published version (1.2.0-2), it
will not be installed if someone chooses to install iotivity-node
by simply
running npm install iotivity-node
. This will install the non-Node-API version
by default. The user will have to run npm install iotivity-node@n-api
to
receive the Node-API version. For more information on using tags with npm check
out "Using dist-tags".
如何引入对包的 Node-API 版本的依赖
¥How to introduce a dependency on a Node-API version of a package
要将 iotivity-node
的 Node-API 版本添加为依赖,package.json
将如下所示:
¥To add the Node-API version of iotivity-node
as a dependency, the package.json
will look like this:
"dependencies": {
"iotivity-node": "n-api"
}
如 "使用 dist-tags" 中所述,与常规版本不同,标记版本不能通过版本范围(例如
package.json
内的"^2.0.0"
)来寻址。原因是标签只引用一个版本。因此,如果软件包维护者选择使用相同的标签标记软件包的更高版本,npm update
将收到更高版本。这应该是除了最新发布的版本之外的可接受版本,package.json
依赖必须引用确切的版本,如下所示:¥As explained in "Using dist-tags", unlike regular versions, tagged versions cannot be addressed by version ranges such as
"^2.0.0"
insidepackage.json
. The reason for this is that the tag refers to exactly one version. So, if the package maintainer chooses to tag a later version of the package using the same tag,npm update
will receive the later version. This should be acceptable version other than the latest published, thepackage.json
dependency will have to refer to the exact version like the following:
"dependencies": {
"iotivity-node": "1.2.0-3"
}