Skip to content

Commit dc662a1

Browse files
authored
Merge pull request #182 from alex-feel/alex-feel-dev
Use robust npm discovery to prevent WinError 193 on Windows
2 parents ad6510c + 6ef2ff6 commit dc662a1

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

scripts/install_claude.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,17 +1096,9 @@ def get_latest_claude_version() -> str | None:
10961096
Returns:
10971097
Latest version string (e.g., "1.0.135") or None if cannot determine.
10981098
"""
1099-
npm_path = find_command('npm')
1099+
npm_path = find_command_robust('npm')
11001100
if not npm_path:
1101-
# On Windows, try to find npm.cmd explicitly
1102-
if platform.system() == 'Windows':
1103-
npm_cmd_path = Path(r'C:\Program Files\nodejs\npm.cmd')
1104-
if npm_cmd_path.exists():
1105-
npm_path = str(npm_cmd_path)
1106-
else:
1107-
return None
1108-
else:
1109-
return None
1101+
return None
11101102

11111103
# Query npm for latest version
11121104
cmd = [npm_path, 'view', f'{CLAUDE_NPM_PACKAGE}@latest', 'version']
@@ -1168,7 +1160,7 @@ def install_claude_npm(upgrade: bool = False, version: str | None = None) -> boo
11681160
if npm_cmd.exists():
11691161
info(f'Found npm.cmd at {npm_cmd}')
11701162

1171-
npm_path = find_command('npm')
1163+
npm_path = find_command_robust('npm')
11721164
if not npm_path:
11731165
# On Windows, try to find npm.cmd explicitly
11741166
if platform.system() == 'Windows':
@@ -1183,6 +1175,28 @@ def install_claude_npm(upgrade: bool = False, version: str | None = None) -> boo
11831175
error('npm not found. Please install Node.js with npm')
11841176
return False
11851177

1178+
# Validate npm path before execution
1179+
if npm_path:
1180+
npm_path_obj = Path(npm_path)
1181+
if not npm_path_obj.exists():
1182+
error(f'npm executable not found at: {npm_path}')
1183+
error('This usually indicates a PATH synchronization issue')
1184+
return False
1185+
1186+
# On Windows, ensure we're using the .cmd version
1187+
if platform.system() == 'Windows' and not npm_path.lower().endswith('.cmd'):
1188+
# Check if .cmd version exists
1189+
npm_cmd_path_str = npm_path if npm_path.lower().endswith('.cmd') else npm_path + '.cmd'
1190+
if Path(npm_cmd_path_str).exists():
1191+
warning(f'Using {npm_cmd_path_str} instead of {npm_path}')
1192+
npm_path = npm_cmd_path_str
1193+
else:
1194+
error(f'npm.cmd not found. Found non-executable: {npm_path}')
1195+
error('This file cannot be executed directly on Windows')
1196+
return False
1197+
1198+
info(f'Validated npm executable: {npm_path}')
1199+
11861200
action = 'Upgrading' if upgrade else 'Installing'
11871201

11881202
# Determine version to install

0 commit comments

Comments
 (0)