Skip to content

Commit 6f51900

Browse files
justin808claude
andcommitted
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]>
1 parent 57ddb2c commit 6f51900

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/react_on_rails/packer_utils.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ def self.extract_precompile_hook
197197
config_data = ::Shakapacker.config.send(:data)
198198

199199
# Try symbol keys first (Shakapacker's internal format), then fall back to string keys
200-
# Note: Currently only one hook value is supported, but this will change to support lists
201-
config_data&.dig(:hooks, :precompile) || config_data&.dig("hooks", "precompile")
200+
# The key is 'precompile_hook' at the top level of the config
201+
config_data&.[](:precompile_hook) || config_data&.[]("precompile_hook")
202202
end
203203

204204
def self.hook_contains_generate_packs?(hook_value)

spec/react_on_rails/packer_utils_spec.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,18 @@ module ReactOnRails
148148
end
149149

150150
context "when precompile_hook is configured" do
151-
it "returns true" do
152-
allow(mock_config).to receive(:send).with(:data).and_return({ precompile_hook: "bin/hook" })
151+
it "returns true when hook command contains generate_packs rake task" do
152+
hook_value = "bundle exec rake react_on_rails:generate_packs"
153+
allow(mock_config).to receive(:send).with(:data)
154+
.and_return({ precompile_hook: hook_value })
153155
expect(described_class.shakapacker_precompile_hook_configured?).to be true
154156
end
157+
158+
it "returns false when hook command doesn't contain generate_packs" do
159+
allow(mock_config).to receive(:send).with(:data)
160+
.and_return({ precompile_hook: "bin/some-other-command" })
161+
expect(described_class.shakapacker_precompile_hook_configured?).to be false
162+
end
155163
end
156164

157165
context "when precompile_hook is not configured" do

0 commit comments

Comments
 (0)