import * as child from 'child_process' ; import * as shlex from 'shlex' ; /**
 * Options for the `run` function.
 */ export interface RunOptions { default readonly cwd ? : string ; default readonly capture ? : boolean ; default readonly shell ? : boolean ; } param command export function run ( command , options = { } ) { const shsplit = shlex . split ( command ) ; const pipeOrInherit = ( options . capture ?? false ) ? 'pipe' : 'inherit' ; const result = child . spawnSync ( shsplit [ 0 ] , shsplit . slice ( 1 ) , { stdio : [ 'ignore' , pipeOrInherit , pipeOrInherit ] , cwd : options . cwd , shell : options . shell , } ) ; if ( result . error ) { throw result . error ; } const stdout = result . stdout ?. toString ( ) ; const stderr = result . stderr ?. toString ( ) ; if ( result . status !== 0 ) { const message = `
    Command failed: ${ command }.
      Output: ${ stdout }
      Error:${ stderr }` ; throw new Error ( message ) ; } return stdout ; } param program export function which ( program ) { try { return run ( `which ${ program }` , { capture : true } ) ; } catch ( err ) { return '' ; } }