forked from Maciek-roboblog/Claude-Code-Usage-Monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_dependency.py
More file actions
68 lines (63 loc) · 1.99 KB
/
Copy pathcheck_dependency.py
File metadata and controls
68 lines (63 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python3
import shutil
import subprocess
import sys
# Minimum Node.js version that includes npx by default
MIN_NODE_MAJOR = 8
MIN_NODE_MINOR = 2
def test_node():
"""
Ensure 'node' is on PATH and at least version MIN_NODE_MAJOR.MIN_NODE_MINOR.
On failure, prints an error and exits with code 1.
"""
node_path = shutil.which("node")
if not node_path:
print("✗ node not found on PATH")
sys.exit(1)
try:
out = subprocess.run(
[node_path, "--version"], capture_output=True, text=True, check=True
)
version = out.stdout.strip().lstrip("v")
parts = version.split(".")
major = int(parts[0])
minor = int(parts[1]) if len(parts) > 1 else 0
if major < MIN_NODE_MAJOR or (
major == MIN_NODE_MAJOR and minor < MIN_NODE_MINOR
):
print(
f"✗ node v{version} is too old (requires ≥ v{MIN_NODE_MAJOR}.{MIN_NODE_MINOR})"
)
sys.exit(1)
except subprocess.CalledProcessError as e:
err = (e.stderr or e.stdout or "").strip()
print("✗ node exists but failed to run '--version':")
print(err)
sys.exit(1)
except Exception as e:
print(f"✗ Unexpected error invoking node: {e}")
sys.exit(1)
def test_npx():
"""
Ensure 'npx' is on PATH and runnable.
On failure, prints an error and exits with code 1.
"""
npx_path = shutil.which("npx")
if not npx_path:
print("✗ npx not found on PATH")
sys.exit(1)
try:
subprocess.run(
[npx_path, "--version"],
check=True,
stdout=subprocess.DEVNULL,
stderr=subprocess.PIPE,
text=True,
)
except subprocess.CalledProcessError as e:
err = e.stderr.strip() or e.stdout.strip()
print(f"✗ npx test failed: {err}")
sys.exit(1)
except Exception as e:
print(f"✗ Failed to invoke npx: {e}")
sys.exit(1)