Skip to content

Commit

Permalink
Fix package name handling to retain version and strip ‘@’ suffix
Browse files Browse the repository at this point in the history
Signed-off-by: Emin Aktas <[email protected]>
  • Loading branch information
eminaktas committed Jan 9, 2025
1 parent 995ee5a commit 8ca624b
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions pkg/build/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ func unify(originals []string, inputs []resolved) (map[string][]string, map[stri
if idx := strings.IndexAny(orig, "=<>~"); idx >= 0 {
name = orig[:idx]
}
// Strip @ and the rest from the package name, e.g. foo@bar -> foo
if idx := strings.Index(orig, "@"); idx >= 0 {
name = orig[:idx]
}
originalPackages.packages.Insert(name)
originalPackages.versions[name] = strings.TrimPrefix(orig, name)
}
Expand Down Expand Up @@ -235,7 +239,12 @@ func unify(originals []string, inputs []resolved) (map[string][]string, map[stri
// Append all of the resolved and unified packages with an exact match
// based on the resolved version we found.
for _, pkg := range sets.List(acc.packages) {
pl = append(pl, fmt.Sprintf("%s=%s", pkg, acc.versions[pkg]))
pkgName := fmt.Sprintf("%s=%s", pkg, acc.versions[pkg])
// Add back the version if that is stripped before
if originalPackages.versions[pkg] != "" {
pkgName = pkgName + originalPackages.versions[pkg]
}
pl = append(pl, pkgName)
}
// Sort the package list explicitly with the `=` included.
// This is because (foo, foo-bar) sorts differently than (foo=1, foo-bar=1)
Expand All @@ -249,7 +258,12 @@ func unify(originals []string, inputs []resolved) (map[string][]string, map[stri
for _, input := range inputs {
pl := make([]string, 0, len(input.packages))
for _, pkg := range sets.List(input.packages) {
pl = append(pl, fmt.Sprintf("%s=%s", pkg, input.versions[pkg]))
pkgName := fmt.Sprintf("%s=%s", pkg, input.versions[pkg])
// Add back the version if that is stripped before
if originalPackages.versions[pkg] != "" {
pkgName = pkgName + originalPackages.versions[pkg]
}
pl = append(pl, pkgName)
}
// Sort the package list explicitly with the `=` included.
// This is because (foo, foo-bar) sorts differently than (foo=1, foo-bar=1)
Expand Down

0 comments on commit 8ca624b

Please sign in to comment.