Skip to content

Commit 869a83f

Browse files
justin808claude
andcommitted
Fix pack generation in bin/dev by preventing Bundler auto-exec interception
When running bin/dev, pack generation was failing with "Could not find command 'react_on_rails:generate_packs'" because Bundler was intercepting the system call and trying to execute it as a gem executable command instead of passing it through to rake. The fix wraps the bundle exec subprocess call with Bundler.with_unbundled_env to prevent Bundler from intercepting when already running inside a Bundler context. Added with_unbundled_context helper method that supports both new (with_unbundled_env) and legacy (with_clean_env) Bundler APIs for backwards compatibility. Fixes #2084 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent e2ca31a commit 869a83f

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

lib/react_on_rails/dev/pack_generator.rb

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,34 @@ def handle_rake_error(error, _silent)
141141
end
142142

143143
def run_via_bundle_exec(silent: false)
144-
if silent
145-
system(
146-
"bundle", "exec", "rake", "react_on_rails:generate_packs",
147-
out: File::NULL, err: File::NULL
148-
)
144+
# Need to unbundle to prevent Bundler from intercepting our bundle exec call
145+
# when already running inside a Bundler context (e.g., from bin/dev)
146+
with_unbundled_context do
147+
if silent
148+
system(
149+
"bundle", "exec", "rake", "react_on_rails:generate_packs",
150+
out: File::NULL, err: File::NULL
151+
)
152+
else
153+
system("bundle", "exec", "rake", "react_on_rails:generate_packs")
154+
end
155+
end
156+
end
157+
158+
# DRY helper method for Bundler context switching with API compatibility
159+
# Supports both new (with_unbundled_env) and legacy (with_clean_env) Bundler APIs
160+
def with_unbundled_context(&block)
161+
if defined?(Bundler)
162+
if Bundler.respond_to?(:with_unbundled_env)
163+
Bundler.with_unbundled_env(&block)
164+
elsif Bundler.respond_to?(:with_clean_env)
165+
Bundler.with_clean_env(&block)
166+
else
167+
# Fallback if neither method is available (very old Bundler versions)
168+
yield
169+
end
149170
else
150-
system("bundle", "exec", "rake", "react_on_rails:generate_packs")
171+
yield
151172
end
152173
end
153174
end

0 commit comments

Comments
 (0)