shakapacker 9.2.0 → 9.3.0.beta.0

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.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +6 -9
  3. data/.github/ISSUE_TEMPLATE/feature_request.md +6 -8
  4. data/.github/workflows/claude-code-review.yml +4 -5
  5. data/.github/workflows/claude.yml +1 -2
  6. data/.github/workflows/dummy.yml +4 -4
  7. data/.github/workflows/generator.yml +9 -9
  8. data/.github/workflows/node.yml +11 -2
  9. data/.github/workflows/ruby.yml +16 -16
  10. data/.github/workflows/test-bundlers.yml +9 -9
  11. data/.gitignore +4 -0
  12. data/CHANGELOG.md +19 -4
  13. data/CLAUDE.md +6 -1
  14. data/CONTRIBUTING.md +0 -1
  15. data/Gemfile.lock +1 -1
  16. data/README.md +14 -14
  17. data/TODO.md +10 -2
  18. data/TODO_v9.md +13 -3
  19. data/bin/export-bundler-config +1 -1
  20. data/conductor-setup.sh +1 -1
  21. data/conductor.json +1 -1
  22. data/docs/cdn_setup.md +13 -8
  23. data/docs/common-upgrades.md +2 -1
  24. data/docs/configuration.md +630 -0
  25. data/docs/css-modules-export-mode.md +120 -100
  26. data/docs/customizing_babel_config.md +16 -16
  27. data/docs/deployment.md +18 -0
  28. data/docs/developing_shakapacker.md +6 -0
  29. data/docs/optional-peer-dependencies.md +9 -4
  30. data/docs/peer-dependencies.md +17 -6
  31. data/docs/precompile_hook.md +342 -0
  32. data/docs/react.md +57 -47
  33. data/docs/releasing.md +0 -2
  34. data/docs/rspack.md +25 -21
  35. data/docs/rspack_migration_guide.md +335 -8
  36. data/docs/sprockets.md +1 -0
  37. data/docs/style_loader_vs_mini_css.md +12 -12
  38. data/docs/subresource_integrity.md +13 -7
  39. data/docs/transpiler-performance.md +40 -19
  40. data/docs/troubleshooting.md +0 -2
  41. data/docs/typescript-migration.md +48 -39
  42. data/docs/typescript.md +12 -8
  43. data/docs/using_esbuild_loader.md +10 -10
  44. data/docs/v6_upgrade.md +33 -20
  45. data/docs/v7_upgrade.md +8 -6
  46. data/docs/v8_upgrade.md +13 -12
  47. data/docs/v9_upgrade.md +2 -1
  48. data/eslint.config.fast.js +134 -0
  49. data/eslint.config.js +140 -0
  50. data/knip.ts +54 -0
  51. data/lib/install/bin/export-bundler-config +1 -1
  52. data/lib/install/config/shakapacker.yml +16 -5
  53. data/lib/shakapacker/compiler.rb +80 -0
  54. data/lib/shakapacker/configuration.rb +33 -5
  55. data/lib/shakapacker/dev_server_runner.rb +140 -1
  56. data/lib/shakapacker/doctor.rb +294 -65
  57. data/lib/shakapacker/instance.rb +8 -3
  58. data/lib/shakapacker/runner.rb +244 -8
  59. data/lib/shakapacker/version.rb +1 -1
  60. data/lib/tasks/shakapacker/doctor.rake +42 -2
  61. data/package/babel/preset.ts +7 -4
  62. data/package/config.ts +42 -30
  63. data/package/configExporter/cli.ts +799 -208
  64. data/package/configExporter/configFile.ts +520 -0
  65. data/package/configExporter/fileWriter.ts +12 -8
  66. data/package/configExporter/index.ts +9 -1
  67. data/package/configExporter/types.ts +36 -2
  68. data/package/configExporter/yamlSerializer.ts +22 -8
  69. data/package/dev_server.ts +1 -1
  70. data/package/environments/__type-tests__/rspack-plugin-compatibility.ts +11 -5
  71. data/package/environments/base.ts +18 -13
  72. data/package/environments/development.ts +1 -1
  73. data/package/environments/production.ts +4 -1
  74. data/package/index.d.ts +50 -3
  75. data/package/index.d.ts.template +50 -0
  76. data/package/index.ts +7 -7
  77. data/package/loaders.d.ts +2 -2
  78. data/package/optimization/rspack.ts +1 -1
  79. data/package/plugins/rspack.ts +15 -4
  80. data/package/plugins/webpack.ts +7 -3
  81. data/package/rspack/index.ts +10 -2
  82. data/package/rules/raw.ts +3 -2
  83. data/package/rules/sass.ts +1 -1
  84. data/package/types/README.md +15 -13
  85. data/package/types/index.ts +5 -5
  86. data/package/types.ts +0 -1
  87. data/package/utils/defaultConfigPath.ts +4 -1
  88. data/package/utils/errorCodes.ts +129 -100
  89. data/package/utils/errorHelpers.ts +34 -29
  90. data/package/utils/getStyleRule.ts +5 -2
  91. data/package/utils/helpers.ts +21 -11
  92. data/package/utils/pathValidation.ts +43 -35
  93. data/package/utils/requireOrError.ts +1 -1
  94. data/package/utils/snakeToCamelCase.ts +1 -1
  95. data/package/utils/typeGuards.ts +132 -83
  96. data/package/utils/validateDependencies.ts +1 -1
  97. data/package/webpack-types.d.ts +3 -3
  98. data/package/webpackDevServerConfig.ts +22 -10
  99. data/package-lock.json +2 -2
  100. data/package.json +36 -28
  101. data/scripts/type-check-no-emit.js +1 -1
  102. data/test/configExporter/configFile.test.js +392 -0
  103. data/test/configExporter/integration.test.js +275 -0
  104. data/test/helpers.js +1 -1
  105. data/test/package/configExporter.test.js +154 -0
  106. data/test/package/helpers.test.js +2 -2
  107. data/test/package/rules/sass-version-parsing.test.js +71 -0
  108. data/test/package/rules/sass.test.js +2 -4
  109. data/test/package/rules/sass1.test.js +1 -3
  110. data/test/package/rules/sass16.test.js +23 -0
  111. data/tools/README.md +15 -5
  112. data/tsconfig.eslint.json +2 -9
  113. data/yarn.lock +1894 -1492
  114. metadata +19 -3
  115. data/.eslintignore +0 -5
