Skip to content

Commit fc8fda9

Browse files
authored
Add optional "npmrc" flag to leverage alternative NPM repositories (#258)
fixes #252 Allow the CLI to accept an optional --npmrc flag to include additional rules when resolving NPM dependencies for comparing alternate versions of a package. This is required when working with private repositories/packages.
1 parent bfea185 commit fc8fda9

File tree

6 files changed

+30
-4
lines changed

6 files changed

+30
-4
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ tach http://example.com
857857
| `--package-version` / `-p` | _(none)_ | Specify an NPM package version to swap in ([details](#swap-npm-dependencies)) |
858858
| `--browser` / `-b` | `chrome` | Which browsers to launch in automatic mode, comma-delimited (chrome, firefox, safari, edge, ie) ([details](#browsers)) |
859859
| `--window-size` | `1024,768` | "width,height" in pixels of the browser windows that will be created |
860-
| `--sample-size` / `-n` | `50` | Minimum number of times to run each benchmark ([details](#minimum-sample-size)) |
860+
| `--sample-size` / `-n` | `50` | Minimum number of times to run each benchmark ([details](#minimum-sample-size)) |
861861
| `--auto-sample-conditions` | `0%` | The degrees of difference to try and resolve when auto-sampling ("N%" or "Nms", comma-delimited) ([details](#auto-sample-conditions)) |
862862
| `--timeout` | `3` | The maximum number of minutes to spend auto-sampling ([details](#auto-sample)) |
863863
| `--measure` | `callback` | Which time interval to measure (`callback`, `global`, `fcp`) ([details](#measurement-modes)) |

src/cli.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,11 @@ $ tach http://example.com
145145
for (const {npmInstalls, mountPoints, specs} of plans) {
146146
promises.push(
147147
...npmInstalls.map((install) =>
148-
prepareVersionDirectory(install, config.forceCleanNpmInstall)
148+
prepareVersionDirectory(
149+
install,
150+
config.forceCleanNpmInstall,
151+
config.npmrc
152+
)
149153
)
150154
);
151155
promises.push(

src/config.ts

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export interface Config {
3434
resolveBareModules: boolean;
3535
remoteAccessibleHost: string;
3636
forceCleanNpmInstall: boolean;
37+
npmrc?: string;
3738
csvFileStats: string;
3839
csvFileRaw: string;
3940
}
@@ -49,6 +50,7 @@ export async function makeConfig(opts: Opts): Promise<Config> {
4950
csvFileStats: opts['csv-file'],
5051
csvFileRaw: opts['csv-file-raw'],
5152
forceCleanNpmInstall: opts['force-clean-npm-install'],
53+
npmrc: opts['npmrc'],
5254
githubCheck: opts['github-check']
5355
? parseGithubCheckFlag(opts['github-check'])
5456
: undefined,
@@ -149,6 +151,7 @@ export function applyDefaults(partial: Partial<Config>): Config {
149151
partial.forceCleanNpmInstall !== undefined
150152
? partial.forceCleanNpmInstall
151153
: defaults.forceCleanNpmInstall,
154+
npmrc: partial.npmrc !== undefined ? partial.npmrc : '',
152155
githubCheck: partial.githubCheck,
153156
autoSampleConditions:
154157
partial.autoSampleConditions !== undefined

src/flags.ts

+7
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ export const optDefs: commandLineUsage.OptionDefinition[] = [
9292
type: Boolean,
9393
defaultValue: false,
9494
},
95+
{
96+
name: 'npmrc',
97+
description: `.npmrc file to copy into the test install directory.`,
98+
type: String,
99+
defaultValue: '',
100+
},
95101
{
96102
name: 'browser',
97103
description:
@@ -253,6 +259,7 @@ export interface Opts {
253259
'remote-accessible-host': string;
254260
'window-size': string;
255261
'force-clean-npm-install': boolean;
262+
npmrc?: string;
256263
'csv-file': string;
257264
'csv-file-raw': string;
258265
'json-file': string;

src/test/config_test.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ suite('makeConfig', function () {
3333
const argv = ['random-global.html'];
3434
const expected: Config = {
3535
mode: 'automatic',
36+
npmrc: '',
3637
sampleSize: 50,
3738
timeout: 3,
3839
root: '.',
@@ -77,6 +78,7 @@ suite('makeConfig', function () {
7778
const argv = ['--config=random-global.json'];
7879
const expected: Config = {
7980
mode: 'automatic',
81+
npmrc: '',
8082
sampleSize: 50,
8183
timeout: 3,
8284
root: testData,
@@ -122,7 +124,7 @@ suite('makeConfig', function () {
122124
const argv = ['--config=random-global.json', '--manual'];
123125
const expected: Config = {
124126
mode: 'manual',
125-
127+
npmrc: '',
126128
sampleSize: 50,
127129
timeout: 3,
128130
root: testData,
@@ -173,6 +175,7 @@ suite('makeConfig', function () {
173175
];
174176
const expected: Config = {
175177
mode: 'automatic',
178+
npmrc: '',
176179
csvFileStats: 'stats.csv',
177180
csvFileRaw: 'raw.csv',
178181
jsonFile: 'out.json',
@@ -219,6 +222,7 @@ suite('makeConfig', function () {
219222
const argv = ['--config=deprecated-horizons.json'];
220223
const expected: Config = {
221224
mode: 'automatic',
225+
npmrc: '',
222226
csvFileStats: '',
223227
csvFileRaw: '',
224228
jsonFile: '',

src/versions.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@ const installSuccessFile = '__TACHOMETER_INSTALL_SUCCESS__';
304304
*/
305305
export async function prepareVersionDirectory(
306306
{installDir, packageJson}: NpmInstall,
307-
forceCleanInstall: boolean
307+
forceCleanInstall: boolean,
308+
npmrc?: string
308309
): Promise<void> {
309310
if (forceCleanInstall) {
310311
await fsExtra.remove(installDir);
@@ -324,6 +325,13 @@ export async function prepareVersionDirectory(
324325
path.join(installDir, 'package.json'),
325326
JSON.stringify(packageJson, null, 2)
326327
);
328+
if (npmrc) {
329+
await fsExtra.copy(
330+
path.resolve(npmrc),
331+
path.join(installDir, '.npmrc'),
332+
{}
333+
);
334+
}
327335
await runNpm(['install'], {cwd: installDir});
328336
await fsExtra.writeFile(path.join(installDir, installSuccessFile), '');
329337
}

0 commit comments

Comments
 (0)