@@ -4,6 +4,7 @@ import RefreshIcon from 'react-icons/lib/md/refresh';
4
4
import ArrowDropDown from 'react-icons/lib/md/keyboard-arrow-down' ;
5
5
import ArrowDropUp from 'react-icons/lib/md/keyboard-arrow-up' ;
6
6
import algoliasearch from 'algoliasearch' ;
7
+ import compareVersions from 'compare-versions' ;
7
8
import Tooltip from '@codesandbox/common/lib/components/Tooltip' ;
8
9
9
10
import { EntryContainer , IconArea , Icon } from '../../elements' ;
@@ -77,8 +78,15 @@ export default class VersionEntry extends React.PureComponent {
77
78
) ;
78
79
const index = client . initIndex ( 'npm-search' ) ;
79
80
index . search ( { query : dependency , hitsPerPage : 1 } , ( err , { hits } ) => {
81
+ const versions = Object . keys ( hits [ 0 ] . versions ) . sort ( ( a , b ) => {
82
+ try {
83
+ return compareVersions ( b , a ) ;
84
+ } catch ( e ) {
85
+ return 0 ;
86
+ }
87
+ } ) ;
80
88
this . setState ( {
81
- versions : hits [ 0 ] . versions ,
89
+ versions,
82
90
} ) ;
83
91
} ) ;
84
92
@@ -137,13 +145,9 @@ export default class VersionEntry extends React.PureComponent {
137
145
this . setState ( { hovering : false } ) ;
138
146
} }
139
147
>
140
- { Object . keys ( versions )
141
- . filter ( v => v < dependencies [ dependency ] )
142
- . map ( a => < option > { a } </ option > ) }
143
- < option selected > { dependencies [ dependency ] } </ option >
144
- { Object . keys ( versions )
145
- . filter ( v => v > dependencies [ dependency ] )
146
- . map ( a => < option > { a } </ option > ) }
148
+ { versions . map ( a => (
149
+ < option selected = { a === dependencies [ dependency ] } > { a } </ option >
150
+ ) ) }
147
151
</ VersionSelect >
148
152
) : (
149
153
< Version withSize = { ! ! size . size } hovering = { hovering } >
0 commit comments