shakapacker 9.3.0 → 9.3.2

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 (82) hide show
  1. checksums.yaml +4 -4
  2. data/.claude/commands/update-changelog.md +232 -0
  3. data/.github/actionlint-matcher.json +17 -0
  4. data/.github/workflows/dummy.yml +9 -0
  5. data/.github/workflows/generator.yml +13 -0
  6. data/.github/workflows/node.yml +83 -0
  7. data/.github/workflows/ruby.yml +11 -0
  8. data/.github/workflows/test-bundlers.yml +10 -0
  9. data/CHANGELOG.md +24 -9
  10. data/CLAUDE.md +6 -10
  11. data/CONTRIBUTING.md +44 -0
  12. data/Gemfile.lock +1 -1
  13. data/README.md +74 -44
  14. data/docs/api-reference.md +519 -0
  15. data/docs/cdn_setup.md +3 -3
  16. data/docs/common-upgrades.md +6 -7
  17. data/docs/configuration.md +14 -8
  18. data/docs/css-modules-export-mode.md +40 -6
  19. data/docs/deployment.md +3 -3
  20. data/docs/early_hints_manual_api.md +1 -1
  21. data/docs/feature_testing.md +3 -3
  22. data/docs/optional-peer-dependencies.md +2 -2
  23. data/docs/precompile_hook.md +15 -15
  24. data/docs/react.md +1 -1
  25. data/docs/releasing.md +7 -7
  26. data/docs/rspack_migration_guide.md +8 -14
  27. data/docs/transpiler-migration.md +12 -9
  28. data/docs/troubleshooting.md +3 -3
  29. data/docs/using_swc_loader.md +13 -10
  30. data/docs/v6_upgrade.md +2 -2
  31. data/docs/v9_upgrade.md +78 -3
  32. data/eslint.config.fast.js +120 -8
  33. data/eslint.config.js +50 -31
  34. data/lib/install/config/shakapacker.yml +14 -1
  35. data/lib/shakapacker/bundler_switcher.rb +83 -18
  36. data/lib/shakapacker/configuration.rb +47 -4
  37. data/lib/shakapacker/dev_server_runner.rb +4 -0
  38. data/lib/shakapacker/doctor.rb +7 -7
  39. data/lib/shakapacker/runner.rb +1 -1
  40. data/lib/shakapacker/swc_migrator.rb +2 -2
  41. data/lib/shakapacker/version.rb +1 -1
  42. data/lib/tasks/shakapacker/binstubs.rake +4 -2
  43. data/lib/tasks/shakapacker/check_binstubs.rake +2 -2
  44. data/lib/tasks/shakapacker/doctor.rake +3 -3
  45. data/lib/tasks/shakapacker/export_bundler_config.rake +5 -9
  46. data/lib/tasks/shakapacker/install.rake +4 -2
  47. data/lib/tasks/shakapacker/switch_bundler.rake +30 -40
  48. data/package/config.ts +2 -3
  49. data/package/configExporter/cli.ts +29 -24
  50. data/package/dev_server.ts +2 -2
  51. data/package/env.ts +1 -1
  52. data/package/environments/__type-tests__/rspack-plugin-compatibility.ts +6 -6
  53. data/package/environments/base.ts +2 -2
  54. data/package/environments/development.ts +3 -6
  55. data/package/environments/production.ts +2 -2
  56. data/package/environments/test.ts +2 -1
  57. data/package/esbuild/index.ts +0 -2
  58. data/package/index.d.ts +1 -0
  59. data/package/index.d.ts.template +1 -0
  60. data/package/index.ts +0 -1
  61. data/package/loaders.d.ts +1 -1
  62. data/package/plugins/rspack.ts +3 -1
  63. data/package/plugins/webpack.ts +5 -3
  64. data/package/rspack/index.ts +3 -3
  65. data/package/rules/file.ts +1 -1
  66. data/package/rules/raw.ts +3 -1
  67. data/package/rules/rspack.ts +0 -2
  68. data/package/rules/sass.ts +0 -2
  69. data/package/rules/webpack.ts +0 -1
  70. data/package/swc/index.ts +0 -2
  71. data/package/types.ts +8 -11
  72. data/package/utils/debug.ts +0 -4
  73. data/package/utils/getStyleRule.ts +17 -9
  74. data/package/utils/helpers.ts +8 -3
  75. data/package/utils/pathValidation.ts +10 -11
  76. data/package/utils/requireOrError.ts +4 -3
  77. data/package/webpack-types.d.ts +1 -1
  78. data/package/webpackDevServerConfig.ts +4 -4
  79. data/package.json +3 -3
  80. data/test/package/transpiler-defaults.test.js +42 -0
  81. data/yarn.lock +1 -1
  82. metadata +5 -2
