Skip to content

Commit

Permalink
Do not delete the local pnpm store after all install attempts has fai…
Browse files Browse the repository at this point in the history
…led.
  • Loading branch information
iclanton committed Mar 6, 2023
1 parent 83db1b4 commit a964b8b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft/rush",
"comment": "Do not delete the local pnpm store after all install attempts has failed. `rush purge` will still delete a local store.",
"type": "none"
}
],
"packageName": "@microsoft/rush"
}
57 changes: 20 additions & 37 deletions libraries/rush-lib/src/logic/installManager/RushInstallManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,45 +575,28 @@ export class RushInstallManager extends BaseInstallManager {
);
}

try {
Utilities.executeCommandWithRetry(
{
command: packageManagerFilename,
args: installArgs,
workingDirectory: this.rushConfiguration.commonTempFolder,
environment: packageManagerEnv,
suppressOutput: false
},
this.options.maxInstallAttempts,
() => {
if (this.rushConfiguration.packageManager === 'pnpm') {
console.log(colors.yellow(`Deleting the "node_modules" folder`));
this.installRecycler.moveFolder(commonNodeModulesFolder);

// Leave the pnpm-store as is for the retry. This ensures that packages that have already
// been downloaded need not be downloaded again, thereby potentially increasing the chances
// of a subsequent successful install.

Utilities.createFolderWithRetry(commonNodeModulesFolder);
}
Utilities.executeCommandWithRetry(
{
command: packageManagerFilename,
args: installArgs,
workingDirectory: this.rushConfiguration.commonTempFolder,
environment: packageManagerEnv,
suppressOutput: false
},
this.options.maxInstallAttempts,
() => {
if (this.rushConfiguration.packageManager === 'pnpm') {
console.log(colors.yellow(`Deleting the "node_modules" folder`));
this.installRecycler.moveFolder(commonNodeModulesFolder);

// Leave the pnpm-store as is for the retry. This ensures that packages that have already
// been downloaded need not be downloaded again, thereby potentially increasing the chances
// of a subsequent successful install.

Utilities.createFolderWithRetry(commonNodeModulesFolder);
}
);
} catch (error) {
// All the install attempts failed.

if (
this.rushConfiguration.packageManager === 'pnpm' &&
this.rushConfiguration.pnpmOptions.pnpmStore === 'local'
) {
// If the installation has failed even after the retries, then pnpm store may
// have got into a corrupted, irrecoverable state. Delete the store so that a
// future install can create the store afresh.
console.log(colors.yellow(`Deleting the "pnpm-store" folder`));
this.installRecycler.moveFolder(this.rushConfiguration.pnpmOptions.pnpmStorePath);
}

throw error;
}
);

if (this.rushConfiguration.packageManager === 'npm') {
console.log('\n' + colors.bold('Running "npm shrinkwrap"...'));
Expand Down

0 comments on commit a964b8b

Please sign in to comment.