@@ -4,6 +4,7 @@ import RefreshIcon from 'react-icons/lib/md/refresh';
44import ArrowDropDown from 'react-icons/lib/md/keyboard-arrow-down' ;
55import ArrowDropUp from 'react-icons/lib/md/keyboard-arrow-up' ;
66import algoliasearch from 'algoliasearch' ;
7+ import compareVersions from 'compare-versions' ;
78import Tooltip from '@codesandbox/common/lib/components/Tooltip' ;
89
910import { EntryContainer , IconArea , Icon } from '../../elements' ;
@@ -77,8 +78,15 @@ export default class VersionEntry extends React.PureComponent {
7778 ) ;
7879 const index = client . initIndex ( 'npm-search' ) ;
7980 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+ } ) ;
8088 this . setState ( {
81- versions : hits [ 0 ] . versions ,
89+ versions,
8290 } ) ;
8391 } ) ;
8492
@@ -137,13 +145,9 @@ export default class VersionEntry extends React.PureComponent {
137145 this . setState ( { hovering : false } ) ;
138146 } }
139147 >
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+ ) ) }
147151 </ VersionSelect >
148152 ) : (
149153 < Version withSize = { ! ! size . size } hovering = { hovering } >
0 commit comments