openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
34 lines (33 loc) • 1.24 kB
JavaScript
import { c as resolveUserPath } from "./home-dir-BPhrG-aM.js";
import "./utils-P__uGsPB.js";
import { t as isSafeExecutableValue } from "./exec-safety-DtLGRBJm.js";
import { a as getWindowsSystem32ExePath } from "./windows-install-roots-BBaNTTOQ.js";
import { r as runCommandWithTimeout } from "./exec-BIE-3oLG.js";
import path from "node:path";
import fs from "node:fs/promises";
//#region src/infra/detect-binary.ts
/** Return true when a safe executable name/path can be found on this host. */
async function detectBinary(name) {
if (!name?.trim()) return false;
if (!isSafeExecutableValue(name)) return false;
const resolved = name.startsWith("~") ? resolveUserPath(name) : name;
if (path.isAbsolute(resolved) || resolved.startsWith(".") || resolved.includes("/") || resolved.includes("\\")) try {
await fs.access(resolved);
return true;
} catch {
return false;
}
const command = process.platform === "win32" ? [getWindowsSystem32ExePath("where.exe"), name] : [
"/usr/bin/env",
"which",
name
];
try {
const result = await runCommandWithTimeout(command, { timeoutMs: 2e3 });
return result.code === 0 && result.stdout.trim().length > 0;
} catch {
return false;
}
}
//#endregion
export { detectBinary as t };