@@ -249,14 +249,43 @@ export class BoardsServiceImpl implements BoardsService {
249
249
}
250
250
}
251
251
252
+ // We must group the cores by ID, and sort platforms by, first the installed version, then version alphabetical order.
253
+ // Otherwise we lose the FQBN information.
254
+ const groupedById : Map < string , Platform [ ] > = new Map ( ) ;
252
255
for ( const platform of resp . getSearchOutputList ( ) ) {
253
256
const id = platform . getId ( ) ;
254
- const pkg = packages . get ( id ) ;
255
- if ( pkg ) {
256
- pkg . availableVersions . push ( platform . getLatest ( ) ) ;
257
- pkg . availableVersions . sort ( Installable . Version . COMPARATOR ) ;
257
+ if ( groupedById . has ( id ) ) {
258
+ groupedById . get ( id ) ! . push ( platform ) ;
258
259
} else {
259
- packages . set ( id , toPackage ( platform ) ) ;
260
+ groupedById . set ( id , [ platform ] ) ;
261
+ }
262
+ }
263
+ const installedAwareVersionComparator = ( left : Platform , right : Platform ) => {
264
+ // XXX: we cannot rely on `platform.getInstalled()`, it is always an empty string.
265
+ const leftInstalled = ! ! installedPlatforms . find ( ip => ip . getId ( ) === left . getId ( ) && ip . getInstalled ( ) === left . getLatest ( ) ) ;
266
+ const rightInstalled = ! ! installedPlatforms . find ( ip => ip . getId ( ) === right . getId ( ) && ip . getInstalled ( ) === right . getLatest ( ) ) ;
267
+ if ( leftInstalled && ! rightInstalled ) {
268
+ return - 1 ;
269
+ }
270
+ if ( ! leftInstalled && rightInstalled ) {
271
+ return 1 ;
272
+ }
273
+ return Installable . Version . COMPARATOR ( right . getLatest ( ) , left . getLatest ( ) ) ; // Higher version comes first.
274
+ }
275
+ for ( const id of groupedById . keys ( ) ) {
276
+ groupedById . get ( id ) ! . sort ( installedAwareVersionComparator ) ;
277
+ }
278
+
279
+ for ( const id of groupedById . keys ( ) ) {
280
+ for ( const platform of groupedById . get ( id ) ! ) {
281
+ const id = platform . getId ( ) ;
282
+ const pkg = packages . get ( id ) ;
283
+ if ( pkg ) {
284
+ pkg . availableVersions . push ( platform . getLatest ( ) ) ;
285
+ pkg . availableVersions . sort ( Installable . Version . COMPARATOR ) ;
286
+ } else {
287
+ packages . set ( id , toPackage ( platform ) ) ;
288
+ }
260
289
}
261
290
}
262
291
0 commit comments