shakapacker 9.3.4 → 9.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 20f8244a121f25f9c018754007b3588d99e4860677cc8ef4e2f8b55858edbd57
4
- data.tar.gz: 4e5d80d804e55cfbce44d9139e70ea7f60d8709e92f1f07c95391e7e128a7e8e
3
+ metadata.gz: 4a0519c935e0e3d98204aeaeec6cc35b57fa13be1fe8a6f62e5e6cd5124d09c7
4
+ data.tar.gz: 7f6fe4134fd9b17de2dcd26b5c9e80f1f41d2019dfa0ed337092c1d23a9aa077
5
5
  SHA512:
6
- metadata.gz: 02e7f011c8b6d839672e485146221a2e76f014926f4226a4394720837d56a9b646bd4d5732cbf48c0a3639b5067fcbc597c2fd44a3cc7bb2b77242a6d5ecaf41
7
- data.tar.gz: f0510466924af335241216dc70e021ab26942012d3cdaf735fcd1bfa34d4b1ad615a4a9e7906ca5d348c519dde308a26fc46a34d0a54ebcdb9518ae3265ca209
6
+ metadata.gz: 8789ef5d5cf102254f27c0833b3a7bd8239b5b97d2dfa97ac79fb01827931397dc71dd35f82971a61354a1751f6dafd80d91a322e51b6390f83132f17a786626
7
+ data.tar.gz: 3a6cff63ba261b9cec55cdd683e7cfa96a24e52b753639643bf2f6874ed49c0f50a990a771a85c4265e9e6394a8fc7e8b4e3440ed5d62982f89b98cddadf9450
data/CHANGELOG.md CHANGED
@@ -11,6 +11,10 @@
11
11
 
12
12
  Changes since the last non-beta release.
13
13
 
