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 { setupBrew } from "../brew"
import { testBin } from "../../utils/tests/test-helpers" import { testBin } from "../../utils/tests/test-helpers"
import { InstallationInfo } from "../../utils/setup/setupBin"
jest.setTimeout(200000) jest.setTimeout(200000)
describe("setup-brew", () => { describe("setup-brew", () => {
@ -7,7 +8,7 @@ describe("setup-brew", () => {
if (process.platform !== "darwin") { if (process.platform !== "darwin") {
return return
} }
setupBrew("", "", "") const installInfo = setupBrew("", "", "")
await testBin("brew") await testBin("brew", ["--version"], (installInfo as InstallationInfo | undefined)?.binDir)
}) })
}) })

View File

@ -1,18 +1,28 @@
import { execFileSync } from "child_process" import { execFileSync } from "child_process"
import which from "which" import which from "which"
let binDir: string | undefined
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
export function setupBrew(_version: string, _setupCppDir: string, _arch: string) { export function setupBrew(_version: string, _setupCppDir: string, _arch: string) {
if (!["darwin", "linux"].includes(process.platform)) { if (!["darwin", "linux"].includes(process.platform)) {
return return
} }
if (typeof binDir === "string") {
return { binDir }
}
if (which.sync("brew", { nothrow: true }) !== null) { const maybeBinDir = which.sync("brew", { nothrow: true })
return if (maybeBinDir !== null) {
binDir = maybeBinDir
return { binDir }
} }
// brew is not thread-safe // brew is not thread-safe
execFileSync(`/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"`, { execFileSync(`/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"`, {
stdio: "inherit", stdio: "inherit",
}) })
binDir = "/usr/local/bin/"
return { binDir }
} }