Skip to content

Improve generator robustness and error handling #1958

@justin808

Description

@justin808

Summary

Improve the React on Rails install generator to be more robust with better error handling, validation, and package manager detection.

Background

PR #1896 contained several generator improvements that should be extracted and applied to current master.

Proposed Changes

1. Better Package Manager Detection

  • Improve detection of npm vs yarn vs pnpm
  • Handle edge cases where package manager isn't obvious
  • Add validation that chosen package manager is actually available

2. Smarter Validation Skipping

  • Skip version validation when react-on-rails package not yet installed
  • Avoid false errors during initial installation
  • Better error messages when validation does fail

3. Webpack Safety Checks

  • Add checks before modifying webpack config
  • Validate webpack config exists before attempting modifications
  • Better error messages for webpack-related issues

4. Exact Version Specifications

  • Use exact versions where needed to avoid dependency conflicts
  • Document why certain packages need exact versions
  • Provide clear upgrade path

5. Better Error Messages

  • Provide actionable error messages
  • Include suggestions for common issues
  • Link to troubleshooting documentation

Files to Update

From PR #1896 as reference:

  • lib/generators/react_on_rails/base_generator.rb
  • lib/generators/react_on_rails/generator_helper.rb
  • lib/generators/react_on_rails/install_generator.rb
  • Generator templates in lib/generators/react_on_rails/templates/

Testing

  • Test generator with npm, yarn, and pnpm
  • Test in fresh Rails app
  • Test in existing Rails app with react-on-rails
  • Test error scenarios (missing dependencies, etc.)
  • Verify all generator tests pass

Related

Labels

enhancement, generator

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions