Skip to content

Commit 64d14e8

Browse files
justin808claude
andcommitted
Make generator template precompile hook use shared implementation when available
Update the generator template to intelligently use the shared precompile hook implementation when running in the gem's development/test context, while maintaining a self-contained fallback for generated user applications. This provides the best of both worlds: - Test dummy apps and generator template all use the same shared code - Generated user apps have a standalone copy that works independently - Easier to maintain and update the precompile hook logic The hook now tries to load the shared implementation from the gem first, and falls back to its inline implementation if the gem isn't available or accessible. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 641132c commit 64d14e8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@
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)
1430
require "fileutils"
1531

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

0 commit comments

Comments
 (0)