Class: Dependabot::NpmAndYarn::UpdateChecker::DependencyFilesBuilder

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

Instance Method Summary collapse

Constructor Details

#initialize(dependency:, dependency_files:, credentials:) ⇒ DependencyFilesBuilder

Returns a new instance of DependencyFilesBuilder.



23
24
25
26
27
# File 'lib/dependabot/npm_and_yarn/update_checker/dependency_files_builder.rb', line 23

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

Instance Method Details

#lockfilesObject



105
106
107
# File 'lib/dependabot/npm_and_yarn/update_checker/dependency_files_builder.rb', line 105

def lockfiles
  [*package_locks, *shrinkwraps, *yarn_locks, *pnpm_locks]
end

#package_filesObject



110
111
112
113
114
115
116
# File 'lib/dependabot/npm_and_yarn/update_checker/dependency_files_builder.rb', line 110

def package_files
  @package_files ||= T.let(
    dependency_files
    .select { |f| f.name.end_with?("package.json") },
    T.nilable(T::Array[Dependabot::DependencyFile])
  )
end

#package_locksObject



51
52
53
54
55
56
57
# File 'lib/dependabot/npm_and_yarn/update_checker/dependency_files_builder.rb', line 51

def package_locks
  @package_locks ||= T.let(
    dependency_files
    .select { |f| f.name.end_with?("package-lock.json") },
    T.nilable(T::Array[Dependabot::DependencyFile])
  )
end

#pnpm_locksObject



69
70
71
72
73
74
75
# File 'lib/dependabot/npm_and_yarn/update_checker/dependency_files_builder.rb', line 69

def pnpm_locks
  @pnpm_locks ||= T.let(
    dependency_files
    .select { |f| f.name.end_with?("pnpm-lock.yaml") },
    T.nilable(T::Array[Dependabot::DependencyFile])
  )
end

#root_pnpm_lockObject



87
88
89
90
91
92
93
# File 'lib/dependabot/npm_and_yarn/update_checker/dependency_files_builder.rb', line 87

def root_pnpm_lock
  @root_pnpm_lock ||= T.let(
    dependency_files
    .find { |f| f.name == "pnpm-lock.yaml" },
    T.nilable(Dependabot::DependencyFile)
  )
end

#root_yarn_lockObject



78
79
80
81
82
83
84
# File 'lib/dependabot/npm_and_yarn/update_checker/dependency_files_builder.rb', line 78

def root_yarn_lock
  @root_yarn_lock ||= T.let(
    dependency_files
    .find { |f| f.name == "yarn.lock" },
    T.nilable(Dependabot::DependencyFile)
  )
end

#shrinkwrapsObject



96
97
98
99
100
101
102
# File 'lib/dependabot/npm_and_yarn/update_checker/dependency_files_builder.rb', line 96

def shrinkwraps
  @shrinkwraps ||= T.let(
    dependency_files
    .select { |f| f.name.end_with?("npm-shrinkwrap.json") },
    T.nilable(T::Array[Dependabot::DependencyFile])
  )
end

#write_temporary_dependency_filesObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/dependabot/npm_and_yarn/update_checker/dependency_files_builder.rb', line 30

def write_temporary_dependency_files
  write_lockfiles

  if Helpers.yarn_berry?(yarn_locks.first)
    if yarnrc_yml_file
      write_dependency_file(
        file: T.must(yarnrc_yml_file),
        content: T.must(yarnrc_yml_content)
      )
    end
  else
    File.write(".npmrc", npmrc_content)
    File.write(".yarnrc", yarnrc_content) if yarnrc_specifies_private_reg?
  end

  write_dependency_files(package_files) do |file|
    prepared_package_json_content(file)
  end
end

#yarn_locksObject



60
61
62
63
64
65
66
# File 'lib/dependabot/npm_and_yarn/update_checker/dependency_files_builder.rb', line 60

def yarn_locks
  @yarn_locks ||= T.let(
    dependency_files
    .select { |f| f.name.end_with?("yarn.lock") },
    T.nilable(T::Array[Dependabot::DependencyFile])
  )
end