@@ -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