Browse Source

Send registry auth token from .npmrc if accessible

master
Tony Kovanen 9 years ago
parent
commit
cb86654e21
  1. 23
      lib/index.js
  2. 1
      package.json

23
lib/index.js

@ -7,6 +7,8 @@ import retry from 'async-retry';
import Agent from './agent';
import EventEmitter from 'events';
import { basename, resolve as resolvePath } from 'path';
import { homedir } from 'os';
import { parse as parseIni } from 'ini';
import { stat, readFile } from 'fs-promise';
import resumer from 'resumer';
import splitArray from 'split-array';
@ -61,6 +63,26 @@ export default class Now extends EventEmitter {
throw e;
}
// Read .npmrc
let npmrc;
try {
npmrc = await readFile(resolvePath(path, '.npmrc'), 'utf8');
npmrc = parseIni(npmrc);
} catch (err) {
// Do nothing
}
if (!npmrc) {
try {
npmrc = await readFile(resolvePath(homedir(), '.npmrc'), 'utf8');
npmrc = parseIni(npmrc);
} catch (err) {
// Do nothing
}
}
const authToken = npmrc['//registry.npmjs.org/:_authToken'];
if (this._debug) console.time('> [debug] Getting files');
const files = await getFiles(path, pkg, { debug: this._debug });
if (this._debug) console.timeEnd('> [debug] Getting files');
@ -83,6 +105,7 @@ export default class Now extends EventEmitter {
forceSync,
name: pkg.name || basename(path),
description: pkg.description,
registryAuthToken: authToken,
// Flatten the array to contain files to sync where each nested input
// array has a group of files with the same sha but different path
files: Array.prototype.concat.apply([], Array.from(this._files).map(([sha, { data, names }]) => {

1
package.json

@ -62,6 +62,7 @@
"email-validator": "1.0.4",
"fs-promise": "0.5.0",
"graceful-fs": "4.1.4",
"ini": "1.3.4",
"minimatch": "3.0.0",
"minimist": "1.2.0",
"ms": "0.7.1",

Loading…
Cancel
Save