Skip to content

Commit

Permalink
refactor: remove broken package
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyLewen committed Jun 5, 2024
1 parent f24f455 commit 70a3287
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pkg/dependency/parser/nodejs/npm/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,16 @@ func (p *Parser) parseV2(packages map[string]Package) ([]ftypes.Package, []ftype
// node_modules/func1 -> link to target
// see `package-lock_v3_with_workspace.json` to better understanding
func (p *Parser) resolveLinks(packages map[string]Package) {
links := lo.PickBy(packages, func(_ string, pkg Package) bool {
// Checking pkg.Resolved is necessary to avoid memory leaks for corrupt package-lock.json files
return pkg.Link && pkg.Resolved != ""
links := lo.PickBy(packages, func(pkgPath string, pkg Package) bool {
if !pkg.Link {
return false
}
if pkg.Resolved == "" {
p.logger.Warn("`package-lock.json` contains broken link with empty `resolved` field. This package will be skipped to avoid receiving an empty package", log.String("pkg", pkgPath))
delete(packages, pkgPath)
return false
}
return true
})
// Early return
if len(links) == 0 {
Expand Down

0 comments on commit 70a3287

Please sign in to comment.