()
| 22 | * Windows/macOS, PATH is sufficient. |
| 23 | */ |
| 24 | export async function findPowerShell(): Promise<string | null> { |
| 25 | const pwshPath = await which('pwsh') |
| 26 | if (pwshPath) { |
| 27 | // Snap launcher hangs in subprocesses. Prefer the direct binary. |
| 28 | // Check both the resolved PATH entry and its symlink target: on |
| 29 | // some distros /usr/bin/pwsh is a symlink to /snap/bin/pwsh, which |
| 30 | // would bypass a naive startsWith('/snap/') on the which() result. |
| 31 | if (getPlatform() === 'linux') { |
| 32 | const resolved = await realpath(pwshPath).catch(() => pwshPath) |
| 33 | if (pwshPath.startsWith('/snap/') || resolved.startsWith('/snap/')) { |
| 34 | const direct = |
| 35 | (await probePath('/opt/microsoft/powershell/7/pwsh')) ?? |
| 36 | (await probePath('/usr/bin/pwsh')) |
| 37 | if (direct) { |
| 38 | const directResolved = await realpath(direct).catch(() => direct) |
| 39 | if ( |
| 40 | !direct.startsWith('/snap/') && |
| 41 | !directResolved.startsWith('/snap/') |
| 42 | ) { |
| 43 | return direct |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | return pwshPath |
| 49 | } |
| 50 | |
| 51 | const powershellPath = await which('powershell') |
| 52 | if (powershellPath) { |
| 53 | return powershellPath |
| 54 | } |
| 55 | |
| 56 | return null |
| 57 | } |
| 58 | |
| 59 | let cachedPowerShellPath: Promise<string | null> | null = null |
| 60 |
no test coverage detected