From a02735d0d69b2eadb2773d66ddf6de8bfe49a413 Mon Sep 17 00:00:00 2001 From: Luke Tomlinson Date: Thu, 6 May 2021 17:30:09 -0400 Subject: [PATCH] Formatting --- packages/exec/src/toolrunner.ts | 216 ++++++++++++++++---------------- 1 file changed, 109 insertions(+), 107 deletions(-) diff --git a/packages/exec/src/toolrunner.ts b/packages/exec/src/toolrunner.ts index cdfcc57cdb..4fe2d9e4e0 100644 --- a/packages/exec/src/toolrunner.ts +++ b/packages/exec/src/toolrunner.ts @@ -415,134 +415,136 @@ export class ToolRunner extends events.EventEmitter { this.toolPath = await io.which(this.toolPath, true) return new Promise(async (resolve, reject) => { - this._debug(`exec tool: ${this.toolPath}`) - this._debug('arguments:') - for (const arg of this.args) { - this._debug(` ${arg}`) - } - - this.on('error', (error: Error) => { - reject(error) - }) - + this._debug(`exec tool: ${this.toolPath}`) + this._debug('arguments:') + for (const arg of this.args) { + this._debug(` ${arg}`) + } - const optionsNonNull = this._cloneExecOptions(this.options) - if (!optionsNonNull.silent && optionsNonNull.outStream) { - optionsNonNull.outStream.write( - this._getCommandString(optionsNonNull) + os.EOL - ) - } + this.on('error', (error: Error) => { + reject(error) + }) - const state = new ExecState(optionsNonNull, this.toolPath) - state.on('debug', (message: string) => { - this._debug(message) - }) + const optionsNonNull = this._cloneExecOptions(this.options) + if (!optionsNonNull.silent && optionsNonNull.outStream) { + optionsNonNull.outStream.write( + this._getCommandString(optionsNonNull) + os.EOL + ) + } - if (this.options.cwd && !(await ioUtil.exists(this.options.cwd))) { - this.emit('error', new Error(`The cwd: ${this.options.cwd} does not exist!`)) - return - } + const state = new ExecState(optionsNonNull, this.toolPath) + state.on('debug', (message: string) => { + this._debug(message) + }) - const fileName = this._getSpawnFileName() - const cp = child.spawn( - fileName, - this._getSpawnArgs(optionsNonNull), - this._getSpawnOptions(this.options, fileName) + if (this.options.cwd && !(await ioUtil.exists(this.options.cwd))) { + this.emit( + 'error', + new Error(`The cwd: ${this.options.cwd} does not exist!`) ) + return + } - const stdbuffer = '' - if (cp.stdout) { - cp.stdout.on('data', (data: Buffer) => { - if (this.options.listeners && this.options.listeners.stdout) { - this.options.listeners.stdout(data) - } - - if (!optionsNonNull.silent && optionsNonNull.outStream) { - optionsNonNull.outStream.write(data) - } + const fileName = this._getSpawnFileName() + const cp = child.spawn( + fileName, + this._getSpawnArgs(optionsNonNull), + this._getSpawnOptions(this.options, fileName) + ) - this._processLineBuffer(data, stdbuffer, (line: string) => { - if (this.options.listeners && this.options.listeners.stdline) { - this.options.listeners.stdline(line) - } - }) - }) - } + const stdbuffer = '' + if (cp.stdout) { + cp.stdout.on('data', (data: Buffer) => { + if (this.options.listeners && this.options.listeners.stdout) { + this.options.listeners.stdout(data) + } - const errbuffer = '' - if (cp.stderr) { - cp.stderr.on('data', (data: Buffer) => { - state.processStderr = true - if (this.options.listeners && this.options.listeners.stderr) { - this.options.listeners.stderr(data) - } + if (!optionsNonNull.silent && optionsNonNull.outStream) { + optionsNonNull.outStream.write(data) + } - if ( - !optionsNonNull.silent && - optionsNonNull.errStream && - optionsNonNull.outStream - ) { - const s = optionsNonNull.failOnStdErr - ? optionsNonNull.errStream - : optionsNonNull.outStream - s.write(data) + this._processLineBuffer(data, stdbuffer, (line: string) => { + if (this.options.listeners && this.options.listeners.stdline) { + this.options.listeners.stdline(line) } - - this._processLineBuffer(data, errbuffer, (line: string) => { - if (this.options.listeners && this.options.listeners.errline) { - this.options.listeners.errline(line) - } - }) }) - } - - cp.on('error', (err: Error) => { - state.processError = err.message - state.processExited = true - state.processClosed = true - state.CheckComplete() - }) - - cp.on('exit', (code: number) => { - state.processExitCode = code - state.processExited = true - this._debug(`Exit code ${code} received from tool '${this.toolPath}'`) - state.CheckComplete() - }) - - cp.on('close', (code: number) => { - state.processExitCode = code - state.processExited = true - state.processClosed = true - this._debug(`STDIO streams have closed for tool '${this.toolPath}'`) - state.CheckComplete() }) + } - state.on('done', (error: Error, exitCode: number) => { - if (stdbuffer.length > 0) { - this.emit('stdline', stdbuffer) + const errbuffer = '' + if (cp.stderr) { + cp.stderr.on('data', (data: Buffer) => { + state.processStderr = true + if (this.options.listeners && this.options.listeners.stderr) { + this.options.listeners.stderr(data) } - if (errbuffer.length > 0) { - this.emit('errline', errbuffer) + if ( + !optionsNonNull.silent && + optionsNonNull.errStream && + optionsNonNull.outStream + ) { + const s = optionsNonNull.failOnStdErr + ? optionsNonNull.errStream + : optionsNonNull.outStream + s.write(data) } - cp.removeAllListeners() - - if (error) { - reject(error) - } else { - resolve(exitCode) - } + this._processLineBuffer(data, errbuffer, (line: string) => { + if (this.options.listeners && this.options.listeners.errline) { + this.options.listeners.errline(line) + } + }) }) + } - if (this.options.input) { - if (!cp.stdin) { - throw new Error('child process missing stdin') - } + cp.on('error', (err: Error) => { + state.processError = err.message + state.processExited = true + state.processClosed = true + state.CheckComplete() + }) + + cp.on('exit', (code: number) => { + state.processExitCode = code + state.processExited = true + this._debug(`Exit code ${code} received from tool '${this.toolPath}'`) + state.CheckComplete() + }) + + cp.on('close', (code: number) => { + state.processExitCode = code + state.processExited = true + state.processClosed = true + this._debug(`STDIO streams have closed for tool '${this.toolPath}'`) + state.CheckComplete() + }) + + state.on('done', (error: Error, exitCode: number) => { + if (stdbuffer.length > 0) { + this.emit('stdline', stdbuffer) + } + + if (errbuffer.length > 0) { + this.emit('errline', errbuffer) + } + + cp.removeAllListeners() - cp.stdin.end(this.options.input) + if (error) { + reject(error) + } else { + resolve(exitCode) + } + }) + + if (this.options.input) { + if (!cp.stdin) { + throw new Error('child process missing stdin') } + + cp.stdin.end(this.options.input) + } }) } }