Gar*_*iel 7 versioning npm semantic-versioning
考虑使用这些版本的库(例如 NPM 包):
如果我^1.0.0
在依赖项中指定,将安装什么版本?1.1.0-prerelease
是最新版本,但我认为任何预发布版本都不满足我未指定预发布部分的范围。我尝试过使用https://semver.npmjs.com,但 lodash 不存在预发布也是最新的情况。
通常,带有插入符号 ( ) 前缀的范围(^
例如)^1.0.0
不会1.1.0-prerelease
导致安装预发行版本。
因此,鉴于您的问题中提供的示例,通常安装的版本是1.0.2
.
注意:但是,这种逻辑可能并不总是如此 - 我将很快解释原因。
在撰写本文时,说明使用 Semver 计算器的典型typescript
逻辑的更好示例是使用而不是进行测试lodash
。
使用semver 计算器:
typescript
作为套餐^4.0.0
正如您所看到的,它选择4.0.2
和不选择4.2.0-dev.20201204
(在 后发布到 npm 注册表4.0.2
)。通常会发生这种逻辑。
You'll, have noticed that in my previous explanation I say "typically" alot. I say that because npm has a dist-tag feature that allows the publisher of a package to modify the distribution tags. A short excerpt from the documentation for dist-tag reads as follows:
By default, the
latest
tag is used by npm to identify the current version of a package, andnpm install <pkg>
(without any@<version>
or@<tag>
specifier) installs thelatest
tag. Typically, projects only use thelatest
tag for stable release versions, and use other tags for unstable versions such as prereleases.
So, if we consider again the typescript
example described in the previous section. If the publisher associated the latest
tag in the npm registry with version 4.2.0-dev.20201204
. For example if they run the following command:
npm dist-tag add typescript@4.2.0-dev.20201204 latest
Run Code Online (Sandbox Code Playgroud)
then version 4.0.2
will not be installed (given a semver range of ^4.0.0
), and instead version 4.2.0-dev.20201204
will be installed.
Similarly, given the examples provided in your question, if we were to associate the latest
tag with version 1.1.0-prerelease
(using the npm dist-tag ...
command), and given a range specified as ^1.0.0
in the dependencies
section of your package.json, then version 1.1.0-prerelease
will be installed and not 1.0.2
.
Note: I would consider these scenarios described in this section as quite rare, (they're certainly not typical but useful to understand), because as stated in that previous excerpt from the docs:
Typically, projects only use the
latest
tag for stable release versions
Additional info:
Utilize the npm view command to discover information about a package(s) dist tags, particularly the latest
tag. For example:
The following command prints all tag information for the typescript
package:
npm view typescript dist-tags
Run Code Online (Sandbox Code Playgroud)
The following command prints the version associated with the latest
tag for the typescript
package:
npm view typescript dist-tags.latest
Run Code Online (Sandbox Code Playgroud)
For further info about distribution tags refer to adding dist-tags to packages.
归档时间: |
|
查看次数: |
2656 次 |
最近记录: |