fix(shell): prefer PowerShell 7 on Windows with tested fallbacks (#25684)

This commit is contained in:
Peter Steinberger
2026-02-25 01:49:33 +00:00
parent bf5a96ad63
commit fa525bf212
3 changed files with 118 additions and 3 deletions

View File

@@ -2,7 +2,27 @@ import { spawn } from "node:child_process";
import fs from "node:fs";
import path from "node:path";
function resolvePowerShellPath(): string {
export function resolvePowerShellPath(): string {
// Prefer PowerShell 7 when available; PS 5.1 lacks "&&" support.
const programFiles = process.env.ProgramFiles || process.env.PROGRAMFILES || "C:\\Program Files";
const pwsh7 = path.join(programFiles, "PowerShell", "7", "pwsh.exe");
if (fs.existsSync(pwsh7)) {
return pwsh7;
}
const programW6432 = process.env.ProgramW6432;
if (programW6432 && programW6432 !== programFiles) {
const pwsh7Alt = path.join(programW6432, "PowerShell", "7", "pwsh.exe");
if (fs.existsSync(pwsh7Alt)) {
return pwsh7Alt;
}
}
const pwshInPath = resolveShellFromPath("pwsh");
if (pwshInPath) {
return pwshInPath;
}
const systemRoot = process.env.SystemRoot || process.env.WINDIR;
if (systemRoot) {
const candidate = path.join(