Skip to content

Commit

Permalink
refactor: make ID calling consistent
Browse files Browse the repository at this point in the history
Signed-off-by: knqyf263 <[email protected]>
  • Loading branch information
knqyf263 committed Mar 8, 2024
1 parent fc60099 commit 0e025f9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
8 changes: 6 additions & 2 deletions pkg/dependency/parser/golang/mod/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (p *Parser) Parse(r xio.ReadSeekerAt) ([]types.Library, []types.Dependency,
continue
}
libs[require.Mod.Path] = types.Library{
ID: dependency.ID(ftypes.GoModule, require.Mod.Path, require.Mod.Version[1:]),
ID: packageID(require.Mod.Path, require.Mod.Version[1:]),
Name: require.Mod.Path,
Version: require.Mod.Version[1:],
Indirect: require.Indirect,
Expand Down Expand Up @@ -125,7 +125,7 @@ func (p *Parser) Parse(r xio.ReadSeekerAt) ([]types.Library, []types.Dependency,

// Add replaced library to library register.
libs[rep.New.Path] = types.Library{
ID: dependency.ID(ftypes.GoModule, rep.New.Path, rep.New.Version[1:]),
ID: packageID(rep.New.Path, rep.New.Version[1:]),
Name: rep.New.Path,
Version: rep.New.Version[1:],
Indirect: old.Indirect,
Expand Down Expand Up @@ -154,3 +154,7 @@ func lessThan117(ver string) bool {

return major <= 1 && minor < 17
}

func packageID(name, version string) string {
return dependency.ID(ftypes.GoModule, name, version)
}
12 changes: 6 additions & 6 deletions pkg/dependency/parser/nodejs/pnpm/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ func NewParser() types.Parser {
return &Parser{}
}

func (p *Parser) ID(name, version string) string {
return dependency.ID(ftypes.Pnpm, name, version)
}

func (p *Parser) Parse(r xio.ReadSeekerAt) ([]types.Library, []types.Dependency, error) {
var lockFile LockFile
if err := yaml.NewDecoder(r).Decode(&lockFile); err != nil {
Expand Down Expand Up @@ -82,11 +78,11 @@ func (p *Parser) parse(lockVer float64, lockFile LockFile) ([]types.Library, []t
if name == "" {
name, version = parsePackage(depPath, lockVer)
}
pkgID := p.ID(name, version)
pkgID := packageID(name, version)

dependencies := make([]string, 0, len(info.Dependencies))
for depName, depVer := range info.Dependencies {
dependencies = append(dependencies, p.ID(depName, depVer))
dependencies = append(dependencies, packageID(depName, depVer))
}

libs = append(libs, types.Library{
Expand Down Expand Up @@ -180,3 +176,7 @@ func parseDepPath(depPath, versionSep string) (string, string) {
}
return name, version
}

func packageID(name, version string) string {
return dependency.ID(ftypes.Pnpm, name, version)
}

0 comments on commit 0e025f9

Please sign in to comment.