Skip to content
Myr

Fix `encoding` option not working with `ignore` and `inherit` (#738)

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

authored by ehmicky · committed by GitHub · parent a5761a8 · Browse files · 4 files+51 added−16 removed
This commit

State

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

Diff stats

4 files+51 added−16 removed

  • tests:+24 added−0 removed
  • other:+27 added−16 removed

4 files+51 added−16 removed

modified:lib/stdio/encoding.js+7 added-1 removed
modified:lib/stdio/handle.js+2 added-15 removed
added:lib/stdio/pipe.js+18 added
1// When the `std*: Iterable | WebStream | URL | filePath`, `input` or `inputFile` option is used, we pipe to `childProcess.std*`.2// When the `std*: Array` option is used, we emulate some of the native values ('inherit', Node.js stream and file descriptor integer). To do so, we also need to pipe to `childProcess.std*`.3// Therefore the `std*` options must be either `pipe` or `overlapped`. Other values do not set `childProcess.std*`.4export const updateStdio = stdioStreamsGroups => stdioStreamsGroups.map(stdioStreams => updateStdioItem(stdioStreams));56// Whether `childProcess.std*` will be set7export const willPipeStreams = stdioStreams => PIPED_STDIO_VALUES.has(updateStdioItem(stdioStreams));89const PIPED_STDIO_VALUES = new Set(['pipe', 'overlapped', undefined, null]);1011const updateStdioItem = stdioStreams => {12 if (stdioStreams.length > 1) {13 return stdioStreams.some(({value}) => value === 'overlapped') ? 'overlapped' : 'pipe';14 }1516 const [stdioStream] = stdioStreams;17 return stdioStream.type !== 'native' && stdioStream.value !== 'overlapped' ? 'pipe' : stdioStream.value;18};
modified:test/stdio/encoding.js+24 added
1import {Buffer} from 'node:buffer';2import {exec} from 'node:child_process';3import process from 'node:process';4import {promisify} from 'node:util';5import test from 'ava';6import getStream, {getStreamAsBuffer} from 'get-stream';7import {execa, execaSync} from '../../index.js';
139 unmodified lines
147test('Other encodings work with transforms that return objects', async t => {148 const {stdout} = await execa('noop.js', {stdout: outputObjectGenerator, encoding: 'base64'});149 t.deepEqual(stdout, [foobarObject]);150});151152const testIgnoredEncoding = async (t, stdoutOption, isUndefined) => {153 const {stdout} = await execa('empty.js', {stdout: stdoutOption, encoding: 'base64'});154 t.is(stdout === undefined, isUndefined);155};156157test('Is ignored with other encodings and "ignore"', testIgnoredEncoding, 'ignore', true);158test('Is ignored with other encodings and ["ignore"]', testIgnoredEncoding, ['ignore'], true);159test('Is ignored with other encodings and "ipc"', testIgnoredEncoding, 'ipc', true);160test('Is ignored with other encodings and ["ipc"]', testIgnoredEncoding, ['ipc'], true);161test('Is ignored with other encodings and "inherit"', testIgnoredEncoding, 'inherit', true);162test('Is ignored with other encodings and ["inherit"]', testIgnoredEncoding, ['inherit'], true);163test('Is ignored with other encodings and 1', testIgnoredEncoding, 1, true);164test('Is ignored with other encodings and [1]', testIgnoredEncoding, [1], true);165test('Is ignored with other encodings and process.stdout', testIgnoredEncoding, process.stdout, true);166test('Is ignored with other encodings and [process.stdout]', testIgnoredEncoding, [process.stdout], true);167test('Is not ignored with other encodings and "pipe"', testIgnoredEncoding, 'pipe', false);168test('Is not ignored with other encodings and ["pipe"]', testIgnoredEncoding, ['pipe'], false);169test('Is not ignored with other encodings and "overlapped"', testIgnoredEncoding, 'overlapped', false);170test('Is not ignored with other encodings and ["overlapped"]', testIgnoredEncoding, ['overlapped'], false);171test('Is not ignored with other encodings and ["inherit", "pipe"]', testIgnoredEncoding, ['inherit', 'pipe'], false);172test('Is not ignored with other encodings and undefined', testIgnoredEncoding, undefined, false);173test('Is not ignored with other encodings and null', testIgnoredEncoding, null, false);