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

npm: ignore anything that doesn't start with a digit #45

Merged
merged 2 commits into from
Oct 3, 2021
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
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
}