-
-
Notifications
You must be signed in to change notification settings - Fork 638
Improve SWC compiler detection and default dependencies #2135
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
base: master
Are you sure you want to change the base?
Conversation
Add using_swc? helper method to detect SWC configuration: - Parses shakapacker.yml for javascript_transpiler setting - Returns true when SWC is explicitly configured - Returns true for Shakapacker 9.3.0+ when not specified (SWC default) - Returns true for fresh installations (SWC is recommended) Add SWC dependency installation to generator: - Add SWC_DEPENDENCIES constant (@swc/core, swc-loader) - Install SWC deps automatically when using_swc? returns true - Add to devDependencies since they're build-time tools Update spec/dummy to include SWC packages: - Add @swc/core and swc-loader to devDependencies - Matches the javascript_transpiler: swc setting in shakapacker.yml Add comprehensive tests for using_swc? helper: - Test explicit swc config returns true - Test explicit babel config returns false - Test missing config defaults to SWC for 9.3.0+ - Test missing file defaults to SWC - Test invalid YAML defaults to SWC Closes #1956 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
|
Warning Rate limit exceeded@justin808 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 19 minutes and 46 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (5)
✨ Finishing touches
🧪 Generate unit tests (beta)
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 |
Code Review: PR #2135 - Improve SWC compiler detection and default dependenciesSummaryThis PR adds intelligent SWC (Speedy Web Compiler) detection and automatic dependency installation for the React on Rails generator. Overall, the implementation is well-designed and production-ready with excellent test coverage and error handling. ✅ Strengths1. Excellent Error Handling & Graceful DegradationThe code follows a defensive programming approach that aligns well with the project's error handling philosophy: def parse_shakapacker_yml(path)
require "yaml"
YAML.load_file(path, aliases: true)
rescue ArgumentError
# Older Psych versions don't support the aliases parameter
YAML.load_file(path)
rescue StandardError
# If we can't parse the file, return empty config
{}
end
2. Smart Default BehaviorThe detection logic makes sensible assumptions:
3. Comprehensive Test CoverageThe specs cover all edge cases: ✅ Explicit SWC configuration
✅ Explicit Babel configuration
✅ No transpiler specified (version-based default)
✅ Missing shakapacker.yml
✅ Malformed YAML parsing errors4. Proper Memoizationdef using_swc?
return @using_swc if defined?(@using_swc)
@using_swc = detect_swc_configuration
endUses 5. Clear DocumentationExcellent inline documentation explaining:
🔍 Potential Issues & Suggestions1. Missing Version Check Implementation
|
| Category | Rating | Notes |
|---|---|---|
| Error Handling | ⭐⭐⭐⭐⭐ | Excellent graceful degradation |
| Test Coverage | ⭐⭐⭐⭐½ | Comprehensive, missing version boundary test |
| Documentation | ⭐⭐⭐⭐⭐ | Clear comments and inline docs |
| Code Style | ⭐⭐⭐⭐⭐ | Follows project conventions |
| Security | ⭐⭐⭐⭐☆ | Minor YAML.load concern (low risk) |
| Performance | ⭐⭐⭐⭐⭐ | Proper memoization |
🚀 Testing Recommendations
Before merging, please verify:
-
Fresh Installation Test:
# In a new Rails app without Shakapacker rails new test_app cd test_app bundle add react_on_rails --git=<your-branch> rails generate react_on_rails:install # Verify SWC dependencies are installed grep -E '@swc/core|swc-loader' package.json
-
Babel Override Test:
# Edit config/shakapacker.yml BEFORE running generator # Set javascript_transpiler: babel rails generate react_on_rails:install # Verify SWC dependencies are NOT installed grep -E '@swc/core|swc-loader' package.json # Should be empty
-
Existing Installation Test:
# In an app with existing Shakapacker 9.3.0+ rails generate react_on_rails:install # Verify SWC deps are added
📋 Checklist for Author
- Manual testing completed per recommendations above
- CI passes (RuboCop, RSpec)
- Tested with both fresh and existing installations
- Verified SWC deps are correctly installed/skipped based on config
- Consider adding version boundary test (optional)
- Consider YAML.safe_load_file (optional security hardening)
✅ Final Recommendation
APPROVE with minor suggestions.
This is a well-implemented feature that:
- Solves a real problem (manual SWC dependency installation)
- Has excellent error handling
- Includes comprehensive tests
- Follows project conventions
- Makes sensible default assumptions
The suggestions above are minor improvements, not blocking issues. The code is production-ready as-is.
Great work! 🎉
Reviewed by: Claude Code
Date: 2025-11-26
The JsDependencyManager tests create a mock test class that includes the module. After adding the using_swc? call to add_js_dependencies, the test class needs to provide this method (which comes from GeneratorHelper in actual generator classes). Changes: - Add using_swc? method stub to test class (defaults to true) - Add using_swc setter for test control - Add test for SWC_DEPENDENCIES constant 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Summary
using_swc?helper method to detect SWC configuration in shakapacker.ymlKey Changes
1. Enhanced
using_swc?Helpershakapacker.ymlforjavascript_transpilersettingtruewhen SWC is explicitly configuredtruefor Shakapacker 9.3.0+ when not specified (SWC is the default)truefor fresh installations (SWC is recommended)2. Generator Updates
SWC_DEPENDENCIESconstant with @swc/core and swc-loaderusing_swc?returns true3. spec/dummy Updates
javascript_transpiler: swcsetting already in shakapacker.ymlTesting
using_swc?helperTest Plan
Closes #1956
🤖 Generated with Claude Code