Upgrade `merge-streams` (#717)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 0fbd3a2 · Browse files · 3 files·+20 added−10 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+20 added−10 removed
- tests:+14 added−0 removed
- other:+6 added−10 removed
Provenance
- Commit
8ef8e90- Tree
9c36657- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
0fbd3a2
3 files changed+20 added−10 removed
modified:lib/stream.js+5 added-9 removed
24 unmodified lines25262728292930313233343536323334353610 unmodified lines4748495055515253545560565758596055 unmodified lines11611711811912412012112212312424 unmodified lines24 unmodified lines }};
const getStdioPromise = ({stream, stdioStreams, encoding, buffer, maxBuffer}) => stdioStreams[0].direction === 'output' ? getStreamPromise({stream, encoding, buffer, maxBuffer, objectMode: stream?.readableObjectMode}) ? getStreamPromise({stream, encoding, buffer, maxBuffer}) : undefined;
const getAllPromise = ({spawned, encoding, buffer, maxBuffer}) => { const stream = getAllStream(spawned, encoding); const objectMode = spawned.stdout?.readableObjectMode || spawned.stderr?.readableObjectMode; return getStreamPromise({stream, encoding, buffer, maxBuffer, objectMode});};const getAllPromise = ({spawned, encoding, buffer, maxBuffer}) => getStreamPromise({stream: getAllStream(spawned, encoding), encoding, buffer, maxBuffer: maxBuffer * 2});
// When `childProcess.stdout` is in objectMode but not `childProcess.stderr` (or the opposite), we need to use both:// - `getStreamAsArray()` for the chunks in objectMode, to return as an array without changing each chunk// - `getStreamAsArrayBuffer()` or `getStream()` for the chunks not in objectMode, to convert them from Buffers to string or Uint8Array10 unmodified lines writableObjectMode: true, readableObjectMode: true,};
const getStreamPromise = async ({stream, encoding, buffer, maxBuffer, objectMode}) => {const getStreamPromise = async ({stream, encoding, buffer, maxBuffer}) => { if (!stream || !buffer) { return; }
if (objectMode) { if (stream.readableObjectMode) { return getStreamAsArray(stream, {maxBuffer}); }
const contents = encoding === 'buffer'55 unmodified lines cleanupOnExit(spawned, cleanup, detached, finalizers); const customStreams = getCustomStreams(stdioStreamsGroups);
const stdioPromises = spawned.stdio.map((stream, index) => getStdioPromise({stream, stdioStreams: stdioStreamsGroups[index], encoding, buffer, maxBuffer})); const allPromise = getAllPromise({spawned, encoding, buffer, maxBuffer: maxBuffer * 2}); const allPromise = getAllPromise({spawned, encoding, buffer, maxBuffer});
try { return await Promise.race([ Promise.all([24 unmodified linesmodified:test/stream.js+14 added
1 import {Buffer} from 'node:buffer';2 import {once} from 'node:events';3 import process from 'node:process';4+import {getDefaultHighWaterMark} from 'node:stream';5 import {setTimeout} from 'node:timers/promises';6 import test from 'ava';7 import getStream from 'get-stream';8 import {execa, execaSync} from '../index.js';18 unmodified lines27 const {all} = await execa('noop.js', {stdio: 'ignore', all: true});28 t.is(all, undefined);29 });30 31+const testAllProperties = async (t, options) => {32+ const childProcess = execa('empty.js', {...options, all: true});33+ t.is(childProcess.all.readableObjectMode, false);34+ t.is(childProcess.all.readableHighWaterMark, getDefaultHighWaterMark(false));35+ await childProcess;36+};37+38+test('childProcess.all has the right objectMode and highWaterMark - stdout + stderr', testAllProperties, {});39+test('childProcess.all has the right objectMode and highWaterMark - stdout only', testAllProperties, {stderr: 'ignore'});40+test('childProcess.all has the right objectMode and highWaterMark - stderr only', testAllProperties, {stdout: 'ignore'});41+42 const testAllIgnore = async (t, streamName, otherStreamName) => {43 const childProcess = execa('noop-both.js', {[otherStreamName]: 'ignore', all: true});44 t.is(childProcess[otherStreamName], null);45 t.not(childProcess[streamName], null);46 t.not(childProcess.all, null);47+ t.is(childProcess.all.readableObjectMode, childProcess[streamName].readableObjectMode);48+ t.is(childProcess.all.readableHighWaterMark, childProcess[streamName].readableHighWaterMark);49 50 const result = await childProcess;51 t.is(result[otherStreamName], undefined);52 t.is(result[streamName], 'foobar');298 unmodified linesmodified:package.json+1 added-1 removed
43 unmodified lines44 "local",45 "zx"46 ],47 "dependencies": {48- "@sindresorhus/merge-streams": "^1.0.0",48+ "@sindresorhus/merge-streams": "^2.0.1",49 "cross-spawn": "^7.0.3",50 "get-stream": "^8.0.1",51 "human-signals": "^6.0.0",52 "is-stream": "^3.0.0",38 unmodified lines