@@ -25,6 +25,7 @@ import (
25
25
"go.jetpack.io/devbox/internal/devpkg"
26
26
"go.jetpack.io/devbox/internal/devpkg/pkgtype"
27
27
"go.jetpack.io/devbox/internal/lock"
28
+ "go.jetpack.io/devbox/internal/searcher"
28
29
"go.jetpack.io/devbox/internal/setup"
29
30
"go.jetpack.io/devbox/internal/shellgen"
30
31
"go.jetpack.io/devbox/internal/telemetry"
@@ -43,6 +44,48 @@ const StateOutOfDateMessage = "Your devbox environment may be out of date. Run %
43
44
// packages.go has functions for adding, removing and getting info about nix
44
45
// packages
45
46
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
+
46
89
// Add adds the `pkgs` to the config (i.e. devbox.json) and nix profile for this
47
90
// devbox project
48
91
func (d * Devbox ) Add (ctx context.Context , pkgsNames []string , opts devopt.AddOpts ) error {
0 commit comments