From 68325392f26722aad16bf9ae7c9a80708a3a5c67 Mon Sep 17 00:00:00 2001 From: Sherman Boyd Date: Sun, 6 Apr 2025 16:53:01 -0700 Subject: [PATCH 1/3] support fnm as well as nvm --- scripts/install-dependencies.sh | 69 ++++++++++++++++++++++++--------- 1 file changed, 51 insertions(+), 18 deletions(-) diff --git a/scripts/install-dependencies.sh b/scripts/install-dependencies.sh index c3262e66c..b5a420eab 100755 --- a/scripts/install-dependencies.sh +++ b/scripts/install-dependencies.sh @@ -5,27 +5,60 @@ # - Debug -> Extension set -e -# Check if node version matches .nvmrc -if [ -f .nvmrc ]; then +# Set the correct Node version at the start of the script +setup_node_version() { + # Get required node version from .node-version or .nvmrc + if [ -f .node-version ]; then + required_node_version=$(cat .node-version) + elif [ -f .nvmrc ]; then required_node_version=$(cat .nvmrc) - current_node_version=$(node -v) - - # Remove 'v' prefix from versions for comparison - required_version=${required_node_version#v} - current_version=${current_node_version#v} + else + echo "No .node-version or .nvmrc file found. Skipping Node.js version check." + return + fi - if [ "$required_version" != "$current_version" ]; then - echo "⚠️ Warning: Your Node.js version ($current_node_version) does not match the required version ($required_node_version)" - echo "Please consider switching to the correct version using: nvm use" - - if [ -t 0 ]; then - read -p "Press Enter to continue with installation anyway..." - else - echo "Continuing with installation anyway..." - fi - echo + # Remove 'v' prefix if present + required_version=${required_node_version#v} + + # Try fnm first + if command -v fnm &> /dev/null; then + echo "📦 Using fnm to set Node.js version to $required_version..." + eval "$(fnm env --use-on-cd)" + fnm use "$required_version" || fnm use + # Then try nvm + elif command -v nvm &> /dev/null || [ -s "$NVM_DIR/nvm.sh" ]; then + echo "📦 Using nvm to set Node.js version to $required_version..." + export NVM_DIR="$HOME/.nvm" + [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # Load nvm + nvm use "$required_version" || nvm use + # Fall back to version check only + else + echo "Neither fnm nor nvm found. Proceeding with current Node.js version." + fi + + # Verify the current Node.js version after our attempt to set it + current_node_version=$(node -v) + current_version=${current_node_version#v} + + if [ "$required_version" != "$current_version" ]; then + echo "⚠️ Warning: Your Node.js version ($current_node_version) does not match the required version (v$required_version)" + echo "Even after attempting to use version managers, the correct version couldn't be activated." + echo "Please consider switching to the correct version using: `nvm use` or `fnm use` or setting " + echo "the correct version in a .nvmrc or .node-version file." + + if [ -t 0 ]; then + read -p "Press Enter to continue with installation anyway..." + else + echo "Continuing with installation anyway..." fi -fi + echo + else + echo "✅ Using Node.js $current_node_version as required." + fi +} + +# Run the node version setup +setup_node_version echo "Installing root-level dependencies..." npm install From b6f2f3905dc4d16249a69e50543bd8ce569563b6 Mon Sep 17 00:00:00 2001 From: Sherman Boyd Date: Sun, 6 Apr 2025 16:56:47 -0700 Subject: [PATCH 2/3] suppress output for fnm and nvm commands --- scripts/install-dependencies.sh | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/scripts/install-dependencies.sh b/scripts/install-dependencies.sh index b5a420eab..7120e8c5d 100755 --- a/scripts/install-dependencies.sh +++ b/scripts/install-dependencies.sh @@ -23,14 +23,15 @@ setup_node_version() { # Try fnm first if command -v fnm &> /dev/null; then echo "📦 Using fnm to set Node.js version to $required_version..." - eval "$(fnm env --use-on-cd)" - fnm use "$required_version" || fnm use + # Capture output to avoid duplicate messages + eval "$(fnm env --use-on-cd)" &> /dev/null + fnm use "$required_version" &> /dev/null || fnm use &> /dev/null # Then try nvm elif command -v nvm &> /dev/null || [ -s "$NVM_DIR/nvm.sh" ]; then echo "📦 Using nvm to set Node.js version to $required_version..." export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # Load nvm - nvm use "$required_version" || nvm use + nvm use "$required_version" &> /dev/null || nvm use &> /dev/null # Fall back to version check only else echo "Neither fnm nor nvm found. Proceeding with current Node.js version." @@ -43,9 +44,6 @@ setup_node_version() { if [ "$required_version" != "$current_version" ]; then echo "⚠️ Warning: Your Node.js version ($current_node_version) does not match the required version (v$required_version)" echo "Even after attempting to use version managers, the correct version couldn't be activated." - echo "Please consider switching to the correct version using: `nvm use` or `fnm use` or setting " - echo "the correct version in a .nvmrc or .node-version file." - if [ -t 0 ]; then read -p "Press Enter to continue with installation anyway..." else From 576978e8c9d747363d810f456995293d266aaedb Mon Sep 17 00:00:00 2001 From: Sherman Boyd Date: Sun, 6 Apr 2025 16:59:09 -0700 Subject: [PATCH 3/3] Add node version for fnm users --- .node-version | 1 + 1 file changed, 1 insertion(+) create mode 100644 .node-version diff --git a/.node-version b/.node-version new file mode 100644 index 000000000..18c284172 --- /dev/null +++ b/.node-version @@ -0,0 +1 @@ +20.11.0 \ No newline at end of file