Skip to content

Commit 738b8c7

Browse files
committed
fix: install-dev script to prevent node version override
1 parent be3d583 commit 738b8c7

1 file changed

Lines changed: 23 additions & 17 deletions

File tree

bin/install-dev

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -369,21 +369,8 @@ print_success "Python $PYTHON_VERSION set up"
369369
# =============================================================================
370370
print_step "Setting up Node.js environment..."
371371

372-
# Detect existing Node.js version and decide whether to skip install/switch
373-
EXISTING_NODE_VERSION=""
374-
EXISTING_NODE_MAJOR=""
375-
SKIP_NODE_INSTALL="false"
376-
377-
if command_exists node; then
378-
EXISTING_NODE_VERSION="$(node -v 2>/dev/null | sed 's/^v//')"
379-
EXISTING_NODE_MAJOR="${EXISTING_NODE_VERSION%%.*}"
380-
381-
# If an existing Node.js major version is greater than 22, do not override it
382-
if [[ -n "$EXISTING_NODE_MAJOR" ]] && [[ "$EXISTING_NODE_MAJOR" =~ ^[0-9]+$ ]] && [ "$EXISTING_NODE_MAJOR" -gt 22 ]; then
383-
SKIP_NODE_INSTALL="true"
384-
print_step "Detected Node.js v$EXISTING_NODE_VERSION (>22); skipping installation and version switch to avoid override"
385-
fi
386-
fi
372+
# Minimum required Node.js version
373+
MIN_NODE_VERSION=18
387374

388375
# Install nvm if not available
389376
if [[ ! -d "$HOME/.nvm" ]] && ! command_exists nvm; then
@@ -396,11 +383,30 @@ export NVM_DIR="$HOME/.nvm"
396383
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
397384
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
398385

399-
# Install Node.js (unless an existing >22 installation is present)
386+
# Detect existing Node.js version AFTER nvm is sourced
387+
EXISTING_NODE_VERSION=""
388+
EXISTING_NODE_MAJOR=""
389+
SKIP_NODE_INSTALL="false"
390+
391+
if command_exists node; then
392+
EXISTING_NODE_VERSION="$(node -v 2>/dev/null | sed 's/^v//')"
393+
EXISTING_NODE_MAJOR="${EXISTING_NODE_VERSION%%.*}"
394+
395+
# If an existing Node.js major version meets minimum requirements, keep it
396+
if [[ -n "$EXISTING_NODE_MAJOR" ]] && [[ "$EXISTING_NODE_MAJOR" =~ ^[0-9]+$ ]] && [ "$EXISTING_NODE_MAJOR" -ge "$MIN_NODE_VERSION" ]; then
397+
SKIP_NODE_INSTALL="true"
398+
print_success "Detected Node.js v$EXISTING_NODE_VERSION (>= $MIN_NODE_VERSION); keeping existing version"
399+
else
400+
print_warning "Detected Node.js v$EXISTING_NODE_VERSION (< $MIN_NODE_VERSION); will install newer version"
401+
fi
402+
fi
403+
404+
# Install Node.js only if needed
400405
if command_exists nvm; then
401406
if [[ "$SKIP_NODE_INSTALL" == "true" ]]; then
402-
print_success "Keeping existing Node.js v$EXISTING_NODE_VERSION unchanged"
407+
print_success "Node.js v$EXISTING_NODE_VERSION meets requirements"
403408
else
409+
print_step "Installing Node.js (stable)..."
404410
nvm install stable
405411
nvm use stable
406412
nvm alias default stable

0 commit comments

Comments
 (0)