|
|
@ -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'; |
|
|
@ -28,7 +30,7 @@ export default class Now extends EventEmitter { |
|
|
|
this._onRetry = this._onRetry.bind(this); |
|
|
|
} |
|
|
|
|
|
|
|
async create (path, { forceNew, forceSync, quiet = false }) { |
|
|
|
async create (path, { forceNew, forceSync, forwardNpm, quiet = false }) { |
|
|
|
this._path = path; |
|
|
|
|
|
|
|
try { |
|
|
@ -61,6 +63,33 @@ export default class Now extends EventEmitter { |
|
|
|
throw e; |
|
|
|
} |
|
|
|
|
|
|
|
const nowProperties = pkg.now || {}; |
|
|
|
|
|
|
|
forwardNpm = forwardNpm || nowProperties['forward-npm']; |
|
|
|
|
|
|
|
// Read .npmrc
|
|
|
|
let npmrc = {}; |
|
|
|
let authToken; |
|
|
|
if (forwardNpm) { |
|
|
|
try { |
|
|
|
npmrc = await readFile(resolvePath(path, '.npmrc'), 'utf8'); |
|
|
|
npmrc = parseIni(npmrc); |
|
|
|
authToken = npmrc['//registry.npmjs.org/:_authToken']; |
|
|
|
} catch (err) { |
|
|
|
// Do nothing
|
|
|
|
} |
|
|
|
|
|
|
|
if (!authToken) { |
|
|
|
try { |
|
|
|
npmrc = await readFile(resolvePath(homedir(), '.npmrc'), 'utf8'); |
|
|
|
npmrc = parseIni(npmrc); |
|
|
|
authToken = npmrc['//registry.npmjs.org/:_authToken']; |
|
|
|
} catch (err) { |
|
|
|
// Do nothing
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
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'); |
|
|
@ -71,7 +100,6 @@ export default class Now extends EventEmitter { |
|
|
|
|
|
|
|
this._files = hashes; |
|
|
|
|
|
|
|
const nowProperties = pkg.now || {}; |
|
|
|
const engines = nowProperties.engines || pkg.engines; |
|
|
|
|
|
|
|
const deployment = await this.retry(async (bail) => { |
|
|
@ -83,6 +111,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 }]) => { |
|
|
|