I understand that ^
means anything up to the next major versions, ~
means only patches. There is a lot of documentation covering that, but unclear what the max version is when using >=
What does >=
equate to, that is, what is the maximum version allowed?
{
"foo": "^1.1.1", // packages from 1.1.1 and less than 2.0.0
"bar": "~1.1.1", // packages from 1.1.1 and less than 1.2
"bar": ">=1.1.1" // packages from 1.1.1 and less than ?
}
The >=
comparator is defined as you might expect:
>=
Greater than or equal to
Which has no maximum in its definition.
To add a max version number, one way would be to join it with another comparator via whitespace (e.g.
) to create a comparator set, which is
comparator set - satisfied by the intersection of all of the comparators it includes.
Let's say you wanted a version greater than or equal to 1.2.0
but less than 5.0.0
. Your full semver range would then be
>=1.2.0 <5.0.0
It is worth nothing that all ranges can be satisfied by primitive comparators (<
, <=
,>
, >=
, or =
), but libraries such as NPM allows for advanced range syntax that converts down to the primitive comparators in predictable ways. Here are some other examples you may find more useful, but again just note that you aren't bound by any specific syntax. You can use what you find most readable.
X.Y.Z - A.B.C
1.2.3 - 2.3.4
→ >=1.2.3 <=2.3.4
1.2.x
1.X
1.2.*
*
1.x
→ >=1.0.0 <2.0.0
~1.2.3
~1.2
~1
~1.2.3
→ >=1.2.3 <1.3.0
^1.2.3
^0.2.5
^0.0.4
^1.2.3
→ >=1.2.3 <2.0.0