How to install the latest package on npm?

For instance:

  • I have a version 2.0.0of of installed package-name.
  • The latest minor version with the same major version is 2.1.2
  • The latest major version (which will be installed if I run npm install package-name@latest,4.3.0

How can I install the last package that does not have an interrupt?

+4
source share
2 answers

Npm uses semver, so you can use many things to achieve those close to your goal.

Looking at the official documentation , you can use something like:

npm install package-name@">=2.1.2 <2.2.0"

, , , , semver repo , :

.

, , ||. Hyphen Ranges X.Y.Z - A.B.C

.

1.2.3 - 2.3.4 := >=1.2.3 <=2.3.4

, .

1.2 - 2.3.4 := >=1.2.0 <=2.3.4

, , , , .

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. * *

X, x * "" [major, minor, patch].

* := >=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)

X-Range, .

"" (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

~ 1.2.3 ~ 1.2 ~ 1

, . , .

~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

2. , 1.2.3-beta.4, 1.2.4-2 , [, , ] .

^ 1.2.3 ^ 0.2.5 ^ 0.0.4

, [, , ] . , 1.0.0 , 0.X >= 0.1.0 0.0.X.

0.x, "break-change".

Caret , 0,2,4 0,3 , . , , 0.2.4 0.2.5. , ( ), .

^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

2. , 1.2.3-beta.4, 1.2.4-2 , [, , ] .     ^ 0.0.3-beta: = >= 0.0.3-beta < 0.0.4 , 0.0.3 , -. , 0.0.3-pr.2.

0, , 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

- , , .

^1.x := >=1.0.0 <2.0.0
^0.x := >=0.0.0 <1.0.0

npm install package-name@"^2.1.x"
+4

: -

( ). ~ 1.2.3 1.2.x, 1.3.0.

, , . ( ). ^ 1.2.3 1.x.x, 1.3.0, 2.0.0.

http://fredkschott.com/post/2014/02/npm-no-longer-defaults-to-tildes/

0

Source: https://habr.com/ru/post/1654815/


All Articles