renovate/lib/versioning/semver/index.ts
2020-02-18 08:34:10 +01:00

53 lines
1.2 KiB
TypeScript

import semver from 'semver';
import stable from 'semver-stable';
import { NewValueConfig, VersioningApi } from '../common';
export const id = 'semver';
export const displayName = 'Semantic';
export const urls = ['https://semver.org/'];
export const supportsRanges = false;
const { is: isStable } = stable;
const {
compare: sortVersions,
maxSatisfying: maxSatisfyingVersion,
minSatisfying: minSatisfyingVersion,
major: getMajor,
minor: getMinor,
patch: getPatch,
satisfies: matches,
valid,
ltr: isLessThanRange,
gt: isGreaterThan,
eq: equals,
} = semver;
// If this is left as an alias, inputs like "17.04.0" throw errors
export const isVersion = (input: string): string => valid(input);
export { isVersion as isValid, maxSatisfyingVersion };
function getNewValue({ toVersion }: NewValueConfig): string {
return toVersion;
}
export const api: VersioningApi = {
equals,
getMajor,
getMinor,
getPatch,
isCompatible: isVersion,
isGreaterThan,
isLessThanRange,
isSingleVersion: isVersion,
isStable,
isValid: isVersion,
isVersion,
matches,
maxSatisfyingVersion,
minSatisfyingVersion,
getNewValue,
sortVersions,
};
export default api;