data/TODO_v9.md CHANGED
@@ -3,17 +3,21 @@
3
3
  ## CSS Modules Configuration Alignment
4
4
 
5
5
  ### Problem
6
+
6
7
  Current CSS modules configuration causes TypeScript/webpack warnings because of default vs named export mismatch.
7
8
 
8
9
  ### Current Behavior (v8)
10
+
9
11
  - CSS modules use default export: `import styles from './styles.module.css'`
10
12
  - This causes warnings but works at runtime
11
13
  - Warning example: `export 'default' (imported as 'style') was not found in './HelloWorld.module.css'`
12
14
 
13
15
  ### Proposed v9 Change
16
+
14
17
  Align with Next.js and modern tooling by using named exports:
15
18
 
16
19
  1. **Update css-loader configuration:**
20
+
17
21
  ```javascript
18
22
  {
19
23
  loader: 'css-loader',
@@ -30,30 +34,34 @@ Align with Next.js and modern tooling by using named exports:
30
34
  css-loader only allows `'camelCaseOnly'` or `'dashesOnly'` when named exports are enabled.
31
35
 
32
36
  2. **Update TypeScript types:**
37
+
33
38
  - Ensure proper typing for CSS modules with named exports
34
39
  - May need to update or generate `.d.ts` files for CSS modules
35
40
 
36
41
  3. **Migration guide for users:**
42
+
37
43
  - Document the breaking change
38
44
  - Provide codemod or migration script to update imports from:
39
45
  ```javascript
40
- import styles from './styles.module.css'
46
+ import styles from "./styles.module.css"
41
47
  styles.className
42
48
  ```
43
49
  to:
44
50
  ```javascript
