openai/codex-action

Public

mirrored from https://github.com/openai/codex-actionAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
pr20

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/which.ts

32lines · modecode

1import { spawn } from "child_process";
2
3export function which(command: string): Promise<string | null> {
4 return new Promise<string>((resolve, reject) => {
5 const which = spawn("which", [command], {
6 env: process.env,
7 stdio: ["ignore", "pipe", "inherit"],
8 });
9
10 which.on("error", reject);
11
12 let output = "";
13 which.stdout.on("data", (chunk) => {
14 output += chunk.toString();
15 });
16
17 which.on("close", (code) => {
18 if (code !== 0) {
19 reject(new Error(`which exited with code ${code}`));
20 return;
21 }
22
23 const path = output.trim();
24 if (path === "") {
25 reject(new Error("could not find 'codex' in PATH"));
26 return;
27 }
28
29 resolve(path);
30 });
31 });
32}