From 16424697617d5dff6ba16c7ef2af2949cd832265 Mon Sep 17 00:00:00 2001 From: Guillermo Rauch Date: Mon, 6 Jun 2016 12:11:26 -0700 Subject: [PATCH] index: add version reporting, support for `engines` --- lib/index.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index 1a7e98c..e89f3a2 100644 --- a/lib/index.js +++ b/lib/index.js @@ -72,7 +72,7 @@ export default class Now extends EventEmitter { this._files = hashes; const nowProperties = pkg.now || {}; - const engines = nowProperties.engines; + const engines = nowProperties.engines || pkg.engines; const deployment = await retry(async (bail) => { if (this._debug) console.time('> [debug] /now/create'); @@ -115,6 +115,7 @@ export default class Now extends EventEmitter { }, { retries: 3, minTimeout: 2500, onRetry: this._onRetry }); // we report about files whose sizes are too big + let missingVersion = false; if (deployment.warnings) { let sizeExceeded = 0; deployment.warnings.forEach((warning) => { @@ -129,10 +130,11 @@ export default class Now extends EventEmitter { sizeExceeded++; } else if ('node_version_not_found' === warning.reason) { const { wanted, used } = warning; - console.error('> \u001b[31mWarning!\u001b[39m Requested node version %s is not available, using default version %s', + console.error('> \u001b[31mWarning!\u001b[39m Requested node version %s is not available', wanted, used ); + missingVersion = true; } }); @@ -143,6 +145,16 @@ export default class Now extends EventEmitter { } } + if (engines.node) { + if (missingVersion) { + 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}\``)})`); + } + } else { + console.log(`> Using Node.js ${chalk.bold(deployment.nodeVersion)} (default)`); + } + this._id = deployment.deploymentId; this._host = deployment.url; this._missing = deployment.missing || [];