Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix development dependency not being added if introduced by two gemspecs #7358

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions bundler/lib/bundler/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ def gem(name, *args)

# if there's already a dependency with this name we try to prefer one
if current = @dependencies.find {|d| d.name == dep.name }
# Always prefer the dependency from the Gemfile
@dependencies.delete(current) if current.gemspec_dev_dep?

if current.requirement != dep.requirement
current_requirement_open = current.requirements_list.include?(">= 0")

Expand All @@ -116,8 +113,6 @@ def gem(name, *args)
Bundler.ui.warn "A gemspec development dependency (#{gemspec_dep.name}, #{gemspec_dep.requirement}) is being overridden by a Gemfile dependency (#{gemfile_dep.name}, #{gemfile_dep.requirement}).\n" \
"This behaviour may change in the future. Please remove either of them, or make sure they both have the same requirement\n"
end

return if dep.gemspec_dev_dep?
else
update_prompt = ""

Expand All @@ -135,8 +130,13 @@ def gem(name, *args)
"You specified: #{current.name} (#{current.requirement}) and #{dep.name} (#{dep.requirement})" \
"#{update_prompt}"
end
elsif current.gemspec_dev_dep? || dep.gemspec_dev_dep?
return if dep.gemspec_dev_dep?
end

# Always prefer the dependency from the Gemfile
if current.gemspec_dev_dep?
@dependencies.delete(current)
elsif dep.gemspec_dev_dep?
return
elsif current.source != dep.source
raise GemfileError, "You cannot specify the same gem twice coming from different sources.\n" \
"You specified that #{dep.name} (#{dep.requirement}) should come from " \
Expand Down
29 changes: 29 additions & 0 deletions bundler/spec/commands/install_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,35 @@
expect(the_bundle).to include_gems("rubocop 1.37.1")
end

it "includes the gem without warning if two gemspecs add it with the same requirement" do
gem1 = tmp.join("my-gem-1")
gem2 = tmp.join("my-gem-2")

build_lib "my-gem", path: gem1 do |s|
s.add_development_dependency "rubocop", "~> 1.36.0"
end

build_lib "my-gem-2", path: gem2 do |s|
s.add_development_dependency "rubocop", "~> 1.36.0"
end

build_repo4 do
build_gem "rubocop", "1.36.0"
end

gemfile <<~G
source "#{file_uri_for(gem_repo4)}"

gemspec path: "#{gem1}"
gemspec path: "#{gem2}"
G

bundle :install

expect(err).to be_empty
expect(the_bundle).to include_gems("rubocop 1.36.0")
end

it "warns when a Gemfile dependency is overriding a gemspec development dependency, with different requirements" do
build_lib "my-gem", path: bundled_app do |s|
s.add_development_dependency "rails", ">= 5"
Expand Down