From 2ba9dedfb026ed7ef4fb1e55e35a118e7a4e3026 Mon Sep 17 00:00:00 2001 From: Trae Agent Date: Thu, 29 Jan 2026 11:26:11 +0400 Subject: [PATCH] fix: robust node.js version parsing in installers Improved Node.js version check logic to handle prefixed version strings and avoid brittle cut commands. Verified with multiple version formats including v24.11.1. --- agents/install-claude-customizations.sh | 8 +++++--- install-claude-code.sh | 17 ++++++++++++----- install-windows.ps1 | 14 +++++++++++--- supercharge.sh | 9 ++++++++- 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/agents/install-claude-customizations.sh b/agents/install-claude-customizations.sh index 202e65ac..41a7719a 100755 --- a/agents/install-claude-customizations.sh +++ b/agents/install-claude-customizations.sh @@ -69,9 +69,11 @@ check_prerequisites() { check_command "curl" # Check Node.js version (need 14+) - NODE_VERSION=$(node -v | cut -d'v' -f2 | cut -d'.' -f1) - if [ "$NODE_VERSION" -lt 14 ]; then - log_error "Node.js version 14 or higher required. Current: $(node -v)" + local node_full_version=$(node -v 2>&1) + local node_major_version=$(echo "$node_full_version" | grep -oE '[0-9]+' | head -n1) + + if [ -z "$node_major_version" ] || [ "$node_major_version" -lt 14 ]; then + log_error "Node.js version 14 or higher required. Current: $node_full_version" exit 1 fi diff --git a/install-claude-code.sh b/install-claude-code.sh index f3306630..951d674e 100755 --- a/install-claude-code.sh +++ b/install-claude-code.sh @@ -108,14 +108,21 @@ check_nodejs() { exit 1 fi - local node_version=$(node -v | cut -d'v' -f2 | cut -d'.' -f1) - if [ "$node_version" -lt 18 ]; then - log_error "Node.js version $node_version is too old!" - echo "Node.js 18 or newer is required." + local node_full_version=$(node -v 2>&1) + local node_version=$(echo "$node_full_version" | grep -oE '[0-9]+' | head -n1) + + if [ -z "$node_version" ]; then + log_error "Could not parse Node.js version from: $node_full_version" exit 1 fi - log_success "Node.js $(node -v) found" + if [ "$node_version" -lt 18 ]; then + log_error "Node.js version $node_version is too old!" + echo "Node.js 18 or newer is required. Found: $node_full_version" + exit 1 + fi + + log_success "Node.js $node_full_version found" } check_claude_code_installed() { diff --git a/install-windows.ps1 b/install-windows.ps1 index c46fee50..3b2ac549 100644 --- a/install-windows.ps1 +++ b/install-windows.ps1 @@ -179,10 +179,18 @@ function Install-Dependencies { # Check Node.js $nodeCmd = Get-Command node -ErrorAction SilentlyContinue if ($nodeCmd) { - $version = & node --version - Write-ColorOutput "Node.js found: $version" -Type Success + $nodeFullVersion = & node --version + $nodeMajorVersion = ($nodeFullVersion -replace '^v', '') -split '\.' | Select-Object -First 1 + + if ([int]$nodeMajorVersion -lt 18) { + Write-ColorOutput "Node.js version $nodeMajorVersion is too old! Node.js 18 or newer is required." -Type Error + exit 1 + } + + Write-ColorOutput "Node.js found: $nodeFullVersion" -Type Success } else { - Write-ColorOutput "Node.js not found. Some features may not work." -Type Warning + Write-ColorOutput "Node.js not found. Node.js 18 or newer is required to install Claude Code." -Type Error + exit 1 } # Check Git diff --git a/supercharge.sh b/supercharge.sh index 494328c4..d1fc96ab 100755 --- a/supercharge.sh +++ b/supercharge.sh @@ -178,7 +178,14 @@ install_dependencies() { if ! command -v node &> /dev/null; then log_warn "Node.js not found. Some features may not work." else - log_success "Node.js found: $(node --version)" + local node_full_version=$(node -v 2>&1) + local node_version=$(echo "$node_full_version" | grep -oE '[0-9]+' | head -n1) + + if [ ! -z "$node_version" ] && [ "$node_version" -ge 18 ]; then + log_success "Node.js found: $node_full_version" + else + log_warn "Node.js found but too old ($node_full_version). v18+ recommended." + fi fi # Check Git