如何在 npm 上安装最新的次要版本的包?
How do I install the latest minor version of a package on npm?
例如:
- 我安装了
package-name
的 2.0.0
版本。
- 具有相同主版本的最新次版本是
2.1.2
- 最新的主要版本(如果我 运行
npm install package-name@latest
是 4.3.0
就会安装
如何安装没有重大更改的最新软件包?
Npm 使用 semver,所以你可以使用各种东西来接近你的目标
看看官方 documentation,你可以使用类似的东西:
npm install package-name@">=2.1.2 <2.2.0"
此外,还有多种范围,因此您可以使用此表格
Advanced Range Syntax 如您所见,这是一个示例,最后来自 semver 存储库的有趣摘录是您的答案:
Advanced range syntax desugars to primitive comparators in
deterministic ways.
Advanced ranges may be combined in the same way as primitive
comparators using white space or ||. Hyphen Ranges X.Y.Z - A.B.C
Specifies an inclusive set.
1.2.3 - 2.3.4 := >=1.2.3 <=2.3.4
If a partial version is provided as the first version in the inclusive
range, then the missing pieces are replaced with zeroes.
1.2 - 2.3.4 := >=1.2.0 <=2.3.4
If a partial version is provided as the second version in the
inclusive range, then all versions that start with the supplied parts
of the tuple are accepted, but nothing that would be greater than the
provided tuple parts.
1.2.3 - 2.3 := >=1.2.3 <2.4.0
1.2.3 - 2 := >=1.2.3 <3.0.0
X-Ranges 1.2.x 1.X 1.2.* *
Any of X, x, or * may be used to "stand in" for one of the numeric
values in the [major, minor, patch] tuple.
* := >=0.0.0 (Any version satisfies)
1.x := >=1.0.0 <2.0.0 (Matching major version)
1.2.x := >=1.2.0 <1.3.0 (Matching major and minor versions)
A partial version range is treated as an X-Range, so the special
character is in fact optional.
"" (empty string) := * := >=0.0.0
1 := 1.x.x := >=1.0.0 <2.0.0
1.2 := 1.2.x := >=1.2.0 <1.3.0
Tilde Ranges ~1.2.3 ~1.2 ~1
Allows patch-level changes if a minor version is specified on the
comparator. Allows minor-level changes if not.
~1.2.3 := >=1.2.3 <1.(2+1).0 := >=1.2.3 <1.3.0
~1.2 := >=1.2.0 <1.(2+1).0 := >=1.2.0 <1.3.0 (Same as 1.2.x)
~1 := >=1.0.0 <(1+1).0.0 := >=1.0.0 <2.0.0 (Same as 1.x)
~0.2.3 := >=0.2.3 <0.(2+1).0 := >=0.2.3 <0.3.0
~0.2 := >=0.2.0 <0.(2+1).0 := >=0.2.0 <0.3.0 (Same as 0.2.x)
~0 := >=0.0.0 <(0+1).0.0 := >=0.0.0 <1.0.0 (Same as 0.x)
~1.2.3-beta.2 := >=1.2.3-beta.2 <1.3.0 Note that prereleases in the 1.2.3 version will be allowed, if they are greater than or equal
to beta.2. So, 1.2.3-beta.4 would be allowed, but 1.2.4-beta.2 would
not, because it is a prerelease of a different [major, minor, patch]
tuple.
Caret Ranges ^1.2.3 ^0.2.5 ^0.0.4
Allows changes that do not modify the left-most non-zero digit in the
[major, minor, patch] tuple. In other words, this allows patch and
minor updates for versions 1.0.0 and above, patch updates for versions
0.X >=0.1.0, and no updates for versions 0.0.X.
Many authors treat a 0.x version as if the x were the major
"breaking-change" indicator.
Caret ranges are ideal when an author may make breaking changes
between 0.2.4 and 0.3.0 releases, which is a common practice. However,
it presumes that there will not be breaking changes between 0.2.4 and
0.2.5. It allows for changes that are presumed to be additive (but non-breaking), according to commonly observed practices.
^1.2.3 := >=1.2.3 <2.0.0
^0.2.3 := >=0.2.3 <0.3.0
^0.0.3 := >=0.0.3 <0.0.4
^1.2.3-beta.2 := >=1.2.3-beta.2 <2.0.0 Note that prereleases in the 1.2.3 version will be allowed, if they are greater than or equal
to beta.2. So, 1.2.3-beta.4 would be allowed, but 1.2.4-beta.2 would
not, because it is a prerelease of a different [major, minor, patch]
tuple.
^0.0.3-beta := >=0.0.3-beta <0.0.4 Note that prereleases in the 0.0.3 version only will be allowed, if they are greater than or equal to beta. So, 0.0.3-pr.2 would be allowed.
When parsing caret ranges, a missing patch value desugars to the
number 0, but will allow flexibility within that value, even if the
major and minor versions are both 0.
^1.2.x := >=1.2.0 <2.0.0
^0.0.x := >=0.0.0 <0.1.0
^0.0 := >=0.0.0 <0.1.0
A missing minor and patch values will desugar to zero, but also allow
flexibility within those values, even if the major version is zero.
^1.x := >=1.0.0 <2.0.0
^0.x := >=0.0.0 <1.0.0
所以总结你的例子可以是
npm install package-name@"^2.1.x"
您可以使用以下两种方法:-
In the simplest terms, the tilde matches the most recent minor version
(the middle number). ~1.2.3 will match all 1.2.x versions but will
miss 1.3.0.
The caret, on the other hand, is more relaxed. It will update you to
the most recent major version (the first number). ^1.2.3 will match
any 1.x.x release including 1.3.0, but will hold off on 2.0.0.
http://fredkschott.com/post/2014/02/npm-no-longer-defaults-to-tildes/
使用npm install package-name@"<next-major.0.0"
例如:
npm install package-name@"<3.0.0"
将在 3.0.0 之前安装最新版本(例如 2.11.1)
我遇到了同样的问题,并且来自 Java & Maven 环境,我会首先搜索 https://www.npmjs.com/ 以查找我的每个特定包。
然后我会查看包的“版本”选项卡并了解有关其版本的更多信息。 我假设主要版本带来重大更改,而次要版本仅包含代码改进和错误修复,至少这是惯例。但是阅读手册总是有帮助的:)
有时,版本谓词可以这样组成:“codelyzer@5.2.2 需要@angular/compiler@>=2.3.1 <10.0.0 || >9.0.0-beta 的对等体<10.0.0 || >9.1.0-beta <10.0.0 || >9.2.0-beta <10.0.0 但已安装 none。您必须自己安装对等依赖项。“
major.minor.patch = 1.0.3
major version
= 1
,
minor version
= 0
,
patch version
= 3
Major
、minor
和patch
表示package
. 的不同releases
tilde (~)
和 caret (^)
分别指定要使用的 patch
和 minor
版本。
~1.0.3
- 表示 install
version 1.0.3
或 latest
patch
version
例如 1.0.6
.
^1.0.3
- 表示 install
version
1.0.3
或 latest
minor
或 patch
version
比如1.4.0
.
- 如果
npm
package.json
引用尚未达到版本 1.0
的包,使用 caret(^)
符号只会获取 patch
version
.
例如:
- 我安装了
package-name
的2.0.0
版本。 - 具有相同主版本的最新次版本是
2.1.2
- 最新的主要版本(如果我 运行
npm install package-name@latest
是4.3.0
就会安装
如何安装没有重大更改的最新软件包?
Npm 使用 semver,所以你可以使用各种东西来接近你的目标
看看官方 documentation,你可以使用类似的东西:
npm install package-name@">=2.1.2 <2.2.0"
此外,还有多种范围,因此您可以使用此表格 Advanced Range Syntax 如您所见,这是一个示例,最后来自 semver 存储库的有趣摘录是您的答案:
Advanced range syntax desugars to primitive comparators in deterministic ways.
Advanced ranges may be combined in the same way as primitive comparators using white space or ||. Hyphen Ranges X.Y.Z - A.B.C
Specifies an inclusive set.
1.2.3 - 2.3.4 := >=1.2.3 <=2.3.4
If a partial version is provided as the first version in the inclusive range, then the missing pieces are replaced with zeroes.
1.2 - 2.3.4 := >=1.2.0 <=2.3.4
If a partial version is provided as the second version in the inclusive range, then all versions that start with the supplied parts of the tuple are accepted, but nothing that would be greater than the provided tuple parts.
1.2.3 - 2.3 := >=1.2.3 <2.4.0 1.2.3 - 2 := >=1.2.3 <3.0.0
X-Ranges 1.2.x 1.X 1.2.* *
Any of X, x, or * may be used to "stand in" for one of the numeric values in the [major, minor, patch] tuple.
* := >=0.0.0 (Any version satisfies) 1.x := >=1.0.0 <2.0.0 (Matching major version) 1.2.x := >=1.2.0 <1.3.0 (Matching major and minor versions)
A partial version range is treated as an X-Range, so the special character is in fact optional.
"" (empty string) := * := >=0.0.0 1 := 1.x.x := >=1.0.0 <2.0.0 1.2 := 1.2.x := >=1.2.0 <1.3.0
Tilde Ranges ~1.2.3 ~1.2 ~1
Allows patch-level changes if a minor version is specified on the comparator. Allows minor-level changes if not.
~1.2.3 := >=1.2.3 <1.(2+1).0 := >=1.2.3 <1.3.0 ~1.2 := >=1.2.0 <1.(2+1).0 := >=1.2.0 <1.3.0 (Same as 1.2.x) ~1 := >=1.0.0 <(1+1).0.0 := >=1.0.0 <2.0.0 (Same as 1.x) ~0.2.3 := >=0.2.3 <0.(2+1).0 := >=0.2.3 <0.3.0 ~0.2 := >=0.2.0 <0.(2+1).0 := >=0.2.0 <0.3.0 (Same as 0.2.x) ~0 := >=0.0.0 <(0+1).0.0 := >=0.0.0 <1.0.0 (Same as 0.x) ~1.2.3-beta.2 := >=1.2.3-beta.2 <1.3.0 Note that prereleases in the 1.2.3 version will be allowed, if they are greater than or equal
to beta.2. So, 1.2.3-beta.4 would be allowed, but 1.2.4-beta.2 would not, because it is a prerelease of a different [major, minor, patch] tuple.
Caret Ranges ^1.2.3 ^0.2.5 ^0.0.4
Allows changes that do not modify the left-most non-zero digit in the [major, minor, patch] tuple. In other words, this allows patch and minor updates for versions 1.0.0 and above, patch updates for versions 0.X >=0.1.0, and no updates for versions 0.0.X.
Many authors treat a 0.x version as if the x were the major "breaking-change" indicator.
Caret ranges are ideal when an author may make breaking changes between 0.2.4 and 0.3.0 releases, which is a common practice. However, it presumes that there will not be breaking changes between 0.2.4 and 0.2.5. It allows for changes that are presumed to be additive (but non-breaking), according to commonly observed practices.
^1.2.3 := >=1.2.3 <2.0.0 ^0.2.3 := >=0.2.3 <0.3.0 ^0.0.3 := >=0.0.3 <0.0.4 ^1.2.3-beta.2 := >=1.2.3-beta.2 <2.0.0 Note that prereleases in the 1.2.3 version will be allowed, if they are greater than or equal
to beta.2. So, 1.2.3-beta.4 would be allowed, but 1.2.4-beta.2 would not, because it is a prerelease of a different [major, minor, patch] tuple. ^0.0.3-beta := >=0.0.3-beta <0.0.4 Note that prereleases in the 0.0.3 version only will be allowed, if they are greater than or equal to beta. So, 0.0.3-pr.2 would be allowed.
When parsing caret ranges, a missing patch value desugars to the number 0, but will allow flexibility within that value, even if the major and minor versions are both 0.
^1.2.x := >=1.2.0 <2.0.0 ^0.0.x := >=0.0.0 <0.1.0 ^0.0 := >=0.0.0 <0.1.0
A missing minor and patch values will desugar to zero, but also allow flexibility within those values, even if the major version is zero.
^1.x := >=1.0.0 <2.0.0 ^0.x := >=0.0.0 <1.0.0
所以总结你的例子可以是
npm install package-name@"^2.1.x"
您可以使用以下两种方法:-
In the simplest terms, the tilde matches the most recent minor version (the middle number). ~1.2.3 will match all 1.2.x versions but will miss 1.3.0.
The caret, on the other hand, is more relaxed. It will update you to the most recent major version (the first number). ^1.2.3 will match any 1.x.x release including 1.3.0, but will hold off on 2.0.0.
http://fredkschott.com/post/2014/02/npm-no-longer-defaults-to-tildes/
使用npm install package-name@"<next-major.0.0"
例如:
npm install package-name@"<3.0.0"
将在 3.0.0 之前安装最新版本(例如 2.11.1)
我遇到了同样的问题,并且来自 Java & Maven 环境,我会首先搜索 https://www.npmjs.com/ 以查找我的每个特定包。
然后我会查看包的“版本”选项卡并了解有关其版本的更多信息。 我假设主要版本带来重大更改,而次要版本仅包含代码改进和错误修复,至少这是惯例。但是阅读手册总是有帮助的:)
有时,版本谓词可以这样组成:“codelyzer@5.2.2 需要@angular/compiler@>=2.3.1 <10.0.0 || >9.0.0-beta 的对等体<10.0.0 || >9.1.0-beta <10.0.0 || >9.2.0-beta <10.0.0 但已安装 none。您必须自己安装对等依赖项。“
major.minor.patch = 1.0.3
major version
= 1
,
minor version
= 0
,
patch version
= 3
Major
、minor
和patch
表示package
. 的不同tilde (~)
和caret (^)
分别指定要使用的patch
和minor
版本。~1.0.3
- 表示install
version 1.0.3
或latest
patch
version
例如1.0.6
.^1.0.3
- 表示install
version
1.0.3
或latest
minor
或patch
version
比如1.4.0
.- 如果
npm
package.json
引用尚未达到版本1.0
的包,使用caret(^)
符号只会获取patch
version
.
releases