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

Add support for NPM V6 deprecation warning and unsupported error #11112

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
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
12 changes: 8 additions & 4 deletions npm_and_yarn/lib/dependabot/npm_and_yarn/package_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,13 @@ class NpmPackageManager < Ecosystem::VersionManager

# Keep versions in ascending order
SUPPORTED_VERSIONS = T.let([
Version.new(NPM_V6),
Version.new(NPM_V7),
Version.new(NPM_V8),
Version.new(NPM_V9),
Version.new(NPM_V10)
].freeze, T::Array[Dependabot::Version])

DEPRECATED_VERSIONS = T.let([].freeze, T::Array[Dependabot::Version])
DEPRECATED_VERSIONS = T.let([Version.new(NPM_V6)].freeze, T::Array[Dependabot::Version])

sig do
params(
Expand All @@ -89,12 +88,17 @@ def initialize(raw_version, requirement: nil)

sig { override.returns(T::Boolean) }
def deprecated?
false
return false if unsupported?
return false unless Dependabot::Experiments.enabled?(:npm_v6_deprecation_warning)

deprecated_versions.include?(version)
end

sig { override.returns(T::Boolean) }
def unsupported?
false
return false unless Dependabot::Experiments.enabled?(:npm_v6_unsupported_error)

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,54 @@
it "returns false" do
expect(package_manager.deprecated?).to be false
end

context "with feature flag npm_v6_deprecation_warning" do
before do
allow(Dependabot::Experiments).to receive(:enabled?)
.with(:npm_v6_deprecation_warning)
.and_return(deprecation_enabled)
allow(Dependabot::Experiments).to receive(:enabled?)
.with(:npm_v6_unsupported_error)
.and_return(unsupported_enabled)
end

context "when npm_v6_deprecation_warning is enabled and version is deprecated" do
let(:deprecation_enabled) { true }
let(:unsupported_enabled) { false }

it "returns true" do
expect(package_manager.deprecated?).to be true
end
end

context "when npm_v6_deprecation_warning is enabled but version is not deprecated" do
let(:version) { "9" }
let(:deprecation_enabled) { true }
let(:unsupported_enabled) { false }

it "returns false" do
expect(package_manager.deprecated?).to be false
end
end

context "when npm_v6_deprecation_warning is disabled" do
let(:deprecation_enabled) { false }
let(:unsupported_enabled) { false }

it "returns false" do
expect(package_manager.deprecated?).to be false
end
end

context "when version is unsupported" do
let(:deprecation_enabled) { true }
let(:unsupported_enabled) { true }

it "returns false, as unsupported takes precedence" do
expect(package_manager.deprecated?).to be false
end
end
end
end

describe "#unsupported?" do
Expand All @@ -46,5 +94,65 @@
it "returns false for supported versions" do
expect(package_manager.unsupported?).to be false
end

context "with feature flag npm_v6_unsupported_error" do
before do
allow(Dependabot::Experiments).to receive(:enabled?)
.with(:npm_v6_unsupported_error)
.and_return(unsupported_enabled)
end

context "when npm_v6_unsupported_error is enabled and version is unsupported" do
let(:version) { "6" }
let(:unsupported_enabled) { true }

it "returns true" do
expect(package_manager.unsupported?).to be true
end
end

context "when npm_v6_unsupported_error is enabled but version is supported" do
let(:version) { "7" }
let(:unsupported_enabled) { true }

it "returns false" do
expect(package_manager.unsupported?).to be false
end
end

context "when npm_v6_unsupported_error is disabled" do
let(:unsupported_enabled) { false }

it "returns false" do
expect(package_manager.unsupported?).to be false
end
end
end
end

describe "#raise_if_unsupported!" do
before do
allow(Dependabot::Experiments).to receive(:enabled?)
.with(:npm_v6_unsupported_error)
.and_return(unsupported_enabled)
end

context "when npm_v6_unsupported_error is enabled and version is unsupported" do
let(:version) { "6" }
let(:unsupported_enabled) { true }

it "raises a ToolVersionNotSupported error" do
expect { package_manager.raise_if_unsupported! }.to raise_error(Dependabot::ToolVersionNotSupported)
end
end

context "when npm_v6_unsupported_error is disabled" do
let(:version) { "6" }
let(:unsupported_enabled) { false }

it "does not raise an error" do
expect { package_manager.raise_if_unsupported! }.not_to raise_error
end
end
end
end
Loading