shakapacker 9.0.0.beta.7 → 9.0.0.beta.9
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/.eslintrc.fast.js +40 -0
- data/.eslintrc.js +48 -0
- data/.gitignore +1 -3
- data/.husky/pre-commit +2 -0
- data/.npmignore +1 -0
- data/CHANGELOG.md +25 -22
- data/CONTRIBUTING.md +75 -21
- data/Gemfile.lock +1 -1
- data/README.md +3 -2
- data/TODO.md +15 -16
- data/TODO_v9.md +5 -2
- data/conductor-setup.sh +12 -0
- data/docs/css-modules-export-mode.md +102 -8
- data/docs/v9_upgrade.md +57 -3
- data/lib/shakapacker/doctor.rb +94 -0
- data/lib/shakapacker/swc_migrator.rb +60 -2
- data/lib/shakapacker/version.rb +1 -1
- data/package/babel/preset.ts +56 -0
- data/package/esbuild/index.ts +42 -0
- data/package/optimization/rspack.ts +36 -0
- data/package/optimization/{webpack.js → webpack.ts} +12 -4
- data/package/plugins/{rspack.js → rspack.ts} +20 -5
- data/package/plugins/{webpack.js → webpack.ts} +2 -2
- data/package/rspack/{index.js → index.ts} +17 -10
- data/package/rules/{babel.js → babel.ts} +1 -1
- data/package/rules/{coffee.js → coffee.ts} +1 -1
- data/package/rules/{css.js → css.ts} +1 -1
- data/package/rules/{erb.js → erb.ts} +1 -1
- data/package/rules/{esbuild.js → esbuild.ts} +2 -2
- data/package/rules/{file.js → file.ts} +11 -6
- data/package/rules/{jscommon.js → jscommon.ts} +4 -4
- data/package/rules/{less.js → less.ts} +3 -3
- data/package/rules/raw.ts +25 -0
- data/package/rules/{rspack.js → rspack.ts} +21 -11
- data/package/rules/{sass.js → sass.ts} +1 -1
- data/package/rules/{stylus.js → stylus.ts} +3 -7
- data/package/rules/{swc.js → swc.ts} +2 -2
- data/package/rules/{webpack.js → webpack.ts} +1 -1
- data/package/swc/index.ts +54 -0
- data/package/utils/getStyleRule.ts +7 -2
- data/package.json +22 -2
- data/scripts/type-check-no-emit.js +27 -0
- data/test/package/rules/raw.test.js +40 -7
- data/test/package/rules/webpack.test.js +21 -2
- data/tools/README.md +2 -2
- data/tsconfig.eslint.json +16 -0
- data/tsconfig.json +9 -10
- data/yarn.lock +415 -6
- metadata +28 -24
- data/package/babel/preset.js +0 -48
- data/package/esbuild/index.js +0 -40
- data/package/optimization/rspack.js +0 -29
- data/package/rules/raw.js +0 -15
- data/package/swc/index.js +0 -50
|
@@ -32,6 +32,55 @@ import * as styles from './Foo.module.css';
|
|
|
32
32
|
- Aligns with modern JavaScript module standards
|
|
33
33
|
- Automatically converts kebab-case to camelCase (`my-button` → `myButton`)
|
|
34
34
|
|
|
35
|
+
### Important: exportLocalsConvention with namedExport
|
|
36
|
+
|
|
37
|
+
When `namedExport: true` is enabled (v9 default), css-loader requires `exportLocalsConvention` to be either `'camelCaseOnly'` or `'dashesOnly'`.
|
|
38
|
+
|
|
39
|
+
**The following will cause a build error:**
|
|
40
|
+
```js
|
|
41
|
+
modules: {
|
|
42
|
+
namedExport: true,
|
|
43
|
+
exportLocalsConvention: 'camelCase' // ❌ ERROR: incompatible with namedExport: true
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**Error message:**
|
|
48
|
+
```
|
|
49
|
+
"exportLocalsConvention" with "camelCase" value is incompatible with "namedExport: true" option
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**Correct v9 configuration:**
|
|
53
|
+
```js
|
|
54
|
+
modules: {
|
|
55
|
+
namedExport: true,
|
|
56
|
+
exportLocalsConvention: 'camelCaseOnly' // ✅ Correct - only camelCase exported
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
**exportLocalsConvention options with namedExport:**
|
|
61
|
+
|
|
62
|
+
When `namedExport: true`, you can use:
|
|
63
|
+
- `'camelCaseOnly'` (v9 default): Exports ONLY the camelCase version (e.g., only `myButton`)
|
|
64
|
+
- `'dashesOnly'`: Exports ONLY the original kebab-case version (e.g., only `my-button`)
|
|
65
|
+
|
|
66
|
+
**Not compatible with namedExport: true:**
|
|
67
|
+
- `'camelCase'`: Exports both versions (both `my-button` and `myButton`) - only works with `namedExport: false` (v8 behavior)
|
|
68
|
+
|
|
69
|
+
**Configuration Quick Reference:**
|
|
70
|
+
|
|
71
|
+
| namedExport | exportLocalsConvention | `.my-button` exports | Use Case | Compatible? |
|
|
72
|
+
|-------------|------------------------|---------------------|----------|-------------|
|
|
73
|
+
| `true` | `'camelCaseOnly'` | `myButton` | JavaScript conventions | ✅ Valid |
|
|
74
|
+
| `true` | `'dashesOnly'` | `'my-button'` | Preserve CSS naming | ✅ Valid |
|
|
75
|
+
| `false` | `'camelCase'` | Both `myButton` AND `'my-button'` | v8 compatibility | ✅ Valid |
|
|
76
|
+
| `false` | `'asIs'` | `'my-button'` | No transformation | ✅ Valid |
|
|
77
|
+
| `true` | `'camelCase'` | - | - | ❌ Build Error |
|
|
78
|
+
|
|
79
|
+
**When to use each option:**
|
|
80
|
+
- Use `'camelCaseOnly'` if you prefer standard JavaScript naming conventions
|
|
81
|
+
- Use `'dashesOnly'` if you want to preserve your CSS class names exactly as written
|
|
82
|
+
- Use `'camelCase'` (with `namedExport: false`) only if you need both versions available
|
|
83
|
+
|
|
35
84
|
## Version 8.x and Earlier Behavior
|
|
36
85
|
|
|
37
86
|
In Shakapacker v8 and earlier, the default behavior was to use a **default export object**:
|
|
@@ -244,7 +293,9 @@ import { bright, container, button } from './Component.module.css';
|
|
|
244
293
|
|
|
245
294
|
#### 3. Handle Kebab-Case Class Names
|
|
246
295
|
|
|
247
|
-
|
|
296
|
+
**Option A: Use camelCase (v9 default)**
|
|
297
|
+
|
|
298
|
+
With `exportLocalsConvention: 'camelCaseOnly'`, kebab-case class names are automatically converted:
|
|
248
299
|
|
|
249
300
|
```css
|
|
250
301
|
/* styles.module.css */
|
|
@@ -253,13 +304,35 @@ With v9's `exportLocalsConvention: 'camelCase'`, kebab-case class names are auto
|
|
|
253
304
|
```
|
|
254
305
|
|
|
255
306
|
```js
|
|
256
|
-
// v9
|
|
307
|
+
// v9 default - camelCase conversion
|
|
257
308
|
import { myButton, primaryColor } from './styles.module.css';
|
|
309
|
+
<button className={myButton} />
|
|
310
|
+
```
|
|
258
311
|
|
|
259
|
-
|
|
312
|
+
**Option B: Keep kebab-case with 'dashesOnly'**
|
|
313
|
+
|
|
314
|
+
If you prefer to preserve the original kebab-case names, configure your webpack to use `'dashesOnly'`:
|
|
315
|
+
|
|
316
|
+
```js
|
|
317
|
+
// config/webpack/commonWebpackConfig.js
|
|
318
|
+
modules: {
|
|
319
|
+
namedExport: true,
|
|
320
|
+
exportLocalsConvention: 'dashesOnly'
|
|
321
|
+
}
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
```js
|
|
325
|
+
// With dashesOnly - preserve kebab-case
|
|
326
|
+
import * as styles from './styles.module.css';
|
|
327
|
+
<button className={styles['my-button']} />
|
|
328
|
+
|
|
329
|
+
// Or with aliasing:
|
|
330
|
+
import { 'my-button': myButton } from './styles.module.css';
|
|
260
331
|
<button className={myButton} />
|
|
261
332
|
```
|
|
262
333
|
|
|
334
|
+
**Note:** With both `'camelCaseOnly'` and `'dashesOnly'`, only one version of each class name is exported. The original kebab-case name is NOT available with `'camelCaseOnly'`, and the camelCase version is NOT available with `'dashesOnly'`.
|
|
335
|
+
|
|
263
336
|
#### 4. Using a Codemod for Large Codebases
|
|
264
337
|
|
|
265
338
|
For large codebases, you can create a codemod to automate the migration:
|
|
@@ -298,12 +371,12 @@ npx jscodeshift -t css-modules-v9-migration.js src/
|
|
|
298
371
|
|
|
299
372
|
## Version Comparison
|
|
300
373
|
|
|
301
|
-
| Feature | v8 (and earlier) | v9 |
|
|
302
|
-
|---------|-----------------|----|
|
|
374
|
+
| Feature | v8 (and earlier) | v9 |
|
|
375
|
+
|---------|-----------------|----|
|
|
303
376
|
| Default behavior | Default export object | Named exports |
|
|
304
377
|
| Import syntax | `import styles from '...'` | `import { className } from '...'` |
|
|
305
378
|
| Class reference | `styles.className` | `className` |
|
|
306
|
-
| Export convention | `asIs` (no transformation) | `
|
|
379
|
+
| Export convention | `asIs` (no transformation) | `camelCaseOnly` |
|
|
307
380
|
| TypeScript warnings | May show warnings | No warnings |
|
|
308
381
|
| Tree-shaking | Limited | Optimized |
|
|
309
382
|
|
|
@@ -368,13 +441,34 @@ Then search for `css-loader` options in the generated JSON file.
|
|
|
368
441
|
|
|
369
442
|
## Troubleshooting
|
|
370
443
|
|
|
444
|
+
### Build Error: exportLocalsConvention Incompatible with namedExport
|
|
445
|
+
|
|
446
|
+
If you see this error during build:
|
|
447
|
+
```
|
|
448
|
+
"exportLocalsConvention" with "camelCase" value is incompatible with "namedExport: true" option
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
**Cause:** Your webpack configuration has `namedExport: true` with `exportLocalsConvention: 'camelCase'`.
|
|
452
|
+
|
|
453
|
+
**Solution:** Change `exportLocalsConvention` to `'camelCaseOnly'` or `'dashesOnly'`:
|
|
454
|
+
|
|
455
|
+
```js
|
|
456
|
+
// config/webpack/commonWebpackConfig.js or similar
|
|
457
|
+
modules: {
|
|
458
|
+
namedExport: true,
|
|
459
|
+
exportLocalsConvention: 'camelCaseOnly' // or 'dashesOnly'
|
|
460
|
+
}
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
Alternatively, if you need the `'camelCase'` option (both original and camelCase exports), you must revert to v8 behavior by setting `namedExport: false` as shown in the "Reverting to Default Exports" section above.
|
|
464
|
+
|
|
371
465
|
### CSS Classes Not Applying
|
|
372
466
|
|
|
373
467
|
If your CSS classes aren't applying after the upgrade:
|
|
374
468
|
|
|
375
469
|
1. **Check import syntax**: Ensure you're using the correct import style for your configuration
|
|
376
470
|
2. **Verify class names**: Use `console.log` to see available classes
|
|
377
|
-
3. **Check camelCase conversion**: Kebab-case names are converted to camelCase in v9
|
|
471
|
+
3. **Check camelCase conversion**: Kebab-case names are converted to camelCase in v9 with `'camelCaseOnly'`
|
|
378
472
|
4. **Rebuild webpack**: Clear cache and rebuild: `rm -rf tmp/cache && bin/shakapacker`
|
|
379
473
|
|
|
380
474
|
### TypeScript Support
|
|
@@ -415,4 +509,4 @@ The configuration changes should not impact build performance significantly. If
|
|
|
415
509
|
- **v8 default**: Default export object with no conversion
|
|
416
510
|
- **Migration path**: Update imports or override configuration
|
|
417
511
|
- **Benefits of v9**: No warnings, better tree-shaking, explicit dependencies
|
|
418
|
-
- **Keeping v8 behavior**: Override css-loader configuration as shown above
|
|
512
|
+
- **Keeping v8 behavior**: Override css-loader configuration as shown above
|
data/docs/v9_upgrade.md
CHANGED
|
@@ -19,7 +19,18 @@ See the [TypeScript Documentation](./typescript.md) for usage examples.
|
|
|
19
19
|
|
|
20
20
|
### 1. CSS Modules Configuration Changed to Named Exports
|
|
21
21
|
|
|
22
|
-
**What changed:** CSS Modules are now configured with `namedExport: true` and `exportLocalsConvention: '
|
|
22
|
+
**What changed:** CSS Modules are now configured with `namedExport: true` and `exportLocalsConvention: 'camelCaseOnly'` by default, aligning with Next.js and modern tooling standards.
|
|
23
|
+
|
|
24
|
+
> **Important:** When `namedExport: true` is enabled, css-loader requires `exportLocalsConvention` to be either `'camelCaseOnly'` or `'dashesOnly'`. Using `'camelCase'` will cause a build error: `"exportLocalsConvention" with "camelCase" value is incompatible with "namedExport: true" option`.
|
|
25
|
+
|
|
26
|
+
**Quick Reference: Configuration Options**
|
|
27
|
+
|
|
28
|
+
| Configuration | namedExport | exportLocalsConvention | CSS: `.my-button` | Export Available | Works With |
|
|
29
|
+
|---------------|-------------|------------------------|-------------------|------------------|------------|
|
|
30
|
+
| **v9 Default** | `true` | `'camelCaseOnly'` | `.my-button` | `myButton` only | ✅ Named exports |
|
|
31
|
+
| **Alternative** | `true` | `'dashesOnly'` | `.my-button` | `'my-button'` only | ✅ Named exports |
|
|
32
|
+
| **v8 Style** | `false` | `'camelCase'` | `.my-button` | Both `myButton` AND `'my-button'` | ✅ Default export |
|
|
33
|
+
| **❌ Invalid** | `true` | `'camelCase'` | - | - | ❌ Build Error |
|
|
23
34
|
|
|
24
35
|
**JavaScript Projects:**
|
|
25
36
|
```js
|
|
@@ -198,7 +209,7 @@ declare module '*.module.css' {
|
|
|
198
209
|
|
|
199
210
|
### Step 3: Handle Kebab-Case Class Names
|
|
200
211
|
|
|
201
|
-
v9 automatically converts kebab-case to camelCase:
|
|
212
|
+
v9 automatically converts kebab-case to camelCase with `exportLocalsConvention: 'camelCaseOnly'`:
|
|
202
213
|
|
|
203
214
|
```css
|
|
204
215
|
/* styles.module.css */
|
|
@@ -207,10 +218,34 @@ v9 automatically converts kebab-case to camelCase:
|
|
|
207
218
|
```
|
|
208
219
|
|
|
209
220
|
```js
|
|
210
|
-
// v9
|
|
221
|
+
// v9 default - camelCase conversion
|
|
211
222
|
import { myButton, primaryColor } from './styles.module.css';
|
|
212
223
|
```
|
|
213
224
|
|
|
225
|
+
**Alternative: Keep kebab-case names with 'dashesOnly'**
|
|
226
|
+
|
|
227
|
+
If you prefer to keep kebab-case names in JavaScript, you can override the configuration to use `'dashesOnly'`:
|
|
228
|
+
|
|
229
|
+
```js
|
|
230
|
+
// config/webpack/commonWebpackConfig.js
|
|
231
|
+
modules: {
|
|
232
|
+
namedExport: true,
|
|
233
|
+
exportLocalsConvention: 'dashesOnly' // Keep original kebab-case names
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
Then use the original kebab-case names in your imports:
|
|
238
|
+
|
|
239
|
+
```js
|
|
240
|
+
// With dashesOnly configuration
|
|
241
|
+
import { 'my-button': myButton, 'primary-color': primaryColor } from './styles.module.css';
|
|
242
|
+
// or access as properties
|
|
243
|
+
import * as styles from './styles.module.css';
|
|
244
|
+
const buttonClass = styles['my-button'];
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
**Note:** With `'camelCaseOnly'` (default) or `'dashesOnly'`, only one version is exported. If you need both the original and camelCase versions, you would need to use `'camelCase'` instead, but this requires `namedExport: false` (v8 behavior). See the [CSS Modules Export Mode documentation](./css-modules-export-mode.md) for details on reverting to v8 behavior.
|
|
248
|
+
|
|
214
249
|
### Step 4: Update Configuration Files
|
|
215
250
|
|
|
216
251
|
If you have `webpack_loader` in your configuration:
|
|
@@ -253,6 +288,25 @@ Update your global type definitions as shown in Step 2.
|
|
|
253
288
|
|
|
254
289
|
If you see warnings about CSS module exports, ensure you've updated all imports to use named exports or have properly configured the override.
|
|
255
290
|
|
|
291
|
+
### Build Error: exportLocalsConvention Incompatible with namedExport
|
|
292
|
+
|
|
293
|
+
If you see this error:
|
|
294
|
+
```
|
|
295
|
+
"exportLocalsConvention" with "camelCase" value is incompatible with "namedExport: true" option
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
This means your webpack configuration has `namedExport: true` with `exportLocalsConvention: 'camelCase'`. The fix is to change to `'camelCaseOnly'` or `'dashesOnly'`:
|
|
299
|
+
|
|
300
|
+
```js
|
|
301
|
+
// config/webpack/commonWebpackConfig.js or wherever you configure css-loader
|
|
302
|
+
modules: {
|
|
303
|
+
namedExport: true,
|
|
304
|
+
exportLocalsConvention: 'camelCaseOnly' // or 'dashesOnly'
|
|
305
|
+
}
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
If you want to use `'camelCase'` (which exports both original and camelCase versions), you must set `namedExport: false` and revert to v8 behavior. See the [CSS Modules Export Mode documentation](./css-modules-export-mode.md) for details.
|
|
309
|
+
|
|
256
310
|
### Unexpected Peer Dependency Warnings After Upgrade
|
|
257
311
|
|
|
258
312
|
If you experience unexpected peer dependency warnings after upgrading to v9, you may need to clear your package manager's cache and reinstall dependencies. This ensures the new optional peer dependency configuration takes effect properly.
|
data/lib/shakapacker/doctor.rb
CHANGED
|
@@ -43,6 +43,7 @@ module Shakapacker
|
|
|
43
43
|
# Dependency checks
|
|
44
44
|
check_javascript_transpiler_dependencies if config_exists?
|
|
45
45
|
check_css_dependencies
|
|
46
|
+
check_css_modules_configuration
|
|
46
47
|
check_bundler_dependencies if config_exists?
|
|
47
48
|
check_file_type_dependencies if config_exists?
|
|
48
49
|
check_sri_dependencies if config_exists?
|
|
@@ -432,6 +433,28 @@ module Shakapacker
|
|
|
432
433
|
if transpiler == "esbuild" && package_installed?("babel-loader")
|
|
433
434
|
@warnings << "Both esbuild and Babel dependencies are installed. Consider removing Babel dependencies to reduce node_modules size"
|
|
434
435
|
end
|
|
436
|
+
|
|
437
|
+
# Check for SWC configuration conflicts
|
|
438
|
+
if transpiler == "swc"
|
|
439
|
+
check_swc_config_conflicts
|
|
440
|
+
end
|
|
441
|
+
end
|
|
442
|
+
|
|
443
|
+
def check_swc_config_conflicts
|
|
444
|
+
swcrc_path = root_path.join(".swcrc")
|
|
445
|
+
return unless swcrc_path.exist?
|
|
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"
|
|
457
|
+
end
|
|
435
458
|
end
|
|
436
459
|
|
|
437
460
|
def check_css_dependencies
|
|
@@ -440,6 +463,77 @@ module Shakapacker
|
|
|
440
463
|
check_optional_dependency("mini-css-extract-plugin", @warnings, "CSS extraction")
|
|
441
464
|
end
|
|
442
465
|
|
|
466
|
+
def check_css_modules_configuration
|
|
467
|
+
# Check for CSS module files in the project
|
|
468
|
+
return unless config_exists?
|
|
469
|
+
|
|
470
|
+
source_path = config.source_path
|
|
471
|
+
return unless source_path.exist?
|
|
472
|
+
|
|
473
|
+
# Performance optimization: Just check if ANY CSS module file exists
|
|
474
|
+
# Using .first with early return is much faster than globbing all files
|
|
475
|
+
css_module_exists = Dir.glob(File.join(source_path, "**/*.module.{css,scss,sass}")).first
|
|
476
|
+
return unless css_module_exists
|
|
477
|
+
|
|
478
|
+
# Check webpack configuration for CSS modules settings
|
|
479
|
+
webpack_config_paths = [
|
|
480
|
+
root_path.join("config/webpack/webpack.config.js"),
|
|
481
|
+
root_path.join("config/webpack/webpack.config.ts"),
|
|
482
|
+
root_path.join("config/webpack/commonWebpackConfig.js"),
|
|
483
|
+
root_path.join("config/webpack/commonWebpackConfig.ts")
|
|
484
|
+
]
|
|
485
|
+
|
|
486
|
+
webpack_config_paths.each do |config_path|
|
|
487
|
+
next unless config_path.exist?
|
|
488
|
+
|
|
489
|
+
config_content = File.read(config_path)
|
|
490
|
+
|
|
491
|
+
# Check for the invalid configuration: namedExport: true with exportLocalsConvention: 'camelCase'
|
|
492
|
+
if config_content.match(/namedExport\s*:\s*true/) && config_content.match(/exportLocalsConvention\s*:\s*['"]camelCase['"]/)
|
|
493
|
+
@issues << "CSS Modules: Invalid configuration detected in #{config_path.relative_path_from(root_path)}"
|
|
494
|
+
@issues << " Using exportLocalsConvention: 'camelCase' with namedExport: true will cause build errors"
|
|
495
|
+
@issues << " Change to 'camelCaseOnly' or 'dashesOnly'. See docs/v9_upgrade.md for details"
|
|
496
|
+
end
|
|
497
|
+
|
|
498
|
+
# Warn if CSS modules are used but no configuration is found
|
|
499
|
+
if !config_content.match(/namedExport/) && !config_content.match(/exportLocalsConvention/)
|
|
500
|
+
@info << "CSS module files found but no explicit CSS modules configuration detected"
|
|
501
|
+
@info << " v9 defaults: namedExport: true, exportLocalsConvention: 'camelCaseOnly'"
|
|
502
|
+
end
|
|
503
|
+
end
|
|
504
|
+
|
|
505
|
+
# Check for common v8 to v9 migration issues
|
|
506
|
+
check_css_modules_import_patterns
|
|
507
|
+
rescue => e
|
|
508
|
+
# Don't fail doctor if CSS modules check has issues
|
|
509
|
+
@warnings << "Unable to validate CSS modules configuration: #{e.message}"
|
|
510
|
+
end
|
|
511
|
+
|
|
512
|
+
def check_css_modules_import_patterns
|
|
513
|
+
# Look for JavaScript/TypeScript files that might have v8-style imports
|
|
514
|
+
source_path = config.source_path
|
|
515
|
+
|
|
516
|
+
# Use lazy evaluation with Enumerator to avoid loading all file paths into memory
|
|
517
|
+
# Stop after checking 50 files or finding a match
|
|
518
|
+
v8_pattern = /import\s+\w+\s+from\s+['"][^'"]*\.module\.(css|scss|sass)['"]/
|
|
519
|
+
|
|
520
|
+
Dir.glob(File.join(source_path, "**/*.{js,jsx,ts,tsx}")).lazy.take(50).each do |file|
|
|
521
|
+
# Read file and check for v8 pattern
|
|
522
|
+
content = File.read(file)
|
|
523
|
+
|
|
524
|
+
# Check for v8 default import pattern with .module.css
|
|
525
|
+
if v8_pattern.match?(content)
|
|
526
|
+
@warnings << "Potential v8-style CSS module imports detected (using default import)"
|
|
527
|
+
@warnings << " v9 uses named exports. Update to: import { className } from './styles.module.css'"
|
|
528
|
+
@warnings << " Or use: import * as styles from './styles.module.css' (TypeScript)"
|
|
529
|
+
@warnings << " See docs/v9_upgrade.md for migration guide"
|
|
530
|
+
break # Stop after finding first occurrence
|
|
531
|
+
end
|
|
532
|
+
end
|
|
533
|
+
rescue => e
|
|
534
|
+
# Don't fail doctor if import pattern check has issues
|
|
535
|
+
end
|
|
536
|
+
|
|
443
537
|
def check_bundler_dependencies
|
|
444
538
|
bundler = config.assets_bundler
|
|
445
539
|
case bundler
|
|
@@ -30,6 +30,15 @@ module Shakapacker
|
|
|
30
30
|
"swc-loader" => "^0.2.6"
|
|
31
31
|
}.freeze
|
|
32
32
|
|
|
33
|
+
ESLINT_CONFIG_FILES = %w[
|
|
34
|
+
.eslintrc
|
|
35
|
+
.eslintrc.js
|
|
36
|
+
.eslintrc.cjs
|
|
37
|
+
.eslintrc.yaml
|
|
38
|
+
.eslintrc.yml
|
|
39
|
+
.eslintrc.json
|
|
40
|
+
].freeze
|
|
41
|
+
|
|
33
42
|
DEFAULT_SWCRC_CONFIG = {
|
|
34
43
|
"jsc" => {
|
|
35
44
|
"parser" => {
|
|
@@ -41,8 +50,7 @@ module Shakapacker
|
|
|
41
50
|
"react" => {
|
|
42
51
|
"runtime" => "automatic"
|
|
43
52
|
}
|
|
44
|
-
}
|
|
45
|
-
"target" => "es2015"
|
|
53
|
+
}
|
|
46
54
|
},
|
|
47
55
|
"module" => {
|
|
48
56
|
"type" => "es6"
|
|
@@ -67,6 +75,10 @@ module Shakapacker
|
|
|
67
75
|
logger.info "🎉 Migration to SWC complete!"
|
|
68
76
|
logger.info " Note: SWC is approximately 20x faster than Babel for transpilation."
|
|
69
77
|
logger.info " Please test your application thoroughly after migration."
|
|
78
|
+
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'"
|
|
70
82
|
|
|
71
83
|
# Show cleanup recommendations if babel packages found
|
|
72
84
|
if results[:babel_packages_found].any?
|
|
@@ -99,6 +111,16 @@ module Shakapacker
|
|
|
99
111
|
return { removed_packages: [], config_files_deleted: [] }
|
|
100
112
|
end
|
|
101
113
|
|
|
114
|
+
# Check if ESLint uses Babel parser
|
|
115
|
+
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
|
+
end
|
|
123
|
+
|
|
102
124
|
removed_packages = remove_babel_from_package_json(package_json_path)
|
|
103
125
|
deleted_files = delete_babel_config_files
|
|
104
126
|
|
|
@@ -132,6 +154,42 @@ module Shakapacker
|
|
|
132
154
|
|
|
133
155
|
private
|
|
134
156
|
|
|
157
|
+
def eslint_uses_babel?
|
|
158
|
+
# Check for ESLint config files
|
|
159
|
+
# Note: This is a heuristic check that may have false positives (e.g., in comments),
|
|
160
|
+
# but false positives only result in an extra warning, which is safer than silently
|
|
161
|
+
# breaking ESLint configurations.
|
|
162
|
+
ESLINT_CONFIG_FILES.each do |config_file|
|
|
163
|
+
config_path = root_path.join(config_file)
|
|
164
|
+
next unless config_path.exist?
|
|
165
|
+
|
|
166
|
+
content = File.read(config_path)
|
|
167
|
+
# Check for Babel parser references
|
|
168
|
+
return true if content.match?(/@babel\/eslint-parser|babel-eslint/)
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
# Check package.json for eslintConfig
|
|
172
|
+
package_json_path = root_path.join("package.json")
|
|
173
|
+
if package_json_path.exist?
|
|
174
|
+
begin
|
|
175
|
+
package_json = JSON.parse(File.read(package_json_path))
|
|
176
|
+
if package_json["eslintConfig"]
|
|
177
|
+
return true if package_json["eslintConfig"].to_json.match?(/@babel\/eslint-parser|babel-eslint/)
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
# Check if Babel ESLint packages are installed
|
|
181
|
+
dependencies = package_json["dependencies"] || {}
|
|
182
|
+
dev_dependencies = package_json["devDependencies"] || {}
|
|
183
|
+
all_deps = dependencies.merge(dev_dependencies)
|
|
184
|
+
return true if all_deps.key?("@babel/eslint-parser") || all_deps.key?("babel-eslint")
|
|
185
|
+
rescue JSON::ParserError => e
|
|
186
|
+
logger.debug "Could not parse package.json for ESLint detection: #{e.message}"
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
false
|
|
191
|
+
end
|
|
192
|
+
|
|
135
193
|
def update_shakapacker_config
|
|
136
194
|
config_path = root_path.join("config/shakapacker.yml")
|
|
137
195
|
return false unless config_path.exist?
|
data/lib/shakapacker/version.rb
CHANGED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { moduleExists, packageFullVersion } from "../utils/helpers"
|
|
2
|
+
import type { ConfigAPI, PluginItem } from "@babel/core"
|
|
3
|
+
|
|
4
|
+
const CORE_JS_VERSION_REGEX = /^\d+\.\d+/
|
|
5
|
+
|
|
6
|
+
const coreJsVersion = (): string => {
|
|
7
|
+
try {
|
|
8
|
+
const version = packageFullVersion("core-js").match(CORE_JS_VERSION_REGEX)
|
|
9
|
+
return version?.[0] ?? "3.8"
|
|
10
|
+
} catch (e) {
|
|
11
|
+
const error = e as NodeJS.ErrnoException
|
|
12
|
+
if (error.code !== "MODULE_NOT_FOUND") {
|
|
13
|
+
throw e
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return "3.8"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export = function config(api: ConfigAPI): { presets: PluginItem[]; plugins: PluginItem[] } {
|
|
21
|
+
const validEnv = ["development", "test", "production"]
|
|
22
|
+
const currentEnv = api.env()
|
|
23
|
+
const isDevelopmentEnv = api.env("development")
|
|
24
|
+
const isProductionEnv = api.env("production")
|
|
25
|
+
const isTestEnv = api.env("test")
|
|
26
|
+
|
|
27
|
+
if (!validEnv.includes(currentEnv)) {
|
|
28
|
+
throw new Error(
|
|
29
|
+
`Please specify a valid NODE_ENV or BABEL_ENV environment variable. Valid values are "development", "test", and "production". Instead, received: "${currentEnv}".`
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const presets: PluginItem[] = [
|
|
34
|
+
isTestEnv && ["@babel/preset-env", { targets: { node: "current" } }],
|
|
35
|
+
(isProductionEnv || isDevelopmentEnv) && [
|
|
36
|
+
"@babel/preset-env",
|
|
37
|
+
{
|
|
38
|
+
useBuiltIns: "entry",
|
|
39
|
+
corejs: coreJsVersion(),
|
|
40
|
+
modules: "auto",
|
|
41
|
+
bugfixes: true,
|
|
42
|
+
exclude: ["transform-typeof-symbol"]
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
moduleExists("@babel/preset-typescript") && "@babel/preset-typescript"
|
|
46
|
+
].filter(Boolean) as PluginItem[]
|
|
47
|
+
|
|
48
|
+
const plugins: PluginItem[] = [["@babel/plugin-transform-runtime", { helpers: false }]].filter(
|
|
49
|
+
Boolean
|
|
50
|
+
) as PluginItem[]
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
presets,
|
|
54
|
+
plugins
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/* eslint global-require: 0 */
|
|
2
|
+
/* eslint import/no-dynamic-require: 0 */
|
|
3
|
+
|
|
4
|
+
import { resolve } from "path"
|
|
5
|
+
import { existsSync } from "fs"
|
|
6
|
+
import { merge } from "webpack-merge"
|
|
7
|
+
import type { RuleSetRule } from "webpack"
|
|
8
|
+
|
|
9
|
+
const LOADER_EXT_REGEX = /\.([jt]sx?)(\.erb)?$/
|
|
10
|
+
|
|
11
|
+
const getLoaderExtension = (filename: string): string => {
|
|
12
|
+
const matchData = filename.match(LOADER_EXT_REGEX)
|
|
13
|
+
|
|
14
|
+
if (!matchData) {
|
|
15
|
+
return "js"
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return matchData[1] ?? "js"
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const getCustomConfig = (): Partial<RuleSetRule> => {
|
|
22
|
+
const path = resolve("config", "esbuild.config.js")
|
|
23
|
+
if (existsSync(path)) {
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
25
|
+
return require(path)
|
|
26
|
+
}
|
|
27
|
+
return {}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const getEsbuildLoaderConfig = (filenameToProcess: string): RuleSetRule => {
|
|
31
|
+
const customConfig = getCustomConfig()
|
|
32
|
+
const defaultConfig: RuleSetRule = {
|
|
33
|
+
loader: require.resolve("esbuild-loader"),
|
|
34
|
+
options: {
|
|
35
|
+
loader: getLoaderExtension(filenameToProcess)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return merge(defaultConfig, customConfig)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { getEsbuildLoaderConfig }
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const { requireOrError } = require("../utils/requireOrError")
|
|
2
|
+
const { error: logError } = require("../utils/debug")
|
|
3
|
+
|
|
4
|
+
const rspack = requireOrError("@rspack/core")
|
|
5
|
+
|
|
6
|
+
interface OptimizationConfig {
|
|
7
|
+
minimize: boolean
|
|
8
|
+
minimizer?: unknown[]
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const getOptimization = (): OptimizationConfig => {
|
|
12
|
+
// Use Rspack's built-in minification instead of terser-webpack-plugin
|
|
13
|
+
const result: OptimizationConfig = { minimize: true }
|
|
14
|
+
try {
|
|
15
|
+
result.minimizer = [
|
|
16
|
+
new rspack.SwcJsMinimizerRspackPlugin(),
|
|
17
|
+
new rspack.LightningCssMinimizerRspackPlugin()
|
|
18
|
+
]
|
|
19
|
+
} catch (error: unknown) {
|
|
20
|
+
const errorMessage = error instanceof Error ? error.message : String(error)
|
|
21
|
+
const errorStack = error instanceof Error ? error.stack : ''
|
|
22
|
+
// Log full error with stack trace
|
|
23
|
+
logError(
|
|
24
|
+
`Failed to configure Rspack minimizers: ${errorMessage}\n${errorStack}`
|
|
25
|
+
)
|
|
26
|
+
// Re-throw the error to properly propagate it
|
|
27
|
+
throw new Error(
|
|
28
|
+
`Could not configure Rspack minimizers: ${errorMessage}. Please check that @rspack/core is properly installed.`
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
return result
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export = {
|
|
35
|
+
getOptimization
|
|
36
|
+
}
|
|
@@ -3,7 +3,7 @@ const { requireOrError } = require("../utils/requireOrError")
|
|
|
3
3
|
const TerserPlugin = requireOrError("terser-webpack-plugin")
|
|
4
4
|
const { moduleExists } = require("../utils/helpers")
|
|
5
5
|
|
|
6
|
-
const tryCssMinimizer = () => {
|
|
6
|
+
const tryCssMinimizer = (): unknown | null => {
|
|
7
7
|
if (
|
|
8
8
|
moduleExists("css-loader") &&
|
|
9
9
|
moduleExists("css-minimizer-webpack-plugin")
|
|
@@ -15,12 +15,20 @@ const tryCssMinimizer = () => {
|
|
|
15
15
|
return null
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
interface OptimizationConfig {
|
|
19
|
+
minimizer: unknown[]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const getOptimization = (): OptimizationConfig => {
|
|
19
23
|
return {
|
|
20
24
|
minimizer: [
|
|
21
25
|
tryCssMinimizer(),
|
|
22
26
|
new TerserPlugin({
|
|
23
|
-
|
|
27
|
+
// SHAKAPACKER_PARALLEL env var: number of parallel workers, or true for auto (os.cpus().length - 1)
|
|
28
|
+
// If not set or invalid, defaults to true (automatic parallelization)
|
|
29
|
+
parallel: process.env.SHAKAPACKER_PARALLEL
|
|
30
|
+
? Number.parseInt(process.env.SHAKAPACKER_PARALLEL, 10) || true
|
|
31
|
+
: true,
|
|
24
32
|
terserOptions: {
|
|
25
33
|
parse: {
|
|
26
34
|
// Let terser parse ecma 8 code but always output
|
|
@@ -44,6 +52,6 @@ const getOptimization = () => {
|
|
|
44
52
|
}
|
|
45
53
|
}
|
|
46
54
|
|
|
47
|
-
|
|
55
|
+
export = {
|
|
48
56
|
getOptimization
|
|
49
57
|
}
|