shakapacker 9.3.0.beta.7 → 9.3.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 (55) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +46 -109
  3. data/Gemfile.lock +1 -1
  4. data/README.md +53 -2
  5. data/docs/configuration.md +28 -0
  6. data/docs/rspack_migration_guide.md +238 -2
  7. data/docs/troubleshooting.md +21 -21
  8. data/eslint.config.fast.js +8 -0
  9. data/eslint.config.js +47 -10
  10. data/knip.ts +8 -1
  11. data/lib/install/config/shakapacker.yml +6 -6
  12. data/lib/shakapacker/configuration.rb +227 -4
  13. data/lib/shakapacker/dev_server.rb +88 -1
  14. data/lib/shakapacker/doctor.rb +4 -4
  15. data/lib/shakapacker/instance.rb +85 -1
  16. data/lib/shakapacker/manifest.rb +85 -11
  17. data/lib/shakapacker/version.rb +1 -1
  18. data/lib/shakapacker.rb +143 -3
  19. data/lib/tasks/shakapacker/doctor.rake +1 -1
  20. data/lib/tasks/shakapacker/export_bundler_config.rake +4 -4
  21. data/package/config.ts +0 -1
  22. data/package/configExporter/buildValidator.ts +53 -29
  23. data/package/configExporter/cli.ts +81 -56
  24. data/package/configExporter/configFile.ts +33 -26
  25. data/package/configExporter/types.ts +64 -0
  26. data/package/configExporter/yamlSerializer.ts +118 -43
  27. data/package/dev_server.ts +2 -1
  28. data/package/env.ts +1 -1
  29. data/package/environments/base.ts +4 -4
  30. data/package/environments/development.ts +7 -6
  31. data/package/environments/production.ts +6 -7
  32. data/package/environments/test.ts +2 -1
  33. data/package/index.ts +28 -4
  34. data/package/loaders.d.ts +2 -2
  35. data/package/optimization/webpack.ts +29 -31
  36. data/package/rspack/index.ts +2 -1
  37. data/package/rules/file.ts +1 -0
  38. data/package/rules/jscommon.ts +1 -0
  39. data/package/utils/helpers.ts +0 -1
  40. data/package/utils/pathValidation.ts +68 -7
  41. data/package/utils/requireOrError.ts +10 -2
  42. data/package/utils/typeGuards.ts +43 -46
  43. data/package/webpack-types.d.ts +2 -2
  44. data/package/webpackDevServerConfig.ts +1 -0
  45. data/package.json +2 -3
  46. data/test/package/configExporter/cli.test.js +440 -0
  47. data/test/package/configExporter/types.test.js +163 -0
  48. data/test/package/configExporter.test.js +264 -0
  49. data/test/package/yamlSerializer.test.js +204 -0
  50. data/test/typescript/pathValidation.test.js +44 -0
  51. data/test/typescript/requireOrError.test.js +49 -0
  52. data/yarn.lock +0 -32
  53. metadata +11 -5
  54. data/.eslintrc.fast.js +0 -40
  55. data/.eslintrc.js +0 -84
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d74b7ba9b6d6c78f1909339be00ce6d88a6d3f8e8cd64ada499992c3bf6691f
4
- data.tar.gz: f51ffe665f554536b8defcf139399eb6f6630c61f427a4be9c88aebf14404b25
3
+ metadata.gz: 1e94cd0b57c81506b9cab0fb54cc6a876276c3f3331686cf921fa4485442ab99
4
+ data.tar.gz: 292b0623b5241014524f9227ed2a1009752de53e8db610344567f761c7b8b4bc
5
5
  SHA512:
6
- metadata.gz: 7fa1c2252b25cc3e265e6375561e0be38d1656604e6bf873eb1d6b25d41478bc48c530e8bcac3a05f6d09f7569f988a65cb52609564c87ea35f657bda3baed27
7
- data.tar.gz: a322b6a94de55f7f8da67d54778e6f455726d4778576e5ff689e2874d68f58b8613260d683d93e019d48d44eeeb9a46a7094be12cb7dbaea76824e688350994a
6
+ metadata.gz: 6dd27e8501b86f06fbefd6f71a2a3ceb9c975dd28f140251ab03cf6bd972b631db35666e9c05bdf434bf2ac13c1568f57bd73a7841efb38befb541f2d0cfaeb1
7
+ data.tar.gz: 623358b9543ddcad7586a68e03aba4848151d4490a298c39320a395cb4aa450783a91f4c21d53b491868600d57e054f3f52bcb72eb244f25ebc0e8cb20ff1738
data/CHANGELOG.md CHANGED
@@ -11,132 +11,69 @@
11
11
 
12
12
  Changes since the last non-beta release.
13
13
 
14
- ### Added
14
+ ### Fixed
15
15
 
