teen_process
Advanced tools
Comparing version 1.14.2 to 1.14.3
@@ -27,3 +27,8 @@ "use strict"; | ||
} = _events.default; | ||
const MAX_LINE_PORTION_LENGTH = 0xFFFF; | ||
function cutSuffix(str, suffixLength) { | ||
return str.length > suffixLength ? ` ${str.substr(str.length - suffixLength)}`.substr(1) : str; | ||
} | ||
class SubProcess extends EventEmitter { | ||
@@ -102,4 +107,11 @@ constructor(cmd, args = [], opts = {}) { | ||
const handleOutput = data => { | ||
const streams = _lodash.default.cloneDeep(data); | ||
const { | ||
stdout, | ||
stderr | ||
} = streams; | ||
try { | ||
if (startDetector && startDetector(data.stdout, data.stderr)) { | ||
if (startDetector && startDetector(stdout, stderr)) { | ||
startDetector = null; | ||
@@ -112,16 +124,22 @@ resolve(); | ||
this.emit('output', data.stdout, data.stderr); | ||
this.emit('output', stdout, stderr); | ||
for (const stream of ['stdout', 'stderr']) { | ||
if (!data[stream]) continue; | ||
let lines = data[stream].split('\n'); | ||
for (const [streamName, streamData] of _lodash.default.toPairs(streams)) { | ||
if (!streamData) continue; | ||
const lines = streamData.split('\n').map(x => ` ${x}`.substr(1)); | ||
if (lines.length > 1) { | ||
let retLines = lines.slice(0, -1); | ||
retLines[0] = this.lastLinePortion[stream] + retLines[0]; | ||
this.lastLinePortion[stream] = lines[lines.length - 1]; | ||
this.emit(`lines-${stream}`, retLines); | ||
this.emitLines(stream, retLines); | ||
lines[0] = this.lastLinePortion[streamName] + lines[0]; | ||
this.lastLinePortion[streamName] = cutSuffix(_lodash.default.last(lines), MAX_LINE_PORTION_LENGTH); | ||
const resultLines = lines.slice(0, -1); | ||
this.emit(`lines-${streamName}`, resultLines); | ||
this.emitLines(streamName, resultLines); | ||
} else { | ||
this.lastLinePortion[stream] += lines[0]; | ||
const currentPortion = cutSuffix(lines[0], MAX_LINE_PORTION_LENGTH); | ||
if (this.lastLinePortion[streamName].length + currentPortion.length > MAX_LINE_PORTION_LENGTH) { | ||
this.lastLinePortion[streamName] = currentPortion; | ||
} else { | ||
this.lastLinePortion[streamName] += currentPortion; | ||
} | ||
} | ||
@@ -256,2 +274,2 @@ } | ||
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImxpYi9zdWJwcm9jZXNzLmpzIl0sIm5hbWVzIjpbIkV2ZW50RW1pdHRlciIsImV2ZW50cyIsIlN1YlByb2Nlc3MiLCJjb25zdHJ1Y3RvciIsImNtZCIsImFyZ3MiLCJvcHRzIiwiRXJyb3IiLCJfIiwiaXNTdHJpbmciLCJpc0FycmF5IiwicHJvYyIsImV4cGVjdGluZ0V4aXQiLCJyZXAiLCJpc1J1bm5pbmciLCJlbWl0TGluZXMiLCJzdHJlYW0iLCJsaW5lcyIsImxpbmUiLCJlbWl0IiwidG9VcHBlckNhc2UiLCJzdGFydCIsInN0YXJ0RGV0ZWN0b3IiLCJ0aW1lb3V0TXMiLCJkZXRhY2giLCJzdGFydERlbGF5IiwiZ2VuZXJpY1N0YXJ0RGV0ZWN0b3IiLCJzdGRvdXQiLCJzdGRlcnIiLCJpc051bWJlciIsImlzQm9vbGVhbiIsImRldGFjaGVkIiwiQiIsInJlc29sdmUiLCJyZWplY3QiLCJzZXRFbmNvZGluZyIsImVuY29kaW5nIiwibGFzdExpbmVQb3J0aW9uIiwiaGFuZGxlT3V0cHV0IiwiZGF0YSIsImUiLCJzcGxpdCIsImxlbmd0aCIsInJldExpbmVzIiwic2xpY2UiLCJvbiIsImVyciIsInJlbW92ZUFsbExpc3RlbmVycyIsImtpbGwiLCJlcnJubyIsInBpcGUiLCJjb2RlIiwic2lnbmFsIiwiaGFuZGxlTGFzdExpbmVzIiwiZXZlbnQiLCJzZXRUaW1lb3V0IiwiZmluYWxseSIsInVucmVmIiwibGFzdExpbmVzIiwic3RvcCIsInRpbWVvdXQiLCJqb2luIiwiYWxsb3dlZEV4aXRDb2RlcyIsImluZGV4T2YiLCJkZXRhY2hQcm9jZXNzIiwicGlkIl0sIm1hcHBpbmdzIj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HRoaXMucHJvYy5waWQgOiBudWxsO1xuICB9XG59XG5cbmV4cG9ydCB7IFN1YlByb2Nlc3MgfTtcbmV4cG9ydCBkZWZhdWx0IFN1YlByb2Nlc3M7XG4iXSwiZmlsZSI6ImxpYi9zdWJwcm9jZXNzLmpzIiwic291cmNlUm9vdCI6Ii4uLy4uIn0= |
@@ -11,3 +11,15 @@ /* eslint-disable promise/prefer-await-to-callbacks */ | ||
// This is needed to avoid memory leaks | ||
// when the process output is too long and contains | ||
// no line breaks | ||
const MAX_LINE_PORTION_LENGTH = 0xFFFF; | ||
function cutSuffix (str, suffixLength) { | ||
return str.length > suffixLength | ||
// https://bugs.chromium.org/p/v8/issues/detail?id=2869 | ||
? ` ${str.substr(str.length - suffixLength)}`.substr(1) | ||
: str; | ||
} | ||
class SubProcess extends EventEmitter { | ||
@@ -92,6 +104,8 @@ constructor (cmd, args = [], opts = {}) { | ||
const handleOutput = (data) => { | ||
const streams = _.cloneDeep(data); | ||
const {stdout, stderr} = streams; | ||
// if we have a startDetector, run it on the output so we can resolve/ | ||
// reject and move on from start | ||
try { | ||
if (startDetector && startDetector(data.stdout, data.stderr)) { | ||
if (startDetector && startDetector(stdout, stderr)) { | ||
startDetector = null; | ||
@@ -105,3 +119,3 @@ resolve(); | ||
// emit the actual output for whomever's listening | ||
this.emit('output', data.stdout, data.stderr); | ||
this.emit('output', stdout, stderr); | ||
@@ -112,13 +126,20 @@ // we also want to emit lines, but it's more complex since output | ||
// remember a line that started but did not finish in the last chunk) | ||
for (const stream of ['stdout', 'stderr']) { | ||
if (!data[stream]) continue; // eslint-disable-line curly | ||
let lines = data[stream].split('\n'); | ||
for (const [streamName, streamData] of _.toPairs(streams)) { | ||
if (!streamData) continue; // eslint-disable-line curly | ||
const lines = streamData.split('\n') | ||
// https://bugs.chromium.org/p/v8/issues/detail?id=2869 | ||
.map((x) => ` ${x}`.substr(1)); | ||
if (lines.length > 1) { | ||
let retLines = lines.slice(0, -1); | ||
retLines[0] = this.lastLinePortion[stream] + retLines[0]; | ||
this.lastLinePortion[stream] = lines[lines.length - 1]; | ||
this.emit(`lines-${stream}`, retLines); | ||
this.emitLines(stream, retLines); | ||
lines[0] = this.lastLinePortion[streamName] + lines[0]; | ||
this.lastLinePortion[streamName] = cutSuffix(_.last(lines), MAX_LINE_PORTION_LENGTH); | ||
const resultLines = lines.slice(0, -1); | ||
this.emit(`lines-${streamName}`, resultLines); | ||
this.emitLines(streamName, resultLines); | ||
} else { | ||
this.lastLinePortion[stream] += lines[0]; | ||
const currentPortion = cutSuffix(lines[0], MAX_LINE_PORTION_LENGTH); | ||
if (this.lastLinePortion[streamName].length + currentPortion.length > MAX_LINE_PORTION_LENGTH) { | ||
this.lastLinePortion[streamName] = currentPortion; | ||
} else { | ||
this.lastLinePortion[streamName] += currentPortion; | ||
} | ||
} | ||
@@ -125,0 +146,0 @@ } |
@@ -8,3 +8,3 @@ { | ||
], | ||
"version": "1.14.2", | ||
"version": "1.14.3", | ||
"author": "appium", | ||
@@ -11,0 +11,0 @@ "license": "Apache-2.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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
81325
876
7