Comparing version 1.2.8 to 1.2.9
@@ -5,3 +5,3 @@ { | ||
"homepage": "https://github.com/microlinkhq/tinyspawn", | ||
"version": "1.2.8", | ||
"version": "1.2.9", | ||
"main": "src/index.js", | ||
@@ -63,3 +63,3 @@ "author": { | ||
"engines": { | ||
"node": ">= 16" | ||
"node": ">= 18" | ||
}, | ||
@@ -66,0 +66,0 @@ "files": [ |
@@ -6,15 +6,25 @@ 'use strict' | ||
const EE_PROPS = Object.getOwnPropertyNames(require('events').EventEmitter.prototype).filter(name => !name.startsWith('_')) | ||
const EE_PROPS = Object.getOwnPropertyNames( | ||
require('events').EventEmitter.prototype | ||
) | ||
.filter(name => !name.startsWith('_')) | ||
.concat(['kill', 'ref', 'unref']) | ||
const eos = (stream, listener, buffer = []) => stream[listener].on('data', data => buffer.push(data)) && buffer | ||
const eos = (stream, listener, buffer = []) => | ||
stream[listener].on('data', data => buffer.push(data)) && buffer | ||
const clean = str => str.trim().replace(/\n$/, '') | ||
const parse = (buffer, { json } = {}) => (encoding, start, end) => { | ||
const data = clean(Buffer.concat(buffer).toString(encoding, start, end)) | ||
return json ? JSON.parse(data) : data | ||
} | ||
const parse = | ||
(buffer, { json } = {}) => | ||
(encoding, start, end) => { | ||
const data = clean(Buffer.concat(buffer).toString(encoding, start, end)) | ||
return json ? JSON.parse(data) : data | ||
} | ||
const extend = defaults => (input, args, options) => { | ||
if (!(args instanceof Array)) { options = args; args = [] } | ||
if (!(args instanceof Array)) { | ||
options = args | ||
args = [] | ||
} | ||
const [cmd, ...cmdArgs] = input.split(' ').concat(args).filter(Boolean) | ||
@@ -29,23 +39,32 @@ let childProcess | ||
childProcess | ||
.on('error', reject) | ||
.on('exit', code => { | ||
Object.defineProperty(childProcess, 'stdout', { get: parse(stdout, opts) }) | ||
Object.defineProperty(childProcess, 'stderr', { get: parse(stderr) }) | ||
if (code === 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: ${code} }\` 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) | ||
childProcess.on('error', reject).on('exit', code => { | ||
Object.defineProperty(childProcess, 'stdout', { | ||
get: parse(stdout, opts) | ||
}) | ||
Object.defineProperty(childProcess, 'stderr', { get: parse(stderr) }) | ||
if (code === 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: ${code} }\` 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) | ||
}) | ||
}) | ||
const subprocess = Object.assign(promise, childProcess) | ||
if (childProcess) EE_PROPS.forEach(name => (subprocess[name] = childProcess[name].bind(childProcess))) | ||
if (childProcess) { | ||
EE_PROPS.forEach( | ||
name => (subprocess[name] = childProcess[name].bind(childProcess)) | ||
) | ||
} | ||
return subprocess | ||
@@ -52,0 +71,0 @@ } |
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
11717
64