lib/jets/builders/ruby_packager.rb in jets-1.5.8 vs lib/jets/builders/ruby_packager.rb in jets-1.5.9

- old
+ new

@@ -56,10 +56,12 @@ "cd #{cache_area} && " \ "env BUNDLE_IGNORE_CONFIG=1 bundle install --path #{cache_area}/vendor/gems --without development test" ) end + remove_bundled_with("#{cache_area}/Gemfile.lock") + # Copy the Gemfile.lock back to the project in case it was updated. # For example we add the jets-rails to the Gemfile. copy_back_gemfile_lock puts 'Bundle install success.' @@ -97,10 +99,12 @@ def clean_old_submodules # https://stackoverflow.com/questions/38800129/parsing-a-gemfile-lock-with-bundler lockfile = "#{cache_area}/Gemfile.lock" return unless File.exist?(lockfile) + return if Bundler.bundler_major_version <= 1 # LockfileParser only works for Bundler version 2+ + parser = Bundler::LockfileParser.new(Bundler.read_file(lockfile)) specs = parser.specs # specs = Bundler.load.specs # IE: spec.source.to_s: "https://github.com/tongueroo/webpacker.git (at jets@a8c4661)" @@ -129,23 +133,24 @@ FileUtils.mkdir_p(cache_area) FileUtils.cp("#{full_project_path}/Gemfile", "#{cache_area}/Gemfile") gemfile_lock = "#{full_project_path}/Gemfile.lock" dest = "#{cache_area}/Gemfile.lock" - FileUtils.cp(gemfile_lock, dest) if File.exist?(gemfile_lock) - adjust_gemfile_lock(dest) + return unless File.exist?(gemfile_lock) + + FileUtils.cp(gemfile_lock, dest) end # Remove the BUNDLED WITH line since we don't control the bundler gem version on AWS Lambda # And this can cause issues with require 'bundler/setup' - def adjust_gemfile_lock(path) - lines = IO.readlines(path) + def remove_bundled_with(gemfile_lock) + lines = IO.readlines(gemfile_lock) n = lines.index { |l| l.include?("BUNDLED WITH") } return unless n new_lines = lines[0..n-1] content = new_lines.join('') - IO.write(path, content) + IO.write(gemfile_lock, content) end def setup_bundle_config ensure_build_cache_bundle_config_exists!