diff --git a/lib/index.js b/lib/index.js index e0acd72..c4c8b21 100644 --- a/lib/index.js +++ b/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 }]) => { diff --git a/package.json b/package.json index 5f64116..56895c5 100644 --- a/package.json +++ b/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",