16
- - **`--help=verbose` flag support** to display all available webpack/rspack bundler options. [PR #763](https://github.com/shakacode/shakapacker/pull/763) by [justin808](https://github.com/justin808).
17
- - Run `bin/shakapacker --help=verbose` to see complete bundler documentation
18
- - Shows all webpack CLI options when using webpack
19
- - Useful for discovering advanced bundler configuration options
20
- - **Support for arbitrary output names in build configurations**. [PR #752](https://github.com/shakacode/shakapacker/pull/752) by [justin808](https://github.com/justin808).
21
- - `outputs` array now accepts any custom names (e.g., `client-modern`, `client-legacy`, `server-bundle`)
22
- - Previously limited to only `client`, `server`, and `all`
23
- - Enables better organization of multi-config webpack builds
24
- - **Enhanced error reporting in config exporter**. [PR #752](https://github.com/shakacode/shakapacker/pull/752) by [justin808](https://github.com/justin808).
25
- - Shows detailed environment variable state when config functions fail
26
- - Provides actionable suggestions based on error patterns (e.g., missing NODE_ENV)
27
- - Improved formatting with clear sections for easier debugging
28
- - **Config count validation for build outputs**. [PR #752](https://github.com/shakacode/shakapacker/pull/752) by [justin808](https://github.com/justin808).
29
- - Validates webpack/rspack config array length matches `outputs` array
30
- - Clear error messages when mismatch detected
31
- - Suggests fixes with example configuration
32
- - **HTTP 103 Early Hints support** for faster asset loading. [PR #722](https://github.com/shakacode/shakapacker/pull/722) by [justin808](https://github.com/justin808). Fixes [#721](https://github.com/shakacode/shakapacker/issues/721).
33
- - **Automatic sending**: Early hints are sent automatically when `early_hints: enabled: true` in `shakapacker.yml`
34
- - **Per-page configuration**: Configure hints per-controller/action with `preload`/`prefetch`/`none` options
35
- - **Hero image/video preloading**: Use Rails' built-in `preload_link_tag` (automatically sends early hints)
36
- - **Zero-config upgrade**: No changes to layouts or views needed - just enable the config!
37
- - Works seamlessly with existing `append_javascript_pack_tag` / `append_stylesheet_pack_tag` pattern
38
- - Automatically discovers packs from queues populated by views/partials
39
- - New `configure_pack_early_hints` class method for controller-level configuration
40
- - New `skip_send_pack_early_hints` helper to opt-out for specific controllers (e.g., JSON APIs)
41
- - Optional manual control: `configure_early_hints` can be called in controllers or views
42
- - Added `early_hints:` option to `javascript_pack_tag` for per-tag control
43
- - New `early_hints` configuration in `shakapacker.yml` with per-environment settings (`enabled: false` by default)
44
- - Requires Rails 5.2+ and HTTP/2-capable server (e.g., Puma 5+)
45
- - Browser support: All modern browsers (Chrome/Edge/Firefox 103+, Safari 16.4+)
46
- - Gracefully degrades if not supported
47
- - **Performance note**: May improve or hurt page load performance depending on content - careful testing advised
48
- - See [Early Hints Guide](docs/early_hints.md) for detailed usage and advanced patterns
49
-
50
- ## [v9.3.0-beta.5] - October 18, 2025
16
+ - **Enhanced error handling for better security and debugging**. [PR #786](https://github.com/shakacode/shakapacker/pull/786) by [justin808](https://github.com/justin808).
17
+ - Path validation now properly reports permission errors instead of silently handling them
18
+ - Module loading errors now include original error context for easier troubleshooting
19
+ - Improved security by only catching ENOENT errors in path resolution, rethrowing permission and access errors
20
+ - Better type safety with custom ErrorWithCause interface and optional chaining for error.code checks
21
+ - **Improved type safety and error handling in configExporter module**. [PR #778](https://github.com/shakacode/shakapacker/pull/778) by [justin808](https://github.com/justin808). Resolves [#707](https://github.com/shakacode/shakapacker/issues/707).
22
+ - Enhanced type safety across configFile, buildValidator, and yamlSerializer modules
23
+ - Improved error message preservation for webpack/rspack build failures
24
+ - Fixed edge cases in YAML serialization (empty arrays, malformed objects)
25
+ - More robust constructor name detection for object serialization
26
+ - Better handling of Symbol, BigInt, and edge case types
27
+ - **Default template no longer triggers production warning**. [PR #774](https://github.com/shakacode/shakapacker/pull/774) by [justin808](https://github.com/justin808). Fixes [#703](https://github.com/shakacode/shakapacker/issues/703).
28
+ - Changed default `useContentHash` to `true` in `shakapacker.yml` template
29
+ - Eliminates confusing warning about `useContentHash: false` not being allowed in production
30
+ - Development environment now explicitly sets `useContentHash: false` for faster builds
31
+ - Production no longer needs explicit override since it inherits the correct default
32
+
33
+ ## [v9.3.0] - October 28, 2025
51
34
 
52
35
  ### Added
53
36
 
54
- - **New `precompile_hook` configuration option** to run custom commands during asset precompilation. [PR #678](https://github.com/shakacode/shakapacker/pull/678) by [justin808](https://github.com/justin808).
55
- - Allows executing custom scripts or tasks during the precompile process
56
- - Configure in `shakapacker.yml` with `precompile_hook: "command to run"`
57
- - **New `assets_bundler_config_path` configuration option** for custom bundler config locations. [PR #710](https://github.com/shakacode/shakapacker/pull/710) by [justin808](https://github.com/justin808).
58
- - Allows specifying a custom path for webpack/rspack configuration files
59
- - Useful for complex project structures or shared configurations
60
- - **YAML output format support for `bin/export-bundler-config`**. [PR #704](https://github.com/shakacode/shakapacker/pull/704) by [justin808](https://github.com/justin808).
61
- - New `--format yaml` option exports bundler configuration as YAML
62
- - Easier to read than JSON for debugging and documentation
63
- - **Custom help messages for `bin/shakapacker` commands**. [PR #702](https://github.com/shakacode/shakapacker/pull/702) by [justin808](https://github.com/justin808).
64
- - Improved help output for better command discoverability
65
- - Clear usage examples and option descriptions
66
- - **HMR client config export in doctor mode**. [PR #701](https://github.com/shakacode/shakapacker/pull/701) by [justin808](https://github.com/justin808).
67
- - `bin/export-bundler-config --doctor` now includes HMR client configuration
68
- - Helps debug Hot Module Replacement issues
69
- - **Build timing logs** for webpack and rspack. [PR #706](https://github.com/shakacode/shakapacker/pull/706) by [justin808](https://github.com/justin808).
70
- - Shows duration of build operations
71
- - Helps identify performance bottlenecks
72
- - **Named build configurations with `--build` flag**. [PR #728](https://github.com/shakacode/shakapacker/pull/728) by [justin808](https://github.com/justin808).
73
- - Allows specifying custom build configurations: `bin/shakapacker --build=production` or `bin/shakapacker --build=test`
74
- - Useful for creating specialized build configurations for different deployment environments
75
- - **Build validation in `bin/export-bundler-config`**. [PR #717](https://github.com/shakacode/shakapacker/pull/717) by [justin808](https://github.com/justin808).
76
- - Validates webpack/rspack configuration before export to catch errors early
77
- - Provides clear error messages for configuration issues
78
- - **Backward compatibility for rspack config in `config/webpack/`**. [PR #734](https://github.com/shakacode/shakapacker/pull/734) by [justin808](https://github.com/justin808).
79
- - Rspack configurations can now be placed in `config/webpack/` directory for easier migration
80
- - Maintains compatibility with existing project structures
81
- - Added Knip for detecting dead code to CI. [PR #675](https://github.com/shakacode/shakapacker/pull/675) by [justin808](https://github.com/justin808).
37
+ - **HTTP 103 Early Hints support** for faster asset loading. [PR #722](https://github.com/shakacode/shakapacker/pull/722) by [justin808](https://github.com/justin808). Automatically sends early hints when `early_hints: enabled: true` in `shakapacker.yml`. Works with `append_javascript_pack_tag`/`append_stylesheet_pack_tag`, supports per-controller/action configuration, and includes helpers like `configure_pack_early_hints` and `skip_send_pack_early_hints`. Requires Rails 5.2+ and HTTP/2-capable server. See [Early Hints Guide](docs/early_hints.md).
38
+ - **`--help=verbose` flag** to display all available webpack/rspack bundler options. [PR #763](https://github.com/shakacode/shakapacker/pull/763) by [justin808](https://github.com/justin808). Run `bin/shakapacker --help=verbose` to see complete bundler documentation.
39
+ - **Support for arbitrary output names in build configurations**. [PR #752](https://github.com/shakacode/shakapacker/pull/752) by [justin808](https://github.com/justin808). The `outputs` array now accepts any custom names (e.g., `client-modern`, `client-legacy`, `server-bundle`) instead of being limited to only `client`, `server`, and `all`.
40
+ - **Enhanced error reporting in config exporter**. [PR #752](https://github.com/shakacode/shakapacker/pull/752) by [justin808](https://github.com/justin808). Shows detailed environment variable state when config functions fail and provides actionable suggestions based on error patterns.
41
+ - **Config count validation for build outputs**. [PR #752](https://github.com/shakacode/shakapacker/pull/752) by [justin808](https://github.com/justin808). Validates webpack/rspack config array length matches `outputs` array with clear error messages and suggested fixes.
42
+ - **`precompile_hook` configuration option** to run custom commands during asset precompilation. [PR #678](https://github.com/shakacode/shakapacker/pull/678) by [justin808](https://github.com/justin808). Configure in `shakapacker.yml` with `precompile_hook: "command to run"`.
43
+ - **`assets_bundler_config_path` configuration option** for custom bundler config locations. [PR #710](https://github.com/shakacode/shakapacker/pull/710) by [justin808](https://github.com/justin808). Allows specifying a custom path for webpack/rspack configuration files.
44
+ - **YAML output format support for `bin/shakapacker-config`** (formerly `bin/export-bundler-config`). [PR #704](https://github.com/shakacode/shakapacker/pull/704) by [justin808](https://github.com/justin808). New `--format yaml` option exports bundler configuration as YAML.
45
+ - **Plugin names displayed in YAML config export**. [PR #750](https://github.com/shakacode/shakapacker/pull/750) by [justin808](https://github.com/justin808). Shows plugin constructor names in exported configuration to help identify which plugins are active.
46
+ - **Custom help messages for `bin/shakapacker` commands**. [PR #702](https://github.com/shakacode/shakapacker/pull/702) by [justin808](https://github.com/justin808). Improved help output for better command discoverability with clear usage examples.
47
+ - **HMR client config export in doctor mode**. [PR #701](https://github.com/shakacode/shakapacker/pull/701) by [justin808](https://github.com/justin808). `bin/shakapacker-config --doctor` now includes HMR client configuration to help debug Hot Module Replacement issues.
48
+ - **Build timing logs** for webpack and rspack. [PR #706](https://github.com/shakacode/shakapacker/pull/706) by [justin808](https://github.com/justin808). Shows duration of build operations to help identify performance bottlenecks.
49
+ - **Named build configurations with `--build` flag**. [PR #728](https://github.com/shakacode/shakapacker/pull/728) by [justin808](https://github.com/justin808). Allows specifying custom build configurations like `bin/shakapacker --build=production` or `bin/shakapacker --build=test`.
50
+ - **Build validation in `bin/shakapacker-config`**. [PR #717](https://github.com/shakacode/shakapacker/pull/717) by [justin808](https://github.com/justin808). Validates webpack/rspack configuration before export to catch errors early.
51
+ - **Backward compatibility for rspack config in `config/webpack/`**. [PR #734](https://github.com/shakacode/shakapacker/pull/734) by [justin808](https://github.com/justin808). Rspack configurations can now be placed in `config/webpack/` directory for easier migration.
52
+ - **Merge option for WebpackAssetsManifestPlugin**. [PR #760](https://github.com/shakacode/shakapacker/pull/760) by [justin808](https://github.com/justin808). Adds `merge` option to control manifest merging behavior, useful for multi-compiler setups.
53
+ - Support for esbuild-loader v5. [PR #758](https://github.com/shakacode/shakapacker/pull/758) by [justin808](https://github.com/justin808).
82
54
 
83
55
  ### Changed
84
56
 
85
- - **Migrated to ESLint v9 with flat config format**. [PR #677](https://github.com/shakacode/shakapacker/pull/677) by [justin808](https://github.com/justin808).
86
- - Updated all ESLint plugins to latest versions
87
- - Uses new flat config format for better maintainability
88
- - **Replaced custom argument parser with yargs**. [PR #692](https://github.com/shakacode/shakapacker/pull/692) by [justin808](https://github.com/justin808).
89
- - More robust command-line argument parsing
90
- - Better error messages and help output
91
- - Replaced `require` with `import` in package/index.ts. [PR #674](https://github.com/shakacode/shakapacker/pull/674) by [justin808](https://github.com/justin808).
57
+ - **Generated `swc.config.js` now uses single quotes and trailing commas**. [PR #755](https://github.com/shakacode/shakapacker/pull/755) by [justin808](https://github.com/justin808). Consistent code style in generated configuration files.
92
58
  - Updated @rspack dependencies to 1.5.8. [PR #700](https://github.com/shakacode/shakapacker/pull/700) by [justin808](https://github.com/justin808).
93
59
 
94
60
  ### Improved
95
61
 
96
- - **Enhanced rspack migration documentation** with real-world lessons. [PR #713](https://github.com/shakacode/shakapacker/pull/713) by [justin808](https://github.com/justin808).
97
- - Added practical migration guidance based on actual project experiences
98
- - Common pitfalls and solutions documented
99
- - **Consolidated duplicate configuration documentation**. [PR #714](https://github.com/shakacode/shakapacker/pull/714) by [justin808](https://github.com/justin808).
100
- - Removed redundant documentation
101
- - Single source of truth for configuration options
102
- - **Improved error messages** to suggest `assets_bundler_config_path`. [PR #712](https://github.com/shakacode/shakapacker/pull/712) by [justin808](https://github.com/justin808).
103
- - More helpful error messages when bundler config is not found
104
- - Suggests using `assets_bundler_config_path` for custom locations
105
- - **Improved doctor command output** clarity and accuracy. [PR #682](https://github.com/shakacode/shakapacker/pull/682) by [justin808](https://github.com/justin808).
106
- - Better formatting and organization of diagnostic information
107
- - More actionable recommendations
108
- - **Documented `content_for` pattern to prevent FOUC** with `stylesheet_pack_tag`. [PR #737](https://github.com/shakacode/shakapacker/pull/737) by [justin808](https://github.com/justin808).
109
- - Added documentation on using `content_for` to prevent Flash of Unstyled Content
110
- - Best practice patterns for managing stylesheet loading order
111
- - **Improved upgrade documentation** to clarify dual Gemfile and package.json updates. [PR #731](https://github.com/shakacode/shakapacker/pull/731) by [justin808](https://github.com/justin808).
112
- - Clearer instructions for upgrading both Ruby gem and NPM package
113
- - Helps prevent version mismatch issues
114
- - Formatted all markdown files with prettier. [PR #673](https://github.com/shakacode/shakapacker/pull/673) by [justin808](https://github.com/justin808).
62
+ - **Improved error messages** to suggest `assets_bundler_config_path`. [PR #712](https://github.com/shakacode/shakapacker/pull/712) by [justin808](https://github.com/justin808). More helpful error messages when bundler config is not found, suggesting use of `assets_bundler_config_path` for custom locations.
63
+ - **Improved doctor command output** clarity and accuracy. [PR #682](https://github.com/shakacode/shakapacker/pull/682) by [justin808](https://github.com/justin808). Better formatting and organization of diagnostic information with more actionable recommendations.
115
64
 
116
65
  ### Fixed
117
66
 
118
- - Fixed rspack native bindings installation issue when switching bundlers. [PR #672](https://github.com/shakacode/shakapacker/pull/672) by [justin808](https://github.com/justin808).
119
- - Running `rake shakapacker:switch_bundler rspack -- --install-deps` now properly installs platform-specific native bindings
120
- - Fixes "Cannot find native binding" error when switching to rspack
121
- - Fixed Rails constant error when using custom environments like staging. [PR #681](https://github.com/shakacode/shakapacker/pull/681) by [justin808](https://github.com/justin808).
122
- - `RAILS_ENV=staging` no longer causes "uninitialized constant Shakapacker::Instance::Rails" error
123
- - Shakapacker now works in non-Rails contexts (like standalone runner)
124
- - Fixed TypeScript type definitions to export proper types instead of `any`. [PR #684](https://github.com/shakacode/shakapacker/pull/684) by [justin808](https://github.com/justin808).
125
- - Previously `package/index.d.ts` was exporting all types as `any`, breaking IDE autocomplete
126
- - Now properly exports typed interfaces for `WebpackConfig`, `RspackConfig`, etc.
127
- - Fixed integrity config handling and sass-loader version check. [PR #688](https://github.com/shakacode/shakapacker/pull/688) by [justin808](https://github.com/justin808).
128
- - Properly handles subresource integrity configuration
129
- - Correctly detects sass-loader version for conditional logic
130
- - Prevented index.d.ts confusion in build process. [PR #698](https://github.com/shakacode/shakapacker/pull/698) by [justin808](https://github.com/justin808).
131
- - TypeScript declaration files no longer interfere with build output
132
- - Fixed yarn.lock formatting changes in Conductor setup. [PR #683](https://github.com/shakacode/shakapacker/pull/683) by [justin808](https://github.com/justin808).
67
+ - Fixed Rails constant error when using custom environments like staging. [PR #681](https://github.com/shakacode/shakapacker/pull/681) by [justin808](https://github.com/justin808). `RAILS_ENV=staging` no longer causes "uninitialized constant Shakapacker::Instance::Rails" error. Shakapacker now works in non-Rails contexts.
68
+ - Fixed TypeScript type definitions to export proper types instead of `any`. [PR #684](https://github.com/shakacode/shakapacker/pull/684) by [justin808](https://github.com/justin808). Previously `package/index.d.ts` was exporting all types as `any`, breaking IDE autocomplete. Now properly exports typed interfaces.
69
+ - Fixed integrity config handling and sass-loader version check. [PR #688](https://github.com/shakacode/shakapacker/pull/688) by [justin808](https://github.com/justin808). Properly handles subresource integrity configuration and correctly detects sass-loader version for conditional logic.
133
70
 
134
71
  ## [v9.2.0] - October 9, 2025
135
72
 
136
73
  ### Added
137
74
 
138
75
  - **New config export utility for debugging webpack/rspack configurations** [PR #647](https://github.com/shakacode/shakapacker/pull/647) by [justin808](https://github.com/justin808).
139
- - Adds `bin/export-bundler-config` utility with three modes:
76
+ - Adds `bin/shakapacker-config` utility (originally named `bin/export-bundler-config`, renamed in PR #728) with three modes:
140
77
  - **Doctor mode** (`--doctor`): Exports all configs (dev + prod, client + server) to `shakapacker-config-exports/` directory - best for troubleshooting
141
78
  - **Save mode** (`--save`): Export current environment configs to files
142
79
  - **Stdout mode** (default): View configs in terminal
@@ -148,7 +85,7 @@ Changes since the last non-beta release.
148
85
  - Validates bundler value and output paths
149
86
  - Sanitizes filenames to prevent path traversal
150
87
  - Helpful `.gitignore` suggestions
151
- - **Usage:** `bin/export-bundler-config --doctor` or `bundle exec rake shakapacker:export_bundler_config`
88
+ - **Usage:** `bin/shakapacker-config --doctor` or `bundle exec rake shakapacker:export_bundler_config`
152
89
  - Works seamlessly with `rake shakapacker:switch_bundler` for comparing webpack vs rspack configs
153
90
  - Lays groundwork for future config diff feature (tracked in [#667](https://github.com/shakacode/shakapacker/issues/667))
154
91
 
@@ -783,8 +720,8 @@ Note: [Rubygem is 6.3.0.pre.rc.1](https://rubygems.org/gems/shakapacker/versions
783
720
 
784
721
  See [CHANGELOG.md in rails/webpacker (up to v5.4.3)](https://github.com/rails/webpacker/blob/master/CHANGELOG.md)
785
722
 
786
- [Unreleased]: https://github.com/shakacode/shakapacker/compare/v9.3.0-beta.5...main
787
- [v9.3.0-beta.5]: https://github.com/shakacode/shakapacker/compare/v9.2.0...v9.3.0-beta.5
723
+ [Unreleased]: https://github.com/shakacode/shakapacker/compare/v9.3.0...main
724
+ [v9.3.0]: https://github.com/shakacode/shakapacker/compare/v9.2.0...v9.3.0
788
725
  [v9.2.0]: https://github.com/shakacode/shakapacker/compare/v9.1.0...v9.2.0
789
726
  [v9.1.0]: https://github.com/shakacode/shakapacker/compare/v9.0.0...v9.1.0
790
727
  [v9.0.0]: https://github.com/shakacode/shakapacker/compare/v8.4.0...v9.0.0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shakapacker (9.3.0.beta.7)
4
+ shakapacker (9.3.0)
5
5
  activesupport (>= 5.2)
6
6
  package_json
7
7
  rack-proxy (>= 0.6.1)
data/README.md CHANGED
@@ -85,6 +85,7 @@ Read the [full review here](https://clutch.co/profile/shakacode#reviews?sort_by=
85
85
  - [Automatic Webpack Code Building](#automatic-webpack-code-building)
86
86
  - [Compiler strategies](#compiler-strategies)
87
87
  - [Common Development Commands](#common-development-commands)
88
+ - [API Documentation](#api-documentation)
88
89
  - [Webpack Configuration](#webpack-configuration)
89
90
  - [Babel configuration](#babel-configuration)
90
91
  - [SWC configuration](#swc-configuration)
@@ -316,7 +317,15 @@ At its core, Shakapacker's essential function is to:
316
317
 
317
318
  ### Configuration and Code
318
319
 
319
- **📖 For a comprehensive guide to all configuration options, see [Configuration Guide](./docs/configuration.md)**
320
+ **📖 For a comprehensive guide to all configuration options, see the [Configuration Guide](./docs/configuration.md)**
321
+
322
+ This includes documentation for:
323
+
324
+ - All `config/shakapacker.yml` options (including `assets_bundler_config_path`)
325
+ - Environment-specific configuration
326
+ - Development server settings
327
+ - Build configurations (`config/shakapacker-builds.yml`)
328
+ - Best practices and common patterns
320
329
 
321
330
  You will need your file system to correspond to the setup of your `config/shakapacker.yml` file.
322
331
 
@@ -664,6 +673,48 @@ end
664
673
 
665
674
  **Note:** Don't forget to prefix `ruby` when running these binstubs on Windows
666
675
 
676
+ ### API Documentation
677
+
678
+ Shakapacker's Ruby API is documented using RDoc comments. You can generate the API documentation locally using either RDoc or YARD:
679
+
680
+ #### Using RDoc (Standard Ruby Documentation)
681
+
682
+ ```bash
683
+ # Generate documentation in the doc/ directory
684
+ rdoc lib/
685
+
686
+ # View the generated documentation
687
+ open doc/index.html
688
+ ```
689
+
690
+ #### Using YARD (Enhanced Documentation)
691
+
692
+ YARD provides better formatting and supports additional tags used in the codebase:
693
+
694
+ ```bash
695
+ # Install YARD if you don't have it
696
+ gem install yard
697
+
698
+ # Generate documentation
699
+ yard doc
700
+
701
+ # View the generated documentation
702
+ open doc/index.html
703
+
704
+ # Or start a local documentation server
705
+ yard server
706
+ ```
707
+
708
+ The API documentation covers:
709
+
710
+ - **Shakapacker** - Main module with configuration, compilation, and manifest access
711
+ - **Shakapacker::Configuration** - All configuration options from `shakapacker.yml`
712
+ - **Shakapacker::Manifest** - Asset lookup methods used by view helpers
713
+ - **Shakapacker::DevServer** - Development server status and configuration
714
+ - **Shakapacker::Instance** - Instance management and lifecycle
715
+
716
+ For the most up-to-date API reference, generate the documentation from the source code as shown above.
717
+
667
718
  ### Webpack Configuration
668
719
 
669
720
  First, you don't _need_ to use Shakapacker's webpack configuration. However, the `shakapacker` NPM package provides convenient access to configuration code that reads the `config/shakapacker.yml` file which the view helpers also use. If you have your customized webpack configuration, at the minimum, you must ensure:
@@ -801,7 +852,7 @@ Shakapacker provides a powerful utility to export and analyze your webpack/rspac
801
852
 
802
853
  ```bash
803
854
  # Export all configs for troubleshooting (recommended)
804
- bin/export-bundler-config --doctor
855
+ bin/shakapacker-config --doctor
805
856
 
806
857
  # Or via rake task
807
858
  bundle exec rake shakapacker:export_bundler_config -- --doctor
@@ -4,6 +4,7 @@ This guide covers all configuration options available in `config/shakapacker.yml
4
4
 
5
5
  ## Table of Contents
6
6
 
7
+ - [Quick Reference](#quick-reference)
7
8
  - [Basic Configuration](#basic-configuration)
8
9
  - [Source Configuration](#source-configuration)
9
10
  - [Output Configuration](#output-configuration)
@@ -16,6 +17,33 @@ This guide covers all configuration options available in `config/shakapacker.yml
16
17
  - [Environment-Specific Configuration](#environment-specific-configuration)
17
18
  - [Build Configurations (config/shakapacker-builds.yml)](#build-configurations-configshakapacker-buildsyml)
18
19
 
20
+ ## Quick Reference
21
+
22
+ Common configuration options with their defaults:
23
+
24
+ | Option | Type | Default | Description |
25
+ | ------------------------------ | ------- | --------------------------------------- | ---------------------------------------------------------- |
26
+ | `assets_bundler` | string | `"webpack"` | Bundler to use: `"webpack"` or `"rspack"` |
27
+ | `assets_bundler_config_path` | string | `"config/webpack"` or `"config/rspack"` | Directory containing bundler config files |
28
+ | `javascript_transpiler` | string | `"swc"` or `"babel"` | Transpiler: `"swc"`, `"babel"`, or `"esbuild"` |
29
+ | `source_path` | string | `"app/javascript"` | Root directory for JavaScript source files |
30
+ | `source_entry_path` | string | `"packs"` | Subdirectory within `source_path` for entry points |
31
+ | `nested_entries` | boolean | `true` | Discover entry points in subdirectories |
32
+ | `public_output_path` | string | `"packs"` | Subdirectory within `public_root_path` for compiled assets |
33
+ | `private_output_path` | string | `nil` | Directory for private server-side bundles (e.g., SSR) |
34
+ | `compile` | boolean | env-specific | Compile assets on-demand when requests are made |
35
+ | `cache_manifest` | boolean | `false` (dev), `true` (prod) | Cache manifest.json in memory |
36
+ | `compiler_strategy` | string | `"mtime"` (dev), `"digest"` (prod) | How to determine if recompilation is needed |
37
+ | `useContentHash` | boolean | `false` (dev), `true` (prod) | Include content hashes in asset filenames |
38
+ | `webpack_compile_output` | boolean | `true` | Show webpack/rspack compilation output |
39
+ | `shakapacker_precompile` | boolean | `true` | Include in `rails assets:precompile` |
40
+ | `ensure_consistent_versioning` | boolean | `true` | Enforce gem/npm version matching |
41
+ | `dev_server.host` | string | `"localhost"` | Development server host |
42
+ | `dev_server.port` | number | `3035` | Development server port |
43
+ | `dev_server.hmr` | boolean | `false` | Enable Hot Module Replacement |
44
+
45
+ For detailed explanations, examples, and additional options, see the sections below.
46
+
19
47
  ## Basic Configuration
20
48
 
21
49
  ### `assets_bundler`
@@ -11,7 +11,9 @@
11
11
  - [Server-Side Rendering (SSR) Considerations](#server-side-rendering-ssr-considerations)
12
12
  - [Key Differences from Webpack](#key-differences-from-webpack)
13
13
  - [Migration Steps](#migration-steps)
14
+ - [Build Verification](#build-verification)
14
15
  - [Configuration Best Practices](#configuration-best-practices)
16
+ - [Common Migration Issues](#common-migration-issues)
15
17
  - [Common Issues and Solutions](#common-issues-and-solutions)
16
18
  - [Performance Tips](#performance-tips)
17
19
  - [Debugging Configuration](#debugging-configuration)
@@ -312,6 +314,73 @@ bin/shakapacker --mode production
312
314
  - [ ] Deploy to staging
313
315
  - [ ] Monitor performance improvements
314
316
 
317
+ ## Build Verification
318
+
319
+ After completing your migration, verify that everything works correctly:
320
+
321
+ ### Basic Build Verification
322
+
323
+ ```bash
324
+ # Clean previous build artifacts
325
+ rm -rf public/packs public/packs-test
326
+
327
+ # Test development build
328
+ bin/shakapacker
329
+
330
+ # Test production build
331
+ RAILS_ENV=production bin/shakapacker
332
+
333
+ # Verify assets were generated
334
+ ls -la public/packs/
335
+ ```
336
+
337
+ ### SSR Build Verification
338
+
339
+ If your application uses Server-Side Rendering, perform these additional checks:
340
+
341
+ ```bash
342
+ # 1. Verify server bundle was created
343
+ ls -la public/packs/*-server-bundle.js
344
+
345
+ # 2. Test SSR rendering in Rails console
346
+ bundle exec rails console
347
+ # In console:
348
+ ReactOnRails::ServerRenderingPool.reset_pool
349
+ # Then visit a page that uses SSR and check for errors
350
+
351
+ # 3. Run full test suite (watch for SSR-related failures)
352
+ bundle exec rspec
353
+
354
+ # 4. Check for CSS extraction issues in SSR
355
+ # Look for "Cannot read properties of undefined" errors in tests
356
+ # or intermittent test failures related to styling
357
+ ```
358
+
359
+ ### Common Verification Issues
360
+
361
+ **Silent SSR failures**: If your SSR pages render without errors but components appear unstyled or with missing data, check:
362
+
363
+ - Server bundle is being generated correctly
364
+ - CSS extraction is disabled for server bundle (see [Common Migration Issues](#common-migration-issues))
365
+ - React runtime configuration is compatible with your SSR framework
366
+
367
+ **Error patterns to watch for**:
368
+
369
+ - `Cannot read properties of undefined (reading 'className')` - CSS Modules configuration issue
370
+ - `Invalid call to renderToString` - React runtime compatibility issue
371
+ - `Module not found: Can't resolve './Module.bs.js'` - File extension resolution issue
372
+ - Intermittent/flaky tests - CSS extraction leaking into server bundle
373
+
374
+ ### Testing Strategy for SSR
375
+
376
+ For applications with SSR, follow this verification order:
377
+
378
+ 1. Test client-only pages first (verify basic Rspack build works)
379
+ 2. Test SSR pages without CSS modules (verify SSR configuration)
380
+ 3. Test SSR pages with CSS modules (verify CSS extraction + SSR work together)
381
+ 4. Run full test suite multiple times to catch flaky tests
382
+ 5. Test in production mode (some issues only appear with minification)
383
+
315
384
  ## Configuration Best Practices
316
385
 
317
386
  ### Configuration Organization
@@ -390,6 +459,173 @@ When upgrading to Shakapacker 9 with Rspack:
390
459
  4. **Check Node version compatibility**: Verify your Node version meets all dependency requirements
391
460
  5. **Don't make empty commits**: If CI fails but local passes, investigate the root cause - don't try to "trigger CI re-run" with empty commits
392
461
 
462
+ ## Common Migration Issues
463
+
464
+ This section highlights the most critical configuration issues that cause build failures during webpack-to-Rspack migration. These issues are especially important for applications using Server-Side Rendering (SSR), CSS Modules, or non-standard file extensions.
465
+
466
+ ### 1. SWC React Runtime for SSR (CRITICAL for React on Rails)
467
+
468
+ **Problem**: React on Rails SSR detection expects specific function signatures that may not work with SWC's automatic React runtime.
469
+
470
+ **Symptoms**:
471
+
472
+ - Error: `Invalid call to renderToString. Possibly you have a renderFunction...`
473
+ - SSR pages fail to render or render without React hydration
474
+
475
+ **Solution**: Configure SWC to use classic React runtime instead of automatic:
476
+
477
+ ```javascript
478
+ // config/swc.config.js
479
+ const customConfig = {
480
+ options: {
481
+ jsc: {
482
+ transform: {
483
+ react: {
484
+ runtime: "classic", // Use 'classic' instead of 'automatic' for SSR
485
+ refresh: env.isDevelopment && env.runningWebpackDevServer
486
+ }
487
+ }
488
+ }
489
+ }
490
+ }
491
+ ```
492
+
493
+ **Why this matters**: The automatic runtime changes how React imports work (`import { jsx as _jsx }` vs `import React`), which breaks React on Rails' SSR function detection logic. This is a silent failure that only manifests at runtime.
494
+
495
+ **Implementation checklist for SSR users**:
496
+
497
+ - [ ] Locate your SWC configuration file (typically `config/swc.config.js`)
498
+ - [ ] Change `runtime: 'automatic'` to `runtime: 'classic'`
499
+ - [ ] Test SSR rendering in development and production modes
500
+ - [ ] Verify React hydration works correctly on client side
501
+ - [ ] Run full test suite to catch any related issues
502
+
503
+ ### 2. CSS Modules Configuration for Server Bundles (CRITICAL for SSR + CSS Modules)
504
+
505
+ **Problem**: When configuring server bundles, you must preserve Shakapacker 9's CSS Modules settings (`namedExport: true`) while adding SSR-specific settings. Simply setting `exportOnlyLocals: true` will override the base configuration and break CSS imports.
506
+
507
+ **Symptoms**:
508
+
509
+ - Error: `export 'default' (imported as 'css') was not found`
510
+ - CSS classes return undefined in SSR
511
+ - Client-side CSS works but SSR fails
512
+ - Intermittent/flaky test failures
513
+
514
+ **Solution**: Use spread operator to merge CSS Modules options instead of replacing them:
515
+
516
+ ```javascript
517
+ // config/webpack/serverWebpackConfig.js
518
+ if (cssLoader && cssLoader.options && cssLoader.options.modules) {
519
+ // ✅ CORRECT - Preserves namedExport and other settings
520
+ cssLoader.options.modules = {
521
+ ...cssLoader.options.modules,
522
+ exportOnlyLocals: true
523
+ }
524
+
525
+ // ❌ INCORRECT - Overwrites all settings
526
+ // cssLoader.options.modules.exportOnlyLocals = true
527
+ }
528
+ ```
529
+
530
+ **Why this matters**: Shakapacker 9 changed the default CSS Modules configuration to use named exports. If you only set `exportOnlyLocals: true` without preserving the base config, you'll lose the `namedExport: true` setting, causing import/export mismatches between client and server bundles.
531
+
532
+ **Related configuration**: You must also filter out CSS extraction loaders in server bundles:
533
+
534
+ ```javascript
535
+ // config/webpack/serverWebpackConfig.js
536
+ rule.use = rule.use.filter((item) => {
537
+ let testValue
538
+ if (typeof item === "string") {
539
+ testValue = item
540
+ } else if (typeof item.loader === "string") {
541
+ testValue = item.loader
542
+ }
543
+ // Handle both Webpack and Rspack CSS extract loaders
544
+ return !(
545
+ testValue?.match(/mini-css-extract-plugin/) ||
546
+ testValue?.includes("cssExtractLoader") || // Rspack uses this path
547
+ testValue === "style-loader"
548
+ )
549
+ })
550
+ ```
551
+
552
+ **Implementation checklist for SSR + CSS Modules users**:
553
+
554
+ - [ ] Update server bundle config to use spread operator for CSS Modules options
555
+ - [ ] Ensure CSS extraction loaders are filtered for both webpack and Rspack paths
556
+ - [ ] Test SSR pages with CSS Modules imports
557
+ - [ ] Verify CSS classes are defined (not undefined) during SSR
558
+ - [ ] Run tests multiple times to catch flaky failures
559
+
560
+ ### 3. ReScript File Resolution (CRITICAL for ReScript users)
561
+
562
+ **Problem**: Rspack requires explicit configuration to resolve `.bs.js` extensions (ReScript compiled output), while webpack handled this automatically.
563
+
564
+ **Symptoms**:
565
+
566
+ - Error: `Module not found: Can't resolve './Module.bs.js'`
567
+ - ReScript modules fail to import
568
+ - Build fails with missing module errors
569
+
570
+ **Solution**: Add `.bs.js` to resolve extensions:
571
+
572
+ ```javascript
573
+ // config/webpack/webpack.config.js (works for both webpack and rspack)
574
+ const commonOptions = {
575
+ resolve: {
576
+ extensions: [".css", ".ts", ".tsx", ".bs.js"] // Add .bs.js for ReScript
577
+ }
578
+ }
579
+
580
+ module.exports = merge({}, baseConfig, commonOptions)
581
+ ```
582
+
583
+ **Why this matters**: ReScript compiles `.res` source files to `.bs.js` JavaScript files. If your bundler can't resolve these extensions, all ReScript imports will fail, even though the compiled files exist.
584
+
585
+ **Additional consideration - Missing compiled files**: Some ReScript npm packages ship only `.res` source files without compiled `.bs.js` files. If you encounter this, use `patch-package` to fix the dependency's `bsconfig.json` (see detailed solution in [Common Issues and Solutions](#issue-rescript-dependencies-missing-compiled-files)).
586
+
587
+ **Implementation checklist for ReScript users**:
588
+
589
+ - [ ] Add `.bs.js` to resolve extensions in webpack/rspack config
590
+ - [ ] Verify all ReScript modules can be imported
591
+ - [ ] Check if any ReScript dependencies are missing compiled files
592
+ - [ ] If needed, patch broken dependencies with `patch-package`
593
+ - [ ] Test build with all ReScript code paths
594
+
595
+ ### 4. Build Verification Steps (IMPORTANT for all migrations)
596
+
597
+ **Problem**: The migration documentation lacked practical verification procedures, leaving developers without guidance on testing SSR functionality or identifying configuration errors.
598
+
599
+ **Solution**: Follow the comprehensive verification steps in the [Build Verification](#build-verification) section above, which includes:
600
+
601
+ - Basic build verification commands
602
+ - SSR-specific testing procedures
603
+ - Error pattern identification
604
+ - Testing strategy for SSR applications
605
+
606
+ **Why this matters**: Silent SSR failures and configuration issues often only manifest in specific scenarios (production mode, certain page types, race conditions in tests). Without systematic verification, these issues may slip into production.
607
+
608
+ **Implementation checklist for all users**:
609
+
610
+ - [ ] Clean build artifacts before testing
611
+ - [ ] Test both development and production builds
612
+ - [ ] Verify generated assets in `public/packs/`
613
+ - [ ] For SSR: verify server bundle generation
614
+ - [ ] For SSR: test rendering in Rails console
615
+ - [ ] Run full test suite multiple times
616
+ - [ ] Check for error patterns listed in Build Verification
617
+
618
+ ### Configuration Differences: webpack vs Rspack Summary
619
+
620
+ Quick reference for the key differences that cause migration issues:
621
+
622
+ | Area | Webpack | Rspack | Migration Action |
623
+ | -------------------------- | ------------------------- | ----------------------------------- | ------------------------------------------- |
624
+ | CSS Extraction Loader Path | `mini-css-extract-plugin` | `cssExtractLoader.js` | Filter both paths in SSR config |
625
+ | React Runtime (SSR) | Works with both | Classic required for React on Rails | Use `runtime: 'classic'` |
626
+ | ReScript Extensions | Auto-resolves `.bs.js` | Requires explicit config | Add to `resolve.extensions` |
627
+ | CSS Modules Default | `namedExport: true` (v9+) | Same | Preserve with spread operator in SSR config |
628
+
393
629
  ## Common Issues and Solutions
394
630
 
395
631
  ### Issue: CSS Modules Returning Undefined (CRITICAL)
@@ -601,13 +837,13 @@ To compare your webpack and rspack configurations during migration:
601
837
 
602
838
  ```bash
603
839
  # Export webpack configs before switching
604
- bin/export-bundler-config --doctor
840
+ bin/shakapacker-config --doctor
605
841
 
606
842
  # Switch to rspack
607
843
  rails shakapacker:switch_bundler rspack --install-deps
608
844
 
609
845
  # Export rspack configs to compare
610
- bin/export-bundler-config --doctor
846
+ bin/shakapacker-config --doctor
611
847
 
612
848
  # Compare the files in shakapacker-config-exports/
613
849
  diff shakapacker-config-exports/webpack-production-client.yaml \