Commit 5186da7
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]>1 parent 3182910 commit 5186da7
1 file changed
+96
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
24 | 118 | | |
25 | 119 | | |
26 | 120 | | |
| |||
0 commit comments