Skip to content

Commit ae62698

Browse files
fzxeniclanton
andauthored
Support fallback syntax in .npmrc file (#5030)
* Support fallback syntax in .npmrc file * Simplify diff. * Simplify tests. * More minor cleanup. * fixup! More minor cleanup. * Add isPnpm property. * Only support fallback for pnpm. * Rush change. --------- Co-authored-by: Ian Clanton-Thuon <[email protected]>
1 parent 3f9aa73 commit ae62698

26 files changed

+481
-78
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/rush",
5+
"comment": "Support fallback syntax in `.npmrc` files if the package manager is PNPM. See https://pnpm.io/npmrc",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@microsoft/rush"
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/rush",
5+
"comment": "Add an `.isPnpm` property to `RushConfiguration` that is set to true if the package manager for the Rush repo is PNPM.",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@microsoft/rush"
10+
}

common/reviews/api/rush-lib.api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,7 @@ export class RushConfiguration {
12221222
readonly gitTagSeparator: string | undefined;
12231223
readonly gitVersionBumpCommitMessage: string | undefined;
12241224
readonly hotfixChangeEnabled: boolean;
1225+
readonly isPnpm: boolean;
12251226
static loadFromConfigurationFile(rushJsonFilename: string): RushConfiguration;
12261227
// (undocumented)
12271228
static loadFromDefaultLocation(options?: ITryFindRushJsonLocationOptions): RushConfiguration;

libraries/rush-lib/src/api/RushConfiguration.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,11 @@ export class RushConfiguration {
251251
*/
252252
public readonly packageManager!: PackageManagerName;
253253

254+
/**
255+
* If true, the repository is using PNPM as its package manager.
256+
*/
257+
public readonly isPnpm!: boolean;
258+
254259
/**
255260
* {@inheritdoc PackageManager}
256261
*
@@ -698,16 +703,20 @@ export class RushConfiguration {
698703
// TODO: Add an actual "packageManager" field in rush.json
699704
const packageManagerFields: string[] = [];
700705

706+
this.isPnpm = false;
701707
if (rushConfigurationJson.npmVersion) {
702708
this.packageManager = 'npm';
703709
this.packageManagerOptions = this.npmOptions;
704710
packageManagerFields.push('npmVersion');
705711
}
712+
706713
if (rushConfigurationJson.pnpmVersion) {
707714
this.packageManager = 'pnpm';
715+
this.isPnpm = true;
708716
this.packageManagerOptions = this.pnpmOptions;
709717
packageManagerFields.push('pnpmVersion');
710718
}
719+
711720
if (rushConfigurationJson.yarnVersion) {
712721
this.packageManager = 'yarn';
713722
this.packageManagerOptions = this.yarnOptions;

libraries/rush-lib/src/cli/RushXCommandLine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ export class RushXCommandLine {
224224
});
225225
const terminal: ITerminal = new Terminal(terminalProvider);
226226

227-
if (rushConfiguration?.packageManager === 'pnpm' && rushConfiguration?.experimentsConfiguration) {
227+
if (rushConfiguration?.isPnpm && rushConfiguration?.experimentsConfiguration) {
228228
const { configuration: experiments } = rushConfiguration?.experimentsConfiguration;
229229

230230
if (experiments?.usePnpmSyncForInjectedDependencies) {

libraries/rush-lib/src/cli/actions/DeployAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export class DeployAction extends BaseRushAction {
159159
}
160160

161161
const projects: RushConfigurationProject[] = this.rushConfiguration.projects;
162-
if (this.rushConfiguration.packageManager === 'pnpm') {
162+
if (this.rushConfiguration.isPnpm) {
163163
const currentlyInstalledVariant: string | undefined =
164164
await this.rushConfiguration.getCurrentlyInstalledVariantAsync();
165165
for (const project of projects) {

libraries/rush-lib/src/cli/actions/InstallAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class InstallAction extends BaseInstallAction {
4949
description: `Only check the validity of the shrinkwrap file without performing an install.`
5050
});
5151

52-
if (this.rushConfiguration?.packageManager === 'pnpm') {
52+
if (this.rushConfiguration?.isPnpm) {
5353
this._resolutionOnlyParameter = this.defineFlagParameter({
5454
parameterLongName: '--resolution-only',
5555
description: `Only perform dependency resolution, useful for ensuring peer dependendencies are up to date. Note that this flag is only supported when using the pnpm package manager.`

libraries/rush-lib/src/cli/actions/PublishAction.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ export class PublishAction extends BaseRushAction {
239239

240240
this._validate();
241241

242-
this._addNpmPublishHome();
242+
this._addNpmPublishHome(this.rushConfiguration.isPnpm);
243243

244244
const git: Git = new Git(this.rushConfiguration);
245245
const publishGit: PublishGit = new PublishGit(git, this._targetBranch.value);
@@ -455,7 +455,7 @@ export class PublishAction extends BaseRushAction {
455455
args.push(`--access`, this._npmAccessLevel.value);
456456
}
457457

458-
if (this.rushConfiguration.packageManager === 'pnpm') {
458+
if (this.rushConfiguration.isPnpm) {
459459
// PNPM 4.11.0 introduced a feature that may interrupt publishing and prompt the user for input.
460460
// See this issue for details: https://github.com/microsoft/rushstack/issues/1940
461461
args.push('--no-git-checks');
@@ -582,15 +582,16 @@ export class PublishAction extends BaseRushAction {
582582
}
583583
}
584584

585-
private _addNpmPublishHome(): void {
585+
private _addNpmPublishHome(supportEnvVarFallbackSyntax: boolean): void {
586586
// Create "common\temp\publish-home" folder, if it doesn't exist
587587
Utilities.createFolderWithRetry(this._targetNpmrcPublishFolder);
588588

589589
// Copy down the committed "common\config\rush\.npmrc-publish" file, if there is one
590590
Utilities.syncNpmrc({
591591
sourceNpmrcFolder: this.rushConfiguration.commonRushConfigFolder,
592592
targetNpmrcFolder: this._targetNpmrcPublishFolder,
593-
useNpmrcPublish: true
593+
useNpmrcPublish: true,
594+
supportEnvVarFallbackSyntax
594595
});
595596
}
596597

libraries/rush-lib/src/cli/scriptActions/PhasedScriptAction.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,10 +466,7 @@ export class PhasedScriptAction extends BaseScriptAction<IPhasedCommandConfig> {
466466
}
467467

468468
const { configuration: experiments } = this.rushConfiguration.experimentsConfiguration;
469-
if (
470-
this.rushConfiguration?.packageManager === 'pnpm' &&
471-
experiments?.usePnpmSyncForInjectedDependencies
472-
) {
469+
if (this.rushConfiguration?.isPnpm && experiments?.usePnpmSyncForInjectedDependencies) {
473470
const { PnpmSyncCopyOperationPlugin } = await import(
474471
'../../logic/operations/PnpmSyncCopyOperationPlugin'
475472
);

libraries/rush-lib/src/logic/Autoinstaller.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ export class Autoinstaller {
137137
// Copy: .../common/autoinstallers/my-task/.npmrc
138138
Utilities.syncNpmrc({
139139
sourceNpmrcFolder: this._rushConfiguration.commonRushConfigFolder,
140-
targetNpmrcFolder: autoinstallerFullPath
140+
targetNpmrcFolder: autoinstallerFullPath,
141+
supportEnvVarFallbackSyntax: this._rushConfiguration.isPnpm
141142
});
142143

143144
this._logIfConsoleOutputIsNotRestricted(
@@ -193,7 +194,7 @@ export class Autoinstaller {
193194
oldFileContents = FileSystem.readFile(this.shrinkwrapFilePath, { convertLineEndings: NewlineKind.Lf });
194195
this._logIfConsoleOutputIsNotRestricted('Deleting ' + this.shrinkwrapFilePath);
195196
await FileSystem.deleteFileAsync(this.shrinkwrapFilePath);
196-
if (this._rushConfiguration.packageManager === 'pnpm') {
197+
if (this._rushConfiguration.isPnpm) {
197198
// Workaround for https://github.com/pnpm/pnpm/issues/1890
198199
//
199200
// When "rush update-autoinstaller" is run, Rush deletes "common/autoinstallers/my-task/pnpm-lock.yaml"
@@ -222,7 +223,8 @@ export class Autoinstaller {
222223

223224
Utilities.syncNpmrc({
224225
sourceNpmrcFolder: this._rushConfiguration.commonRushConfigFolder,
225-
targetNpmrcFolder: this.folderFullPath
226+
targetNpmrcFolder: this.folderFullPath,
227+
supportEnvVarFallbackSyntax: this._rushConfiguration.isPnpm
226228
});
227229

228230
await Utilities.executeCommandAsync({

0 commit comments

Comments
 (0)