@@ -940,24 +940,36 @@ export class InstallManager {
940940 + FileSystem . getRealPath ( packageManagerFilename ) + ' ' + installArgs . join ( ' ' ) + os . EOL ) ;
941941 }
942942
943- Utilities . executeCommandWithRetry ( MAX_INSTALL_ATTEMPTS , packageManagerFilename ,
944- installArgs ,
945- this . _rushConfiguration . commonTempFolder ,
946- undefined ,
947- false , ( ) => {
948- if ( this . _rushConfiguration . packageManager === 'pnpm' ) {
949- // If there is a failure in pnpm, it is possible that it left the
950- // store in a bad state. Therefore, we should clean out the store
951- // before attempting the install again.
952-
953- console . log ( colors . yellow ( `Deleting the "node_modules" folder` ) ) ;
954- this . _commonTempFolderRecycler . moveFolder ( commonNodeModulesFolder ) ;
955- console . log ( colors . yellow ( `Deleting the "pnpm-store" folder` ) ) ;
956- this . _commonTempFolderRecycler . moveFolder ( this . _rushConfiguration . pnpmStoreFolder ) ;
957-
958- Utilities . createFolderWithRetry ( commonNodeModulesFolder ) ;
959- }
943+ try {
944+ Utilities . executeCommandWithRetry ( MAX_INSTALL_ATTEMPTS , packageManagerFilename ,
945+ installArgs ,
946+ this . _rushConfiguration . commonTempFolder ,
947+ undefined ,
948+ false , ( ) => {
949+ if ( this . _rushConfiguration . packageManager === 'pnpm' ) {
950+ console . log ( colors . yellow ( `Deleting the "node_modules" folder` ) ) ;
951+ this . _commonTempFolderRecycler . moveFolder ( commonNodeModulesFolder ) ;
952+
953+ // Leave the pnpm-store as is for the retry. This ensures that packages that have already
954+ // been downloaded need not be downloaded again, thereby potentially increasing the chances
955+ // of a subsequent successful install.
956+
957+ Utilities . createFolderWithRetry ( commonNodeModulesFolder ) ;
958+ }
960959 } ) ;
960+ } catch ( error ) {
961+ // All the install attempts failed.
962+
963+ if ( this . _rushConfiguration . packageManager === 'pnpm' ) {
964+ // If the installation has failed even after the retries, then pnpm store may
965+ // have got into a corrupted, irrecoverable state. Delete the store so that a
966+ // future install can create the store afresh.
967+ console . log ( colors . yellow ( `Deleting the "pnpm-store" folder` ) ) ;
968+ this . _commonTempFolderRecycler . moveFolder ( this . _rushConfiguration . pnpmStoreFolder ) ;
969+ }
970+
971+ throw error ;
972+ }
961973
962974 if ( this . _rushConfiguration . packageManager === 'npm' ) {
963975
0 commit comments