Version constraints in JSON files
By Mike Street
While running through my "recent" 11ty upgrade I got caught out by a version contain syntax difference between Composer and NPM.
I use Composer a lot at work so am used to the syntax it has - this whole post centres around the caret (^).
When specifying a package and a version, the caret signifies:
- on NPM
^2.0.0installs2.x.x(All minor versions) - on Composer
^2.0.0installs2.0.x(Only bug fixes)
Composer allows the last number you specify to be incremented freely, so you can set ^2.0 to get all minor versions and bug fixes for version 2.
To be a bit more verbose, if our package had the following tags:
- 1.1.0
- 1.1.1
- 1.1.2
- 1.2.0
- 1.2.1
On Composer:
If you had ^1.1.0 you would go up to 1.1.2
If you put ^1.1 you would get all the way up 1.2.1
On NPM
- If you had
^1.1.0you would go up to1.2.1 - If you put
^1.1you would get all the way up1.2.1 - If you wanted just bug fixes, you would do
~1.1.0which would stop at1.1.2
It's a small difference that could have a big impact on the packages your site uses.