diff --git a/lib/handlers/git/tarball.js b/lib/handlers/git/tarball.js index 6880878..c7a04b2 100644 --- a/lib/handlers/git/tarball.js +++ b/lib/handlers/git/tarball.js @@ -12,7 +12,6 @@ const path = require('path') const pipe = BB.promisify(require('mississippi').pipe) const rimraf = BB.promisify(require('rimraf')) const tar = require('tar-fs') -const to = require('mississippi').to const uniqueFilename = require('unique-filename') const gitManifest = require('./manifest') @@ -20,12 +19,10 @@ const gitManifest = require('./manifest') module.exports = tarball function tarball (spec, opts) { opts = optCheck(opts) - let streamErr = null - const stream = new PassThrough().on('error', e => { streamErr = e }) + const stream = new PassThrough() gitManifest(spec, opts).then(manifest => { - if (streamErr) { throw streamErr } return pipe(fromManifest(manifest, spec, opts), stream) - }) + }, err => stream.emit('error', err)) return stream } @@ -46,7 +43,7 @@ function fromManifest (manifest, spec, opts) { return stream.emit('error', err) } else { stream.emit('reset') - withTmp(opts, tmp => { + return withTmp(opts, tmp => { if (streamError) { throw streamError } return cloneRepo( manifest._repo, manifest._ref, manifest._rawRef, tmp, opts @@ -100,20 +97,9 @@ function packDir (spec, label, tmp, target, opts) { const cacher = cache.put.stream( opts.cache, cache.key('git-clone', label), opts ) - cacher.once('error', err => packer.emit('error', err)) - target.once('error', err => packer.emit('error', err)) - packer.once('error', err => { - cacher.emit('error', err) - target.emit('error', err) - }) - return pipe(packer, to((chunk, enc, cb) => { - cacher.write(chunk, enc, () => { - target.write(chunk, enc, cb) - }) - }, done => { - cacher.end(() => { - target.end(done) - }) - })) + return Promise.all([ + pipe(packer, cacher), + pipe(packer, target) + ]) } }