Skip to content

Commit 6369ba1

Browse files
committed
Replace our exec with promisify(cp.exec)
Using the built-in is better because it includes stdout and stderr properties on the error which we will need when checking if the errors emitted by the CLI are authentication issues.
1 parent 29d9d8c commit 6369ba1

File tree

3 files changed

+3
-29
lines changed

3 files changed

+3
-29
lines changed

src/download.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import * as cp from "child_process"
22
import { promises as fs } from "fs"
33
import * as path from "path"
4+
import { promisify } from "util"
45
import * as vscode from "vscode"
56
import * as nodeWhich from "which"
67
import { requestResponse } from "./request"
7-
import { context, debug, exec, extractTar, extractZip, getAssetUrl, onLine, outputChannel, wrapExit } from "./utils"
8+
import { context, debug, extractTar, extractZip, getAssetUrl, onLine, outputChannel, wrapExit } from "./utils"
89

910
/**
1011
* Return "true" if the binary is found in $PATH.
@@ -22,7 +23,7 @@ export const binaryExists = async (bin: string): Promise<boolean> => {
2223
export const execCoder = async (command: string): Promise<string> => {
2324
debug(`Run command: ${command}`)
2425
const coderBinary = await preflight()
25-
const output = await exec(coderBinary + " " + command)
26+
const output = await promisify(cp.exec)(coderBinary + " " + command)
2627
return output.stdout
2728
}
2829

src/utils.test.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,6 @@ import * as utils from "./utils"
88
suite("Utils", () => {
99
vscode.window.showInformationMessage("Start util tests.")
1010

11-
test("exec", async () => {
12-
assert.deepStrictEqual(await utils.exec("printf stdout"), {
13-
stdout: "stdout",
14-
stderr: "",
15-
})
16-
assert.deepStrictEqual(await utils.exec(">&2 printf stderr"), {
17-
stdout: "",
18-
stderr: "stderr",
19-
})
20-
await assert.rejects(utils.exec("false"), {
21-
name: "Error",
22-
message: "Command failed: false\n",
23-
})
24-
})
25-
2611
suiteSetup(() => {
2712
// Cleanup anything left over from the last run.
2813
utils.clean("tests/utils")

src/utils.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,6 @@ export const context = (ctx?: vscode.ExtensionContext): vscode.ExtensionContext
3232
return _context
3333
}
3434

35-
/**
36-
* Run a command and get its stdout and stderr on completion.
37-
*
38-
* Use for short-running processes where you need the full output before you can
39-
* continue.
40-
*/
41-
export const exec = async (command: string): Promise<{ stdout: string; stderr: string }> => {
42-
return new Promise((res, rej) => {
43-
cp.exec(command, (err, stdout, stderr) => (err ? rej(err) : res({ stdout, stderr })))
44-
})
45-
}
46-
4735
/**
4836
* Split a string up to the delimiter. If the delimiter does not exist the
4937
* first item will have all the text and the second item will be an empty

0 commit comments

Comments
 (0)