Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
feat(analyzer): add dependency deduplication
Browse files Browse the repository at this point in the history
  • Loading branch information
temsa committed Aug 6, 2018
1 parent 1183949 commit df9bdcf
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@ func runWalkers(path string, walkers []nodepackage.Walker) ([]nodepackage.NodePa
return nil, nil
}

func packagesCleanupAndDeduplication(packageList []nodepackage.NodePackage) []nodepackage.NodePackage {
packageMap := make(map[string]nodepackage.NodePackage)
for _, pkg := range packageList {
if pkg.Name == "" {
log.Print("Ignoring package with empty name")
continue
}
if pkg.Version == "" {
pkg.Version = "*"
}
packageMap[pkg.Name+"@"+pkg.Version] = pkg
}

var packages []nodepackage.NodePackage
for _, pkg := range packageMap {
packages = append(packages, pkg)
}
return packages
}

// Analyze analyzes a path to an installed (npm install) node package
func Analyze(path string, walkers ...nodepackage.Walker) (vulnfetcher.VulnerabilityReport, error) {
fmt.Println("Will scan folder <", path, ">")
Expand All @@ -61,17 +81,7 @@ func Analyze(path string, walkers ...nodepackage.Walker) (vulnfetcher.Vulnerabil
}

// keep only valid packages
var packages []nodepackage.NodePackage
for _, pkg := range packageList {
if pkg.Name == "" {
log.Print("Ignoring package with empty name")
continue
}
if pkg.Version == "" {
pkg.Version = "*"
}
packages = append(packages, pkg)
}
packages := packagesCleanupAndDeduplication(packageList)

ossFetcher := ossvulnfetcher.New(OSSIndexURL)
err = ossFetcher.Fetch()
Expand Down

0 comments on commit df9bdcf

Please sign in to comment.