exec-sh
Advanced tools
Comparing version 0.2.2 to 0.3.0
@@ -85,2 +85,19 @@ var cp = require('child_process') | ||
execSh.promise = function (command, options) { | ||
return new Promise(function (resolve, reject) { | ||
execSh(command, options, function (err, stdout, stderr) { | ||
if (err) { | ||
err.stdout = stdout | ||
err.stderr = stderr | ||
return reject(err) | ||
} | ||
resolve({ | ||
stderr: stderr, | ||
stdout: stdout | ||
}) | ||
}) | ||
}) | ||
} | ||
module.exports = execSh |
{ | ||
"name": "exec-sh", | ||
"version": "0.2.2", | ||
"version": "0.3.0", | ||
"description": "Execute shell command forwarding all stdio.", | ||
@@ -5,0 +5,0 @@ "main": "lib/exec-sh.js", |
@@ -69,2 +69,25 @@ # exec-sh | ||
## Promise Interface | ||
```javascript | ||
var execShPromise = require("exec-sh").promise; | ||
// run interactive bash shell | ||
const run = async () => { | ||
let out; | ||
try { | ||
out = await execShPromise('pwd', true); | ||
} catch (e) { | ||
return console.log('Error: ', e); | ||
return console.log('Stderr: ', e.stderr); | ||
return console.log('Stdout: ', e.stdout); | ||
} | ||
console.log('out: ', out.stdout, out.stderr); | ||
} | ||
run(); | ||
``` | ||
## Public API | ||
@@ -71,0 +94,0 @@ |
@@ -13,2 +13,6 @@ /* global describe, it, beforeEach, afterEach */ | ||
}) | ||
it('should export promise interface', function () { | ||
assert.strictEqual(typeof execSh.promise, 'function') | ||
}) | ||
}) | ||
@@ -149,3 +153,23 @@ | ||
}) | ||
it('promise interface: should return promise', function () { | ||
assert(execSh.promise('command') instanceof Promise) | ||
}) | ||
it('promise interface: should resolve with stderr and stdout', function (done) { | ||
execSh.promise('command').then(function (data) { | ||
assert(data.hasOwnProperty('stdout')) | ||
assert(data.hasOwnProperty('stderr')) | ||
done() | ||
}) | ||
}) | ||
it('promise interface: should reject promise when exceptions thrown by spawn', function (done) { | ||
spawn.throws() | ||
execSh.promise('command').catch(function (err) { | ||
assert(err instanceof Error) | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
22761
250
126
2