11import { window } from "vscode" ;
2+ import semver from "semver" ;
23import { logger } from "./logger" ;
34import { getConfig } from "./config" ;
45import { state } from "./state" ;
@@ -80,24 +81,25 @@ export class Releases {
8081 return false ;
8182 }
8283
83- const prereleaseEnabled = this . prereleaseEnabled ( ) ;
84+ const filteredReleases = this . all ( ) ;
8485
85- const idx = this . releases
86- . filter ( ( r ) => prereleaseEnabled || ! r . prerelease )
87- . findIndex ( ( r ) => r . tag_name === tag_name ) ;
88-
89- if ( idx === - 1 ) {
90- return true ;
86+ if ( filteredReleases . length === 0 ) {
87+ return false ;
9188 }
9289
93- if ( idx >= 3 ) {
94- return true ;
95- }
90+ // Get the latest version (first in the sorted array)
91+ const latestVersion = filteredReleases [ 0 ] . tag_name ;
92+
93+ // Use semantic version comparison to check if current version is outdated
94+ // A version is considered outdated if it's less than the latest version
95+ return semver . lt ( tag_name , latestVersion ) ;
9696 }
9797
9898 latestVersion ( ) : string | null {
99- if ( this . releases . length > 0 ) {
100- return this . releases [ 0 ] . tag_name ;
99+ const filteredReleases = this . all ( ) ;
100+
101+ if ( filteredReleases . length > 0 ) {
102+ return filteredReleases [ 0 ] . tag_name ;
101103 } else {
102104 return null ;
103105 }
@@ -165,12 +167,17 @@ async function fromGithub(): Promise<Release[]> {
165167
166168 const filteredAndSorted = releases
167169 . filter ( ( r ) => ! r . draft )
168- . sort (
169- ( a , b ) =>
170- new Date ( b . published_at ) . getTime ( ) - new Date ( a . published_at ) . getTime ( )
171- ) ;
170+ . sort ( ( a , b ) => {
171+ // Sort by semantic version (highest first), then by publication date as fallback
172+ const versionComparison = semver . rcompare ( a . tag_name , b . tag_name ) ;
173+ if ( versionComparison !== 0 ) {
174+ return versionComparison ;
175+ }
176+ // If versions are equal, sort by publication date (newest first)
177+ return new Date ( b . published_at ) . getTime ( ) - new Date ( a . published_at ) . getTime ( ) ;
178+ } ) ;
172179
173180 await setCache ( filteredAndSorted ) ;
174181
175182 return filteredAndSorted ;
176- }
183+ }
0 commit comments