data/README.md CHANGED
@@ -85,7 +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
+ - [Ruby API Reference](#ruby-api-reference)
89
89
  - [Webpack Configuration](#webpack-configuration)
90
90
  - [Babel configuration](#babel-configuration)
91
91
  - [SWC configuration](#swc-configuration)
@@ -163,7 +163,7 @@ Then run the following to install Shakapacker:
163
163
 
164
164
  ```bash
165
165
  ./bin/bundle install
166
- ./bin/rails shakapacker:install
166
+ bundle exec rake shakapacker:install
167
167
  ```
168
168
 
169
169
  Before initiating the installation process, ensure you have committed all the changes. While installing Shakapacker, there might be some conflict between the existing file content and what Shakapacker tries to copy. You can either approve all the prompts for overriding these files or use the `FORCE=true` environment variable before the installation command to force the override without any prompt.
@@ -282,12 +282,10 @@ Depending on your setup, you'll need different subsets of the optional peer depe
282
282
  **Quick tip:** You can easily switch between webpack and rspack using:
283
283
 
284
284
  ```bash
285
- rails shakapacker:switch_bundler rspack --install-deps
286
- # or with rake (note the -- separator)
287
- rake shakapacker:switch_bundler rspack -- --install-deps
285
+ bundle exec rake shakapacker:switch_bundler rspack -- --install-deps
288
286
 
289
287
  # For faster switching, use --no-uninstall to keep both bundlers installed
290
- rails shakapacker:switch_bundler webpack --install-deps --no-uninstall
288
+ bundle exec rake shakapacker:switch_bundler webpack -- --install-deps --no-uninstall
291
289
  ```
292
290
 
293
291
  See the [Rspack Migration Guide](./docs/rspack_migration_guide.md) for details.
@@ -673,47 +671,55 @@ end
673
671
 
674
672
  **Note:** Don't forget to prefix `ruby` when running these binstubs on Windows
675
673
 
676
- ### API Documentation
674
+ ### Ruby API Reference
677
675
 
678
- Shakapacker's Ruby API is documented using RDoc comments. You can generate the API documentation locally using either RDoc or YARD:
676
+ **📚 For comprehensive Ruby API documentation, see the [API Reference Guide](./docs/api-reference.md).**
679
677
 
680
- #### Using RDoc (Standard Ruby Documentation)
678
+ This guide covers:
681
679
 
682
- ```bash
683
- # Generate documentation in the doc/ directory
684
- rdoc lib/
680
+ - **Main Shakapacker Module** - Configuration, compilation, and manifest access
681
+ - **Configuration API** - Accessing `config/shakapacker.yml` settings programmatically
682
+ - **View Helpers** - Complete reference for all Rails helpers
683
+ - **Manifest API** - Asset lookup and resolution methods
684
+ - **Dev Server API** - Development server status and management
685
+ - **Advanced Usage** - Multiple instances, testing, custom configurations
685
686
 
686
- # View the generated documentation
687
- open doc/index.html
687
+ #### Quick Examples
688
+
689
+ ```ruby
690
+ # Access configuration
691
+ Shakapacker.config.source_path
692
+ # => #<Pathname:/app/app/javascript>
693
+
694
+ # Get raw configuration hash
695
+ Shakapacker.config.data
696
+ # => { "source_path" => "app/javascript", ... }
697
+
698
+ # Look up compiled assets
699
+ Shakapacker.manifest.lookup("application.js")
700
+ # => "/packs/application-abc123.js"
701
+
702
+ # Check dev server status
703
+ Shakapacker.dev_server.running?
704
+ # => true
688
705
  ```
689
706
 
690
- #### Using YARD (Enhanced Documentation)
707
+ #### Generating Full API Documentation
691
708
 
692
- YARD provides better formatting and supports additional tags used in the codebase:
709
+ For complete API documentation with all methods and parameters:
693
710
 
694
711
  ```bash
695
- # Install YARD if you don't have it
712
+ # Using YARD (recommended - better formatting)
696
713
  gem install yard
697
-
698
- # Generate documentation
699
714
  yard doc
715
+ yard server # Browse at http://localhost:8808
700
716
 
701
- # View the generated documentation
717
+ # Using RDoc (standard Ruby documentation)
718
+ rdoc lib/
702
719
  open doc/index.html
703
-
704
- # Or start a local documentation server
705
- yard server
706
720
  ```
707
721
 
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.
722
+ The generated documentation includes all public and private methods with detailed descriptions.
717
723
 
718
724
  ### Webpack Configuration
719
725
 
@@ -724,6 +730,21 @@ First, you don't _need_ to use Shakapacker's webpack configuration. However, the
724
730
 
725
731
  The webpack configuration used by Shakapacker lives in `config/webpack/webpack.config.js`; this makes it easy to customize the configuration beyond what's available in `config/shakapacker.yml` by giving you complete control of the final configuration. By default, this file exports the result of `generateWebpackConfig` which handles generating a webpack configuration based on `config/shakapacker.yml`.
726
732
 
733
+ #### Using a Completely Custom Webpack Configuration
734
+
735
+ If you're providing a completely custom webpack configuration without using `generateWebpackConfig()`, you should set `javascript_transpiler: 'none'` in your `config/shakapacker.yml` to skip Shakapacker's transpiler validation and dependency checks:
736
+
737
+ ```yml
738
+ # config/shakapacker.yml
739
+ default: &default
740
+ javascript_transpiler: "none" # Skip Shakapacker's transpiler setup
741
+ # ... other config
742
+ ```
743
+
744
+ This is useful when you're managing your own transpiler configuration entirely outside of Shakapacker's defaults.
745
+
746
+ **Note:** Only use `javascript_transpiler: 'none'` if you're providing a completely custom webpack configuration without using `generateWebpackConfig()`. If you're using Shakapacker's webpack generation (which is the common case), use one of the supported transpilers (`'babel'`, `'swc'`, or `'esbuild'`) instead.
747
+
727
748
  The easiest way to modify this config is to pass your desired customizations to `generateWebpackConfig` which will use [webpack-merge](https://github.com/survivejs/webpack-merge) to merge them with the configuration generated from `config/shakapacker.yml`:
728
749
 
729
750
  ```js
@@ -818,7 +839,7 @@ fileRule.type = "asset"
818
839
 
819
840
  ### Babel configuration
820
841
 
821
- By default, you will find the Shakapacker preset in your `package.json`. Note, you need to use the new NPM package name, `shakapacker`.
842
+ If you choose to use Babel instead of the default SWC transpiler, you will need to configure it in your `package.json`:
822
843
 
823
844
  ```json
824
845
  "babel": {
@@ -828,19 +849,21 @@ By default, you will find the Shakapacker preset in your `package.json`. Note, y
828
849
  },
829
850
  ```
830
851
 
831
- Optionally, you can change your Babel configuration by removing these lines in your `package.json` and adding [a Babel configuration file](https://babeljs.io/docs/en/config-files) to your project. For an example of customization based on the original, see [Customizing Babel Config](./docs/customizing_babel_config.md).
852
+ You can also change your Babel configuration by removing these lines in your `package.json` and adding [a Babel configuration file](https://babeljs.io/docs/en/config-files) to your project. For an example of customization based on the original, see [Customizing Babel Config](./docs/customizing_babel_config.md).
832
853
 
833
854
  ### SWC configuration
834
855
 
835
- You can try out experimental integration with the SWC loader. You can read more at [SWC usage docs](./docs/using_swc_loader.md).
856
+ SWC is the recommended JavaScript transpiler in Shakapacker v9+ (20x faster than Babel). New installations use SWC by default via the installation template. You can read more at [SWC usage docs](./docs/using_swc_loader.md).
857
+
858
+ **Note on defaults**: The installation template explicitly sets `javascript_transpiler: "swc"` for new projects. However, for backward compatibility, webpack's runtime default (when no explicit config exists) remains `"babel"`. Rspack always defaults to `"swc"`.
836
859
 
837
- Please note that if you want opt-in to use SWC, you can skip [React](#react) integration instructions as it is supported out of the box.
860
+ Please note that SWC supports [React](#react) integration out of the box - no additional configuration needed.
838
861
 
839
862
  ### esbuild loader configuration
840
863
 
841
- You can try out experimental integration with the esbuild-loader. You can read more at [esbuild-loader usage docs](./docs/using_esbuild_loader.md).
864
+ You can use esbuild as an alternative JavaScript transpiler. You can read more at [esbuild-loader usage docs](./docs/using_esbuild_loader.md).
842
865
 
843
- Please note that if you want opt-in to use esbuild-loader, you can skip [React](#react) integration instructions as it is supported out of the box.
866
+ Please note that esbuild supports [React](#react) integration out of the box - no additional configuration needed.
844
867
 
845
868
  ### Switching between transpilers
846
869
 
@@ -1092,13 +1115,13 @@ Otherwise, Shakapacker will use the production environment as a fallback environ
1092
1115
  For example, the below command will compile assets in production mode but will use staging configurations from `config/shakapacker.yml` if available or use fallback production environment configuration:
1093
1116
 
1094
1117
  ```bash
1095
- RAILS_ENV=staging bundle exec rails assets:precompile
1118
+ RAILS_ENV=staging bundle exec rake assets:precompile
1096
1119
  ```
1097
1120
 
1098
1121
  And, this will compile in development mode and load configuration for the cucumber environment if defined in `shakapacker.yml` or fallback to production configuration
1099
1122
 
1100
1123
  ```bash
1101
- RAILS_ENV=cucumber NODE_ENV=development bundle exec rails assets:precompile
1124
+ RAILS_ENV=cucumber NODE_ENV=development bundle exec rake assets:precompile
1102
1125
  ```
1103
1126
 
1104
1127
  Please note, binstubs compiles in development mode however rake tasks compiles in production mode.
@@ -1109,8 +1132,8 @@ Please note, binstubs compiles in development mode however rake tasks compiles i
1109
1132
  ./bin/shakapacker-dev-server
1110
1133
 
1111
1134
  # Compiles in production mode by default unless NODE_ENV is specified, per `lib/tasks/shakapacker/compile.rake`
1112
- bundle exec rails assets:precompile
1113
- bundle exec rails shakapacker:compile
1135
+ bundle exec rake assets:precompile
1136
+ bundle exec rake shakapacker:compile
1114
1137
  ```
1115
1138
 
1116
1139
  ### Upgrading
@@ -1122,7 +1145,7 @@ You can run the following commands to upgrade Shakapacker to the latest stable v
1122
1145
  bundle update shakapacker
1123
1146
 
1124
1147
  # overwrite your changes to the default install files and revert any unwanted changes from the install
1125
- rails shakapacker:install
1148
+ bundle exec rake shakapacker:install
1126
1149
 
1127
1150
  # using npm
1128
1151
  npm install shakapacker@latest
@@ -1269,7 +1292,7 @@ For detailed CDN setup instructions, including CloudFlare configuration, trouble
1269
1292
 
1270
1293
  ```bash
1271
1294
  export SHAKAPACKER_ASSET_HOST=https://cdn.example.com
1272
- RAILS_ENV=production bundle exec rails assets:precompile
1295
+ RAILS_ENV=production bundle exec rake assets:precompile
1273
1296
  ```
1274
1297
 
1275
1298
  For more deployment documentation, see [Deployment](./docs/deployment.md).
@@ -1323,3 +1346,10 @@ The following companies support our Open Source projects, and ShakaCode uses the
1323
1346
  <a href="https://www.honeybadger.io">
1324
1347
  <img src="https://user-images.githubusercontent.com/4244251/184881133-79ee9c3c-8165-4852-958e-31687b9536f4.png" alt="Honeybadger" height="55px">
1325
1348
  </a>
1349
+ <a href="https://coderabbit.ai">
1350
+ <picture>
1351
+ <source media="(prefers-color-scheme: dark)" srcset="https://victorious-bubble-f69a016683.media.strapiapp.com/White_Typemark_7229870ac5.svg">
1352
+ <source media="(prefers-color-scheme: light)" srcset="https://victorious-bubble-f69a016683.media.strapiapp.com/Orange_Typemark_7958cfa790.svg">
1353
+ <img alt="CodeRabbit" src="https://victorious-bubble-f69a016683.media.strapiapp.com/Orange_Typemark_7958cfa790.svg" height="55px">
1354
+ </picture>
1355
+ </a>