Reputation: 193
How can i get the latest version (including the pre-releases) from an array of versions using node/semver.
For example:
var semver = require("semver");
var versions = ["1.0.0-rc.10","1.0.0-rc.11"];
console.log(semver.maxSatisfying(versions, "*"));
Returns null, but i want to get the 1.0.0-rc.11 back.
Kind Regards and have a nice day!
Upvotes: 2
Views: 2416
Reputation: 178
You need to add the includePrerelease
option to your maxSatisfying
method as described here: https://github.com/npm/node-semver#functions
In your example:
var semver = require("semver");
var versions = ["1.0.0-rc.10","1.0.0-rc.11"];
console.log(semver.maxSatisfying(versions, "*", {
includePrerelease: true
}));
Upvotes: 7
Reputation: 193
Okay i've found a solution.
The node module semver-extra
adds some nice extra functions to the semver library, also one for getting the max version including the pre-releases.
https://www.npmjs.com/package/semver-extra
Upvotes: 2