@@ -216,11 +216,17 @@ export class Migrator {
216
216
) ;
217
217
for ( const packageToCheck of packagesToCheck ) {
218
218
const filteredUpdates : Record < string , PackageUpdate > = { } ;
219
- for ( const packageUpdate of packageToCheck . updates ) {
219
+ for ( const [ packageUpdateKey , packageUpdate ] of Object . entries (
220
+ packageToCheck . updates
221
+ ) ) {
220
222
if (
221
223
this . areRequirementsMet ( packageUpdate . requires ) &&
222
224
( ! this . interactive ||
223
- ( await this . runPackageJsonUpdatesConfirmationPrompt ( packageUpdate ) ) )
225
+ ( await this . runPackageJsonUpdatesConfirmationPrompt (
226
+ packageUpdate ,
227
+ packageUpdateKey ,
228
+ packageToCheck . package
229
+ ) ) )
224
230
) {
225
231
Object . entries ( packageUpdate . packages ) . forEach ( ( [ name , update ] ) => {
226
232
filteredUpdates [ name ] = update ;
@@ -243,7 +249,7 @@ export class Migrator {
243
249
) : Promise <
244
250
{
245
251
package : string ;
246
- updates : PackageJsonUpdates [ string ] [ ] ;
252
+ updates : PackageJsonUpdates ;
247
253
} [ ]
248
254
> {
249
255
let targetVersion = target . version ;
@@ -293,11 +299,11 @@ export class Migrator {
293
299
migrationConfig
294
300
) ;
295
301
296
- if ( ! packageJsonUpdates . length ) {
302
+ if ( ! Object . keys ( packageJsonUpdates ) . length ) {
297
303
return [ ] ;
298
304
}
299
305
300
- const shouldCheckUpdates = packageJsonUpdates . some (
306
+ const shouldCheckUpdates = Object . values ( packageJsonUpdates ) . some (
301
307
( packageJsonUpdate ) =>
302
308
( this . interactive && packageJsonUpdate [ 'x-prompt' ] ) ||
303
309
Object . keys ( packageJsonUpdate . requires ?? { } ) . length
@@ -307,7 +313,7 @@ export class Migrator {
307
313
return [ { package : targetPackage , updates : packageJsonUpdates } ] ;
308
314
}
309
315
310
- const packageUpdatesToApply = packageJsonUpdates . reduce (
316
+ const packageUpdatesToApply = Object . values ( packageJsonUpdates ) . reduce (
311
317
( m , c ) => ( { ...m , ...c . packages } ) ,
312
318
{ } as Record < string , PackageUpdate >
313
319
) ;
@@ -336,7 +342,7 @@ export class Migrator {
336
342
targetVersion : string ,
337
343
migrationConfig : ResolvedMigrationConfiguration
338
344
) : {
339
- packageJsonUpdates : PackageJsonUpdates [ string ] [ ] ;
345
+ packageJsonUpdates : PackageJsonUpdates ;
340
346
packageGroupOrder : string [ ] ;
341
347
} {
342
348
const packageGroupOrder : string [ ] =
@@ -350,7 +356,7 @@ export class Migrator {
350
356
! migrationConfig . packageJsonUpdates ||
351
357
! this . getPkgVersion ( packageName )
352
358
) {
353
- return { packageJsonUpdates : [ ] , packageGroupOrder } ;
359
+ return { packageJsonUpdates : { } , packageGroupOrder } ;
354
360
}
355
361
356
362
const packageJsonUpdates = this . filterPackageJsonUpdates (
@@ -416,10 +422,12 @@ export class Migrator {
416
422
packageJsonUpdates : PackageJsonUpdates ,
417
423
packageName : string ,
418
424
targetVersion : string
419
- ) : PackageJsonUpdates [ string ] [ ] {
420
- const filteredPackageJsonUpdates : PackageJsonUpdates [ string ] [ ] = [ ] ;
425
+ ) : PackageJsonUpdates {
426
+ const filteredPackageJsonUpdates : PackageJsonUpdates = { } ;
421
427
422
- for ( const packageJsonUpdate of Object . values ( packageJsonUpdates ) ) {
428
+ for ( const [ packageJsonUpdateKey , packageJsonUpdate ] of Object . entries (
429
+ packageJsonUpdates
430
+ ) ) {
423
431
if (
424
432
! packageJsonUpdate . packages ||
425
433
this . lt ( packageJsonUpdate . version , this . getPkgVersion ( packageName ) ) ||
@@ -456,7 +464,7 @@ export class Migrator {
456
464
}
457
465
if ( Object . keys ( filtered ) . length ) {
458
466
packageJsonUpdate . packages = filtered ;
459
- filteredPackageJsonUpdates . push ( packageJsonUpdate ) ;
467
+ filteredPackageJsonUpdates [ packageJsonUpdateKey ] = packageJsonUpdate ;
460
468
}
461
469
}
462
470
@@ -563,7 +571,9 @@ export class Migrator {
563
571
}
564
572
565
573
private async runPackageJsonUpdatesConfirmationPrompt (
566
- packageUpdate : PackageJsonUpdates [ string ]
574
+ packageUpdate : PackageJsonUpdates [ string ] ,
575
+ packageUpdateKey : string ,
576
+ packageName : string
567
577
) : Promise < boolean > {
568
578
if ( ! packageUpdate [ 'x-prompt' ] ) {
569
579
return Promise . resolve ( true ) ;
@@ -574,26 +584,39 @@ export class Migrator {
574
584
return Promise . resolve ( false ) ;
575
585
}
576
586
577
- return await prompt ( [
578
- {
579
- name : 'shouldApply' ,
580
- type : 'confirm' ,
581
- message : packageUpdate [ 'x-prompt' ] ,
582
- initial : true ,
583
- } ,
584
- ] ) . then ( ( { shouldApply } : { shouldApply : boolean } ) => {
585
- this . promptAnswers [ promptKey ] = shouldApply ;
587
+ const promptConfig = {
588
+ name : 'shouldApply' ,
589
+ type : 'confirm' ,
590
+ message : packageUpdate [ 'x-prompt' ] ,
591
+ initial : true ,
592
+ } ;
586
593
587
- if (
588
- ! shouldApply &&
589
- ( ! this . minVersionWithSkippedUpdates ||
590
- lt ( packageUpdate . version , this . minVersionWithSkippedUpdates ) )
591
- ) {
592
- this . minVersionWithSkippedUpdates = packageUpdate . version ;
593
- }
594
+ if ( packageName . startsWith ( '@nx/' ) ) {
595
+ // @ts -expect-error -- enquirer types aren't correct, footer does exist
596
+ promptConfig . footer = ( ) =>
597
+ chalk . dim (
598
+ ` View migration details at https://nx.dev/nx-api/${ packageName . replace (
599
+ '@nx/' ,
600
+ ''
601
+ ) } #${ packageUpdateKey . replace ( / [ - \. ] / g, '' ) } packageupdates`
602
+ ) ;
603
+ }
594
604
595
- return shouldApply ;
596
- } ) ;
605
+ return await prompt ( [ promptConfig ] ) . then (
606
+ ( { shouldApply } : { shouldApply : boolean } ) => {
607
+ this . promptAnswers [ promptKey ] = shouldApply ;
608
+
609
+ if (
610
+ ! shouldApply &&
611
+ ( ! this . minVersionWithSkippedUpdates ||
612
+ lt ( packageUpdate . version , this . minVersionWithSkippedUpdates ) )
613
+ ) {
614
+ this . minVersionWithSkippedUpdates = packageUpdate . version ;
615
+ }
616
+
617
+ return shouldApply ;
618
+ }
619
+ ) ;
597
620
}
598
621
599
622
private getPackageUpdatePromptKey (
0 commit comments