Skip to content

Commit c7908c3

Browse files
justin808claude
andcommitted
Migrate to Shakapacker 9.0.0-beta.11 with SWC transpiler
Upgrade Shakapacker from beta.8 to beta.11 and migrate from Babel to SWC for JavaScript/TypeScript transpilation. Changes: - Update shakapacker gem to 9.0.0.beta.11 - Update Ruby version from 3.4.3 to 3.4.6 for CI compatibility - Set javascript_transpiler: swc in config/shakapacker.yml - Add config/swc.config.js with ES2022 target for minimal transformations - Remove babel.config.js and most Babel dependencies - Keep @babel/core and @babel/preset-react in devDependencies for ESLint - Move @swc/core and swc-loader to dependencies - Update Jest to use @swc/jest - Add parserOptions to .eslintrc for ESLint to work without babel.config.js - Fix validation logic in comments_controller.js to show both error messages - Add explicit class name to Stimulus controller for better debugging 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 577e4b5 commit c7908c3

File tree

9 files changed

+227
-957
lines changed

9 files changed

+227
-957
lines changed

.eslintrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ extends:
55
- plugin:jsx-a11y/recommended
66
- prettier
77

8+
parserOptions:
9+
requireConfigFile: false
10+
babelOptions:
11+
presets:
12+
- "@babel/preset-react"
13+
814
plugins:
915
- react
1016
- jsx-a11y

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
66
ruby "3.4.6"
77

88
gem "react_on_rails", "16.1.1"
9-
gem "shakapacker", "9.0.0.beta.8"
9+
gem "shakapacker", "9.0.0.beta.11"
1010

1111
# Bundle edge Rails instead: gem "rails", github: "rails/rails"
1212
gem "listen"

Gemfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ GEM
383383
websocket (~> 1.0)
384384
semantic_range (3.1.0)
385385
sexp_processor (4.17.1)
386-
shakapacker (9.0.0.beta.8)
386+
shakapacker (9.0.0.beta.11)
387387
activesupport (>= 5.2)
388388
package_json
389389
rack-proxy (>= 0.6.1)
@@ -493,7 +493,7 @@ DEPENDENCIES
493493
scss_lint
494494
sdoc
495495
selenium-webdriver (~> 4)
496-
shakapacker (= 9.0.0.beta.8)
496+
shakapacker (= 9.0.0.beta.11)
497497
spring
498498
spring-commands-rspec
499499
stimulus-rails (~> 1.3)
@@ -502,7 +502,7 @@ DEPENDENCIES
502502
web-console
503503

504504
RUBY VERSION
505-
ruby 3.4.6p54
505+
ruby 3.4.6p0
506506

507507
BUNDLED WITH
508508
2.4.17

babel.config.js

Lines changed: 0 additions & 32 deletions
This file was deleted.

client/app/controllers/comments_controller.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { mangle } from 'marked-mangle';
77
marked.use(gfmHeadingId());
88
marked.use(mangle());
99

10-
export default class extends Controller {
10+
export default class CommentsController extends Controller {
1111
static targets = ['commentList', 'commentAuthor', 'commentText', 'commentRefresh', 'alertDiv', 'errorList'];
1212

1313
resetText() {
@@ -22,10 +22,8 @@ export default class extends Controller {
2222
errorList.innerHTML = '';
2323
if (!inputAuthor.value) {
2424
errors.push('Author');
25-
} else if (!inputText.value) {
26-
errors.push('Text');
27-
} else {
28-
errors.push('Author');
25+
}
26+
if (!inputText.value) {
2927
errors.push('Text');
3028
}
3129
errors.forEach((error) => {

config/shakapacker.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ default: &default
88
cache_path: tmp/shakapacker
99
webpack_compile_output: true
1010
nested_entries: true
11-
javascript_transpiler: babel
11+
javascript_transpiler: swc
1212

1313
# Additional paths webpack should lookup modules
1414
# ['app/assets', 'engine/foo/app/assets']
1515
additional_paths: []
1616

1717
# Reload manifest.json on all requests so we reload latest compiled packs
1818
cache_manifest: false
19-
19+
2020
# Use the config.build_production_command in config/initializers/react_on_rails.rb
2121
shakapacker_precompile: false
2222

config/swc.config.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// config/swc.config.js
2+
// This file is merged with Shakapacker's default SWC configuration
3+
// See: https://swc.rs/docs/configuration/compilation
4+
5+
module.exports = {
6+
jsc: {
7+
parser: {
8+
syntax: 'ecmascript',
9+
jsx: true,
10+
dynamicImport: true,
11+
decorators: false,
12+
},
13+
transform: {
14+
react: {
15+
runtime: 'automatic',
16+
},
17+
// Disable optimizer to preserve class structure for Stimulus
18+
optimizer: {
19+
globals: {
20+
vars: {},
21+
},
22+
},
23+
},
24+
// Critical for Stimulus: preserve class names and method bindings
25+
keepClassNames: true,
26+
// Use spec-compliant class transforms (not loose mode)
27+
loose: false,
28+
// Don't use external helpers
29+
externalHelpers: false,
30+
// Target ES2022 to avoid transforming class features
31+
target: 'es2022',
32+
},
33+
// Preserve ES6 module semantics
34+
module: {
35+
type: 'es6',
36+
},
37+
};

package.json

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,8 @@
3131
"build:clean": "rm -rf public/packs || true"
3232
},
3333
"dependencies": {
34-
"@babel/cli": "^7.21.0",
35-
"@babel/core": "^7.21.0",
36-
"@babel/plugin-transform-runtime": "^7.21.0",
37-
"@babel/preset-env": "^7.20.2",
38-
"@babel/preset-react": "^7.18.6",
3934
"@babel/runtime": "^7.17.9",
35+
"@swc/core": "^1.3.100",
4036
"@glennsl/rescript-fetch": "^0.2.0",
4137
"@glennsl/rescript-json-combinators": "^1.2.1",
4238
"@hotwired/stimulus": "^3.2.1",
@@ -47,9 +43,6 @@
4743
"@rescript/react": "^0.11.0",
4844
"autoprefixer": "^10.4.14",
4945
"axios": "^0.21.1",
50-
"babel-loader": "^9.1.2",
51-
"babel-plugin-macros": "^3.1.0",
52-
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
5346
"classnames": "^2.3.2",
5447
"compression-webpack-plugin": "10.0.0",
5548
"css-loader": "^6.7.3",
@@ -103,14 +96,17 @@
10396
"webpack": "5",
10497
"webpack-assets-manifest": "5",
10598
"webpack-cli": "5",
106-
"webpack-merge": "5"
99+
"webpack-merge": "5",
100+
"swc-loader": "^0.2.6"
107101
},
108102
"devDependencies": {
103+
"@babel/core": "^7.21.0",
109104
"@babel/eslint-parser": "^7.16.5",
105+
"@babel/preset-react": "^7.18.6",
110106
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.10",
107+
"@swc/jest": "^0.2.29",
111108
"@tailwindcss/typography": "^0.5.10",
112109
"@webpack-cli/serve": "^2.0.5",
113-
"babel-jest": "^29.5.0",
114110
"body-parser": "^1.20.2",
115111
"eslint": "^8.35.0",
116112
"eslint-config-prettier": "^8.6.0",
@@ -155,7 +151,7 @@
155151
],
156152
"testRegex": "./app/.*.spec\\.jsx?$",
157153
"transform": {
158-
"^.+\\.jsx?$": "babel-jest"
154+
"^.+\\.jsx?$": "@swc/jest"
159155
}
160156
},
161157
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"

0 commit comments

Comments
 (0)