From 0ac3502dd6a9ed8c43608023c0c73b4f136e23ec Mon Sep 17 00:00:00 2001 From: williamfzc <178894043@qq.com> Date: Wed, 23 Aug 2023 19:40:21 +0800 Subject: [PATCH] fix: miss `Root` field in npm/yarn/pnpm --- npm/handler.go | 1 + pnpm/handler.go | 7 +++++++ yarn/handler.go | 1 + 3 files changed, 9 insertions(+) diff --git a/npm/handler.go b/npm/handler.go index c357384..67964e3 100644 --- a/npm/handler.go +++ b/npm/handler.go @@ -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", diff --git a/pnpm/handler.go b/pnpm/handler.go index 73d3109..59ae290 100644 --- a/pnpm/handler.go +++ b/pnpm/handler.go @@ -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) @@ -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_@babel+core@7.15.0 + // Remove parentheses and content inside parts := strings.Split(pkg, "(") pkg = parts[0] diff --git a/yarn/handler.go b/yarn/handler.go index b113958..0ec72af 100644 --- a/yarn/handler.go +++ b/yarn/handler.go @@ -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)