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

allow single quotes in preamble #8

Merged
merged 1 commit into from
Oct 6, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/bundler/multilock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def inject_preamble
Bundler.ui.debug("Injecting multilock preamble")

minor_version = Gem::Version.new(::Bundler::Multilock::VERSION).segments[0..1].join(".")
bundle_preamble1_match = %(plugin "bundler-multilock")
bundle_preamble1_match = /plugin ["']bundler-multilock["']/
bundle_preamble1 = <<~RUBY
plugin "bundler-multilock", "~> #{minor_version}"
RUBY
Expand Down Expand Up @@ -384,8 +384,10 @@ def reset!

private

def inject_specific_preamble(gemfile, gemfiles, injection_point, preamble, add_newline:, match: preamble)
return false if gemfiles.any? { |g| g.include?(match) }
def inject_specific_preamble(gemfile, gemfiles, injection_point, preamble, add_newline:, match: nil)
# allow either type of quotes
match ||= Regexp.new(Regexp.escape(preamble).gsub('"', %(["'])))
return false if gemfiles.any? { |g| match.match?(g) }

add_newline = false unless gemfile[injection_point - 1] == "\n"

Expand Down
24 changes: 24 additions & 0 deletions spec/bundler/multilock_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,30 @@
end
end

it "does not inject duplicate plugin load commands when you prefer single quotes" do
gemfile = <<~RUBY
# frozen_string_literal: true

source 'https://rubygems.org'

plugin 'bundler-multilock', '~> 1.0'
return unless Plugin.installed?('bundler-multilock')

Plugin.send(:load_plugin, 'bundler-multilock')

gem 'concurrent-ruby', '1.2.2'
RUBY

with_gemfile("") do
File.write("Gemfile", gemfile)

local_git = Shellwords.escape(File.expand_path("../..", __dir__))
invoke_bundler("plugin install bundler-multilock --local_git=#{local_git}")

expect(File.read("Gemfile")).to eq gemfile
end
end

it "does not inject when a secondary Gemfile has the necessary commands" do
with_gemfile("") do
File.write("Gemfile", <<~RUBY)
Expand Down