refactor: consolidate Node.js path setup into shared script and add fnm support

This commit is contained in:
hewigovens 2025-07-06 11:09:32 +09:00
parent 9fad6301a0
commit 826d8de4c1
No known key found for this signature in database
3 changed files with 46 additions and 32 deletions

View file

@ -62,17 +62,9 @@ fi
echo "Building web frontend..."
# Setup PATH for Node.js
export PATH="/opt/homebrew/bin:/usr/local/bin:$PATH"
# Load NVM if available
if [ -s "$HOME/.nvm/nvm.sh" ]; then
export NVM_DIR="$HOME/.nvm"
. "$NVM_DIR/nvm.sh"
fi
# Put volta on the path if it exists
export PATH="$HOME/.volta/bin:$PATH"
# Setup Node.js PATH (Homebrew, nvm, Volta, fnm)
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
source "${SCRIPT_DIR}/node-path-setup.sh"
# Export CI to prevent interactive prompts
export CI=true

View file

@ -16,27 +16,9 @@ fi
echo "Checking for Node.js..."
# Add common Node.js installation paths to PATH
# Homebrew on Apple Silicon
if [ -d "/opt/homebrew/bin" ]; then
export PATH="/opt/homebrew/bin:$PATH"
fi
# Homebrew on Intel Macs
if [ -d "/usr/local/bin" ]; then
export PATH="/usr/local/bin:$PATH"
fi
# NVM default location
if [ -s "$HOME/.nvm/nvm.sh" ]; then
export NVM_DIR="$HOME/.nvm"
. "$NVM_DIR/nvm.sh"
fi
# Volta
if [ -d "$HOME/.volta/bin" ]; then
export PATH="$HOME/.volta/bin:$PATH"
fi
# Load Node.js environment managers (Homebrew, nvm, Volta, fnm)
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]:-}" )" && pwd )"
source "${SCRIPT_DIR}/node-path-setup.sh"
# Check if Node.js is available
if command -v node &> /dev/null; then
@ -72,6 +54,7 @@ else
echo " - Download from: https://nodejs.org/"
echo " - Using nvm: nvm install 20"
echo " - Using volta: volta install node@20"
echo " - Using fnm: fnm install 20"
echo ""
echo "PATH checked: $PATH"
exit 1

View file

@ -0,0 +1,39 @@
#!/bin/bash
# node-path-setup.sh
# -------------------------------------------------------------
# Common helper to ensure Node.js managers add their binaries to
# PATH for VibeTunnel build scripts. Source this instead of
# duplicating logic in every script.
#
# Usage (Bash):
# SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-${0}}")" && pwd)"
# source "${SCRIPT_DIR}/node-path-setup.sh"
# Usage (Zsh):
# SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
# source "${SCRIPT_DIR}/node-path-setup.sh"
# -------------------------------------------------------------
# Homebrew (Apple Silicon & Intel)
if [ -d "/opt/homebrew/bin" ]; then
export PATH="/opt/homebrew/bin:$PATH"
fi
if [ -d "/usr/local/bin" ]; then
export PATH="/usr/local/bin:$PATH"
fi
# NVM default location
if [ -s "$HOME/.nvm/nvm.sh" ]; then
export NVM_DIR="$HOME/.nvm"
# shellcheck source=/dev/null
. "$NVM_DIR/nvm.sh"
fi
# Volta
if [ -d "$HOME/.volta/bin" ]; then
export PATH="$HOME/.volta/bin:$PATH"
fi
# fnm (Fast Node Manager)
if command -v fnm &> /dev/null; then
eval "$(fnm env)"
fi