fix(check): windows pnpm version detection in check script (#2189)
* fix: resolve Windows pnpm detection in check script * style: format check script regression test * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * fix: resolve corepack fallback on windows --------- Co-authored-by: Willem Jiang <willem.jiang@gmail.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
+14
-7
@@ -6,6 +6,7 @@ from __future__ import annotations
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def configure_stdio() -> None:
|
||||
@@ -30,13 +31,19 @@ def run_command(command: list[str]) -> str | None:
|
||||
|
||||
def find_pnpm_command() -> list[str] | None:
|
||||
"""Return a pnpm-compatible command that exists on this machine."""
|
||||
candidates = [["pnpm"], ["pnpm.cmd"]]
|
||||
if shutil.which("corepack"):
|
||||
candidates.append(["corepack", "pnpm"])
|
||||
pnpm_path = shutil.which("pnpm")
|
||||
if pnpm_path:
|
||||
return [str(Path(pnpm_path))]
|
||||
|
||||
for command in candidates:
|
||||
if shutil.which(command[0]):
|
||||
return command
|
||||
pnpm_cmd_path = shutil.which("pnpm.cmd")
|
||||
if pnpm_cmd_path:
|
||||
return [str(Path(pnpm_cmd_path))]
|
||||
|
||||
corepack_path = shutil.which("corepack")
|
||||
if not corepack_path:
|
||||
corepack_path = shutil.which("corepack.cmd")
|
||||
if corepack_path:
|
||||
return [str(Path(corepack_path)), "pnpm"]
|
||||
return None
|
||||
|
||||
|
||||
@@ -88,7 +95,7 @@ def main() -> int:
|
||||
if pnpm_command:
|
||||
pnpm_version = run_command([*pnpm_command, "-v"])
|
||||
if pnpm_version:
|
||||
if pnpm_command[0] == "corepack":
|
||||
if Path(pnpm_command[0]).stem.lower() == "corepack":
|
||||
print(f" OK pnpm {pnpm_version} (via Corepack)")
|
||||
else:
|
||||
print(f" OK pnpm {pnpm_version}")
|
||||
|
||||
Reference in New Issue
Block a user