@@ -97,7 +97,12 @@ export type InstallPhaseHandler = (
97
97
export type Installer = (
98
98
pkgEnvDetails : EnvDetails ,
99
99
options : InstallOptions ,
100
- ) => Promise < NodeClass | null >
100
+ ) => Promise < InstallerResult >
101
+
102
+ export type InstallerResult = {
103
+ actualTree ?: NodeClass | undefined
104
+ error ?: unknown | undefined
105
+ }
101
106
102
107
const noopHandler = ( ( ) => { } ) as unknown as InstallPhaseHandler
103
108
@@ -198,13 +203,15 @@ export async function agentFix(
198
203
: [ ]
199
204
}
200
205
201
- const handleInstallFail = ( ) : CResult < { fixed : boolean } > => {
206
+ const handleInstallFail = (
207
+ error ?: unknown | undefined ,
208
+ ) : CResult < { fixed : boolean } > => {
202
209
cleanupInfoEntriesLoop ( )
203
210
spinner ?. stop ( )
204
211
return {
205
212
ok : false ,
206
213
message : 'Install failed' ,
207
- cause : `Unexpected condition: ${ pkgEnvDetails . agent } install failed` ,
214
+ cause : `${ pkgEnvDetails . agent } install failed${ error ? `; ${ error } ` : '' } ` ,
208
215
}
209
216
}
210
217
@@ -273,19 +280,25 @@ export async function agentFix(
273
280
// eslint-disable-next-line no-await-in-loop
274
281
await removeNodeModules ( cwd )
275
282
}
276
- const maybeActualTree =
277
- fixEnv . isCi && existsSync ( path . join ( rootPath , 'node_modules' ) )
278
- ? // eslint-disable-next-line no-await-in-loop
279
- await getActualTree ( cwd )
280
- : // eslint-disable-next-line no-await-in-loop
281
- await installer ( pkgEnvDetails , { cwd, spinner } )
282
- if ( maybeActualTree && existsSync ( pkgEnvDetails . lockPath ) ) {
283
+ if ( fixEnv . isCi && existsSync ( path . join ( rootPath , 'node_modules' ) ) ) {
284
+ // eslint-disable-next-line no-await-in-loop
285
+ actualTree = await getActualTree ( cwd )
286
+ } else {
287
+ // eslint-disable-next-line no-await-in-loop
288
+ const installResult = await installer ( pkgEnvDetails , { cwd, spinner } )
289
+ const maybeActualTree = installResult . actualTree
290
+ if ( ! maybeActualTree ) {
291
+ // Exit early if install fails.
292
+ return handleInstallFail ( installResult . error )
293
+ }
283
294
actualTree = maybeActualTree
284
295
}
285
- }
286
- if ( ! actualTree ) {
287
- // Exit early if install fails.
288
- return handleInstallFail ( )
296
+ if ( ! existsSync ( pkgEnvDetails . lockPath ) ) {
297
+ // Exit early if lockfile is missing.
298
+ return handleInstallFail (
299
+ new Error ( `Missing lockfile at ${ pkgEnvDetails . lockPath } ` ) ,
300
+ )
301
+ }
289
302
}
290
303
291
304
const oldVersions = arrayUnique (
@@ -447,15 +460,22 @@ export async function agentFix(
447
460
const newId = `${ name } @${ applyRange ( refRange , newVersion , rangeStyle ) } `
448
461
spinner ?. info ( `Installing ${ newId } in ${ workspace } .` )
449
462
450
- let error
463
+ let error : unknown | undefined
451
464
let errored = false
452
465
try {
453
466
// eslint-disable-next-line no-await-in-loop
454
- const maybeActualTree = await installer ( pkgEnvDetails , {
467
+ const installResult = await installer ( pkgEnvDetails , {
455
468
cwd,
456
469
spinner,
457
470
} )
458
- if ( maybeActualTree && existsSync ( pkgEnvDetails . lockPath ) ) {
471
+ const maybeActualTree = installResult . actualTree
472
+ if ( ! maybeActualTree ) {
473
+ errored = true
474
+ error = installResult . error
475
+ } else if ( ! existsSync ( pkgEnvDetails . lockPath ) ) {
476
+ errored = true
477
+ error = new Error ( `Missing lockfile at ${ pkgEnvDetails . lockPath } ` )
478
+ } else {
459
479
actualTree = maybeActualTree
460
480
// eslint-disable-next-line no-await-in-loop
461
481
await afterInstall (
@@ -473,8 +493,6 @@ export async function agentFix(
473
493
}
474
494
spinner ?. success ( `Fixed ${ name } in ${ workspace } .` )
475
495
seenVersions . add ( newVersion )
476
- } else {
477
- errored = true
478
496
}
479
497
} catch ( e ) {
480
498
error = e
@@ -516,16 +534,23 @@ export async function agentFix(
516
534
// eslint-disable-next-line no-await-in-loop
517
535
await gitDeleteBranch ( branch , cwd )
518
536
// eslint-disable-next-line no-await-in-loop
519
- const maybeActualTree = await installer ( pkgEnvDetails , {
537
+ const installResult = await installer ( pkgEnvDetails , {
520
538
cwd,
521
539
spinner,
522
540
} )
523
- if ( maybeActualTree && existsSync ( pkgEnvDetails . lockPath ) ) {
524
- actualTree = maybeActualTree
525
- continue infosLoop
541
+ const maybeActualTree = installResult . actualTree
542
+ if ( ! maybeActualTree ) {
543
+ // Exit early if install fails.
544
+ return handleInstallFail ( installResult . error )
526
545
}
527
- // Exit early if install fails.
528
- return handleInstallFail ( )
546
+ if ( ! existsSync ( pkgEnvDetails . lockPath ) ) {
547
+ // Exit early if lockfile is missing.
548
+ return handleInstallFail (
549
+ new Error ( `Missing lockfile at ${ pkgEnvDetails . lockPath } ` ) ,
550
+ )
551
+ }
552
+ actualTree = maybeActualTree
553
+ continue infosLoop
529
554
}
530
555
531
556
seenBranches . add ( branch )
@@ -595,15 +620,17 @@ export async function agentFix(
595
620
// eslint-disable-next-line no-await-in-loop
596
621
await gitCheckoutBranch ( fixEnv . baseBranch , cwd )
597
622
// eslint-disable-next-line no-await-in-loop
598
- const maybeActualTree = await installer ( pkgEnvDetails , {
623
+ const installResult = await installer ( pkgEnvDetails , {
599
624
cwd,
600
625
spinner,
601
626
} )
602
627
spinner ?. stop ( )
628
+ const maybeActualTree = installResult . actualTree
603
629
if ( maybeActualTree ) {
604
630
actualTree = maybeActualTree
605
631
} else {
606
632
errored = true
633
+ error = installResult . error
607
634
}
608
635
}
609
636
if ( errored ) {
@@ -624,17 +651,17 @@ export async function agentFix(
624
651
editablePkgJson . save ( { ignoreWhitespace : true } ) ,
625
652
] )
626
653
// eslint-disable-next-line no-await-in-loop
627
- const maybeActualTree = await installer ( pkgEnvDetails , {
654
+ const installResult = await installer ( pkgEnvDetails , {
628
655
cwd,
629
656
spinner,
630
657
} )
631
658
spinner ?. stop ( )
632
- if ( maybeActualTree ) {
633
- actualTree = maybeActualTree
634
- } else {
659
+ const maybeActualTree = installResult . actualTree
660
+ if ( ! maybeActualTree ) {
635
661
// Exit early if install fails.
636
- return handleInstallFail ( )
662
+ return handleInstallFail ( installResult . error )
637
663
}
664
+ actualTree = maybeActualTree
638
665
}
639
666
return {
640
667
ok : false ,
0 commit comments