import { execFileTracked } from "../../processes.js";
const stripAnsi = (value) => value.replace(/\u001b\[[0-9;]*m/g, "");
export function execTweetCli(binary, args, timeoutMs, env) {
    return new Promise((resolve, reject) => {
        const toText = (value) => typeof value === "string" ? value : value ? value.toString("utf8") : "";
        execFileTracked(binary, args, {
            timeout: timeoutMs,
            env: { ...process.env, ...env },
            maxBuffer: 1024 * 1024,
        }, (error, stdout, stderr) => {
            const stdoutText = toText(stdout).trim();
            const stderrText = stripAnsi(toText(stderr)).trim();
            if (error) {
                const detail = stderrText || stdoutText;
                const suffix = detail ? `: ${detail}` : "";
                reject(new Error(`${binary} read failed${suffix}`));
                return;
            }
            resolve(stdoutText);
        });
    });
}
//# sourceMappingURL=exec.js.map