-
-
Notifications
You must be signed in to change notification settings - Fork 638
Fix duplicate messages in install generator #1788
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughReorganized JS dependency setup: added a public RSpec configuration constant and moved JS dependency flow into new private helpers in the base generator; added comprehensive JS dependency helpers, package-manager detection, and centralized failure handling in the install generator; exposed Redux post-install messaging as a public method. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Dev as Developer
participant BG as BaseGenerator
Dev->>BG: run generator
activate BG
BG->>BG: setup_js_dependencies()
BG->>BG: add_js_dependencies()
BG->>BG: install_js_dependencies() -> detects package manager, runs install or warns
BG-->>Dev: finish
deactivate BG
sequenceDiagram
autonumber
participant User
participant IG as InstallGenerator
User->>IG: run_generators
activate IG
IG->>IG: setup_react_dependencies() — adds packages to package.json
IG->>IG: add_react_on_rails_package()
IG->>IG: add_react_dependencies() / add_css_dependencies() / add_dev_dependencies()
IG->>IG: install_js_dependencies() -- uses yarn/pnpm/npm or warns on failure
alt options.redux? == false
IG->>IG: add_post_install_message()
else options.redux? == true
IG->>IG: add_redux_specific_messages()
end
IG-->>User: done
deactivate IG
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
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. Comment |
Pull Request Review: Fix duplicate messages in install generatorThank you for this PR addressing the duplicate message issues in the install generator. I've conducted a thorough review covering code quality, potential bugs, performance, security, and test coverage. ✅ Code Quality and Best PracticesStrengths:
Suggestions:
🐛 Potential Bugs or IssuesIssue 1: Potential NPM Install Still Running Twice
This could lead to:
Recommendation: Either:
⚡ Performance ConsiderationsThe current implementation may cause performance issues:
Suggested Optimization: def add_js_dependencies
add_react_on_rails_package # Just add to package.json
add_react_dependencies # Just add to package.json
add_css_dependencies # Just add to package.json
add_dev_dependencies # Just add to package.json
install_js_dependencies # Single install at the end
end 🔐 Security ConcernsNo security issues identified. The changes maintain proper:
🧪 Test CoverageCurrent Coverage:
Missing Test Coverage:
Recommended Additional Tests: it "calls npm/yarn install only once during installation" do
expect_any_instance_of(InstallGenerator).to receive(:run).with(/npm install|yarn install/).once
run_generator_test_with_args(%w[--redux], package_json: true)
end
it "does not show duplicate success messages with redux option" do
run_generator_test_with_args(%w[--redux], package_json: true)
output = GeneratorMessages.output.join("\n")
expect(output.scan("React on Rails Successfully Installed").count).to eq(1)
end 📋 SummaryThe PR successfully addresses the duplicate message issue for Redux installations. However, there's still a concern about NPM install commands potentially running multiple times. I recommend:
The changes are safe to merge as-is for fixing the message duplication, but the NPM install duplication should be addressed in a follow-up PR if not resolved here. Great work identifying and fixing these generator issues! 🎉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
lib/generators/react_on_rails/base_generator.rb (1)
233-233
: Remove redundantprivate
(fix RuboCop Lint/UselessAccessModifier)Remove the later
private
in lib/generators/react_on_rails/base_generator.rb (line 233). The earlierprivate
is at line 106, so the second is redundant and triggers RuboCop. Runbundle exec rubocop -A
to confirm the pipeline is green.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
lib/generators/react_on_rails/base_generator.rb
(1 hunks)lib/generators/react_on_rails/install_generator.rb
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.rb
📄 CodeRabbit inference engine (CLAUDE.md)
Use RuboCop for all Ruby code
Files:
lib/generators/react_on_rails/install_generator.rb
lib/generators/react_on_rails/base_generator.rb
lib/**/*.rb
📄 CodeRabbit inference engine (CLAUDE.md)
Place Ruby gem source under lib/ (e.g., lib/react_on_rails/*)
Files:
lib/generators/react_on_rails/install_generator.rb
lib/generators/react_on_rails/base_generator.rb
🪛 GitHub Actions: Lint JS and Ruby
lib/generators/react_on_rails/base_generator.rb
[error] 233-233: Command 'bundle exec rubocop' failed. Rubocop: Lint/UselessAccessModifier - Useless private access modifier. Offense at line 233. This offense is autocorrectable. Run 'bundle exec rubocop -a' to fix.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
- GitHub Check: dummy-app-integration-tests (3.4, 22)
- GitHub Check: dummy-app-integration-tests (3.2, 20)
- GitHub Check: examples (3.2, minimum)
- GitHub Check: examples (3.4, latest)
- GitHub Check: rspec-package-tests (3.2, latest)
- GitHub Check: claude-review
- GitHub Check: rspec-package-tests (3.4, minimum)
- GitHub Check: rspec-package-tests (3.4, latest)
- GitHub Check: rspec-package-tests (3.2, minimum)
🔇 Additional comments (2)
lib/generators/react_on_rails/install_generator.rb (1)
35-37
: Good guard to prevent duplicate success messaging on Redux path.Conditionalizing
add_post_install_message
behindoptions.redux?
aligns with the PR goal and avoids double messages. LGTM.Please confirm that the Redux generator already emits a complete post‑install message so non‑Redux users aren’t missing guidance.
lib/generators/react_on_rails/base_generator.rb (1)
98-104
: Centralize dependency installation — good consolidation.Calling
install_js_dependencies
fromadd_js_dependencies
should stop the “second full npm install” and reduce noise. LGTM.Double‑check that no other top‑level generator still triggers a project‑wide install to avoid regressions (e.g., via
run "npm install"
or similar).
Code Review for PR #1788: Fix duplicate messages in install generator✅ Strengths
🔍 Observations & Suggestions1. Method visibility changeThe install_js_dependencies method was moved from public to private. While this is good encapsulation, verify that no external code relies on this method being public. The method is only called internally, so this change appears safe. 2. Test coverageThe existing tests in spec/react_on_rails/generators/install_generator_spec.rb verify that success messages appear correctly for both Redux and non-Redux installations (lines 66-86). However, consider adding explicit tests to verify:
3. Package manager detection logicThe package manager detection in install_js_dependencies (lines 197-207) is well-structured with proper fallback handling. The method correctly:
🔒 Security & Performance
✨ Code Quality
✅ Overall AssessmentThis is a well-executed bug fix that improves the user experience during installation. The changes are minimal, focused, and solve the reported issues effectively. The code maintains backward compatibility while fixing the duplicate message problems. Recommendation: Ready to merge after considering the test coverage suggestion above. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
lib/generators/react_on_rails/base_generator.rb (1)
196-223
: Skip bulk install when direct installs already ran; add an early return guard.Avoids second install pass and duplicate logs when any fallback performed direct installs and nothing was queued via
add_npm_dependencies
.Apply this diff:
def install_js_dependencies + # If fallbacks already installed packages directly and we didn't queue any + # package.json edits via `add_npm_dependencies`, skip the bulk install. + return true if @did_any_direct_install && !@used_add_npm_dependencies # Detect which package manager to use success = if File.exist?(File.join(destination_root, "yarn.lock")) run "yarn install" elsif File.exist?(File.join(destination_root, "pnpm-lock.yaml")) run "pnpm install" elsif File.exist?(File.join(destination_root, "package-lock.json")) || File.exist?(File.join(destination_root, "package.json")) # Use npm for package-lock.json or as default fallback run "npm install" else true # No package manager detected, skip end @@ success end
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
lib/generators/react_on_rails/base_generator.rb
(3 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.rb
📄 CodeRabbit inference engine (CLAUDE.md)
Use RuboCop for all Ruby code
Files:
lib/generators/react_on_rails/base_generator.rb
lib/**/*.rb
📄 CodeRabbit inference engine (CLAUDE.md)
Place Ruby gem source under lib/ (e.g., lib/react_on_rails/*)
Files:
lib/generators/react_on_rails/base_generator.rb
🧠 Learnings (2)
📚 Learning: 2025-02-12T16:38:06.537Z
Learnt from: Romex91
PR: shakacode/react_on_rails#1697
File: package-scripts.yml:28-28
Timestamp: 2025-02-12T16:38:06.537Z
Learning: The file `node_package/lib/ReactOnRails.full.js` is autogenerated during the build process and should not be present in the repository.
Applied to files:
lib/generators/react_on_rails/base_generator.rb
📚 Learning: 2025-09-16T08:01:11.146Z
Learnt from: justin808
PR: shakacode/react_on_rails#1770
File: lib/generators/react_on_rails/templates/base/base/app/javascript/src/HelloWorld/ror_components/HelloWorld.client.jsx:2-2
Timestamp: 2025-09-16T08:01:11.146Z
Learning: React on Rails uses webpack CSS Modules configuration with namedExports: true, which requires the import syntax `import * as style from './file.module.css'` rather than the default export pattern. This configuration enables better tree shaking and bundle size optimization for CSS modules.
Applied to files:
lib/generators/react_on_rails/base_generator.rb
🧬 Code graph analysis (1)
lib/generators/react_on_rails/base_generator.rb (1)
lib/generators/react_on_rails/generator_messages.rb (1)
add_warning
(13-15)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
- GitHub Check: dummy-app-integration-tests (3.4, 22)
- GitHub Check: dummy-app-integration-tests (3.2, 20)
- GitHub Check: rspec-package-tests (3.4, minimum)
- GitHub Check: rspec-package-tests (3.2, minimum)
- GitHub Check: rspec-package-tests (3.2, latest)
- GitHub Check: rspec-package-tests (3.4, latest)
- GitHub Check: examples (3.4, latest)
- GitHub Check: examples (3.2, minimum)
- GitHub Check: build
🔇 Additional comments (1)
lib/generators/react_on_rails/base_generator.rb (1)
132-132
: Approve — helpers privatized; public Thor tasks confirmedPrivate is correctly placed; the following methods remain public (Thor tasks): add_hello_world_route, create_react_directories, copy_base_files, copy_js_bundle_files, copy_webpack_config, copy_packer_config, add_base_gems_to_gemfile, add_js_dependencies, update_gitignore_for_auto_registration, append_to_spec_rails_helper
Code Review for PR #1788: Fix duplicate messages in install generator✅ Overall AssessmentThis PR successfully addresses the duplicate message issues in the install generator. The changes are minimal, focused, and solve the problem effectively. 🎯 Code Quality & Best PracticesPositive aspects:
Suggestions:
🐛 Potential IssuesNone identified. The changes properly address the duplicate message problems without introducing new issues. ⚡ Performance Considerations
🔒 Security ConcernsNone. The changes don't introduce any security vulnerabilities. 🧪 Test CoverageConcern: While the existing tests at Recommendation: Consider adding a test that explicitly verifies:
Example test approach: specify "redux generator does not duplicate success messages" do
GeneratorMessages.clear
run_generator_test_with_args(%w[--redux], package_json: true)
output_text = GeneratorMessages.output.join("\n")
# Count occurrences of the success message
success_count = output_text.scan("🎉 React on Rails Successfully Installed!").length
expect(success_count).to eq(1)
end 📝 Additional Notes
✅ ApprovalThis PR effectively fixes the reported issues with minimal, clean changes. The code quality is good and follows the project's conventions. I recommend approval with the minor suggestion to enhance test coverage for message deduplication verification. Great work on identifying and fixing these UX issues! 👍 |
Code Review for PR #1788: Fix duplicate messages in install generatorThank you for this PR addressing the duplicate message issues! I've reviewed the changes and here's my comprehensive feedback: ✅ Code Quality & Best PracticesStrengths:
Suggestions:
✅ Bug FixesThe PR successfully addresses both issues:
✅ Performance Considerations
✅ Security Assessment
|
Code Review✅ Strengths
🔍 Areas for Improvement1. Missing Test Coverage 🚨The PR checklist indicates tests were added/updated, but I don't see any new test files. Consider adding tests for:
2. Method Visibility InconsistencyIn
3. Potential Edge CaseThe condition 💡 Suggestions
describe "install generator messages" do
context "with redux option" do
it "does not display duplicate success messages" do
# Test implementation
end
end
context "without redux option" do
it "displays post-install message once" do
# Test implementation
end
end
end
def detect_package_manager
return :yarn if File.exist?(File.join(destination_root, "yarn.lock"))
return :pnpm if File.exist?(File.join(destination_root, "pnpm-lock.yaml"))
return :npm if File.exist?(File.join(destination_root, "package-lock.json")) ||
File.exist?(File.join(destination_root, "package.json"))
nil
end ✅ Security & Performance
📝 DocumentationWhile the CHANGELOG update isn't required for this bug fix, consider adding a comment explaining why the post-install message is suppressed for Redux installations to help future maintainers understand the logic. VerdictThe changes effectively fix the duplicate message issues. However, test coverage should be added before merging to ensure the fixes work correctly and prevent regression. The code organization could be slightly improved for better maintainability. |
|
Code Review✅ Overall AssessmentThis PR successfully addresses the duplicate message issues in the install generator. The changes are clean and well-focused on the specific problems identified. 🎯 Code Quality & Best PracticesStrengths:
Suggestions:
🐛 Potential Issues
⚡ Performance Considerations
🔒 Security Concerns
🧪 Test Coverage
Recommendation: Add test cases to verify:
💡 Additional Suggestions
def detect_package_manager
return :yarn if File.exist?(File.join(destination_root, "yarn.lock"))
return :pnpm if File.exist?(File.join(destination_root, "pnpm-lock.yaml"))
return :npm if File.exist?(File.join(destination_root, "package-lock.json")) ||
File.exist?(File.join(destination_root, "package.json"))
nil
end
✅ ApprovalThe changes effectively fix the reported issues and the code is production-ready. The suggestions above are for future improvements and don't block merging. |
Code Review for PR #1788: Fix duplicate messages in install generatorSummaryThis PR addresses two duplicate message issues in the install generator:
✅ Strengths
🔍 Issues and Suggestions1. Unused Method in Redux Generator (Medium Priority)The add_redux_specific_messages method in react_with_redux_generator.rb:131 is defined but never called. This appears to be dead code that should either be:
Recommendation: Since this method clears existing messages and adds Redux-specific ones, it should probably be called after the Redux setup completes. Consider adding it to the generator workflow or removing it entirely. 2. Potential Race Condition (Low Priority)The install_js_dependencies method is now called within add_js_dependencies, which might run before all dependencies are fully written to package.json. Recommendation: Verify that all npm package additions complete before the install command runs. 3. Missing Test Coverage (Medium Priority)While the PR checklist indicates tests were added/updated, I don't see specific tests verifying:
Recommendation: Add specific test cases to verify the duplicate message fixes work as intended. 🔒 Security Considerations✅ No security concerns identified. The code properly validates package manager names before building commands, preventing command injection. 🎯 Performance Considerations✅ Positive impact: Eliminating duplicate npm install calls will reduce installation time, especially for projects with many dependencies. 📝 DocumentationThe inline comments added are helpful and explain the reasoning behind the conditional logic. 💡 Additional Suggestions
✅ Overall AssessmentThis PR successfully addresses the stated issues with minimal, focused changes. The refactoring improves code organization while fixing the duplicate message problems. With the suggested improvements (especially addressing the unused method and adding test coverage), this will be a solid contribution. Verdict: Approved with suggestions for improvement 👍 |
Code Review for PR #1788: Fix duplicate messages in install generatorSummaryThis PR addresses two duplicate message issues in the React on Rails install generator. The changes are well-structured and follow good software engineering practices. ✅ Strengths
🔍 Areas for Consideration
🚀 PerformanceThe changes improve performance by eliminating duplicate NPM install operations, which can save significant time during generator execution. 🔒 SecurityNo security concerns identified. Package manager detection and command execution follow safe patterns. ✅ Overall AssessmentThis is a solid bug fix that addresses the reported issues cleanly. The code quality is good and follows Rails generator conventions. With the addition of test coverage to prevent regression, this PR would be ready to merge. Recommendation: Approve with minor suggestions for test coverage enhancement. |
Code Review for PR #1788: Fix duplicate messages in install generatorThanks for this PR @ihabadham! I've conducted a thorough review of the changes. ✅ Strengths
🎯 Suggestions for Improvement
✅ Security & Performance
✅ Test CoverageThe existing test suite appears comprehensive with contexts for both 🔍 Verification NeededPlease verify that the Redux generator ( VerdictThe changes look good and effectively solve the duplicate message problem. With the minor documentation suggestion above, this PR is ready to merge. 👍 🤖 Generated with Claude Code |
Code Review for PR #1788: Fix duplicate messages in install generatorThank you for this PR! I've reviewed the changes and here's my feedback: ✅ What works well
🎯 Suggestions for improvement
✔️ No critical issues found
📊 Overall assessmentThis is a solid bug fix that addresses the reported issues cleanly. The changes are minimal and focused, which reduces the risk of introducing new issues. The code reorganization improves maintainability by grouping related functionality. Recommendation: ✅ Approve with minor suggestions The PR is ready to merge after considering the minor suggestions above, particularly around method visibility consistency. |
Code Review for PR #1788: Fix duplicate messages in install generatorThank you for this PR! I've reviewed the changes and here's my feedback: ✅ Strengths
🔍 Code Quality & Best PracticesThe code follows Rails generator conventions well. The refactoring in
|
Code Review for PR #1788: Fix duplicate messages in install generator🟢 Overall Assessment: APPROVEDThis PR effectively addresses the duplicate message issues in the install generator, with clean and minimal changes that solve the root causes. ✅ What I Like:
🎯 Code Quality & Best Practices:
🔒 Security Considerations:
⚡ Performance Impact:
🧪 Test Coverage Observations:The existing test suite covers:
Suggestion: Consider adding explicit test cases that verify:
💡 Minor Suggestions for Future Improvements:
✅ Conclusion:This is a well-crafted fix that addresses the reported issues without introducing complexity. The changes are minimal, focused, and maintain the existing architecture while solving the duplicate message problems effectively. Great work on keeping this fix clean and targeted! 👍 |
Code Review for PR #1788: Fix duplicate messages in install generator📋 SummaryThis PR addresses duplicate message issues in the install generator:
✅ Strengths
|
Code ReviewThank you for this PR fixing the duplicate message issues! Here's my comprehensive review: ✅ Strengths
🎯 Code Quality & Best Practices
|
Code Review for PR #1788: Fix duplicate messages in install generator🎯 SummaryThis PR successfully addresses the duplicate message issues in the install generator by:
✅ Strengths
🔍 Areas for Improvement
🐛 Potential Issues
🔒 SecurityNo security concerns identified. The code properly uses ⚡ PerformanceNo performance concerns. The changes actually improve performance slightly by eliminating redundant npm install calls. 📋 Recommendations
✨ Overall AssessmentApproved with suggestions ✅ This is a well-implemented fix that cleanly addresses the reported issues. The code is maintainable and follows Rails generator conventions. With the addition of specific test coverage for the deduplication behavior, this will be a solid improvement to the codebase. Great work on identifying and fixing this UX issue! The cleaner output will definitely improve the developer experience when setting up React on Rails. |
Code Review for PR #1788: Fix duplicate messages in install generator🎯 OverviewThis PR addresses two duplicate message issues in the install generator - duplicate Redux success messages and duplicate NPM install command execution. The changes are well-targeted and follow good refactoring practices. ✅ Strengths
🔍 Areas for Consideration1. Test CoverageWhile the existing tests at lines 167-176 in install_generator_spec.rb verify success messages appear, consider adding explicit tests to ensure:
Suggestion: Add a test that counts message occurrences to verify no duplicates occur. 2. Method OrganizationThe base_generator.rb now has install_js_dependencies as a private method alongside other dependency-related private methods. This organization is consistent and appropriate. 3. Error HandlingThe error handling in install_js_dependencies is appropriate - it warns but doesn't fail the generator if package installation fails, allowing users to manually install later. 🐛 Potential IssuesNone identified. The changes appropriately fix the reported issues without introducing new problems. 🔒 SecurityNo security concerns. The package manager detection and execution follows safe patterns without risk of command injection. 🚀 PerformanceMinor performance improvement by eliminating duplicate NPM install execution. 📝 DocumentationNo documentation updates needed as this is a bug fix that doesn't change the API or user-facing behavior. ✨ Suggestions for Future Improvements
✅ VerdictAPPROVED - This is a clean, focused fix that addresses the reported issues without introducing complexity. The code follows project conventions and maintains good separation of concerns. The changes correctly:
Great work on identifying and fixing these usability issues! 👍 |
Code Review for PR #1788: Fix duplicate messages in install generatorThanks for this PR @ihabadham! I've reviewed the changes and here's my detailed feedback: ✅ Strengths
🔍 Areas for Improvement1. Test Coverage GapThe PR claims to add tests but I don't see any new test cases verifying the duplicate message fix:
Recommendation: Add specific test cases like: context "with --redux prevents duplicate messages" do
it "does not show post-install message twice" do
run_generator_test_with_args(%w[--redux], package_json: true)
output_text = GeneratorMessages.output.join("\n")
success_count = output_text.scan("🎉 React on Rails Successfully Installed!").count
expect(success_count).to eq(1)
end
end 2. Potential Edge CaseThe Redux generator clears messages with 3. Documentation UpdateThe PR checklist indicates documentation doesn't need updating, but this behavior change might warrant a note in the generator documentation explaining when success messages appear. 🐛 Potential Issues
🔒 Security ConsiderationsNo security issues identified. The package manager detection and command execution follow safe patterns. ⚡ Performance ConsiderationsGood improvement - eliminating duplicate npm/yarn/pnpm install calls will speed up the generator, especially for projects with many dependencies. 📝 Minor Suggestions
# Only add the post install message if not using Redux
# Redux generator handles its own messages via add_redux_specific_messages
add_post_install_message unless options.redux?
# Skip post-install message for Redux to avoid duplicate success messages
# since ReactWithReduxGenerator::add_redux_specific_messages handles this ✅ Overall AssessmentThis is a solid fix that addresses the reported issues effectively. The main concern is the lack of explicit test coverage for the duplicate message prevention. Once tests are added to verify the fix, this PR will be ready to merge. Recommendation: Approve with minor changes - add test coverage for the duplicate message prevention. |
Code Review for PR #1788: Fix duplicate messages in install generatorSummaryThis PR addresses two duplicate message issues in the install generator. The changes are clean and well-structured. Here is my detailed review: ✅ Strengths
🔍 Code Quality Observations
💡 Suggestions for Improvement
|
@ihabadham check the review comments and address. |
Fixes duplicate success messages in Redux generator and duplicate NPM install output by preventing double execution of generator methods.
2b4e5ea
to
f177299
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
lib/generators/react_on_rails/base_generator.rb (1)
196-223
: Unify package-manager selection for direct installs (avoid npm in yarn/pnpm projects).The fallbacks hardcode npm, which can create/modify the wrong lockfile and confuse users. Introduce a helper that picks the right PM and reuse it for both bulk and per‑group installs.
Proposed helper (define below
private
):def preferred_package_manager if File.exist?(File.join(destination_root, "yarn.lock")) :yarn elsif File.exist?(File.join(destination_root, "pnpm-lock.yaml")) :pnpm else :npm end end def install_packages(packages, dev: false) case preferred_package_manager when :yarn args = ["yarn", "add"] args << "--dev" if dev run (args + packages).join(" ") when :pnpm args = ["pnpm", "add"] args << "--save-dev" if dev run (args + packages).join(" ") else args = ["npm", "install"] args << "--save-dev" if dev system(*args, *packages) end endThen replace direct fallbacks like:
success = system("npm", "install", *react_deps)with:
success = install_packages(react_deps)(and pass
dev: true
for dev deps).
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
lib/generators/react_on_rails/base_generator.rb
(3 hunks)lib/generators/react_on_rails/install_generator.rb
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- lib/generators/react_on_rails/install_generator.rb
🧰 Additional context used
📓 Path-based instructions (2)
{Gemfile,Rakefile,**/*.{rb,rake,gemspec,ru}}
📄 CodeRabbit inference engine (CLAUDE.md)
{Gemfile,Rakefile,**/*.{rb,rake,gemspec,ru}}
: Before every commit/push, runbundle exec rubocop
and fix all violations in Ruby code
Let RuboCop handle all Ruby code formatting; never manually format Ruby files
Files:
lib/generators/react_on_rails/base_generator.rb
{Gemfile,Rakefile,**/*.{rb,rake,gemspec,ru,js,jsx,ts,tsx,json,yml,yaml,md,css,scss}}
📄 CodeRabbit inference engine (CLAUDE.md)
Ensure all committed files end with a trailing newline character
Files:
lib/generators/react_on_rails/base_generator.rb
🧠 Learnings (3)
📚 Learning: 2025-02-12T16:38:06.537Z
Learnt from: Romex91
PR: shakacode/react_on_rails#1697
File: package-scripts.yml:28-28
Timestamp: 2025-02-12T16:38:06.537Z
Learning: The file `node_package/lib/ReactOnRails.full.js` is autogenerated during the build process and should not be present in the repository.
Applied to files:
lib/generators/react_on_rails/base_generator.rb
📚 Learning: 2025-04-26T21:55:55.874Z
Learnt from: alexeyr-ci2
PR: shakacode/react_on_rails#1732
File: spec/dummy/client/app-react16/startup/ReduxSharedStoreApp.client.jsx:40-44
Timestamp: 2025-04-26T21:55:55.874Z
Learning: In the react_on_rails project, files under `app-react16` directories are copied/moved to corresponding `/app` directories during the conversion process (removing the `-react16` suffix), which affects their relative import paths at runtime.
Applied to files:
lib/generators/react_on_rails/base_generator.rb
📚 Learning: 2025-09-16T08:01:11.146Z
Learnt from: justin808
PR: shakacode/react_on_rails#1770
File: lib/generators/react_on_rails/templates/base/base/app/javascript/src/HelloWorld/ror_components/HelloWorld.client.jsx:2-2
Timestamp: 2025-09-16T08:01:11.146Z
Learning: React on Rails uses webpack CSS Modules configuration with namedExports: true, which requires the import syntax `import * as style from './file.module.css'` rather than the default export pattern. This configuration enables better tree shaking and bundle size optimization for CSS modules.
Applied to files:
lib/generators/react_on_rails/base_generator.rb
🧬 Code graph analysis (1)
lib/generators/react_on_rails/base_generator.rb (1)
lib/generators/react_on_rails/generator_messages.rb (1)
add_warning
(13-15)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
- GitHub Check: dummy-app-integration-tests (3.4, 22)
- GitHub Check: dummy-app-integration-tests (3.2, 20)
- GitHub Check: examples (3.2, minimum)
- GitHub Check: examples (3.4, latest)
- GitHub Check: build
- GitHub Check: rspec-package-tests (3.4, latest)
- GitHub Check: rspec-package-tests (3.2, latest)
- GitHub Check: rspec-package-tests (3.4, minimum)
- GitHub Check: rspec-package-tests (3.2, minimum)
🔇 Additional comments (3)
lib/generators/react_on_rails/base_generator.rb (3)
98-104
: Still triggers duplicate installs when any fallback runs; gate the bulk install.If any add_* method falls back to direct installs, the final
install_js_dependencies
causes a second full install. Gate it based on flags set by the add_* methods.Apply this diff here:
- install_js_dependencies + install_js_dependencies if @used_add_npm_dependencies && !@did_any_direct_installAnd update each add_* method (outside this hunk) to track execution paths:
# Example pattern to apply in add_react_on_rails_package / add_react_dependencies / add_css_dependencies / add_dev_dependencies: if add_npm_dependencies(pkgs, dev: false) # dev: true for dev_deps @used_add_npm_dependencies = true return end # Fallback: success = system("npm", "install", *install_args) # see comment on using yarn/pnpm in another review below @did_any_direct_install = true if success handle_npm_failure("...", pkgs, dev: ...) unless success
132-132
: Good: helper methods below are now private; tasks above remain public.This avoids unintended Thor tasks. Please confirm no method below
private
is meant to be a task.
196-223
: GeneratorMessages.add_warning is a module-level (class) method — no change required.
Defined insideclass << self
in lib/generators/react_on_rails/generator_messages.rb, soGeneratorMessages.add_warning
is valid.
Code Review for React on Rails Repository SetupThis appears to be an initial repository setup or major restructuring commit. Based on my analysis of the codebase: ✅ Strengths1. Code Quality & Best Practices
2. Test Coverage
3. Documentation
🔍 Areas for Improvement1. Security Considerations
2. Performance Optimizations
3. Code Maintainability
4. Potential Issues
📋 Recommendations
✨ Overall AssessmentThis is a well-architected gem that provides solid React integration for Rails applications. The codebase demonstrates good engineering practices with comprehensive testing, linting, and documentation. The suggested improvements would enhance security, performance, and maintainability for production deployments. The separation between open-source and Pro features is clear, and the licensing model is transparent. The extensive example applications and test coverage provide confidence in the stability of the implementation. |
Code Review for PR #1788: Fix duplicate messages in install generatorThank you for this PR! I've reviewed the changes and here's my feedback: ✅ Strengths
📋 Code Quality & Best PracticesThe changes follow Ruby best practices and maintain the existing code style. The refactoring is minimal and focused on the specific issue. 🔍 Potential Issues
🚀 Performance ConsiderationsNo performance concerns - the changes are purely organizational and behavioral. 🔐 Security ConcernsNo security issues identified. The package manager detection and command execution maintain proper validation. 💡 Suggestions for Improvement
✅ Overall AssessmentThis is a good, focused fix that addresses the duplicate message issue effectively. The implementation is clean and maintains backward compatibility. With the addition of test coverage, this PR would be ready to merge. Recommendation: Approve with minor suggestions for test coverage improvement. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
lib/generators/react_on_rails/base_generator.rb
(2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
{Gemfile,Rakefile,**/*.{rb,rake,gemspec,ru}}
📄 CodeRabbit inference engine (CLAUDE.md)
{Gemfile,Rakefile,**/*.{rb,rake,gemspec,ru}}
: Before every commit/push, runbundle exec rubocop
and fix all violations in Ruby code
Let RuboCop handle all Ruby code formatting; never manually format Ruby files
Files:
lib/generators/react_on_rails/base_generator.rb
{Gemfile,Rakefile,**/*.{rb,rake,gemspec,ru,js,jsx,ts,tsx,json,yml,yaml,md,css,scss}}
📄 CodeRabbit inference engine (CLAUDE.md)
Ensure all committed files end with a trailing newline character
Files:
lib/generators/react_on_rails/base_generator.rb
🧠 Learnings (4)
📓 Common learnings
Learnt from: Romex91
PR: shakacode/react_on_rails#1697
File: package-scripts.yml:28-28
Timestamp: 2025-02-12T16:38:06.537Z
Learning: The file `node_package/lib/ReactOnRails.full.js` is autogenerated during the build process and should not be present in the repository.
📚 Learning: 2025-02-12T16:38:06.537Z
Learnt from: Romex91
PR: shakacode/react_on_rails#1697
File: package-scripts.yml:28-28
Timestamp: 2025-02-12T16:38:06.537Z
Learning: The file `node_package/lib/ReactOnRails.full.js` is autogenerated during the build process and should not be present in the repository.
Applied to files:
lib/generators/react_on_rails/base_generator.rb
📚 Learning: 2025-04-26T21:55:55.874Z
Learnt from: alexeyr-ci2
PR: shakacode/react_on_rails#1732
File: spec/dummy/client/app-react16/startup/ReduxSharedStoreApp.client.jsx:40-44
Timestamp: 2025-04-26T21:55:55.874Z
Learning: In the react_on_rails project, files under `app-react16` directories are copied/moved to corresponding `/app` directories during the conversion process (removing the `-react16` suffix), which affects their relative import paths at runtime.
Applied to files:
lib/generators/react_on_rails/base_generator.rb
📚 Learning: 2025-09-16T08:01:11.146Z
Learnt from: justin808
PR: shakacode/react_on_rails#1770
File: lib/generators/react_on_rails/templates/base/base/app/javascript/src/HelloWorld/ror_components/HelloWorld.client.jsx:2-2
Timestamp: 2025-09-16T08:01:11.146Z
Learning: React on Rails uses webpack CSS Modules configuration with namedExports: true, which requires the import syntax `import * as style from './file.module.css'` rather than the default export pattern. This configuration enables better tree shaking and bundle size optimization for CSS modules.
Applied to files:
lib/generators/react_on_rails/base_generator.rb
🧬 Code graph analysis (1)
lib/generators/react_on_rails/base_generator.rb (1)
lib/generators/react_on_rails/generator_messages.rb (1)
add_warning
(13-15)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
- GitHub Check: dummy-app-integration-tests (3.2, 20)
- GitHub Check: dummy-app-integration-tests (3.4, 22)
- GitHub Check: examples (3.4, latest)
- GitHub Check: claude-review
- GitHub Check: examples (3.2, minimum)
- GitHub Check: build
- GitHub Check: rspec-package-tests (3.4, latest)
- GitHub Check: rspec-package-tests (3.2, latest)
- GitHub Check: rspec-package-tests (3.4, minimum)
- GitHub Check: rspec-package-tests (3.2, minimum)
🔇 Additional comments (1)
lib/generators/react_on_rails/base_generator.rb (1)
131-132
: Confirm visibility change: all subsequent defs become non‑tasks; verify no external callers.Public tasks above remain public; everything from here down is private. Likely intended, but please confirm no external generator calls these now‑private helpers directly.
Run to find any direct usages outside this file:
def install_js_dependencies | ||
# Detect which package manager to use | ||
success = if File.exist?(File.join(destination_root, "yarn.lock")) | ||
system("yarn", "install") | ||
elsif File.exist?(File.join(destination_root, "pnpm-lock.yaml")) | ||
system("pnpm", "install") | ||
elsif File.exist?(File.join(destination_root, "package-lock.json")) || | ||
File.exist?(File.join(destination_root, "package.json")) | ||
# Use npm for package-lock.json or as default fallback | ||
system("npm", "install") | ||
else | ||
true # No package manager detected, skip | ||
end | ||
|
||
unless success | ||
GeneratorMessages.add_warning(<<~MSG.strip) | ||
⚠️ JavaScript dependencies installation failed. | ||
This could be due to network issues or missing package manager. | ||
You can install dependencies manually later by running: | ||
• npm install (if using npm) | ||
• yarn install (if using yarn) | ||
• pnpm install (if using pnpm) | ||
MSG | ||
end | ||
|
||
success | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
🧩 Analysis chain
Avoid mixing package managers in fallbacks; use a manager‑aware add helper.
Fallbacks elsewhere use npm install ...
even if yarn.lock
/pnpm-lock.yaml
exist, causing lockfile conflicts. Introduce a helper that picks yarn/pnpm/npm and use it for per‑package installs and failure messaging.
Add these helpers (then replace the system("npm", "install", ...)
calls in add_* methods with install_packages(packages, dev: true/false)
, and update handle_npm_failure
to show the right command):
# Helper to detect the package manager once
def detected_package_manager
@detected_package_manager ||= if File.exist?(File.join(destination_root, "yarn.lock"))
:yarn
elsif File.exist?(File.join(destination_root, "pnpm-lock.yaml"))
:pnpm
else
:npm
end
end
def install_packages(packages, dev: false)
case detected_package_manager
when :yarn
args = ["yarn", "add"]
args << "-D" if dev
when :pnpm
args = ["pnpm", "add"]
args << "-D" if dev
else
args = ["npm", "install"]
args << "--save-dev" if dev
end
system(*args, *packages)
end
def suggested_install_cmd(dev: false)
case detected_package_manager
when :yarn then dev ? "yarn add -D" : "yarn add"
when :pnpm then dev ? "pnpm add -D" : "pnpm add"
else dev ? "npm install --save-dev" : "npm install"
end
end
Then, in handle_npm_failure
, build the advice line with:
#{suggested_install_cmd(dev: dev)} #{packages.join(' ')}
Verify call sites and potential double/bulk installs:
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Where is install_js_dependencies actually called?
rg -nP -C3 '\binstall_js_dependencies\b' --type rb
# Any remaining hard-coded npm per-package installs?
rg -nP -C2 'system\(\s*["'\'']npm["'\'']\s*,\s*["'\'']install' --type rb
# Any advice strings that still mention npm specifically?
rg -nP -n 'npm install' --type rb
Length of output: 26
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== Searching for install_js_dependencies occurrences =="
rg -n -C3 '\binstall_js_dependencies\b' || true
echo
echo "== Searching for system(...npm...install...) patterns =="
rg -n -C2 "system\([^)]*['\"]npm['\"][^)]*['\"]install['\"]" || true
echo
echo "== Searching for any system(...) calls that mention npm =="
rg -n -C2 "system\([^)]*npm" || true
echo
echo "== Searching for literal 'npm install' strings =="
rg -n "npm install" || true
echo
echo "== Searching for handle_npm_failure and add_ helpers =="
rg -n -C3 'handle_npm_failure' || true
rg -n -C3 '\badd_' || true
Length of output: 113780
Introduce a package-manager-aware installer and stop hard-coding npm as a fallback
Direct npm fallbacks were found; replace them with a small helper that detects :yarn/:pnpm/:npm, exposes install_packages(packages, dev:), and suggested_install_cmd(dev:) and use it everywhere.
-
Replace system("npm", ...) fallbacks in:
- lib/generators/react_on_rails/base_generator.rb — methods: add_react_on_rails_package, add_react_dependencies, add_css_dependencies, add_dev_dependencies, install_js_dependencies, handle_npm_failure.
- lib/generators/react_on_rails/install_generator.rb — fallback for TypeScript dev packages (system("npm", "install", "--save-dev", ...)).
- lib/generators/react_on_rails/react_with_redux_generator.rb — unify its install/command logic with the helper.
-
Keep add_npm_dependencies (package_json) as the first choice; only call install_packages(...) when that fails and update handle_npm_failure to show suggested_install_cmd(dev: dev) + packages.
🤖 Prompt for AI Agents
lib/generators/react_on_rails/base_generator.rb lines 195-222: the code
currently hard-codes npm as a fallback and duplicates package-manager logic
across several methods; create a small package-manager helper that detects
:yarn/:pnpm/:npm and exposes install_packages(packages, dev: false) and
suggested_install_cmd(dev: false), then replace all direct
system("npm"...)/system("yarn"...)/system("pnpm"... ) calls in the listed
methods to use this helper; specifically, keep existing
add_npm_dependencies(package_json) as the primary path and only call
install_packages when add_npm_dependencies fails, update install_js_dependencies
to use the helper detection and install_packages, and modify handle_npm_failure
to print the helper's suggested_install_cmd(dev: dev) along with the package
list; apply the same replacement in
lib/generators/react_on_rails/install_generator.rb (TypeScript dev packages) and
lib/generators/react_on_rails/react_with_redux_generator.rb so all
install/command logic is unified through the helper and no npm fallback is
hard-coded.
Code Review for PR #1788: Fix duplicate messages in install generatorSummaryThis PR addresses duplicate message and installation command issues in the React on Rails generator. The changes properly reorganize the code to eliminate redundant operations while maintaining backward compatibility. ✅ Strengths
🔍 Areas for Consideration
🐛 Potential Issues
📊 Performance ConsiderationsThe fix properly ensures package installation happens only once, which should improve generator performance, especially on slower networks. 🔒 SecurityNo security concerns identified. The changes do not introduce any new external dependencies or unsafe operations. 💡 Suggestions
✅ Overall AssessmentThe PR successfully addresses the reported issues and the core fix is sound. However, the code duplication introduced should be addressed either by refactoring to share the common code or by documenting why the duplication is necessary. Adding explicit test coverage for the fixed scenarios would also increase confidence in the changes. Recommendation: Approve with suggestions - the functionality works correctly but the code organization could be improved to reduce duplication and improve maintainability. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (3)
lib/generators/react_on_rails/install_generator.rb (2)
519-531
: Make failure advice package‑manager aware (npm/yarn/pnpm).Use the detected lockfile to recommend the correct command.
- def handle_npm_failure(dependency_type, packages, dev: false) - install_command = dev ? "npm install --save-dev" : "npm install" + def handle_npm_failure(dependency_type, packages, dev: false) + install_command = + if File.exist?(File.join(destination_root, "yarn.lock")) + dev ? "yarn add -D" : "yarn add" + elsif File.exist?(File.join(destination_root, "pnpm-lock.yaml")) + dev ? "pnpm add -D" : "pnpm add" + else + dev ? "npm install --save-dev" : "npm install" + end GeneratorMessages.add_warning(<<~MSG.strip)
335-360
: Unify TypeScript fallback install with lockfile detection (avoid hard‑coded npm).Switch the fallback in install_typescript_dependencies to yarn add -D / pnpm add -D / npm install --save-dev based on existing lockfiles, mirroring handle_npm_failure.
Would you like a small helper (suggested_install_cmd, install_packages) to DRY this across methods?
lib/generators/react_on_rails/base_generator.rb (1)
132-145
: Private JS‑dependency flow is fine; avoid duplication with InstallGenerator.add_js_dependencies/install_js_dependencies now exist here and in InstallGenerator. Consider extracting to a shared helper to keep a single source of truth.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
lib/generators/react_on_rails/base_generator.rb
(2 hunks)lib/generators/react_on_rails/install_generator.rb
(3 hunks)lib/generators/react_on_rails/react_with_redux_generator.rb
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
{Gemfile,Rakefile,**/*.{rb,rake,gemspec,ru}}
📄 CodeRabbit inference engine (CLAUDE.md)
{Gemfile,Rakefile,**/*.{rb,rake,gemspec,ru}}
: Before every commit/push, runbundle exec rubocop
and fix all violations in Ruby code
Let RuboCop handle all Ruby code formatting; never manually format Ruby files
Files:
lib/generators/react_on_rails/install_generator.rb
lib/generators/react_on_rails/react_with_redux_generator.rb
lib/generators/react_on_rails/base_generator.rb
{Gemfile,Rakefile,**/*.{rb,rake,gemspec,ru,js,jsx,ts,tsx,json,yml,yaml,md,css,scss}}
📄 CodeRabbit inference engine (CLAUDE.md)
Ensure all committed files end with a trailing newline character
Files:
lib/generators/react_on_rails/install_generator.rb
lib/generators/react_on_rails/react_with_redux_generator.rb
lib/generators/react_on_rails/base_generator.rb
🧠 Learnings (3)
📚 Learning: 2025-02-12T16:38:06.537Z
Learnt from: Romex91
PR: shakacode/react_on_rails#1697
File: package-scripts.yml:28-28
Timestamp: 2025-02-12T16:38:06.537Z
Learning: The file `node_package/lib/ReactOnRails.full.js` is autogenerated during the build process and should not be present in the repository.
Applied to files:
lib/generators/react_on_rails/install_generator.rb
lib/generators/react_on_rails/base_generator.rb
📚 Learning: 2025-04-26T21:55:55.874Z
Learnt from: alexeyr-ci2
PR: shakacode/react_on_rails#1732
File: spec/dummy/client/app-react16/startup/ReduxSharedStoreApp.client.jsx:40-44
Timestamp: 2025-04-26T21:55:55.874Z
Learning: In the react_on_rails project, files under `app-react16` directories are copied/moved to corresponding `/app` directories during the conversion process (removing the `-react16` suffix), which affects their relative import paths at runtime.
Applied to files:
lib/generators/react_on_rails/install_generator.rb
lib/generators/react_on_rails/base_generator.rb
📚 Learning: 2025-09-16T08:01:11.146Z
Learnt from: justin808
PR: shakacode/react_on_rails#1770
File: lib/generators/react_on_rails/templates/base/base/app/javascript/src/HelloWorld/ror_components/HelloWorld.client.jsx:2-2
Timestamp: 2025-09-16T08:01:11.146Z
Learning: React on Rails uses webpack CSS Modules configuration with namedExports: true, which requires the import syntax `import * as style from './file.module.css'` rather than the default export pattern. This configuration enables better tree shaking and bundle size optimization for CSS modules.
Applied to files:
lib/generators/react_on_rails/base_generator.rb
🧬 Code graph analysis (3)
lib/generators/react_on_rails/install_generator.rb (2)
lib/generators/react_on_rails/generator_helper.rb (1)
add_npm_dependencies
(23-39)lib/generators/react_on_rails/generator_messages.rb (1)
add_warning
(13-15)
lib/generators/react_on_rails/react_with_redux_generator.rb (1)
lib/generators/react_on_rails/generator_messages.rb (4)
output
(5-7)clear
(37-39)add_info
(17-19)helpful_message_after_installation
(41-82)
lib/generators/react_on_rails/base_generator.rb (3)
lib/generators/react_on_rails/install_generator.rb (6)
add_js_dependencies
(421-426)install_js_dependencies
(490-517)add_react_on_rails_package
(428-446)add_react_dependencies
(448-462)add_css_dependencies
(464-476)add_dev_dependencies
(478-488)lib/react_on_rails/system_checker.rb (1)
add_warning
(20-22)lib/generators/react_on_rails/generator_messages.rb (1)
add_warning
(13-15)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
- GitHub Check: dummy-app-integration-tests (3.4, 22)
- GitHub Check: dummy-app-integration-tests (3.2, 20)
- GitHub Check: rspec-package-tests (3.2, minimum)
- GitHub Check: examples (3.2, minimum)
- GitHub Check: rspec-package-tests (3.4, minimum)
- GitHub Check: examples (3.4, latest)
- GitHub Check: rspec-package-tests (3.4, latest)
- GitHub Check: rspec-package-tests (3.2, latest)
- GitHub Check: build
- GitHub Check: claude-review
🔇 Additional comments (4)
lib/generators/react_on_rails/install_generator.rb (2)
43-45
: Good: prevent duplicate success message when Redux is enabled.Please confirm ReactWithReduxGenerator exposes a public task that appends its own post‑install message, so users still see guidance after Redux installs.
65-67
: Verified: GeneratorMessages.messages exists — no action required.
lib/generators/react_on_rails/generator_messages.rb defines bothdef output
(line 5) anddef messages
(line 21);print_generator_messages
callingGeneratorMessages.messages
is valid.lib/generators/react_on_rails/base_generator.rb (2)
124-131
: LGTM: RSpec configuration constant addition.Nice consolidation for injecting asset-compile config.
208-235
: Same install duplication and manager‑awareness concerns as in InstallGenerator.Apply the same skip‑bulk‑install logic and manager‑aware advice here for consistency.
Root cause: JavaScript dependency methods in BaseGenerator were public, causing automatic execution when generators were invoked. This led to dependencies being installed twice when using --redux option. Changes: - Move dependency installation methods to private in BaseGenerator - Add explicit dependency management in InstallGenerator - Make Redux generator's success message method public - Ensure success messages appear correctly for all installation types Fixes duplicate installations while maintaining all existing functionality. All 51 generator tests pass. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
6b73496
to
5219afe
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (5)
lib/generators/react_on_rails/base_generator.rb (1)
208-235
: Add Bun support in detection and guidance.You already accept Bun as a valid manager in InstallGenerator checks; add it here for parity.
def install_js_dependencies # Detect which package manager to use success = if File.exist?(File.join(destination_root, "yarn.lock")) system("yarn", "install") elsif File.exist?(File.join(destination_root, "pnpm-lock.yaml")) system("pnpm", "install") + elsif File.exist?(File.join(destination_root, "bun.lockb")) + system("bun", "install") elsif File.exist?(File.join(destination_root, "package-lock.json")) || File.exist?(File.join(destination_root, "package.json")) # Use npm for package-lock.json or as default fallback system("npm", "install") else true # No package manager detected, skip end unless success GeneratorMessages.add_warning(<<~MSG.strip) ⚠️ JavaScript dependencies installation failed. This could be due to network issues or missing package manager. You can install dependencies manually later by running: • npm install (if using npm) • yarn install (if using yarn) • pnpm install (if using pnpm) + • bun install (if using bun) MSG end success endlib/generators/react_on_rails/install_generator.rb (4)
490-517
: Add Bun support to package manager detection and guidance.Parity with earlier package-manager checks; improves DX on bun-only setups.
def install_js_dependencies # Detect which package manager to use success = if File.exist?(File.join(destination_root, "yarn.lock")) system("yarn", "install") elsif File.exist?(File.join(destination_root, "pnpm-lock.yaml")) system("pnpm", "install") + elsif File.exist?(File.join(destination_root, "bun.lockb")) + system("bun", "install") elsif File.exist?(File.join(destination_root, "package-lock.json")) || File.exist?(File.join(destination_root, "package.json")) # Use npm for package-lock.json or as default fallback system("npm", "install") else true # No package manager detected, skip end unless success GeneratorMessages.add_warning(<<~MSG.strip) ⚠️ JavaScript dependencies installation failed. This could be due to network issues or missing package manager. You can install dependencies manually later by running: • npm install (if using npm) • yarn install (if using yarn) • pnpm install (if using pnpm) + • bun install (if using bun) MSG end success end
519-531
: Make failure advice package-manager aware (avoid hard-coded npm).Pick the right command based on detected manager/lockfile.
- def handle_npm_failure(dependency_type, packages, dev: false) - install_command = dev ? "npm install --save-dev" : "npm install" + def handle_npm_failure(dependency_type, packages, dev: false) + install_command = + if File.exist?(File.join(destination_root, "yarn.lock")) + dev ? "yarn add -D" : "yarn add" + elsif File.exist?(File.join(destination_root, "pnpm-lock.yaml")) + dev ? "pnpm add -D" : "pnpm add" + elsif File.exist?(File.join(destination_root, "bun.lockb")) + dev ? "bun add -d" : "bun add" + else + dev ? "npm install --save-dev" : "npm install" + end GeneratorMessages.add_warning(<<~MSG.strip) ⚠️ Failed to install #{dependency_type}.
421-426
: DRY opportunity: reuse BaseGenerator’s helpers instead of duplicating add/install JS logic here.Move shared JS dependency helpers to BaseGenerator and call them from InstallGenerator to reduce duplication and drift.
428-446
: Optional: stop hard-coding npm in per-package fallbacks; use a manager-aware helper.Avoid mixing managers (lockfile conflicts). Introduce small helpers and replace the direct npm calls in the add_* methods.
Add these helpers (can live in this class or a shared module):
# Detect once def detected_package_manager @detected_package_manager ||= if File.exist?(File.join(destination_root, "yarn.lock")) :yarn elsif File.exist?(File.join(destination_root, "pnpm-lock.yaml")) :pnpm elsif File.exist?(File.join(destination_root, "bun.lockb")) :bun else :npm end end def install_packages(packages, dev: false) case detected_package_manager when :yarn system("yarn", "add", *(dev ? ["-D"] : []), *packages) when :pnpm system("pnpm", "add", *(dev ? ["-D"] : []), *packages) when :bun system("bun", "add", *(dev ? ["-d"] : []), *packages) else system("npm", "install", *(dev ? ["--save-dev"] : []), *packages) end endThen, in each add_* fallback, replace
system("npm", "install", ...)
withinstall_packages(packages, dev: ...)
.Also applies to: 448-462, 464-476, 478-488
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
lib/generators/react_on_rails/base_generator.rb
(2 hunks)lib/generators/react_on_rails/install_generator.rb
(3 hunks)lib/generators/react_on_rails/react_with_redux_generator.rb
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- lib/generators/react_on_rails/react_with_redux_generator.rb
🧰 Additional context used
📓 Path-based instructions (2)
{Gemfile,Rakefile,**/*.{rb,rake,gemspec,ru}}
📄 CodeRabbit inference engine (CLAUDE.md)
{Gemfile,Rakefile,**/*.{rb,rake,gemspec,ru}}
: Before every commit/push, runbundle exec rubocop
and fix all violations in Ruby code
Let RuboCop handle all Ruby code formatting; never manually format Ruby files
Files:
lib/generators/react_on_rails/install_generator.rb
lib/generators/react_on_rails/base_generator.rb
{Gemfile,Rakefile,**/*.{rb,rake,gemspec,ru,js,jsx,ts,tsx,json,yml,yaml,md,css,scss}}
📄 CodeRabbit inference engine (CLAUDE.md)
Ensure all committed files end with a trailing newline character
Files:
lib/generators/react_on_rails/install_generator.rb
lib/generators/react_on_rails/base_generator.rb
🧠 Learnings (4)
📚 Learning: 2025-01-23T18:20:45.824Z
Learnt from: alexeyr-ci
PR: shakacode/react_on_rails#1687
File: spec/dummy/package.json:0-0
Timestamp: 2025-01-23T18:20:45.824Z
Learning: When adding or updating dependencies in spec/dummy/package.json, maintain version consistency with other package.json files in the codebase to avoid potential version conflicts.
Applied to files:
lib/generators/react_on_rails/install_generator.rb
📚 Learning: 2025-04-26T21:55:55.874Z
Learnt from: alexeyr-ci2
PR: shakacode/react_on_rails#1732
File: spec/dummy/client/app-react16/startup/ReduxSharedStoreApp.client.jsx:40-44
Timestamp: 2025-04-26T21:55:55.874Z
Learning: In the react_on_rails project, files under `app-react16` directories are copied/moved to corresponding `/app` directories during the conversion process (removing the `-react16` suffix), which affects their relative import paths at runtime.
Applied to files:
lib/generators/react_on_rails/install_generator.rb
lib/generators/react_on_rails/base_generator.rb
📚 Learning: 2025-02-12T16:38:06.537Z
Learnt from: Romex91
PR: shakacode/react_on_rails#1697
File: package-scripts.yml:28-28
Timestamp: 2025-02-12T16:38:06.537Z
Learning: The file `node_package/lib/ReactOnRails.full.js` is autogenerated during the build process and should not be present in the repository.
Applied to files:
lib/generators/react_on_rails/install_generator.rb
lib/generators/react_on_rails/base_generator.rb
📚 Learning: 2025-09-16T08:01:11.146Z
Learnt from: justin808
PR: shakacode/react_on_rails#1770
File: lib/generators/react_on_rails/templates/base/base/app/javascript/src/HelloWorld/ror_components/HelloWorld.client.jsx:2-2
Timestamp: 2025-09-16T08:01:11.146Z
Learning: React on Rails uses webpack CSS Modules configuration with namedExports: true, which requires the import syntax `import * as style from './file.module.css'` rather than the default export pattern. This configuration enables better tree shaking and bundle size optimization for CSS modules.
Applied to files:
lib/generators/react_on_rails/base_generator.rb
🧬 Code graph analysis (2)
lib/generators/react_on_rails/install_generator.rb (2)
lib/generators/react_on_rails/generator_helper.rb (1)
add_npm_dependencies
(23-39)lib/generators/react_on_rails/generator_messages.rb (1)
add_warning
(13-15)
lib/generators/react_on_rails/base_generator.rb (3)
lib/generators/react_on_rails/install_generator.rb (6)
add_js_dependencies
(421-426)install_js_dependencies
(490-517)add_react_on_rails_package
(428-446)add_react_dependencies
(448-462)add_css_dependencies
(464-476)add_dev_dependencies
(478-488)lib/react_on_rails/system_checker.rb (1)
add_warning
(20-22)lib/generators/react_on_rails/generator_messages.rb (1)
add_warning
(13-15)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
- GitHub Check: dummy-app-integration-tests (3.4, 22)
- GitHub Check: dummy-app-integration-tests (3.2, 20)
- GitHub Check: rspec-package-tests (3.2, minimum)
- GitHub Check: rspec-package-tests (3.4, latest)
- GitHub Check: rspec-package-tests (3.4, minimum)
- GitHub Check: rspec-package-tests (3.2, latest)
- GitHub Check: examples (3.4, latest)
- GitHub Check: examples (3.2, minimum)
- GitHub Check: build
🔇 Additional comments (8)
lib/generators/react_on_rails/base_generator.rb (2)
139-145
: LGTM: Centralized JS dependency grouping.The grouping via add_js_dependencies is clear and keeps call sites tidy.
132-137
: Gate bulk install to avoid double-running installs.If any add_* fallback runs a direct install, skip the final bulk install here. Track flags and gate.
- def setup_js_dependencies - add_js_dependencies - install_js_dependencies - end + def setup_js_dependencies + @added_dependencies_to_package_json ||= false + @ran_direct_installs ||= false + add_js_dependencies + install_js_dependencies if @added_dependencies_to_package_json && !@ran_direct_installs + endNote: Ensure the add_* helper methods set these flags (see similar changes suggested in install_generator.rb).
lib/generators/react_on_rails/install_generator.rb (6)
43-46
: Good: avoid duplicate success message for Redux runs.Gating add_post_install_message with
unless options.redux?
resolves the duplicate messaging.
85-88
: Prevent duplicate installs: gate the bulk install.If any add_* fallback did a direct install, a subsequent full install reprints output and wastes time.
- def setup_react_dependencies - add_js_dependencies - install_js_dependencies - end + def setup_react_dependencies + @added_dependencies_to_package_json ||= false + @ran_direct_installs ||= false + add_js_dependencies + install_js_dependencies if @added_dependencies_to_package_json && !@ran_direct_installs + end
428-446
: Track flags to support single-install behavior.Mark when package.json was edited vs. when a direct install was performed.
puts "Installing React on Rails package..." - return if add_npm_dependencies(react_on_rails_pkg) + if add_npm_dependencies(react_on_rails_pkg) + @added_dependencies_to_package_json = true + return + end puts "Using direct npm commands as fallback" - success = system("npm", "install", *react_on_rails_pkg) + success = system("npm", "install", *react_on_rails_pkg) + @ran_direct_installs = true if success handle_npm_failure("react-on-rails package", react_on_rails_pkg) unless success
448-462
: Track flags for React deps to avoid double install.] - return if add_npm_dependencies(react_deps) + if add_npm_dependencies(react_deps) + @added_dependencies_to_package_json = true + return + end - success = system("npm", "install", *react_deps) + success = system("npm", "install", *react_deps) + @ran_direct_installs = true if success handle_npm_failure("React dependencies", react_deps) unless success
464-476
: Track flags for CSS deps to avoid double install.] - return if add_npm_dependencies(css_deps) + if add_npm_dependencies(css_deps) + @added_dependencies_to_package_json = true + return + end - success = system("npm", "install", *css_deps) + success = system("npm", "install", *css_deps) + @ran_direct_installs = true if success handle_npm_failure("CSS dependencies", css_deps) unless success
478-488
: Track flags for dev deps to avoid double install.] - return if add_npm_dependencies(dev_deps, dev: true) + if add_npm_dependencies(dev_deps, dev: true) + @added_dependencies_to_package_json = true + return + end - success = system("npm", "install", "--save-dev", *dev_deps) + success = system("npm", "install", "--save-dev", *dev_deps) + @ran_direct_installs = true if success handle_npm_failure("development dependencies", dev_deps, dev: true) unless success
CONFIGURE_RSPEC_TO_COMPILE_ASSETS = <<-STR.strip_heredoc | ||
RSpec.configure do |config| | ||
# Ensure that if we are running js tests, we are using latest webpack assets | ||
# This will use the defaults of :js and :server_rendering meta tags | ||
ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config) | ||
end | ||
STR | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix RSpec injection: current gsub replaces only the opener with a full block (breaks rails_helper).
Replacing just "RSpec.configure do |config|" with an entire block will leave the original block body and closing end
in place, yielding invalid Ruby and/or duplicated config. Inject inside the existing block instead.
Apply this diff to change the constant to a snippet (no open/close), then insert it inside the existing block (method change shown below):
- CONFIGURE_RSPEC_TO_COMPILE_ASSETS = <<-STR.strip_heredoc
- RSpec.configure do |config|
- # Ensure that if we are running js tests, we are using latest webpack assets
- # This will use the defaults of :js and :server_rendering meta tags
- ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
- end
- STR
+ CONFIGURE_RSPEC_TO_COMPILE_ASSETS = <<~STR.strip
+ # Ensure that if we are running js tests, we are using latest webpack assets
+ # This will use the defaults of :js and :server_rendering meta tags
+ ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
+ STR
Update the injector method (outside this hunk) to insert rather than replace:
def add_configure_rspec_to_compile_assets(helper_file)
snippet = "\n#{CONFIGURE_RSPEC_TO_COMPILE_ASSETS}\n"
content = File.read(helper_file)
return if content.include?("ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)")
insert_into_file(helper_file, snippet, after: /RSpec\.configure do \|config\|\n/)
end
🤖 Prompt for AI Agents
lib/generators/react_on_rails/base_generator.rb lines 124-131: the constant
currently contains a full RSpec.configure open/close block which, when gsubbed
in, duplicates the existing block body and closing `end`; change the constant to
contain only the inner snippet (no opening `RSpec.configure` or `end`) and
update the injector to insert that snippet inside the existing RSpec.configure
block rather than replacing it: read the helper file, early-return if the
configure call is already present, then call insert_into_file with the snippet
after the existing `RSpec.configure do |config|` line so the helper keeps a
single open/close and the snippet is added into the block.
Fix duplicate dependency installations: - Track package_json vs direct install usage to prevent duplicate installs - Only run bulk install when package_json was used and no direct installs occurred - Avoids multiple npm install commands for the same dependencies Fix GeneratorMessages handling: - Remove GeneratorMessages.output.clear to preserve important warnings/errors - Redux generator now appends messages instead of clearing previous ones - Prevents loss of Shakapacker warnings and other installation messages 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
lib/generators/react_on_rails/install_generator.rb (1)
337-362
: TypeScript deps can remain uninstalled — set gating flags here, too.If TypeScript deps are added via package_json (no direct install) and later steps perform direct installs, the final bulk install is skipped and TS deps remain uninstalled. Mark the flags in this method like the other add_* helpers.
Apply:
@@ - # Try using GeneratorHelper first (package manager agnostic) - return if add_npm_dependencies(typescript_packages, dev: true) + # Try using GeneratorHelper first (package manager agnostic) + if add_npm_dependencies(typescript_packages, dev: true) + @added_dependencies_to_package_json = true + return + end @@ - # Fallback to npm if GeneratorHelper fails - success = system("npm", "install", "--save-dev", *typescript_packages) - return if success + # Fallback to npm if GeneratorHelper fails + success = system("npm", "install", "--save-dev", *typescript_packages) + if success + @ran_direct_installs = true + return + end
🧹 Nitpick comments (1)
lib/generators/react_on_rails/install_generator.rb (1)
537-549
: Include per‑manager manual commands (npm/yarn/pnpm/bun) for failed package installs.Improves guidance and aligns with bun support.
Apply:
- def handle_npm_failure(dependency_type, packages, dev: false) - install_command = dev ? "npm install --save-dev" : "npm install" + def handle_npm_failure(dependency_type, packages, dev: false) GeneratorMessages.add_warning(<<~MSG.strip) ⚠️ Failed to install #{dependency_type}. The following packages could not be installed automatically: #{packages.map { |pkg| " • #{pkg}" }.join("\n")} - This could be due to network issues or missing package manager. - You can install them manually later by running: - #{install_command} #{packages.join(' ')} + You can install them manually with your package manager: + • npm: npm install#{dev ? ' --save-dev' : ''} #{packages.join(' ')} + • yarn: yarn add#{dev ? ' -D' : ''} #{packages.join(' ')} + • pnpm: pnpm add#{dev ? ' -D' : ''} #{packages.join(' ')} + • bun: bun add#{dev ? ' --dev' : ''} #{packages.join(' ')} MSG end
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
lib/generators/react_on_rails/install_generator.rb
(3 hunks)lib/generators/react_on_rails/react_with_redux_generator.rb
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- lib/generators/react_on_rails/react_with_redux_generator.rb
🧰 Additional context used
📓 Path-based instructions (2)
{Gemfile,Rakefile,**/*.{rb,rake,gemspec,ru}}
📄 CodeRabbit inference engine (CLAUDE.md)
{Gemfile,Rakefile,**/*.{rb,rake,gemspec,ru}}
: Before every commit/push, runbundle exec rubocop
and fix all violations in Ruby code
Let RuboCop handle all Ruby code formatting; never manually format Ruby files
Files:
lib/generators/react_on_rails/install_generator.rb
{Gemfile,Rakefile,**/*.{rb,rake,gemspec,ru,js,jsx,ts,tsx,json,yml,yaml,md,css,scss}}
📄 CodeRabbit inference engine (CLAUDE.md)
Ensure all committed files end with a trailing newline character
Files:
lib/generators/react_on_rails/install_generator.rb
🧠 Learnings (3)
📚 Learning: 2025-01-23T18:20:45.824Z
Learnt from: alexeyr-ci
PR: shakacode/react_on_rails#1687
File: spec/dummy/package.json:0-0
Timestamp: 2025-01-23T18:20:45.824Z
Learning: When adding or updating dependencies in spec/dummy/package.json, maintain version consistency with other package.json files in the codebase to avoid potential version conflicts.
Applied to files:
lib/generators/react_on_rails/install_generator.rb
📚 Learning: 2025-04-26T21:55:55.874Z
Learnt from: alexeyr-ci2
PR: shakacode/react_on_rails#1732
File: spec/dummy/client/app-react16/startup/ReduxSharedStoreApp.client.jsx:40-44
Timestamp: 2025-04-26T21:55:55.874Z
Learning: In the react_on_rails project, files under `app-react16` directories are copied/moved to corresponding `/app` directories during the conversion process (removing the `-react16` suffix), which affects their relative import paths at runtime.
Applied to files:
lib/generators/react_on_rails/install_generator.rb
📚 Learning: 2025-02-12T16:38:06.537Z
Learnt from: Romex91
PR: shakacode/react_on_rails#1697
File: package-scripts.yml:28-28
Timestamp: 2025-02-12T16:38:06.537Z
Learning: The file `node_package/lib/ReactOnRails.full.js` is autogenerated during the build process and should not be present in the repository.
Applied to files:
lib/generators/react_on_rails/install_generator.rb
🧬 Code graph analysis (1)
lib/generators/react_on_rails/install_generator.rb (2)
lib/generators/react_on_rails/generator_helper.rb (1)
add_npm_dependencies
(23-39)lib/generators/react_on_rails/generator_messages.rb (1)
add_warning
(13-15)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
- GitHub Check: dummy-app-integration-tests (3.4, 22)
- GitHub Check: dummy-app-integration-tests (3.2, 20)
- GitHub Check: examples (3.4, latest)
- GitHub Check: build
- GitHub Check: examples (3.2, minimum)
- GitHub Check: claude-review
- GitHub Check: rspec-package-tests (3.2, latest)
- GitHub Check: rspec-package-tests (3.4, minimum)
- GitHub Check: rspec-package-tests (3.4, latest)
- GitHub Check: rspec-package-tests (3.2, minimum)
🔇 Additional comments (7)
lib/generators/react_on_rails/install_generator.rb (7)
43-46
: Redux post‑install messaging correctly gated.Prevents the duplicate success message when using Redux.
82-90
: Bulk JS install gated to prevent duplicate installs — LGTM.Matches the intended fix: only run the bulk install when package.json was edited and no direct installs ran.
423-429
: Orchestrated JS deps setup is clear and cohesive.
430-452
: React on Rails package install flow looks solid.Pinned when a semver is available; falls back to latest with clear messaging; flags are set correctly.
454-472
: React deps install: good fallback and flagging.
474-490
: CSS deps install: good coverage and flagging.
492-506
: Dev deps install: correct dev flag handling and gating.
def install_js_dependencies | ||
# Detect which package manager to use | ||
success = if File.exist?(File.join(destination_root, "yarn.lock")) | ||
system("yarn", "install") | ||
elsif File.exist?(File.join(destination_root, "pnpm-lock.yaml")) | ||
system("pnpm", "install") | ||
elsif File.exist?(File.join(destination_root, "package-lock.json")) || | ||
File.exist?(File.join(destination_root, "package.json")) | ||
# Use npm for package-lock.json or as default fallback | ||
system("npm", "install") | ||
else | ||
true # No package manager detected, skip | ||
end | ||
|
||
unless success | ||
GeneratorMessages.add_warning(<<~MSG.strip) | ||
⚠️ JavaScript dependencies installation failed. | ||
This could be due to network issues or missing package manager. | ||
You can install dependencies manually later by running: | ||
• npm install (if using npm) | ||
• yarn install (if using yarn) | ||
• pnpm install (if using pnpm) | ||
MSG | ||
end | ||
|
||
success | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Support bun and avoid invoking missing CLIs; otherwise installs may fail silently.
You accept bun as a valid package manager earlier but don’t handle it here, and you might call yarn/pnpm when those CLIs aren’t present. Add bun detection and guard each branch by CLI availability.
Apply:
@@
- success = if File.exist?(File.join(destination_root, "yarn.lock"))
- system("yarn", "install")
- elsif File.exist?(File.join(destination_root, "pnpm-lock.yaml"))
- system("pnpm", "install")
- elsif File.exist?(File.join(destination_root, "package-lock.json")) ||
- File.exist?(File.join(destination_root, "package.json"))
- # Use npm for package-lock.json or as default fallback
- system("npm", "install")
- else
- true # No package manager detected, skip
- end
+ success = if File.exist?(File.join(destination_root, "yarn.lock")) && cli_exists?("yarn")
+ system("yarn", "install")
+ elsif File.exist?(File.join(destination_root, "pnpm-lock.yaml")) && cli_exists?("pnpm")
+ system("pnpm", "install")
+ elsif File.exist?(File.join(destination_root, "bun.lockb")) && cli_exists?("bun")
+ system("bun", "install")
+ elsif (File.exist?(File.join(destination_root, "package-lock.json")) ||
+ File.exist?(File.join(destination_root, "package.json")))
+ # Use npm for package-lock.json or as default fallback
+ system("npm", "install")
+ else
+ true # No supported package manager detected, skip
+ end
@@
- • pnpm install (if using pnpm)
+ • pnpm install (if using pnpm)
+ • bun install (if using bun)
Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
lib/generators/react_on_rails/install_generator.rb around lines 508 to 535: the
current install_js_dependencies block omits bun detection and may call package
manager CLIs that are not installed; update the logic to first detect bun (e.g.,
check for bun lockfile like bun.lockb or presence of the bun binary) and include
a branch that runs bun install, and for each package manager branch (bun, yarn,
pnpm, npm) verify the CLI is available before invoking it (use a portable check
such as `system("command -v <cli> > /dev/null 2>&1")` or equivalent on Windows)
and if the CLI is missing either skip to the next available manager or set
success = false and add a clear GeneratorMessages.add_warning explaining the
missing CLI and how to install or run installs manually; ensure the method still
returns a boolean success value and does not silently attempt to run a missing
binary.
@claude please open followup PR with your suggestions: 🔍 Areas for Consideration
|
@ihabadham @AbanoubGhadban ^^^^ let's see if this works. |
Claude finished @justin808's task —— View job • ✅ Followup PR Created SuccessfullyCompleted Tasks:
Summary of Changes:I've successfully implemented all the requested improvements from the code review:
What Was Changed:
Pull Request:All requested improvements have been implemented successfully. The code is now more maintainable with proper separation of concerns and comprehensive test coverage. |
Addresses code review feedback from PR #1788: 1. Created shared JsDependencyManager module to eliminate code duplication between base_generator.rb and install_generator.rb 2. Added comprehensive test coverage for: - Message deduplication (ensuring messages appear exactly once) - NPM install command deduplication - Proper module inclusion and method organization 3. Improved method organization in install_generator.rb This refactoring follows DRY principles and makes the codebase more maintainable by consolidating shared dependency management logic. Co-authored-by: Justin Gordon <[email protected]>
Summary
Fixes two duplicate message issues in the install generator:
Pull Request checklist
Update documentationUpdate CHANGELOG fileThis change is
Summary by CodeRabbit
Bug Fixes
New Features
Improvements
Tests