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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1157b2b32dc1e415593d4b3386abcdc6dc0e8d5b8863d34ca418c4e3333ca9f1
4
- data.tar.gz: 83787074dfb2bce32284997b1312262e28b086ebc7e5bfcd11b647859268b842
3
+ metadata.gz: 8e0621d94ac8535638e4678fba06be1449ec6c5705dfd94877866344f9b4784f
4
+ data.tar.gz: 7727840c175b5b5a710e6f74d5f69b0ad6bbd4a810ec180b38218f2ab435f062
5
5
  SHA512:
6
- metadata.gz: 888e0bbb28ede4eeea180a4a60885a49c073a6aec63f1f84db15c130624b7d8b79f903a66af640e996ddb7985ce022c781c6113dc1f274d4b6f60f59f6851733
7
- data.tar.gz: 432465adefccd3610b99ec23b6551e89a9cc39e658b475f70664af1791587f574f2b4bcb2c833aa1dad7bc11ad06c9dff52f5892b3b914c5629a58f327e90d92
6
+ metadata.gz: 126010b0c2bcf735ff324f38a4bddc93435540f543b17c233112535696bfcb0f8005aef1a55563a7cf1526ac5fa4248c9dd6c7e3d04fd17d44348d7b5e9e3f34
7
+ data.tar.gz: cd8fa6305ed923e30421ef5e427118bfe2d6fcdd3a592c673af5e25340ac047aa34e3fa30b6fe66dfde0e6054b16cf03d48b6d2701b4830cf5164360331052f7
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shakapacker (9.0.0.beta.10)
4
+ shakapacker (9.0.0.beta.11)
5
5
  activesupport (>= 5.2)
6
6
  package_json
7
7
  rack-proxy (>= 0.6.1)
@@ -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 `.swcrc`:
57
-
58
- ```json
59
- {
60
- "$schema": "https://json.schemastore.org/swcrc",
61
- "jsc": {
62
- "parser": {
63
- "syntax": "ecmascript",
64
- "jsx": true,
65
- "dynamicImport": true
66
- },
67
- "transform": {
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 | Babel | SWC | Improvement |
97
- |-------------|-------|-----|-------------|
98
- | Small (<100 files) | 5s | 1s | 5x faster |
99
- | Medium (100-500 files) | 20s | 3s | 6.7x faster |
100
- | Large (500+ files) | 60s | 8s | 7.5x faster |
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 # Revert to 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 `.swcrc`:
170
+ **Solution**: Enable decorator support in `config/swc.config.js`:
175
171
 
176
- ```json
177
- {
178
- "jsc": {
179
- "parser": {
180
- "decorators": true,
181
- "decoratorsBeforeExport": true
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)
@@ -442,18 +442,17 @@ module Shakapacker
442
442
 
443
443
  def check_swc_config_conflicts
444
444
  swcrc_path = root_path.join(".swcrc")
445
- return unless swcrc_path.exist?
445
+ swc_config_path = root_path.join("config/swc.config.js")
446
446
 
447
- begin
448
- swcrc = JSON.parse(File.read(swcrc_path))
449
- # Check for conflicting jsc.target and env settings
450
- if swcrc.dig("jsc", "target") && swcrc["env"]
451
- @issues << "SWC configuration conflict: .swcrc contains both 'jsc.target' and 'env' settings, which are mutually exclusive. Remove 'jsc.target' from .swcrc"
452
- elsif swcrc.dig("jsc", "target")
453
- @warnings << "SWC configuration: .swcrc contains 'jsc.target' which may conflict with the loader's 'env' setting. Consider removing 'jsc.target' from .swcrc to avoid build errors"
454
- end
455
- rescue JSON::ParserError
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
- DEFAULT_SWCRC_CONFIG = {
43
- "jsc" => {
44
- "parser" => {
45
- "syntax" => "ecmascript",
46
- "jsx" => true,
47
- "dynamicImport" => true
48
- },
49
- "transform" => {
50
- "react" => {
51
- "runtime" => "automatic"
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
- }.freeze
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
- swcrc_created: create_swcrc,
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 " - .swcrc provides base configuration for all environments"
80
- logger.info " - The SWC loader adds automatic environment targeting (via 'env' setting)"
81
- logger.info " - You can customize .swcrc, but avoid setting 'jsc.target' as it conflicts with 'env'"
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⚠️ WARNING: ESLint configuration detected that may use Babel"
117
- logger.info " If you use @babel/eslint-parser or babel-eslint, you may need to:"
118
- logger.info " 1. Keep @babel/core and related Babel packages for ESLint"
119
- logger.info " 2. Or switch to @typescript-eslint/parser for TypeScript files"
120
- logger.info " 3. Or use espree (ESLint's default parser) for JavaScript files"
121
- logger.info "\n Proceeding with Babel package removal. Check your ESLint config after."
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
- found_packages = BABEL_PACKAGES.select { |pkg| all_deps.key?(pkg) }
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 create_swcrc
258
- swcrc_path = root_path.join(".swcrc")
259
- if swcrc_path.exist?
260
- logger.info "ℹ️ .swcrc already exists"
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
- logger.info "📄 Creating .swcrc configuration..."
265
- File.write(swcrc_path, JSON.pretty_generate(DEFAULT_SWCRC_CONFIG) + "\n")
266
- logger.info " .swcrc created"
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 .swcrc: #{e.message}"
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
@@ -1,4 +1,4 @@
1
1
  module Shakapacker
2
2
  # Change the version in package.json too, please!
3
- VERSION = "9.0.0.beta.10".freeze
3
+ VERSION = "9.0.0.beta.11".freeze
4
4
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shakapacker",
3
- "version": "9.0.0-beta.10",
3
+ "version": "9.0.0-beta.11",
4
4
  "description": "Use webpack to manage app-like JavaScript modules in Rails",
5
5
  "homepage": "https://github.com/shakacode/shakapacker",
6
6
  "bugs": {
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.10
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.10
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