(
ws: WorkspaceClient,
command: string,
options: { cwd?: string; secretToRedact?: string } = {},
)
| 195 | } |
| 196 | |
| 197 | async function exec( |
| 198 | ws: WorkspaceClient, |
| 199 | command: string, |
| 200 | options: { cwd?: string; secretToRedact?: string } = {}, |
| 201 | ): Promise<string> { |
| 202 | const handle = await ws.runtime.exec(command, { cwd: options.cwd, encoding: "utf8" }); |
| 203 | try { |
| 204 | const result = await handle.result(); |
| 205 | if (result.exitCode === 0) return result.stdout; |
| 206 | |
| 207 | const raw = result.stderr || result.stdout || `exit code ${result.exitCode}`; |
| 208 | const output = options.secretToRedact |
| 209 | ? raw.replaceAll(options.secretToRedact, "<artifact-remote>") |
| 210 | : raw; |
| 211 | throw new Error(`command failed: ${output}`); |
| 212 | } finally { |
| 213 | handle[Symbol.dispose]?.(); |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | function parseJSON<T>(text: string): T { |
| 218 | return JSON.parse(text) as T; |
no test coverage detected