Skip to content

Commit 27dba50

Browse files
authored
Add react_on_rails:doctor generator for comprehensive setup diagnostics (#1787)
Merge pull request #1787: Add react_on_rails:doctor generator for setup diagnostics This PR introduces a comprehensive diagnostic tool to help developers troubleshoot React on Rails setup issues and verify their development environment configuration. ## Key Features **New Generator:** - `rails generate react_on_rails:doctor` - Comprehensive setup diagnostics - `--verbose` flag for detailed output of all checks - Color-coded output with actionable error messages and solutions **Diagnostic Checks:** - Environment prerequisites (Node.js, package managers, Git status) - React on Rails packages (gem/NPM version sync, wildcard detection) - Shakapacker configuration and version compatibility - React dependencies and build tools - Rails integration (initializer, routes, view helpers) - Webpack configuration validation - Development workflow (bin/dev Launcher, Procfiles) **Security & Code Quality:** - Fixed shell injection vulnerabilities in system commands - Replaced unsafe backticks with secure Open3.capture3 calls - Proper semantic version comparison using Gem::Version - Comprehensive test coverage with RSpec **Developer Experience:** - Actionable commands and troubleshooting guidance - Bundle analysis workflow with webpack-bundle-analyzer - Configuration validation with helpful warnings - Enhanced documentation with mandatory linting requirements The doctor tool is especially useful for: - Troubleshooting setup issues after installation - Verifying compatibility after React on Rails upgrades - Onboarding new developers to existing projects - Diagnosing configuration problems in CI environments
1 parent 3e664d9 commit 27dba50

File tree

10 files changed

+2587
-2
lines changed

10 files changed

+2587
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ Changes since the last non-beta release.
5858
- **Cleaner generated code**: Streamlined templates following modern React and TypeScript best practices
5959
- **Improved helper methods**: Added reusable `component_extension` helper for consistent file extension handling
6060

61+
#### Added
62+
63+
- **`react_on_rails:doctor` rake task**: New diagnostic command to validate React on Rails setup and identify configuration issues. Provides comprehensive checks for environment prerequisites, dependencies, Rails integration, and Webpack configuration. Use `rake react_on_rails:doctor` to diagnose your setup, with optional `VERBOSE=true` for detailed output.
64+
6165
### [16.0.0] - 2025-09-16
6266

6367
**React on Rails v16 is a major release that modernizes the library with ESM support, removes legacy Webpacker compatibility, and introduces significant performance improvements. This release builds on the foundation of v14 with enhanced RSC (React Server Components) support and streamlined configuration.**

CLAUDE.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
44

5+
## ⚠️ CRITICAL REQUIREMENTS
6+
7+
**BEFORE EVERY COMMIT/PUSH:**
8+
9+
1. **ALWAYS run `bundle exec rubocop` and fix ALL violations**
10+
2. **ALWAYS ensure files end with a newline character**
11+
3. **NEVER push without running full lint check first**
12+
13+
These requirements are non-negotiable. CI will fail if not followed.
14+
515
## Development Commands
616

717
### Essential Commands
@@ -11,15 +21,17 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
1121
- Ruby tests: `rake run_rspec`
1222
- JavaScript tests: `yarn run test` or `rake js_tests`
1323
- All tests: `rake` (default task runs lint and all tests except examples)
14-
- **Linting**:
24+
- **Linting** (MANDATORY BEFORE EVERY COMMIT):
25+
- **REQUIRED**: `bundle exec rubocop` - Must pass with zero offenses
1526
- All linters: `rake lint` (runs ESLint and RuboCop)
1627
- ESLint only: `yarn run lint` or `rake lint:eslint`
1728
- RuboCop only: `rake lint:rubocop`
1829
- **Code Formatting**:
19-
- Format code with Prettier: `yarn start format`
30+
- Format code with Prettier: `rake autofix`
2031
- Check formatting without fixing: `yarn start format.listDifferent`
2132
- **Build**: `yarn run build` (compiles TypeScript to JavaScript in node_package/lib)
2233
- **Type checking**: `yarn run type-check`
34+
- **⚠️ MANDATORY BEFORE GIT PUSH**: `bundle exec rubocop` and fix ALL violations + ensure trailing newlines
2335

2436
### Development Setup Commands
2537

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ rails generate react_on_rails:install
6262
- `shakapacker.yml` settings
6363
- other configuration files
6464

65+
### Troubleshooting Setup Issues
66+
67+
If you encounter issues during installation or after upgrading, use the doctor command to diagnose your setup:
68+
69+
```bash
70+
rake react_on_rails:doctor
71+
```
72+
73+
The doctor command checks your environment, dependencies, and configuration files to identify potential issues. Use `VERBOSE=true rake react_on_rails:doctor` for detailed output.
74+
6575
For detailed upgrade instructions, see [upgrade guide documentation](docs/guides/upgrading-react-on-rails.md).
6676

6777
## React on Rails Pro
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
Description:
2+
The `react_on_rails:doctor` generator diagnoses your React on Rails setup
3+
and identifies potential configuration issues. It performs comprehensive
4+
checks on your environment, dependencies, and configuration files.
5+
6+
This command is especially useful for:
7+
• Troubleshooting setup issues
8+
• Verifying installation after running react_on_rails:install
9+
• Ensuring compatibility after upgrades
10+
• Getting help with configuration problems
11+
12+
Example:
13+
# Basic diagnosis
14+
rails generate react_on_rails:doctor
15+
16+
# Verbose output showing all checks
17+
rails generate react_on_rails:doctor --verbose
18+
19+
# Show help
20+
rails generate react_on_rails:doctor --help
21+
22+
Checks performed:
23+
Environment Prerequisites:
24+
• Node.js installation and version compatibility
25+
• JavaScript package manager availability (npm, yarn, pnpm, bun)
26+
• Git working directory status
27+
28+
React on Rails Packages:
29+
• React on Rails gem installation
30+
• react-on-rails NPM package installation
31+
• Version synchronization between gem and NPM package
32+
• Shakapacker configuration and installation
33+
34+
Dependencies:
35+
• React and React DOM installation
36+
• Babel preset configuration
37+
• Required development dependencies
38+
39+
Rails Integration:
40+
• React on Rails initializer configuration
41+
• Route and controller setup (Hello World example)
42+
• View helper integration
43+
44+
Webpack Configuration:
45+
• Webpack config file existence and structure
46+
• React on Rails compatibility checks
47+
• Environment-specific configuration validation
48+
49+
Development Environment:
50+
• JavaScript bundle files
51+
• Procfile.dev for development workflow
52+
• .gitignore configuration for generated files
53+
54+
Options:
55+
--verbose, -v: Show detailed output for all checks, including successful ones
56+
--fix, -f: Attempt to fix simple issues automatically (planned feature)
57+
58+
Exit codes:
59+
0: All checks passed or only warnings found
60+
1: Critical errors found that prevent React on Rails from working
61+
62+
For more help:
63+
• Documentation: https://github.com/shakacode/react_on_rails
64+
• Issues: https://github.com/shakacode/react_on_rails/issues
65+
• Discord: https://discord.gg/reactrails

0 commit comments

Comments
 (0)