45
- import * as styles from './styles.module.css'
51
+ import * as styles from "./styles.module.css"
46
52
  // or
47
- import { className } from './styles.module.css'
53
+ import { className } from "./styles.module.css"
48
54
  ```
49
55
 
50
56
  ### Benefits
57
+
51
58
  - Eliminates webpack/TypeScript warnings
52
59
  - Better tree-shaking potential
53
60
  - More explicit about what CSS classes are being used
54
61
  - Easier interoperability with frameworks that support named exports
55
62
 
56
63
  ### Implementation Notes
64
+
57
65
  - This is a BREAKING CHANGE and appropriate for major version bump
58
66
  - Need to test with both webpack and rspack
59
67
  - Consider providing a compatibility mode via configuration option
@@ -63,6 +71,7 @@ css-loader only allows `'camelCaseOnly'` or `'dashesOnly'` when named exports ar
63
71
  ## Related Issues from PR #597
64
72
 
65
73
  ### React Component Not Rendering (spec/dummy) - RESOLVED ✅
74
+
66
75
  - **Issue**: React component was not rendering due to CSS module import mismatch
67
76
  - **Symptoms**:
68
77
  - Component wasn't rendering "Hello, Stranger!"
@@ -82,6 +91,7 @@ css-loader only allows `'camelCaseOnly'` or `'dashesOnly'` when named exports ar
82
91
  - Interactive functionality restored
83
92
 
84
93
  ### Test Infrastructure
94
+
85
95
  - Successfully implemented dual bundler support (webpack/rspack)
86
96
  - test-bundler script working well with status command
87
97
  - Consider adding more comprehensive tests for both bundlers
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // Minimal shim - all logic is in the TypeScript module
4
- const { run } = require('shakapacker/configExporter')
4
+ const { run } = require("shakapacker/configExporter")
5
5
 
6
6
  run(process.argv.slice(2))
7
7
  .then((exitCode) => process.exit(exitCode))
data/conductor-setup.sh CHANGED
@@ -33,7 +33,7 @@ $BUNDLE_CMD install
33
33
 
34
34
  # Install JavaScript dependencies
35
35
  echo "📦 Installing JavaScript dependencies..."
36
- yarn install
36
+ yarn install --frozen-lockfile
37
37
 
38
38
  # Set up Husky git hooks
39
39
  echo "🪝 Setting up Husky git hooks..."
data/conductor.json CHANGED
@@ -4,4 +4,4 @@
4
4
  "run": "bundle exec rspec",
5
5
  "archive": ""
6
6
  }
7
- }
7
+ }
data/docs/cdn_setup.md CHANGED
@@ -64,7 +64,7 @@ Add the `asset_host` setting to your `config/shakapacker.yml`:
64
64
  production:
65
65
  # ... other settings ...
66
66
  asset_host: https://cdn.example.com
67
-
67
+
68
68
  # You can also set different CDN hosts per environment
69
69
  staging:
70
70
  asset_host: https://staging-cdn.example.com
@@ -77,8 +77,8 @@ Configure in your Rails environment file (e.g., `config/environments/production.
77
77
  ```ruby
78
78
  Rails.application.configure do
79
79
  # ... other settings ...
80
-
81
- # This will be used by Shakapacker if SHAKAPACKER_ASSET_HOST
80
+
81
+ # This will be used by Shakapacker if SHAKAPACKER_ASSET_HOST
82
82
  # and asset_host in shakapacker.yml are not set
83
83
  config.action_controller.asset_host = 'https://cdn.example.com'
84
84
  end
@@ -95,6 +95,7 @@ RAILS_ENV=production bundle exec rails assets:precompile
95
95
  ```
96
96
 
97
97
  This ensures that:
98
+
98
99
  - Webpack's `publicPath` is set to your CDN URL
99
100
  - Dynamic imports and code-split chunks load from the CDN
100
101
  - Asset manifest references use CDN URLs
@@ -189,9 +190,9 @@ If using code splitting, verify dynamic chunks load from CDN:
189
190
 
