import { spawnSync } from "node:child_process";
import { existsSync, statSync } from "node:fs";
import { homedir } from "node:os";
function binaryInPath(name) {
  const isWin = process.platform === "win32";
  const cmd = isWin ? "where" : "which";
  try {
    const r = spawnSync(cmd, [name], { encoding: "utf-8", timeout: 3e3 });
    if (r.error || r.status !== 0) return null;
    const first = (r.stdout || "").split(/\r?\n/).map((s) => s.trim()).find((s) => s.length > 0);
    return first ?? null;
  } catch {
    return null;
  }
}
function dirExists(path) {
  try {
    if (!existsSync(path)) return false;
    return statSync(path).isDirectory();
  } catch {
    return false;
  }
}
function fileExists(path) {
  try {
    if (!existsSync(path)) return false;
    return statSync(path).isFile();
  } catch {
    return false;
  }
}
function getHome() {
  return homedir();
}
function getCwd() {
  return process.cwd();
}
export {
  binaryInPath,
  dirExists,
  fileExists,
  getCwd,
  getHome
};
//# sourceMappingURL=detect-helpers.js.map