Skip to content

Commit a2add46

Browse files
author
Nick Pape
committed
Merge branch 'master' into nickpape/pnpm2
2 parents 0a17a1f + 2e7dcdb commit a2add46

3 files changed

Lines changed: 50 additions & 55 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export default class GenerateAction extends BaseRushAction {
7474

7575
if (shrinkwrapFile
7676
&& !this._forceParameter.value
77-
&& installManager.createTempModulesAndCheckShrinkwrap(shrinkwrapFile)) {
77+
&& installManager.createTempModulesAndCheckShrinkwrap(shrinkwrapFile, false)) {
7878
console.log();
7979
console.log(colors.yellow('Skipping generate, since all project dependencies are already satisfied.'));
8080
console.log();
@@ -89,7 +89,7 @@ export default class GenerateAction extends BaseRushAction {
8989

9090
installManager.ensureLocalPackageManager(false);
9191

92-
installManager.createTempModules();
92+
installManager.createTempModules(true);
9393

9494
// Delete both copies of the shrinkwrap file
9595
if (fsx.existsSync(committedShrinkwrapFilename)) {

‎apps/rush-lib/src/cli/actions/InstallAction.ts‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,20 @@ export default class InstallAction extends BaseRushAction {
9393
return;
9494
}
9595

96-
if (!installManager.createTempModulesAndCheckShrinkwrap(shrinkwrapFile)) {
97-
console.log('');
98-
console.log(colors.red('You need to run "rush generate" to update your NPM shrinkwrap file.'));
99-
process.exit(1);
100-
return;
101-
}
102-
10396
let installType: InstallType = InstallType.Normal;
10497
if (this._cleanInstallFull.value) {
10598
installType = InstallType.UnsafePurge;
10699
} else if (this._cleanInstall.value) {
107100
installType = InstallType.ForceClean;
108101
}
109102

103+
if (!installManager.createTempModulesAndCheckShrinkwrap(shrinkwrapFile, installType !== InstallType.Normal)) {
104+
console.log('');
105+
console.log(colors.red('You need to run "rush generate" to update your NPM shrinkwrap file.'));
106+
process.exit(1);
107+
return;
108+
}
109+
110110
installManager.installCommonModules(installType);
111111

112112
stopwatch.stop();

‎apps/rush-lib/src/cli/utilities/InstallManager.ts‎

Lines changed: 41 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)