@@ -200,8 +200,8 @@ export default class InstallManager {
200200 /**
201201 * Regenerates the common/package.json and all temp_modules projects.
202202 */
203- public createTempModules ( ) : void {
204- this . createTempModulesAndCheckShrinkwrap ( undefined ) ;
203+ public createTempModules ( forceCreate : boolean ) : void {
204+ this . createTempModulesAndCheckShrinkwrap ( undefined , forceCreate ) ;
205205 }
206206
207207 /**
@@ -210,7 +210,9 @@ export default class InstallManager {
210210 * everything we need to install and returns true if so; in all other cases,
211211 * the return value is false.
212212 */
213- public createTempModulesAndCheckShrinkwrap ( shrinkwrapFile : ShrinkwrapFile | undefined ) : boolean {
213+ public createTempModulesAndCheckShrinkwrap (
214+ shrinkwrapFile : ShrinkwrapFile | undefined ,
215+ forceCreate : boolean ) : boolean {
214216 const stopwatch : Stopwatch = Stopwatch . start ( ) ;
215217
216218 // Example: "C:\MyRepo\common\temp\projects"
@@ -384,38 +386,23 @@ export default class InstallManager {
384386 // NPM expects the root of the tarball to have a directory called 'package'
385387 const npmPackageFolder : string = 'package' ;
386388
387- // Example: "C:\MyRepo\common\temp\projects\my-project-2.new "
389+ // Example: "C:\MyRepo\common\temp\projects\my-project-2"
388390 const tempProjectFolder : string = path . join (
389391 this . _rushConfiguration . commonTempFolder ,
390392 RushConstants . rushTempProjectsFolderName ,
391- unscopedTempProjectName + '.new' ) ;
393+ unscopedTempProjectName ) ;
392394
393395 // Example: "C:\MyRepo\common\temp\projects\my-project-2\package.json"
394396 const tempPackageJsonFilename : string = path . join ( tempProjectFolder , RushConstants . packageJsonFilename ) ;
395397
396- // Example: "C:\MyRepo\common\temp\projects\my-project-2.old"
397- const extractedFolder : string = tempProjectFolder + '.old' ;
398-
399398 // we only want to overwrite the package if the existing tarball's package.json is different from tempPackageJson
400399 let shouldOverwrite : boolean = true ;
401400 try {
402- // extract the tarball and compare the package.json directly
403- if ( fsx . existsSync ( tarballFile ) ) {
404-
405- // ensure the folder we are about to extract into exists
406- Utilities . createFolderWithRetry ( extractedFolder ) ;
407-
408- tar . extract ( {
409- cwd : extractedFolder ,
410- file : tarballFile ,
411- sync : true
412- } ) ;
413-
414- const extractedPackageJsonFilename : string =
415- path . join ( extractedFolder , npmPackageFolder , RushConstants . packageJsonFilename ) ;
401+ // if the tarball and the temp file still exist, then compare the contents
402+ if ( fsx . existsSync ( tarballFile ) && fsx . existsSync ( tempPackageJsonFilename ) ) {
416403
417404 // compare the extracted package.json with the one we are about to write
418- const oldBuffer : Buffer = fsx . readFileSync ( extractedPackageJsonFilename ) ;
405+ const oldBuffer : Buffer = fsx . readFileSync ( tempPackageJsonFilename ) ;
419406 const newBuffer : Buffer = new Buffer ( JsonFile . stringify ( tempPackageJson ) ) ;
420407
421408 if ( Buffer . compare ( oldBuffer , newBuffer ) === 0 ) {
@@ -426,30 +413,38 @@ export default class InstallManager {
426413 // ignore the error, we will go ahead and create a new tarball
427414 }
428415
429- if ( shouldOverwrite ) {
430- // ensure the folder we are about to zip exists
431- Utilities . createFolderWithRetry ( tempProjectFolder ) ;
432-
433- // write the expected package.json file into the zip staging folder
434- JsonFile . save ( tempPackageJson , tempPackageJsonFilename ) ;
435-
436- // create the new tarball, this overwrites the existing one
437- tar . create ( {
438- gzip : true ,
439- file : tarballFile ,
440- cwd : tempProjectFolder ,
441- portable : true ,
442- noPax : true ,
443- sync : true ,
444- prefix : npmPackageFolder
445- } , [ 'package.json' ] ) ;
446-
447- console . log ( `Updating ${ tarballFile } ` ) ;
448- }
416+ if ( shouldOverwrite || forceCreate ) {
417+ try {
418+ // ensure the folder we are about to zip exists
419+ Utilities . createFolderWithRetry ( tempProjectFolder ) ;
449420
450- // clean up the old tarball & the temp folder
451- fsx . removeSync ( tempProjectFolder ) ;
452- fsx . removeSync ( extractedFolder ) ;
421+ // remove the old tarball & old temp package json, this is for any cases where new tarball creation
422+ // fails, and the shouldOverwrite logic is messed up because the my-project-2\package.json
423+ // exists and is updated, but the tarball is not accurate
424+ fsx . removeSync ( tarballFile ) ;
425+ fsx . removeSync ( tempPackageJsonFilename ) ;
426+
427+ // write the expected package.json file into the zip staging folder
428+ JsonFile . save ( tempPackageJson , tempPackageJsonFilename ) ;
429+
430+ // create the new tarball
431+ tar . create ( {
432+ gzip : true ,
433+ file : tarballFile ,
434+ cwd : tempProjectFolder ,
435+ portable : true ,
436+ noPax : true ,
437+ sync : true ,
438+ prefix : npmPackageFolder
439+ } , [ 'package.json' ] ) ;
440+
441+ console . log ( `Updating ${ tarballFile } ` ) ;
442+ } catch ( error ) {
443+ // delete everything in case of any error
444+ fsx . removeSync ( tarballFile ) ;
445+ fsx . removeSync ( tempPackageJsonFilename ) ;
446+ }
447+ }
453448 }
454449
455450 // Example: "C:\MyRepo\common\temp\package.json"
0 commit comments