Skip to content

Instantly share code, notes, and snippets.

@annikoff
Created May 13, 2019 09:13
Show Gist options
  • Save annikoff/b587999c9a9d2c4a0beeccdf01eb9740 to your computer and use it in GitHub Desktop.
Save annikoff/b587999c9a9d2c4a0beeccdf01eb9740 to your computer and use it in GitHub Desktop.
Prevent specific gem from locking
require 'bundler/lockfile_generator'
module GitPatch
def initialize(options)
@skip_locking = options['skip_locking'] === true
super
end
def skip_locking?
@skip_locking
end
end
module DependencyPatch
def initialize(name, version, options = {}, &blk)
@skip_locking = options["skip_locking"] === true
super
end
def skip_locking?
@skip_locking
end
end
module LockfileGeneratorPatch
def add_dependencies
out << "\nDEPENDENCIES\n"
handled = []
definition.dependencies.sort_by(&:to_s).each do |dep|
next if handled.include?(dep.name)
next if dep.skip_locking?
out << dep.to_lock
handled << dep.name
end
end
end
module SourceListPatch
def lock_sources
super.reject do |source|
source.respond_to?(:skip_locking?) && source.skip_locking?
end
end
end
Bundler::Dsl.class_eval do
Bundler::Source::Git.prepend GitPatch
Bundler::Dependency.prepend DependencyPatch
Bundler::LockfileGenerator.prepend LockfileGeneratorPatch
Bundler::SourceList.prepend SourceListPatch
valid_keys = VALID_KEYS
remove_const 'VALID_KEYS'
const_set 'VALID_KEYS', (valid_keys + ['skip_locking'])
end
@annikoff
Copy link
Author

Usage example gem 'my_extension', git: 'url_to_repo', skip_locking: true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment