From 2349363917963ed55dcdaa91e0a0b93879e27962 Mon Sep 17 00:00:00 2001 From: igorklopov Date: Tue, 16 Aug 2016 17:15:34 +0300 Subject: [PATCH] reimplemented promised spawn --- lib/build.js | 2 +- lib/spawn.js | 15 ++++++++++++--- package.json | 1 - 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/build.js b/lib/build.js index f447c33..18a4d78 100644 --- a/lib/build.js +++ b/lib/build.js @@ -16,7 +16,7 @@ const nodeRepo = 'https://github.com/nodejs/node'; async function gitClone () { const args = [ 'clone', '--progress', nodeRepo, 'node' ]; const promise = spawn('git', args, { cwd: buildPath }); - const child = promise.childProcess; + const { child } = promise; const gauge = log.newItem('', 100); gauge.enableProgress(); diff --git a/lib/spawn.js b/lib/spawn.js index eb9e7c7..9f86556 100644 --- a/lib/spawn.js +++ b/lib/spawn.js @@ -1,5 +1,14 @@ -import chipo from 'child-process-promise'; +import chipo from 'child_process'; -export function spawn (...args) { - return chipo.spawn(...args); +export function spawn (cmd, args, opts) { + const child = chipo.spawn(cmd, args, opts); + const promise = new Promise((resolve, reject) => { + child.on('error', reject); + child.on('close', function (code) { + if (code) return reject(new Error(`${cmd} failed with code ${code}`)); + resolve(); + }); + }); + promise.child = child; + return promise; } diff --git a/package.json b/package.json index 3b837d4..b134922 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,6 @@ ] }, "dependencies": { - "child-process-promise": "2.0.3", "expand-template": "1.0.2", "fs-promise": "0.5.0", "minimist": "1.2.0",