Skip to content

Commit 3988a3a

Browse files
justin808claude
andcommitted
Improve rvm/nvm support with robust error handling
Enhanced the ci-switch-config script based on code review feedback: **Error Handling & Validation:** - Add comprehensive error checking for rvm/nvm commands with helpful messages - Detect and fail early when only rvm or only nvm is installed - Guide users to source shell configs or install missing managers - Make rvm version check more flexible (handles with/without ruby- prefix) **nvm Installation Detection:** - Support multiple common nvm locations (standard, Homebrew, XDG config) - Try ~/.nvm, /opt/homebrew/opt/nvm, and ~/.config/nvm - Provide clear error messages showing which locations were tried **Documentation:** - Update SWITCHING_CI_CONFIGS.md with complete rvm+nvm installation guide - Add troubleshooting sections for each version manager - Include verification commands for all supported managers - Add note clarifying asdf sourcing only affects script's subshell 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 8eceea6 commit 3988a3a

File tree

2 files changed

+118
-16
lines changed

2 files changed

+118
-16
lines changed

SWITCHING_CI_CONFIGS.md

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,50 @@ The project runs tests against two configurations:
5353

5454
## Prerequisites
5555

56-
You must have a version manager like [mise](https://mise.jdx.dev/) (recommended) or [asdf](https://asdf-vm.com/) installed to manage Ruby and Node versions.
56+
You must have a version manager installed to manage Ruby and Node versions. The script supports:
57+
58+
- **[mise](https://mise.jdx.dev/)** - Recommended, modern, manages both Ruby and Node
59+
- **[asdf](https://asdf-vm.com/)** - Legacy option, manages both Ruby and Node
60+
- **[rvm](https://rvm.io/) + [nvm](https://github.com/nvm-sh/nvm)** - Separate managers for Ruby and Node
61+
62+
### Option 1: mise (Recommended)
5763

5864
```bash
59-
# Install mise (recommended, modern alternative to asdf)
65+
# Install mise
6066
brew install mise
6167
echo 'eval "$(mise activate zsh)"' >> ~/.zshrc
6268
source ~/.zshrc
6369

64-
# OR install asdf (legacy option)
70+
# mise automatically reads from .tool-versions
71+
```
72+
73+
### Option 2: asdf
74+
75+
```bash
76+
# Install asdf
6577
brew install asdf
6678
echo -e "\n. $(brew --prefix asdf)/libexec/asdf.sh" >> ~/.zshrc
6779
source ~/.zshrc
6880

69-
# Install plugins (only needed for asdf, mise reads from mise.toml)
81+
# Install plugins
7082
asdf plugin add ruby
7183
asdf plugin add nodejs
7284
```
7385

86+
### Option 3: rvm + nvm
87+
88+
```bash
89+
# Install rvm for Ruby
90+
\curl -sSL https://get.rvm.io | bash -s stable
91+
source ~/.rvm/scripts/rvm
92+
93+
# Install nvm for Node
94+
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
95+
# Add to shell config (the installer usually does this automatically)
96+
```
97+
98+
**Note:** If you only have rvm (no nvm) or only nvm (no rvm), the script will detect this and provide helpful error messages guiding you to install the missing manager or switch to mise/asdf.
99+
74100
## Detailed Usage
75101

76102
### 1. Check Current Configuration
@@ -107,7 +133,9 @@ This will:
107133
```bash
108134
# Reload your shell to pick up new Ruby/Node versions
109135
cd <project-root>
110-
mise current # or: asdf current
136+
mise current # For mise users
137+
# asdf current # For asdf users
138+
# rvm current && nvm current # For rvm+nvm users
111139

112140
# Build and test
113141
rake node_package
@@ -137,7 +165,9 @@ This will:
137165
```bash
138166
# Reload your shell to pick up new Ruby/Node versions
139167
cd <project-root>
140-
mise current # or: asdf current
168+
mise current # For mise users
169+
# asdf current # For asdf users
170+
# rvm current && nvm current # For rvm+nvm users
141171

142172
# Build and test
143173
rake node_package
@@ -243,6 +273,22 @@ asdf reshim ruby
243273
asdf reshim nodejs
244274
```
245275

276+
**For rvm + nvm:**
277+
278+
```bash
279+
# Install and use specific Ruby version
280+
rvm install 3.2.8 # or 3.4.3
281+
rvm use 3.2.8
282+
283+
# Install and use specific Node version
284+
nvm install 20.18.1 # or 22.12.0
285+
nvm use 20.18.1
286+
287+
# Verify versions
288+
ruby --version
289+
node --version
290+
```
291+
246292
### Yarn install fails
247293

248294
If you get package resolution errors:

bin/ci-switch-config

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,29 @@ set_ruby_version() {
6464
;;
6565
rvm|rvm+nvm)
6666
print_header "Setting Ruby $version with rvm"
67-
if ! rvm list strings | grep -q "^ruby-${version}$"; then
67+
# Check if version exists (with or without ruby- prefix)
68+
if ! rvm list strings | grep -qE "^(ruby-)?${version}$"; then
6869
print_warning "Ruby $version not installed. Installing..."
69-
rvm install "$version"
70+
if ! rvm install "$version"; then
71+
print_error "Failed to install Ruby $version with rvm"
72+
print_warning "Make sure rvm is properly configured. Try running: source ~/.rvm/scripts/rvm"
73+
exit 1
74+
fi
7075
fi
71-
rvm use "$version"
76+
if ! rvm use "$version"; then
77+
print_error "Failed to switch to Ruby $version"
78+
print_warning "Make sure rvm is properly configured. Try running: source ~/.rvm/scripts/rvm"
79+
exit 1
80+
fi
81+
print_success "Switched to Ruby $version"
82+
;;
83+
nvm)
84+
print_error "Cannot set Ruby version: nvm doesn't manage Ruby"
85+
echo "Please install one of the following to manage Ruby versions:"
86+
echo " - rvm: https://rvm.io/"
87+
echo " - mise: https://mise.jdx.dev/ (recommended, manages both Ruby and Node)"
88+
echo " - asdf: https://asdf-vm.com/ (manages both Ruby and Node)"
89+
exit 1
7290
;;
7391
esac
7492
}
@@ -83,16 +101,52 @@ set_node_version() {
83101
;;
84102
nvm|rvm+nvm)
85103
print_header "Setting Node $version with nvm"
86-
# Source nvm if not already loaded
87-
if [ -z "${NVM_DIR:-}" ]; then
88-
export NVM_DIR="$HOME/.nvm"
89-
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
104+
105+
# Source nvm if not already loaded - try multiple common locations
106+
if ! command -v nvm &> /dev/null; then
107+
# Try standard nvm location
108+
if [ -s "$HOME/.nvm/nvm.sh" ]; then
109+
export NVM_DIR="$HOME/.nvm"
110+
\. "$NVM_DIR/nvm.sh"
111+
# Try Homebrew location (macOS)
112+
elif [ -s "/opt/homebrew/opt/nvm/nvm.sh" ]; then
113+
export NVM_DIR="/opt/homebrew/opt/nvm"
114+
\. "/opt/homebrew/opt/nvm/nvm.sh"
115+
# Try XDG config location
116+
elif [ -s "${XDG_CONFIG_HOME:-$HOME/.config}/nvm/nvm.sh" ]; then
117+
export NVM_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/nvm"
118+
\. "$NVM_DIR/nvm.sh"
119+
else
120+
print_error "Could not find nvm installation"
121+
print_warning "Tried locations: ~/.nvm, /opt/homebrew/opt/nvm, ~/.config/nvm"
122+
echo "Please source nvm manually or install it from: https://github.com/nvm-sh/nvm"
123+
exit 1
124+
fi
90125
fi
91-
if ! nvm list "$version" &> /dev/null; then
126+
127+
# Check if version is already installed
128+
if ! nvm list | grep -q "v${version}"; then
92129
print_warning "Node $version not installed. Installing..."
93-
nvm install "$version"
130+
if ! nvm install "$version"; then
131+
print_error "Failed to install Node $version with nvm"
132+
exit 1
133+
fi
94134
fi
95-
nvm use "$version"
135+
136+
if ! nvm use "$version"; then
137+
print_error "Failed to switch to Node $version"
138+
print_warning "Make sure nvm is properly configured. Try running: nvm use $version"
139+
exit 1
140+
fi
141+
print_success "Switched to Node $version"
142+
;;
143+
rvm)
144+
print_error "Cannot set Node version: rvm doesn't manage Node"
145+
echo "Please install one of the following to manage Node versions:"
146+
echo " - nvm: https://github.com/nvm-sh/nvm"
147+
echo " - mise: https://mise.jdx.dev/ (recommended, manages both Ruby and Node)"
148+
echo " - asdf: https://asdf-vm.com/ (manages both Ruby and Node)"
149+
exit 1
96150
;;
97151
esac
98152
}
@@ -218,6 +272,7 @@ EOF
218272
# mise will auto-detect .tool-versions on next cd
219273
;;
220274
asdf)
275+
# Note: This only affects the script's subshell, not the user's current shell
221276
if [ -f "$HOME/.asdf/asdf.sh" ]; then
222277
source "$HOME/.asdf/asdf.sh"
223278
fi
@@ -325,6 +380,7 @@ EOF
325380
# mise will auto-detect .tool-versions on next cd
326381
;;
327382
asdf)
383+
# Note: This only affects the script's subshell, not the user's current shell
328384
if [ -f "$HOME/.asdf/asdf.sh" ]; then
329385
source "$HOME/.asdf/asdf.sh"
330386
fi

0 commit comments

Comments
 (0)