Skip to content

Commit 05a5610

Browse files
authored
Merge pull request microsoft#1490 from microsoft/sachinjoseph/dontDeletePnpmStoreForInstallRetry
[rush] Don't delete pnpm store for rush install retry
2 parents a8feeb2 + b6beb4b commit 05a5610

2 files changed

Lines changed: 40 additions & 17 deletions

File tree

apps/rush-lib/src/logic/InstallManager.ts

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"comment": "Do not delete the pnpm store if an installation retry fails. Delete the pnpm store if and only if all the installation retry attempts fail.",
5+
"packageName": "@microsoft/rush",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@microsoft/rush",
10+
"email": "sachinjoseph@users.noreply.github.com"
11+
}

0 commit comments

Comments
 (0)