diff --git a/src/utils/extension/extension.ts b/src/utils/extension/extension.ts new file mode 100644 index 00000000..33e0646d --- /dev/null +++ b/src/utils/extension/extension.ts @@ -0,0 +1,15 @@ +/** Add bin extension to a binary. This will be `.exe` on Windows. */ +export function addBinExtension(name: string) { + if (process.platform === "win32") { + return `${name}.exe` + } + return name +} + +/** Add native shell extension. This will be `.bat` on Windows and `sh` on unix. */ +export function addShellExtension(name: string) { + if (process.platform === "win32") { + return `${name}.bat` + } + return `${name}.sh` +} diff --git a/src/utils/setup/setupBin.ts b/src/utils/setup/setupBin.ts index d605d890..411c4773 100644 --- a/src/utils/setup/setupBin.ts +++ b/src/utils/setup/setupBin.ts @@ -89,10 +89,3 @@ export async function setupBin( return { installDir, binDir } } -/** Add bin extension to a binary. This will be `.exe` on Windows. */ -export function addBinExtension(name: string) { - if (process.platform === "win32") { - return `${name}.exe` - } - return name -} diff --git a/src/utils/tests/test-helpers.ts b/src/utils/tests/test-helpers.ts index eff0bb81..eef4da04 100644 --- a/src/utils/tests/test-helpers.ts +++ b/src/utils/tests/test-helpers.ts @@ -1,7 +1,7 @@ import * as io from "@actions/io" import { tmpdir } from "os" import * as path from "path" -import { addBinExtension } from "../setup/setupBin" +import { addBinExtension } from "../extension/extension" import { join } from "path" import spawn from "cross-spawn" diff --git a/src/vcpkg/vcpkg.ts b/src/vcpkg/vcpkg.ts index 7c70b3d2..868ad79f 100644 --- a/src/vcpkg/vcpkg.ts +++ b/src/vcpkg/vcpkg.ts @@ -3,6 +3,7 @@ import execa from "execa" import path from "path" import untildify from "untildify" import which from "which" +import { addShellExtension } from "../utils/extension/extension" import { InstallationInfo } from "../utils/setup/setupBin" let hasVCPKG = false @@ -12,7 +13,7 @@ export function setupVcpkg(_version: string, _setupCppDir: string, _arch: string if (!hasVCPKG || which.sync("vcpkg", { nothrow: true }) === null) { execa.sync("git", ["clone", "https://github.com/microsoft/vcpkg"], { cwd: untildify("~/") }) const vcpkgDir = untildify("~/vcpkg") - execa.sync("./vcpkg/bootstrap-vcpkg", { cwd: vcpkgDir, shell: true }) + execa.sync(addShellExtension("./vcpkg/bootstrap-vcpkg"), { cwd: vcpkgDir, shell: true }) addPath(vcpkgDir) hasVCPKG = true return { binDir: vcpkgDir }