Created
May 13, 2019 09:13
-
-
Save annikoff/b587999c9a9d2c4a0beeccdf01eb9740 to your computer and use it in GitHub Desktop.
Prevent specific gem from locking
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage example
gem 'my_extension', git: 'url_to_repo', skip_locking: true