|
1 | 1 | import { execRootSync } from "admina" |
| 2 | +import { error } from "ci-log" |
2 | 3 | import { addPath } from "envosman" |
| 4 | +import { addExeExt } from "patha" |
3 | 5 | import { installAptPack } from "setup-apt" |
4 | 6 | import { rcOptions } from "../cli-options.js" |
5 | 7 | import { hasDnf } from "../utils/env/hasDnf.js" |
6 | 8 | import { isArch } from "../utils/env/isArch.js" |
7 | 9 | import { isUbuntu } from "../utils/env/isUbuntu.js" |
8 | 10 | import { ubuntuVersion } from "../utils/env/ubuntu_version.js" |
| 11 | +import { extractTarByExe, extractZip } from "../utils/setup/extract.js" |
| 12 | +import { type PackageInfo, setupBin } from "../utils/setup/setupBin.js" |
9 | 13 | import { setupBrewPack } from "../utils/setup/setupBrewPack.js" |
10 | 14 | import { setupChocoPack } from "../utils/setup/setupChocoPack.js" |
11 | 15 | import { setupDnfPack } from "../utils/setup/setupDnfPack.js" |
12 | 16 | import { setupPacmanPack } from "../utils/setup/setupPacmanPack.js" |
13 | 17 |
|
| 18 | +/** Get the platform data for cmake */ |
| 19 | +function getPowerShellPackageInfo(version: string, platform: NodeJS.Platform, arch: string): PackageInfo { |
| 20 | + const binFileName = addExeExt("pwsh") |
| 21 | + |
| 22 | + switch (platform) { |
| 23 | + case "win32": { |
| 24 | + const osArchStr = (["ia32", "x86", "i386", "x32"].includes(arch)) |
| 25 | + ? "win-x86" |
| 26 | + : "win-x64" |
| 27 | + |
| 28 | + return { |
| 29 | + binRelativeDir: "", |
| 30 | + binFileName, |
| 31 | + extractedFolderName: "", |
| 32 | + extractFunction: extractZip, |
| 33 | + url: |
| 34 | + `https://github.com/PowerShell/PowerShell/releases/download/v${version}/PowerShell-${version}-${osArchStr}.zip`, |
| 35 | + } |
| 36 | + } |
| 37 | + case "darwin": { |
| 38 | + const osArchStr = ["arm", "arm64"].includes(arch) ? "osx-arm64" : "osx-x64" |
| 39 | + |
| 40 | + return { |
| 41 | + binRelativeDir: "", |
| 42 | + binFileName, |
| 43 | + extractedFolderName: "", |
| 44 | + extractFunction: extractTarByExe, |
| 45 | + url: |
| 46 | + `https://github.com/PowerShell/PowerShell/releases/download/v${version}/powershell-${version}-${osArchStr}.tar.gz`, |
| 47 | + } |
| 48 | + } |
| 49 | + case "linux": { |
| 50 | + const archMap = { |
| 51 | + arm64: "linux-arm64", |
| 52 | + arm: "linux-arm64", |
| 53 | + arm32: "linux-arm32", |
| 54 | + aarch64: "linux-arm64", |
| 55 | + x64: "linux-x64", |
| 56 | + } as Record<string, string | undefined> |
| 57 | + const osArchStr = archMap[arch] ?? "linux-x64" |
| 58 | + // TODO support musl |
| 59 | + |
| 60 | + return { |
| 61 | + binRelativeDir: "", |
| 62 | + binFileName, |
| 63 | + extractedFolderName: "", |
| 64 | + extractFunction: extractTarByExe, |
| 65 | + url: |
| 66 | + `https://github.com/PowerShell/PowerShell/releases/download/v${version}/powershell-${version}-${osArchStr}.tar.gz`, |
| 67 | + } |
| 68 | + } |
| 69 | + default: |
| 70 | + throw new Error(`Unsupported platform '${platform}'`) |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +// eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 75 | +export async function setupPowershell(version: string, setupDir: string, arch: string) { |
| 76 | + try { |
| 77 | + return await setupBin("pwsh", version, getPowerShellPackageInfo, setupDir, arch) |
| 78 | + } catch (err) { |
| 79 | + error(`Failed to setup pwsh via download: ${err}. Trying package managers...`) |
| 80 | + return setupPowershellSystem(version, setupDir, arch) |
| 81 | + } |
| 82 | +} |
| 83 | + |
14 | 84 | // eslint-disable-next-line @typescript-eslint/no-unused-vars |
15 | | -export async function setupPowershell(version: string | undefined, _setupDir: string, _arch: string) { |
| 85 | +export async function setupPowershellSystem(version: string | undefined, _setupDir: string, _arch: string) { |
16 | 86 | switch (process.platform) { |
17 | 87 | case "win32": { |
18 | 88 | await setupChocoPack("powershell-core", version) |
|
0 commit comments