import semver from 'semver' ; import { Package } from '@verdaccio/types' ; import { DIST_TAGS } from './constants' ; return { Array } export function semverSort ( listVersions ) { return listVersions . filter ( function ( x ) : boolean { if ( ! semver . parse ( x , true ) ) { return false ; } return true ; } ) . sort ( semver . compareLoose ) . map ( String ) ; } param package export function getLatest ( pkg ) { const listVersions = Object . keys ( pkg . versions ) ; if ( listVersions . length < 1 ) { throw Error ( 'cannot get lastest version of none' ) ; } const versions = semverSort ( listVersions ) ; const latest = pkg [ DIST_TAGS ] ?. latest ? pkg [ DIST_TAGS ] . latest : versions [ 0 ] ; return latest ; } param { * } local param { * } upstream param { * } config export function mergeVersions ( local , upstream ) { for ( const i in upstream . versions ) { if ( typeof local . versions [ i ] === 'undefined' ) { local . versions [ i ] = upstream . versions [ i ] ; } } for ( const i in upstream [ DIST_TAGS ] ) { if ( local [ DIST_TAGS ] [ i ] !== upstream [ DIST_TAGS ] [ i ] ) { if ( ! local [ DIST_TAGS ] [ i ] || semver . lte ( local [ DIST_TAGS ] [ i ] , upstream [ DIST_TAGS ] [ i ] ) ) { local [ DIST_TAGS ] [ i ] = upstream [ DIST_TAGS ] [ i ] ; } if ( i === 'latest' && local [ DIST_TAGS ] [ i ] === upstream [ DIST_TAGS ] [ i ] ) { local . readme = upstream . readme ; } } } }