@@ -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
0 commit comments