[now-build-utils][now-node] Throw new NowBuildError() (#3496)

This PR does the following

- Add and export class, `NowBuildError`, that can be thrown to stop the build and print an error but it will not print a stack trace.
- Improve logic for discontinued node versions and add more tests
- Remove hack (#3425) for undefined TERM, fixed by updating dependencies
- Rename `silent` variable to `isAuto` which means the node version was automatically selected, not defined in `package.json`
- Rename `test` deployments to `test2020` so that a fresh project is created with latest Node.js 12.x
This commit is contained in:
Steven
2020-01-06 10:00:27 -05:00
committed by kodiakhq[bot]
parent d9c84fc4ce
commit 44f6e1904e
9 changed files with 134 additions and 76 deletions

View File

@@ -1,6 +1,5 @@
const assert = require('assert');
const { createHash } = require('crypto');
const { homedir } = require('os');
const path = require('path');
const fetch = require('./fetch-retry.js');
@@ -28,7 +27,7 @@ async function nowDeploy (bodies, randomness) {
RANDOMNESS_BUILD_ENV_VAR: randomness,
},
},
name: 'test',
name: 'test2020',
files,
builds: nowJson.builds,
routes: nowJson.routes || [],
@@ -133,20 +132,12 @@ async function fetchWithAuth (url, opts = {}) {
if (!opts.headers) opts.headers = {};
if (!opts.headers.Authorization) {
const { NOW_TOKEN, CIRCLECI } = process.env;
currentCount += 1;
if (!token || currentCount === MAX_COUNT) {
currentCount = 0;
if (NOW_TOKEN) {
token = NOW_TOKEN;
} else if (CIRCLECI) {
token = await fetchTokenWithRetry(
Buffer.from(str, 'base64').toString()
);
} else {
const authJsonPath = path.join(homedir(), '.now/auth.json');
token = require(authJsonPath).token;
}
token = await fetchTokenWithRetry(
Buffer.from(str, 'base64').toString()
);
}
opts.headers.Authorization = `Bearer ${token}`;