Add top-level setup script for unified dependency installation
Problem
Currently, setting up the development environment requires running multiple commands in different directories:
# Root directory
pnpm install
bundle install
# Dummy app
cd spec/dummy
pnpm install
bundle install
# Pro package (if working on Pro features)
cd react_on_rails_pro
pnpm install
bundle install
cd react_on_rails_pro/spec/dummy
pnpm install
bundle install
This is error-prone and easy to forget, especially for new contributors or when switching between branches with different dependency requirements.
Proposed Solution
Add a top-level bin/setup script (the Rails convention) that:
- Installs all dependencies across all directories
- Runs any necessary setup tasks (e.g.,
rake node_package) - Provides clear output about what's being installed
- Handles errors gracefully with helpful messages
Example implementation
#!/bin/bash
set -e
echo "Setting up React on Rails development environment..."
# Root dependencies
echo "Installing root dependencies..."
pnpm install
bundle install
# Build node package
echo "Building node package..."
rake node_package
# Dummy app
echo "Setting up spec/dummy..."
cd spec/dummy
pnpm install
bundle install
cd ../..
# Pro package (if present)
if [ -d "react_on_rails_pro" ]; then
echo "Setting up react_on_rails_pro..."
cd react_on_rails_pro
pnpm install
bundle install
if [ -d "spec/dummy" ]; then
cd spec/dummy
pnpm install
bundle install
cd ../..
fi
cd ..
fi
echo ""
echo "Setup complete! You can now run:"
echo " rake # Run all tests"
echo " rake lint # Run linters"
Acceptance Criteria
- [ ]
bin/setupscript exists and is executable - [ ] Running
bin/setupfrom the repo root installs all dependencies - [ ] Script handles missing directories gracefully (e.g., if Pro package isn't cloned)
- [ ] Script provides clear progress output
- [ ] Script fails fast with helpful error messages if something goes wrong
- [ ] README.md updated to reference
bin/setupin the development setup section
Related
This would also help with the CI setup steps, which currently duplicate this logic across multiple workflow files.
๐ค Generated with Claude Code
๐ CodeRabbit Plan Mode
Generate an implementation plan and agent prompts for this issue.
- [ ] Create Plan
๐ Similar & Duplicate Issues
Related Issues
- shakacode/react_on_rails#2091
- shakacode/react_on_rails#2099
- shakacode/shakapacker#849
- shakacode/react_on_rails#1876
- shakacode/react_on_rails#2084
๐ Related PRs
shakacode/react_on_rails-demos#58 - Auto-install npm dependencies before building packages [merged] shakacode/react_on_rails#1873 - Update preinstall script to enable use as a Git dependency [merged] shakacode/shakapacker#768 - Refactor bin scripts to extract auto-configuration logic [merged] shakacode/hichee#8880 - Add Conductor configuration for workspace setup [merged] shakacode/react_on_rails#1977 - Add Shakapacker precompile hook with ReScript support to Pro dummy app [merged]
๐ค Suggested Assignees
- justin808
- AbanoubGhadban
- alexeyr-ci2
- frullah
๐งช Issue enrichment is currently in early access.
To disable automatic issue enrichment, add the following to your .coderabbit.yaml:
issue_enrichment:
auto_enrich:
enabled: false
Additional Context from Local Testing
When testing the precompile check locally, I discovered several setup issues that this setup script should address:
1. PNPM Workspace vs Independent Installs
The dummy app (spec/dummy) is not part of the pnpm workspace. Running pnpm install from the dummy app directory without --ignore-workspace causes pnpm to install at the workspace root instead:
# WRONG - installs at workspace root
cd spec/dummy
pnpm install
# CORRECT - installs in dummy app specifically
cd spec/dummy
pnpm install --ignore-workspace
The setup script should handle this automatically.
2. Precompile Hook Not Running Build Steps
There's a bug in spec/support/shakapacker_precompile_hook_shared.rb - the main execution block at line 116 uses:
if __FILE__ == $PROGRAM_NAME
build_rescript_if_needed
generate_packs_if_needed
end
But when loaded via load shared_hook from bin/shakapacker-precompile-hook, $PROGRAM_NAME doesn't match __FILE__, so the build steps never run. This is why the precompile hook says "completed successfully" but doesn't actually build ReScript or generate packs.
This should be a separate bug fix, but the setup script should also run these steps explicitly as a workaround/belt-and-suspenders approach.
3. Recommended Setup Sequence
The setup script should run these steps for the dummy app:
cd spec/dummy
pnpm install --ignore-workspace # Install deps independently
pnpm run build:rescript # Build ReScript files
bundle install # Install Ruby deps
bundle exec rake react_on_rails:generate_packs # Generate server bundle
This matches what the CI workflow does in .github/workflows/precompile-check.yml lines 117-134.
๐ค Generated with Claude Code
Correction: Workspace Behavior Clarification
After more testing, here's the accurate behavior:
When running pnpm install from spec/dummy/:
- pnpm detects it's inside a workspace (walks up to find
pnpm-workspace.yaml) - Shows
Scope: all 4 workspace projectsand operates at../../..(workspace root) - Does NOT install the dummy app's dependencies (like
webpack-cli)
The fix is pnpm install --ignore-workspace which:
- Ignores the parent workspace
- Installs the dummy app's own
package.jsondependencies locally
The CI workflow uses this correctly at line 118:
run: cd react_on_rails/spec/dummy && pnpm install --ignore-workspace
๐ค Generated with Claude Code
# Pro package (if working on Pro features)
cd react_on_rails_pro
pnpm install
bundle install
pnpm install is not needed here, and the root one should be pnpm install -r.
https://github.com/shakacode/react_on_rails/issues/2190#issuecomment-3630283957 is obsolete since https://github.com/shakacode/react_on_rails/commit/d67c1aac42547238d4379eac9a1b741385da344d.