fix: fix brew path

This commit is contained in:
Amin Yahyaabadi 2021-09-16 14:54:04 -05:00
parent 5993d7b019
commit a6648a2296
2 changed files with 15 additions and 4 deletions

View File

@ -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)
})
})

View File

@ -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 }
}