@@ -62,10 +62,14 @@ async function findPackagesWithDependency(depName: string): Promise<PackageWithD
6262 return packagesWithDep ;
6363}
6464
65- async function getLatestVersion ( packageName : string ) : Promise < string > {
65+ async function getLatestVersion ( packageName : string , versionPrefix ?: string ) : Promise < string > {
6666 console . log ( `Fetching latest version for ${ packageName } ...` ) ;
6767 const { stdout } = await execa ( 'npm' , [ 'view' , packageName , 'version' ] ) ;
68- return stdout . trim ( ) ;
68+ const version = stdout . trim ( ) ;
69+ if ( versionPrefix ) {
70+ return version . startsWith ( versionPrefix ) ? version : `${ versionPrefix } ${ version } ` ;
71+ }
72+ return version ;
6973}
7074
7175async function updatePackageJson (
@@ -92,7 +96,12 @@ async function runYarnInstall(): Promise<void> {
9296 } ) ;
9397}
9498
95- async function cmdUpgrade ( opts : { package : string ; version ?: string ; dryRun : boolean } ) : Promise < void > {
99+ async function cmdUpgrade ( opts : {
100+ package : string ;
101+ version ?: string ;
102+ versionPrefix ?: string ;
103+ dryRun : boolean ;
104+ } ) : Promise < void > {
96105 const { package : depName , version : targetVersion , dryRun } = opts ;
97106
98107 console . log ( `\n🔍 Searching for packages with dependency: ${ depName } \n` ) ;
@@ -114,7 +123,7 @@ async function cmdUpgrade(opts: { package: string; version?: string; dryRun: boo
114123 newVersion = targetVersion ;
115124 console . log ( `\n📦 Target version: ${ newVersion } ` ) ;
116125 } else {
117- newVersion = await getLatestVersion ( depName ) ;
126+ newVersion = await getLatestVersion ( depName , opts . versionPrefix ?? '' ) ;
118127 console . log ( `\n📦 Latest version: ${ newVersion } ` ) ;
119128 }
120129
@@ -158,6 +167,11 @@ yargs
158167 describe : 'Target version (defaults to latest from npm registry)' ,
159168 alias : 'v' ,
160169 } ,
170+ versionPrefix : {
171+ type : 'string' ,
172+ describe : 'Version prefix to use when getting latest version' ,
173+ default : '^' ,
174+ } ,
161175 dryRun : {
162176 type : 'boolean' ,
163177 default : false ,
0 commit comments