Skip to content

Conversation

@justin808
Copy link
Member

@justin808 justin808 commented Dec 9, 2025

Summary

Adds a unified bin/setup script that installs all dependencies across the monorepo, making it easy for new contributors to get started quickly with a single command.

Changes

  • Add bin/setup script for unified development environment setup
  • Update CONTRIBUTING.md with quick setup instructions referencing the new script
  • Script handles all directories: root, react_on_rails/spec/dummy, and react_on_rails_pro/* (if present)

Features

  • Prerequisite checking (pnpm, bundle, node, ruby) with version display
  • Colored output with clear step indicators
  • Path verification to ensure script is run from correct directory
  • Build artifact verification after rake node_package
  • Graceful handling of missing directories (e.g., react_on_rails_pro for non-Pro contributors)
  • Uses --frozen-lockfile for pnpm to match CI behavior
  • --skip-pro flag for contributors without Pro access
  • --help flag for usage information
  • Elapsed time display at completion
  • Git hooks documentation in completion message

Manual Testing Requirements

Before merging, verify the following (per CLAUDE.md requirements):

Test Scenarios

  • Fresh clone: Test in a fresh clone (not existing dev environment)
  • Pro directory present: Test with Pro directory available
  • Pro directory absent: Test without Pro directory (or use --skip-pro)
  • --skip-pro flag: Verify it correctly skips Pro setup

Build Verification

After setup completes, verify:

ls -la packages/react-on-rails/lib/ReactOnRails.full.js

Post-Setup Commands

Verify these work after setup:

rake              # Should run tests successfully
rake lint         # Should pass linting

Additional Tests

  • Test running from different working directories
  • Verify --help shows usage
  • Verify unknown options show error message

Usage

# First, verify your versions match the project requirements
ruby -v  # Should show 3.4.x or version in .ruby-version
node -v  # Should show 22.x or version in .node-version

# Then run the setup script
bin/setup

# Or skip Pro setup (for contributors without Pro access)
bin/setup --skip-pro

Test plan

  • Tested bin/setup --help displays usage correctly
  • Tested error handling for unknown flags
  • Tested path verification logic (missing Rakefile detection)
  • Verified trailing newlines on all files
  • Pre-commit hooks pass

🤖 Generated with Claude Code

This adds a top-level setup script that installs all dependencies across
the monorepo with a single command, making it easier for new contributors
to get started.

The script:
- Checks for required tools (pnpm, bundler, node, ruby)
- Installs root pnpm and bundle dependencies
- Builds the node package via rake node_package
- Sets up react_on_rails/spec/dummy
- Sets up react_on_rails_pro and its dummy apps (if present)
- Provides clear progress output and helpful error messages

Fixes #2190

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 9, 2025

Warning

Rate limit exceeded

@justin808 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 14 minutes and 1 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 3acff76 and 7bd92c7.

📒 Files selected for processing (2)
  • CONTRIBUTING.md (2 hunks)
  • bin/setup (1 hunks)
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch jg/fix-2190

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@claude
Copy link

claude bot commented Dec 9, 2025

Code Review

Thanks for this contribution! This is a useful addition that will improve the onboarding experience for new contributors. Here's my review:

✅ Strengths

  1. Clear purpose and documentation - The help text and comments explain exactly what the script does
  2. Good error handling - Uses set -e and checks for prerequisites before proceeding
  3. User-friendly output - Color-coded messages and clear progress indicators
  4. Handles missing directories gracefully - Skips react_on_rails_pro directories if not present
  5. Follows conventions - Uses bash best practices like `` for script location
  6. Good CONTRIBUTING.md updates - Documents both quick and manual setup approaches

🔍 Potential Issues & Suggestions

1. Missing RuboCop Check (CRITICAL per CLAUDE.md)

Per the project's CLAUDE.md requirements:

⚠️ CRITICAL REQUIREMENTS
BEFORE EVERY COMMIT/PUSH:

  1. ALWAYS run bundle exec rubocop and fix ALL violations

Please run:

bundle exec rubocop bin/setup

If there are any violations, fix them before merging.

2. Potential Shellcheck Issues

Consider running shellcheck on the script to catch any potential issues:

shellcheck bin/setup

Common issues to watch for:

  • Unquoted variables (though I see good quoting in the diff)
  • Path handling edge cases

3. Error Handling for rake node_package

The script runs rake node_package (line 156) in the root directory. If this fails, the entire setup will abort due to set -e. Consider:

  • Adding a more informative error message if this specific step fails
  • This is a critical step, so aborting is correct, but a helpful error message would be nice

Example:

print_step "Building node package..."
if rake node_package; then
  print_success "Node package built"
else
  print_error "Failed to build node package. This is required for development."
  exit 1
fi

4. Test Plan Incomplete

The PR description shows:

- [ ] Manual test of full setup on a fresh clone

Per CLAUDE.md guidelines, this should be completed before merging:

CRITICAL - LOCAL TESTING REQUIREMENTS:

  1. NEVER claim a test is "fixed" without running it locally first

Please test this script on a fresh clone to ensure it works end-to-end. Specific scenarios to test:

  • Fresh clone without any dependencies installed
  • Partial setup (e.g., root deps installed, but not dummy apps)
  • With and without react_on_rails_pro directory

5. Consider Adding Git Hooks Setup

Per CLAUDE.md:

🚀 AUTOMATIC: Git hooks are installed automatically during setup

Does bundle install automatically set up the git hooks? If not, the setup script should explicitly mention this or ensure hooks are installed. Verify that after running bin/setup, the pre-commit hooks are active.

6. Minor: CONTRIBUTING.md Formatting

Line 32 removes cd react_on_rails/ from the update command. This is correct since we're running from root, but ensure this command actually works from root:

bundle && pnpm install && rake shakapacker_examples:gen_all && rake node_package && rake

Test this command from the root directory to confirm it works as documented.

🧪 Testing Recommendations

Before merging, please verify:

  1. # Test on a fresh clone
    git clone <repo-url> /tmp/react-on-rails-test
    cd /tmp/react-on-rails-test
    bin/setup
  2. # Test partial setup scenario
    # (simulate a contributor who ran some commands manually)
    bundle install
    bin/setup  # Should handle already-installed deps gracefully
  3. # Verify the documented update command works
    bundle && pnpm install && rake shakapacker_examples:gen_all && rake node_package && rake

📋 Checklist Before Merge

  • Run bundle exec rubocop bin/setup and fix any violations
  • Run shellcheck bin/setup and address any warnings
  • Test script on a fresh clone
  • Verify git hooks are installed after setup
  • Confirm the CONTRIBUTING.md command works from root directory
  • Mark the test plan checkbox as complete

🎯 Overall Assessment

This is a solid contribution that will definitely improve the developer experience. The code quality is good, and the approach is sound. Just need to complete the testing and address the linting requirements per the project's strict guidelines.

Great work on improving the onboarding process! 🚀

@claude
Copy link

claude bot commented Dec 9, 2025

Code Review

Great work on adding a unified setup script! This will significantly improve the developer onboarding experience. Here's my detailed feedback:

✅ Strengths

  1. Good UX: Clear colored output, helpful error messages, and progress indicators make the script user-friendly
  2. Idempotent: Uses bundle check to skip unnecessary reinstalls - following Rails conventions
  3. Robust: Proper prerequisite checking with helpful installation links
  4. Monorepo-aware: Correctly handles both open-source and Pro packages
  5. Documentation: Well-documented in CONTRIBUTING.md with both quick and manual setup paths

🔍 Code Quality Issues

Critical: Error Handling for rake node_package

Location: bin/setup:158

rake node_package
print_success "Node package built"

Issue: The script has set -e which will exit on errors, but the success message is unconditional. If rake node_package fails, the script exits but the user sees no context about what failed.

Recommendation: Add error context:

print_step "Building node package..."
if rake node_package; then
  print_success "Node package built"
else
  print_error "Failed to build node package"
  echo "This runs: pnpm run build && pnpm yalc:publish"
  exit 1
fi

Security: Command Injection via Directory Names

Location: bin/setup:103-134

Issue: The install_dependencies function uses unsanitized directory paths in cd commands. If a directory name contains special characters (unlikely but possible), it could cause issues.

Current Risk: Low (we control directory names)

Best Practice: Quote variables:

cd "$dir"

This is already done on line 113, so it's actually fine. No change needed.

Performance: Redundant Directory Changes

Location: bin/setup:133

cd ""

Issue: Every install_dependencies call returns to ROOT_DIR, but the next call immediately changes to a different directory. This is harmless but slightly inefficient.

Suggestion: Not critical, but could remove the cd "" from install_dependencies since main() always provides absolute paths. This is a very minor optimization.

🧪 Testing Gaps

From PR description:

  • Manual test of full setup on a fresh clone

This is CRITICAL per CLAUDE.md guidelines:

Per the project's own documentation:

CRITICAL - LOCAL TESTING REQUIREMENTS:

  1. NEVER claim a test is "fixed" without running it locally first

Recommendations:

  1. Test in a Docker container to simulate a fresh environment:

    docker run -it --rm -v /path/to/repo:/workspace ruby:3.4 bash
    cd /workspace
    ./bin/setup
  2. Test the failure modes:

    • Run with missing prerequisites (uninstall pnpm temporarily)
    • Run in a directory without react_on_rails_pro
    • Run with corrupted Gemfile.lock
  3. Test idempotency: Run bin/setup twice in a row and verify it's fast the second time

📝 Documentation

Missing: Relationship to Existing Scripts

The CONTRIBUTING.md doesn't explain that react_on_rails/spec/dummy/bin/setup still exists and serves a different purpose (sets up the database, clears logs, etc.). This might confuse contributors.

Suggestion: Add a note:

**Note**: The root `bin/setup` installs all dependencies across the monorepo. Individual apps like `react_on_rails/spec/dummy/` have their own `bin/setup` scripts that handle app-specific tasks like database setup.

CONTRIBUTING.md Change Analysis

The removal of cd react_on_rails/ in the manual setup is correct since we're now at the root. Good catch!

🔒 Security Considerations

Overall: ✅ No security issues found

  • Script properly validates prerequisites before executing commands
  • No dynamic command construction from user input
  • Proper use of set -e to fail fast

⚡ Performance Considerations

Current: The script runs sequentially, which is correct and safe.

Future optimization: For large monorepos, you could parallelize independent install_dependencies calls, but this adds complexity and the current approach is fine.

🎯 Recommendations Summary

Must Fix Before Merge:

  1. ✅ Manual testing in a fresh environment (per project guidelines)

Should Fix:

  1. Add error context to rake node_package step (makes debugging easier)

Nice to Have:

  1. Add note about relationship between root bin/setup and app-specific bin/setup scripts
  2. Test failure modes to ensure error messages are helpful

Overall Assessment

This is a solid contribution that addresses a real pain point (#2190). The code is well-structured, follows Bash best practices, and integrates nicely with the existing tooling. The main blocker is completing the manual testing in a fresh environment as required by the project's testing guidelines.

Verdict: Approve after manual testing is completed and documented. ✨

@claude
Copy link

claude bot commented Dec 9, 2025

Code Review for PR #2191: Add bin/setup for unified development environment setup

✅ Overall Assessment

This is a well-implemented enhancement that addresses a real developer pain point. The script follows bash best practices and provides a great DX improvement. I have a few suggestions for improvement below.


🎯 Strengths

  1. Clear UX: Excellent use of colored output, progress messages, and helpful error reporting
  2. Idempotent design: Uses bundle check to avoid redundant installs
  3. Error handling: set -e ensures failures don't go unnoticed
  4. Good documentation: Comprehensive help text and inline comments
  5. Prerequisite checking: Validates required tools before running
  6. Proper path handling: Uses absolute paths from script location

🔍 Issues & Suggestions

1. Path Inconsistency - Potentially Critical

Issue: The script installs dependencies for react_on_rails/spec/dummy:

install_dependencies "$ROOT_DIR/react_on_rails/spec/dummy" "react_on_rails/spec/dummy"

But based on the directory structure, the path should be $ROOT_DIR/spec/dummy (no react_on_rails/ prefix).

Evidence: The existing dummy app setup script is at react_on_rails/spec/dummy/bin/setup, suggesting the working directory structure is already at root, not nested.

Impact: This will cause the script to skip dummy app setup with a warning, which defeats part of its purpose.

Fix: Update line 160 to:

install_dependencies "$ROOT_DIR/spec/dummy" "spec/dummy"

And similarly for Pro paths if they follow the same pattern.


2. Missing CONTRIBUTING.md Path Update

Issue: CONTRIBUTING.md line 32 still references:

cd react_on_rails/
bundle && pnpm install && rake shakapacker_examples:gen_all && rake node_package && rake

This cd react_on_rails/ suggests the old nested structure. If the repo root IS the react_on_rails directory, this should just be:

bundle && pnpm install && rake shakapacker_examples:gen_all && rake node_package && rake

Fix: Remove the cd react_on_rails/ line (already done in the diff, good!)


3. Test Coverage Missing

Issue: The PR checklist shows:

  • Script syntax validated with bash -n
  • Script help works: bin/setup --help
  • Pre-commit hooks pass
  • Manual test of full setup on a fresh clone ⚠️

Per CLAUDE.md guidelines:

NEVER claim a test is "fixed" without running it locally first

While this is a new feature (not a fix), the same principle applies: infrastructure scripts MUST be tested manually.

Recommendation:

  • Test in a fresh clone (or at minimum, after rm -rf node_modules)
  • Verify all paths resolve correctly
  • Confirm the script completes successfully
  • Document the test results before merging

4. Minor: Inconsistent Naming Convention

Issue: The script checks for react_on_rails_pro/spec/dummy and react_on_rails_pro/spec/execjs-compatible-dummy, but installs react_on_rails/spec/dummy.

The first is react_on_rails_pro/, the second is react_on_rails/ - this suggests structural inconsistency.

Verification needed: Confirm the actual directory structure matches the script's assumptions.


🔒 Security Review

No security concerns identified:

  • No user input is executed without validation
  • No credential handling
  • Proper escaping in string interpolations
  • Safe use of set -e

🚀 Performance Considerations

Minor optimization opportunity: The bundle check optimization is great, but consider adding similar for pnpm:

if pnpm install --frozen-lockfile --offline &> /dev/null; then
  print_success "JavaScript dependencies already satisfied"
else
  pnpm install
  print_success "JavaScript dependencies installed"
fi

This would make subsequent runs faster (though not critical).


📝 Documentation

Suggestion: Consider adding a note about what to do if the script fails midway:

  • Is it safe to re-run?
  • Should users clean up first?

The script is idempotent, so this should be fine, but explicit documentation helps.


✅ Required Actions Before Merge

  1. CRITICAL: Verify and fix the directory paths (see Issue TODO for first version #1)
  2. MANDATORY: Run bin/setup in a fresh clone per CLAUDE.md requirements
  3. Recommended: Add offline check for pnpm (optional performance improvement)

📋 Checklist Review

Based on CLAUDE.md requirements:

  • ✅ Code quality and best practices: Excellent
  • ⚠️ Potential bugs: Path issue needs verification
  • ✅ Performance: Good, with minor optimization opportunity
  • ✅ Security: No concerns
  • ⚠️ Test coverage: Manual testing required before merge

Great work overall! This will significantly improve the contributor onboarding experience. Just need to verify those paths and complete the manual testing. 🚀

@claude
Copy link

claude bot commented Dec 9, 2025

Code Review - PR #2191: Add bin/setup for unified development environment setup

Overall Assessment

This is a well-structured PR that adds a useful developer experience improvement. The script follows best practices and aligns with the repository's guidelines. I found one critical issue and several suggestions for improvement.


Critical Issues

1. Lint Failure in CI

The "Lint JS and Ruby" workflow failed. According to CLAUDE.md:

MANDATORY BEFORE GIT PUSH: bundle exec rubocop and fix ALL violations + ensure trailing newlines

Action Required:

bundle exec rubocop
# Fix any violations, then commit the changes

Code Quality & Best Practices

What's Good:

  1. Excellent documentation: Help text is clear and comprehensive
  2. Good error handling: Uses set -e to exit on errors
  3. Prerequisite checks: Validates required tools before starting
  4. Clear output: Color-coded messages make progress easy to follow
  5. Script portability: Uses SCRIPT_DIR for path resolution
  6. Follows conventions: Aligns with existing .claude/docs/ guidance

Suggestions for Improvement:

1. Consider adding ShellCheck validation

The test plan mentions bash -n but ShellCheck provides deeper validation:

shellcheck bin/setup

2. Consider adding a dry-run mode

For transparency and safety, allow users to see what would happen:

# Usage: bin/setup --dry-run

3. Validate Node/Ruby versions

The script could check that versions meet minimum requirements per .tool-versions.

4. Exit code consistency

Consider tracking warnings and exiting with non-zero if any optional components fail, so CI can catch issues.


Security Considerations

Good:

  • No user input is executed unsafely
  • Paths are properly quoted
  • Uses set -e to fail fast

Minor concern:

  • The script runs rake node_package which executes code. This is fine since the Rakefile is in the trusted repo.

Test Coverage

From PR Description:

  • ✅ Script syntax validated with bash -n
  • ✅ Script help works: bin/setup --help
  • ✅ Pre-commit hooks pass
  • ❌ Manual test of full setup on a fresh clone (marked incomplete)

Recommendation: Test in a fresh clone or Docker container to verify the full flow works as expected.


Documentation Updates

CONTRIBUTING.md changes look good:

  • Clear quick setup instructions
  • Maintains manual setup as alternative
  • Properly documents what the script does

Suggestion: Consider adding a troubleshooting section to CONTRIBUTING.md for common setup issues (permission denied, version mismatches, etc.).


Performance Considerations

The script runs sequentially, which is appropriate for a setup script. The output is clear and progress is well-communicated.


Alignment with Project Requirements

Follows CLAUDE.md guidelines:

  • ✅ Uses pnpm (not npm/yarn)
  • ✅ Installs dependencies correctly
  • ✅ Builds node package
  • ✅ Sets up all required directories

Aligns with .claude/docs/testing-build-scripts.md:

  • Script will be tested during CI
  • Handles build artifacts properly

Final Checklist

Before merging:

  • Fix lint failures (bundle exec rubocop)
  • Ensure bin/setup has executable permissions (appears to be set)
  • Ensure all files end with trailing newlines
  • Test in fresh clone (per test plan)
  • Consider running shellcheck bin/setup
  • Verify all CI checks pass

Summary

This is a valuable contribution that will significantly improve the developer onboarding experience. The code is well-written and follows bash scripting best practices. Once the lint issues are resolved, this will be ready to merge!

Estimated time to fix: 5-10 minutes (run bundle exec rubocop and commit fixes)

Great work on making the setup process more accessible! 🎉

@claude
Copy link

claude bot commented Dec 9, 2025

Code Review

Thank you for this helpful contribution! The bin/setup script will make onboarding much smoother for new contributors. Here's my detailed review:

✅ Strengths

  1. Excellent UX: Clear colored output, helpful error messages, and progress indicators make the script very user-friendly
  2. Comprehensive coverage: Handles all parts of the monorepo (root, dummy apps, pro packages)
  3. Good error handling: Uses set -e and checks prerequisites before proceeding
  4. Smart dependency checks: Uses bundle check to avoid unnecessary reinstalls
  5. Well-documented: Clear help message and inline comments explain what's happening
  6. Follows conventions: Matches the style and approach of other setup scripts in the ecosystem

🔍 Suggestions for Improvement

1. Missing RuboCop compliance check

According to CLAUDE.md, RuboCop must pass before every commit. Consider adding a final validation step:

# After all setup is complete
print_step "Running linters to verify setup..."
if bundle exec rubocop &> /dev/null; then
  print_success "RuboCop passed"
else
  print_warning "RuboCop found issues - run 'bundle exec rubocop -a' to auto-fix"
fi

2. Git hooks installation clarification

The script doesn't explicitly mention git hooks installation. According to CLAUDE.md:

Git hooks are installed automatically when you run the standard setup commands

Consider adding a note in the success message or a verification step:

# In the final success message
echo "  bin/setup --help  # View setup options"
echo ""
echo "Note: Git hooks for automatic linting are installed and active."

3. Error handling for rake node_package

The rake node_package command is critical but has no error handling. If it fails, the script will exit due to set -e, but the error message might not be clear. Consider:

print_step "Building node package..."
if rake node_package; then
  print_success "Node package built"
else
  print_error "Failed to build node package"
  echo "This is a critical step. Please check the error output above."
  exit 1
fi

4. CONTRIBUTING.md: Minor inconsistency

Line 29: The path cd react_on_rails/ is removed, but the command is still shown as if run from root. Consider clarifying:

- After updating code via Git, to prepare all examples (run from root):

```sh
bundle && pnpm install && rake shakapacker_examples:gen_all && rake node_package && rake

### 5. **Consider adding a `--skip-pro` flag**

For open-source-only contributors, it might be useful to skip Pro setup:

```bash
SKIP_PRO=false

# In show_help
echo "  --skip-pro  Skip react_on_rails_pro setup (for open-source only)"

# Parse arguments
while [[ $# -gt 0 ]]; do
  case $1 in
    --skip-pro)
      SKIP_PRO=true
      shift
      ;;
    # ... other args
  esac
done

# In main()
if [ "$SKIP_PRO" = false ] && [ -d "$ROOT_DIR/react_on_rails_pro" ]; then
  # ... Pro setup
fi

6. Testing gap noted in PR description

The PR description shows:

  • Manual test of full setup on a fresh clone

This is critical! According to CLAUDE.md:

CRITICAL: NEVER claim a test is "fixed" without running it locally first

Before merging, please test on a fresh clone or clearly mark this as untested. The script modifies multiple directories and installs dependencies - a fresh clone test is essential.

🔒 Security Review

  • ✅ No unsafe variable interpolation
  • ✅ Proper quoting of paths
  • ✅ No external downloads or curl | bash patterns
  • ✅ Only runs commands that users would run manually anyway
  • ✅ Uses set -e to fail fast on errors

🎯 Best Practices Compliance

  • ✅ Follows monorepo structure awareness
  • ✅ Handles optional Pro package correctly
  • ✅ Uses pnpm (not npm/yarn) per project standards
  • ⚠️ Missing explicit RuboCop validation (see suggestion TODO for first version #1)
  • ⚠️ Should be tested on fresh clone before merge (see suggestion Detailed Setup and Usage Docs #6)

📊 Overall Assessment

This is a high-quality contribution that will significantly improve the contributor experience. The code is well-structured, safe, and comprehensive. The suggestions above are minor enhancements that would make it even better.

Recommendation: Approve with minor suggestions. The only blocker would be completing the manual test on a fresh clone, which is critical per CLAUDE.md guidelines.

Great work! 🎉

@claude
Copy link

claude bot commented Dec 9, 2025

Code Review: bin/setup Script

Thank you for creating this unified setup script! This is a valuable addition that will significantly improve the contributor onboarding experience. I've reviewed the code and have several suggestions for improvement.


🟢 Strengths

  1. Clear structure and helpful output - The colored output and progress indicators make the setup process easy to follow
  2. Prerequisite checking - Validates required tools before attempting installation
  3. Idempotent design - Safe to run multiple times (using bundle check)
  4. Good documentation - Help text and comments explain what the script does
  5. Handles optional directories - Gracefully skips react_on_rails_pro if not present

🔴 Critical Issues

1. Missing Git Hooks Installation

Severity: High

According to CLAUDE.md:

🚀 AUTOMATIC: Git hooks are installed automatically during setup
Git hooks will automatically run linting on all changed files (staged + unstabled + untracked) before each commit

The script does NOT install git hooks (lefthook), which is a critical part of the development setup. Without this, contributors will:

  • Miss pre-commit linting
  • Potentially push code that fails CI due to linting issues
  • Not have the automatic formatting experience mentioned in the docs

Fix: Add after the root bundle install:

# Install git hooks (after root bundle install)
print_step "Installing git hooks..."
bundle exec lefthook install
print_success "Git hooks installed"

2. Incorrect Reference in CONTRIBUTING.md

Line 33 in CONTRIBUTING.md:

bundle && pnpm install && rake shakapacker_examples:gen_all && rake node_package && rake

This command still assumes you're in the react_on_rails/ subdirectory (removed on line 33), but the commands should now run from the root directory. The documentation is inconsistent.

Recommendation: Either:

  • Keep the cd react_on_rails/ line if this command is meant for subdirectory execution, OR
  • Clarify that this command should be run from the root directory

🟡 Moderate Issues

3. Missing Lefthook Prerequisite Check

The script checks for pnpm, bundle, node, and ruby, but doesn't verify that lefthook is available. Since lefthook comes from bundler, this should be checked after bundle install or documented as an expectation.

4. Incomplete Setup Compared to Manual Instructions

CLAUDE.md mentions several additional steps that bin/setup doesn't perform:

  • Missing: rake shakapacker_examples:gen_all (generates test examples)
  • Missing: Running initial rake to verify setup works

From CLAUDE.md:

bundle && pnpm install && rake shakapacker_examples:gen_all && rake node_package && rake

Your script only runs rake node_package. Consider adding:

# Generate test examples (after node_package)
print_step "Generating Shakapacker examples..."
rake shakapacker_examples:gen_all
print_success "Shakapacker examples generated"

# Optionally run tests to verify setup
print_step "Running initial tests to verify setup..."
echo "This may take a few minutes..."
rake all_but_examples

Or at minimum, mention in the final success message that users should run rake shakapacker_examples:gen_all next.

5. Error Handling Could Be More Specific

The script uses set -e which will exit on any error, but it doesn't provide context about what failed. Consider adding error traps:

trap 'print_error "Setup failed at line $LINENO. Check the output above for details."' ERR

🔵 Minor Suggestions

6. Consider Adding a --skip-pro Flag

For open-source contributors who don't have access to the Pro package, you could add an option to explicitly skip Pro setup:

# Usage: bin/setup --skip-pro

7. Improve "Missing Prerequisites" Message for Bundler

The current message suggests gem install bundler, but doesn't mention that the Ruby version manager (rvm/rbenv) should be set up first. Consider:

bundler)
  echo "  - bundler: Install Ruby first (using rvm/rbenv), then: gem install bundler"
  ;;

8. Add Verification Step

After successful setup, consider adding a verification command in the success message:

echo "To verify your setup:"
echo "  rake lint         # Verify linters work"
echo "  bundle exec lefthook run pre-commit --all-files  # Test git hooks"

📋 Testing Recommendations

Based on CLAUDE.md's critical testing requirements:

Before merging, please verify:

  1. Test on a completely fresh clone (required by CLAUDE.md)

    # In a temporary directory
    git clone <repo-url> test-setup
    cd test-setup
    bin/setup
  2. Verify git hooks are working after setup

    echo "test" > test.rb  # No newline
    git add test.rb
    git commit -m "test"  # Should fail due to trailing newline check
  3. Test with react_on_rails_pro present

  4. Test with react_on_rails_pro absent

  5. Verify all critical paths exist after setup:

    ls -la packages/react-on-rails/lib/ReactOnRails.full.js
    ls -la .git/hooks/pre-commit  # Should exist if lefthook installed

🎯 Summary

Must fix before merge:

  1. Add lefthook installation (critical - breaks documented workflow)
  2. Fix CONTRIBUTING.md path inconsistency

Should fix:
3. Add shakapacker_examples:gen_all or document it in success message
4. Add error context with trap

Nice to have:
5. Add --skip-pro flag
6. Improve bundler installation message
7. Add verification steps to success message


Overall Assessment

This is a well-structured and valuable contribution that will significantly improve the developer onboarding experience. The code quality is good, and the approach is sound. The main gap is the missing git hooks installation, which contradicts the documented "automatic" behavior mentioned in CLAUDE.md.

Once the critical issues are addressed, this will be a great addition to the project! 🎉

@claude
Copy link

claude bot commented Dec 9, 2025

Code Review: bin/setup Script

I've reviewed PR #2191 and have the following feedback:

Strengths

  1. Well-structured and readable: The script follows bash best practices with clear sections and good error handling
  2. Proper error handling: Uses set -e and validates prerequisites before proceeding
  3. User-friendly output: Color-coded messages and progress indicators make it easy to follow
  4. Flexible pathing: Uses SCRIPT_DIR and ROOT_DIR to work from any location
  5. Graceful degradation: Skips missing directories (like Pro) with warnings rather than failing
  6. Good documentation: Inline comments and --help flag explain what the script does

🔍 Issues & Suggestions

1. CRITICAL: Path Verification Missing

Per CLAUDE.md's "Managing File Paths" guidelines, you should verify paths exist before operations:

# In build_node_package(), add verification:
if [ ! -f "$ROOT_DIR/Rakefile" ]; then
  print_error "Rakefile not found. Are you in the correct directory?"
  exit 1
fi

2. Missing Mandatory Post-Setup Validation

According to CLAUDE.md's "Testing Build and Package Scripts" section, the script should verify build artifacts after rake node_package:

# After rake node_package:
if [ ! -f "packages/react-on-rails/lib/ReactOnRails.full.js" ]; then
  print_error "Build failed: ReactOnRails.full.js not found"
  exit 1
fi
print_success "Build artifacts verified"

3. Bundle Check Silent Failures

The bundle check may pass but bundle install could still fail. Consider:

if bundle check &> /dev/null; then
  print_success "Ruby dependencies already satisfied"
else
  if ! bundle install; then
    print_error "Failed to install Ruby dependencies in $name"
    exit 1
  fi
  print_success "Ruby dependencies installed"
fi

4. Missing Git Hooks Setup

According to CONTRIBUTING.md, git hooks are "installed automatically when you run the standard setup commands." Your script should either:

  • Document that hooks are auto-installed by bundler/rake
  • OR explicitly set them up with a message

5. pnpm Install Frozen Lockfile

Per CLAUDE.md testing guidelines, use --frozen-lockfile in CI-like setup:

if [ -f "package.json" ]; then
  echo "  Installing JavaScript dependencies..."
  pnpm install --frozen-lockfile
  print_success "JavaScript dependencies installed"
fi

This ensures lockfile is respected and matches CI behavior.

6. Error Handling for rake node_package

Add error handling:

print_step "Building node package..."
if ! rake node_package; then
  print_error "Failed to build node package"
  exit 1
fi

📋 Testing Recommendations

Before merging, verify (per CLAUDE.md requirements):

  1. ✅ Test in a fresh clone (not existing dev environment)
  2. ✅ Test with Pro directory present
  3. ✅ Test with Pro directory absent
  4. ✅ Verify build artifacts exist after completion:
    ls -la packages/react-on-rails/lib/ReactOnRails.full.js
  5. ✅ Test that subsequent rake command works
  6. ✅ Test running from different working directories

🎯 Minor Improvements

  1. Version checks: Consider showing Node/Ruby/pnpm versions found
  2. Skip option: Add --skip-pro flag for contributors without Pro access
  3. Timing: Show elapsed time at the end

📖 CONTRIBUTING.md Changes

The documentation updates look good! Just one suggestion:

In the Quick Setup section, clarify that Ruby/Node version managers should be configured before running bin/setup, perhaps with an example:

After checking out the repo and ensuring you have Ruby and Node version managers set up with the correct versions active:

# Example: verify versions
ruby -v  # Should show 3.4.x or configured version
node -v  # Should show 22.x or configured version

Then run:
bin/setup

🏁 Summary

This is a great addition that will significantly improve the contributor experience! The main concerns are:

  1. Add path/artifact verification (aligned with CLAUDE.md guidelines)
  2. Improve error handling for critical commands
  3. Use --frozen-lockfile for pnpm installs
  4. Test in a fresh clone before merging

Overall: Approve with changes requested

Great work on following bash best practices and making this contributor-friendly! 🚀

@claude
Copy link

claude bot commented Dec 9, 2025

Code Review: bin/setup Script

Overview

This PR adds a unified bin/setup script for monorepo-wide dependency installation. The script is well-structured and follows the project's conventions. Here's my detailed review:


✅ Strengths

1. Consistent with Existing Scripts

  • Uses the same color scheme and output formatting as other bin scripts
  • Follows the established pattern (e.g., bin/ci-rerun-failures)
  • Proper help message with --help flag

2. Good Error Handling

  • Checks for prerequisites upfront
  • Provides helpful installation instructions when tools are missing
  • Uses set -e to fail fast on errors

3. Clear Documentation

  • Good inline comments
  • CONTRIBUTING.md updates are clear and helpful
  • Bullet points explaining what the script does

4. Idempotent Design

  • Checks if dependencies already satisfied before installing
  • Safe to run multiple times

⚠️ Issues and Recommendations

1. CRITICAL: Use set -euo pipefail instead of set -e

Current: Line 13 uses set -e
Should be: set -euo pipefail

Why? All other bin scripts in the repository use set -euo pipefail:

  • -u: Treats unset variables as errors (prevents silent bugs)
  • -o pipefail: Ensures pipeline failures are caught (e.g., false | true will fail)

This is consistent with bin/ci-rerun-failures, bin/ci-local, bin/ci-switch-config, etc.

Example from bin/ci-rerun-failures:9:

set -euo pipefail

2. Missing: Direct path to script directory is unused

Lines 22-23 define SCRIPT_DIR and ROOT_DIR but the script changes directories frequently using cd. This pattern is inconsistent with the project's philosophy stated in CLAUDE.md:

"Try to maintain your current working directory throughout the session by using absolute paths and avoiding usage of cd."

Current approach:

cd ""
bundle install
cd ""

Better approach (used in other scripts):

(cd "" && bundle install)

This keeps the working directory stable and is safer (subshell exits even if cd fails).

However, for this particular script, the current approach is acceptable since we're explicitly managing state. Consider adding a comment explaining why we're using cd here.


3. Potential Issue: rake node_package may not be in PATH

Line 156 runs rake node_package but doesn't guarantee rake is available via bundler context.

Safer approach:

bundle exec rake node_package

This ensures we're using the correct rake version from the Gemfile.


4. Enhancement: Missing feedback for bundle check path

In install_dependencies function (lines 115-121), when bundle check succeeds, it prints a success message. But when it fails and runs bundle install, there's no intermediate message. Consider:

if bundle check &> /dev/null; then
  print_success "Ruby dependencies already satisfied"
else
  bundle install  # Already has implicit output
  print_success "Ruby dependencies installed"
fi

The current code does this for the success message but not the failure→install path. It's fine as-is, but could be clearer.


5. Test Coverage: Manual testing checkbox not completed

From the PR description:

- [ ] Manual test of full setup on a fresh clone

CRITICAL from CLAUDE.md:

"NEVER claim a test is 'fixed' without running it locally first"

Before merging, this should be tested on a fresh clone. The script is infrastructure code that affects all contributors.

Testing checklist:

# In a separate directory
git clone https://github.com/shakacode/react_on_rails.git
cd react_on_rails
bin/setup

# Verify all dependencies installed
bundle check
pnpm list --depth 0
ls -la packages/react-on-rails/lib/ReactOnRails.full.js

6. Documentation: Path inconsistency in CONTRIBUTING.md

Lines 29-30 of CONTRIBUTING.md say:

"After cloning the repo, run bin/setup from the root directory to install all dependencies."

Then lines 33-35 say:

"After updating code via Git, to prepare all examples:"

bundle && pnpm install && rake shakapacker_examples:gen_all && rake node_package && rake

But this line doesn't specify the directory. Should it start with:

cd /path/to/react_on_rails  # or just assume root?
bundle && pnpm install...

Consider clarifying whether these commands run from root or require a cd first.


🔍 Security Considerations

No major security issues identified

  • No user input is directly executed
  • No network requests without validation
  • Tool checks prevent command injection
  • Proper quoting of variables

🎯 Performance Considerations

Efficient design:

  • bundle check before bundle install (skips unnecessary work)
  • Clear error messages prevent wasted developer time
  • Idempotent design means safe to re-run

Potential optimization:

Consider adding a flag like --skip-pro to skip react_on_rails_pro setup for contributors only working on open source. But this might be premature optimization.


📋 Test Coverage

Good:

  • Syntax validation with bash -n
  • Help flag tested

Missing:

  • Manual test on fresh clone (see Add Unit tests #5 above)
  • Consider adding to CI: a workflow that clones the repo and runs bin/setup to catch regressions

Summary of Required Changes

Must fix before merge:

  1. ✅ Change set -e to set -euo pipefail (line 13)
  2. ✅ Change rake node_package to bundle exec rake node_package (line 156)
  3. Manual test on fresh clone and check the box in PR description

Nice to have:

  1. Consider subshell pattern for cd operations (or add comment explaining why not)
  2. Clarify directory context in CONTRIBUTING.md for the update commands
  3. Consider adding CI test for bin/setup

Final Verdict

This is high-quality work that will significantly improve the contributor experience. The script is well-designed and follows project conventions closely.

After addressing the two critical issues (#1 and #2) and completing the manual testing (#3), this is ready to merge.

Great job on making the monorepo more accessible to new contributors! 🎉


Checklist for Author

Before merging:

  • Change set -e to set -euo pipefail
  • Use bundle exec rake node_package
  • Test on fresh clone (outside this repo)
  • Update test plan checkbox in PR description
  • Consider adding a comment explaining the cd usage pattern

Key improvements based on PR review feedback:

1. Path verification: Added verify_root_directory() to check Rakefile
   and package.json exist before proceeding

2. Build artifact validation: Added verify_build_artifacts() to verify
   packages/react-on-rails/lib/ReactOnRails.full.js exists after build

3. Error handling: Improved bundle install error handling with explicit
   failure detection and messages

4. CI-like behavior: Use pnpm install --frozen-lockfile to match CI and
   ensure lockfile integrity

5. Rake error handling: Added error handling for rake node_package

6. Version display: Show Ruby, Node, pnpm, and Bundler versions during
   prerequisites check

7. --skip-pro flag: Added for contributors without Pro access

8. Elapsed time: Display total setup time at completion

9. Git hooks documentation: Added message about automatic git hooks
   installation

10. CONTRIBUTING.md: Added version verification example before setup

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@claude
Copy link

claude bot commented Dec 9, 2025

Code Review: bin/setup Script

I've reviewed PR #2191 and have the following feedback:

✅ Strengths

  1. Excellent User Experience

    • Clear, colored output with step indicators makes the script friendly for new contributors
    • Helpful error messages with installation links for missing prerequisites
    • --help flag with comprehensive usage information
    • Elapsed time display at completion
    • Graceful handling of missing directories (Pro package)
  2. Robust Error Handling

    • set -e ensures script fails fast on errors
    • Prerequisite checking prevents confusing mid-script failures
    • Path verification ensures script is run from correct directory
    • Build artifact verification catches silent failures
  3. Follows Project Conventions

    • Consistent with other bin/ scripts (similar structure to ci-rerun-failures)
    • Uses pnpm install --frozen-lockfile to match CI behavior (critical per CLAUDE.md)
    • Documentation properly updated in CONTRIBUTING.md
    • Includes trailing newline (per project requirements)
  4. Comprehensive Coverage

    • Handles all monorepo directories systematically
    • Tests bundle check before installing (idempotent behavior)
    • Verifies build artifacts exist after rake node_package

🔍 Potential Issues & Suggestions

1. Security: Unquoted Variable Expansion

Lines 159-163 use pnpm install --frozen-lockfile without quotes around variables. While set -e is set, the script should be more defensive:

# Current (line 159):
if \! pnpm install --frozen-lockfile; then

# Safer (though pnpm is unlikely to have spaces):
if \! pnpm install --frozen-lockfile; then

Actually, the current code is fine here since there are no variable expansions in the command itself. However, ensure all path variables are quoted when used:

  • Line 116: if [ \! -f "$ROOT_DIR/Rakefile" ]; then ✅ Already quoted
  • Line 133: if [ \! -d "$dir" ]; then ✅ Already quoted

Status: ✅ The script already properly quotes all variable expansions.

2. bundle check Exit Code Handling

Line 144-145 uses bundle check &> /dev/null as a condition:

if bundle check &> /dev/null; then
  print_success "Ruby dependencies already satisfied"

This is correct, but since set -e is enabled, consider explicitly handling bundle check failures:

if bundle check &> /dev/null; then
  print_success "Ruby dependencies already satisfied"
else
  if \! bundle install; then
    print_error "Failed to install Ruby dependencies in $name"
    exit 1
  fi
  print_success "Ruby dependencies installed"
fi

Current code: Uses implicit `||" operator via the if/else structure, which is fine. ✅

3. Potential Race Condition: Build Verification

Lines 178-186 verify build artifacts immediately after rake node_package. Consider adding a small delay or checking if the file is still being written:

verify_build_artifacts() {
  print_step "Verifying build artifacts..."
  
  local artifact="packages/react-on-rails/lib/ReactOnRails.full.js"
  
  # Give file system a moment to flush
  sleep 0.5
  
  if [ \! -f "$ROOT_DIR/$artifact" ]; then
    print_error "Build failed: $artifact not found"
    print_error "Expected location: $ROOT_DIR/$artifact"
    exit 1
  fi
  print_success "Build artifacts verified"
}

Likelihood: Very low, but rake node_package might buffer output. If CI passes consistently, this is probably fine. Consider adding only if you see flaky failures.

4. Missing Verification: Pro Package Build Artifacts

The script verifies packages/react-on-rails/lib/ReactOnRails.full.js but doesn't verify Pro artifacts if Pro is installed. Consider:

verify_build_artifacts() {
  print_step "Verifying build artifacts..."

  local artifact="packages/react-on-rails/lib/ReactOnRails.full.js"
  if [ \! -f "$ROOT_DIR/$artifact" ]; then
    print_error "Build failed: $artifact not found"
    print_error "Expected location: $ROOT_DIR/$artifact"
    exit 1
  fi
  
  # Verify Pro artifacts if Pro is present and not skipped
  if [ "$SKIP_PRO" = false ] && [ -d "$ROOT_DIR/react_on_rails_pro" ]; then
    local pro_artifact="packages/react-on-rails-pro/lib/ReactOnRails.full.js"
    if [ \! -f "$ROOT_DIR/$pro_artifact" ]; then
      print_warning "Pro build artifact not found: $pro_artifact"
      print_warning "This may be expected if Pro package doesn't have a separate build"
    fi
  fi
  
  print_success "Build artifacts verified"
}

Note: Only add this if Pro actually generates separate build artifacts. Check the Pro package structure first.

5. Documentation: Testing Instructions

The PR description includes excellent manual testing requirements, but these should be documented in the script's comments or in a separate testing doc. Consider adding to CLAUDE.md:

## Testing bin/setup

Before pushing changes to bin/setup, verify:
- [ ] Fresh clone test (not existing dev environment)
- [ ] With Pro directory present
- [ ] Without Pro directory (or use --skip-pro)
- [ ] From different working directories
- [ ] Build artifacts exist: `ls -la packages/react-on-rails/lib/ReactOnRails.full.js`
- [ ] Post-setup commands work: `rake` and `rake lint`

📝 Minor Suggestions

  1. Consistency: The script uses both &> /dev/null and >/dev/null 2>&1 for output redirection. Choose one for consistency:

    • Line 144: bundle check &> /dev/null (Bash-specific)
    • Other scripts use: >/dev/null 2>&1 (POSIX-compatible)

    Recommendation: Keep &> /dev/null since the script already uses #\!/usr/bin/env bash and Bash-specific features like arrays.

  2. Progress Indication: For long-running operations, consider showing progress:

    echo "  Installing JavaScript dependencies (this may take a few minutes)..."
    if \! pnpm install --frozen-lockfile; then
  3. Pro Directory Detection: Consider a more explicit check for Pro access:

    # After root install, before Pro setup
    if [ -d "$ROOT_DIR/react_on_rails_pro" ] && [ "$SKIP_PRO" = false ]; then
      # Check if Pro is accessible (not just present)
      if [ \! -r "$ROOT_DIR/react_on_rails_pro/Gemfile" ]; then
        print_warning "react_on_rails_pro directory found but not readable"
        print_warning "Run with --skip-pro if you don't have Pro access"
      fi
    fi

🎯 Action Items

Must Fix:

  • None! The script is well-written and handles edge cases properly.

Should Consider:

  1. Add verification for Pro build artifacts (if applicable)
  2. Document testing requirements in CLAUDE.md
  3. Consider adding progress messages for long operations

Nice to Have:

  1. Standardize output redirection syntax
  2. Add Pro access check before attempting Pro setup

✅ Test Coverage Assessment

The PR description includes excellent test coverage:

  • --help flag tested
  • ✅ Error handling for unknown flags tested
  • ✅ Path verification logic tested
  • ✅ Trailing newlines verified
  • ✅ Pre-commit hooks pass

Missing from test plan (per CLAUDE.md §CRITICAL REQUIREMENTS):

  • ⚠️ Run bundle exec rubocop before committing - Did you run this?
  • ⚠️ Test rake node_package builds successfully - Should add to test plan
  • ⚠️ Test in fresh clone - Mentioned in PR description but not in test plan checkboxes

📊 Overall Assessment

Code Quality: ⭐⭐⭐⭐⭐ (5/5)

  • Excellent structure, clear logic, good error handling

Best Practices: ⭐⭐⭐⭐⭐ (5/5)

  • Follows project conventions, uses set -e, quotes variables

Security: ⭐⭐⭐⭐⭐ (5/5)

  • Properly quotes all variable expansions, no injection risks

Documentation: ⭐⭐⭐⭐☆ (4/5)

  • Excellent inline help, good PR description, could add testing docs

Recommendation: ✅ Approve with minor suggestions

This is a high-quality contribution that significantly improves the contributor experience. The suggestions above are minor refinements, not blockers.


🤖 Generated with Claude Code

@justin808
Copy link
Member Author

Feedback from Local Testing

I tested the precompile workflow locally and found some issues that affect this PR:

Key Issue: --ignore-workspace Required for Dummy App

The dummy app (spec/dummy) is not part of the pnpm workspace, so it needs --ignore-workspace:

# Current (doesn't work correctly):
cd spec/dummy && pnpm install

# Required:
cd spec/dummy && pnpm install --ignore-workspace

Without this flag, pnpm resolves to the workspace root and doesn't install the dummy app's dependencies (like webpack-cli).

Precompile Hook Bug

There's also a bug where the precompile hook (bin/shakapacker-precompile-hook) doesn't actually run the ReScript build or pack generation. The shared implementation uses if __FILE__ == $PROGRAM_NAME which fails when loaded via load. This should be fixed in a separate PR.

Suggestions for This PR

  1. Use pnpm install --ignore-workspace for the dummy app install step
  2. Explicitly run pnpm run build:rescript for dummy app (until the hook bug is fixed)
  3. Consider also running bundle exec rake react_on_rails:generate_packs as a belt-and-suspenders approach

🤖 Generated with Claude Code

@claude
Copy link

claude bot commented Dec 9, 2025

Code Review: bin/setup Script

I've reviewed PR #2191 and overall this is a well-structured and valuable addition to the project. The script will significantly improve the contributor onboarding experience. Here's my detailed feedback:


✅ Strengths

1. Excellent Error Handling

  • Comprehensive prerequisite checking with clear error messages
  • Build artifact verification ensures setup completed successfully
  • Proper exit codes on failures
  • Directory existence checks before attempting installations

2. User Experience

  • Colored output makes it easy to scan progress
  • --help and --skip-pro flags are well-documented
  • Elapsed time display is a nice touch
  • Clear success/error messages guide users

3. CI Alignment

  • Using pnpm install --frozen-lockfile matches CI behavior ✅
  • This is critical per CLAUDE.md testing requirements

4. Robust Path Handling

  • Uses $SCRIPT_DIR and $ROOT_DIR for location-independent execution
  • Verifies root directory by checking for Rakefile and package.json

🔍 Issues & Suggestions

Critical: Missing set -u for Undefined Variables

Issue: The script uses set -e but not set -u, which means undefined variables will silently expand to empty strings rather than failing.

Risk: If $ROOT_DIR somehow becomes empty, commands like cd "$ROOT_DIR" could inadvertently cd to $HOME.

Recommendation:

set -euo pipefail  # Add -u for undefined variables, -o pipefail for pipeline failures

Or at minimum:

set -eu

Why pipefail: While less critical here, it's a best practice for robust bash scripts to catch failures in piped commands.


Medium: Inconsistent Use of bundle check

Issue: The script uses bundle check to skip installation if dependencies are satisfied:

if bundle check &> /dev/null; then
  print_success "Ruby dependencies already satisfied"
else
  if ! bundle install; then
    # ...
  fi
fi

Problem: This optimization is not used for pnpm, creating inconsistent behavior. More importantly, in a fresh clone (the primary use case), bundle check will always fail, so this adds complexity without much benefit.

Recommendation: Remove the bundle check optimization for consistency and simplicity:

echo "  Installing Ruby dependencies..."
if ! bundle install; then
  print_error "Failed to install Ruby dependencies in $name"
  exit 1
fi
print_success "Ruby dependencies installed"

Why: bundle install is already idempotent—it won't reinstall if dependencies are satisfied. The extra check adds 3-5 lines of code for minimal benefit.


Medium: Missing Validation for rake node_package Success

Issue: The build_node_package() function checks if rake node_package exits with non-zero, but there's a gap between build completion and artifact verification.

Current Flow:

  1. rake node_package runs
  2. Script continues
  3. verify_build_artifacts() checks for file existence

Problem: If rake node_package succeeds but produces the artifact at the wrong location (due to a bug), the error message will be misleading:

✓ Node package built
Error: Build failed: packages/react-on-rails/lib/ReactOnRails.full.js not found

Recommendation: Call verify_build_artifacts() immediately after build_node_package() (they're already sequential, so this is minor). Alternatively, combine them into a single function:

build_and_verify_node_package() {
  print_step "Building node package..."
  if ! rake node_package; then
    print_error "Failed to build node package"
    exit 1
  fi
  
  # Verify immediately
  local artifact="packages/react-on-rails/lib/ReactOnRails.full.js"
  if [ ! -f "$ROOT_DIR/$artifact" ]; then
    print_error "Build succeeded but artifact not found: $artifact"
    exit 1
  fi
  print_success "Node package built and verified"
}

Low: CONTRIBUTING.md Formatting

Issue: The diff shows removal of cd react_on_rails/ from the update command:

-cd react_on_rails/
 bundle && pnpm install && rake shakapacker_examples:gen_all && rake node_package && rake

Question: Is this intentional? The command now implies running from the root directory. This is fine if accurate, but worth confirming that:

  1. These commands work from the root
  2. The documentation is clear about the expected working directory

Recommendation: If running from root is now the standard, consider adding a comment:

# From the repository root:
bundle && pnpm install && rake shakapacker_examples:gen_all && rake node_package && rake

Low: Consider Adding a Dry-Run Mode

Suggestion: For debugging and transparency, consider adding a --dry-run flag that shows what would be executed without actually running commands.

Example:

if [ "$DRY_RUN" = true ]; then
  echo "[DRY RUN] Would execute: bundle install in $dir"
else
  bundle install
fi

Benefit: Helps users understand what the script will do before committing to a potentially long setup process.


🧪 Testing Recommendations

Per CLAUDE.md, the following manual tests are mandatory before merge:

Critical Tests

  1. Fresh clone test:

    cd /tmp
    git clone https://github.com/shakacode/react_on_rails.git fresh-test
    cd fresh-test
    bin/setup
  2. Verify build artifacts exist:

    ls -la packages/react-on-rails/lib/ReactOnRails.full.js
  3. Post-setup validation:

    rake              # Should pass
    rake lint         # Should pass
    bundle exec rubocop  # Should pass with zero offenses
  4. Test --skip-pro flag:

    rm -rf node_modules
    bin/setup --skip-pro
    # Verify it skips react_on_rails_pro
  5. Test from wrong directory:

    cd /tmp
    /path/to/react_on_rails/bin/setup
    # Should show clear error about Rakefile not found

📋 Minor Nitpicks

  1. Typo in help text: "expectable outcome" → "expected outcome" (though this is from Rails default template)

  2. Consistency: The script uses both [ -f ... ] and [ -d ... ]. This is fine, but for maximum portability, you could use [[ ... ]] consistently (bash-specific but more robust).

  3. Magic number: The artifact path packages/react-on-rails/lib/ReactOnRails.full.js is hardcoded in two places (could be a variable).


🎯 Security Considerations

No security concerns identified. The script:

  • Doesn't download external content
  • Doesn't execute user-provided input
  • Uses safe path handling
  • Properly quotes variables

📊 Performance Considerations

Good performance characteristics:

  • Skips missing directories gracefully
  • Uses --frozen-lockfile for faster installs
  • Shows progress to avoid user concern during long operations

Potential optimization:

  • Parallel installation (install root, dummy, and pro dependencies in parallel using & and wait). However, this adds complexity and may not be worth it for a one-time setup script.

🔒 Test Coverage

Not applicable - This is a bash script, not application code. Manual testing per the checklist above is appropriate.


Final Recommendation

Approve with minor changes:

  1. ✅ Add set -u (or set -euo pipefail)
  2. ⚠️ Consider removing bundle check optimization
  3. ℹ️ Optionally combine build and verify steps

The script is production-ready as-is, but these changes would improve robustness.

Excellent work overall! This will significantly improve the contributor experience. 🎉


Reference: CLAUDE.md sections on testing build scripts, managing file paths, and avoiding CI failure cycles.

@claude
Copy link

claude bot commented Dec 9, 2025

Code Review Feedback

Thank you for this contribution! This is a valuable addition that will significantly improve the developer onboarding experience.

✅ Strengths

  1. Excellent Documentation: Clear inline comments, comprehensive help text, and detailed PR description with manual testing checklist
  2. User Experience: Well-designed colored output, progress indicators, and elapsed time display
  3. Error Handling: Robust prerequisite checking, path verification, and graceful handling of missing directories
  4. CI Alignment: Uses --frozen-lockfile flag to match CI behavior (critical per CLAUDE.md)
  5. Flexibility: --skip-pro flag accommodates contributors without Pro access

🔍 Code Quality - Excellent ✅

  • Proper use of set -e for fail-fast behavior
  • Quoted variables to handle spaces in paths
  • Good separation of concerns with dedicated functions
  • Dynamic path resolution allows running from any directory
  • Build artifact verification at packages/react-on-rails/lib/ReactOnRails.full.js

⚠️ Recommendations

1. CRITICAL: Trailing Newline
Per CLAUDE.md: Files must end with a newline character. Please verify bin/setup has this.

2. CONTRIBUTING.md Line 33
The command after Git updates still shows the old manual flow. Should this reference bin/setup now, or does it serve a different purpose?

3. Hardcoded Path (Line 182)
The artifact path is hardcoded. Fine for now, but note in .claude/docs/managing-file-paths.md for future refactors.

4. RuboCop Check
Please confirm bundle exec rubocop was run (required per CLAUDE.md).

🔒 Security ✅

No concerns - no user input execution, no credentials, proper error handling.

📋 Testing Checklist

Please confirm fresh clone testing and post-setup commands (rake lint, rake) work as expected.

🎯 Recommendation

Approve with minor fixes - Once the 4 items above are addressed, ready to merge!

Great work making contributor onboarding smoother! 🎉

@claude
Copy link

claude bot commented Dec 9, 2025

Code Review - PR #2191: Add bin/setup for unified development environment setup

Overall Assessment

This is a well-crafted PR that adds significant value to the developer experience. The implementation is thorough, follows bash best practices, and aligns well with the project's guidelines in CLAUDE.md.

Recommendation: Approve with minor suggestions

Strengths

  1. Excellent UX Design - Clear, colored output with step-by-step progress indicators, helpful error messages, --help and --skip-pro flags, elapsed time display

  2. Robust Error Handling - set -e for fail-fast, prerequisite checking, path verification, build artifact verification, graceful handling of missing directories

  3. CI Alignment - Uses pnpm install --frozen-lockfile to match CI behavior (CRITICAL per CLAUDE.md)

  4. Documentation - Comprehensive inline comments, CONTRIBUTING.md updates are clear, thorough manual testing checklist

  5. Security & Best Practices - Proper script location handling, all paths quoted, no unsafe command substitution

Suggestions for Improvement

1. Bundle Check Logic (Minor UX Enhancement)
Location: Lines 144-151
Issue: When bundle check passes, it still prints Installing Ruby dependencies... but then says already satisfied. This might confuse users.
Suggestion: Move the Installing... message inside the else block so it only prints when actually installing.

2. pnpm Frozen Lockfile Error Messaging (Minor Enhancement)
Location: Lines 160-162
Suggestion: When pnpm install --frozen-lockfile fails, add a hint: If pnpm-lock.yaml is out of sync, you may need to run pnpm install without --frozen-lockfile

3. Verify Artifacts Path
Location: Line 180
The artifact path packages/react-on-rails/lib/ReactOnRails.full.js is hardcoded. Per CLAUDE.md Managing File Paths guidelines, verify this matches actual build output during manual testing (already in your checklist).

4. Optional: Ruby/Node Version Checks (Future Enhancement)
The script displays versions but doesnt validate against .ruby-version and .node-version. This could help catch mismatches early, but may be better as a follow-up.

Testing Coverage

Your manual testing checklist is excellent and covers all critical scenarios. Additional suggestion: Test with intentionally corrupted pnpm-lock.yaml to verify error message is helpful.

Security, Performance, Bugs

No security concerns or significant bugs identified. Performance is efficient with bundle check pre-checks and conditional Pro package skipping.

Changelog Entry

Per CLAUDE.md, this is a user-visible improvement and should have a changelog entry:

Developer Experience

  • PR 2191 by shakacode: Add bin/setup script for unified development environment setup across the monorepo.

Great work! The code quality is high, testing plan is thorough, and it will significantly improve the contributor onboarding experience.

@claude
Copy link

claude bot commented Dec 9, 2025

Code Review - Fresh Analysis

I've conducted a thorough review of this PR, focusing on areas that complement the existing feedback. Overall, this is a well-implemented script with strong attention to detail. Here are my findings:


✅ Strengths

  1. Robust Error Handling

    • Proper use of set -e to fail fast on errors
    • Individual error checking for critical operations (bundle install, pnpm install, rake tasks)
    • Clear error messages with actionable guidance
  2. Excellent Path Handling

    • Uses SCRIPT_DIR and ROOT_DIR to support running from any location
    • Proper quoting throughout (critical for paths with spaces)
    • Uses cd back to ROOT_DIR after each directory operation
  3. Good UX Design

    • Colored output with semantic meaning (errors in red, success in green)
    • Progress indicators for each step
    • Elapsed time display helps set expectations
    • Help text is comprehensive and well-formatted
  4. CLAUDE.md Compliance

    • Uses pnpm install --frozen-lockfile matching CI behavior (critical per testing-build-scripts.md)
    • Verifies build artifacts exist after rake node_package
    • Properly handles Pro directory optionally

🔍 Potential Issues & Suggestions

1. Missing RuboCop Compliance Check (Critical per CLAUDE.md)

The CLAUDE.md states:

⚠️ MANDATORY BEFORE GIT PUSH: bundle exec rubocop and fix ALL violations

The setup script doesn't verify it can run RuboCop successfully. Consider adding:

# After installing root dependencies
print_step "Verifying linting setup..."
if ! bundle exec rubocop --version &> /dev/null; then
  print_error "Failed to verify RuboCop installation"
  exit 1
fi
print_success "Linting tools verified"

2. Bundle Check Logic Could Be Improved

Current code:

if bundle check &> /dev/null; then
  print_success "Ruby dependencies already satisfied"
else
  if ! bundle install; then

Issue: bundle check might succeed but deps could still be outdated. The script should always run bundle install to ensure consistency with CI.

Recommendation: Remove the bundle check optimization or at least add a comment explaining why it's safe.

3. Missing Verification of Git Hooks Installation

CLAUDE.md emphasizes:

Git hooks are installed automatically during setup

But the completion message just states they've been installed without verification. Consider:

# After setup completes
if [ -f ".git/hooks/pre-commit" ]; then
  print_success "Git hooks installed"
else
  print_warning "Git hooks not found - they should be auto-installed on first commit"
fi

4. pnpm install Error Messages Could Be More Helpful

When pnpm install --frozen-lockfile fails, it's often due to:

  • Outdated pnpm version
  • Lockfile out of sync
  • Node version mismatch

Consider enhanced error output:

if ! pnpm install --frozen-lockfile; then
  print_error "Failed to install JavaScript dependencies in $name"
  echo ""
  echo "Common causes:"
  echo "  - pnpm version mismatch (need 9.x+)"
  echo "  - Node version mismatch (check .node-version)"
  echo "  - Lockfile out of sync (try: rm pnpm-lock.yaml && pnpm install)"
  exit 1
fi

5. Consider Adding Verification Step

Per CLAUDE.md's testing-build-scripts.md, after setup should verify:

verify_setup() {
  print_step "Verifying setup..."
  
  # Check critical artifacts exist
  local artifacts=(
    "packages/react-on-rails/lib/ReactOnRails.full.js"
  )
  
  for artifact in "${artifacts[@]}"; do
    if [ ! -f "$ROOT_DIR/$artifact" ]; then
      print_error "Setup verification failed: $artifact not found"
      return 1
    fi
  done
  
  print_success "Setup verification passed"
}

6. Minor: Inconsistent Directory Existence Check

The script checks [ ! -d "$dir" ] for skipping directories, but doesn't check for the dummy apps' existence before attempting setup. This is fine since the check happens inside install_dependencies, but it could be more explicit in the main flow.


🔒 Security Considerations

✅ No security issues found:

  • No user input is used in dangerous contexts
  • No eval or similar dynamic execution
  • Proper quoting prevents injection
  • Only writes to project directories

🎯 Test Coverage Recommendations

The PR's test plan is good, but consider adding these verification steps to the manual testing checklist:

# After bin/setup completes:

# 1. Verify all critical artifacts exist
ls -la packages/react-on-rails/lib/ReactOnRails.full.js
ls -la node_modules  # Should exist in root
ls -la react_on_rails/spec/dummy/node_modules  # Should exist

# 2. Verify linting works
bundle exec rubocop --version
pnpm run lint --help

# 3. Verify git hooks are ready (they install on first commit)
ls -la .git/hooks/

# 4. Try a basic rake command
rake --version

📝 Documentation Improvements

The CONTRIBUTING.md updates are excellent! One minor suggestion:

In the "Manual Setup" section, consider adding a note about why someone might choose manual setup:

### Manual Setup (Alternative)

If you prefer to set up manually or need more control (e.g., selective installation, debugging setup issues):

🚀 Performance Considerations

✅ No performance issues:

  • bundle check optimization avoids redundant installs
  • --frozen-lockfile prevents unnecessary lockfile operations
  • Elapsed time display helps users understand normal duration

✨ Overall Verdict

This is a high-quality contribution that significantly improves developer experience. The code follows bash best practices and aligns well with the project's conventions.

Recommendation: Approve with minor suggestions

The suggestions above are mostly optional improvements. The core functionality is solid and ready to merge. The only critical consideration is whether to keep the bundle check optimization or always run bundle install for consistency with CI.

Great work! 🎉

@claude
Copy link

claude bot commented Dec 9, 2025

Code Review: bin/setup Script

I've reviewed PR #2191 and have the following feedback:

✅ Strengths

  1. Well-structured and clear: The script follows good bash practices with clear step-by-step execution
  2. Excellent user experience: Colored output, progress indicators, and helpful error messages
  3. Comprehensive coverage: Handles all monorepo directories (root, dummy apps, Pro package)
  4. Good error handling: Uses set -e and explicit error checking with informative messages
  5. CI alignment: Uses --frozen-lockfile to match CI behavior
  6. Build verification: Checks for ReactOnRails.full.js after build - critical per CLAUDE.md
  7. Documentation: Clear help text and updated CONTRIBUTING.md

🔧 Issues & Recommendations

1. CRITICAL: Missing set -u flag

Your script uses set -e but is missing set -u (and ideally set -o pipefail). Looking at other scripts in the codebase (e.g., bin/ci-switch-config, bin/ci-local), they all use:

set -euo pipefail

Why this matters:

  • -u: Treats unset variables as errors (prevents silent bugs from typos)
  • -o pipefail: Ensures pipe failures are caught (e.g., command1 | command2 fails if command1 fails)

Recommendation:

set -euo pipefail

2. Potential issue: Directory existence check order

In install_dependencies(), you check if the directory exists and skip if not:

if [ ! -d "$dir" ]; then
  print_warning "Directory not found: $dir (skipping)"
  return 0
fi

This is good for optional directories (like Pro), but for required directories like react_on_rails/spec/dummy, a missing directory might indicate a broken checkout. Consider:

# For required directories, fail instead of skip
install_dependencies_required() {
  local dir="$1"
  local name="$2"
  
  if [ ! -d "$dir" ]; then
    print_error "Required directory not found: $dir"
    exit 1
  fi
  # ... rest of function
}

3. Bundle check optimization

Great job checking if bundle is already satisfied before running install! However, consider redirecting stderr as well for cleaner output:

if bundle check &>/dev/null; then

4. Consistency: pnpm vs bundle error handling

You have explicit error handling for pnpm install failure, but bundle install doesn't exit on failure:

# Bundle (current)
if ! bundle install; then
  print_error "Failed to install Ruby dependencies in $name"
  exit 1
fi

# PNPM (current)
if ! pnpm install --frozen-lockfile; then
  print_error "Failed to install JavaScript dependencies in $name"
  exit 1
fi

Actually, this looks consistent now! ✓

5. Performance: Consider parallel installation

For a potential future enhancement (not blocking), consider offering parallel installation of independent directories using background jobs. This could significantly speed up setup:

# Example (future enhancement)
install_dependencies "$ROOT_DIR" "root directory" &
PID1=$!
install_dependencies "$ROOT_DIR/react_on_rails/spec/dummy" "react_on_rails/spec/dummy" &
PID2=$!
wait $PID1 $PID2

But for initial version, sequential is safer.

🧪 Testing Recommendations

Per CLAUDE.md requirements for testing build scripts:

  1. Test clean install: The script should work in a fresh clone
  2. Test idempotency: Running twice should work without errors
  3. ⚠️ Test edge cases:
    • What happens if pnpm/bundle are mid-version (e.g., incompatible lockfile)?
    • What if rake node_package fails mid-way?
    • What if network fails during pnpm install?

Suggested test checklist (add to PR description):

# Test in a fresh clone
cd /tmp && git clone <repo> test-setup && cd test-setup
bin/setup

# Test idempotency
bin/setup  # Should succeed without errors

# Test --skip-pro
bin/setup --skip-pro

# Test partial failure recovery
rm -rf node_modules
bin/setup  # Should recover

📝 Minor Suggestions

  1. Version display: Excellent addition showing Ruby/Node/pnpm/Bundler versions!

  2. Elapsed time: Great UX touch!

  3. Consider adding a --verbose flag for debugging:

    VERBOSE=false
    # ... in argument parsing
    --verbose)
      VERBOSE=true
      set -x  # Enable bash debugging
  4. Git hooks message: Good reminder! Consider also mentioning how to skip hooks if needed:

    echo "Git hooks have been automatically installed during setup."
    echo "They will run linting on changed files before each commit."
    echo "To skip hooks: git commit --no-verify (not recommended)"

🔒 Security Considerations

  1. ✅ No user input is executed unsanitized
  2. ✅ No eval or unsafe command execution
  3. ✅ All paths are properly quoted
  4. cd operations are safe with proper error handling

📊 Overall Assessment

Strong PR! The script is well-designed and solves a real pain point for new contributors. The main issue is the missing set -u and set -o pipefail flags for consistency with the rest of the codebase.

Recommendation: Approve with minor changes (add set -euo pipefail)


Great work on this! The script will definitely help onboard new contributors faster. 🎉

@claude
Copy link

claude bot commented Dec 9, 2025

Code Review: bin/setup Script

Great work on creating a unified setup script! This will significantly improve the contributor onboarding experience.


✅ Strengths

  1. Excellent User Experience - Clear colored output, helpful prerequisite checking, elapsed time display, comprehensive --help flag

  2. Robust Error Handling - set -e for exits on errors, validates prerequisites, verifies root directory structure, checks build artifacts

  3. Consistency with Existing Scripts - Follows same patterns as bin/ci-switch-config, uses consistent color codes and helper functions

  4. Smart Design Decisions - --skip-pro flag for open-source contributors, uses --frozen-lockfile to match CI behavior, gracefully handles missing directories


🐛 Issues and Concerns

1. CRITICAL: set -e without set -u and set -o pipefail

Issue: The script uses set -e but not the safer set -euo pipefail used in other scripts like bin/ci-switch-config.

Current (line 13): set -e
Should be: set -euo pipefail

Why this matters:

  • -u: Treats unset variables as errors (prevents typos like SKIP_PR0 instead of SKIP_PRO)
  • -o pipefail: Catches failures in pipelines

Reference: Line 9 of bin/ci-switch-config shows the correct pattern.


2. WARNING: Inconsistent Behavior with bundle check

The script skips bundle install if dependencies are satisfied (lines 140-151). When bundle check passes, we won't pick up new gems added to Gemfile until someone runs bundle install manually.

Recommendation: This is probably fine for a setup script, but consider documenting in CONTRIBUTING.md that developers should run bundle install after git pull to pick up new dependencies.


3. DOCUMENTATION: Missing Context for rake node_package

Recommendation: Add a comment explaining what this does - it builds TypeScript packages and runs pnpm yalc:publish for local development


4. EDGE CASE: No Verification of PNPM Version

The script checks for pnpm existence but not version. The project uses packageManager: [email protected].

Recommendation: Consider adding a version check to warn about version mismatches. Impact: Low priority - pnpm 9 is backward compatible.


📝 Documentation Review

The CONTRIBUTING.md changes are excellent:

  1. ✅ Clear Quick Setup vs Manual Setup sections
  2. ✅ Version verification steps before running setup
  3. ✅ Explicit mention of version managers (rvm, nvm, etc.)
  4. ✅ Lists what the script does

Minor suggestion: Add a troubleshooting section for common issues.


✅ Testing Coverage

The PR description includes excellent manual testing requirements. Suggest adding:

  • Test with older pnpm versions (8.x) to verify behavior
  • Test with missing .ruby-version or .node-version files
  • Test running from subdirectories (should fail gracefully with clear error)

🎯 Summary and Recommendations

Must Fix Before Merge:

  1. ❗ Change set -e to set -euo pipefail (line 13) for consistency with other scripts

Should Consider:
2. ⚠️ Add pnpm version check to warn about version mismatches
3. ⚠️ Add troubleshooting section to CONTRIBUTING.md
4. ⚠️ Add comment explaining what rake node_package does

Nice to Have:
5. 💡 Consider --skip-dummy flag for faster partial setup (future enhancement)


🚀 Overall Assessment

This is a high-quality PR that significantly improves developer experience. The code is well-structured, follows project conventions, and includes comprehensive error handling. Once the critical set -euo pipefail fix is applied, this is ready to merge.

Code Quality: 9/10
Documentation: 9/10
Testing: 8/10 (could add more edge case tests)
Overall: ✅ Approve with minor changes

Great work!

- Use set -euo pipefail for stricter error handling (matches bin/ci-switch-config)
- Add comment explaining what rake node_package does

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@claude
Copy link

claude bot commented Dec 9, 2025

Code Review

This is an excellent addition that will significantly improve the contributor experience! The script is well-structured, follows bash best practices, and handles edge cases gracefully. Here's my detailed review:


✅ Strengths

Code Quality

  • Excellent error handling: Uses set -euo pipefail for strict error handling
  • Clear output: Color-coded messages with distinct status indicators
  • Robust path handling: Correctly resolves ROOT_DIR from script location
  • Graceful degradation: Handles missing directories (Pro package) elegantly
  • User-friendly: --help and --skip-pro flags are well documented

Best Practices Alignment

  • Matches CI behavior: Uses --frozen-lockfile flag (critical per CLAUDE.md)
  • Build verification: Confirms artifacts exist at expected paths
  • Prerequisite checking: Validates all required tools before starting
  • Clear documentation: Updated CONTRIBUTING.md with quick setup section

Security & Reliability

  • Proper quoting of all variables
  • No command injection vulnerabilities
  • Validates directory structure before proceeding
  • Exits cleanly on errors with helpful messages

🔍 Observations & Minor Suggestions

1. Path Reference in Comment (Line 173)

Current:

# This compiles node_package/src/ to lib/ and makes packages available locally.

Observation: The comment mentions node_package/src/, but based on the .claude/docs/testing-build-scripts.md history, the actual structure is packages/react-on-rails/src/. The comment should match current reality.

Suggested fix:

# This compiles packages/react-on-rails/src/ to lib/ and makes packages available locally.

2. Error Message Consistency

The script uses print_error for failures, which is perfect. No changes needed here, but worth noting that all error paths properly use exit 1.

3. Build Artifact Verification (Lines 182-192)

Current behavior: Only verifies packages/react-on-rails/lib/ReactOnRails.full.js

Consider: Should we also verify Pro package artifacts when react_on_rails_pro exists and --skip-pro is not set? This would catch build issues earlier.

Optional enhancement:

verify_build_artifacts() {
  print_step "Verifying build artifacts..."

  local artifact="packages/react-on-rails/lib/ReactOnRails.full.js"
  if [ ! -f "$ROOT_DIR/$artifact" ]; then
    print_error "Build failed: $artifact not found"
    print_error "Expected location: $ROOT_DIR/$artifact"
    exit 1
  fi
  
  # Verify Pro artifacts if Pro package was set up
  if [ "$SKIP_PRO" = false ] && [ -d "$ROOT_DIR/react_on_rails_pro" ]; then
    local pro_artifact="packages/react-on-rails-pro/lib/ReactOnRails.full.js"
    if [ ! -f "$ROOT_DIR/$pro_artifact" ]; then
      print_warning "Pro build artifact not found: $pro_artifact"
    fi
  fi
  
  print_success "Build artifacts verified"
}

However, this is optional and not blocking—the current implementation is sufficient.

4. Relationship with script/setup

There's an existing script/setup that references script/bootstrap and does database setup. Consider:

  • Is script/setup still used? If not, document deprecation
  • Should bin/setup mention database setup or reference script/setup for Rails-specific initialization?

🧪 Testing Verification

Per CLAUDE.md requirements, before merging verify:

Critical Tests (from PR description):

  • Test in fresh clone (not existing dev environment)
  • Test with Pro directory present
  • Test with --skip-pro flag
  • Verify build artifacts: ls -la packages/react-on-rails/lib/ReactOnRails.full.js
  • Run rake and rake lint after setup completes

Additional Recommended Tests:

# Test from different working directories
cd /tmp && /path/to/react_on_rails/bin/setup

# Test error handling
# (temporarily rename pnpm to simulate missing prerequisite)

# Test idempotency - run twice
bin/setup && bin/setup

📋 CONTRIBUTING.md Changes

The documentation updates are clear and well-organized:

  • ✅ New "Quick Setup" section is prominent and easy to follow
  • ✅ Manual setup instructions preserved for power users
  • ✅ Version verification instructions included

Minor suggestion: Consider adding a troubleshooting section for common issues:

  • "If pnpm install fails, ensure lockfile is committed"
  • "If Ruby/Node version mismatch, check .ruby-version / .node-version"

🎯 Final Verdict

Approve with minor suggestions. The script is production-ready and will greatly improve the contributor experience. The suggestions above are all optional enhancements—none are blocking issues.

Required Before Merge:

  1. ✅ Fix path reference in comment (line 173) to match current structure
  2. ✅ Complete manual testing checklist per CLAUDE.md requirements
  3. ✅ Ensure trailing newline (likely already handled by pre-commit hooks)

Nice-to-Have:

  • Consider Pro artifact verification
  • Document relationship with script/setup
  • Add troubleshooting section to CONTRIBUTING.md

Great work on this improvement! This will save countless hours for new contributors. 🚀

@claude
Copy link

claude bot commented Dec 9, 2025

Code Review: bin/setup Script

I've reviewed PR #2191 and the implementation looks excellent overall!

✅ Strengths

1. Excellent Code Quality

  • Clear, well-structured bash script with proper error handling
  • Good use of color-coded output for better UX
  • Proper validation and prerequisite checks
  • Comprehensive help documentation

2. Follows Project Guidelines

  • Uses pnpm install --frozen-lockfile to match CI behavior ✅
  • Proper file organization (bin/ directory is appropriate)
  • Good documentation in CONTRIBUTING.md
  • Includes elapsed time display (nice touch!)

3. Robustness

  • Directory verification before proceeding
  • Graceful handling of missing directories (Pro package)
  • Build artifact verification
  • Good error messages with helpful context

4. Security & Best Practices

  • Uses set -e for fail-fast behavior
  • Proper quoting of variables
  • No hardcoded credentials or sensitive data

🔍 Observations & Minor Suggestions

1. Build Artifact Path Verification ✅

The script verifies packages/react-on-rails/lib/ReactOnRails.full.js exists after running rake node_package.

I verified this is correct by checking react_on_rails/rakelib/node_package.rake which runs pnpm run build && pnpm yalc:publish.

Status: ✅ Path is correct and will work as expected.

2. Bundle Check Optimization ✅

The script already optimizes bundle install with bundle check - nice work! This makes re-running the script much faster.

📋 Testing Recommendations

Per CLAUDE.md critical requirements, ensure these manual tests are completed:

  • Fresh clone test - Clone to a new directory and run bin/setup (CRITICAL!)
  • Pro directory present - Test with react_on_rails_pro available
  • Pro directory absent - Test without react_on_rails_pro OR use --skip-pro
  • Post-setup verification: verify rake and rake lint work

The fresh clone test is CRITICAL per CLAUDE.md - it's the best way to catch assumptions about local state.

🎯 Code-Specific Comments

Lines 169-172: Excellent Choice ✅

Using rake node_package instead of directly calling pnpm run build ensures consistency with CI. Right approach.

Lines 115-127: Strong Validation ✅

Excellent defensive programming - prevents silent failures from running in the wrong directory.

Lines 251-262: Pro Package Handling ✅

Perfect logic for handling open-source contributors without Pro access.

Lines 155-165: pnpm Frozen Lockfile ✅

This matches CI behavior per CLAUDE.md requirements. Excellent!

📝 Documentation Review

CONTRIBUTING.md changes look great with clear Quick Setup vs Manual Setup sections.

Minor suggestion: Around line 29-30, consider noting that bin/setup replaces the first part of the setup command.

🚀 Final Verdict

LGTM with minor suggestions! 🎉

This is well-implemented and will significantly improve contributor onboarding. Code follows bash best practices and adheres to project guidelines.

Before Merging:

  1. ✅ Complete all manual testing scenarios (especially fresh clone test!)
  2. ✅ Verify build artifacts are created correctly
  3. ⚡ Consider the minor documentation enhancement (optional)

Key Strengths:

  • Follows CLAUDE.md requirements for CI-matching behavior
  • Excellent error handling and user feedback
  • Proper handling of monorepo structure
  • Well-documented with inline comments

Great work! 🚀


CI Status: ✅ All checks passing (25/25 workflows succeeded)

@justin808 justin808 merged commit 8100792 into master Dec 9, 2025
27 checks passed
@justin808 justin808 deleted the jg/fix-2190 branch December 9, 2025 05:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants