mirror of
https://github.com/moltbot/moltbot.git
synced 2026-03-08 06:54:24 +00:00
refactor(runtime): unify node version guard parsing
This commit is contained in:
@@ -16,6 +16,9 @@ MUTED='\033[38;2;90;100;128m' # text-muted #5a6480
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
DEFAULT_TAGLINE="All your chats, one OpenClaw."
|
||||
NODE_MIN_MAJOR=22
|
||||
NODE_MIN_MINOR=12
|
||||
NODE_MIN_VERSION="${NODE_MIN_MAJOR}.${NODE_MIN_MINOR}"
|
||||
|
||||
ORIGINAL_PATH="${PATH:-}"
|
||||
|
||||
@@ -1247,26 +1250,10 @@ install_homebrew() {
|
||||
}
|
||||
|
||||
# Check Node.js version
|
||||
node_major_version() {
|
||||
parse_node_version_components() {
|
||||
if ! command -v node &> /dev/null; then
|
||||
return 1
|
||||
fi
|
||||
local version major
|
||||
version="$(node -v 2>/dev/null || true)"
|
||||
major="${version#v}"
|
||||
major="${major%%.*}"
|
||||
if [[ "$major" =~ ^[0-9]+$ ]]; then
|
||||
echo "$major"
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
node_is_at_least_22_12() {
|
||||
if ! command -v node &> /dev/null; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
local version major minor
|
||||
version="$(node -v 2>/dev/null || true)"
|
||||
major="${version#v}"
|
||||
@@ -1281,11 +1268,32 @@ node_is_at_least_22_12() {
|
||||
if [[ ! "$minor" =~ ^[0-9]+$ ]]; then
|
||||
return 1
|
||||
fi
|
||||
echo "${major} ${minor}"
|
||||
return 0
|
||||
}
|
||||
|
||||
if [[ "$major" -gt 22 ]]; then
|
||||
node_major_version() {
|
||||
local version_components major minor
|
||||
version_components="$(parse_node_version_components || true)"
|
||||
read -r major minor <<< "$version_components"
|
||||
if [[ "$major" =~ ^[0-9]+$ && "$minor" =~ ^[0-9]+$ ]]; then
|
||||
echo "$major"
|
||||
return 0
|
||||
fi
|
||||
if [[ "$major" -eq 22 && "$minor" -ge 12 ]]; then
|
||||
return 1
|
||||
}
|
||||
|
||||
node_is_at_least_required() {
|
||||
local version_components major minor
|
||||
version_components="$(parse_node_version_components || true)"
|
||||
read -r major minor <<< "$version_components"
|
||||
if [[ ! "$major" =~ ^[0-9]+$ || ! "$minor" =~ ^[0-9]+$ ]]; then
|
||||
return 1
|
||||
fi
|
||||
if [[ "$major" -gt "$NODE_MIN_MAJOR" ]]; then
|
||||
return 0
|
||||
fi
|
||||
if [[ "$major" -eq "$NODE_MIN_MAJOR" && "$minor" -ge "$NODE_MIN_MINOR" ]]; then
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
@@ -1343,7 +1351,7 @@ ensure_macos_node22_active() {
|
||||
}
|
||||
|
||||
ensure_node22_active_shell() {
|
||||
if node_is_at_least_22_12; then
|
||||
if node_is_at_least_required; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
@@ -1351,7 +1359,7 @@ ensure_node22_active_shell() {
|
||||
active_path="$(command -v node 2>/dev/null || echo "not found")"
|
||||
active_version="$(node -v 2>/dev/null || echo "missing")"
|
||||
|
||||
ui_error "Active Node.js must be v22.12+ but this shell is using ${active_version} (${active_path})"
|
||||
ui_error "Active Node.js must be v${NODE_MIN_VERSION}+ but this shell is using ${active_version} (${active_path})"
|
||||
print_active_node_paths || true
|
||||
|
||||
local nvm_detected=0
|
||||
@@ -1380,15 +1388,15 @@ ensure_node22_active_shell() {
|
||||
check_node() {
|
||||
if command -v node &> /dev/null; then
|
||||
NODE_VERSION="$(node_major_version || true)"
|
||||
if node_is_at_least_22_12; then
|
||||
if node_is_at_least_required; then
|
||||
ui_success "Node.js v$(node -v | cut -d'v' -f2) found"
|
||||
print_active_node_paths || true
|
||||
return 0
|
||||
else
|
||||
if [[ -n "$NODE_VERSION" ]]; then
|
||||
ui_info "Node.js $(node -v) found, upgrading to v22.12+"
|
||||
ui_info "Node.js $(node -v) found, upgrading to v${NODE_MIN_VERSION}+"
|
||||
else
|
||||
ui_info "Node.js found but version could not be parsed; reinstalling v22.12+"
|
||||
ui_info "Node.js found but version could not be parsed; reinstalling v${NODE_MIN_VERSION}+"
|
||||
fi
|
||||
return 1
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user