Comparing version 1.2.13 to 1.2.14
@@ -5,3 +5,3 @@ { | ||
"homepage": "https://github.com/microlinkhq/tinyspawn", | ||
"version": "1.2.13", | ||
"version": "1.2.14", | ||
"main": "src/index.js", | ||
@@ -8,0 +8,0 @@ "author": { |
@@ -6,5 +6,3 @@ 'use strict' | ||
const EE_PROPS = Object.getOwnPropertyNames( | ||
require('events').EventEmitter.prototype | ||
) | ||
const EE_PROPS = Object.getOwnPropertyNames(require('events').EventEmitter.prototype) | ||
.filter(name => !name.startsWith('_')) | ||
@@ -14,6 +12,22 @@ .concat(['kill', 'ref', 'unref']) | ||
const eos = (stream, listener, buffer = []) => | ||
stream[listener] | ||
? stream[listener].on('data', data => buffer.push(data)) && buffer | ||
: buffer | ||
stream[listener] ? stream[listener].on('data', data => buffer.push(data)) && buffer : buffer | ||
const createChildProcessError = ({ cmd, cmdArgs, exitCode, stderr, childProcess }) => { | ||
const command = `${cmd} ${cmdArgs.join(' ')}` | ||
let message = `The command spawned as:${EOL}${EOL}` | ||
message += ` ${command}${EOL}${EOL}` | ||
message += `exited with \`{ code: ${exitCode} }\` and the following trace:${EOL}${EOL}` | ||
message += String(stderr) | ||
.split(EOL) | ||
.map(line => ` ${line}`) | ||
.join(EOL) | ||
const error = new Error(message) | ||
error.command = command | ||
error.name = 'ChildProcessError' | ||
Object.keys(childProcess).forEach(key => { | ||
error[key] = childProcess[key] | ||
}) | ||
return error | ||
} | ||
const clean = str => str.trim().replace(/\n$/, '') | ||
@@ -47,18 +61,5 @@ | ||
Object.defineProperty(childProcess, 'stderr', { get: parse(stderr) }) | ||
if (exitCode === 0) return resolve(childProcess) | ||
const command = `${cmd} ${cmdArgs.join(' ')}` | ||
let message = `The command spawned as:${EOL}${EOL}` | ||
message += ` ${command}${EOL}${EOL}` | ||
message += `exited with \`{ code: ${exitCode} }\` and the following trace:${EOL}${EOL}` | ||
message += String(stderr) | ||
.split(EOL) | ||
.map(line => ` ${line}`) | ||
.join(EOL) | ||
const error = new Error(message) | ||
error.command = command | ||
error.name = 'ChildProcessError' | ||
Object.keys(childProcess).forEach(key => { | ||
error[key] = childProcess[key] | ||
}) | ||
reject(error) | ||
return exitCode === 0 | ||
? resolve(childProcess) | ||
: reject(createChildProcessError({ cmd, cmdArgs, exitCode, stderr, childProcess })) | ||
}) | ||
@@ -69,5 +70,3 @@ }) | ||
if (childProcess) { | ||
EE_PROPS.forEach( | ||
name => (subprocess[name] = childProcess[name].bind(childProcess)) | ||
) | ||
EE_PROPS.forEach(name => (subprocess[name] = childProcess[name].bind(childProcess))) | ||
} | ||
@@ -74,0 +73,0 @@ return subprocess |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11874
64