Skip to content
Myr

Refactor `getStream()` (#287)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ehmicky · committed by Sindre Sorhus · parent 76c2e07 · Browse files · 1 file+14 added−19 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+14 added−19 removed

  • other:+14 added−19 removed

1 file+14 added−19 removed

modified:index.js+14 added-19 removed
5 unmodified lines
6const crossSpawn = require('cross-spawn');7const stripFinalNewline = require('strip-final-newline');8const npmRunPath = require('npm-run-path');9const isStream = require('is-stream');10const _getStream = require('get-stream');10const getStream = require('get-stream');11const mergeStream = require('merge-stream');12const pFinally = require('p-finally');13const onExit = require('signal-exit');14const stdio = require('./lib/stdio');
104 unmodified lines
119 return error.bufferedData;120 }121}122123function getStream(process, stream, {encoding, buffer, maxBuffer}) {124 if (!process[stream]) {123function getStreamPromise(stream, {encoding, buffer, maxBuffer}) {124 if (!stream) {125 return;126 }127128 let ret;129128 if (!buffer) {131 // TODO: Use `ret = util.promisify(stream.finished)(process[stream]);` when targeting Node.js 10132 ret = new Promise((resolve, reject) => {133 process[stream]129 // TODO: Use `ret = util.promisify(stream.finished)(stream);` when targeting Node.js 10130 return new Promise((resolve, reject) => {131 stream132 .once('end', resolve)133 .once('error', reject);134 });137 } else if (encoding) {138 ret = _getStream(process[stream], {139 encoding,140 maxBuffer141 });142 } else {143 ret = _getStream.buffer(process[stream], {maxBuffer});135 }136146 return ret;137 if (encoding) {138 return getStream(stream, {encoding, maxBuffer});139 }140141 return getStream.buffer(stream, {maxBuffer});142}143144function makeError(result, options) {145 const {stdout, stderr, signal} = result;
214 unmodified lines
360 }361 }), cleanup);362363 const handlePromise = () => {369 const stdoutPromise = getStream(spawned, 'stdout', {encoding, buffer, maxBuffer});370 const stderrPromise = getStream(spawned, 'stderr', {encoding, buffer, maxBuffer});371 const allPromise = getStream(spawned, 'all', {encoding, buffer, maxBuffer: maxBuffer * 2});364 const stdoutPromise = getStreamPromise(spawned.stdout, {encoding, buffer, maxBuffer});365 const stderrPromise = getStreamPromise(spawned.stderr, {encoding, buffer, maxBuffer});366 const allPromise = getStreamPromise(spawned.all, {encoding, buffer, maxBuffer: maxBuffer * 2});367368 const finalize = async () => {369 let results;370 try {
152 unmodified lines