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

Commit

Permalink
Merge pull request #2 from ashishvishal7810gmailcom/npm-fix
Browse files Browse the repository at this point in the history
npm-fix
  • Loading branch information
ashishvishal1 authored Oct 19, 2022
2 parents 83b9bc8 + 2281758 commit 109433c
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions pkg/modules/npm/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,19 @@ func (m *npm) buildDependencies(path string, deps map[string]interface{}) ([]mod
depName := strings.TrimPrefix(key, "@")
for nkey := range dd {
var mod models.Module
d := dd[nkey].(map[string]interface{})
mod.Version = strings.TrimSpace(strings.TrimPrefix(strings.TrimPrefix(strings.TrimPrefix(strings.TrimPrefix(nkey, "^"), "~"), ">"), "="))
mod.Version = strings.Split(mod.Version, " ")[0]
mod.Name = depName

r := ""
if d["resolved"] != nil {
r = d["resolved"].(string)
mod.PackageDownloadLocation = r
if _, ok := dd[nkey].(map[string]interface{}); ok {
d := dd[nkey].(map[string]interface{})
if d["resolved"] != nil {
r = d["resolved"].(string)
mod.PackageDownloadLocation = r
}
}

if mod.PackageDownloadLocation == "" {
r := "https://www.npmjs.com/package/%s/v/%s"
mod.PackageDownloadLocation = fmt.Sprintf(r, mod.Name, mod.Version)
Expand Down Expand Up @@ -369,7 +372,12 @@ func appendDependencies(d interface{}, allDeps map[string]map[string]interface{}
if m == nil {
m = make(map[string]interface{})
}
m[dv.(map[string]interface{})["version"].(string)] = dv.(map[string]interface{})

if _, ok := dv.(string); ok {
m[dv.(string)] = dv.(string)
} else {
m[dv.(map[string]interface{})["version"].(string)] = dv.(map[string]interface{})
}
allDeps[dk] = m
}
}
Expand Down

0 comments on commit 109433c

Please sign in to comment.