Commit 73dacca
Add Shakapacker precompile hook template for generator (#1916)
* Add Shakapacker precompile hook support for auto pack generation
This change leverages Shakapacker's new precompile_hook feature to
automatically generate packs before webpack compilation, replacing the
need to manually modify assets:precompile tasks or bin/dev scripts.
Changes:
- Add bin/shakapacker-precompile-hook script to templates and spec/dummy
- Update shakapacker.yml to configure precompile_hook
- Add PackerUtils.shakapacker_precompile_hook_configured? method
- Skip generate_packs in configuration and PackGenerator when hook configured
- Update generator to copy hook script and make it executable
The precompile hook runs before webpack compilation and is properly
validated by Shakapacker to ensure it points to a file within the
project root.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
* Fix: Add execute permission to shakapacker-precompile-hook template
The template file needs execute permission to pass RuboCop's
Lint/ScriptPermission check.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
* Fix: Skip validation in precompile hook to prevent generator failures
The shakapacker-precompile-hook was causing generator failures because
it loads the Rails environment (which triggers version validation)
before the react-on-rails npm package is installed during initial setup.
This fix adds ENV["REACT_ON_RAILS_SKIP_VALIDATION"] = "true" at the start
of the hook script to skip version validation, since the hook runs as part
of the build process and doesn't need package version validation.
Fixes CI failures in generator tests where the hook was executed during
`rails generate react_on_rails:install` before packages were installed.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
* Fix: Disable yarn caching in examples workflow to prevent V8 crash
The examples.yml workflow was experiencing Node.js V8 crashes during
yarn cache dir commands, similar to the issue fixed in commit a1c71ea.
This commit applies the same fix - disabling yarn caching until the
upstream V8 issue is resolved.
Error observed:
```
# Fatal error in , line 0
# unreachable code
```
Tracking: actions/setup-node#1028
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
* Fix: Remove duplicate precompile_hook key in shakapacker.yml
The spec/dummy/config/shakapacker.yml had two `precompile_hook` entries
which caused a YAML parsing error:
YAMLException: duplicated mapping key (31:3)
Removed the first instance at line 14, keeping the one with better
documentation at line 31.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
* Fix: Correct misleading security comment in shakapacker.yml
The comment claimed "The hook command will be validated to ensure it
points to a file within the project root" but no such validation exists
in the codebase. Updated the comment to accurately reflect that users
must ensure the hook path points to a trusted file they control.
This removes the false promise of automatic validation and places the
security responsibility appropriately on the user configuring the hook.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
* Fix: Correct precompile_hook detection to use top-level config key
The master's sophisticated hook detection was looking for the hook at
`:hooks/:precompile` but shakapacker.yml uses `precompile_hook` at the
top level. Updated `extract_precompile_hook` to look in the correct
location.
Also updated specs to match the sophisticated implementation that checks
if the hook actually contains the generate_packs rake task, rather than
just checking for any hook presence.
Fixes failing rspec-package-tests in CI.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
---------
Co-authored-by: Claude <[email protected]>1 parent bedee51 commit 73dacca
File tree
9 files changed
+246
-292
lines changed- .github/workflows
- lib
- generators/react_on_rails
- templates/base/base
- bin
- config
- react_on_rails
- dev
- spec
- dummy/config
- react_on_rails
- dev
9 files changed
+246
-292
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
70 | | - | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
71 | 73 | | |
72 | 74 | | |
73 | 75 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
| 41 | + | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
46 | 50 | | |
47 | 51 | | |
48 | 52 | | |
| |||
Lines changed: 30 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
45 | 50 | | |
46 | 51 | | |
47 | 52 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
248 | 248 | | |
249 | 249 | | |
250 | 250 | | |
251 | | - | |
| 251 | + | |
252 | 252 | | |
253 | 253 | | |
254 | 254 | | |
| |||
257 | 257 | | |
258 | 258 | | |
259 | 259 | | |
260 | | - | |
| 260 | + | |
261 | 261 | | |
262 | 262 | | |
263 | 263 | | |
264 | 264 | | |
265 | 265 | | |
266 | 266 | | |
267 | 267 | | |
268 | | - | |
| 268 | + | |
269 | 269 | | |
270 | 270 | | |
271 | 271 | | |
| |||
281 | 281 | | |
282 | 282 | | |
283 | 283 | | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
284 | 294 | | |
285 | 295 | | |
286 | 296 | | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
| 297 | + | |
294 | 298 | | |
295 | 299 | | |
296 | 300 | | |
| |||
409 | 413 | | |
410 | 414 | | |
411 | 415 | | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
412 | 429 | | |
413 | 430 | | |
414 | | - | |
415 | | - | |
416 | | - | |
417 | | - | |
418 | | - | |
419 | | - | |
420 | | - | |
| 431 | + | |
421 | 432 | | |
422 | 433 | | |
423 | 434 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
200 | | - | |
201 | | - | |
| 200 | + | |
| 201 | + | |
202 | 202 | | |
203 | 203 | | |
204 | 204 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | 11 | | |
16 | 12 | | |
17 | 13 | | |
| |||
24 | 20 | | |
25 | 21 | | |
26 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
0 commit comments