summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/pacote/lib/util/finished.js
blob: 6dadc8b5b3b669975f19cd92f101add677872962 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
'use strict'

const BB = require('bluebird')

module.exports = function (child, hasExitCode = false) {
  return BB.fromNode(function (cb) {
    child.on('error', cb)
    child.on(hasExitCode ? 'close' : 'end', function (exitCode) {
      if (exitCode === undefined || exitCode === 0) {
        cb()
      } else {
        let err = new Error('exited with error code: ' + exitCode)
        cb(err)
      }
    })
  })
}