openai/codex-action

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
pr19

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/which.ts

32lines · modeblame

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