@@ -25,6 +25,7 @@ import (
2525 "go.jetpack.io/devbox/internal/devpkg"
2626 "go.jetpack.io/devbox/internal/devpkg/pkgtype"
2727 "go.jetpack.io/devbox/internal/lock"
28+ "go.jetpack.io/devbox/internal/searcher"
2829 "go.jetpack.io/devbox/internal/setup"
2930 "go.jetpack.io/devbox/internal/shellgen"
3031 "go.jetpack.io/devbox/internal/telemetry"
@@ -43,6 +44,48 @@ const StateOutOfDateMessage = "Your devbox environment may be out of date. Run %
4344// packages.go has functions for adding, removing and getting info about nix
4445// packages
4546
47+ type UpdateVersion struct {
48+ Current string
49+ Latest string
50+ }
51+
52+ // Outdated returns a map of package names to their available latest version.
53+ func (d * Devbox ) Outdated (ctx context.Context ) (map [string ]UpdateVersion , error ) {
54+ ctx , task := trace .NewTask (ctx , "devboxOutdated" )
55+ defer task .End ()
56+
57+ outdatedPackages := map [string ]UpdateVersion {}
58+
59+ for _ , pkg := range d .AllPackages () {
60+ if strings .HasSuffix (pkg .Versioned (), "latest" ) {
61+ continue
62+ }
63+
64+ result , err := searcher .Client ().Search (ctx , pkg .CanonicalName ())
65+ if err != nil {
66+ return nil , err
67+ }
68+
69+ for _ , p := range result .Packages {
70+ if p .Name == pkg .CanonicalName () {
71+ for _ , v := range p .Versions {
72+ vv , err := pkg .ResolvedVersion ()
73+ if err != nil {
74+ return nil , err
75+ }
76+
77+ if v .Version > vv {
78+ outdatedPackages [p .Name ] = UpdateVersion {Current : vv , Latest : v .Version }
79+ break
80+ }
81+ }
82+ }
83+ }
84+ }
85+
86+ return outdatedPackages , nil
87+ }
88+
4689// Add adds the `pkgs` to the config (i.e. devbox.json) and nix profile for this
4790// devbox project
4891func (d * Devbox ) Add (ctx context.Context , pkgsNames []string , opts devopt.AddOpts ) error {
0 commit comments