File tree Expand file tree Collapse file tree 1 file changed +17
-12
lines changed
src/components/versionSelector Expand file tree Collapse file tree 1 file changed +17
-12
lines changed Original file line number Diff line number Diff line change @@ -12,21 +12,26 @@ import styles from './style.module.scss';
1212import { VersionBanner } from '../versionBanner' ;
1313
1414function sortVersions ( versions : string [ ] ) {
15- return versions
16- . sort ( ( a , b ) => {
17- const aSegments = parseInt ( a . split ( '.' ) [ 0 ] , 10 ) ;
18- const bSegments = parseInt ( b . split ( '.' ) [ 0 ] , 10 ) ;
15+ return versions . sort ( ( a , b ) => {
16+ const aMajor = parseInt ( a . split ( '.' ) [ 0 ] , 10 ) ;
17+ const bMajor = parseInt ( b . split ( '.' ) [ 0 ] , 10 ) ;
1918
20- if ( isNaN ( aSegments ) || isNaN ( bSegments ) ) {
21- return a . localeCompare ( b ) ;
22- }
19+ if ( isNaN ( aMajor ) || isNaN ( bMajor ) ) {
20+ return a . localeCompare ( b ) ;
21+ }
2322
24- if ( aSegments < bSegments ) {
25- return - 1 ;
26- }
23+ if ( aMajor < bMajor ) {
2724 return 1 ;
28- } )
29- . reverse ( ) ;
25+ }
26+
27+ if ( aMajor === bMajor ) {
28+ // yes, this is flawed. But for now there's no case where we need to order
29+ // by minor or patch so I wanna avoid pulling in semver as a dependency
30+ return a . localeCompare ( b ) ;
31+ }
32+
33+ return - 1 ;
34+ } ) ;
3035}
3136
3237export function VersionSelector ( { versions, sdk} : { sdk : string ; versions : string [ ] } ) {
You can’t perform that action at this time.
0 commit comments