* Exec a tool. * Output will be streamed to the live console. * Returns promise with return code * * @param tool path to tool to exec * @param options optional exec options. See ExecOptions * @returns number
()
| 2122 | * @returns number |
| 2123 | */ |
| 2124 | exec() { |
| 2125 | return __awaiter(this, void 0, void 0, function* () { |
| 2126 | // root the tool path if it is unrooted and contains relative pathing |
| 2127 | if (!ioUtil.isRooted(this.toolPath) && |
| 2128 | (this.toolPath.includes('/') || |
| 2129 | (IS_WINDOWS && this.toolPath.includes('\\')))) { |
| 2130 | // prefer options.cwd if it is specified, however options.cwd may also need to be rooted |
| 2131 | this.toolPath = path.resolve(process.cwd(), this.options.cwd || process.cwd(), this.toolPath); |
| 2132 | } |
| 2133 | // if the tool is only a file name, then resolve it from the PATH |
| 2134 | // otherwise verify it exists (add extension on Windows if necessary) |
| 2135 | this.toolPath = yield io.which(this.toolPath, true); |
| 2136 | return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () { |
| 2137 | this._debug(`exec tool: ${this.toolPath}`); |
| 2138 | this._debug('arguments:'); |
| 2139 | for (const arg of this.args) { |
| 2140 | this._debug(` ${arg}`); |
| 2141 | } |
| 2142 | const optionsNonNull = this._cloneExecOptions(this.options); |
| 2143 | if (!optionsNonNull.silent && optionsNonNull.outStream) { |
| 2144 | optionsNonNull.outStream.write(this._getCommandString(optionsNonNull) + os.EOL); |
| 2145 | } |
| 2146 | const state = new ExecState(optionsNonNull, this.toolPath); |
| 2147 | state.on('debug', (message) => { |
| 2148 | this._debug(message); |
| 2149 | }); |
| 2150 | if (this.options.cwd && !(yield ioUtil.exists(this.options.cwd))) { |
| 2151 | return reject(new Error(`The cwd: ${this.options.cwd} does not exist!`)); |
| 2152 | } |
| 2153 | const fileName = this._getSpawnFileName(); |
| 2154 | const cp = child.spawn(fileName, this._getSpawnArgs(optionsNonNull), this._getSpawnOptions(this.options, fileName)); |
| 2155 | let stdbuffer = ''; |
| 2156 | if (cp.stdout) { |
| 2157 | cp.stdout.on('data', (data) => { |
| 2158 | if (this.options.listeners && this.options.listeners.stdout) { |
| 2159 | this.options.listeners.stdout(data); |
| 2160 | } |
| 2161 | if (!optionsNonNull.silent && optionsNonNull.outStream) { |
| 2162 | optionsNonNull.outStream.write(data); |
| 2163 | } |
| 2164 | stdbuffer = this._processLineBuffer(data, stdbuffer, (line) => { |
| 2165 | if (this.options.listeners && this.options.listeners.stdline) { |
| 2166 | this.options.listeners.stdline(line); |
| 2167 | } |
| 2168 | }); |
| 2169 | }); |
| 2170 | } |
| 2171 | let errbuffer = ''; |
| 2172 | if (cp.stderr) { |
| 2173 | cp.stderr.on('data', (data) => { |
| 2174 | state.processStderr = true; |
| 2175 | if (this.options.listeners && this.options.listeners.stderr) { |
| 2176 | this.options.listeners.stderr(data); |
| 2177 | } |
| 2178 | if (!optionsNonNull.silent && |
| 2179 | optionsNonNull.errStream && |
| 2180 | optionsNonNull.outStream) { |
| 2181 | const s = optionsNonNull.failOnStdErr |
no test coverage detected