|
|
|
|
@@ -1,10 +1,18 @@
|
|
|
|
|
import { createRequire } from "module"
|
|
|
|
|
import { dirname, join } from "path"
|
|
|
|
|
import { existsSync } from "fs"
|
|
|
|
|
import { existsSync, statSync } from "fs"
|
|
|
|
|
import { getCachedBinaryPath } from "./downloader"
|
|
|
|
|
|
|
|
|
|
type Platform = "darwin" | "linux" | "win32" | "unsupported"
|
|
|
|
|
|
|
|
|
|
function isValidBinary(filePath: string): boolean {
|
|
|
|
|
try {
|
|
|
|
|
return statSync(filePath).size > 10000
|
|
|
|
|
} catch {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getPlatformPackageName(): string | null {
|
|
|
|
|
const platform = process.platform as Platform
|
|
|
|
|
const arch = process.arch
|
|
|
|
|
@@ -22,27 +30,9 @@ function getPlatformPackageName(): string | null {
|
|
|
|
|
return platformMap[`${platform}-${arch}`] ?? null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function isValidBinary(filePath: string): boolean {
|
|
|
|
|
try {
|
|
|
|
|
const stats = require("fs").statSync(filePath)
|
|
|
|
|
return stats.size > 10000
|
|
|
|
|
} catch {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function findSgCliPathSync(): string | null {
|
|
|
|
|
const binaryName = process.platform === "win32" ? "sg.exe" : "sg"
|
|
|
|
|
|
|
|
|
|
if (process.platform === "darwin") {
|
|
|
|
|
const homebrewPaths = ["/opt/homebrew/bin/sg", "/usr/local/bin/sg"]
|
|
|
|
|
for (const path of homebrewPaths) {
|
|
|
|
|
if (existsSync(path) && isValidBinary(path)) {
|
|
|
|
|
return path
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const cachedPath = getCachedBinaryPath()
|
|
|
|
|
if (cachedPath && isValidBinary(cachedPath)) {
|
|
|
|
|
return cachedPath
|
|
|
|
|
@@ -78,6 +68,15 @@ export function findSgCliPathSync(): string | null {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (process.platform === "darwin") {
|
|
|
|
|
const homebrewPaths = ["/opt/homebrew/bin/sg", "/usr/local/bin/sg"]
|
|
|
|
|
for (const path of homebrewPaths) {
|
|
|
|
|
if (existsSync(path) && isValidBinary(path)) {
|
|
|
|
|
return path
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|