Install @babel/preset-react for non-SWC generator installs#2421
Install @babel/preset-react for non-SWC generator installs#2421
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughThe generator now installs Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
Greptile SummaryThis PR fixes a missing dependency issue where the generator creates a Key Changes:
Why This Matters: Confidence Score: 5/5
Important Files Changed
Flowchartflowchart TD
A[Generator starts] --> B[add_js_dependencies called]
B --> C{using_swc?}
C -->|true| D[add_swc_dependencies]
C -->|false| E[add_babel_react_dependencies]
D --> F[Install @swc/core and swc-loader as devDependencies]
E --> G[Install @babel/preset-react as devDependency]
F --> H[Continue with other dependencies]
G --> H
H --> I[babel.config.js template requires @babel/preset-react]
I --> J{SWC path?}
J -->|Yes| K[No babel.config.js needed - SWC handles transpilation]
J -->|No| L[babel.config.js uses @babel/preset-react preset]
Last reviewed commit: ff49925 |
a66cc1e to
1e0da86
Compare
|
PR top-level review: see inline comments below for specific line-level feedback. Summary of issues found:
|
|
|
||
| def add_transpiler_dependencies | ||
| add_swc_dependencies if using_swc? | ||
| add_babel_react_dependencies if !using_swc? && !using_rspack? |
There was a problem hiding this comment.
Bug: esbuild transpiler installs @babel/preset-react incorrectly
using_swc? returns false for any non-SWC transpiler, including esbuild and none. If a user has javascript_transpiler: 'esbuild' in their shakapacker.yml, this condition will incorrectly install @babel/preset-react, which esbuild doesn't use.
The intent appears to be "install only when Babel is the active transpiler", not "install whenever SWC isn't". Consider adding a using_babel? helper in GeneratorHelper that explicitly checks for transpiler == "babel", or guard this with a check specifically for the babel case:
| add_babel_react_dependencies if !using_swc? && !using_rspack? | |
| add_babel_react_dependencies if using_babel? |
Where using_babel? would be something like:
def using_babel?
!using_swc? && !using_rspack? && transpiler_is_babel?
endThis also avoids the double-negative condition which is harder to read at a glance.
| MSG | ||
| end | ||
|
|
||
| def add_babel_react_dependencies |
There was a problem hiding this comment.
Consider whether @babel/core is missing from BABEL_REACT_DEPENDENCIES
@babel/preset-react requires @babel/core as a peer dependency. This works today because Shakapacker (when configured with Babel) already installs @babel/core as a transitive dependency. However, this is an implicit coupling — if a user installs @babel/preset-react and their Shakapacker version does not pull in @babel/core automatically, they'll get a confusing peer dependency warning.
Worth a brief comment explaining why @babel/core is intentionally omitted (i.e., "Shakapacker's babel-loader already provides @babel/core").
| expect(babel_calls).to eq([]) | ||
| end | ||
|
|
||
| it "does not add Babel React preset when rspack is used and SWC is not configured" do |
There was a problem hiding this comment.
Missing test case: esbuild transpiler
There's a test for the rspack case, but there's no test verifying the behavior when javascript_transpiler: 'esbuild' is in use. Given the bug noted on add_transpiler_dependencies — where using_swc? == false for esbuild — adding a spec here would both document the expected behavior and catch the regression:
it "does not add Babel React preset when esbuild is used" do
instance.using_swc = false
# simulate esbuild: currently the code would incorrectly install @babel/preset-react
# This test documents the expected (correct) behavior once the guard is fixed
...
end
Review SummaryThe direction is correct — fixing #2281 by explicitly installing Bug: The condition in Other notes:
|
- Stamp version header for 16.4.0.rc.7 - Collapse rc.6 section into rc.7 (single prerelease section) - Add new entries: #2418 (CSP nonce for RSC), #2421 (babel preset), #2581 (doctor false positives) - Remove duplicate PR 2407 entry (appeared in both sections) - Update version diff links Co-Authored-By: Claude Opus 4.6 <[email protected]>
Summary
BABEL_REACT_DEPENDENCIESto the generator dependency manager@babel/preset-reactas a dev dependency when SWC is not the active transpiler@babel/preset-reactfor older Shakapacker/Babel defaultsCloses #2281
Test plan
bundle exec rspec react_on_rails/spec/react_on_rails/generators/js_dependency_manager_spec.rbbundle exec rspec react_on_rails/spec/react_on_rails/generators/install_generator_spec.rb2.6.10) vs project requirement (>= 3.0.0)Summary by CodeRabbit
New Features
Tests
Note
Low Risk
Small, generator-only dependency change with expanded test coverage; main risk is unintended
package.jsonoutput differences for non-SWC installs.Overview
Ensures generator installs
@babel/preset-reactas a dev dependency for non-SWC setups, while keeping the existing SWC path unchanged.JsDependencyManager#add_js_dependenciesnow conditionally installs eitherSWC_DEPENDENCIESor the newBABEL_REACT_DEPENDENCIES, with matching warning/"install manually" messaging on failure. Specs are updated to assert the new dependency behavior (includinginstall_generator_specexpectations for older Shakapacker/Babel defaults) and to track multipleadd_npm_dependenciescalls for verification.Written by Cursor Bugbot for commit 1e0da86. Configure here.