openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
50 lines (49 loc) • 2.04 kB
JavaScript
import { n as canAccessSync } from "./path-existence-Co7-GyVr.mjs";
import fs from "node:fs";
import path from "node:path";
import os from "node:os";
//#region src/infra/brew.ts
/** Returns standard Homebrew bin directories suitable for PATH augmentation. */
function resolveBrewPathDirs(e) {
const t = e?.homeDir ?? os.homedir();
return [
path.join(t, ".linuxbrew", "bin"),
path.join(t, ".linuxbrew", "sbin"),
"/home/linuxbrew/.linuxbrew/bin",
"/home/linuxbrew/.linuxbrew/sbin",
"/opt/homebrew/bin",
"/usr/local/bin"
];
}
/** Resolves an executable `brew` path from trusted PATH entries or standard install roots. */
function resolveBrewExecutable(e) {
const t = e?.homeDir ?? os.homedir();
for (const e of (process.env.PATH ?? "").split(path.delimiter)) {
const t = e.trim();
if (!t || !path.isAbsolute(t)) continue;
const n = path.join(t, "brew");
if (canAccessSync(n, fs.constants.X_OK)) return n;
}
return [
path.join(t, ".linuxbrew", "bin", "brew"),
"/home/linuxbrew/.linuxbrew/bin/brew",
"/opt/homebrew/bin/brew",
"/usr/local/bin/brew"
].find((e) => canAccessSync(e, fs.constants.X_OK));
}
/** Recognize formula-owned OpenClaw files and keep service paths independent of the keg version. */
async function resolveBrewOpenClawPath(e) {
const t = /^(.*)\/(?:Cellar\/openclaw-cli\/[^/]+|opt\/openclaw-cli)(\/libexec(?:\/.*)?)$/u.exec(e);
if (!t || process.platform === "win32") return null;
const [, n, r] = t;
if (![process.env.HOMEBREW_PREFIX, ...resolveBrewPathDirs().map((e) => path.dirname(e))].some((e) => e && path.isAbsolute(e) && path.resolve(e) === n)) {
const e = resolveBrewExecutable();
if (!e) return null;
const { runCommandWithTimeout: t } = await import("./exec-Df6gUJ1h.mjs");
const r = await t([e, "--prefix"], { timeoutMs: 5e3 }).catch(() => null);
if (r?.code !== 0 || r.stdout.trim() !== n) return null;
}
return path.join(n, "opt", "openclaw-cli", r);
}
//#endregion
export { resolveBrewOpenClawPath as n, resolveBrewPathDirs as r, resolveBrewExecutable as t };