From 33b95279565c8ba3fd4a8feccadc7cb24f0ff788 Mon Sep 17 00:00:00 2001 From: mcoops Date: Sat, 2 Oct 2021 15:05:34 +1000 Subject: [PATCH] npm: ignore anything that doesn't start with a digit --- deplist_test.go | 2 -- internal/scan/nodejs.go | 13 ++++++++++--- internal/utils/utils.go | 11 +++++++++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/deplist_test.go b/deplist_test.go index cf5cfe6..2b8f8a0 100644 --- a/deplist_test.go +++ b/deplist_test.go @@ -74,7 +74,6 @@ func BuildWant() []Dependency { "d3-timer", "d3-scale-chromatic", "d3-time-format", - "d3-array", "d3-axis", "d3-timer", "d3-ease", @@ -93,7 +92,6 @@ func BuildWant() []Dependency { "d3-time", "js-tokens", "d3-format", - "safer-buffer", "d3-contour", "d3-geo", "safer-buffer", diff --git a/internal/scan/nodejs.go b/internal/scan/nodejs.go index d0f02c2..5f15a04 100644 --- a/internal/scan/nodejs.go +++ b/internal/scan/nodejs.go @@ -6,6 +6,8 @@ import ( "os/exec" "path/filepath" "strings" + + "github.com/mcoops/deplist/internal/utils" ) type yarnDependencies []yarnDependency @@ -43,9 +45,14 @@ var gatheredNode map[string]NodeJSGather func recordPackage(packageName, version string) { // opposite now, we don't care if its specifying version ranges like 5.x.x, // or 5.* etc. Just get the versions. - if len(version) > 0 && - (version[0] == '^' || version[0] == '~' || version[0] == '*' || version[len(version)-1] == 'x') { - return + if len(version) > 0 { + if !utils.CharIsDigit(version) { + return + } + + if version[len(version)-1] == 'x' { + return + } } if _, ok := gatheredNode[packageName+version]; !ok { diff --git a/internal/utils/utils.go b/internal/utils/utils.go index b049666..7232dab 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -15,3 +15,14 @@ func BelongsToIgnoreList(needle string) bool { } return false } + +func CharIsDigit(c string) bool { + if len(c) == 0 { + return false + } + + if c[0] < '0' || c[0] > '9' { + return false + } + return true +}