@@ -37,28 +37,27 @@ export const npm = {
37
37
38
38
// Run NPM to get the latest published version of the package
39
39
options . debug ( `Running command: npm view ${ name } version` , { command, env } ) ;
40
- let result : ezSpawn . Process < string > | Error ;
40
+ let result ;
41
+
41
42
try {
42
43
result = await ezSpawn . async ( command , { env } ) ;
43
44
}
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 ;
46
48
}
47
- // In case ezSpawn.async throws, it still has stdout and stderr properties.
48
- const { stdout, stderr } = result as ezSpawn . Process < string > ;
49
49
50
50
// 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" ) ) {
52
52
options . debug ( `The latest version of ${ name } is at v0.0.0, as it was never published.` ) ;
53
53
return new SemVer ( "0.0.0" ) ;
54
54
}
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 ;
59
58
}
60
59
61
- let version = stdout . trim ( ) ;
60
+ let version = result . stdout . trim ( ) ;
62
61
63
62
// Parse/validate the version number
64
63
let semver = new SemVer ( version ) ;
0 commit comments