Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does npm honour newer prerelease versions in semver?

In my app, I have users install dependencies by running npm install -- bog standard behaviour.

However, I have one package that changes frequently, and in an effort to not end up with a ridiculously large version number like 0.1.12324, I stumbled upon the concept of pre-releases.

How does npm treat prerelease numbers when running npm install?

Assuming my package packageA has a version number of 0.1.1-r1234, and my users have a dependency semver of ~0.1.1:

I know that a new user without packageA installed will automatically have that version (0.1.1-r1234) installed.

What if someone already has packageA installed, of version 0.1.1-r1233? Does npm install know to install the newer pre-release?

like image 750
Julian H. Lam Avatar asked Nov 28 '13 23:11

Julian H. Lam


1 Answers

I seemed to have answered my own question. From the main page at semver.org:

Precedence for two pre-release versions with the same major, minor, and patch version MUST be determined by comparing each dot separated identifier from left to right until a difference is found as follows: identifiers consisting of only digits are compared numerically and identifiers with letters or hyphens are compared lexically in ASCII sort order. Numeric identifiers always have lower precedence than non-numeric identifiers. A larger set of pre-release fields has a higher precedence than a smaller set, if all of the preceding identifiers are equal. Example: 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0.

like image 135
Julian H. Lam Avatar answered Oct 08 '22 13:10

Julian H. Lam