@@ -2,10 +2,7 @@ import dns from 'node:dns/promises';
22import { existsSync } from 'node:fs' ;
33import { readFile } from 'node:fs/promises' ;
44import { color } from '@astrojs/cli-kit' ;
5- import semverCoerce from 'semver/functions/coerce.js' ;
6- import semverDiff from 'semver/functions/diff.js' ;
7- import semverGt from 'semver/functions/gt.js' ;
8- import semverParse from 'semver/functions/parse.js' ;
5+ import { coerce , difference , isGreater , tryParse } from 'verkit' ;
96import { bannerAbort , error , getRegistry , info , newline } from '../messages.js' ;
107import type { Context , PackageInfo } from './context.js' ;
118
@@ -81,7 +78,7 @@ function isAllowedPackage(name: string, _version: string) {
8178}
8279
8380function isValidVersion ( _name : string , version : string ) {
84- return semverCoerce ( version , { loose : true } ) !== null ;
81+ return coerce ( version , { loose : true } ) !== null ;
8582}
8683
8784function isSupportedPackage ( name : string , version : string ) : boolean {
@@ -149,10 +146,10 @@ export async function resolveTargetVersion(
149146 const { 'dist-tags' : distTags } = await packageMetadata . json ( ) ;
150147 let version = distTags [ packageInfo . targetVersion ] ;
151148 if ( version ) {
152- const currentCoerced = semverCoerce ( packageInfo . currentVersion ) ;
153- const targetParsed = semverParse ( version ) ;
149+ const currentCoerced = coerce ( packageInfo . currentVersion ) ;
150+ const targetParsed = tryParse ( version ) ;
154151 // If the dist-tag points to a version older than the installed one, fall back to latest.
155- if ( currentCoerced && targetParsed && semverGt ( currentCoerced , targetParsed ) ) {
152+ if ( currentCoerced && targetParsed && isGreater ( currentCoerced , targetParsed ) ) {
156153 packageInfo . targetVersion = 'latest' ;
157154 version = distTags . latest ;
158155 } else {
@@ -168,10 +165,10 @@ export async function resolveTargetVersion(
168165 }
169166 const prefix = packageInfo . targetVersion === 'latest' ? '^' : '' ;
170167 packageInfo . targetVersion = `${ prefix } ${ version } ` ;
171- const fromVersion = semverCoerce ( packageInfo . currentVersion ) ! ;
172- const toVersion = semverParse ( version ) ! ;
173- const bump = semverDiff ( fromVersion , toVersion ) ;
174- if ( ( bump === 'major' && toVersion . prerelease . length === 0 ) || bump === 'premajor' ) {
168+ const fromVersion = coerce ( packageInfo . currentVersion ) ! ;
169+ const toVersion = tryParse ( version ) ! ;
170+ const bump = difference ( fromVersion , toVersion ) ;
171+ if ( ( bump === 'major' && ( toVersion . prerelease ? .length ?? 0 ) === 0 ) || bump === 'premajor' ) {
175172 packageInfo . isMajor = true ;
176173 if ( packageInfo . name === 'astro' ) {
177174 const upgradeGuide = `https://docs.astro.build/en/guides/upgrade-to/v${ toVersion . major } /` ;
0 commit comments