import L from "lodash" ; import * as semverlib from "semver" ; /**
 * Wrap `semver` with support for understanding "latest"
 * - "latest" is both a version and a range
 * - "latest" range will match any valid version number
 * - "latest" version will only match "latest" version range
 **/ export type Version = semverlib . SemVer | "latest" ; export const latestTag = "latest" ; export const isLatest = ( v ) => v === latestTag ; export const valid = ( v ) => isLatest ( v ) ? latestTag : semverlib . valid ( v ) ; export const inc = ( v , release ) => isLatest ( v ) ? latestTag : semverlib . inc ( v , release ) ; export const prerelease = ( v ) => isLatest ( v ) ? [ ] : semverlib . prerelease ( v ) ; export const major = ( v ) => isLatest ( v ) ? latestTag : semverlib . major ( v ) ; export const minor = ( v ) => isLatest ( v ) ? latestTag : semverlib . minor ( v ) ; export const patch = ( v ) => isLatest ( v ) ? latestTag : semverlib . patch ( v ) ; export const eq = ( v1 , v2 ) => ( isLatest ( v1 ) && isLatest ( v2 ) ) || ( ! isLatest ( v1 ) && ! isLatest ( v2 ) && semverlib . eq ( v1 , v2 ) ) ; export const gt = ( v1 , v2 ) => ( isLatest ( v1 ) && ! isLatest ( v2 ) ) || ( ! isLatest ( v1 ) && ! isLatest ( v2 ) && semverlib . gt ( v1 , v2 ) ) ; export const lt = ( v1 , v2 ) => ( ! isLatest ( v1 ) && isLatest ( v2 ) ) || ( ! isLatest ( v1 ) && ! isLatest ( v2 ) && semverlib . lt ( v1 , v2 ) ) ; export const validRange = ( range ) => isLatest ( range ) ? latestTag : semverlib . validRange ( range ) ; export const satisfies = ( v , range ) => ( isLatest ( range ) && ! ! valid ( v ) ) || ( ! isLatest ( v ) && ! isLatest ( range ) && semverlib . satisfies ( v , range ) ) ; export const toTildeRange = ( v ) => isLatest ( v ) ? latestTag : ! ! semverlib . valid ( v ) ? "~" + v : null ; export const toCaretRange = ( v ) => isLatest ( v ) ? latestTag : ! ! semverlib . valid ( v ) ? "^" + v : null ; export const gte = ( v1 , v2 ) => eq ( v1 , v2 ) || gt ( v1 , v2 ) ; export const lte = ( v1 , v2 ) => eq ( v1 , v2 ) || lt ( v1 , v2 ) ; export const neq = ( v1 , v2 ) => ! eq ( v1 , v2 ) ; export const sortAsc = ( versions ) => L . cloneDeep ( versions ) . sort ( ( v1 , v2 ) => gt ( v1 , v2 ) ? + 1 : eq ( v1 , v2 ) ? 0 : - 1 ) ; export const sortDesc = ( versions ) => sortAsc ( versions ) . reverse ( ) ; export const minSatisfying = ( versions , range ) => sortAsc ( versions ) . find ( ( v ) => satisfies ( v , range ) ) ?? null ; export const maxSatisfying = ( versions , range ) => sortDesc ( versions ) . find ( ( v ) => satisfies ( v , range ) ) ?? null ; export const coerce = ( v ) => isLatest ( v ) ? latestTag : semverlib . coerce ( v ) ?. version ; export const gtr = ( version , range ) => ( isLatest ( version ) && ! isLatest ( range ) ) || ( ! isLatest ( version ) && ! isLatest ( range ) && semverlib . gtr ( version , range ) ) ; export const ltr = ( version , range ) => ( ! isLatest ( version ) && isLatest ( range ) ) || ( ! isLatest ( version ) && ! isLatest ( range ) && semverlib . ltr ( version , range ) ) ; export const outside = ( version , range , hilo ? ) => ( hilo === ">" && gtr ( version , range ) ) || ( hilo === "<" && ltr ( version , range ) ) || ( ! hilo && ( gtr ( version , range ) || ltr ( version , range ) ) ) ;