@@ -14,11 +14,21 @@ const logger = getDefaultLogger()
1414 * @returns {Promise<number> } Exit code
1515 */
1616export async function runCommand ( command , args = [ ] , options = { } ) {
17- const result = await spawn ( command , args , {
18- stdio : 'inherit' ,
19- ...options ,
20- } )
21- return result . code
17+ try {
18+ const result = await spawn ( command , args , {
19+ stdio : 'inherit' ,
20+ ...( process . platform === 'win32' && { shell : true } ) ,
21+ ...options ,
22+ } )
23+ return result . code
24+ } catch ( error ) {
25+ // spawn() from @socketsecurity/lib throws on non-zero exit
26+ // Return the exit code from the error
27+ if ( error && typeof error === 'object' && 'code' in error ) {
28+ return error . code
29+ }
30+ throw error
31+ }
2232}
2333
2434/**
@@ -75,23 +85,43 @@ export async function runParallel(commands) {
7585}
7686
7787/**
78- * Run a command and capture output.
88+ * Run a command and suppress output.
7989 * @param {string } command - The command to run
8090 * @param {string[] } args - Arguments to pass to the command
8191 * @param {object } options - Spawn options
8292 * @returns {Promise<{exitCode: number, stdout: string, stderr: string}> }
8393 */
8494export async function runCommandQuiet ( command , args = [ ] , options = { } ) {
85- const result = await spawn ( command , args , {
86- ...options ,
87- stdio : [ 'inherit' , 'pipe' , 'pipe' ] ,
88- stdioString : true ,
89- } )
95+ try {
96+ const result = await spawn ( command , args , {
97+ ...options ,
98+ ...( process . platform === 'win32' && { shell : true } ) ,
99+ stdio : 'pipe' ,
100+ stdioString : true ,
101+ } )
90102
91- return {
92- exitCode : result . code ,
93- stderr : result . stderr ,
94- stdout : result . stdout ,
103+ return {
104+ exitCode : result . code ,
105+ stderr : result . stderr ,
106+ stdout : result . stdout ,
107+ }
108+ } catch ( error ) {
109+ // spawn() from @socketsecurity/lib throws on non-zero exit
110+ // Return the exit code and output from the error
111+ if (
112+ error &&
113+ typeof error === 'object' &&
114+ 'code' in error &&
115+ 'stdout' in error &&
116+ 'stderr' in error
117+ ) {
118+ return {
119+ exitCode : error . code ,
120+ stderr : error . stderr ,
121+ stdout : error . stdout ,
122+ }
123+ }
124+ throw error
95125 }
96126}
97127
0 commit comments