Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function sleepyhollow() {
// the modified event-emitter bridge
var sleepyhollow = new EventEmitter();
_emit = sleepyhollow.emit;
sleepyhollow.emit = function(event, message) {
if (event !== "ack") write({ event: event, message : message });
_emit.apply(sleepyhollow, Array.prototype.slice.call(arguments, 0));
}
// the phantomjs process
var args = Array.prototype.slice.call(arguments, 0);
var phantomjs = spawn.apply(null, ['phantomjs', args]);
// if node goes down, don't leave phantom zombied
var exited = false;
process.on('exit', function() {
if (!exited) process.kill(phantomjs.pid, 'SIGINT');
});
// special listener to the child process lifecycle
phantomjs.on('exit', function() {
exited = true;
sleepyhollow.emit('exit');
});
// we use the stderr channel for communication because we listen on
// stdout for errors and debugging statements
phantomjs.stderr.on('data', function(data) {
function runCommand(executable, args) {
if (executable) {
pending.push([executable, args]);
}
if (!proc && pending.length) {
proc = spawn.apply(null, pending.shift());
proc.stdout.on('data', function(data) {
util.print(data);
});
proc.stderr.on('data', function(data) {
util.print(data);
});
proc.on('exit', function(code) {
if (code) {
util.print('exited with code ' + code + '\n');
}
proc = null;
runCommand();
});
npmPath.set({cwd: options.cwd, env: process.env}, function(err) {
options.stdio = 'inherit'
spawn.apply(null, args)
.once('error', function(err) {
if (err.code === 'ENOENT') {
err.cmd = args.slice(0, -1).join(' ')
err.message = 'Invalid npm-run command: ' + err.cmd
}
process.send(serializerr(err))
})
.on('close', function(code) {
process.exit(code)
})
})
openEditor._spawn = function() {
return spawn.apply(this, arguments);
};
function safeSpawn() {
var child = spawn.apply(this, arguments);
safeSpawn._children.push(child);
return child;
}
var spawnWithoutOutput = function () {
var proc = spawn.apply(null, arguments)
proc.stdout.resume()
proc.stderr.resume()
return proc
}
function safeSpawn() {
var child = spawn.apply(this, arguments);
safeSpawn._children.push(child);
return child;
}
function gitInstall () {
var args = ['clone', '--depth', '1', '-q', (self.url.replace('git+', '')), self.installTo]
var cmd = ['git', args]
if (self.ref) args.splice(1, 2)
if (typeof self._mock === 'function') {
self._mock(cmd)
} else {
self.log.info('git', '%s into %s', self.url, self.name)
var git = spawn.apply(spawn, cmd)
git.stderr.on('data', log.error)
git.on('close', function (code, signal) {
var checkout
if (code) return cb(code, signal)
if (self.ref) {
checkout = spawn('git', ['checkout', self.ref], {cwd: self.installTo})
checkout.stderr.on('data', log.info)
checkout.on('close', function () {
rimraf(path.resolve(self.installTo, '.git'), cb)
})
} else {
rimraf(path.resolve(self.installTo, '.git'), cb)
}
})
}
}
exports.spawnChild = function spawnChild(binPath, args, options, cacheKey,
readyMessage, printStdout, printStderr) {
var child, spawnArgs, stdoutBuffer, stderrBuffer,
timeoutId = null, readyEmitted = false;
args = args || [];
spawnArgs = [binPath, args];
if (options) {
spawnArgs.push(options);
}
child = spawn.apply(this, spawnArgs);
function emitReadyFunc(err) {
if (!readyEmitted) {
readyEmitted = true;
emitReady(cacheKey, child, err);
}
}
function handleStderr() {
emitReadyFunc(new Error('Received data on stderr: ' +
stderrBuffer.toString()));
}
child.stdout.on('data', function(chunk) {
stdoutBuffer += chunk;