@@ -195,8 +195,8 @@ export default class InstallManager {
195195 /**
196196 * Regenerates the common/package.json and all temp_modules projects.
197197 */
198- public createTempModules ( ) : void {
199- this . createTempModulesAndCheckShrinkwrap ( undefined ) ;
198+ public createTempModules ( forceCreate : boolean ) : void {
199+ this . createTempModulesAndCheckShrinkwrap ( undefined , forceCreate ) ;
200200 }
201201
202202 /**
@@ -205,7 +205,9 @@ export default class InstallManager {
205205 * everything we need to install and returns true if so; in all other cases,
206206 * the return value is false.
207207 */
208- public createTempModulesAndCheckShrinkwrap ( shrinkwrapFile : ShrinkwrapFile | undefined ) : boolean {
208+ public createTempModulesAndCheckShrinkwrap (
209+ shrinkwrapFile : ShrinkwrapFile | undefined ,
210+ forceCreate : boolean ) : boolean {
209211 const stopwatch : Stopwatch = Stopwatch . start ( ) ;
210212
211213 // Example: "C:\MyRepo\common\temp\projects"
@@ -379,38 +381,23 @@ export default class InstallManager {
379381 // NPM expects the root of the tarball to have a directory called 'package'
380382 const npmPackageFolder : string = 'package' ;
381383
382- // Example: "C:\MyRepo\common\temp\projects\my-project-2.new "
384+ // Example: "C:\MyRepo\common\temp\projects\my-project-2"
383385 const tempProjectFolder : string = path . join (
384386 this . _rushConfiguration . commonTempFolder ,
385387 RushConstants . rushTempProjectsFolderName ,
386- unscopedTempProjectName + '.new' ) ;
388+ unscopedTempProjectName ) ;
387389
388390 // Example: "C:\MyRepo\common\temp\projects\my-project-2\package.json"
389391 const tempPackageJsonFilename : string = path . join ( tempProjectFolder , RushConstants . packageJsonFilename ) ;
390392
391- // Example: "C:\MyRepo\common\temp\projects\my-project-2.old"
392- const extractedFolder : string = tempProjectFolder + '.old' ;
393-
394393 // we only want to overwrite the package if the existing tarball's package.json is different from tempPackageJson
395394 let shouldOverwrite : boolean = true ;
396395 try {
397- // extract the tarball and compare the package.json directly
398- if ( fsx . existsSync ( tarballFile ) ) {
399-
400- // ensure the folder we are about to extract into exists
401- Utilities . createFolderWithRetry ( extractedFolder ) ;
402-
403- tar . extract ( {
404- cwd : extractedFolder ,
405- file : tarballFile ,
406- sync : true
407- } ) ;
408-
409- const extractedPackageJsonFilename : string =
410- path . join ( extractedFolder , npmPackageFolder , RushConstants . packageJsonFilename ) ;
396+ // if the tarball and the temp file still exist, then compare the contents
397+ if ( fsx . existsSync ( tarballFile ) && fsx . existsSync ( tempPackageJsonFilename ) ) {
411398
412399 // compare the extracted package.json with the one we are about to write
413- const oldBuffer : Buffer = fsx . readFileSync ( extractedPackageJsonFilename ) ;
400+ const oldBuffer : Buffer = fsx . readFileSync ( tempPackageJsonFilename ) ;
414401 const newBuffer : Buffer = new Buffer ( JsonFile . stringify ( tempPackageJson ) ) ;
415402
416403 if ( Buffer . compare ( oldBuffer , newBuffer ) === 0 ) {
@@ -421,30 +408,38 @@ export default class InstallManager {
421408 // ignore the error, we will go ahead and create a new tarball
422409 }
423410
424- if ( shouldOverwrite ) {
425- // ensure the folder we are about to zip exists
426- Utilities . createFolderWithRetry ( tempProjectFolder ) ;
427-
428- // write the expected package.json file into the zip staging folder
429- JsonFile . save ( tempPackageJson , tempPackageJsonFilename ) ;
430-
431- // create the new tarball, this overwrites the existing one
432- tar . create ( {
433- gzip : true ,
434- file : tarballFile ,
435- cwd : tempProjectFolder ,
436- portable : true ,
437- noPax : true ,
438- sync : true ,
439- prefix : npmPackageFolder
440- } , [ 'package.json' ] ) ;
441-
442- console . log ( `Updating ${ tarballFile } ` ) ;
443- }
411+ if ( shouldOverwrite || forceCreate ) {
412+ try {
413+ // ensure the folder we are about to zip exists
414+ Utilities . createFolderWithRetry ( tempProjectFolder ) ;
444415
445- // clean up the old tarball & the temp folder
446- fsx . removeSync ( tempProjectFolder ) ;
447- fsx . removeSync ( extractedFolder ) ;
416+ // remove the old tarball & old temp package json, this is for any cases where new tarball creation
417+ // fails, and the shouldOverwrite logic is messed up because the my-project-2\package.json
418+ // exists and is updated, but the tarball is not accurate
419+ fsx . removeSync ( tarballFile ) ;
420+ fsx . removeSync ( tempPackageJsonFilename ) ;
421+
422+ // write the expected package.json file into the zip staging folder
423+ JsonFile . save ( tempPackageJson , tempPackageJsonFilename ) ;
424+
425+ // create the new tarball
426+ tar . create ( {
427+ gzip : true ,
428+ file : tarballFile ,
429+ cwd : tempProjectFolder ,
430+ portable : true ,
431+ noPax : true ,
432+ sync : true ,
433+ prefix : npmPackageFolder
434+ } , [ 'package.json' ] ) ;
435+
436+ console . log ( `Updating ${ tarballFile } ` ) ;
437+ } catch ( error ) {
438+ // delete everything in case of any error
439+ fsx . removeSync ( tarballFile ) ;
440+ fsx . removeSync ( tempPackageJsonFilename ) ;
441+ }
442+ }
448443 }
449444
450445 // Example: "C:\MyRepo\common\temp\package.json"
0 commit comments