Felix
Felix

Reputation: 620

Should I include minor version in package.json when using Caret?

I understand that using ^2.x and ^2.1.2 will both update minor versions and patches as long as major version is still 2, however should I specify minor version and/or patch version if I use the caret?

One of the comments in https://bytearcher.com/articles/semver-explained-why-theres-a-caret-in-my-package-json/ says:

you don't actually want 2.., because that allows both newer and older releases. ^2.1.2 means "2.1.2 or newer".

But if I know ^2.1.2 is already released, wouldn't using ^2.x essentially always be equivalent to ^2.1.2, so is there a purpose to including minor and patch version?

Upvotes: 3

Views: 767

Answers (1)

Ogen
Ogen

Reputation: 6709

Use this tool to test your hypotheses: https://semver.npmjs.com/

According to this tool, there is a point in including the minor and/or patch version. After experimenting a little bit, it seems that the caret symbol will lock down the minor version but it won't pull in anything that is older than the version you supplied.

So for example: ^2 can pull in version 2.2 but ^2.3 will not.

Upvotes: 1

Related Questions