fix: improve Windows compatibility in dependency check (#1550)

* fix: improve Windows compatibility in dependency check

* fix: tolerate stdio reconfigure failures in check script

---------

Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
This commit is contained in:
tryag 2026-03-31 21:54:41 +08:00 committed by GitHub
parent b356a13da5
commit 09a9209724
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -9,6 +9,17 @@ import sys
from typing import Optional from typing import Optional
def configure_stdio() -> None:
"""Prefer UTF-8 output so Unicode status markers render on Windows."""
for stream_name in ("stdout", "stderr"):
stream = getattr(sys, stream_name, None)
if hasattr(stream, "reconfigure"):
try:
stream.reconfigure(encoding="utf-8", errors="replace")
except (OSError, ValueError):
continue
def run_command(command: list[str]) -> Optional[str]: def run_command(command: list[str]) -> Optional[str]:
"""Run a command and return trimmed stdout, or None on failure.""" """Run a command and return trimmed stdout, or None on failure."""
try: try:
@ -29,6 +40,7 @@ def parse_node_major(version_text: str) -> Optional[int]:
def main() -> int: def main() -> int:
configure_stdio()
print("==========================================") print("==========================================")
print(" Checking Required Dependencies") print(" Checking Required Dependencies")
print("==========================================") print("==========================================")
@ -61,8 +73,9 @@ def main() -> int:
print() print()
print("Checking pnpm...") print("Checking pnpm...")
if shutil.which("pnpm"): pnpm_executable = shutil.which("pnpm.cmd") or shutil.which("pnpm")
pnpm_version = run_command(["pnpm", "-v"]) if pnpm_executable:
pnpm_version = run_command([pnpm_executable, "-v"])
if pnpm_version: if pnpm_version:
print(f" ✓ pnpm {pnpm_version}") print(f" ✓ pnpm {pnpm_version}")
else: else: