|
|
@ -1,6 +1,6 @@ |
|
|
|
// Native
|
|
|
|
const { homedir } = require('os') |
|
|
|
const { resolve: resolvePath, join: joinPaths } = require('path') |
|
|
|
const { resolve: resolvePath } = require('path') |
|
|
|
const EventEmitter = require('events') |
|
|
|
const qs = require('querystring') |
|
|
|
const { parse: parseUrl } = require('url') |
|
|
@ -55,14 +55,12 @@ module.exports = class Now extends EventEmitter { |
|
|
|
name, |
|
|
|
description, |
|
|
|
type = 'npm', |
|
|
|
isStatic = false, |
|
|
|
pkg = {}, |
|
|
|
nowConfig = {}, |
|
|
|
hasNowJson = false |
|
|
|
} |
|
|
|
) { |
|
|
|
this._path = path |
|
|
|
this._static = isStatic |
|
|
|
|
|
|
|
let files |
|
|
|
let engines |
|
|
@ -108,7 +106,7 @@ module.exports = class Now extends EventEmitter { |
|
|
|
} |
|
|
|
|
|
|
|
const pkgDetails = Object.assign({ name }, pkg) |
|
|
|
const hashes = await hash(files, isStatic, pkgDetails) |
|
|
|
const hashes = await hash(files, pkgDetails) |
|
|
|
|
|
|
|
if (this._debug) { |
|
|
|
console.timeEnd('> [debug] Computing hashes') |
|
|
@ -131,23 +129,12 @@ module.exports = class Now extends EventEmitter { |
|
|
|
const statFn = followSymlinks ? stat : lstat |
|
|
|
|
|
|
|
return names.map(async name => { |
|
|
|
let mode |
|
|
|
|
|
|
|
const getMode = async () => { |
|
|
|
const st = await statFn(name) |
|
|
|
return st.mode |
|
|
|
} |
|
|
|
|
|
|
|
if (this._static) { |
|
|
|
if (toRelative(name, this._path) === 'package.json') { |
|
|
|
mode = 33261 |
|
|
|
} else { |
|
|
|
mode = await getMode() |
|
|
|
name = this.pathInsideContent(name) |
|
|
|
} |
|
|
|
} else { |
|
|
|
mode = await getMode() |
|
|
|
} |
|
|
|
const mode = await getMode() |
|
|
|
|
|
|
|
return { |
|
|
|
sha, |
|
|
@ -245,12 +232,18 @@ module.exports = class Now extends EventEmitter { |
|
|
|
if (!quiet && type === 'npm' && deployment.nodeVersion) { |
|
|
|
if (engines && engines.node) { |
|
|
|
if (missingVersion) { |
|
|
|
console.log(`> Using Node.js ${chalk.bold(deployment.nodeVersion)} (default)`) |
|
|
|
console.log( |
|
|
|
`> Using Node.js ${chalk.bold(deployment.nodeVersion)} (default)` |
|
|
|
) |
|
|
|
} else { |
|
|
|
console.log(`> Using Node.js ${chalk.bold(deployment.nodeVersion)} (requested: ${chalk.dim(`\`${engines.node}\``)})`) |
|
|
|
console.log( |
|
|
|
`> Using Node.js ${chalk.bold(deployment.nodeVersion)} (requested: ${chalk.dim(`\`${engines.node}\``)})` |
|
|
|
) |
|
|
|
} |
|
|
|
} else { |
|
|
|
console.log(`> Using Node.js ${chalk.bold(deployment.nodeVersion)} (default)`) |
|
|
|
console.log( |
|
|
|
`> Using Node.js ${chalk.bold(deployment.nodeVersion)} (default)` |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -261,14 +254,6 @@ module.exports = class Now extends EventEmitter { |
|
|
|
return this._url |
|
|
|
} |
|
|
|
|
|
|
|
pathInsideContent(position) { |
|
|
|
const relativePath = toRelative(position, this._path) |
|
|
|
const contentDir = joinPaths(this._path, 'content') |
|
|
|
const newPath = joinPaths(contentDir, relativePath) |
|
|
|
|
|
|
|
return newPath |
|
|
|
} |
|
|
|
|
|
|
|
upload() { |
|
|
|
const parts = splitArray(this._missing, MAX_CONCURRENT) |
|
|
|
|
|
|
@ -302,10 +287,6 @@ module.exports = class Now extends EventEmitter { |
|
|
|
'x-now-sha': sha, |
|
|
|
'x-now-file': names |
|
|
|
.map(name => { |
|
|
|
if (this._static) { |
|
|
|
name = this.pathInsideContent(name) |
|
|
|
} |
|
|
|
|
|
|
|
return toRelative(encodeURIComponent(name), this._path) |
|
|
|
}) |
|
|
|
.join(','), |
|
|
@ -315,7 +296,9 @@ module.exports = class Now extends EventEmitter { |
|
|
|
}) |
|
|
|
|
|
|
|
if (this._debug) { |
|
|
|
console.timeEnd(`> [debug] /sync #${attempt} ${names.join(' ')}`) |
|
|
|
console.timeEnd( |
|
|
|
`> [debug] /sync #${attempt} ${names.join(' ')}` |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
// No retry on 4xx
|
|
|
@ -405,8 +388,9 @@ module.exports = class Now extends EventEmitter { |
|
|
|
console.time(`> [debug] /deployments/${deploymentId}/instances`) |
|
|
|
} |
|
|
|
|
|
|
|
const res = await this |
|
|
|
._fetch(`/now/deployments/${deploymentId}/instances`) |
|
|
|
const res = await this._fetch( |
|
|
|
`/now/deployments/${deploymentId}/instances` |
|
|
|
) |
|
|
|
|
|
|
|
if (this._debug) { |
|
|
|
console.timeEnd(`> [debug] /deployments/${deploymentId}/instances`) |
|
|
@ -589,14 +573,19 @@ module.exports = class Now extends EventEmitter { |
|
|
|
|
|
|
|
this.retry(async (bail, attempt) => { |
|
|
|
if (this._debug) { |
|
|
|
console.time(`> [debug] #${attempt} GET /whois-ns${fallback ? '-fallback' : ''}`) |
|
|
|
console.time( |
|
|
|
`> [debug] #${attempt} GET /whois-ns${fallback ? '-fallback' : ''}` |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
const res = await this |
|
|
|
._fetch(`/whois-ns${fallback ? '-fallback' : ''}?domain=${encodeURIComponent(domain)}`) |
|
|
|
const res = await this._fetch( |
|
|
|
`/whois-ns${fallback ? '-fallback' : ''}?domain=${encodeURIComponent(domain)}` |
|
|
|
) |
|
|
|
|
|
|
|
if (this._debug) { |
|
|
|
console.timeEnd(`> [debug] #${attempt} GET /whois-ns${fallback ? '-fallback' : ''}`) |
|
|
|
console.timeEnd( |
|
|
|
`> [debug] #${attempt} GET /whois-ns${fallback ? '-fallback' : ''}` |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
const body = await res.json() |
|
|
@ -862,7 +851,9 @@ module.exports = class Now extends EventEmitter { |
|
|
|
setScale(nameOrId, scale) { |
|
|
|
return this.retry(async (bail, attempt) => { |
|
|
|
if (this._debug) { |
|
|
|
console.time(`> [debug] #${attempt} POST /deployments/${nameOrId}/instances`) |
|
|
|
console.time( |
|
|
|
`> [debug] #${attempt} POST /deployments/${nameOrId}/instances` |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
const res = await this._fetch(`/now/deployments/${nameOrId}/instances`, { |
|
|
@ -871,7 +862,9 @@ module.exports = class Now extends EventEmitter { |
|
|
|
}) |
|
|
|
|
|
|
|
if (this._debug) { |
|
|
|
console.timeEnd(`> [debug] #${attempt} POST /deployments/${nameOrId}/instances`) |
|
|
|
console.timeEnd( |
|
|
|
`> [debug] #${attempt} POST /deployments/${nameOrId}/instances` |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
if (res.status === 403) { |
|
|
|