Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

executive

Package Overview
Dependencies
Maintainers
1
Versions
86
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

executive - npm Package Compare versions

Comparing version 0.2.3 to 0.2.4

test.js

172

index.js

@@ -1,2 +0,3 @@

var child_process = require('child_process');
var child_process = require('child_process'),
Stream = require('stream');

@@ -19,11 +20,100 @@ function parseShell(s) {

function exec(args, options, callback) {
var env = process.env,
function bufferedExec(cmd, args, callback) {
var err = '',
out = '';
// stream to capture stdout
stdout = new Stream();
stdout.writable = true;
stdout.write = function(data) {
out += data;
};
stdout.end = function(data) {
if (arguments.length) stdout.write(data);
stdout.writable = false;
};
stdout.destroy = function() {
stdout.writable = false;
};
// stream to capture stderr
stderr = new Stream();
stderr.writable = true;
stderr.write = function(data) {
err += data;
};
stderr.end = function(data) {
if (arguments.length) stderr.write(data);
stderr.writable = false;
};
stderr.destroy = function() {
stderr.writable = false;
};
var child = child_process.spawn(cmd, args, {stdio: [0, 'pipe', 'pipe']});
child.setMaxListeners(0);
child.stdout.setEncoding('utf8');
child.stderr.setEncoding('utf8');
child.stdout.pipe(stdout);
child.stderr.pipe(stderr);
child.stdout.pipe(process.stdout);
child.stderr.pipe(process.stderr);
child.on('close', function(code) {
stdout.destroy();
stderr.destroy();
callback(err, out, code);
});
return child;
}
function interactiveExec(cmd, args, callback) {
var child = child_process.spawn(cmd, args, {stdio: [0, 1, 2]});
child.setMaxListeners(0);
child.on('exit', function(code) {
callback(null, null, code);
});
return child;
}
// Do not echo to stdout/stderr
function quietExec(cmd, args, callback) {
var child = child_process.spawn(cmd, args),
err = '',
out = '',
cmd,
_var,
arg,
proc;
out = '';
child.setMaxListeners(0);
child.stdout.setEncoding('utf8');
child.stderr.setEncoding('utf8');
child.stdout.on('data', function(data) {
out += data;
});
child.stderr.on('data', function(data) {
err += data;
});
child.on('close', function(code) {
callback(err, out, code);
});
return child;
}
function exec(args, options, callback) {
var _var, cmd, arg;
// Reverse arguments, javascript does not support lookbehind assertions so

@@ -57,54 +147,9 @@ // we'll use a lookahead assertion instead in our regex later.

if (options.quiet) {
// Do not echo to stdout/stderr
proc = child_process.spawn(cmd, args, {env: env});
if (options.quiet)
return quietExec(cmd, args, callback);
proc.stdout.on('data', function(data) {
out += data.toString();
});
if (options.interactive)
return interactiveExec(cmd, args, callback);
proc.stderr.on('data', function(data) {
err += data.toString();
});
proc.on('close', function(code) {
callback(err, out, code);
});
} else {
// Echo to stdout/stderr and handle stdin (unless interactive)
proc = child_process.spawn(cmd, args, {env: env, stdio: [0, 1, 2]});
proc.setMaxListeners(0);
if (!options.interactive) {
process.stdin.resume();
var stdoutListener = function(data) {
out += data.toString();
};
var stderrListener = function(data) {
err += data.toString();
};
try {
process.stdout.on('data', stdoutListener);
process.stderr.on('data', stderrListener);
} catch (error) {
// well guess that won't work...
}
}
proc.on('exit', function(code) {
if (!options.interactive) {
process.stdin.pause();
process.stdout.removeListener('data', stdoutListener);
process.stderr.removeListener('data', stderrListener);
}
callback(err, out, code);
});
}
return proc;
return bufferedExec(cmd, args, callback);
}

@@ -129,3 +174,5 @@

var complete = 0;
var complete = 0,
outBuf = '',
errBuf = '';

@@ -135,4 +182,7 @@ // Iterate over list of cmds, calling each in order as long as all of them return without errors

return exec(cmds[complete], options, function(err, out, code) {
errBuf += err;
outBuf += out;
if (options.safe && code !== 0) {
return callback(err, out, code);
return callback(errBuf, outBuf, code);
}

@@ -142,3 +192,3 @@

if (complete === cmds.length) {
callback(err, out, code);
callback(errBuf, outBuf, code);
} else {

@@ -145,0 +195,0 @@ iterate();

{
"name": "executive",
"version": "0.2.3",
"version": "0.2.4",
"description": "exec for the lazy",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc