Skip to content

Commit

Permalink
only re-sync the same lockfile when it _actually_ changed (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
ccutrer authored Oct 5, 2023
1 parent 2106daf commit 68891b2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/bundler/multilock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require_relative "multilock/ext/dsl"
require_relative "multilock/ext/plugin"
require_relative "multilock/ext/plugin/dsl"
require_relative "multilock/ext/shared_helpers"
require_relative "multilock/ext/source"
require_relative "multilock/ext/source_list"
require_relative "multilock/version"
Expand Down Expand Up @@ -427,7 +428,7 @@ def write_lockfile(lockfile_definition, lockfile, install:, dependency_changes:
end

resolved_remotely = false
begin
accesses = begin
previous_ui_level = Bundler.ui.level
Bundler.ui.level = "warn"
begin
Expand All @@ -438,7 +439,9 @@ def write_lockfile(lockfile_definition, lockfile, install:, dependency_changes:
definition.resolve_remotely!
resolved_remotely = true
end
definition.lock(lockfile_definition[:lockfile], true)
SharedHelpers.capture_filesystem_access do
definition.lock(lockfile_definition[:lockfile], true)
end
ensure
Bundler.ui.level = previous_ui_level
end
Expand All @@ -451,7 +454,7 @@ def write_lockfile(lockfile_definition, lockfile, install:, dependency_changes:
end
end

!definition.nothing_changed?
accesses && !accesses.empty?
end
end

Expand Down
28 changes: 28 additions & 0 deletions lib/bundler/multilock/ext/shared_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

module Bundler
module Multilock
module Ext
module SharedHeleprs
module ClassMethods
::Bundler::SharedHelpers.singleton_class.prepend(self)
::Bundler::SharedHelpers.instance_variable_set(:@filesystem_accesses, nil)

def capture_filesystem_access
@filesystem_accesses = []
yield
@filesystem_accesses
ensure
@filesystem_accesses = nil
end

def filesystem_access(path, action = :write)
@filesystem_accesses << [path, action] if @filesystem_accesses

super
end
end
end
end
end
end

0 comments on commit 68891b2

Please sign in to comment.