Skip to content

Commit 7702db7

Browse files
author
Nick Pape
committed
Update RushConfiguration to allow for switching to pnpm
1 parent 9b7b99a commit 7702db7

6 files changed

Lines changed: 167 additions & 23 deletions

File tree

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ export namespace RushConstants {
5858
*/
5959
export const npmShrinkwrapFilename: string = 'npm-shrinkwrap.json';
6060

61+
/**
62+
* The filename ("shrinkwrap.yaml") used to store state for pnpm
63+
*/
64+
export const pnpmShrinkwrapFilename: string = 'shrinkwrap.yaml';
65+
6166
/**
6267
* The folder name ("node_modules") where NPM installs its packages.
6368
*/

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

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ export interface IRushRepositoryJson {
7171
*/
7272
export interface IRushConfigurationJson {
7373
$schema: string;
74-
npmVersion: string;
74+
npmVersion?: string;
75+
pnpmVersion?: string;
7576
rushMinimumVersion: string;
7677
repository?: IRushRepositoryJson;
7778
nodeSupportedVersionRange?: string;
@@ -108,14 +109,15 @@ export default class RushConfiguration {
108109
private _commonFolder: string;
109110
private _commonTempFolder: string;
110111
private _commonRushConfigFolder: string;
111-
private _npmCacheFolder: string;
112-
private _npmTmpFolder: string;
112+
private _packageManager: 'pnpm' | 'npm';
113+
private _packageManagerCacheFolder: string;
114+
private _packageManagerTmpFolder: string;
113115
private _committedShrinkwrapFilename: string;
114116
private _tempShrinkwrapFilename: string;
115117
private _homeFolder: string;
116118
private _rushLinkJsonFilename: string;
117-
private _npmToolVersion: string;
118-
private _npmToolFilename: string;
119+
private _packageManagerToolVersion: string;
120+
private _packageManagerToolFilename: string;
119121
private _projectFolderMinDepth: number;
120122
private _projectFolderMaxDepth: number;
121123

@@ -261,6 +263,10 @@ export default class RushConfiguration {
261263
}
262264
}
263265

266+
public get packageManager(): 'pnpm' | 'npm' {
267+
return this._packageManager;
268+
}
269+
264270
/**
265271
* The Rush configuration file
266272
*/
@@ -321,7 +327,7 @@ export default class RushConfiguration {
321327
* Example: "C:\MyRepo\common\temp\npm-cache"
322328
*/
323329
public get npmCacheFolder(): string {
324-
return this._npmCacheFolder;
330+
return this._packageManagerCacheFolder;
325331
}
326332

327333
/**
@@ -332,14 +338,14 @@ export default class RushConfiguration {
332338
* Example: "C:\MyRepo\common\temp\npm-tmp"
333339
*/
334340
public get npmTmpFolder(): string {
335-
return this._npmTmpFolder;
341+
return this._packageManagerTmpFolder;
336342
}
337343

338344
/**
339345
* The filename of the NPM shrinkwrap file that is tracked e.g. by Git. (The "rush install"
340346
* command uses a temporary copy, whose path is tempShrinkwrapFilename.)
341347
* This property merely reports the filename; the file itself may not actually exist.
342-
* Example: "C:\MyRepo\common\npm-shrinkwrap.json"
348+
* Example: "C:\MyRepo\common\npm-shrinkwrap.json" or "C:\MyRepo\common\shrinkwrap.yaml"
343349
*/
344350
public get committedShrinkwrapFilename(): string {
345351
return this._committedShrinkwrapFilename;
@@ -349,7 +355,7 @@ export default class RushConfiguration {
349355
* The filename of the temporary NPM shrinkwrap file that is used by "rush install".
350356
* (The master copy is tempShrinkwrapFilename.)
351357
* This property merely reports the filename; the file itself may not actually exist.
352-
* Example: "C:\MyRepo\common\temp\npm-shrinkwrap.json"
358+
* Example: "C:\MyRepo\common\temp\npm-shrinkwrap.json" or "C:\MyRepo\common\temp\shrinkwrap.yaml"
353359
*/
354360
public get tempShrinkwrapFilename(): string {
355361
return this._tempShrinkwrapFilename;
@@ -378,7 +384,7 @@ export default class RushConfiguration {
378384
* The version of the locally installed NPM tool. (Example: "1.2.3")
379385
*/
380386
public get npmToolVersion(): string {
381-
return this._npmToolVersion;
387+
return this._packageManagerToolVersion;
382388
}
383389

384390
/**
@@ -387,7 +393,7 @@ export default class RushConfiguration {
387393
* Example: "C:\MyRepo\common\temp\npm-local\node_modules\.bin\npm"
388394
*/
389395
public get npmToolFilename(): string {
390-
return this._npmToolFilename;
396+
return this._packageManagerToolFilename;
391397
}
392398

393399
/**
@@ -559,14 +565,11 @@ export default class RushConfiguration {
559565
RushConfiguration._validateCommonRushConfigFolder(this._commonRushConfigFolder);
560566

561567
this._commonTempFolder = path.join(this._commonFolder, RushConstants.rushTempFolderName);
562-
this._npmCacheFolder = path.resolve(path.join(this._commonTempFolder, 'npm-cache'));
563-
this._npmTmpFolder = path.resolve(path.join(this._commonTempFolder, 'npm-tmp'));
568+
this._packageManagerCacheFolder = path.resolve(path.join(this._commonTempFolder, 'packages-cache'));
569+
this._packageManagerTmpFolder = path.resolve(path.join(this._commonTempFolder, 'packages-tmp'));
564570

565571
this._changesFolder = path.join(this._commonFolder, RushConstants.changeFilesFolderName);
566572

567-
this._committedShrinkwrapFilename = path.join(this._commonRushConfigFolder, RushConstants.npmShrinkwrapFilename);
568-
this._tempShrinkwrapFilename = path.join(this._commonTempFolder, RushConstants.npmShrinkwrapFilename);
569-
570573
const unresolvedUserFolder: string = process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME'];
571574
this._homeFolder = path.resolve(unresolvedUserFolder);
572575
if (!fsx.existsSync(this._homeFolder)) {
@@ -575,9 +578,29 @@ export default class RushConfiguration {
575578

576579
this._rushLinkJsonFilename = path.join(this._commonTempFolder, 'rush-link.json');
577580

578-
this._npmToolVersion = rushConfigurationJson.npmVersion;
579-
this._npmToolFilename = path.resolve(path.join(this._commonTempFolder,
580-
'npm-local', 'node_modules', '.bin', 'npm'));
581+
if (rushConfigurationJson.npmVersion) {
582+
this._packageManager = 'npm';
583+
584+
this._committedShrinkwrapFilename = path.join(this._commonRushConfigFolder, RushConstants.npmShrinkwrapFilename);
585+
this._tempShrinkwrapFilename = path.join(this._commonTempFolder, RushConstants.npmShrinkwrapFilename);
586+
587+
this._packageManagerToolVersion = rushConfigurationJson.npmVersion;
588+
this._packageManagerToolFilename = path.resolve(path.join(this._commonTempFolder,
589+
'npm-local', 'node_modules', '.bin', 'npm'));
590+
591+
} else if (rushConfigurationJson.pnpmVersion) {
592+
this._packageManager = 'pnpm';
593+
594+
this._committedShrinkwrapFilename = path.join(this._commonRushConfigFolder, RushConstants.pnpmShrinkwrapFilename);
595+
this._tempShrinkwrapFilename = path.join(this._commonTempFolder, RushConstants.pnpmShrinkwrapFilename);
596+
597+
this._packageManagerToolVersion = rushConfigurationJson.pnpmVersion;
598+
this._packageManagerToolFilename = path.resolve(path.join(this._commonTempFolder,
599+
'pnpm-local', 'node_modules', '.bin', 'pnpm'));
600+
601+
} else {
602+
throw new Error(`Neither "npmVersion" nor "pnpmVersion" was defined in the rush configuration.`);
603+
}
581604

582605
this._projectFolderMinDepth = rushConfigurationJson.projectFolderMinDepth !== undefined
583606
? rushConfigurationJson.projectFolderMinDepth : 1;

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

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ function assertPathProperty(validatedPropertyName: string, absolutePath: string,
2222

2323
describe('RushConfiguration', () => {
2424

25-
it('can load repo/rush.json', (done: MochaDone) => {
26-
const rushFilename: string = path.resolve(__dirname, 'repo', 'rush.json');
25+
it('can load repo/rush-npm.json', (done: MochaDone) => {
26+
const rushFilename: string = path.resolve(__dirname, 'repo', 'rush-npm.json');
2727
const rushConfiguration: RushConfiguration = RushConfiguration.loadFromConfigurationFile(rushFilename);
2828

29+
assert.equal(rushConfiguration.packageManager, 'npm');
2930
assertPathProperty('committedShrinkwrapFilename',
3031
rushConfiguration.committedShrinkwrapFilename, './repo/common/config/rush/npm-shrinkwrap.json');
3132
assertPathProperty('commonFolder',
@@ -35,9 +36,9 @@ describe('RushConfiguration', () => {
3536
assertPathProperty('commonTempFolder',
3637
rushConfiguration.commonTempFolder, './repo/common/temp');
3738
assertPathProperty('npmCacheFolder',
38-
rushConfiguration.npmCacheFolder, './repo/common/temp/npm-cache');
39+
rushConfiguration.npmCacheFolder, './repo/common/temp/packages-cache');
3940
assertPathProperty('npmTmpFolder',
40-
rushConfiguration.npmTmpFolder, './repo/common/temp/npm-tmp');
41+
rushConfiguration.npmTmpFolder, './repo/common/temp/packages-tmp');
4142
assertPathProperty('npmToolFilename',
4243
rushConfiguration.npmToolFilename, './repo/common/temp/npm-local/node_modules/.bin/npm');
4344
assertPathProperty('rushJsonFolder',
@@ -81,4 +82,65 @@ describe('RushConfiguration', () => {
8182

8283
done();
8384
});
85+
86+
it('can load repo/rush-pnpm.json', (done: MochaDone) => {
87+
const rushFilename: string = path.resolve(__dirname, 'repo', 'rush-pnpm.json');
88+
const rushConfiguration: RushConfiguration = RushConfiguration.loadFromConfigurationFile(rushFilename);
89+
90+
assert.equal(rushConfiguration.packageManager, 'pnpm');
91+
assertPathProperty('committedShrinkwrapFilename',
92+
rushConfiguration.committedShrinkwrapFilename, './repo/common/config/rush/shrinkwrap.yaml');
93+
assertPathProperty('commonFolder',
94+
rushConfiguration.commonFolder, './repo/common');
95+
assertPathProperty('commonRushConfigFolder',
96+
rushConfiguration.commonRushConfigFolder, './repo/common/config/rush');
97+
assertPathProperty('commonTempFolder',
98+
rushConfiguration.commonTempFolder, './repo/common/temp');
99+
assertPathProperty('npmCacheFolder',
100+
rushConfiguration.npmCacheFolder, './repo/common/temp/packages-cache');
101+
assertPathProperty('npmTmpFolder',
102+
rushConfiguration.npmTmpFolder, './repo/common/temp/packages-tmp');
103+
assertPathProperty('npmToolFilename',
104+
rushConfiguration.npmToolFilename, './repo/common/temp/pnpm-local/node_modules/.bin/pnpm');
105+
assertPathProperty('rushJsonFolder',
106+
rushConfiguration.rushJsonFolder, './repo');
107+
assertPathProperty('rushLinkJsonFilename',
108+
rushConfiguration.rushLinkJsonFilename, './repo/common/temp/rush-link.json');
109+
110+
assert.equal(rushConfiguration.npmToolVersion, '4.5.0', 'Failed to validate npmToolVersion');
111+
112+
assert.equal(rushConfiguration.repositoryUrl, 'someFakeUrl', 'Failed to get repository url');
113+
assert.equal(rushConfiguration.projectFolderMaxDepth, 99, 'Failed to validate projectFolderMaxDepth');
114+
assert.equal(rushConfiguration.projectFolderMinDepth, 1, 'Failed to validate projectFolderMinDepth');
115+
116+
assert.equal(rushConfiguration.projects.length, 3);
117+
118+
// "approvedPackagesPolicy" feature
119+
const approvedPackagesPolicy: ApprovedPackagesPolicy = rushConfiguration.approvedPackagesPolicy;
120+
assert.isTrue(approvedPackagesPolicy.enabled, 'Failed to validate approvedPackagesPolicy.enabled');
121+
assert.deepEqual(Utilities.getSetAsArray(approvedPackagesPolicy.reviewCategories),
122+
[ 'first-party', 'third-party', 'prototype' ],
123+
'Failed to validate approvedPackagesPolicy.reviewCategories');
124+
assert.deepEqual(Utilities.getSetAsArray(approvedPackagesPolicy.ignoredNpmScopes),
125+
[ '@types', '@internal' ],
126+
'Failed to validate approvedPackagesPolicy.ignoredNpmScopes');
127+
128+
assert.equal(approvedPackagesPolicy.browserApprovedPackages.items[0].packageName, 'example',
129+
'Failed to validate browserApprovedPackages.items[0]');
130+
assert.equal(approvedPackagesPolicy.browserApprovedPackages.items[0].allowedCategories.size, 3,
131+
'Failed to validate browserApprovedPackages.items[0]');
132+
133+
assert.isNotTrue(rushConfiguration.telemetryEnabled);
134+
135+
// Validate project1 settings
136+
const project1: RushConfigurationProject = rushConfiguration.getProjectByName('project1')!;
137+
assert.ok(project1, 'Failed to find project1');
138+
139+
assert.equal(project1.packageName, 'project1', 'Failed to validate project1.packageName');
140+
assertPathProperty('project1.projectFolder', project1.projectFolder, './repo/project1');
141+
assert.equal(project1.tempProjectName, '@rush-temp/project1', 'Failed to validate project1.tempProjectName');
142+
assert.equal(project1.unscopedTempProjectName, 'project1');
143+
144+
done();
145+
});
84146
});
File renamed without changes.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"pnpmVersion": "4.5.0",
3+
"rushMinimumVersion": "2.5.0",
4+
"nodeSupportedVersionRange": ">=6.9.0 <7.0.0",
5+
"projectFolderMinDepth": 1,
6+
"projectFolderMaxDepth": 99,
7+
8+
"approvedPackagesPolicy": {
9+
"reviewCategories": [ "first-party", "third-party", "prototype" ],
10+
"ignoredNpmScopes": [ "@types", "@internal" ]
11+
},
12+
13+
"repository": {
14+
"url": "someFakeUrl"
15+
},
16+
17+
"gitPolicy": {
18+
"allowedEmailRegExps": [
19+
"[^@]+@contoso\\.com"
20+
],
21+
"sampleEmail": "mrexample@contoso.com"
22+
},
23+
24+
"eventHooks": {
25+
"postRushBuild": [
26+
"do something"
27+
]
28+
},
29+
30+
"projects": [
31+
32+
{
33+
"packageName": "project1",
34+
"projectFolder": "project1",
35+
"reviewCategory": "third-party"
36+
},
37+
38+
{
39+
"packageName": "project2",
40+
"projectFolder": "project2",
41+
"reviewCategory": "third-party"
42+
},
43+
44+
{
45+
"packageName": "project3",
46+
"projectFolder": "project3",
47+
"reviewCategory": "prototype"
48+
}
49+
]
50+
}

‎common/reviews/api/rush-lib.api.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,8 @@ class RushConfiguration {
312312
public readonly npmTmpFolder: string;
313313
public readonly npmToolFilename: string;
314314
public readonly npmToolVersion: string;
315+
// (undocumented)
316+
public readonly packageManager: 'pnpm' | 'npm';
315317
public readonly pinnedVersions: PinnedVersionsConfiguration;
316318
public readonly projectFolderMaxDepth: number;
317319
public readonly projectFolderMinDepth: number;
@@ -371,6 +373,8 @@ module RushConstants {
371373

372374
pinnedVersionsFilename: string = 'pinned-versions.json';
373375

376+
pnpmShrinkwrapFilename: string = 'shrinkwrap.yaml';
377+
374378
rushTempFolderName: string = 'temp';
375379

376380
rushTempNpmScope: string = '@rush-temp';

0 commit comments

Comments
 (0)