Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEEP-11079 fix infinite loop when package link from package-lock.json… #23

Merged
merged 1 commit into from
Aug 19, 2024
Merged
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
15 changes: 12 additions & 3 deletions pkg/nodejs/npm/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,18 @@ func (p *Parser) parseV2(packages map[string]Package) ([]types.Library, []types.
// node_modules/func1 -> link to target
// see `package-lock_v3_with_workspace.json` to better understanding
func resolveLinks(packages map[string]Package) {
links := lo.PickBy(packages, func(_ string, pkg Package) bool {
return pkg.Link
links := lo.PickBy(packages, func(pkgPath string, pkg Package) bool {
if !pkg.Link {
return false
}
if pkg.Resolved == "" {
log.Logger.Warnf("`package-lock.json` contains broken link with empty `resolved` field. %s package will be skipped to avoid receiving an empty package", pkgPath)
delete(packages, pkgPath)
return false
}
return true
})

// Early return
if len(links) == 0 {
return
Expand All @@ -190,7 +199,7 @@ func resolveLinks(packages map[string]Package) {
}

workspaces := rootPkg.Workspaces
for pkgPath, pkg := range packages {
for pkgPath, pkg := range maps.Clone(packages) {
for linkPath, link := range links {
if !strings.HasPrefix(pkgPath, link.Resolved) {
continue
Expand Down
Loading