Skip to content

Commit 4d945cd

Browse files
committed
Use Bun shell chaining correctly in command helpers
1 parent 0cb83d0 commit 4d945cd

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

scripts/lib/common.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,21 @@ export function yamlStringify(value: unknown): string {
5353

5454
type CommandOptions = { cwd?: string; stdin?: string | Uint8Array };
5555

56+
async function shellCommand(cmd: string[], options: CommandOptions = {}) {
57+
const proc = $`${cmd}`.quiet().nothrow();
58+
if (options.cwd) {
59+
proc.cwd(options.cwd);
60+
}
61+
if (options.stdin !== undefined) {
62+
const writer = proc.stdin.getWriter();
63+
await writer.write(typeof options.stdin === "string" ? new TextEncoder().encode(options.stdin) : options.stdin);
64+
await writer.close();
65+
}
66+
return await proc;
67+
}
68+
5669
export async function runText(cmd: string[], prefix: string, options: CommandOptions = {}): Promise<string> {
57-
const proc = await $({ cwd: options.cwd, stdin: options.stdin, stdout: "pipe", stderr: "pipe" })`${cmd}`.nothrow().quiet();
70+
const proc = await shellCommand(cmd, options);
5871
if (proc.exitCode !== 0) {
5972
const stderr = proc.stderr.toString().trim();
6073
const rendered = stderr || `command failed: ${cmd.join(" ")}`;
@@ -72,7 +85,7 @@ export async function runAllowFailure(
7285
cmd: string[],
7386
options: CommandOptions = {}
7487
): Promise<{ exitCode: number; stdout: string; stderr: string }> {
75-
const proc = await $({ cwd: options.cwd, stdin: options.stdin, stdout: "pipe", stderr: "pipe" })`${cmd}`.nothrow().quiet();
88+
const proc = await shellCommand(cmd, options);
7689
return {
7790
exitCode: proc.exitCode,
7891
stdout: proc.stdout.toString(),

0 commit comments

Comments
 (0)