Skip to content

Commit d110e35

Browse files
ihabadhamclaude
andcommitted
Refactor Gemfile.loader to use instance_eval for proper __dir__ resolution
Changed eval() to instance_eval(content, filepath) which preserves __dir__ in evaluated content (matching Bundler's internal eval_gemfile pattern). This allows eval_gemfile calls to work correctly inside loaded files, so shared dev dependencies can now be loaded from Gemfile.development_dependencies where they logically belong, instead of requiring a workaround in the main Gemfile. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent a04fa6a commit d110e35

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

react_on_rails_pro/Gemfile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,4 @@ source "https://rubygems.org"
55
# Specify your gem"s dependencies in react_on_rails.gemspec
66
gemspec
77

8-
# Shared dev dependencies must be loaded here (not in Gemfile.development_dependencies)
9-
# because Gemfile.loader uses eval() which breaks __dir__ resolution
10-
eval_gemfile File.expand_path("../Gemfile.shared_dev_dependencies", __dir__)
11-
128
eval_gemfile File.expand_path("./Gemfile.loader", __dir__)

react_on_rails_pro/Gemfile.development_dependencies

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
# Keep in sync with https://github.com/shakacode/react_on_rails/blob/master/Gemfile.development_dependencies
22
# frozen_string_literal: true
33

4-
# NOTE: Shared dev dependencies (rubocop, etc.) are loaded via eval_gemfile in
5-
# the main Gemfile, not here. This is because Gemfile.loader uses eval() which
6-
# breaks __dir__ resolution for eval_gemfile calls.
4+
# Shared dev dependencies (rubocop, etc.)
5+
eval_gemfile File.expand_path("../Gemfile.shared_dev_dependencies", __dir__)
76

87
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
98

react_on_rails_pro/Gemfile.loader

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
# frozen_string_literal: true
22

33
# Load base dependencies
4-
base_deps = File.read(File.expand_path("./Gemfile.development_dependencies", __dir__))
4+
base_deps_path = File.expand_path("./Gemfile.development_dependencies", __dir__)
5+
base_deps = File.read(base_deps_path)
56

67
# Determine which override file to use
7-
override_deps = if ENV["CI"] == "true" && File.exist?(File.expand_path("./Gemfile.ci", __dir__))
8+
override_deps_path = if ENV["CI"] == "true" && File.exist?(File.expand_path("./Gemfile.ci", __dir__))
89
# In CI environment, use CI dependencies
9-
File.read(File.expand_path("./Gemfile.ci", __dir__))
10+
File.expand_path("./Gemfile.ci", __dir__)
1011
elsif File.exist?(File.expand_path("./Gemfile.local", __dir__))
1112
# In non-CI environment, use local dependencies if they exist
12-
File.read(File.expand_path("./Gemfile.local", __dir__))
13-
else
14-
""
13+
File.expand_path("./Gemfile.local", __dir__)
1514
end
1615

16+
override_deps = override_deps_path ? File.read(override_deps_path) : ""
17+
1718
# Parse override gems
1819
override_gem_names = override_deps.scan(/^\s*gem\s+["']([^"']+)["']/).flatten
1920

@@ -26,7 +27,9 @@ end
2627
base_deps.gsub!(/^\s*$\n/, '')
2728

2829
# Evaluate the modified base dependencies
29-
eval(base_deps)
30+
# Using instance_eval with filepath preserves __dir__ in evaluated content,
31+
# allowing eval_gemfile calls to work correctly inside loaded files.
32+
instance_eval(base_deps, base_deps_path)
3033

3134
# Evaluate override dependencies if they exist
32-
eval(override_deps) unless override_deps.empty?
35+
instance_eval(override_deps, override_deps_path) unless override_deps.empty?

0 commit comments

Comments
 (0)