Skip to content

Commit ca3b70a

Browse files
committed
Improve docs
1 parent a8d8ca8 commit ca3b70a

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

apps/rush-lib/src/scripts/install-run.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,20 @@ function ensureAndJoinPath(baseFolder: string, ...pathSegments: string[]): strin
190190
return joinedPath;
191191
}
192192

193+
/**
194+
* As a workaround, _syncNpmrc() copies the .npmrc file to the target folder, and also trims
195+
* unusable lines from the .npmrc file. If the source .npmrc file not exist, then _syncNpmrc()
196+
* will delete an .npmrc that is found in the target folder.
197+
*
198+
* Why are we trimming the .npmrc lines? NPM allows environment variables to be specified in
199+
* the .npmrc file to provide different authentication tokens for different registry.
200+
* However, if the environment variable is undefined, it expands to an empty string, which
201+
* produces a valid-looking mapping with an invalid URL that causes an error. Instead,
202+
* we'd prefer to skip that line and continue looking in other places such as the user's
203+
* home directory.
204+
*
205+
* IMPORTANT: THIS CODE SHOULD BE KEPT UP TO DATE WITH Utilities._syncNpmrc()
206+
*/
193207
function syncNpmrc(sourceNpmrcFolder: string, targetNpmrcFolder: string): void {
194208
const sourceNpmrcPath: string = path.join(sourceNpmrcFolder, '.npmrc');
195209
const targetNpmrcPath: string = path.join(targetNpmrcFolder, '.npmrc');
@@ -216,6 +230,8 @@ function syncNpmrc(sourceNpmrcFolder: string, targetNpmrcFolder: string): void {
216230
}
217231

218232
if (lineShouldBeTrimmed) {
233+
// Example output:
234+
// "; MISSING ENVIRONMENT VARIABLE: //my-registry.com/npm/:_authToken=${MY_AUTH_TOKEN}"
219235
resultLines.push('; MISSING ENVIRONMENT VARIABLE: ' + line);
220236
} else {
221237
resultLines.push(line);

apps/rush-lib/src/utilities/Utilities.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -454,13 +454,16 @@ export class Utilities {
454454
}
455455

456456
/**
457-
* NPM allows environment variables to be specified in its .npmrc file. This can be
458-
* used to provide an authentication token for a registry. However if the environment variable
459-
* is undefined, it expands to an empty string, which produces a valid-looking mapping
460-
* with an invalid URL. As a workaround, _syncNpmrc() copies the .npmrc file to the
461-
* target folder and strips out any lines that reference undefined environment variables.
462-
* If the target folder does not exist, then _syncNpmrc() will delete an .npmrc that
463-
* is found there.
457+
* As a workaround, _syncNpmrc() copies the .npmrc file to the target folder, and also trims
458+
* unusable lines from the .npmrc file. If the source .npmrc file not exist, then _syncNpmrc()
459+
* will delete an .npmrc that is found in the target folder.
460+
*
461+
* Why are we trimming the .npmrc lines? NPM allows environment variables to be specified in
462+
* the .npmrc file to provide different authentication tokens for different registry.
463+
* However, if the environment variable is undefined, it expands to an empty string, which
464+
* produces a valid-looking mapping with an invalid URL that causes an error. Instead,
465+
* we'd prefer to skip that line and continue looking in other places such as the user's
466+
* home directory.
464467
*
465468
* IMPORTANT: THIS CODE SHOULD BE KEPT UP TO DATE WITH _syncNpmrc() FROM scripts/install-run.ts
466469
*/
@@ -491,6 +494,8 @@ export class Utilities {
491494
}
492495

493496
if (lineShouldBeTrimmed) {
497+
// Example output:
498+
// "; MISSING ENVIRONMENT VARIABLE: //my-registry.com/npm/:_authToken=${MY_AUTH_TOKEN}"
494499
resultLines.push('; MISSING ENVIRONMENT VARIABLE: ' + line);
495500
} else {
496501
resultLines.push(line);

0 commit comments

Comments
 (0)