Skip to content

Commit 65749d1

Browse files
authored
Merge pull request microsoft#549 from Microsoft/pgonzal/rush-conservative-generate
Add a "--conservative" flag for "rush generate"
2 parents f4fecfd + 2717e92 commit 65749d1

3 files changed

Lines changed: 51 additions & 9 deletions

File tree

apps/rush-lib/src/cli/actions/GenerateAction.ts

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export default class GenerateAction extends BaseRushAction {
2525
private _noLinkParameter: CommandLineFlagParameter;
2626
private _forceParameter: CommandLineFlagParameter;
2727
private _cleanParameter: CommandLineFlagParameter;
28+
private _conservativeParameter: CommandLineFlagParameter;
2829

2930
constructor(parser: RushCommandLineParser) {
3031
super({
@@ -66,6 +67,11 @@ export default class GenerateAction extends BaseRushAction {
6667
description: 'When using pnpm, forces a non-incremental clean install which clears the node_module and pnpm'
6768
+ ' store. Use this if any store corruption has occurred.'
6869
});
70+
this._conservativeParameter = this.defineFlagParameter({
71+
parameterLongName: '--conservative',
72+
description: 'When using pnpm, this only bumps the minimal set of versions necessary to satisfy'
73+
+ ' package.json requirements, avoiding a full upgrade of unrelated shrinkwrap dependencies.'
74+
});
6975
}
7076

7177
protected run(): Promise<void> {
@@ -86,6 +92,10 @@ export default class GenerateAction extends BaseRushAction {
8692
+ ' because its algorithm always performs a clean installation.'));
8793
}
8894

95+
if (this._conservativeParameter.value && this.rushConfiguration.packageManager !== 'pnpm') {
96+
throw new Error(`The --conservative flag is only supported for pnpm.`);
97+
}
98+
8999
ApprovedPackagesChecker.rewriteConfigFiles(this.rushConfiguration);
90100

91101
const installManager: InstallManager = new InstallManager(this.rushConfiguration);
@@ -110,19 +120,29 @@ export default class GenerateAction extends BaseRushAction {
110120
}
111121
} catch (ex) {
112122
console.log();
113-
console.log('There was a problem reading the shrinkwrap file. Proceeeding with "rush generate".');
123+
console.log('There was a problem reading the shrinkwrap file. Proceeding with "rush generate".');
114124
}
115125

116126
return installManager.ensureLocalPackageManager(false).then(() => {
117127
installManager.createTempModules(true);
118128

119-
// Delete both copies of the shrinkwrap file
120-
if (fsx.existsSync(committedShrinkwrapFilename)) {
121-
console.log(os.EOL + 'Deleting ' + committedShrinkwrapFilename);
122-
fsx.unlinkSync(committedShrinkwrapFilename);
123-
}
124-
if (fsx.existsSync(tempShrinkwrapFilename)) {
125-
fsx.unlinkSync(tempShrinkwrapFilename);
129+
if (this._conservativeParameter.value) {
130+
if (fsx.existsSync(committedShrinkwrapFilename)) {
131+
console.log(os.EOL + 'The "--conservative" flag was provided, so preserving '
132+
+ committedShrinkwrapFilename);
133+
} else {
134+
throw new Error('The "--conservative" flag cannot be used because the shrinkwrap file is missing: '
135+
+ committedShrinkwrapFilename);
136+
}
137+
138+
// Copy common\config\rush\shrinkwrap.yaml --> common\temp\shrinkwrap.yaml
139+
console.log(os.EOL + 'Updating ' + tempShrinkwrapFilename);
140+
fsx.copySync(committedShrinkwrapFilename, tempShrinkwrapFilename);
141+
} else {
142+
if (fsx.existsSync(tempShrinkwrapFilename)) {
143+
console.log(os.EOL + 'Deleting ' + tempShrinkwrapFilename);
144+
fsx.unlinkSync(tempShrinkwrapFilename);
145+
}
126146
}
127147

128148
const packageManager: PackageManager = this.rushConfiguration.packageManager;
@@ -189,7 +209,7 @@ export default class GenerateAction extends BaseRushAction {
189209
}
190210

191211
private _syncShrinkwrapAndCheckInstallFlag(installManager: InstallManager): void {
192-
// Copy (or delete) common\temp\npm-shrinkwrap.json --> common\npm-shrinkwrap.json
212+
// Copy (or delete) common\temp\shrinkwrap.yaml --> common\config\rush\shrinkwrap.yaml
193213
installManager.syncFile(this.rushConfiguration.tempShrinkwrapFilename,
194214
this.rushConfiguration.committedShrinkwrapFilename);
195215

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"comment": "Add a new command-line flag \"--conservative\" which causes \"rush generate\" to perform a minimal upgrade",
5+
"packageName": "@microsoft/rush",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@microsoft/rush",
10+
"email": "pgonzal@users.noreply.github.com"
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"comment": "Improved \"rush generate\" so that if interrupted, it does not leave you with a deleted shrinkwrap.yaml; the new integrity checks eliminate the need for this, and it was annoying",
5+
"packageName": "@microsoft/rush",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@microsoft/rush",
10+
"email": "pgonzal@users.noreply.github.com"
11+
}

0 commit comments

Comments
 (0)