🌐 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 版本:
- 更新
package.json中的版本。对于iotivity-node,版本变为1.2.0-2。 - 检查发布清单(确保测试/演示/文档都正常)
npm publish
- 更新
- 然后,发布 Node-API 版本:
- 更新
package.json中的版本。在iotivity-node的情况下,版本变为1.2.0-3。关于版本管理,我们建议按照 semver.org 描述的预发行版本方案,例如1.2.0-napi。 - 检查发布清单(确保测试/演示/文档都正常)
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".
🌐 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"
}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 updatewill receive the later version. This should be acceptable in most cases. If you need a version other than the latest published, thepackage.jsondependency will have to refer to the exact version like the following:
"dependencies": {
"iotivity-node": "1.2.0-3"
}