@@ -37,28 +37,27 @@ export const npm = {
3737
3838 // Run NPM to get the latest published version of the package
3939 options . debug ( `Running command: npm view ${ name } version` , { command, env } ) ;
40- let result : ezSpawn . Process < string > | Error ;
40+ let result ;
41+
4142 try {
4243 result = await ezSpawn . async ( command , { env } ) ;
4344 }
44- catch ( e ) {
45- result = e as Error ;
45+ catch ( err ) {
46+ // In case ezSpawn.async throws, it still has stdout and stderr properties.
47+ result = err as ezSpawn . ProcessError ;
4648 }
47- // In case ezSpawn.async throws, it still has stdout and stderr properties.
48- const { stdout, stderr } = result as ezSpawn . Process < string > ;
4949
5050 // If the package was not previously published, return version 0.0.0.
51- if ( stderr && stderr . includes ( "E404" ) ) {
51+ if ( result . stderr && result . stderr . includes ( "E404" ) ) {
5252 options . debug ( `The latest version of ${ name } is at v0.0.0, as it was never published.` ) ;
5353 return new SemVer ( "0.0.0" ) ;
5454 }
55- else if ( stderr ) {
56- // Rethrow an error. See https://github.com/JS-DevTools/npm-publish/issues/14 for more details.
57- const error = result as Error ;
58- throw error ;
55+ else if ( result instanceof Error ) {
56+ // NPM failed for some reason
57+ throw result ;
5958 }
6059
61- let version = stdout . trim ( ) ;
60+ let version = result . stdout . trim ( ) ;
6261
6362 // Parse/validate the version number
6463 let semver = new SemVer ( version ) ;
0 commit comments