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



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



102
103
104
# File 'lib/dependabot/npm_and_yarn/update_checker/dependency_files_builder.rb', line 102

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

#package_filesObject



107
108
109
110
111
112
113
# File 'lib/dependabot/npm_and_yarn/update_checker/dependency_files_builder.rb', line 107

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



48
49
50
51
52
53
54
# File 'lib/dependabot/npm_and_yarn/update_checker/dependency_files_builder.rb', line 48

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



66
67
68
69
70
71
72
# File 'lib/dependabot/npm_and_yarn/update_checker/dependency_files_builder.rb', line 66

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



84
85
86
87
88
89
90
# File 'lib/dependabot/npm_and_yarn/update_checker/dependency_files_builder.rb', line 84

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



75
76
77
78
79
80
81
# File 'lib/dependabot/npm_and_yarn/update_checker/dependency_files_builder.rb', line 75

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

#shrinkwrapsObject



93
94
95
96
97
98
99
# File 'lib/dependabot/npm_and_yarn/update_checker/dependency_files_builder.rb', line 93

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
# 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)
    File.write(".yarnrc.yml", yarnrc_yml_content) if yarnrc_yml_file
  else
    File.write(".npmrc", npmrc_content)
    File.write(".yarnrc", yarnrc_content) if yarnrc_specifies_private_reg?
  end

  package_files.each do |file|
    path = file.name
    FileUtils.mkdir_p(Pathname.new(path).dirname)
    File.write(file.name, prepared_package_json_content(file))
  end
end

#yarn_locksObject



57
58
59
60
61
62
63
# File 'lib/dependabot/npm_and_yarn/update_checker/dependency_files_builder.rb', line 57

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