14
+ ### Added
15
+
16
+ - **Added `SHAKAPACKER_SKIP_PRECOMPILE_HOOK` environment variable to skip precompile hook**. [PR #XXX](https://github.com/shakacode/shakapacker/pull/XXX) by [justin808](https://github.com/justin808). Set `SHAKAPACKER_SKIP_PRECOMPILE_HOOK=true` to skip the precompile hook during compilation. This is useful when using process managers like Foreman or Overmind to run the hook once before starting multiple webpack processes, preventing duplicate hook execution. **Migration tip:** If you have a custom `bin/dev` script that starts multiple webpack processes, you can now run the precompile hook once in the script and set this environment variable to prevent each webpack process from running the hook again. See the [precompile hook documentation](./docs/precompile_hook.md#skipping-the-hook) for implementation examples.
17
+
14
18
  ## [v9.3.4-beta.0] - November 17, 2025
15
19
 
16
20
  ### Fixed
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shakapacker (9.3.4)
4
+ shakapacker (9.4.0)
5
5
  activesupport (>= 5.2)
6
6
  package_json
7
7
  rack-proxy (>= 0.6.1)
@@ -284,6 +284,104 @@ default:
284
284
 
285
285
  ## Advanced Usage
286
286
 
287
+ ### Skipping the Hook
288
+
289
+ You can skip the precompile hook using the `SHAKAPACKER_SKIP_PRECOMPILE_HOOK` environment variable:
290
+
291
+ ```bash
292
+ SHAKAPACKER_SKIP_PRECOMPILE_HOOK=true bin/shakapacker
293
+ ```
294
+
295
+ **Important:** The environment variable must be set to the exact string `"true"` to skip the hook. Any other value (including `"false"`, `"1"`, or empty string) will run the hook normally.
296
+
297
+ This is useful when:
298
+
299
+ - Using `bin/dev` or Foreman to run the hook once before starting multiple webpack processes
300
+ - Running the hook manually and then compiling multiple times
301
+ - Debugging compilation issues without the hook
302
+
303
+ **Note:** The examples below show how to implement this in your custom `bin/dev` script. If you're using React on Rails, the generated `bin/dev` script already implements this pattern automatically - it runs the precompile hook once before launching processes, then sets `SHAKAPACKER_SKIP_PRECOMPILE_HOOK=true` to prevent duplicate execution.
304
+
305
+ **Recommended: Use Procfile env prefix**
306
+
307
+ The cleanest approach is to set the environment variable per-process in your Procfile:
308
+
309
+ ```procfile
310
+ # Procfile.dev
311
+ web: env SHAKAPACKER_SKIP_PRECOMPILE_HOOK=true bin/rails server
312
+ webpack-client: env SHAKAPACKER_SKIP_PRECOMPILE_HOOK=true bin/shakapacker --watch
313
+ webpack-server: env SHAKAPACKER_SKIP_PRECOMPILE_HOOK=true bin/shakapacker --watch --config-name server
314
+ ```
315
+
316
+ Then your `bin/dev` can run the hook once and launch the process manager:
317
+
318
+ ```bash
319
+ #!/usr/bin/env bash
320
+ # bin/dev
321
+
322
+ # Run the hook once before launching all processes
323
+ bundle exec ruby -r ./config/boot -e "
324
+ hook = Shakapacker.config.precompile_hook
325
+ if hook
326
+ puts \"Running precompile hook: #{hook}\"
327
+ system(hook) or exit(1)
328
+ end
329
+ "
330
+
331
+ exec foreman start -f Procfile.dev
332
+ # or: exec overmind start -f Procfile.dev
333
+ ```
334
+
335
+ **Alternative: Export environment variable**
336
+
337
+ You can export the environment variable before starting your process manager:
338
+
339
+ ```bash
340
+ #!/usr/bin/env bash
341
+ # bin/dev
342
+
343
+ # Run the hook once before launching all processes
344
+ bundle exec ruby -r ./config/boot -e "
345
+ hook = Shakapacker.config.precompile_hook
346
+ if hook
347
+ puts \"Running precompile hook: #{hook}\"
348
+ system(hook) or exit(1)
349
+ end
350
+ "
351
+
352
+ # Export skip flag for all subprocesses
353
+ export SHAKAPACKER_SKIP_PRECOMPILE_HOOK=true
354
+
355
+ exec foreman start -f Procfile.dev
356
+ # or: exec overmind start -f Procfile.dev
357
+ ```
358
+
359
+ **Alternative: Use .env.local (not tracked by git)**
360
+
361
+ For Foreman or Overmind, you can create a `.env.local` file (typically gitignored):
362
+
363
+ ```bash
364
+ #!/usr/bin/env bash
365
+ # bin/dev
366
+
367
+ # Run the hook once before launching all processes
368
+ bundle exec ruby -r ./config/boot -e "
369
+ hook = Shakapacker.config.precompile_hook
370
+ if hook
371
+ puts \"Running precompile hook: #{hook}\"
372
+ system(hook) or exit(1)
373
+ end
374
+ "
375
+
376
+ # Create .env.local for process manager subprocesses
377
+ echo "SHAKAPACKER_SKIP_PRECOMPILE_HOOK=true" > .env.local
378
+
379
+ exec foreman start -f Procfile.dev
380
+ # or: exec overmind start -f Procfile.dev
381
+ ```
382
+
383
+ This pattern ensures the hook runs once when development starts, not separately for each webpack process.
384
+
287
385
  ### Conditional Execution
288
386
 
289
387
  ```bash
@@ -27,7 +27,7 @@ class Shakapacker::Compiler
27
27
  true
28
28
  else
29
29
  acquire_ipc_lock do
30
- run_precompile_hook if config.precompile_hook
30
+ run_precompile_hook if should_run_precompile_hook?
31
31
  run_webpack.tap do |success|
32
32
  after_compile_hook
33
33
  end
@@ -80,6 +80,13 @@ class Shakapacker::Compiler
80
80
  /ruby/.match?(first_line) ? RbConfig.ruby : ""
81
81
  end
82
82
 
83
+ def should_run_precompile_hook?
84
+ return false unless config.precompile_hook
85
+ return false if ENV["SHAKAPACKER_SKIP_PRECOMPILE_HOOK"] == "true"
86
+
87
+ true
88
+ end
89
+
83
90
  def run_precompile_hook
84
91
  hook_command = config.precompile_hook
85
92
  hook_spec = validate_precompile_hook(hook_command)
@@ -1,4 +1,4 @@
1
1
  module Shakapacker
2
2
  # Change the version in package.json too, please!
3
- VERSION = "9.3.4".freeze
3
+ VERSION = "9.4.0".freeze
4
4
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shakapacker",
3
- "version": "9.3.4",
3
+ "version": "9.4.0",
4
4
  "description": "Use webpack to manage app-like JavaScript modules in Rails",
5
5
  "homepage": "https://github.com/shakacode/shakapacker",
6
6
  "bugs": {
@@ -52,8 +52,12 @@ class Shakapacker::Compiler
52
52
 
53
53
  def bin_shakapacker_path: () -> Pathname
54
54
 
55
+ def should_run_precompile_hook?: () -> bool
56
+
55
57
  def run_precompile_hook: () -> void
56
58
 
59
+ def validate_precompile_hook: (String hook_command) -> Hash[Symbol, untyped]
60
+
57
61
  def run_webpack: () -> bool
58
62
 
59
63
  def webpack_env: () -> Hash[String, String]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shakapacker
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.3.4
4
+ version: 9.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
@@ -413,7 +413,7 @@ homepage: https://github.com/shakacode/shakapacker
413
413
  licenses:
414
414
  - MIT
415
415
  metadata:
416
- source_code_uri: https://github.com/shakacode/shakapacker/tree/v9.3.4
416
+ source_code_uri: https://github.com/shakacode/shakapacker/tree/v9.4.0
417
417
  rdoc_options: []
418
418
  require_paths:
419
419
  - lib