import * as childProcess from "child_process" ; import * as observableProcess from "observable-process" ; import { TRWorld } from "../world" ; import { makeFullPath } from "./make-full-path" ; /** Executes the given command in a subshell. */ export async function executeCLI ( command , expectError , world , opts = { } ) { const args = { } ; args . cwd = opts . cwd || world . workspace . platformified ( ) ; if ( world . debug ) { args . env = { DEBUG : "*,-babel" , PATH : process . env . PATH , } ; } const fullCommand = makeFullPath ( command , process . platform ) ; const runner = observableProcess . start ( fullCommand , args ) ; const runResult = ( await runner . waitForEnd ( ) ) as observableProcess . FinishedProcess ; if ( runResult . exitCode && ! expectError ) { console . log ( runner . output . fullText ( ) ) ; throw new Error ( `Expected success but got exit code: ${ runResult . exitCode }` ) ; } if ( expectError && ! runResult . exitCode ) { throw new Error ( "expected error but test succeeded" ) ; } return runResult ; }