Skip to content

Commit

Permalink
Merge pull request #9754 from dependabot/jamiemagee/npm-version-resol…
Browse files Browse the repository at this point in the history
…ver-true-type

True type `Dependabot::NpmAndYarn::UpdateChecker::VersionResolver`
  • Loading branch information
GarryHurleyJr authored May 20, 2024
2 parents 3ed63ea + e1c0635 commit 1cd86b5
Showing 1 changed file with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# typed: false
# typed: true
# frozen_string_literal: true

require "sorbet-runtime"

require "dependabot/errors"
require "dependabot/git_commit_checker"
require "dependabot/logger"
Expand All @@ -21,6 +23,8 @@ module Dependabot
module NpmAndYarn
class UpdateChecker
class VersionResolver
extend T::Sig

require_relative "latest_version_finder"

TIGHTLY_COUPLED_MONOREPOS = {
Expand Down Expand Up @@ -162,6 +166,7 @@ def dependency_updates_from_full_unlock

private

sig { returns(Dependabot::Dependency) }
attr_reader :dependency
attr_reader :credentials
attr_reader :dependency_files
Expand Down Expand Up @@ -356,39 +361,42 @@ def fetch_peer_dependency_errors(version:)
[]
end

# rubocop:disable Metrics/AbcSize
sig { params(message: String).returns(T::Array[T::Hash[String, T.nilable(String)]]) }
def handle_peer_dependency_errors(message)
errors = []
if message.match?(NPM6_PEER_DEP_ERROR_REGEX)
message.scan(NPM6_PEER_DEP_ERROR_REGEX) do
errors << Regexp.last_match.named_captures
errors << Regexp.last_match&.named_captures
end
elsif message.match?(NPM8_PEER_DEP_ERROR_REGEX)
message.scan(NPM8_PEER_DEP_ERROR_REGEX) do
errors << Regexp.last_match.named_captures
errors << T.must(Regexp.last_match).named_captures
end
elsif message.match?(YARN_PEER_DEP_ERROR_REGEX)
message.scan(YARN_PEER_DEP_ERROR_REGEX) do
errors << Regexp.last_match.named_captures
errors << T.must(Regexp.last_match).named_captures
end
elsif message.match?(YARN_BERRY_PEER_DEP_ERROR_REGEX)
message.scan(YARN_BERRY_PEER_DEP_ERROR_REGEX) do
errors << Regexp.last_match.named_captures
errors << T.must(Regexp.last_match).named_captures
end
elsif message.match?(YARN_BERRY_V4_PEER_DEP_ERROR_REGEX)
message.scan(YARN_BERRY_V4_PEER_DEP_ERROR_REGEX) do
errors << Regexp.last_match.named_captures
errors << T.must(Regexp.last_match).named_captures
end
elsif message.match?(PNPM_PEER_DEP_ERROR_REGEX)
message.scan(PNPM_PEER_DEP_ERROR_REGEX) do
captures = Regexp.last_match.named_captures
captures["requiring_dep"].tr!(" ", "@")
captures = T.must(Regexp.last_match).named_captures
T.must(captures["requiring_dep"]).tr!(" ", "@")
errors << captures
end
else
raise
end
errors
end
# rubocop:enable Metrics/AbcSize

def unmet_peer_dependencies
peer_dependency_errors
Expand Down Expand Up @@ -650,7 +658,7 @@ def version_install_arg(version:)
git_source = dependency.requirements.find { |req| req[:source] && req[:source][:type] == "git" }

if git_source
"#{dependency.name}@#{git_req[:source][:url]}##{version}"
"#{dependency.name}@#{git_source[:source][:url]}##{version}"
else
"#{dependency.name}@#{version}"
end
Expand Down Expand Up @@ -715,7 +723,7 @@ def requirement_class
end

def version_regex
version_class::VERSION_PATTERN
Dependabot::NpmAndYarn::Version::VERSION_PATTERN
end
end
end
Expand Down

0 comments on commit 1cd86b5

Please sign in to comment.