|
|
@ -1,7 +1,8 @@ |
|
|
|
import bytes from 'bytes'; |
|
|
|
import chalk from 'chalk'; |
|
|
|
import getFiles from './get-files'; |
|
|
|
import hash from './hash'; |
|
|
|
import retry from './retry'; |
|
|
|
import bytes from 'bytes'; |
|
|
|
import Agent from './agent'; |
|
|
|
import EventEmitter from 'events'; |
|
|
|
import { basename, resolve } from 'path'; |
|
|
@ -9,9 +10,6 @@ import { stat, readFile } from 'fs-promise'; |
|
|
|
import resumer from 'resumer'; |
|
|
|
import splitArray from 'split-array'; |
|
|
|
|
|
|
|
// limit of size of files to find
|
|
|
|
const ONEMB = bytes('1mb'); |
|
|
|
|
|
|
|
// how many concurrent HTTP/2 stream uploads
|
|
|
|
const MAX_CONCURRENT = 10; |
|
|
|
|
|
|
@ -39,7 +37,6 @@ export default class Now extends EventEmitter { |
|
|
|
e.userError = true; |
|
|
|
throw e; |
|
|
|
} |
|
|
|
|
|
|
|
let pkg; |
|
|
|
try { |
|
|
|
pkg = await readFile(resolve(path, 'package.json')); |
|
|
@ -64,7 +61,7 @@ export default class Now extends EventEmitter { |
|
|
|
} |
|
|
|
|
|
|
|
if (this._debug) console.time('> [debug] Getting files'); |
|
|
|
const files = await getFiles(path, pkg, { limit: ONEMB, debug: this._debug }); |
|
|
|
const files = await getFiles(path, pkg, { debug: this._debug }); |
|
|
|
if (this._debug) console.timeEnd('> [debug] Getting files'); |
|
|
|
|
|
|
|
if (this._debug) console.time('> [debug] Computing hashes'); |
|
|
@ -74,8 +71,8 @@ export default class Now extends EventEmitter { |
|
|
|
this._files = hashes; |
|
|
|
|
|
|
|
const deployment = await retry(async (bail) => { |
|
|
|
if (this._debug) console.time('> [debug] /create'); |
|
|
|
const res = await this._fetch('/create', { |
|
|
|
if (this._debug) console.time('> [debug] /now/create'); |
|
|
|
const res = await this._fetch('/now/create', { |
|
|
|
method: 'POST', |
|
|
|
body: { |
|
|
|
forceNew, |
|
|
@ -95,7 +92,7 @@ export default class Now extends EventEmitter { |
|
|
|
})) |
|
|
|
} |
|
|
|
}); |
|
|
|
if (this._debug) console.timeEnd('> [debug] /create'); |
|
|
|
if (this._debug) console.timeEnd('> [debug] /now/create'); |
|
|
|
|
|
|
|
// no retry on 4xx
|
|
|
|
if (200 !== res.status && (400 <= res.status && 500 > res.status)) { |
|
|
@ -112,6 +109,28 @@ export default class Now extends EventEmitter { |
|
|
|
return res.json(); |
|
|
|
}, { retries: 3, minTimeout: 2500, onRetry: this._onRetry }); |
|
|
|
|
|
|
|
// we report about files whose sizes are too big
|
|
|
|
if (deployment.warnings) { |
|
|
|
let sizeExceeded = 0; |
|
|
|
deployment.warnings.forEach(({ reason, sha, limit }) => { |
|
|
|
if ('size_limit_exceeded' === reason) { |
|
|
|
const name = hashes.get(sha).names.pop(); |
|
|
|
console.error('> \u001b[31mWarning!\u001b[39m Skipping file %s (size exceeded %s)', |
|
|
|
name, |
|
|
|
bytes(limit) |
|
|
|
); |
|
|
|
hashes.get(sha).names.unshift(name); // move name (hack, if duplicate matches we report them in order)
|
|
|
|
sizeExceeded++; |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
if (sizeExceeded) { |
|
|
|
console.log(`> \u001b[31mWarning!\u001b[39m ${sizeExceeded} of the files ` + |
|
|
|
'exceeded the limit for your plan.\n' + |
|
|
|
`> See ${chalk.underline('https://zeit.co/account')} to upgrade.`); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
this._id = deployment.deploymentId; |
|
|
|
this._host = deployment.url; |
|
|
|
this._missing = deployment.missing || []; |
|
|
@ -136,7 +155,7 @@ export default class Now extends EventEmitter { |
|
|
|
if (this._debug) console.time(`> [debug] /sync ${names.join(' ')}`); |
|
|
|
|
|
|
|
const stream = resumer().queue(data).end(); |
|
|
|
const res = await this._fetch('/sync', { |
|
|
|
const res = await this._fetch('/now/sync', { |
|
|
|
method: 'POST', |
|
|
|
headers: { |
|
|
|
'Content-Type': 'application/octet-stream', |
|
|
@ -170,7 +189,7 @@ export default class Now extends EventEmitter { |
|
|
|
|
|
|
|
const { deployments } = await retry(async (bail) => { |
|
|
|
if (this._debug) console.time('> [debug] /list'); |
|
|
|
const res = await this._fetch('/list' + query); |
|
|
|
const res = await this._fetch('/now/list' + query); |
|
|
|
if (this._debug) console.timeEnd('> [debug] /list'); |
|
|
|
|
|
|
|
// no retry on 4xx
|
|
|
@ -196,7 +215,7 @@ export default class Now extends EventEmitter { |
|
|
|
|
|
|
|
await retry(async (bail) => { |
|
|
|
if (this._debug) console.time('> [debug] /remove'); |
|
|
|
const res = await this._fetch('/remove', { |
|
|
|
const res = await this._fetch('/now/remove', { |
|
|
|
method: 'DELETE', |
|
|
|
body: data |
|
|
|
}); |
|
|
|