diff --git a/src/brew/__tests__/brew.test.ts b/src/brew/__tests__/brew.test.ts index 23aeffb1..6896c36f 100644 --- a/src/brew/__tests__/brew.test.ts +++ b/src/brew/__tests__/brew.test.ts @@ -1,5 +1,6 @@ import { setupBrew } from "../brew" import { testBin } from "../../utils/tests/test-helpers" +import { InstallationInfo } from "../../utils/setup/setupBin" jest.setTimeout(200000) describe("setup-brew", () => { @@ -7,7 +8,7 @@ describe("setup-brew", () => { if (process.platform !== "darwin") { return } - setupBrew("", "", "") - await testBin("brew") + const installInfo = setupBrew("", "", "") + await testBin("brew", ["--version"], (installInfo as InstallationInfo | undefined)?.binDir) }) }) diff --git a/src/brew/brew.ts b/src/brew/brew.ts index d67cbcaf..feb79bf3 100644 --- a/src/brew/brew.ts +++ b/src/brew/brew.ts @@ -1,18 +1,28 @@ import { execFileSync } from "child_process" import which from "which" +let binDir: string | undefined + // eslint-disable-next-line @typescript-eslint/no-unused-vars export function setupBrew(_version: string, _setupCppDir: string, _arch: string) { if (!["darwin", "linux"].includes(process.platform)) { return } + if (typeof binDir === "string") { + return { binDir } + } - if (which.sync("brew", { nothrow: true }) !== null) { - return + const maybeBinDir = which.sync("brew", { nothrow: true }) + if (maybeBinDir !== null) { + binDir = maybeBinDir + return { binDir } } // brew is not thread-safe execFileSync(`/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"`, { stdio: "inherit", }) + binDir = "/usr/local/bin/" + + return { binDir } }