From 67b55610b73af28f1676b20913b084a51404b63c Mon Sep 17 00:00:00 2001 From: Igor Klopov Date: Thu, 7 Jul 2016 19:30:49 +0300 Subject: [PATCH 1/8] make a binary of `now` using enclosejs (#81) * make a binary of `now` using enclosejs * pin enclosejs version --- bin/now | 7 ++++++- enclose.js | 5 +++++ gulpfile.babel.js | 9 +++++++++ package.json | 4 +++- 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 enclose.js diff --git a/bin/now b/bin/now index e723245..f160437 100755 --- a/bin/now +++ b/bin/now @@ -39,7 +39,12 @@ if (commands.has(cmd)) { args = args.concat(process.argv.slice(2)); } -const bin = resolve(__dirname, 'now-' + cmd); +let bin = resolve(__dirname, 'now-' + cmd); +if (process.enclose) { + args.unshift("--entrypoint", bin); + bin = process.execPath; +} + const proc = spawn(bin, args, { stdio: 'inherit', customFds: [0, 1, 2] }); proc.on('close', (code) => exit(code)); proc.on('error', () => exit(1)); diff --git a/enclose.js b/enclose.js new file mode 100644 index 0000000..13bfb8f --- /dev/null +++ b/enclose.js @@ -0,0 +1,5 @@ +module.exports = { + scripts: [ + "build/bin/now-*" + ] +}; diff --git a/gulpfile.babel.js b/gulpfile.babel.js index d39cb28..bb3e7f8 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -3,6 +3,7 @@ import del from 'del'; import babel from 'gulp-babel'; import uglify from 'gulp-uglify'; import help from 'gulp-task-listing'; +import { exec as enclose } from 'enclose'; gulp.task('help', help); @@ -23,6 +24,14 @@ gulp.task('compile-bin', () => .pipe(uglify()) .pipe(gulp.dest('build/bin'))); +gulp.task('enclose', ['compile'], (cb) => { + enclose([ + 'build/bin/now', + '-c', 'enclose.js', + '-o', 'build/now' + ], cb); +}); + gulp.task('watch-lib', () => gulp.watch('lib/*.js', ['compile-lib'])); gulp.task('watch-bin', () => gulp.watch('bin/*', ['compile-bin'])); gulp.task('clean', () => del(['build'])); diff --git a/package.json b/package.json index 179073f..5f64116 100644 --- a/package.json +++ b/package.json @@ -83,6 +83,7 @@ "babel-preset-es2015": "6.9.0", "babel-register": "6.9.0", "del": "2.2.0", + "enclose": "2.1.0", "eslint": "2.12.0", "eslint-config-standard": "5.3.1", "eslint-plugin-promise": "1.3.2", @@ -97,7 +98,8 @@ "scripts": { "start": "gulp", "test": "ava", - "prepublish": "gulp compile" + "prepublish": "gulp compile", + "enclose": "gulp enclose" }, "ava": { "failFast": true, From cb86654e218407bb43887c1d66695694fad0332b Mon Sep 17 00:00:00 2001 From: Tony Kovanen Date: Fri, 15 Jul 2016 20:21:38 +0300 Subject: [PATCH 2/8] Send registry auth token from .npmrc if accessible --- lib/index.js | 23 +++++++++++++++++++++++ package.json | 1 + 2 files changed, 24 insertions(+) diff --git a/lib/index.js b/lib/index.js index e0acd72..c4c8b21 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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'; @@ -61,6 +63,26 @@ export default class Now extends EventEmitter { throw e; } + // Read .npmrc + let npmrc; + try { + npmrc = await readFile(resolvePath(path, '.npmrc'), 'utf8'); + npmrc = parseIni(npmrc); + } catch (err) { + // Do nothing + } + + if (!npmrc) { + try { + npmrc = await readFile(resolvePath(homedir(), '.npmrc'), 'utf8'); + npmrc = parseIni(npmrc); + } catch (err) { + // Do nothing + } + } + + const authToken = npmrc['//registry.npmjs.org/:_authToken']; + 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'); @@ -83,6 +105,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 }]) => { diff --git a/package.json b/package.json index 5f64116..56895c5 100644 --- a/package.json +++ b/package.json @@ -62,6 +62,7 @@ "email-validator": "1.0.4", "fs-promise": "0.5.0", "graceful-fs": "4.1.4", + "ini": "1.3.4", "minimatch": "3.0.0", "minimist": "1.2.0", "ms": "0.7.1", From f4c55e2864aebd79ad345d62eddb5b3d51beb1cc Mon Sep 17 00:00:00 2001 From: Tony Kovanen Date: Fri, 15 Jul 2016 20:24:40 +0300 Subject: [PATCH 3/8] Forward registry auth token only if asked --- lib/index.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/index.js b/lib/index.js index c4c8b21..873101f 100644 --- a/lib/index.js +++ b/lib/index.js @@ -64,21 +64,23 @@ export default class Now extends EventEmitter { } // Read .npmrc - let npmrc; - try { - npmrc = await readFile(resolvePath(path, '.npmrc'), 'utf8'); - npmrc = parseIni(npmrc); - } catch (err) { - // Do nothing - } - - if (!npmrc) { + let npmrc = {}; + if (pkg['forward-npm']) { try { - npmrc = await readFile(resolvePath(homedir(), '.npmrc'), 'utf8'); + npmrc = await readFile(resolvePath(path, '.npmrc'), 'utf8'); npmrc = parseIni(npmrc); } catch (err) { // Do nothing } + + if (!npmrc) { + try { + npmrc = await readFile(resolvePath(homedir(), '.npmrc'), 'utf8'); + npmrc = parseIni(npmrc); + } catch (err) { + // Do nothing + } + } } const authToken = npmrc['//registry.npmjs.org/:_authToken']; From 9feed0c767da33ab4d98f806c1e3aea4f14341af Mon Sep 17 00:00:00 2001 From: Tony Kovanen Date: Sun, 17 Jul 2016 01:49:26 +0300 Subject: [PATCH 4/8] Look up `forward-npm` from now nowProperties --- lib/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index 873101f..06cf1dd 100644 --- a/lib/index.js +++ b/lib/index.js @@ -63,9 +63,11 @@ export default class Now extends EventEmitter { throw e; } + const nowProperties = pkg.now || {}; + // Read .npmrc let npmrc = {}; - if (pkg['forward-npm']) { + if (nowProperties['forward-npm']) { try { npmrc = await readFile(resolvePath(path, '.npmrc'), 'utf8'); npmrc = parseIni(npmrc); @@ -95,7 +97,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) => { From 753968648368d2e3133d95c6929c08774c38e7cf Mon Sep 17 00:00:00 2001 From: Tony Kovanen Date: Sun, 17 Jul 2016 01:52:25 +0300 Subject: [PATCH 5/8] Keep reading lower .npmrc if no auth in project --- lib/index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/index.js b/lib/index.js index 06cf1dd..896aacc 100644 --- a/lib/index.js +++ b/lib/index.js @@ -67,26 +67,27 @@ export default class Now extends EventEmitter { // Read .npmrc let npmrc = {}; + let authToken; if (nowProperties['forward-npm']) { try { npmrc = await readFile(resolvePath(path, '.npmrc'), 'utf8'); npmrc = parseIni(npmrc); + authToken = npmrc['//registry.npmjs.org/:_authToken']; } catch (err) { // Do nothing } - if (!npmrc) { + if (!authToken) { try { npmrc = await readFile(resolvePath(homedir(), '.npmrc'), 'utf8'); npmrc = parseIni(npmrc); + authToken = npmrc['//registry.npmjs.org/:_authToken']; } catch (err) { // Do nothing } } } - const authToken = npmrc['//registry.npmjs.org/:_authToken']; - 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'); From 7ab8e0d344cef463048bc3444a6cf2aecc961514 Mon Sep 17 00:00:00 2001 From: Tony Kovanen Date: Sun, 17 Jul 2016 12:54:43 +0300 Subject: [PATCH 6/8] Add cmd line flag to forward NPM auth token --- bin/now-deploy | 9 ++++++--- lib/index.js | 6 ++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/bin/now-deploy b/bin/now-deploy index 22174ff..483fa06 100755 --- a/bin/now-deploy +++ b/bin/now-deploy @@ -14,7 +14,7 @@ import ms from 'ms'; import { handleError, error } from '../lib/error'; const argv = minimist(process.argv.slice(2), { - boolean: ['help', 'version', 'debug', 'force', 'login', 'no-clipboard'], + boolean: ['help', 'version', 'debug', 'force', 'login', 'no-clipboard', 'forward-npm'], alias: { help: 'h', debug: 'd', @@ -22,7 +22,8 @@ const argv = minimist(process.argv.slice(2), { force: 'f', forceSync: 'F', login: 'L', - 'no-clipboard': 'C' + 'no-clipboard': 'C', + 'forward-npm': 'N' } }); @@ -47,6 +48,7 @@ const help = () => { -f, --force force a new deployment even if nothing has changed -L, --login configure login -C, --no-clipboard do not attempt to copy URL to clipboard + -N, --forward-npm Forward login information to install private NPM modules ${chalk.dim('Examples:')} @@ -93,6 +95,7 @@ const exit = (code) => { // options const debug = argv.debug; const clipboard = !argv['no-clipboard']; +const forwardNpm = argv['forward-npm']; const force = argv.force; const forceSync = argv.forceSync; const shouldLogin = argv.login; @@ -138,7 +141,7 @@ async function sync (token) { const now = new Now(apiUrl, token, { debug }); try { - await now.create(path, { forceNew: force, forceSync: forceSync }); + await now.create(path, { forceNew: force, forceSync: forceSync, forwardNpm }); } catch (err) { handleError(err); process.exit(1); diff --git a/lib/index.js b/lib/index.js index 896aacc..571fcbd 100644 --- a/lib/index.js +++ b/lib/index.js @@ -30,7 +30,7 @@ export default class Now extends EventEmitter { this._onRetry = this._onRetry.bind(this); } - async create (path, { forceNew, forceSync }) { + async create (path, { forceNew, forceSync, forwardNpm }) { this._path = path; try { @@ -65,10 +65,12 @@ export default class Now extends EventEmitter { const nowProperties = pkg.now || {}; + forwardNpm = forwardNpm || nowProperties['forward-npm']; + // Read .npmrc let npmrc = {}; let authToken; - if (nowProperties['forward-npm']) { + if (forwardNpm) { try { npmrc = await readFile(resolvePath(path, '.npmrc'), 'utf8'); npmrc = parseIni(npmrc); From 38d1e4d32f824a0c851486c4f5434b8a87edafeb Mon Sep 17 00:00:00 2001 From: Guillermo Rauch Date: Fri, 22 Jul 2016 17:40:12 -0700 Subject: [PATCH 7/8] alias: handle `ESERVFAIL` --- lib/alias.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/alias.js b/lib/alias.js index c58bdf9..cedfdc1 100644 --- a/lib/alias.js +++ b/lib/alias.js @@ -282,7 +282,7 @@ export default class Alias extends Now { try { ips = await resolve4(domain); } catch (err) { - if ('ENODATA' === err.code || 'ENOTFOUND' === err.code) { + if ('ENODATA' === err.code || 'ESERVFAIL' === err.code || 'ENOTFOUND' === err.code) { // not errors per se, just absence of records if (this._debug) console.log(`> [debug] No records found for "${domain}"`); } else { From 9284265f1431daaf27483b1b546d7003d1586d8a Mon Sep 17 00:00:00 2001 From: Guillermo Rauch Date: Fri, 22 Jul 2016 17:41:22 -0700 Subject: [PATCH 8/8] Release 0.19.0 --- HISTORY.md | 8 ++++++++ package.json | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index ebdbf7b..f7792bb 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,4 +1,12 @@ +0.19.0 / 2016-07-22 +=================== + + * alias: handle `ESERVFAIL` [@rauchg] + * add cmd line flag to forward NPM auth token [@rase-] + * make a binary of `now` using enclosejs [@igorklopov] + * bunch of misc improvements to build process [@leo] + 0.18.1 / 2016-06-23 =================== diff --git a/package.json b/package.json index 56895c5..0e2e281 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "now", - "version": "0.18.1", + "version": "0.19.0", "description": "realtime instant node.js deployment with one command", "readme": "", "main": "./build/lib/index",