You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix bin/dev pack generation in Bundler context (#1907)
* Fix bin/dev pack generation failure when run from Bundler context
When bin/dev runs in a Bundler context, calling `bundle exec rake` can fail
or cause issues. This change detects when we're already inside a Bundler
context and runs the Rake task directly instead of shelling out.
Key improvements:
- Detects Bundler context and runs tasks directly
- Falls back to bundle exec when not in Bundler context
- Properly handles silent mode for both execution paths
- Loads Rails environment when needed
This fixes pack generation failures when using bin/dev.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
* Add rails_available? check to prevent nil Rails.application
The previous implementation didn't check if Rails.application was available
before calling load_tasks, which caused test failures. This adds the
rails_available? method to check if Rails is properly initialized.
Also updates run_rake_task_directly to use task.reenable for better
re-execution support.
Fixes RSpec test failures in pack_generator_spec.rb
* Improve pack generator robustness and error handling
Based on code review feedback, this commit addresses several critical issues:
1. **Better Bundler context detection**: Now checks ENV['BUNDLE_GEMFILE']
for more robust detection of meaningful Bundler contexts
2. **Enhanced Rails availability checking**: Safely verifies Rails.application
can actually load tasks, with proper error handling
3. **Consistent error handling**: Errors are always written to stderr,
even in silent mode. Backtrace included when DEBUG env var is set
4. **Reduced code complexity**: Refactored run_rake_task_directly into
smaller, focused methods (load_rake_tasks, prepare_rake_task,
capture_output, handle_rake_error) to satisfy RuboCop complexity checks
5. **Maintained test compatibility**: Tests continue to pass because the
code properly falls back to bundle exec in test environment where
BUNDLE_GEMFILE is not set
These changes ensure:
- Tests work correctly (they mock system calls which are used in test env)
- Production bin/dev usage is optimized (direct Rake execution when safe)
- Error messages are never silently swallowed
- More robust detection of execution context
---------
Co-authored-by: Claude <[email protected]>
0 commit comments