@@ -12,9 +12,10 @@ import {
12
12
FileSystemSchematicDescription ,
13
13
NodeWorkflow ,
14
14
} from '@angular-devkit/schematics/tools' ;
15
- import { SpawnSyncReturns , execSync , spawnSync } from 'child_process' ;
16
- import { existsSync , promises as fs } from 'fs' ;
17
- import { createRequire } from 'module' ;
15
+ import { Listr } from 'listr2' ;
16
+ import { SpawnSyncReturns , execSync , spawnSync } from 'node:child_process' ;
17
+ import { existsSync , promises as fs } from 'node:fs' ;
18
+ import { createRequire } from 'node:module' ;
18
19
import npa from 'npm-package-arg' ;
19
20
import pickManifest from 'npm-pick-manifest' ;
20
21
import * as path from 'path' ;
@@ -74,6 +75,8 @@ interface MigrationSchematicDescriptionWithVersion extends MigrationSchematicDes
74
75
version : string ;
75
76
}
76
77
78
+ class CommandError extends Error { }
79
+
77
80
const ANGULAR_PACKAGES_REGEXP = / ^ @ (?: a n g u l a r | n g u n i v e r s a l ) \/ / ;
78
81
const UPDATE_SCHEMATIC_COLLECTION = path . join ( __dirname , 'schematic/collection.json' ) ;
79
82
@@ -756,21 +759,46 @@ export default class UpdateCommandModule extends CommandModule<UpdateCommandArgs
756
759
) ;
757
760
758
761
if ( success ) {
759
- try {
760
- await fs . rm ( path . join ( this . context . root , 'node_modules' ) , {
761
- force : true ,
762
- recursive : true ,
763
- maxRetries : 3 ,
764
- } ) ;
765
- } catch { }
762
+ const { root : commandRoot , packageManager } = this . context ;
763
+ const installArgs = this . packageManagerForce ( options . verbose ) ? [ '--force' ] : [ ] ;
764
+ const tasks = new Listr ( [
765
+ {
766
+ title : 'Cleaning node modules directory' ,
767
+ async task ( _ , task ) {
768
+ try {
769
+ await fs . rm ( path . join ( commandRoot , 'node_modules' ) , {
770
+ force : true ,
771
+ recursive : true ,
772
+ maxRetries : 3 ,
773
+ } ) ;
774
+ } catch ( e ) {
775
+ assertIsError ( e ) ;
776
+ if ( e . code === 'ENOENT' ) {
777
+ task . skip ( 'Cleaning not required. Node modules directory not found.' ) ;
778
+ }
779
+ }
780
+ } ,
781
+ } ,
782
+ {
783
+ title : 'Installing packages' ,
784
+ async task ( ) {
785
+ const installationSuccess = await packageManager . installAll ( installArgs , commandRoot ) ;
766
786
767
- const installationSuccess = await this . context . packageManager . installAll (
768
- this . packageManagerForce ( options . verbose ) ? [ '--force' ] : [ ] ,
769
- this . context . root ,
770
- ) ;
787
+ if ( ! installationSuccess ) {
788
+ throw new CommandError ( 'Unable to install packages' ) ;
789
+ }
790
+ } ,
791
+ } ,
792
+ ] ) ;
771
793
772
- if ( ! installationSuccess ) {
773
- return 1 ;
794
+ try {
795
+ await tasks . run ( ) ;
796
+ } catch ( e ) {
797
+ if ( e instanceof CommandError ) {
798
+ return 1 ;
799
+ }
800
+
801
+ throw e ;
774
802
}
775
803
}
776
804
0 commit comments