Fix SWC migration to use config/swc.config.js instead of .swcrc (#634)#635
Fix SWC migration to use config/swc.config.js instead of .swcrc (#634)#635
Conversation
This addresses three critical issues with the rake shakapacker:migrate_to_swc task: 1. Configuration Override Issue - Changed migration to create config/swc.config.js instead of .swcrc - .swcrc completely overrides Shakapacker defaults, breaking webpack-merge - config/swc.config.js properly merges with Shakapacker's default settings - Prevents loss of important defaults (loose: true, env.coreJs: 3, source maps) 2. ESLint Dependency Preservation - Split BABEL_PACKAGES into safe-to-remove and ESLint-related packages - @babel/core and @babel/eslint-parser now preserved when ESLint uses them - Prevents breaking ESLint in projects using eslint-config-shakacode - Improved warning messages with actionable migration steps 3. Doctor Check Improvements - Updated to warn about .swcrc anti-pattern - Removed obsolete jsc.target/env conflict checks (no longer generated) - Added info message for recommended config/swc.config.js usage Testing: - All RSpec tests updated and passing - RuboCop clean - JavaScript linting clean Documentation: - Updated transpiler-migration.md to show config/swc.config.js - Added important note about .swcrc vs config/swc.config.js - Fixed decorator example to use recommended config file 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
Warning Rate limit exceeded@justin808 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 1 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 #635: Fix SWC migration to use config/swc.config.jsSummaryThis is an excellent bug fix that addresses a critical issue with the SWC migration task. The PR correctly identifies and fixes three major problems with the migration flow. The implementation is solid and well-tested. ✅ Strengths1. Well-Designed Solution
2. Smart ESLint Handling
3. Comprehensive Testing
4. Excellent Documentation
5. Good Code Quality
🔍 Observations & Minor Suggestions1. Code Style ✅The whitespace-only changes (lines with trailing spaces removed) follow the project's linting requirements - good attention to detail! 2. Doctor Check Logic (lib/shakapacker/doctor.rb:443-456)The new logic is simpler and more effective than the old Suggestion: The warning message at line 448-450 is quite long. Consider if it could be split into multiple messages for better readability, though the current approach is acceptable. 3. Migration Path for Existing UsersThe PR description mentions existing users will get warnings from Question: Should there be a task like 4. DEFAULT_SWC_CONFIG Format (lib/shakapacker/swc_migrator.rb:49-63)The heredoc format for the JavaScript config is clean. The comment at the top is helpful. Nitpick: The comment references the SWC docs at line 52. Consider adding a note about what settings Shakapacker provides by default so users know what they can safely override vs. what's already configured. 5. Test Assertions (spec/shakapacker/swc_migrator_spec.rb:77-79)The test reads the generated file and checks for string content. This is pragmatic and works well. config_content = File.read(root_path.join("config/swc.config.js"))
expect(config_content).to include("module.exports")
expect(config_content).to include('runtime: "automatic"')This is fine, though theoretically the test could be more robust by actually 🐛 Potential Issues1. Minor: Directory Creation (lib/shakapacker/swc_migrator.rb:274)FileUtils.mkdir_p(config_dir) unless config_dir.exist?This is fine, but FileUtils.mkdir_p(config_dir)2. ESLint Detection Heuristic (lib/shakapacker/swc_migrator.rb:165-199)The comment at lines 167-169 correctly notes this is a heuristic that may have false positives. The false positive bias is the right choice here (better to preserve packages unnecessarily than break ESLint). However, the string matching at line 176 could potentially match these strings in comments: return true if content.match?(/@babel\/eslint-parser|babel-eslint/)Suggestion: While false positives are acceptable, you could reduce them by:
That said, this is probably premature optimization - the current approach is pragmatic and safe. 🔒 Security ConsiderationsNo security concerns identified. The code:
⚡ Performance ConsiderationsNo performance concerns. All operations are file I/O bound and occur during migration (not runtime). The migration is already an infrequent operation. 📊 Test Coverage AssessmentExcellent test coverage:
The test suite properly validates all the new behavior. 📝 Documentation QualityVery good:
Final Verdict✅ Approve with minor suggestions This is a well-crafted bug fix that solves real problems users are experiencing. The code quality is high, testing is comprehensive, and the documentation is clear. The minor suggestions above are truly minor and don't block merging. The separation of ESLint-related Babel packages is particularly thoughtful - it shows understanding of real-world usage patterns where projects use Babel for ESLint but SWC for transpilation. Recommendation: Merge after addressing the directory creation redundancy (if desired) and considering whether to add CHANGELOG notes about the migration path for existing Great work! 🎉 Review conducted following Shakapacker's CLAUDE.md guidelines |
Code Review for PR #635: Fix SWC Migration Configuration✅ Overall AssessmentThis is a well-executed bug fix that addresses critical issues in the SWC migration task. The changes are thoughtful, well-tested, and properly documented. 🎯 Strengths1. Problem Identification & Solution
2. ESLint Dependencies Handling
3. Code Quality
4. Test Coverage ✅
5. Documentation
🔍 Potential Issues & Suggestions1. Minor: Inconsistent Constant Definition (Low Priority)Location: The diff shows 2. Doctor Check Could Be More ActionableLocation: The new warning for @warnings << "SWC configuration: .swcrc file detected. This file completely overrides Shakapacker's default SWC settings and may cause build failures. " \
"Please migrate to config/swc.config.js which properly merges with Shakapacker defaults. " \
"Run 'rake shakapacker:migrate_to_swc' to update your config. " \
"See: https://github.com/shakacode/shakapacker/blob/main/docs/using_swc_loader.md?target=https://github.com"3. Config File Format ConsiderationLocation: The default config uses ES6 module syntax ( // Alternative ESM format (if supported by the loader)
export default {
jsc: {
transform: {
react: { runtime: "automatic" }
}
}
}However, 4. ESLint Detection HeuristicLocation: The ESLint detection using regex is reasonable, but has a known limitation (noted in comments). Consider adding a check for # Check for parser field in ESLint config
if package_json["eslintConfig"] && package_json["eslintConfig"]["parser"]
parser = package_json["eslintConfig"]["parser"]
return true if parser.match?(/@babel\/eslint-parser|babel-eslint/)
end🔒 Security Considerations✅ No security concerns identified
⚡ Performance Considerations✅ Performance is appropriate
📊 Test Coverage✅ Excellent test coverage
🎯 RecommendationsMust-Have (Before Merge):✅ All items already addressed in the PR Nice-to-Have (Future Improvements):
📝 Final VerdictLGTM 🚀 This PR successfully fixes a critical bug in the migration task while being backwards compatible and user-friendly. The code is clean, well-tested, and properly documented. The approach of preserving ESLint dependencies is smart and prevents breaking user setups. Recommendation: ✅ Approve and merge Great work on this fix, @justin808! The attention to detail in handling edge cases (especially ESLint) shows excellent engineering judgment. |
Pull Request Review: Fix SWC Migration (#635)SummaryThis PR addresses a critical issue where the SWC migration task was creating .swcrc files that completely override Shakapacker's defaults, breaking the webpack-merge functionality. The fix changes the migration to use config/swc.config.js instead, which properly merges with defaults. Code Quality & Best PracticesExcellent Practices
Suggested Improvements1. Missing trailing newline verificationPer CLAUDE.md requirements, all files must end with a trailing newline. Please verify all modified files comply. 2. Potential issue in clean_babel_packages return valueIn lib/shakapacker/swc_migrator.rb:111, the early return hash doesn't match the new signature at line 134. Consider adding preserved_packages key for consistency. 3. Inconsistent ESLint detection behaviorThe eslint_uses_babel? method has good heuristics, but the warning message could be more specific about where the detection occurred. Potential Bugs1. find_babel_packages shows packages that won't be removedAt lib/shakapacker/swc_migrator.rb:153, the method now includes ESLint packages in the results. This means cleanup recommendations will suggest removing @babel/core and @babel/eslint-parser even though they'll be preserved for ESLint. Consider filtering the display to only show packages that will actually be removed. 2. Test expectations may need clarificationThe test at line 277 has a comment saying it removes babel packages but not @babel/core or @babel/eslint-parser, but the test context doesn't set up ESLint, so those packages would actually be removed. The comment and test expectations should align. Test CoverageExcellent Coverage
Missing Coverage
Action ItemsBefore Merge
Nice to Have
ConclusionThis is a high-quality PR that fixes a critical bug in the SWC migration task. The approach is sound, the code is well-structured, and the test coverage is comprehensive. The issues identified above are minor and mostly relate to edge cases and consistency. Recommendation: Approve with minor revisions The PR successfully addresses the core issue and adds valuable functionality. The documentation updates are clear and helpful. Great work! |
- Add migration instructions to .swcrc warning in Doctor - Explicitly check parser field in ESLint config for better detection - Keep fallback to full config scan for nested configurations 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Code Review - PR #635: Fix SWC migration to use config/swc.config.js✅ Overall AssessmentThis is an excellent bug fix that addresses a critical issue with the SWC migration task. The changes are well-structured, thoroughly tested, and properly documented. 🎯 Code Quality & Best PracticesStrengths:
Minor observations:
🐛 Potential Bugs/IssuesNo critical bugs found, but some considerations:
⚡ Performance Considerations
🔒 Security Considerations
🧪 Test CoverageExcellent test coverage:
Suggestions:
📋 Additional ObservationsDocumentation:
Breaking changes:
Adherence to CLAUDE.md:
🎉 RecommendationAPPROVE - This PR is ready to merge. It:
The split between safe-to-remove and ESLint-required Babel packages is particularly elegant and shows good understanding of real-world usage patterns. Great work! 🚀 |
Code Review for PR #635SummaryThis PR fixes a critical bug in the SWC migration task. The code quality is excellent with comprehensive test coverage. ✅ Strengths
🔍 Minor Suggestions1. ESLint Detection (lib/shakapacker/swc_migrator.rb:190)Consider adding a comment explaining why .to_json.match? is used (to catch nested configs). 2. Doctor Warning (lib/shakapacker/doctor.rb:448-451)The 4-line concatenated warning might not wrap well on some terminals. Consider using newlines for better readability. 3. Test Clarity (spec/shakapacker/swc_migrator_spec.rb:277-286)Test description could clarify that @babel/core is now in ESLINT_BABEL_PACKAGES constant. 🔒 Security: ✅ No concerns⚡ Performance: ✅ No concerns🐛 Bugs: ✅ None identified📚 Documentation: ✅ ExcellentFinal Verdict✅ APPROVED - High-quality bug fix. Suggestions above are minor and don't block merging. Great work! 🎉 |
Consolidates all beta version changes into final v9.0.0 entry. Key changes: - Merged unreleased changes and all beta entries into v9.0.0 section - Added PR references for TypeScript installer support (#633) - Added details for SWC migration fix (#635) - Added NODE_ENV fix details (#632) - Updated version comparison links to point to v9.0.0 - Removed all beta version sections (beta.8 through beta.11) - Organized changes by category: Breaking Changes, Added, Security, Fixed 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Summary
Fixes #634 - The
rake shakapacker:migrate_to_swctask now createsconfig/swc.config.jsinstead of.swcrc, fixing three critical issues that made the migration task broken for most users.Changes Made
1. Configuration File Change
config/swc.config.jsinstead of.swcrc.swcrccompletely overrides Shakapacker's default SWC settings, bypassing webpack-mergeconfig/swc.config.jsproperly merges with Shakapacker's defaults, preserving important settings likeloose: true,env.coreJs: 3, source maps, and dynamic parser configuration2. ESLint Dependencies Preserved
BABEL_PACKAGESinto safe-to-remove packages and ESLint-related packages (ESLINT_BABEL_PACKAGES)@babel/coreand@babel/eslint-parserwhen ESLint uses themeslint-config-shakacode) require these packages for ESLint to work3. Doctor Check Updates
.swcrcfile is detected (anti-pattern)jsc.target/envconflict checks (no longer generated)config/swc.config.js4. Documentation Updates
transpiler-migration.mdto showconfig/swc.config.jsinstead of.swcrc.swcrcvsconfig/swc.config.jsdifferenceTesting
Breaking Changes
None - this is a bug fix that makes the migration task actually work correctly.
Migration Path
Existing users with
.swcrcfiles will:shakapacker:doctorto migrate toconfig/swc.config.jsconfig/swc.config.js🤖 Generated with Claude Code