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 = {
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 { 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 > ;
41
49
42
50
// If the package was not previously published, return version 0.0.0.
43
51
if ( stderr && stderr . includes ( "E404" ) ) {
44
52
options . debug ( `The latest version of ${ name } is at v0.0.0, as it was never published.` ) ;
45
53
return new SemVer ( "0.0.0" ) ;
46
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 ;
59
+ }
47
60
48
61
let version = stdout . trim ( ) ;
49
62
Original file line number Diff line number Diff line change @@ -63,7 +63,8 @@ describe("CLI - success tests", () => {
63
63
npm . mock ( {
64
64
args : [ "view" , "my-lib" , "version" ] ,
65
65
stdout : `${ EOL } ` ,
66
- stderr : `npm ERR! code E404${ EOL } `
66
+ stderr : `npm ERR! code E404${ EOL } ` ,
67
+ exitCode : 1 ,
67
68
} ) ;
68
69
69
70
npm . mock ( {
You can’t perform that action at this time.
0 commit comments