Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Commit

Permalink
npm: ignore anything that doesn't start with a digit (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcoops authored Oct 3, 2021
1 parent e0f21b3 commit 84b19bb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
2 changes: 0 additions & 2 deletions deplist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ func BuildWant() []Dependency {
"d3-timer",
"d3-scale-chromatic",
"d3-time-format",
"d3-array",
"d3-axis",
"d3-timer",
"d3-ease",
Expand All @@ -93,7 +92,6 @@ func BuildWant() []Dependency {
"d3-time",
"js-tokens",
"d3-format",
"safer-buffer",
"d3-contour",
"d3-geo",
"safer-buffer",
Expand Down
12 changes: 9 additions & 3 deletions internal/scan/nodejs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path/filepath"
"strings"

"github.com/mcoops/deplist/internal/utils"
log "github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -45,9 +46,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 {
Expand Down
11 changes: 11 additions & 0 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 84b19bb

Please sign in to comment.