Skip to content

Commit 8b1cebf

Browse files
author
Nick Pape
committed
More changes
1 parent 452b168 commit 8b1cebf

9 files changed

Lines changed: 113 additions & 91 deletions

File tree

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { VersionPolicyConfiguration } from './VersionPolicyConfiguration';
2121
*/
2222
const knownRushConfigFilenames: string[] = [
2323
'.npmrc',
24-
RushConstants.npmShrinkwrapFilename,
2524
RushConstants.pinnedVersionsFilename,
2625
RushConstants.browserApprovedPackagesFilename,
2726
RushConstants.nonbrowserApprovedPackagesFilename,
@@ -230,7 +229,7 @@ export default class RushConfiguration {
230229
* _validateCommonRushConfigFolder() function makes sure that this folder only contains
231230
* recognized config files.
232231
*/
233-
private static _validateCommonRushConfigFolder(commonRushConfigFolder: string): void {
232+
private static _validateCommonRushConfigFolder(commonRushConfigFolder: string, packageManager: 'pnpm' | 'npm'): void {
234233
if (!fsx.existsSync(commonRushConfigFolder)) {
235234
console.log(`Creating folder: ${commonRushConfigFolder}`);
236235
fsx.mkdirsSync(commonRushConfigFolder);
@@ -254,6 +253,11 @@ export default class RushConfiguration {
254253
}
255254

256255
const knownSet: Set<string> = new Set<string>(knownRushConfigFilenames.map(x => x.toUpperCase()));
256+
if (packageManager === 'npm') {
257+
knownSet.add(RushConstants.npmShrinkwrapFilename.toUpperCase());
258+
} else {
259+
knownSet.add(RushConstants.pnpmShrinkwrapFilename.toUpperCase());
260+
}
257261

258262
// Is the filename something we know? If not, report an error.
259263
if (!knownSet.has(filename.toUpperCase())) {
@@ -383,7 +387,7 @@ export default class RushConfiguration {
383387
/**
384388
* The version of the locally installed NPM tool. (Example: "1.2.3")
385389
*/
386-
public get npmToolVersion(): string {
390+
public get packageManagerToolVersion(): string {
387391
return this._packageManagerToolVersion;
388392
}
389393

@@ -392,7 +396,7 @@ export default class RushConfiguration {
392396
* been run, then this file may not exist yet.
393397
* Example: "C:\MyRepo\common\temp\npm-local\node_modules\.bin\npm"
394398
*/
395-
public get npmToolFilename(): string {
399+
public get packageManagerToolFilename(): string {
396400
return this._packageManagerToolFilename;
397401
}
398402

@@ -562,7 +566,6 @@ export default class RushConfiguration {
562566
this._commonFolder = path.resolve(path.join(this._rushJsonFolder, RushConstants.commonFolderName));
563567

564568
this._commonRushConfigFolder = path.join(this._commonFolder, 'config', 'rush');
565-
RushConfiguration._validateCommonRushConfigFolder(this._commonRushConfigFolder);
566569

567570
this._commonTempFolder = path.join(this._commonFolder, RushConstants.rushTempFolderName);
568571
this._packageManagerCacheFolder = path.resolve(path.join(this._commonTempFolder, 'packages-cache'));
@@ -602,6 +605,8 @@ export default class RushConfiguration {
602605
throw new Error(`Neither "npmVersion" nor "pnpmVersion" was defined in the rush configuration.`);
603606
}
604607

608+
RushConfiguration._validateCommonRushConfigFolder(this._commonRushConfigFolder);
609+
605610
this._projectFolderMinDepth = rushConfigurationJson.projectFolderMinDepth !== undefined
606611
? rushConfigurationJson.projectFolderMinDepth : 1;
607612
if (this._projectFolderMinDepth < 1) {

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ describe('RushConfiguration', () => {
3939
rushConfiguration.npmCacheFolder, './repo/common/temp/packages-cache');
4040
assertPathProperty('npmTmpFolder',
4141
rushConfiguration.npmTmpFolder, './repo/common/temp/packages-tmp');
42-
assertPathProperty('npmToolFilename',
43-
rushConfiguration.npmToolFilename, './repo/common/temp/npm-local/node_modules/.bin/npm');
42+
assertPathProperty('packageManagerToolFilename',
43+
rushConfiguration.packageManagerToolFilename, './repo/common/temp/npm-local/node_modules/.bin/npm');
4444
assertPathProperty('rushJsonFolder',
4545
rushConfiguration.rushJsonFolder, './repo');
4646
assertPathProperty('rushLinkJsonFilename',
4747
rushConfiguration.rushLinkJsonFilename, './repo/common/temp/rush-link.json');
4848

49-
assert.equal(rushConfiguration.npmToolVersion, '4.5.0', 'Failed to validate npmToolVersion');
49+
assert.equal(rushConfiguration.packageManagerToolVersion, '4.5.0', 'Failed to validate packageManagerToolVersion');
5050

5151
assert.equal(rushConfiguration.repositoryUrl, 'someFakeUrl', 'Failed to get repository url');
5252
assert.equal(rushConfiguration.projectFolderMaxDepth, 99, 'Failed to validate projectFolderMaxDepth');
@@ -100,14 +100,14 @@ describe('RushConfiguration', () => {
100100
rushConfiguration.npmCacheFolder, './repo/common/temp/packages-cache');
101101
assertPathProperty('npmTmpFolder',
102102
rushConfiguration.npmTmpFolder, './repo/common/temp/packages-tmp');
103-
assertPathProperty('npmToolFilename',
104-
rushConfiguration.npmToolFilename, './repo/common/temp/pnpm-local/node_modules/.bin/pnpm');
103+
assertPathProperty('packageManagerToolFilename',
104+
rushConfiguration.packageManagerToolFilename, './repo/common/temp/pnpm-local/node_modules/.bin/pnpm');
105105
assertPathProperty('rushJsonFolder',
106106
rushConfiguration.rushJsonFolder, './repo');
107107
assertPathProperty('rushLinkJsonFilename',
108108
rushConfiguration.rushLinkJsonFilename, './repo/common/temp/rush-link.json');
109109

110-
assert.equal(rushConfiguration.npmToolVersion, '4.5.0', 'Failed to validate npmToolVersion');
110+
assert.equal(rushConfiguration.packageManagerToolVersion, '4.5.0', 'Failed to validate packageManagerToolVersion');
111111

112112
assert.equal(rushConfiguration.repositoryUrl, 'someFakeUrl', 'Failed to get repository url');
113113
assert.equal(rushConfiguration.projectFolderMaxDepth, 99, 'Failed to validate projectFolderMaxDepth');

‎apps/rush/src/actions/GenerateAction.ts‎

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,12 @@ export default class GenerateAction extends BaseRushAction {
6767

6868
const installManager: InstallManager = new InstallManager(this.rushConfiguration);
6969

70+
const committedShrinkwrapFilename: string = this.rushConfiguration.committedShrinkwrapFilename;
71+
const tempShrinkwrapFilename: string = this.rushConfiguration.tempShrinkwrapFilename;
72+
7073
try {
7174
const shrinkwrapFile: ShrinkwrapFile | undefined
72-
= ShrinkwrapFile.loadFromFile(this.rushConfiguration.committedShrinkwrapFilename);
75+
= ShrinkwrapFile.loadFromFile(committedShrinkwrapFilename);
7376

7477
if (shrinkwrapFile
7578
&& !this._forceParameter.value
@@ -86,17 +89,17 @@ export default class GenerateAction extends BaseRushAction {
8689
console.log('There was a problem reading the shrinkwrap file. Proceeeding with "rush generate".');
8790
}
8891

89-
installManager.ensureLocalNpmTool(false);
92+
installManager.ensureLocalPackageManager(false);
9093

9194
installManager.createTempModules();
9295

9396
// Delete both copies of the shrinkwrap file
94-
if (fsx.existsSync(this.rushConfiguration.committedShrinkwrapFilename)) {
95-
console.log(os.EOL + 'Deleting ' + this.rushConfiguration.committedShrinkwrapFilename);
96-
fsx.unlinkSync(this.rushConfiguration.committedShrinkwrapFilename);
97+
if (fsx.existsSync(committedShrinkwrapFilename)) {
98+
console.log(os.EOL + 'Deleting ' + committedShrinkwrapFilename);
99+
fsx.unlinkSync(committedShrinkwrapFilename);
97100
}
98-
if (fsx.existsSync(this.rushConfiguration.tempShrinkwrapFilename)) {
99-
fsx.unlinkSync(this.rushConfiguration.tempShrinkwrapFilename);
101+
if (fsx.existsSync(tempShrinkwrapFilename)) {
102+
fsx.unlinkSync(tempShrinkwrapFilename);
100103
}
101104

102105
if (isLazy) {
@@ -107,20 +110,27 @@ export default class GenerateAction extends BaseRushAction {
107110
// Do an incremental install
108111
installManager.installCommonModules(InstallType.Normal);
109112

110-
console.log(os.EOL + colors.bold('(Skipping "npm shrinkwrap")') + os.EOL);
113+
if (this.rushConfiguration.packageManager === 'npm') {
114+
console.log(os.EOL + colors.bold('(Skipping "npm shrinkwrap")') + os.EOL);
115+
} else if (this.rushConfiguration.packageManager === 'pnpm') {
116+
console.log(os.EOL + colors.bold('(Deleting "shrinkwrap.yaml")') + os.EOL);
117+
fsx.unlinkSync(tempShrinkwrapFilename);
118+
}
111119
} else {
112120
// Do a clean install
113121
installManager.installCommonModules(InstallType.ForceClean);
114122

115-
console.log(os.EOL + colors.bold('Running "npm shrinkwrap"...'));
116-
const npmArgs: string [] = ['shrinkwrap'];
117-
installManager.pushConfigurationNpmArgs(npmArgs);
118-
Utilities.executeCommand(this.rushConfiguration.npmToolFilename,
119-
npmArgs, this.rushConfiguration.commonTempFolder);
120-
console.log('"npm shrinkwrap" completed' + os.EOL);
123+
if (this.rushConfiguration.packageManager === 'npm') {
124+
console.log(os.EOL + colors.bold('Running "npm shrinkwrap"...'));
125+
const npmArgs: string[] = ['shrinkwrap'];
126+
installManager.pushConfigurationArgs(npmArgs);
127+
Utilities.executeCommand(this.rushConfiguration.packageManagerToolFilename,
128+
npmArgs, this.rushConfiguration.commonTempFolder);
129+
console.log('"npm shrinkwrap" completed' + os.EOL);
130+
}
121131

122132
// Copy (or delete) common\temp\npm-shrinkwrap.json --> common\npm-shrinkwrap.json
123-
installManager.syncFile(this.rushConfiguration.tempShrinkwrapFilename,
133+
installManager.syncFile(tempShrinkwrapFilename,
124134
this.rushConfiguration.committedShrinkwrapFilename);
125135

126136
// The flag file is normally created by installCommonModules(), but "rush install" will

‎apps/rush/src/actions/InstallAction.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export default class InstallAction extends BaseRushAction {
8181
try {
8282
const installManager: InstallManager = new InstallManager(this.rushConfiguration);
8383

84-
installManager.ensureLocalNpmTool(this._cleanInstallFull.value);
84+
installManager.ensureLocalPackageManager(this._cleanInstallFull.value);
8585

8686
const shrinkwrapFile: ShrinkwrapFile | undefined
8787
= ShrinkwrapFile.loadFromFile(this.rushConfiguration.committedShrinkwrapFilename);

‎apps/rush/src/actions/PublishAction.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ export default class PublishAction extends BaseRushAction {
270270

271271
PublishUtilities.execCommand(
272272
!!this._publish.value,
273-
this.rushConfiguration.npmToolFilename,
273+
this.rushConfiguration.packageManagerToolFilename,
274274
args,
275275
packagePath,
276276
env);

0 commit comments

Comments
 (0)