diff --git a/package.json b/package.json index da71897f0a..290a9dec0b 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "./package.json": "./package.json" }, "bin": { - "zx": "./build/cli.js" + "zx": "build/cli.js" }, "man": "./man/zx.1", "files": [ @@ -150,7 +150,10 @@ "endOfLine": "lf", "trailingComma": "es5" }, - "repository": "google/zx", + "repository": { + "type": "git", + "url": "git+https://github.com/google/zx.git" + }, "homepage": "https://google.github.io/zx/", "author": "Anton Medvedev ", "license": "Apache-2.0" diff --git a/src/core.ts b/src/core.ts index 090a610d75..f7dbd80c75 100644 --- a/src/core.ts +++ b/src/core.ts @@ -472,6 +472,11 @@ export class ProcessPromise extends Promise { } this._piped = true if (dest instanceof ProcessPromise) { + const _reject = this._reject + this._reject = function (v) { + _reject(v) + dest._reject(v) + } dest.stdio('pipe') dest._prerun = this.run.bind(this) dest._postrun = () => { diff --git a/test/core.test.js b/test/core.test.js index 4380985b24..d1a46cd4cc 100644 --- a/test/core.test.js +++ b/test/core.test.js @@ -324,6 +324,27 @@ describe('core', () => { assert.equal(stdout, 'HELLO WORLD\n') }) + test('propagates rejection', async () => { + const p1 = $`exit 1` + const p2 = p1.pipe($`echo hello`) + + try { + await p1 + } catch (e) { + assert.equal(e.exitCode, 1) + } + + try { + await p2 + } catch (e) { + assert.equal(e.exitCode, 1) + } + + const p3 = await $({ nothrow: true })`echo hello && exit 1`.pipe($`cat`) + assert.equal(p3.exitCode, 0) + assert.equal(p3.stdout.trim(), 'hello') + }) + test('accepts Writable', async () => { let contents = '' let stream = new Writable({