Skip to content

Commit

Permalink
Merge pull request microsoft#4002 from iclanton/remove-pnpm-store-purge
Browse files Browse the repository at this point in the history
[rush] Do not delete the local pnpm store after all install attempts has failed.
  • Loading branch information
iclanton authored Mar 6, 2023
2 parents 83db1b4 + a964b8b commit add49a3
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 add49a3

Please sign in to comment.