190
191
  ```javascript
191
192
  // This dynamic import should load from CDN
192
- import('./components/HeavyComponent').then(module => {
193
+ import("./components/HeavyComponent").then((module) => {
193
194
  // Check Network tab - chunk should load from CDN
194
- });
195
+ })
195
196
  ```
196
197
 
197
198
  ## Troubleshooting
@@ -201,6 +202,7 @@ import('./components/HeavyComponent').then(module => {
201
202
  **Problem**: Assets are still loading from your application domain.
202
203
 
203
204
  **Solutions**:
205
+
204
206
  1. Ensure you set `SHAKAPACKER_ASSET_HOST` **before** running `assets:precompile`
205
207
  2. Clear Rails cache: `rails tmp:cache:clear`
206
208
  3. Check the manifest.json file includes CDN URLs:
@@ -213,6 +215,7 @@ import('./components/HeavyComponent').then(module => {
213
215
  **Problem**: Browser shows CORS errors when loading assets from CDN.
214
216
 
215
217
  **Solutions**:
218
+
216
219
  1. Configure your CDN to add CORS headers:
217
220
  ```
218
221
  Access-Control-Allow-Origin: *
@@ -227,6 +230,7 @@ import('./components/HeavyComponent').then(module => {
227
230
  **Problem**: Web fonts fail to load from CDN due to CORS.
228
231
 
229
232
  **Solutions**:
233
+
230
234
  1. Ensure CDN sends proper CORS headers for font files
231
235
  2. In CloudFlare, create a page rule for `*.woff2`, `*.woff`, `*.ttf` files with CORS headers
232
236
  3. Consider hosting fonts separately or using base64 encoding
@@ -277,6 +281,7 @@ production:
277
281
  ```
278
282
 
279
283
  Ensure your CDN serves files with CORS headers:
284
+
280
285
  ```
281
286
  Access-Control-Allow-Origin: *
282
287
  ```
@@ -339,7 +344,7 @@ production:
339
344
  compile: false
340
345
  cache_manifest: true
341
346
  asset_host: <%= ENV.fetch('SHAKAPACKER_ASSET_HOST', 'https://cdn.example.com') %>
342
-
347
+
343
348
  # Enable integrity checking
344
349
  integrity:
345
350
  enabled: true
@@ -352,7 +357,7 @@ production:
352
357
  Rails.application.configure do
353
358
  # Fallback if SHAKAPACKER_ASSET_HOST is not set
354
359
  config.action_controller.asset_host = 'https://cdn.example.com'
355
-
360
+
356
361
  # Ensure proper headers for CDN
357
362
  config.public_file_server.headers = {
358
363
  'Cache-Control' => 'public, max-age=31536000',
@@ -376,4 +381,4 @@ Setting up a CDN with Shakapacker involves:
376
381
  3. Compiling assets with the CDN URL
377
382
  4. Deploying and verifying the setup
378
383
 
379
- The key is ensuring `SHAKAPACKER_ASSET_HOST` is set during asset compilation so webpack's `publicPath` is configured correctly for dynamic imports and code-split chunks.
384
+ The key is ensuring `SHAKAPACKER_ASSET_HOST` is set during asset compilation so webpack's `publicPath` is configured correctly for dynamic imports and code-split chunks.
@@ -2,6 +2,8 @@
2
2
 
3
3
  This document provides step-by-step instructions for the most common upgrade scenarios in Shakapacker projects.
4
4
 
5
+ **📖 For configuration options, see the [Configuration Guide](./configuration.md)**
6
+
5
7
  ## Table of Contents
6
8
 
7
9
  - [Migrating Package Managers](#migrating-package-managers)
@@ -580,7 +582,6 @@ For maximum performance improvements, you can combine multiple migrations:
580
582
  This combination provides the best performance improvement (up to 50-70x faster builds):
581
583
 
582
584
  1. **First, migrate to SWC** (while still on webpack)
583
-
584
585
  - Follow [Migrating from Babel to SWC](#migrating-from-babel-to-swc)
585
586
  - Test thoroughly
586
587
  - This is a smaller change to validate first