@@ -12,9 +12,10 @@ import {
1212 FileSystemSchematicDescription ,
1313 NodeWorkflow ,
1414} 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' ;
1819import npa from 'npm-package-arg' ;
1920import pickManifest from 'npm-pick-manifest' ;
2021import * as path from 'path' ;
@@ -74,6 +75,8 @@ interface MigrationSchematicDescriptionWithVersion extends MigrationSchematicDes
7475 version : string ;
7576}
7677
78+ class CommandError extends Error { }
79+
7780const ANGULAR_PACKAGES_REGEXP = / ^ @ (?: a n g u l a r | n g u n i v e r s a l ) \/ / ;
7881const UPDATE_SCHEMATIC_COLLECTION = path . join ( __dirname , 'schematic/collection.json' ) ;
7982
@@ -756,21 +759,46 @@ export default class UpdateCommandModule extends CommandModule<UpdateCommandArgs
756759 ) ;
757760
758761 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 ) ;
766786
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+ ] ) ;
771793
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 ;
774802 }
775803 }
776804
0 commit comments