Skip to content

Commit d788f09

Browse files
author
Nick Pape
committed
PR Feedback
1 parent a2add46 commit d788f09

11 files changed

Lines changed: 84 additions & 44 deletions

File tree

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ export default class GenerateAction extends BaseRushAction {
6161
const stopwatch: Stopwatch = Stopwatch.start();
6262
const isLazy: boolean = this._lazyParameter.value;
6363

64+
if (this._lazyParameter.value && this.rushConfiguration.packageManager === 'pnpm') {
65+
console.warn(colors.yellow('The --lazy flag is not required for PNPM'
66+
+ ' because its algorithm inherently incorporates this optimization.'));
67+
}
68+
6469
ApprovedPackagesChecker.rewriteConfigFiles(this.rushConfiguration);
6570

6671
const installManager: InstallManager = new InstallManager(this.rushConfiguration);
@@ -70,7 +75,7 @@ export default class GenerateAction extends BaseRushAction {
7075

7176
try {
7277
const shrinkwrapFile: ShrinkwrapFile | undefined
73-
= ShrinkwrapFile.loadFromFile(committedShrinkwrapFilename);
78+
= ShrinkwrapFile.loadFromFile(this.rushConfiguration.packageManager, committedShrinkwrapFilename);
7479

7580
if (shrinkwrapFile
7681
&& !this._forceParameter.value

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ export default class InstallAction extends BaseRushAction {
8282
installManager.ensureLocalPackageManager(this._cleanInstallFull.value);
8383

8484
const shrinkwrapFile: ShrinkwrapFile | undefined
85-
= ShrinkwrapFile.loadFromFile(this.rushConfiguration.committedShrinkwrapFilename);
85+
= ShrinkwrapFile.loadFromFile(
86+
this.rushConfiguration.packageManager,
87+
this.rushConfiguration.committedShrinkwrapFilename);
8688

8789
if (!shrinkwrapFile) {
8890
console.log('');

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

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import globEscape = require('glob-escape');
1313
import { JsonFile } from '@microsoft/node-core-library';
1414

1515
import AsyncRecycler from '../../utilities/AsyncRecycler';
16-
import RushConfiguration from '../../data/RushConfiguration';
16+
import RushConfiguration, {
17+
PackageManager
18+
} from '../../data/RushConfiguration';
1719
import RushConfigurationProject from '../../data/RushConfigurationProject';
1820
import { RushConstants } from '../../RushConstants';
1921
import Utilities from '../../utilities/Utilities';
@@ -152,7 +154,7 @@ export default class InstallManager {
152154
fsx.mkdirSync(rushHomeFolder);
153155
}
154156

155-
const packageManager: 'pnpm' | 'npm' = this._rushConfiguration.packageManager;
157+
const packageManager: PackageManager = this._rushConfiguration.packageManager;
156158
const packageManagerVersion: string = this._rushConfiguration.packageManagerToolVersion;
157159

158160
// Example: "C:\Users\YourName\.rush\pnpm-1.2.3"
@@ -517,16 +519,16 @@ export default class InstallManager {
517519
}
518520
} else {
519521
if (this._rushConfiguration.packageManager === 'npm') {
520-
console.log(`Deleting the packages-cache folder`);
522+
console.log(`Deleting the "npm-cache" folder`);
521523
// This is faster and more thorough than "npm cache clean"
522524
this._asyncRecycler.moveFolder(this._rushConfiguration.npmCacheFolder);
523525

524-
console.log(`Deleting the "packages-tmp" folder`);
526+
console.log(`Deleting the "npm-tmp" folder`);
525527
this._asyncRecycler.moveFolder(this._rushConfiguration.npmTmpFolder);
526528

527529
} else if (installType === InstallType.UnsafePurge) {
528-
console.log(`Deleting the PNPM store folder`);
529-
this._asyncRecycler.moveFolder(this._rushConfiguration.npmCacheFolder);
530+
console.log(`Deleting the "pnpm-store" folder`);
531+
this._asyncRecycler.moveFolder(this._rushConfiguration.pnpmStoreFolder);
530532
}
531533
}
532534

@@ -545,8 +547,6 @@ export default class InstallManager {
545547
if (deletingNodeModules) {
546548
// YES: Delete "node_modules"
547549

548-
// @todo, try not to remove the local registry install
549-
550550
// Explain to the user why we are hosing their node_modules folder
551551
if (installType === InstallType.Normal) {
552552
console.log('Deleting the "node_modules" folder because the previous Rush install' +
@@ -563,12 +563,15 @@ export default class InstallManager {
563563
} else {
564564
// NO: Do an incremental install in the "node_modules" folder
565565

566-
console.log(`Running "${this._rushConfiguration.packageManager} prune"`
567-
+ ` in ${this._rushConfiguration.commonTempFolder}`);
568-
const args: string[] = ['prune'];
569-
this.pushConfigurationArgs(args);
570-
Utilities.executeCommandWithRetry(packageManagerFilename, args, MAX_INSTALL_ATTEMPTS,
571-
this._rushConfiguration.commonTempFolder);
566+
// note: it is not necessary to run "prune" with pnpm
567+
if (this._rushConfiguration.packageManager === 'npm') {
568+
console.log(`Running "${this._rushConfiguration.packageManager} prune"`
569+
+ ` in ${this._rushConfiguration.commonTempFolder}`);
570+
const args: string[] = ['prune'];
571+
this.pushConfigurationArgs(args);
572+
Utilities.executeCommandWithRetry(packageManagerFilename, args, MAX_INSTALL_ATTEMPTS,
573+
this._rushConfiguration.commonTempFolder);
574+
}
572575

573576
// Delete the (installed image of) the temp projects, since "npm install" does not
574577
// detect changes for "file:./" references.
@@ -596,7 +599,8 @@ export default class InstallManager {
596599

597600
// Run "npm install" in the common folder
598601

599-
// NOTE: we do NOT install optional dependencies for Rush, as it seems that optional dependencies do not
602+
// NOTE FOR NPM:
603+
// we do NOT install optional dependencies for Rush, as it seems that optional dependencies do not
600604
// work properly with shrinkwrap. Consider the "fsevents" package. This is a Mac specific package
601605
// which is an optional second-order dependency. Optional dependencies work by attempting to install
602606
// the package, but removes the package if the install failed.
@@ -637,7 +641,7 @@ export default class InstallManager {
637641
args.push('--cache', this._rushConfiguration.npmCacheFolder);
638642
args.push('--tmp', this._rushConfiguration.npmTmpFolder);
639643
} else if (this._rushConfiguration.packageManager === 'pnpm') {
640-
args.push('--store', this._rushConfiguration.npmCacheFolder);
644+
args.push('--store', this._rushConfiguration.pnpmStoreFolder);
641645
args.push('--no-lock');
642646
}
643647
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import { JsonFile } from '@microsoft/node-core-library';
55

6-
import { IPackageJson } from '../../index';
6+
import IPackageJson from '../../utilities/IPackageJson';
77

88
/**
99
* The type of dependency; used by IPackageDependency.

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as semver from 'semver';
66
import npmPackageArg = require('npm-package-arg');
77

88
import Utilities from '../../utilities/Utilities';
9+
import { PackageManager } from '../../data/RushConfiguration';
910
import { RushConstants } from '../../RushConstants';
1011

1112
/**
@@ -14,14 +15,13 @@ import { RushConstants } from '../../RushConstants';
1415
export default abstract class ShrinkwrapFile {
1516
protected _alreadyWarnedSpecs: Set<string> = new Set<string>();
1617

17-
public static loadFromFile(shrinkwrapFilename: string): ShrinkwrapFile | undefined {
18-
try {
18+
public static loadFromFile(packageManager: PackageManager, shrinkwrapFilename: string): ShrinkwrapFile | undefined {
19+
if (packageManager === 'npm') {
1920
return require('./npm/NpmShrinkwrapFile').default.loadFromFile(shrinkwrapFilename);
20-
} catch (e) { /* no-op */ }
21-
try {
21+
} else if (packageManager === 'pnpm') {
2222
return require('./pnpm/PnpmShrinkwrapFile').default.loadFromFile(shrinkwrapFilename);
23-
} catch (e) { /* no-op */ }
24-
throw new Error(`Unable to load shrinkwrap file!`);
23+
}
24+
throw new Error(`Invalid package manager: "${packageManager}"`);
2525
}
2626

2727
protected static tryGetValue<T>(dictionary: { [key2: string]: T }, key: string): T | undefined {

‎apps/rush-lib/src/cli/utilities/pnpm/PnpmLinkManager.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,18 @@ export default class PnpmLinkManager extends LinkManager {
2323
protected _linkProjects(): Promise<void> {
2424
return new Promise<void>((resolve: () => void, reject: (reason: Error) => void): void => {
2525
// go ahead and find out the registry we are using, we need this to locate the pnpm store folder
26+
27+
// EXAMPLE: https://onedrive.pkgs.visualstudio.com/_packaging/odsp-npm/npm/registry
2628
const registryUrl: string = Utilities.executeCommandAndCaptureOutput(
2729
this._rushConfiguration.packageManagerToolFilename,
2830
['config', 'get', 'registry'],
2931
this._rushConfiguration.commonTempFolder,
3032
process.env);
3133

34+
// EXAMPLE: onedrive.pkgs.visualstudio.com
3235
const encodedRegistry: string = encodeRegistry(registryUrl);
3336

37+
// EXAMPLE: c:/src/foo/common/temp/node_modules/.onedrive.pkgs.visualstudio.com
3438
const registryPath: string = path.join(
3539
this._rushConfiguration.commonTempFolder,
3640
RushConstants.nodeModulesFolderName,

‎apps/rush-lib/src/cli/utilities/test/ShrinkwrapFile.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import ShrinkwapFile from '../ShrinkwrapFile';
88

99
describe('NPM ShrinkwrapFile', () => {
1010
const filename: string = path.resolve(path.join(__dirname, './shrinkwrapFile/npm-shrinkwrap.json'));
11-
const shrinkwrapFile: ShrinkwapFile = ShrinkwapFile.loadFromFile(filename)!;
11+
const shrinkwrapFile: ShrinkwapFile = ShrinkwapFile.loadFromFile('npm', filename)!;
1212

1313
it('verifies root-level dependency', () => {
1414
shrinkwrapFile.hasCompatibleDependency('q', '~1.5.0');
@@ -31,7 +31,7 @@ describe('NPM ShrinkwrapFile', () => {
3131
describe('PNPM ShrinkwrapFile', () => {
3232
const filename: string = path.resolve(path.join(
3333
__dirname, '../../../../src/cli/utilities/test/shrinkwrapFile/shrinkwrap.yaml'));
34-
const shrinkwrapFile: ShrinkwapFile = ShrinkwapFile.loadFromFile(filename)!;
34+
const shrinkwrapFile: ShrinkwapFile = ShrinkwapFile.loadFromFile('pnpm', filename)!;
3535

3636
it('verifies root-level dependency', () => {
3737
shrinkwrapFile.hasCompatibleDependency('q', '~1.5.0');

‎apps/rush-lib/src/data/RushConfiguration.ts‎

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ export interface IRushLinkJson {
9797
};
9898
}
9999

100+
/**
101+
* This represents the available Package Manager tools as a string
102+
* @public
103+
*/
104+
export type PackageManager = 'pnpm' | 'npm';
105+
100106
/**
101107
* This represents the Rush configuration for a repository, based on the Rush.json
102108
* configuration file.
@@ -111,9 +117,10 @@ export default class RushConfiguration {
111117
private _commonFolder: string;
112118
private _commonTempFolder: string;
113119
private _commonRushConfigFolder: string;
114-
private _packageManager: 'pnpm' | 'npm';
115-
private _packageManagerCacheFolder: string;
116-
private _packageManagerTmpFolder: string;
120+
private _packageManager: PackageManager;
121+
private _pnpmStoreFolder: string;
122+
private _npmCacheFolder: string;
123+
private _npmTmpFolder: string;
117124
private _committedShrinkwrapFilename: string;
118125
private _tempShrinkwrapFilename: string;
119126
private _homeFolder: string;
@@ -268,7 +275,7 @@ export default class RushConfiguration {
268275
* _validateCommonRushConfigFolder() function makes sure that this folder only contains
269276
* recognized config files.
270277
*/
271-
private static _validateCommonRushConfigFolder(commonRushConfigFolder: string, packageManager: 'pnpm' | 'npm'): void {
278+
private static _validateCommonRushConfigFolder(commonRushConfigFolder: string, packageManager: PackageManager): void {
272279
if (!fsx.existsSync(commonRushConfigFolder)) {
273280
console.log(`Creating folder: ${commonRushConfigFolder}`);
274281
fsx.mkdirsSync(commonRushConfigFolder);
@@ -306,8 +313,10 @@ export default class RushConfiguration {
306313
}
307314
}
308315

309-
/** The name of the package manager being used to install dependencies */
310-
public get packageManager(): 'pnpm' | 'npm' {
316+
/**
317+
* The name of the package manager being used to install dependencies
318+
*/
319+
public get packageManager(): PackageManager {
311320
return this._packageManager;
312321
}
313322

@@ -371,7 +380,7 @@ export default class RushConfiguration {
371380
* Example: "C:\MyRepo\common\temp\npm-cache"
372381
*/
373382
public get npmCacheFolder(): string {
374-
return this._packageManagerCacheFolder;
383+
return this._npmCacheFolder;
375384
}
376385

377386
/**
@@ -382,7 +391,16 @@ export default class RushConfiguration {
382391
* Example: "C:\MyRepo\common\temp\npm-tmp"
383392
*/
384393
public get npmTmpFolder(): string {
385-
return this._packageManagerTmpFolder;
394+
return this._npmTmpFolder;
395+
}
396+
397+
/**
398+
* The local folder where PNPM stores a global installation for every installed package
399+
*
400+
* Example: "C:\MyRepo\common\temp\pnpm-store"
401+
*/
402+
public get pnpmStoreFolder(): string {
403+
return this._pnpmStoreFolder;
386404
}
387405

388406
/**
@@ -608,8 +626,9 @@ export default class RushConfiguration {
608626
this._commonRushConfigFolder = path.join(this._commonFolder, 'config', 'rush');
609627

610628
this._commonTempFolder = path.join(this._commonFolder, RushConstants.rushTempFolderName);
611-
this._packageManagerCacheFolder = path.resolve(path.join(this._commonTempFolder, 'packages-cache'));
612-
this._packageManagerTmpFolder = path.resolve(path.join(this._commonTempFolder, 'packages-tmp'));
629+
this._npmCacheFolder = path.resolve(path.join(this._commonTempFolder, 'npm-cache'));
630+
this._npmTmpFolder = path.resolve(path.join(this._commonTempFolder, 'npm-tmp'));
631+
this._pnpmStoreFolder = path.resolve(path.join(this._commonTempFolder, 'pnpm-store'));
613632

614633
this._changesFolder = path.join(this._commonFolder, RushConstants.changeFilesFolderName);
615634
this._homeFolder = RushConfiguration.getHomeDirectory();

‎apps/rush-lib/src/data/test/RushConfiguration.test.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ describe('RushConfiguration', () => {
3636
assertPathProperty('commonTempFolder',
3737
rushConfiguration.commonTempFolder, './repo/common/temp');
3838
assertPathProperty('npmCacheFolder',
39-
rushConfiguration.npmCacheFolder, './repo/common/temp/packages-cache');
39+
rushConfiguration.npmCacheFolder, './repo/common/temp/npm-cache');
4040
assertPathProperty('npmTmpFolder',
41-
rushConfiguration.npmTmpFolder, './repo/common/temp/packages-tmp');
41+
rushConfiguration.npmTmpFolder, './repo/common/temp/npm-tmp');
42+
assertPathProperty('pnpmStoreFolder',
43+
rushConfiguration.pnpmStoreFolder, './repo/common/temp/pnpm-store');
4244
assertPathProperty('packageManagerToolFilename',
4345
rushConfiguration.packageManagerToolFilename, './repo/common/temp/npm-local/node_modules/.bin/npm');
4446
assertPathProperty('rushJsonFolder',
@@ -97,9 +99,11 @@ describe('RushConfiguration', () => {
9799
assertPathProperty('commonTempFolder',
98100
rushConfiguration.commonTempFolder, './repo/common/temp');
99101
assertPathProperty('npmCacheFolder',
100-
rushConfiguration.npmCacheFolder, './repo/common/temp/packages-cache');
102+
rushConfiguration.npmCacheFolder, './repo/common/temp/npm-cache');
101103
assertPathProperty('npmTmpFolder',
102-
rushConfiguration.npmTmpFolder, './repo/common/temp/packages-tmp');
104+
rushConfiguration.npmTmpFolder, './repo/common/temp/npm-tmp');
105+
assertPathProperty('pnpmStoreFolder',
106+
rushConfiguration.pnpmStoreFolder, './repo/common/temp/pnpm-store');
103107
assertPathProperty('packageManagerToolFilename',
104108
rushConfiguration.packageManagerToolFilename, './repo/common/temp/pnpm-local/node_modules/.bin/pnpm');
105109
assertPathProperty('rushJsonFolder',

‎apps/rush-lib/src/index.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ export {
1111
} from './data/ApprovedPackagesPolicy';
1212

1313
export {
14-
default as RushConfiguration
14+
default as RushConfiguration,
15+
PackageManager
1516
} from './data/RushConfiguration';
1617

1718
export {

0 commit comments

Comments
 (0)