Skip to content

Commit

Permalink
fix npm_and_yarn issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kbukum1 committed Dec 27, 2024
1 parent 093a2ea commit 72d357e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
11 changes: 8 additions & 3 deletions npm_and_yarn/lib/dependabot/npm_and_yarn/package_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,22 @@ def initialize(detected_version, raw_version, requirement: nil)

sig { override.returns(T::Boolean) }
def deprecated?
return false unless detected_version

return false if unsupported?

return false unless Dependabot::Experiments.enabled?(:npm_v6_deprecation_warning)

deprecated_versions.include?(version)
deprecated_versions.include?(detected_version)
end

sig { override.returns(T::Boolean) }
def unsupported?
return false unless detected_version

return false unless Dependabot::Experiments.enabled?(:npm_v6_unsupported_error)

supported_versions.all? { |supported| supported > version }
supported_versions.all? { |supported| supported > detected_version }
end
end

Expand Down Expand Up @@ -477,7 +482,7 @@ def package_manager_by_name(name)
detected_version = Helpers.npm_version_numeric_latest(@lockfiles[:npm])
package_manager = package_manager_class.new(detected_version.to_s, nil)

return package_manager if package_manager.deprecated? || package_manager.unsupported?
return package_manager if package_manager.unsupported?
end

installed_version = installed_version(name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,15 @@
allow(Dependabot::Experiments).to receive(:enabled?)
.with(:npm_v6_unsupported_error)
.and_return(false)
allow(Dependabot::Experiments).to receive(:enabled?)
.with(:enable_shared_helpers_command_timeout)
.and_return(true)
end

it "returns the deprecated package manager" do
expect(package_manager.deprecated?).to be true
expect(package_manager.version.to_s).to eq "6"
expect(package_manager.detected_version.to_s).to eq "6"
expect(package_manager.version.to_s).to eq "9.6.5"
end
end

Expand Down Expand Up @@ -206,7 +210,8 @@
end

it "returns the unsupported package manager" do
expect(package_manager.version.to_s).to eq "6"
expect(package_manager.detected_version.to_s).to eq "6"
expect(package_manager.version).to be_nil
expect(package_manager.unsupported?).to be true
end
end
Expand Down Expand Up @@ -253,7 +258,7 @@
end

it "returns the deprecated version" do
expect(package_manager.version.to_s).to eq "6"
expect(package_manager.detected_version.to_s).to eq "6"
end
end
end
Expand Down

0 comments on commit 72d357e

Please sign in to comment.