Class: Dependabot::NpmAndYarn::FileUpdater::NpmLockfileUpdater

Inherits:
Object
  • Object
show all
Defined in:
lib/dependabot/npm_and_yarn/file_updater/npm_lockfile_updater.rb

Instance Method Summary collapse

Constructor Details

#initialize(dependencies:, dependency_files:, credentials:) ⇒ NpmLockfileUpdater

Returns a new instance of NpmLockfileUpdater.



18
19
20
21
22
# File 'lib/dependabot/npm_and_yarn/file_updater/npm_lockfile_updater.rb', line 18

def initialize(dependencies:, dependency_files:, credentials:)
  @dependencies = dependencies
  @dependency_files = dependency_files
  @credentials = credentials
end

Instance Method Details

#updated_lockfile_content(lockfile) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/dependabot/npm_and_yarn/file_updater/npm_lockfile_updater.rb', line 24

def updated_lockfile_content(lockfile)
  return lockfile.content if npmrc_disables_lockfile?
  return lockfile.content if updatable_dependencies(lockfile).empty?

  @updated_lockfile_content ||= {}
  @updated_lockfile_content[lockfile.name] ||=
    SharedHelpers.in_a_temporary_directory do
      path = Pathname.new(lockfile.name).dirname.to_s
      lockfile_name = Pathname.new(lockfile.name).basename.to_s
      write_temporary_dependency_files(lockfile.name)
      updated_files = Dir.chdir(path) do
        run_current_npm_update(lockfile_name: lockfile_name)
      end
      updated_content = updated_files.fetch(lockfile_name)
      post_process_npm_lockfile(lockfile.content, updated_content)
    end
rescue SharedHelpers::HelperSubprocessFailed => e
  handle_npm_updater_error(e, lockfile)
end