mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-14 16:46:25 +00:00
addf184473
The goal of this PR is to refactor npm's version lookup/grouping as much as possible to enable the same logic to be used for other package managers.
51 lines
1.2 KiB
JavaScript
51 lines
1.2 KiB
JavaScript
const semver = require('semver');
|
|
const stable = require('semver-stable');
|
|
const { rangify } = require('./range');
|
|
|
|
const { is: isStable } = stable;
|
|
|
|
const {
|
|
compare: sortVersions,
|
|
intersects,
|
|
maxSatisfying: maxSatisfyingVersion,
|
|
minSatisfying: minSatisfyingVersion,
|
|
minor: getMinor,
|
|
satisfies: matches,
|
|
valid: isPinnedVersion,
|
|
validRange,
|
|
} = semver;
|
|
|
|
const padRange = range => range + '.0'.repeat(3 - range.split('.').length);
|
|
|
|
const getMajor = input => {
|
|
const version = isPinnedVersion(input) ? input : padRange(input);
|
|
return semver.major(version);
|
|
};
|
|
|
|
const isRange = input => isValid(input) && !isPinnedVersion(input);
|
|
|
|
// If this is left as an alias, inputs like "17.04.0" throw errors
|
|
const isValid = input => validRange(input);
|
|
|
|
const isLessThan = (version, base) =>
|
|
isPinnedVersion(base) ? semver.lt(version, base) : semver.ltr(version, base);
|
|
|
|
const isGreaterThan = (version, base) =>
|
|
isPinnedVersion(base) ? semver.gt(version, base) : semver.gtr(version, base);
|
|
|
|
module.exports = {
|
|
getMajor,
|
|
getMinor,
|
|
intersects,
|
|
isGreaterThan,
|
|
isLessThan,
|
|
isPinnedVersion,
|
|
isRange,
|
|
isStable,
|
|
isValid,
|
|
matches,
|
|
maxSatisfyingVersion,
|
|
minSatisfyingVersion,
|
|
rangify,
|
|
sortVersions,
|
|
};
|