Skip to content

Commit

Permalink
fix: miss Root field in npm/yarn/pnpm
Browse files Browse the repository at this point in the history
  • Loading branch information
fengzhangchi committed Aug 23, 2023
1 parent 42e46f4 commit a8ef0e9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions npm/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ func (m *NPM) buildDependencies(path string, deps map[string]interface{}) ([]met
if err != nil {
return modules, err
}
de.Root = true
h := fmt.Sprintf("%x", sha256.Sum256([]byte(fmt.Sprintf("%s-%s", de.Name, de.Version))))
de.Checksum = meta.Checksum{
Algorithm: "SHA256",
Expand Down
7 changes: 7 additions & 0 deletions pnpm/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func (m *Pnpm) GetRootModule(path string) (*meta.Package, error) {
return &meta.Package{}, err
}
mod := &meta.Package{}
mod.Root = true

if pkResult["name"] != nil {
mod.Name = pkResult["name"].(string)
Expand Down Expand Up @@ -380,6 +381,12 @@ func extractVersion(s string) string {
}

func splitPackageNameAndVersion(pkg string) (string, string, string) {
// sample input
// 1. /@byted-cmf/data-plugin-indexeddb-storage-client/2.0.4_e239e53d72e8372ca29c63c7108bdc0f
// 2. /esprima/1.2.5
// 3. /@dp/sirius-view/3.7.131
// 4. /@babel/plugin-syntax-json-strings/7.8.3_@[email protected]

// Remove parentheses and content inside
parts := strings.Split(pkg, "(")
pkg = parts[0]
Expand Down
1 change: 1 addition & 0 deletions yarn/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func (m *Yarn) GetRootModule(path string) (*meta.Package, error) {
return &meta.Package{}, err
}
mod := &meta.Package{}
mod.Root = true

if pkResult["name"] != nil {
mod.Name = pkResult["name"].(string)
Expand Down

0 comments on commit a8ef0e9

Please sign in to comment.