File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed
Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -37,13 +37,26 @@ 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 { stdout, stderr } = await ezSpawn . async ( command , { env } ) ;
40+ let result : ezSpawn . Process < string > | Error ;
41+ try {
42+ result = await ezSpawn . async ( command , { env } ) ;
43+ }
44+ catch ( e ) {
45+ result = e as Error ;
46+ }
47+ // In case ezSpawn.async throws, it still has stdout and stderr properties.
48+ const { stdout, stderr } = result as ezSpawn . Process < string > ;
4149
4250 // If the package was not previously published, return version 0.0.0.
4351 if ( stderr && stderr . includes ( "E404" ) ) {
4452 options . debug ( `The latest version of ${ name } is at v0.0.0, as it was never published.` ) ;
4553 return new SemVer ( "0.0.0" ) ;
4654 }
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 ;
59+ }
4760
4861 let version = stdout . trim ( ) ;
4962
Original file line number Diff line number Diff line change @@ -63,7 +63,8 @@ describe("CLI - success tests", () => {
6363 npm . mock ( {
6464 args : [ "view" , "my-lib" , "version" ] ,
6565 stdout : `${ EOL } ` ,
66- stderr : `npm ERR! code E404${ EOL } `
66+ stderr : `npm ERR! code E404${ EOL } ` ,
67+ exitCode : 1 ,
6768 } ) ;
6869
6970 npm . mock ( {
You can’t perform that action at this time.
0 commit comments