PowerShell Detection Utility (shell/powershellDetection.ts)

collection-claude-code-source-code · claude-code-source-code/src/utils/shell/powershellDetection.ts · typescript · Apache-2.0
cli, dev-tools, database, lang:powershell, lang:typescript, tag:detection, tag:cross-platform

Cross-platform utility to locate PowerShell (pwsh preferred) with snap workaround on Linux and caching for CLI tooling.

// Source: https://github.com/chauncygu/collection-claude-code-source-code | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
import { realpath, stat } from 'fs/promises'
import { getPlatform } from '../platform.js'
import { which } from '../which.js'

async function probePath(p: string): Promise<string | null> {
  try {
    return (await stat(p)).isFile() ? p : null
  } catch {
    return null
  }
}

/**
 * Attempts to find PowerShell on the system via PATH.
 * Prefers pwsh (PowerShell Core 7+), falls back to powershell (5.1).
 *
 * On Linux, if PATH resolves to a snap launcher (/snap/…) — directly or
 * via a symlink chain like /usr/bin/pwsh → /snap/bin/pwsh — probe known
 * apt/rp

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key