shakapacker 9.0.0.beta.10 → 9.0.0.beta.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/docs/transpiler-migration.md +33 -36
- data/lib/shakapacker/doctor.rb +10 -11
- data/lib/shakapacker/swc_migrator.rb +64 -38
- data/lib/shakapacker/version.rb +1 -1
- data/package.json +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e0621d94ac8535638e4678fba06be1449ec6c5705dfd94877866344f9b4784f
|
4
|
+
data.tar.gz: 7727840c175b5b5a710e6f74d5f69b0ad6bbd4a810ec180b38218f2ab435f062
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 126010b0c2bcf735ff324f38a4bddc93435540f543b17c233112535696bfcb0f8005aef1a55563a7cf1526ac5fa4248c9dd6c7e3d04fd17d44348d7b5e9e3f34
|
7
|
+
data.tar.gz: cd8fa6305ed923e30421ef5e427118bfe2d6fcdd3a592c673af5e25340ac047aa34e3fa30b6fe66dfde0e6054b16cf03d48b6d2701b4830cf5164360331052f7
|
data/Gemfile.lock
CHANGED
@@ -22,10 +22,10 @@ Set the transpiler in your `config/shakapacker.yml`:
|
|
22
22
|
default: &default
|
23
23
|
# For webpack users (babel is default, no change needed)
|
24
24
|
javascript_transpiler: babel
|
25
|
-
|
25
|
+
|
26
26
|
# To opt-in to SWC for better performance
|
27
27
|
javascript_transpiler: swc
|
28
|
-
|
28
|
+
|
29
29
|
# For rspack users (swc is default, no change needed)
|
30
30
|
assets_bundler: rspack
|
31
31
|
javascript_transpiler: swc
|
@@ -53,30 +53,26 @@ default: &default
|
|
53
53
|
|
54
54
|
#### 3. Create SWC configuration (optional)
|
55
55
|
|
56
|
-
If you need custom transpilation settings, create
|
57
|
-
|
58
|
-
```
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
"react": {
|
69
|
-
"runtime": "automatic"
|
56
|
+
If you need custom transpilation settings, create `config/swc.config.js`:
|
57
|
+
|
58
|
+
```javascript
|
59
|
+
// config/swc.config.js
|
60
|
+
// This file is merged with Shakapacker's default SWC configuration
|
61
|
+
// See: https://swc.rs/docs/configuration/compilation
|
62
|
+
|
63
|
+
module.exports = {
|
64
|
+
jsc: {
|
65
|
+
transform: {
|
66
|
+
react: {
|
67
|
+
runtime: "automatic"
|
70
68
|
}
|
71
|
-
}
|
72
|
-
"target": "es2015"
|
73
|
-
},
|
74
|
-
"module": {
|
75
|
-
"type": "es6"
|
69
|
+
}
|
76
70
|
}
|
77
71
|
}
|
78
72
|
```
|
79
73
|
|
74
|
+
**Important:** Use `config/swc.config.js` instead of `.swcrc`. The `.swcrc` file completely overrides Shakapacker's default SWC settings and can cause build failures. `config/swc.config.js` properly merges with Shakapacker's defaults.
|
75
|
+
|
80
76
|
#### 4. Update React configuration (if using React)
|
81
77
|
|
82
78
|
For React projects, ensure you have the correct refresh plugin:
|
@@ -93,11 +89,11 @@ yarn add --dev @rspack/plugin-react-refresh
|
|
93
89
|
|
94
90
|
Typical build time improvements when migrating from Babel to SWC:
|
95
91
|
|
96
|
-
| Project Size
|
97
|
-
|
98
|
-
| Small (<100 files)
|
99
|
-
| Medium (100-500 files) | 20s
|
100
|
-
| Large (500+ files)
|
92
|
+
| Project Size | Babel | SWC | Improvement |
|
93
|
+
| ---------------------- | ----- | --- | ----------- |
|
94
|
+
| Small (<100 files) | 5s | 1s | 5x faster |
|
95
|
+
| Medium (100-500 files) | 20s | 3s | 6.7x faster |
|
96
|
+
| Large (500+ files) | 60s | 8s | 7.5x faster |
|
101
97
|
|
102
98
|
### Compatibility Notes
|
103
99
|
|
@@ -125,7 +121,7 @@ If you encounter issues, rolling back is simple:
|
|
125
121
|
```yaml
|
126
122
|
# config/shakapacker.yml
|
127
123
|
default: &default
|
128
|
-
javascript_transpiler: babel
|
124
|
+
javascript_transpiler: babel # Revert to babel
|
129
125
|
```
|
130
126
|
|
131
127
|
Then rebuild your application:
|
@@ -165,20 +161,21 @@ yarn add --dev @swc/core swc-loader
|
|
165
161
|
# Webpack
|
166
162
|
yarn add --dev @pmmmwh/react-refresh-webpack-plugin
|
167
163
|
|
168
|
-
# Rspack
|
164
|
+
# Rspack
|
169
165
|
yarn add --dev @rspack/plugin-react-refresh
|
170
166
|
```
|
171
167
|
|
172
168
|
### Issue: Decorators not working
|
173
169
|
|
174
|
-
**Solution**: Enable decorator support in
|
170
|
+
**Solution**: Enable decorator support in `config/swc.config.js`:
|
175
171
|
|
176
|
-
```
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
172
|
+
```javascript
|
173
|
+
// config/swc.config.js
|
174
|
+
module.exports = {
|
175
|
+
jsc: {
|
176
|
+
parser: {
|
177
|
+
decorators: true,
|
178
|
+
decoratorsBeforeExport: true
|
182
179
|
}
|
183
180
|
}
|
184
181
|
}
|
@@ -188,4 +185,4 @@ yarn add --dev @rspack/plugin-react-refresh
|
|
188
185
|
|
189
186
|
- [SWC Documentation](https://swc.rs/docs/getting-started)
|
190
187
|
- [Babel to SWC Migration Guide](https://swc.rs/docs/migrating-from-babel)
|
191
|
-
- [Rspack Configuration](https://www.rspack.dev/config/index)
|
188
|
+
- [Rspack Configuration](https://www.rspack.dev/config/index)
|
data/lib/shakapacker/doctor.rb
CHANGED
@@ -442,18 +442,17 @@ module Shakapacker
|
|
442
442
|
|
443
443
|
def check_swc_config_conflicts
|
444
444
|
swcrc_path = root_path.join(".swcrc")
|
445
|
-
|
445
|
+
swc_config_path = root_path.join("config/swc.config.js")
|
446
446
|
|
447
|
-
|
448
|
-
swcrc
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
@warnings << "SWC configuration: .swcrc exists but contains invalid JSON"
|
447
|
+
if swcrc_path.exist?
|
448
|
+
@warnings << "SWC configuration: .swcrc file detected. This file completely overrides Shakapacker's default SWC settings and may cause build failures. " \
|
449
|
+
"Please migrate to config/swc.config.js which properly merges with Shakapacker defaults. " \
|
450
|
+
"To migrate: Move your custom settings from .swcrc to config/swc.config.js (see docs for format). " \
|
451
|
+
"See: https://github.com/shakacode/shakapacker/blob/main/docs/using_swc_loader.md"
|
452
|
+
end
|
453
|
+
|
454
|
+
if swc_config_path.exist?
|
455
|
+
@info << "SWC configuration: Using config/swc.config.js (recommended). This config is merged with Shakapacker's defaults."
|
457
456
|
end
|
458
457
|
end
|
459
458
|
|
@@ -8,8 +8,9 @@ module Shakapacker
|
|
8
8
|
class SwcMigrator
|
9
9
|
attr_reader :root_path, :logger
|
10
10
|
|
11
|
+
# Babel packages safe to remove when migrating to SWC
|
12
|
+
# Note: @babel/core and @babel/eslint-parser are excluded as they may be needed for ESLint
|
11
13
|
BABEL_PACKAGES = [
|
12
|
-
"@babel/core",
|
13
14
|
"@babel/plugin-proposal-class-properties",
|
14
15
|
"@babel/plugin-proposal-object-rest-spread",
|
15
16
|
"@babel/plugin-syntax-dynamic-import",
|
@@ -25,6 +26,12 @@ module Shakapacker
|
|
25
26
|
"babel-plugin-transform-react-remove-prop-types"
|
26
27
|
].freeze
|
27
28
|
|
29
|
+
# Babel packages that may be needed for ESLint - only remove if user explicitly confirms
|
30
|
+
ESLINT_BABEL_PACKAGES = [
|
31
|
+
"@babel/core",
|
32
|
+
"@babel/eslint-parser"
|
33
|
+
].freeze
|
34
|
+
|
28
35
|
SWC_PACKAGES = {
|
29
36
|
"@swc/core" => "^1.7.39",
|
30
37
|
"swc-loader" => "^0.2.6"
|
@@ -39,23 +46,21 @@ module Shakapacker
|
|
39
46
|
.eslintrc.json
|
40
47
|
].freeze
|
41
48
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
49
|
+
DEFAULT_SWC_CONFIG = <<~JS.freeze
|
50
|
+
// config/swc.config.js
|
51
|
+
// This file is merged with Shakapacker's default SWC configuration
|
52
|
+
// See: https://swc.rs/docs/configuration/compilation
|
53
|
+
|
54
|
+
module.exports = {
|
55
|
+
jsc: {
|
56
|
+
transform: {
|
57
|
+
react: {
|
58
|
+
runtime: "automatic"
|
59
|
+
}
|
52
60
|
}
|
53
61
|
}
|
54
|
-
},
|
55
|
-
"module" => {
|
56
|
-
"type" => "es6"
|
57
62
|
}
|
58
|
-
|
63
|
+
JS
|
59
64
|
|
60
65
|
def initialize(root_path, logger: nil)
|
61
66
|
@root_path = Pathname.new(root_path)
|
@@ -68,7 +73,7 @@ module Shakapacker
|
|
68
73
|
results = {
|
69
74
|
config_updated: update_shakapacker_config,
|
70
75
|
packages_installed: install_swc_packages,
|
71
|
-
|
76
|
+
swc_config_created: create_swc_config,
|
72
77
|
babel_packages_found: find_babel_packages
|
73
78
|
}
|
74
79
|
|
@@ -76,9 +81,9 @@ module Shakapacker
|
|
76
81
|
logger.info " Note: SWC is approximately 20x faster than Babel for transpilation."
|
77
82
|
logger.info " Please test your application thoroughly after migration."
|
78
83
|
logger.info "\n📝 Configuration Info:"
|
79
|
-
logger.info " - .
|
80
|
-
logger.info " -
|
81
|
-
logger.info " -
|
84
|
+
logger.info " - config/swc.config.js is merged with Shakapacker's default SWC configuration"
|
85
|
+
logger.info " - You can customize config/swc.config.js to add additional options"
|
86
|
+
logger.info " - Avoid using .swcrc as it overrides Shakapacker defaults completely"
|
82
87
|
|
83
88
|
# Show cleanup recommendations if babel packages found
|
84
89
|
if results[:babel_packages_found].any?
|
@@ -108,20 +113,21 @@ module Shakapacker
|
|
108
113
|
package_json_path = root_path.join("package.json")
|
109
114
|
unless package_json_path.exist?
|
110
115
|
logger.error "❌ No package.json found"
|
111
|
-
return { removed_packages: [], config_files_deleted: [] }
|
116
|
+
return { removed_packages: [], config_files_deleted: [], preserved_packages: [] }
|
112
117
|
end
|
113
118
|
|
114
119
|
# Check if ESLint uses Babel parser
|
120
|
+
preserved_for_eslint = []
|
115
121
|
if eslint_uses_babel?
|
116
|
-
logger.info "\n⚠️
|
117
|
-
logger.info "
|
118
|
-
logger.info "
|
119
|
-
logger.info "
|
120
|
-
logger.info "
|
121
|
-
|
122
|
+
logger.info "\n⚠️ ESLint configuration detected that uses Babel parser"
|
123
|
+
logger.info " Preserving @babel/core and @babel/eslint-parser for ESLint compatibility"
|
124
|
+
logger.info " To switch ESLint parser:"
|
125
|
+
logger.info " 1. For TypeScript: use @typescript-eslint/parser"
|
126
|
+
logger.info " 2. For JavaScript: use espree (ESLint's default parser)"
|
127
|
+
preserved_for_eslint = ESLINT_BABEL_PACKAGES
|
122
128
|
end
|
123
129
|
|
124
|
-
removed_packages = remove_babel_from_package_json(package_json_path)
|
130
|
+
removed_packages = remove_babel_from_package_json(package_json_path, preserve: preserved_for_eslint)
|
125
131
|
deleted_files = delete_babel_config_files
|
126
132
|
|
127
133
|
if removed_packages.any?
|
@@ -131,7 +137,7 @@ module Shakapacker
|
|
131
137
|
logger.info "ℹ️ No Babel packages found to remove"
|
132
138
|
end
|
133
139
|
|
134
|
-
{ removed_packages: removed_packages, config_files_deleted: deleted_files }
|
140
|
+
{ removed_packages: removed_packages, config_files_deleted: deleted_files, preserved_packages: preserved_for_eslint }
|
135
141
|
end
|
136
142
|
|
137
143
|
def find_babel_packages
|
@@ -144,7 +150,9 @@ module Shakapacker
|
|
144
150
|
dev_dependencies = package_json["devDependencies"] || {}
|
145
151
|
all_deps = dependencies.merge(dev_dependencies)
|
146
152
|
|
147
|
-
|
153
|
+
# Find all babel packages (including ESLint-related ones for display)
|
154
|
+
all_babel_packages = BABEL_PACKAGES + ESLINT_BABEL_PACKAGES
|
155
|
+
found_packages = all_babel_packages.select { |pkg| all_deps.key?(pkg) }
|
148
156
|
found_packages
|
149
157
|
rescue JSON::ParserError => e
|
150
158
|
logger.error "Failed to parse package.json: #{e.message}"
|
@@ -174,6 +182,11 @@ module Shakapacker
|
|
174
182
|
begin
|
175
183
|
package_json = JSON.parse(File.read(package_json_path))
|
176
184
|
if package_json["eslintConfig"]
|
185
|
+
# Check parser field explicitly
|
186
|
+
parser = package_json["eslintConfig"]["parser"]
|
187
|
+
return true if parser && parser.match?(/@babel\/eslint-parser|babel-eslint/)
|
188
|
+
|
189
|
+
# Also check entire config for babel parser references (catches nested configs)
|
177
190
|
return true if package_json["eslintConfig"].to_json.match?(/@babel\/eslint-parser|babel-eslint/)
|
178
191
|
end
|
179
192
|
|
@@ -254,29 +267,35 @@ module Shakapacker
|
|
254
267
|
{}
|
255
268
|
end
|
256
269
|
|
257
|
-
def
|
258
|
-
|
259
|
-
|
260
|
-
|
270
|
+
def create_swc_config
|
271
|
+
config_dir = root_path.join("config")
|
272
|
+
swc_config_path = config_dir.join("swc.config.js")
|
273
|
+
|
274
|
+
if swc_config_path.exist?
|
275
|
+
logger.info "ℹ️ config/swc.config.js already exists"
|
261
276
|
return false
|
262
277
|
end
|
263
278
|
|
264
|
-
|
265
|
-
|
266
|
-
logger.info "
|
279
|
+
FileUtils.mkdir_p(config_dir) unless config_dir.exist?
|
280
|
+
|
281
|
+
logger.info "📄 Creating config/swc.config.js..."
|
282
|
+
File.write(swc_config_path, DEFAULT_SWC_CONFIG)
|
283
|
+
logger.info "✅ config/swc.config.js created"
|
267
284
|
true
|
268
285
|
rescue StandardError => e
|
269
|
-
logger.error "Failed to create .
|
286
|
+
logger.error "Failed to create config/swc.config.js: #{e.message}"
|
270
287
|
false
|
271
288
|
end
|
272
289
|
|
273
|
-
def remove_babel_from_package_json(package_json_path)
|
290
|
+
def remove_babel_from_package_json(package_json_path, preserve: [])
|
274
291
|
package_json = JSON.parse(File.read(package_json_path))
|
275
292
|
dependencies = package_json["dependencies"] || {}
|
276
293
|
dev_dependencies = package_json["devDependencies"] || {}
|
277
294
|
removed_packages = []
|
278
295
|
|
279
296
|
BABEL_PACKAGES.each do |package|
|
297
|
+
next if preserve.include?(package)
|
298
|
+
|
280
299
|
if dependencies.delete(package)
|
281
300
|
removed_packages << package
|
282
301
|
logger.info " - Removed #{package} from dependencies"
|
@@ -287,6 +306,13 @@ module Shakapacker
|
|
287
306
|
end
|
288
307
|
end
|
289
308
|
|
309
|
+
# Log preserved packages
|
310
|
+
preserve.each do |package|
|
311
|
+
if dependencies[package] || dev_dependencies[package]
|
312
|
+
logger.info " - Preserved #{package} (needed for ESLint)"
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
290
316
|
if removed_packages.any?
|
291
317
|
package_json["dependencies"] = dependencies
|
292
318
|
package_json["devDependencies"] = dev_dependencies
|
data/lib/shakapacker/version.rb
CHANGED
data/package.json
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shakapacker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 9.0.0.beta.
|
4
|
+
version: 9.0.0.beta.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
@@ -347,7 +347,7 @@ homepage: https://github.com/shakacode/shakapacker
|
|
347
347
|
licenses:
|
348
348
|
- MIT
|
349
349
|
metadata:
|
350
|
-
source_code_uri: https://github.com/shakacode/shakapacker/tree/v9.0.0.beta.
|
350
|
+
source_code_uri: https://github.com/shakacode/shakapacker/tree/v9.0.0.beta.11
|
351
351
|
rdoc_options: []
|
352
352
|
require_paths:
|
353
353
|
- lib
|