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

Inherits:
Object
  • Object
show all
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.



11
12
13
14
15
# File 'lib/dependabot/npm_and_yarn/update_checker/dependency_files_builder.rb', line 11

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

Instance Method Details

#lockfilesObject



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

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

#package_filesObject



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

def package_files
  @package_files ||=
    dependency_files
    .select { |f| f.name.end_with?("package.json") }
end

#package_locksObject



34
35
36
37
38
# File 'lib/dependabot/npm_and_yarn/update_checker/dependency_files_builder.rb', line 34

def package_locks
  @package_locks ||=
    dependency_files
    .select { |f| f.name.end_with?("package-lock.json") }
end

#pnpm_locksObject



46
47
48
49
50
# File 'lib/dependabot/npm_and_yarn/update_checker/dependency_files_builder.rb', line 46

def pnpm_locks
  @pnpm_locks ||=
    dependency_files
    .select { |f| f.name.end_with?("pnpm-lock.yaml") }
end

#root_pnpm_lockObject



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

def root_pnpm_lock
  @root_pnpm_lock ||=
    dependency_files
    .find { |f| f.name == "pnpm-lock.yaml" }
end

#root_yarn_lockObject



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

def root_yarn_lock
  @root_yarn_lock ||=
    dependency_files
    .find { |f| f.name == "yarn.lock" }
end

#shrinkwrapsObject



64
65
66
67
68
# File 'lib/dependabot/npm_and_yarn/update_checker/dependency_files_builder.rb', line 64

def shrinkwraps
  @shrinkwraps ||=
    dependency_files
    .select { |f| f.name.end_with?("npm-shrinkwrap.json") }
end

#write_temporary_dependency_filesObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/dependabot/npm_and_yarn/update_checker/dependency_files_builder.rb', line 17

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



40
41
42
43
44
# File 'lib/dependabot/npm_and_yarn/update_checker/dependency_files_builder.rb', line 40

def yarn_locks
  @yarn_locks ||=
    dependency_files
    .select { |f| f.name.end_with?("yarn.lock") }
end