Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

True type Dependabot::NpmAndYarn::UpdateChecker::VersionResolver #9754

Merged
merged 1 commit into from
May 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
JamieMagee marked this conversation as resolved.
Show resolved Hide resolved
"#{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
JamieMagee marked this conversation as resolved.
Show resolved Hide resolved
end
end
Expand Down
Loading