diff --git a/npm_and_yarn/lib/dependabot/npm_and_yarn/package_manager.rb b/npm_and_yarn/lib/dependabot/npm_and_yarn/package_manager.rb index 32cda75a86..6e7bd062b5 100644 --- a/npm_and_yarn/lib/dependabot/npm_and_yarn/package_manager.rb +++ b/npm_and_yarn/lib/dependabot/npm_and_yarn/package_manager.rb @@ -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 @@ -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) diff --git a/npm_and_yarn/spec/dependabot/npm_and_yarn/package_manager_helper_spec.rb b/npm_and_yarn/spec/dependabot/npm_and_yarn/package_manager_helper_spec.rb index ded4733cb1..3101bff91e 100644 --- a/npm_and_yarn/spec/dependabot/npm_and_yarn/package_manager_helper_spec.rb +++ b/npm_and_yarn/spec/dependabot/npm_and_yarn/package_manager_helper_spec.rb @@ -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 @@ -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 @@ -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