fix(windows): use shutil.which() for npm subprocess calls (#73)

Two subprocess.run(["npm", ...]) calls in undici installation were
using bare command name, which fails on Windows where npm is
installed as npm.cmd. Now resolves full path via shutil.which()
first, consistent with all other subprocess calls.

Co-authored-by: Panniantong <panniantong@users.noreply.github.com>
This commit is contained in:
Pnant
2026-03-05 10:32:02 +08:00
committed by GitHub
parent b4d189b536
commit e5e20a1154
+4 -3
View File
@@ -410,14 +410,15 @@ def _install_system_deps():
print(" ⬜ xreach CLI requires Node.js (optional — Twitter reading still works via Jina)") print(" ⬜ xreach CLI requires Node.js (optional — Twitter reading still works via Jina)")
# ── undici (proxy support for Node.js fetch) ── # ── undici (proxy support for Node.js fetch) ──
if shutil.which("npm"): npm_cmd = shutil.which("npm")
npm_root = subprocess.run(["npm", "root", "-g"], capture_output=True, encoding="utf-8", errors="replace", timeout=5).stdout.strip() if npm_cmd:
npm_root = subprocess.run([npm_cmd, "root", "-g"], capture_output=True, encoding="utf-8", errors="replace", timeout=5).stdout.strip()
undici_path = os.path.join(npm_root, "undici", "index.js") if npm_root else "" undici_path = os.path.join(npm_root, "undici", "index.js") if npm_root else ""
if os.path.exists(undici_path): if os.path.exists(undici_path):
print(" ✅ undici already installed (Node.js proxy support)") print(" ✅ undici already installed (Node.js proxy support)")
else: else:
try: try:
subprocess.run(["npm", "install", "-g", "undici"], capture_output=True, encoding="utf-8", errors="replace", timeout=60) subprocess.run([npm_cmd, "install", "-g", "undici"], capture_output=True, encoding="utf-8", errors="replace", timeout=60)
print(" ✅ undici installed (Node.js proxy support)") print(" ✅ undici installed (Node.js proxy support)")
except Exception: except Exception:
print(" ⬜ undici install failed (optional — xreach may not work behind proxies)") print(" ⬜ undici install failed (optional — xreach may not work behind proxies)")