From d4724be37f55e551398686c5c7a00b52b2344cfe Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Wed, 20 May 2020 13:25:56 -0700 Subject: [PATCH] Update rush (#9032) --- common/scripts/install-run.js | 80 ++++++++++++++++++++--------------- rush.json | 2 +- 2 files changed, 46 insertions(+), 36 deletions(-) diff --git a/common/scripts/install-run.js b/common/scripts/install-run.js index 028baedd8e60..670a9637a56f 100644 --- a/common/scripts/install-run.js +++ b/common/scripts/install-run.js @@ -47,9 +47,8 @@ function _parsePackageSpecifier(rawPackageSpecifier) { return { name, version }; } /** - * As a workaround, _syncNpmrc() copies the .npmrc file to the target folder, and also trims - * unusable lines from the .npmrc file. If the source .npmrc file not exist, then _syncNpmrc() - * will delete an .npmrc that is found in the target folder. + * As a workaround, copyAndTrimNpmrcFile() copies the .npmrc file to the target folder, and also trims + * unusable lines from the .npmrc file. * * Why are we trimming the .npmrc lines? NPM allows environment variables to be specified in * the .npmrc file to provide different authentication tokens for different registry. @@ -58,45 +57,56 @@ function _parsePackageSpecifier(rawPackageSpecifier) { * we'd prefer to skip that line and continue looking in other places such as the user's * home directory. * + * IMPORTANT: THIS CODE SHOULD BE KEPT UP TO DATE WITH Utilities._copyNpmrcFile() + */ +function _copyAndTrimNpmrcFile(sourceNpmrcPath, targetNpmrcPath) { + console.log(`Copying ${sourceNpmrcPath} --> ${targetNpmrcPath}`); // Verbose + let npmrcFileLines = fs.readFileSync(sourceNpmrcPath).toString().split('\n'); + npmrcFileLines = npmrcFileLines.map((line) => (line || '').trim()); + const resultLines = []; + // Trim out lines that reference environment variables that aren't defined + for (const line of npmrcFileLines) { + // This finds environment variable tokens that look like "${VAR_NAME}" + const regex = /\$\{([^\}]+)\}/g; + const environmentVariables = line.match(regex); + let lineShouldBeTrimmed = false; + if (environmentVariables) { + for (const token of environmentVariables) { + // Remove the leading "${" and the trailing "}" from the token + const environmentVariableName = token.substring(2, token.length - 1); + if (!process.env[environmentVariableName]) { + lineShouldBeTrimmed = true; + break; + } + } + } + if (lineShouldBeTrimmed) { + // Example output: + // "; MISSING ENVIRONMENT VARIABLE: //my-registry.com/npm/:_authToken=${MY_AUTH_TOKEN}" + resultLines.push('; MISSING ENVIRONMENT VARIABLE: ' + line); + } + else { + resultLines.push(line); + } + } + fs.writeFileSync(targetNpmrcPath, resultLines.join(os.EOL)); +} +/** + * syncNpmrc() copies the .npmrc file to the target folder, and also trims unusable lines from the .npmrc file. + * If the source .npmrc file not exist, then syncNpmrc() will delete an .npmrc that is found in the target folder. + * * IMPORTANT: THIS CODE SHOULD BE KEPT UP TO DATE WITH Utilities._syncNpmrc() */ -function _syncNpmrc(sourceNpmrcFolder, targetNpmrcFolder) { - const sourceNpmrcPath = path.join(sourceNpmrcFolder, '.npmrc'); +function _syncNpmrc(sourceNpmrcFolder, targetNpmrcFolder, useNpmrcPublish) { + const sourceNpmrcPath = path.join(sourceNpmrcFolder, !useNpmrcPublish ? '.npmrc' : '.npmrc-publish'); const targetNpmrcPath = path.join(targetNpmrcFolder, '.npmrc'); try { if (fs.existsSync(sourceNpmrcPath)) { - let npmrcFileLines = fs.readFileSync(sourceNpmrcPath).toString().split('\n'); - npmrcFileLines = npmrcFileLines.map((line) => (line || '').trim()); - const resultLines = []; - // Trim out lines that reference environment variables that aren't defined - for (const line of npmrcFileLines) { - // This finds environment variable tokens that look like "${VAR_NAME}" - const regex = /\$\{([^\}]+)\}/g; - const environmentVariables = line.match(regex); - let lineShouldBeTrimmed = false; - if (environmentVariables) { - for (const token of environmentVariables) { - // Remove the leading "${" and the trailing "}" from the token - const environmentVariableName = token.substring(2, token.length - 1); - if (!process.env[environmentVariableName]) { - lineShouldBeTrimmed = true; - break; - } - } - } - if (lineShouldBeTrimmed) { - // Example output: - // "; MISSING ENVIRONMENT VARIABLE: //my-registry.com/npm/:_authToken=${MY_AUTH_TOKEN}" - resultLines.push('; MISSING ENVIRONMENT VARIABLE: ' + line); - } - else { - resultLines.push(line); - } - } - fs.writeFileSync(targetNpmrcPath, resultLines.join(os.EOL)); + _copyAndTrimNpmrcFile(sourceNpmrcPath, targetNpmrcPath); } else if (fs.existsSync(targetNpmrcPath)) { // If the source .npmrc doesn't exist and there is one in the target, delete the one in the target + console.log(`Deleting ${targetNpmrcPath}`); // Verbose fs.unlinkSync(targetNpmrcPath); } } @@ -121,7 +131,7 @@ function getNpmPath() { } else { // We aren't on Windows - assume we're on *NIX or Darwin - _npmPath = childProcess.execSync('which npm', { stdio: [] }).toString(); + _npmPath = childProcess.execSync('command -v npm', { stdio: [] }).toString(); } } catch (e) { diff --git a/rush.json b/rush.json index 49457da3161d..a7aff345bfdd 100644 --- a/rush.json +++ b/rush.json @@ -15,7 +15,7 @@ * path segment in the "$schema" field for all your Rush config files. This will ensure * correct error-underlining and tab-completion for editors such as VS Code. */ - "rushVersion": "5.19.3", + "rushVersion": "5.23.3", /** * The next field selects which package manager should be installed and determines its version. * Rush installs its own local copy of the package manager to ensure that your build process