class Dependabot::NpmAndYarn::FileUpdater
Public Class Methods
updated_files_regex()
click to toggle source
# File lib/dependabot/npm_and_yarn/file_updater.rb, line 26 def self.updated_files_regex [ /^package\.json$/, /^package-lock\.json$/, /^npm-shrinkwrap\.json$/, /^yarn\.lock$/ ] end
Public Instance Methods
updated_dependency_files()
click to toggle source
# File lib/dependabot/npm_and_yarn/file_updater.rb, line 35 def updated_dependency_files updated_files = [] updated_files += updated_manifest_files updated_files += updated_lockfiles if updated_files.none? raise NoChangeError.new( message: "No files were updated!", error_context: error_context(updated_files: updated_files) ) end sorted_updated_files = updated_files.sort_by(&:name) if sorted_updated_files == filtered_dependency_files.sort_by(&:name) raise NoChangeError.new( message: "Updated files are unchanged!", error_context: error_context(updated_files: updated_files) ) end updated_files end
Private Instance Methods
check_required_files()
click to toggle source
# File lib/dependabot/npm_and_yarn/file_updater.rb, line 76 def check_required_files raise "No package.json!" unless get_original_file("package.json") end
error_context(updated_files:)
click to toggle source
# File lib/dependabot/npm_and_yarn/file_updater.rb, line 80 def error_context(updated_files:) { dependencies: dependencies.map(&:to_h), updated_files: updated_files.map(&:name), dependency_files: dependency_files.map(&:name) } end
filtered_dependency_files()
click to toggle source
# File lib/dependabot/npm_and_yarn/file_updater.rb, line 61 def filtered_dependency_files @filtered_dependency_files ||= if dependencies.select(&:top_level?).any? DependencyFilesFilterer.new( dependency_files: dependency_files, updated_dependencies: dependencies ).files_requiring_update else SubDependencyFilesFilterer.new( dependency_files: dependency_files, updated_dependencies: dependencies ).files_requiring_update end end
package_files()
click to toggle source
# File lib/dependabot/npm_and_yarn/file_updater.rb, line 106 def package_files @package_files ||= filtered_dependency_files.select do |f| f.name.end_with?("package.json") end end
package_lock_changed?(package_lock)
click to toggle source
# File lib/dependabot/npm_and_yarn/file_updater.rb, line 117 def package_lock_changed?(package_lock) package_lock.content != updated_lockfile_content(package_lock) end
package_locks()
click to toggle source
# File lib/dependabot/npm_and_yarn/file_updater.rb, line 88 def package_locks @package_locks ||= filtered_dependency_files. select { |f| f.name.end_with?("package-lock.json") } end
shrinkwrap_changed?(shrinkwrap)
click to toggle source
# File lib/dependabot/npm_and_yarn/file_updater.rb, line 121 def shrinkwrap_changed?(shrinkwrap) shrinkwrap.content != updated_lockfile_content(shrinkwrap) end
shrinkwraps()
click to toggle source
# File lib/dependabot/npm_and_yarn/file_updater.rb, line 100 def shrinkwraps @shrinkwraps ||= filtered_dependency_files. select { |f| f.name.end_with?("npm-shrinkwrap.json") } end
updated_lockfile_content(file)
click to toggle source
# File lib/dependabot/npm_and_yarn/file_updater.rb, line 182 def updated_lockfile_content(file) @updated_lockfile_content ||= {} @updated_lockfile_content[file.name] ||= NpmLockfileUpdater.new( lockfile: file, dependencies: dependencies, dependency_files: dependency_files, credentials: credentials ).updated_lockfile.content end
updated_lockfiles()
click to toggle source
# File lib/dependabot/npm_and_yarn/file_updater.rb, line 134 def updated_lockfiles updated_files = [] yarn_locks.each do |yarn_lock| next unless yarn_lock_changed?(yarn_lock) updated_files << updated_file( file: yarn_lock, content: updated_yarn_lock_content(yarn_lock) ) end package_locks.each do |package_lock| next unless package_lock_changed?(package_lock) updated_files << updated_file( file: package_lock, content: updated_lockfile_content(package_lock) ) end shrinkwraps.each do |shrinkwrap| next unless shrinkwrap_changed?(shrinkwrap) updated_files << updated_file( file: shrinkwrap, content: updated_lockfile_content(shrinkwrap) ) end updated_files end
updated_manifest_files()
click to toggle source
# File lib/dependabot/npm_and_yarn/file_updater.rb, line 125 def updated_manifest_files package_files.map do |file| updated_content = updated_package_json_content(file) next if updated_content == file.content updated_file(file: file, content: updated_content) end.compact end
updated_package_json_content(file)
click to toggle source
# File lib/dependabot/npm_and_yarn/file_updater.rb, line 193 def updated_package_json_content(file) @updated_package_json_content ||= {} @updated_package_json_content[file.name] ||= PackageJsonUpdater.new( package_json: file, dependencies: dependencies ).updated_package_json.content end
updated_yarn_lock_content(yarn_lock)
click to toggle source
# File lib/dependabot/npm_and_yarn/file_updater.rb, line 167 def updated_yarn_lock_content(yarn_lock) @updated_yarn_lock_content ||= {} @updated_yarn_lock_content[yarn_lock.name] ||= yarn_lockfile_updater.updated_yarn_lock_content(yarn_lock) end
yarn_lock_changed?(yarn_lock)
click to toggle source
# File lib/dependabot/npm_and_yarn/file_updater.rb, line 113 def yarn_lock_changed?(yarn_lock) yarn_lock.content != updated_yarn_lock_content(yarn_lock) end
yarn_lockfile_updater()
click to toggle source
# File lib/dependabot/npm_and_yarn/file_updater.rb, line 173 def yarn_lockfile_updater @yarn_lockfile_updater ||= YarnLockfileUpdater.new( dependencies: dependencies, dependency_files: dependency_files, credentials: credentials ) end
yarn_locks()
click to toggle source
# File lib/dependabot/npm_and_yarn/file_updater.rb, line 94 def yarn_locks @yarn_locks ||= filtered_dependency_files. select { |f| f.name.end_with?("yarn.lock") } end