Skip to content

Commit 62103d0

Browse files
justin808claude
andauthored
Port Conductor multi-version-manager support from react_on_rails#2302 (#692)
* Port Conductor config multi-version-manager support from react_on_rails#2302 - Add bin/conductor-exec wrapper for Conductor environments - Update conductor-setup.sh to detect mise/asdf/direct PATH - Use bin/conductor-exec in conductor.json scripts - Add test and lint scripts to conductor.json The wrapper uses mise exec when available, falling back to direct execution for non-mise users (asdf, rbenv, nvm, nodenv). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Add CLAUDE.md with Conductor compatibility docs Port documentation from react_on_rails#2301 explaining how to use bin/conductor-exec wrapper for version manager compatibility. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent ce0aef6 commit 62103d0

File tree

4 files changed

+166
-8
lines changed

4 files changed

+166
-8
lines changed

CLAUDE.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# React Webpack Rails Tutorial - Development Guide
2+
3+
## Build and Test Commands
4+
5+
```bash
6+
# Run development server
7+
bin/dev
8+
9+
# Run tests
10+
bundle exec rspec
11+
12+
# Run linting
13+
bundle exec rubocop
14+
15+
# Auto-fix linting issues
16+
bundle exec rubocop -a
17+
```
18+
19+
## Conductor Compatibility (Version Managers)
20+
21+
### Problem
22+
23+
Conductor runs commands in a non-interactive shell that doesn't source `.zshrc`. This means version manager shell hooks (like mise's PATH reordering based on `.tool-versions`) never run. Commands will use system Ruby/Node instead of project-specified versions.
24+
25+
**Symptoms:**
26+
- `ruby --version` returns system Ruby (e.g., 2.6.10) instead of project Ruby (e.g., 3.4.3)
27+
- Pre-commit hooks fail with wrong tool versions
28+
- `bundle` commands fail due to incompatible Ruby versions
29+
- Node/pnpm commands use wrong Node version
30+
31+
### Solution
32+
33+
Use the `bin/conductor-exec` wrapper to ensure commands run with correct tool versions:
34+
35+
```bash
36+
# Instead of:
37+
ruby --version
38+
bundle exec rubocop
39+
pnpm install
40+
git commit -m "message"
41+
42+
# Use:
43+
bin/conductor-exec ruby --version
44+
bin/conductor-exec bundle exec rubocop
45+
bin/conductor-exec pnpm install
46+
bin/conductor-exec git commit -m "message" # Pre-commit hooks work correctly
47+
```
48+
49+
The wrapper:
50+
- Uses `mise exec` when mise is available
51+
- Falls back to direct execution for non-mise users (asdf, rbenv, nvm, nodenv)
52+
53+
### Reference
54+
55+
See [react_on_rails-demos#105](https://github.com/shakacode/react_on_rails-demos/issues/105) for detailed problem analysis and solution development.

bin/conductor-exec

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env zsh
2+
# Wrapper script to run commands in Conductor with proper tool versions
3+
# Usage: bin/conductor-exec <command> [args...]
4+
#
5+
# This is needed because Conductor (and other non-interactive shells) don't
6+
# source .zshrc, so version manager PATH configuration isn't active by default.
7+
#
8+
# - If mise is available: uses `mise exec` for correct tool versions
9+
# - Otherwise: falls back to direct execution (for asdf/rbenv/nvm users)
10+
#
11+
# Examples:
12+
# bin/conductor-exec ruby --version # Uses correct Ruby version
13+
# bin/conductor-exec bundle exec rubocop # Correct Ruby for linting
14+
# bin/conductor-exec git commit -m "msg" # Pre-commit hooks work correctly
15+
# bin/conductor-exec pnpm install # Uses correct Node version
16+
#
17+
# See: https://github.com/shakacode/react_on_rails-demos/issues/105
18+
19+
if command -v mise &> /dev/null; then
20+
exec mise exec -- "$@"
21+
else
22+
# Fall back to direct execution for non-mise users
23+
exec "$@"
24+
fi

conductor-setup.sh

Lines changed: 84 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,107 @@
1-
#!/bin/bash
1+
#!/bin/zsh
22
set -e
33

44
echo "🚀 Setting up React on Rails workspace..."
55

6+
# Detect and initialize version manager
7+
# Supports: mise, asdf, or direct PATH (rbenv/nvm/nodenv already in PATH)
8+
VERSION_MANAGER="none"
9+
10+
echo "📋 Detecting version manager..."
11+
12+
if command -v mise &> /dev/null; then
13+
VERSION_MANAGER="mise"
14+
echo "✅ Found mise"
15+
# Trust mise config for current directory only and install tools
16+
mise trust 2>/dev/null || true
17+
mise install
18+
elif [[ -f ~/.asdf/asdf.sh ]]; then
19+
VERSION_MANAGER="asdf"
20+
source ~/.asdf/asdf.sh
21+
echo "✅ Found asdf (from ~/.asdf/asdf.sh)"
22+
elif command -v asdf &> /dev/null; then
23+
VERSION_MANAGER="asdf"
24+
# For homebrew-installed asdf
25+
if [[ -f /opt/homebrew/opt/asdf/libexec/asdf.sh ]]; then
26+
source /opt/homebrew/opt/asdf/libexec/asdf.sh
27+
fi
28+
echo "✅ Found asdf"
29+
else
30+
echo "ℹ️ No version manager detected, using system PATH"
31+
echo " (Assuming rbenv/nvm/nodenv or system tools are already configured)"
32+
fi
33+
34+
# Helper function to run commands with the detected version manager
35+
run_cmd() {
36+
if [[ "$VERSION_MANAGER" == "mise" ]] && [[ -x "bin/conductor-exec" ]]; then
37+
bin/conductor-exec "$@"
38+
else
39+
"$@"
40+
fi
41+
}
42+
643
# Note: This project requires Ruby 3.4.6.
744
# Please ensure you have the correct Ruby version active before running this script.
845

46+
# Check required tools
47+
echo "📋 Checking required tools..."
48+
run_cmd ruby --version >/dev/null 2>&1 || { echo "❌ Error: Ruby is not installed or not in PATH."; exit 1; }
49+
run_cmd node --version >/dev/null 2>&1 || { echo "❌ Error: Node.js is not installed or not in PATH."; exit 1; }
50+
51+
# Check Ruby version
52+
RUBY_VERSION=$(run_cmd ruby -v | awk '{print $2}')
53+
MIN_RUBY_VERSION="3.0.0"
54+
if [[ $(echo -e "$MIN_RUBY_VERSION\n$RUBY_VERSION" | sort -V | head -n1) != "$MIN_RUBY_VERSION" ]]; then
55+
echo "❌ Error: Ruby version $RUBY_VERSION is too old. This project requires Ruby >= 3.0.0"
56+
echo " Please upgrade Ruby using your version manager or system package manager."
57+
exit 1
58+
fi
59+
echo "✅ Ruby version: $RUBY_VERSION"
60+
61+
# Check Node version
62+
NODE_VERSION=$(run_cmd node -v | cut -d'v' -f2)
63+
MIN_NODE_VERSION="20.0.0"
64+
if [[ $(echo -e "$MIN_NODE_VERSION\n$NODE_VERSION" | sort -V | head -n1) != "$MIN_NODE_VERSION" ]]; then
65+
echo "❌ Error: Node.js version v$NODE_VERSION is too old. This project requires Node.js >= 20.0.0"
66+
echo " Please upgrade Node.js using your version manager or system package manager."
67+
exit 1
68+
fi
69+
echo "✅ Node.js version: v$NODE_VERSION"
70+
971
# Copy environment files if they exist in the root
10-
if [ -f "$CONDUCTOR_ROOT_PATH/.env" ]; then
72+
if [[ -f "$CONDUCTOR_ROOT_PATH/.env" ]]; then
1173
cp "$CONDUCTOR_ROOT_PATH/.env" .env
1274
echo "✅ Copied .env file from root"
13-
elif [ -f "$CONDUCTOR_ROOT_PATH/.env.example" ]; then
75+
elif [[ -f "$CONDUCTOR_ROOT_PATH/.env.example" ]]; then
1476
cp "$CONDUCTOR_ROOT_PATH/.env.example" .env
1577
echo "✅ Copied .env.example to .env"
1678
fi
1779

18-
if [ -f "$CONDUCTOR_ROOT_PATH/config/database.yml" ]; then
80+
if [[ -f "$CONDUCTOR_ROOT_PATH/.env.local" ]]; then
81+
cp "$CONDUCTOR_ROOT_PATH/.env.local" .env.local
82+
echo "✅ Copied .env.local file from root"
83+
fi
84+
85+
if [[ -f "$CONDUCTOR_ROOT_PATH/config/database.yml" ]]; then
1986
cp "$CONDUCTOR_ROOT_PATH/config/database.yml" config/database.yml
2087
echo "✅ Copied database.yml from root"
21-
elif [ -f "config/database.yml.example" ]; then
88+
elif [[ -f "config/database.yml.example" ]]; then
2289
cp config/database.yml.example config/database.yml
2390
echo "✅ Copied database.yml.example to database.yml"
2491
fi
2592

2693
# Run the standard Rails setup script
2794
echo "🔧 Running Rails setup script..."
28-
bin/setup --skip-server
95+
run_cmd bin/setup --skip-server
2996

30-
echo "✨ Setup complete! You can now run the development server."
97+
echo "✨ Setup complete!"
98+
echo ""
99+
echo "📚 Key commands:"
100+
echo " • bin/dev - Start development server"
101+
echo " • bundle exec rspec - Run tests"
102+
echo " • bundle exec rubocop - Run Ruby linting"
103+
echo ""
104+
if [[ "$VERSION_MANAGER" == "mise" ]]; then
105+
echo "💡 Tip: Use 'bin/conductor-exec <command>' if tool versions aren't detected correctly."
106+
fi
107+
echo "⚠️ Remember: Always run 'bundle exec rubocop' before committing!"

conductor.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{
22
"scripts": {
33
"setup": "./conductor-setup.sh",
4-
"run": "bin/dev",
4+
"run": "bin/conductor-exec bin/dev",
5+
"test": "bin/conductor-exec bundle exec rspec",
6+
"lint": "bin/conductor-exec bundle exec rubocop",
57
"archive": ""
68
},
79
"runScriptMode": "nonconcurrent"

0 commit comments

Comments
 (0)