google/tachometer

[feature] Support supplying an `.npmrc` when installing test dependencies.

Westbrook opened this issue · 0 comments

I'd like to be able to install packages from a private NPM registry when making performance comparisons between current and previous releases of a package. Would you accept a PR that adds an --npmrc flag to the CLI?

Roughly, such an addition would look like this in the final JS output:

diff --git a/node_modules/tachometer/lib/cli.js b/node_modules/tachometer/lib/cli.js
index 0f9134d..240dc7e 100644
--- a/node_modules/tachometer/lib/cli.js
+++ b/node_modules/tachometer/lib/cli.js
@@ -101,7 +101,7 @@ $ tach http://example.com
     const servers = new Map();
     const promises = [];
     for (const { npmInstalls, mountPoints, specs } of plans) {
-        promises.push(...npmInstalls.map((install) => prepareVersionDirectory(install, config.forceCleanNpmInstall)));
+        promises.push(...npmInstalls.map((install) => prepareVersionDirectory(install, config.forceCleanNpmInstall, config.npmrc)));
         promises.push((async () => {
             const server = await Server.start({
                 host: opts.host,
diff --git a/node_modules/tachometer/lib/config.js b/node_modules/tachometer/lib/config.js
index f75c027..3ab4cdb 100644
--- a/node_modules/tachometer/lib/config.js
+++ b/node_modules/tachometer/lib/config.js
@@ -20,6 +20,7 @@ export async function makeConfig(opts) {
         csvFileStats: opts['csv-file'],
         csvFileRaw: opts['csv-file-raw'],
         forceCleanNpmInstall: opts['force-clean-npm-install'],
+        npmrc: opts['npmrc'],
         githubCheck: opts['github-check']
             ? parseGithubCheckFlag(opts['github-check'])
             : undefined,
@@ -90,6 +91,7 @@ export function applyDefaults(partial) {
         forceCleanNpmInstall: partial.forceCleanNpmInstall !== undefined
             ? partial.forceCleanNpmInstall
             : defaults.forceCleanNpmInstall,
+        npmrc: partial.npmrc !== undefined ? partial.npmrc : '',
         githubCheck: partial.githubCheck,
         autoSampleConditions: partial.autoSampleConditions !== undefined
             ? partial.autoSampleConditions
diff --git a/node_modules/tachometer/lib/flags.js b/node_modules/tachometer/lib/flags.js
index fa64c37..a1e50e3 100644
--- a/node_modules/tachometer/lib/flags.js
+++ b/node_modules/tachometer/lib/flags.js
@@ -78,6 +78,12 @@ export const optDefs = [
         type: Boolean,
         defaultValue: false,
     },
+    {
+        name: 'npmrc',
+        description: `.npmrc file to copy into the test install directory.`,
+        type: String,
+        defaultValue: '',
+    },
     {
         name: 'browser',
         description: 'Which browsers to launch in automatic mode, ' +
diff --git a/node_modules/tachometer/lib/versions.js b/node_modules/tachometer/lib/versions.js
index a189cc9..f544219 100644
--- a/node_modules/tachometer/lib/versions.js
+++ b/node_modules/tachometer/lib/versions.js
@@ -203,7 +203,7 @@ const installSuccessFile = '__TACHOMETER_INSTALL_SUCCESS__';
  * Write the given package.json to the given directory and run "npm install" in
  * it. If the directory already exists, don't do anything except log.
  */
-export async function prepareVersionDirectory({ installDir, packageJson }, forceCleanInstall) {
+export async function prepareVersionDirectory({ installDir, packageJson }, forceCleanInstall, npmrc) {
     if (forceCleanInstall) {
         await fsExtra.remove(installDir);
     }
@@ -220,6 +220,11 @@ export async function prepareVersionDirectory({ installDir, packageJson }, force
     console.log(`\nRunning npm install in temp dir:\n  ${installDir}\n`);
     await fsExtra.ensureDir(installDir);
     await fsExtra.writeFile(path.join(installDir, 'package.json'), JSON.stringify(packageJson, null, 2));
+    if (npmrc) {
+        await fsExtra.copySync(path.resolve(npmrc), path.join(installDir, '.npmrc'), {
+            
+        });
+    }
     await runNpm(['install'], { cwd: installDir });
     await fsExtra.writeFile(path.join(installDir, installSuccessFile), '');
 }