Skip to content

Commit fc024b6

Browse files
justin808claude
andcommitted
Move shared precompile hook to spec/support and simplify generator template
Address feedback to properly organize the precompile hook code: 1. Move shared implementation to spec/support/ (test-only location) - Renamed: lib/tasks/precompile/shakapacker_precompile_hook_shared.rb - To: spec/support/shakapacker_precompile_hook_shared.rb - This makes it clear the shared code is only for test dummy apps 2. Simplify generator template to be standalone - Remove logic to load shared implementation from gem - Generator template is for newly created production apps - Should be simple, self-contained, and production-ready - No references to development/testing concerns 3. Update test dummy apps to reference new location - spec/dummy/bin/shakapacker-precompile-hook - react_on_rails_pro/spec/dummy/bin/shakapacker-precompile-hook - Both now load from spec/support/ The generator template is now clean and focused on production use cases, while test dummy apps share common implementation from the test support directory. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 64d14e8 commit fc024b6

File tree

4 files changed

+6
-22
lines changed

4 files changed

+6
-22
lines changed

lib/generators/react_on_rails/templates/base/base/bin/shakapacker-precompile-hook

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,6 @@
1111
#
1212
# See: https://github.com/shakacode/shakapacker/blob/main/docs/precompile_hook.md
1313

14-
# Try to use shared implementation from gem if available (during development/testing)
15-
# This allows the gem's test apps and generated apps to share the same implementation
16-
begin
17-
require "react_on_rails"
18-
gem_root = Gem.loaded_specs["react_on_rails"]&.gem_dir
19-
shared_hook = File.join(gem_root, "lib", "tasks", "precompile", "shakapacker_precompile_hook_shared.rb") if gem_root
20-
21-
if shared_hook && File.exist?(shared_hook)
22-
load shared_hook
23-
exit 0
24-
end
25-
rescue LoadError, StandardError
26-
# If we can't load from gem, fall through to inline implementation
27-
end
28-
29-
# Inline implementation for generated apps (when gem source isn't available)
3014
require "fileutils"
3115

3216
# Find Rails root by walking upward looking for config/environment.rb

react_on_rails_pro/spec/dummy/bin/shakapacker-precompile-hook

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44
# Shakapacker precompile hook for React on Rails Pro test dummy app
55
#
6-
# This script loads the shared precompile hook implementation to avoid duplication.
7-
# The shared implementation is maintained in lib/tasks/precompile/shakapacker_precompile_hook_shared.rb
6+
# This script loads the shared test helper implementation.
7+
# For production apps, use the generator template which includes a standalone implementation.
88

99
# Find the gem root directory (four levels up from react_on_rails_pro/spec/dummy/bin)
1010
gem_root = File.expand_path("../../../..", __dir__)
11-
shared_hook = File.join(gem_root, "lib", "tasks", "precompile", "shakapacker_precompile_hook_shared.rb")
11+
shared_hook = File.join(gem_root, "spec", "support", "shakapacker_precompile_hook_shared.rb")
1212

1313
unless File.exist?(shared_hook)
1414
warn "❌ Error: Shared precompile hook not found at #{shared_hook}"

spec/dummy/bin/shakapacker-precompile-hook

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44
# Shakapacker precompile hook for React on Rails test dummy app
55
#
6-
# This script loads the shared precompile hook implementation to avoid duplication.
7-
# The shared implementation is maintained in lib/tasks/precompile/shakapacker_precompile_hook_shared.rb
6+
# This script loads the shared test helper implementation.
7+
# For production apps, use the generator template which includes a standalone implementation.
88

99
# Find the gem root directory (three levels up from spec/dummy/bin)
1010
gem_root = File.expand_path("../../..", __dir__)
11-
shared_hook = File.join(gem_root, "lib", "tasks", "precompile", "shakapacker_precompile_hook_shared.rb")
11+
shared_hook = File.join(gem_root, "spec", "support", "shakapacker_precompile_hook_shared.rb")
1212

1313
unless File.exist?(shared_hook)
1414
warn "❌ Error: Shared precompile hook not found at #{shared_hook}"

0 commit comments

Comments
 (0)