From 826d8de4c1ec35bae9e48e581896aa3f17aa704f Mon Sep 17 00:00:00 2001 From: hewigovens <360470+hewigovens@users.noreply.github.com> Date: Sun, 6 Jul 2025 11:09:32 +0900 Subject: [PATCH 1/3] refactor: consolidate Node.js path setup into shared script and add fnm support --- mac/scripts/build-web-frontend.sh | 14 +++-------- mac/scripts/install-node.sh | 25 ++++---------------- mac/scripts/node-path-setup.sh | 39 +++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 32 deletions(-) create mode 100644 mac/scripts/node-path-setup.sh diff --git a/mac/scripts/build-web-frontend.sh b/mac/scripts/build-web-frontend.sh index 5d983449..9404229e 100755 --- a/mac/scripts/build-web-frontend.sh +++ b/mac/scripts/build-web-frontend.sh @@ -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 diff --git a/mac/scripts/install-node.sh b/mac/scripts/install-node.sh index 8ffca40e..aa754ea9 100755 --- a/mac/scripts/install-node.sh +++ b/mac/scripts/install-node.sh @@ -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 diff --git a/mac/scripts/node-path-setup.sh b/mac/scripts/node-path-setup.sh new file mode 100644 index 00000000..5aa371e7 --- /dev/null +++ b/mac/scripts/node-path-setup.sh @@ -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 From 89240a09a9246c2af30b8ee767bfd9bc1fa7d0f9 Mon Sep 17 00:00:00 2001 From: hewigovens <360470+hewigovens@users.noreply.github.com> Date: Sun, 6 Jul 2025 11:32:16 +0900 Subject: [PATCH 2/3] cleanup --- mac/scripts/node-path-setup.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/mac/scripts/node-path-setup.sh b/mac/scripts/node-path-setup.sh index 5aa371e7..ed728ae8 100644 --- a/mac/scripts/node-path-setup.sh +++ b/mac/scripts/node-path-setup.sh @@ -24,7 +24,6 @@ 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 From 2f829215bceee97fd023ec93a9ed2becd8788912 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 6 Jul 2025 03:38:47 +0100 Subject: [PATCH 3/3] fix: correct SCRIPT_DIR detection for zsh compatibility in install-node.sh The redundant SCRIPT_DIR assignment on line 20 used ${BASH_SOURCE[0]:-} which would expand to an empty string in zsh, causing dirname "" to return the current directory instead of the script's directory. This led to script failures when not run from its own directory. Since SCRIPT_DIR is already correctly set earlier (lines 11-15) with proper zsh handling, the redundant line has been removed. --- mac/scripts/install-node.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/mac/scripts/install-node.sh b/mac/scripts/install-node.sh index aa754ea9..5683ced4 100755 --- a/mac/scripts/install-node.sh +++ b/mac/scripts/install-node.sh @@ -17,7 +17,6 @@ fi echo "Checking for Node.js..." # 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