diff --git a/npm_and_yarn/lib/dependabot/npm_and_yarn/package_name.rb b/npm_and_yarn/lib/dependabot/npm_and_yarn/package_name.rb index 379b7903cff..e02ff10829c 100644 --- a/npm_and_yarn/lib/dependabot/npm_and_yarn/package_name.rb +++ b/npm_and_yarn/lib/dependabot/npm_and_yarn/package_name.rb @@ -3,17 +3,17 @@ module Dependabot module NpmAndYarn class PackageName - DEFINITELY_TYPED_SCOPE = /types/i.freeze - PACKAGE_NAME_REGEX = %r{ + PACKAGE_NAME_REGEX = %r{ \A # beginning of string (?=.{1,214}\z) # enforce length (1 - 214) (@(?[a-z0-9\-~][a-z0-9\-\._~]*)\/)? # capture 'scope' if present (?[a-z0-9\-~][a-z0-9\-._~]*) # capture package name \z # end of string }xi.freeze # multi-line/case-insensitive + TYPES_PACKAGE_NAME_REGEX = %r{ \A # beginning of string - @#{DEFINITELY_TYPED_SCOPE}\/ # starts with @types/ + @types\/ # starts with @types/ ((?.+)__)? # capture scope (?.+) # capture name \z # end of string @@ -81,7 +81,7 @@ def scoped? end def types_package? - DEFINITELY_TYPED_SCOPE.match?(@scope) + "types".casecmp?(@scope) end end end diff --git a/npm_and_yarn/spec/dependabot/npm_and_yarn/package_name_spec.rb b/npm_and_yarn/spec/dependabot/npm_and_yarn/package_name_spec.rb index 60a9cbb0ae9..0279a3d1b16 100644 --- a/npm_and_yarn/spec/dependabot/npm_and_yarn/package_name_spec.rb +++ b/npm_and_yarn/spec/dependabot/npm_and_yarn/package_name_spec.rb @@ -67,11 +67,9 @@ describe "#library_name" do it "returns nil if it is not a types package" do - jquery = "jquery" - - library_name = described_class.new(jquery).library_name - - expect(library_name).to be_nil + expect(described_class.new("jquery").library_name).to be_nil + expect(described_class.new("@babel/core").library_name).to be_nil + expect(described_class.new("@typescript-eslint/parser").library_name).to be_nil end it "returns the corresponding library for a types package" do