Class: Dependabot::NpmAndYarn::UpdateChecker::SubdependencyVersionResolver

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/npm_and_yarn/update_checker/subdependency_version_resolver.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dependency:, credentials:, dependency_files:, ignored_versions:, latest_allowable_version:, repo_contents_path:) ⇒ SubdependencyVersionResolver

Returns a new instance of SubdependencyVersionResolver.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/dependabot/npm_and_yarn/update_checker/subdependency_version_resolver.rb', line 51

def initialize(
  dependency:,
  credentials:,
  dependency_files:,
  ignored_versions:,
  latest_allowable_version:,
  repo_contents_path:
)
  @dependency = dependency
  @credentials = credentials
  @dependency_files = dependency_files
  @ignored_versions = ignored_versions
  @latest_allowable_version = latest_allowable_version
  @repo_contents_path = repo_contents_path
end

Instance Attribute Details

#credentialsObject (readonly)

Returns the value of attribute credentials.



27
28
29
# File 'lib/dependabot/npm_and_yarn/update_checker/subdependency_version_resolver.rb', line 27

def credentials
  @credentials
end

#dependencyObject (readonly)

Returns the value of attribute dependency.



24
25
26
# File 'lib/dependabot/npm_and_yarn/update_checker/subdependency_version_resolver.rb', line 24

def dependency
  @dependency
end

#dependency_filesObject (readonly)

Returns the value of attribute dependency_files.



30
31
32
# File 'lib/dependabot/npm_and_yarn/update_checker/subdependency_version_resolver.rb', line 30

def dependency_files
  @dependency_files
end

#ignored_versionsObject (readonly)

Returns the value of attribute ignored_versions.



33
34
35
# File 'lib/dependabot/npm_and_yarn/update_checker/subdependency_version_resolver.rb', line 33

def ignored_versions
  @ignored_versions
end

#latest_allowable_versionObject (readonly)

Returns the value of attribute latest_allowable_version.



36
37
38
# File 'lib/dependabot/npm_and_yarn/update_checker/subdependency_version_resolver.rb', line 36

def latest_allowable_version
  @latest_allowable_version
end

#repo_contents_pathObject (readonly)

Returns the value of attribute repo_contents_path.



39
40
41
# File 'lib/dependabot/npm_and_yarn/update_checker/subdependency_version_resolver.rb', line 39

def repo_contents_path
  @repo_contents_path
end

Instance Method Details

#latest_resolvable_versionObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/dependabot/npm_and_yarn/update_checker/subdependency_version_resolver.rb', line 68

def latest_resolvable_version
  raise "Not a subdependency!" if dependency.requirements.any?
  return if bundled_dependency?

  base_dir = T.must(dependency_files.first).directory
  SharedHelpers.in_a_temporary_repo_directory(base_dir, repo_contents_path) do
    dependency_files_builder.write_temporary_dependency_files

    updated_lockfiles = filtered_lockfiles.map do |lockfile|
      updated_content = update_subdependency_in_lockfile(lockfile)
      updated_lockfile = lockfile.dup
      updated_lockfile.content = updated_content
      updated_lockfile
    end

    version_from_updated_lockfiles(updated_lockfiles)
  end
rescue SharedHelpers::HelperSubprocessFailed
  # TODO: Move error handling logic from the FileUpdater to this class

  # Return nil (no update possible) if an unknown error occurred
  nil
end