Stricter values for the `encoding` option (#928)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent c9cdd2d · Browse files · 22 files·+139 added−99 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
22 files+139 added−99 removed
- tests:+39 added−38 removed
- other:+100 added−61 removed
Provenance
- Commit
477bbc4- Tree
3eb22ee- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
c9cdd2d
22 files changed+139 added−99 removed
added:lib/arguments/encoding.js+49 added
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849export const validateEncoding = ({encoding}) => { if (ENCODINGS.has(encoding)) { return; }
const correctEncoding = getCorrectEncoding(encoding); if (correctEncoding !== undefined) { throw new TypeError(`Invalid option \`encoding: ${serializeEncoding(encoding)}\`.Please rename it to ${serializeEncoding(correctEncoding)}.`); }
const correctEncodings = [...ENCODINGS].map(correctEncoding => serializeEncoding(correctEncoding)).join(', '); throw new TypeError(`Invalid option \`encoding: ${serializeEncoding(encoding)}\`.Please rename it to one of: ${correctEncodings}.`);};
const TEXT_ENCODINGS = new Set(['utf8', 'utf16le']);export const BINARY_ENCODINGS = new Set(['buffer', 'hex', 'base64', 'base64url', 'latin1', 'ascii']);const ENCODINGS = new Set([...TEXT_ENCODINGS, ...BINARY_ENCODINGS]);
const getCorrectEncoding = encoding => { if (encoding === null) { return 'buffer'; }
if (typeof encoding !== 'string') { return; }
const lowerEncoding = encoding.toLowerCase(); if (lowerEncoding in ENCODING_ALIASES) { return ENCODING_ALIASES[lowerEncoding]; }
if (ENCODINGS.has(lowerEncoding)) { return lowerEncoding; }};
const ENCODING_ALIASES = { // eslint-disable-next-line unicorn/text-encoding-identifier-case 'utf-8': 'utf8', 'utf-16le': 'utf16le', 'ucs-2': 'utf16le', ucs2: 'utf16le', binary: 'latin1',};
const serializeEncoding = encoding => typeof encoding === 'string' ? `"${encoding}"` : String(encoding);modified:lib/arguments/options.js+2 added
6 unmodified lines78910111213141539 unmodified lines55565758596061626359 unmodified lines6 unmodified linesimport {validateTimeout} from '../exit/timeout.js';import {logCommand} from '../verbose/start.js';import {getVerboseInfo} from '../verbose/info.js';import {getStartTime} from '../return/duration.js';import {validateEncoding} from './encoding.js';import {handleNodeOption} from './node.js';import {joinCommand} from './escape.js';import {normalizeCwd, safeNormalizeFileUrl, normalizeFileUrl} from './cwd.js';
39 unmodified lines const {command: file, args, options: initialOptions} = crossSpawn._parse(processedFile, processedArgs, processedOptions);
const options = addDefaultOptions(initialOptions); validateTimeout(options); validateEncoding(options); options.shell = normalizeFileUrl(options.shell); options.env = getEnv(options); options.forceKillAfterDelay = normalizeForceKillAfterDelay(options.forceKillAfterDelay);
59 unmodified linesmodified:lib/convert/add.js+2 added-2 removed
11234567891010111213142 unmodified linesimport {isBinaryEncoding} from '../encoding.js';import {BINARY_ENCODINGS} from '../arguments/encoding.js';import {initializeConcurrentStreams} from './concurrent.js';import {createReadable} from './readable.js';import {createWritable} from './writable.js';import {createDuplex} from './duplex.js';import {createIterable} from './iterable.js';
export const addConvertedStreams = (subprocess, {encoding}) => { const concurrentStreams = initializeConcurrentStreams(); const useBinaryEncoding = isBinaryEncoding(encoding); const useBinaryEncoding = BINARY_ENCODINGS.has(encoding); subprocess.readable = createReadable.bind(undefined, {subprocess, concurrentStreams, useBinaryEncoding}); subprocess.writable = createWritable.bind(undefined, {subprocess, concurrentStreams}); subprocess.duplex = createDuplex.bind(undefined, {subprocess, concurrentStreams, useBinaryEncoding}); subprocess.iterable = createIterable.bind(undefined, subprocess, useBinaryEncoding);2 unmodified linesmodified:lib/return/error.js+1 added-1 removed
1 import {signalsByName} from 'human-signals';2 import stripFinalNewline from 'strip-final-newline';3-import {isUint8Array, uint8ArrayToString} from '../encoding.js';3+import {isUint8Array, uint8ArrayToString} from '../utils.js';4 import {fixCwdError} from '../arguments/cwd.js';5 import {escapeLines} from '../arguments/escape.js';6 import {getDurationMs} from './duration.js';7 import {getFinalError, DiscardedError, isExecaError} from './cause.js';189 unmodified linesmodified:lib/return/output.js+1 added-1 removed
1233456723 unmodified linesimport {Buffer} from 'node:buffer';import stripFinalNewline from 'strip-final-newline';import {bufferToUint8Array} from '../encoding.js';import {bufferToUint8Array} from '../utils.js';import {logFinalResult} from '../verbose/complete.js';
export const handleOutput = (options, value) => { if (value === undefined || value === null) {23 unmodified linesmodified:lib/stdio/encoding-final.js+2 added-2 removed
1 import {StringDecoder} from 'node:string_decoder';2-import {isSimpleEncoding} from '../encoding.js';2 3 // Apply the `encoding` option using an implicit generator.4 // This encodes the final output of `stdout`/`stderr`.5 export const handleStreamsEncoding = ({stdioItems, options: {encoding}, isSync, direction, optionName}) => {13 unmodified lines19 }];20 };21 22 const shouldEncodeOutput = ({stdioItems, encoding, isSync, direction}) => direction === 'output'24- && !isSimpleEncoding(encoding)23+ && encoding !== 'utf8'24+ && encoding !== 'buffer'25 && !isSync26 && !isWritableObjectMode(stdioItems);27 28 const isWritableObjectMode = stdioItems => {14 unmodified linesmodified:lib/stdio/generator.js+2 added-2 removed
1-import {isBinaryEncoding} from '../encoding.js';1+import {BINARY_ENCODINGS} from '../arguments/encoding.js';2 import {generatorsToTransform} from './transform.js';3 import {getEncodingTransformGenerator} from './encoding-transform.js';4 import {getSplitLinesGenerator, getAppendNewlineGenerator} from './split.js';5 import {pipeStreams} from './pipeline.js';20 unmodified lines26 binary: binaryOption = false,27 preserveNewlines = false,28 objectMode,29 } = isGeneratorOptions(value) ? value : {transform: value};30- const binary = binaryOption || isBinaryEncoding(encoding);30+ const binary = binaryOption || BINARY_ENCODINGS.has(encoding);31 const objectModes = direction === 'output'32 ? getOutputObjectModes(objectMode, index, newGenerators)33 : getInputObjectModes(objectMode, index, newGenerators);34 return {...stdioItem, value: {transform, final, binary, preserveNewlines, ...objectModes}};79 unmodified linesmodified:lib/stdio/input.js+1 added-1 removed
1 import {isReadableStream} from 'is-stream';2-import {isUint8Array} from '../encoding.js';2+import {isUint8Array} from '../utils.js';3 import {isUrl, isFilePathString} from './type.js';4 5 // Append the `stdin` option with the `input` and `inputFile` options6 export const handleInputOptions = ({input, inputFile}, fdNumber) => fdNumber === 044 unmodified linesmodified:lib/stdio/lines.js+2 added-2 removed
1-import {isBinaryEncoding} from '../encoding.js';1+import {BINARY_ENCODINGS} from '../arguments/encoding.js';2 3 // Split chunks line-wise for streams exposed to users like `subprocess.stdout`.4 // Appending a noop transform in object mode is enough to do this, since every non-binary transform iterates line-wise.5 export const handleStreamsLines = ({options: {lines, encoding, stripFinalNewline}, isSync, direction, optionName}) => shouldSplitLines({lines, encoding, isSync, direction})5 unmodified lines11 : [];12 13 const shouldSplitLines = ({lines, encoding, isSync, direction}) => direction === 'output'14 && lines15- && !isBinaryEncoding(encoding)15+ && !BINARY_ENCODINGS.has(encoding)16 && !isSync;17 18 const linesEndGenerator = function * (chunk) {19 yield chunk;1 unmodified linemodified:lib/stdio/sync.js+1 added-1 removed
1 import {readFileSync, writeFileSync} from 'node:fs';2-import {bufferToUint8Array, uint8ArrayToString} from '../encoding.js';2+import {bufferToUint8Array, uint8ArrayToString} from '../utils.js';3 import {handleInput} from './handle.js';4 import {TYPE_TO_MESSAGE} from './type.js';5 6 // Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, before spawning, in sync mode74 unmodified linesmodified:lib/stdio/type.js+1 added-1 removed
1 import {isStream as isNodeStream} from 'is-stream';2-import {isUint8Array} from '../encoding.js';2+import {isUint8Array} from '../utils.js';3 4 // The `stdin`/`stdout`/`stderr` option can be of many types. This detects it.5 export const getStdioItemType = (value, optionName) => {6 if (isGenerator(value)) {96 unmodified linesmodified:lib/stdio/validate.js+1 added-1 removed
1 import {Buffer} from 'node:buffer';2-import {isUint8Array} from '../encoding.js';2+import {isUint8Array} from '../utils.js';3 4 export const getValidateTransformReturn = (readableObjectMode, optionName) => readableObjectMode5 ? validateObjectTransformReturn.bind(undefined, optionName)6 : validateStringTransformReturn.bind(undefined, optionName);24 unmodified linesmodified:lib/stream/all.js+1 added-2 removed
1 import mergeStreams from '@sindresorhus/merge-streams';2 import {generatorToDuplexStream} from '../stdio/generator.js';3-import {isBufferEncoding} from '../encoding.js';3 import {waitForSubprocessStream} from './subprocess.js';4 5 // `all` interleaves `stdout` and `stderr`6 export const makeAllStream = ({stdout, stderr}, {all}) => all && (stdout || stderr)21 unmodified lines28 29 const getAllStreamTransform = encoding => ({30 value: {31 * final() {},33- binary: isBufferEncoding(encoding),32+ binary: encoding === 'buffer',33 writableObjectMode: true,34 readableObjectMode: true,35 preserveNewlines: true,36 },3 unmodified linesmodified:lib/stream/subprocess.js+2 added-3 removed
1 import {setImmediate} from 'node:timers/promises';2 import getStream, {getStreamAsArrayBuffer, getStreamAsArray, MaxBufferError} from 'get-stream';3-import {isBufferEncoding} from '../encoding.js';3 import {waitForStream, handleStreamError, isInputFileDescriptor} from './wait.js';4 5 export const waitForSubprocessStream = async ({stream, subprocess, fdNumber, encoding, buffer, maxBuffer, streamInfo}) => {6 if (!stream) {38 unmodified lines45 if (stream.readableObjectMode) {46 return getStreamAsArray(stream, {maxBuffer});47 }48 50- const contents = isBufferEncoding(encoding)49+ const contents = encoding === 'buffer'50 ? await getStreamAsArrayBuffer(stream, {maxBuffer})51 : await getStream(stream, {maxBuffer});52 return applyEncoding(contents, encoding);53 };12 unmodified lines66 const handleBufferedData = (error, encoding) => error.bufferedData === undefined || Array.isArray(error.bufferedData)67 ? error.bufferedData68 : applyEncoding(error.bufferedData, encoding);69 71-const applyEncoding = (contents, encoding) => isBufferEncoding(encoding) ? new Uint8Array(contents) : contents;70+const applyEncoding = (contents, encoding) => encoding === 'buffer' ? new Uint8Array(contents) : contents;modified:lib/verbose/output.js+2 added-2 removed
1 import {inspect} from 'node:util';2 import {escapeLines} from '../arguments/escape.js';3-import {isBinaryEncoding} from '../encoding.js';3+import {BINARY_ENCODINGS} from '../arguments/encoding.js';4 import {PIPED_STDIO_VALUES} from '../stdio/forward.js';5 import {verboseLog} from './log.js';6 7 export const handleStreamsVerbose = ({stdioItems, options, isSync, stdioState, verboseInfo, fdNumber, optionName}) => shouldLogOutput({stdioItems, options, isSync, verboseInfo, fdNumber})10 unmodified lines18 // They can also lead to double printing when passing file descriptor integers or `process.std*`.19 // This only leaves with `pipe` and `overlapped`.20 const shouldLogOutput = ({stdioItems, options: {encoding}, isSync, verboseInfo: {verbose}, fdNumber}) => verbose === 'full'21 && !isSync22- && !isBinaryEncoding(encoding)22+ && !BINARY_ENCODINGS.has(encoding)23 && fdUsesVerbose(fdNumber)24 && (stdioItems.some(({type, value}) => type === 'native' && PIPED_STDIO_VALUES.has(value))25 || stdioItems.every(({type}) => type === 'generator'));26 33 unmodified linesdeleted:lib/encoding.js-19 removed
1-import {Buffer} from 'node:buffer';2-3-export const isSimpleEncoding = encoding => isBufferEncoding(encoding) || DEFAULT_ENCODING.has(encoding.toLowerCase());4-5-// eslint-disable-next-line unicorn/text-encoding-identifier-case6-const DEFAULT_ENCODING = new Set(['utf8', 'utf-8']);7-8-export const isBufferEncoding = encoding => encoding === null || encoding.toLowerCase() === 'buffer';9-10-export const isBinaryEncoding = encoding => isBufferEncoding(encoding) || BINARY_ENCODINGS.has(encoding.toLowerCase());11-12-const BINARY_ENCODINGS = new Set(['hex', 'base64', 'base64url', 'latin1', 'binary', 'ascii']);13-14-export const bufferToUint8Array = buffer => new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);15-16-export const isUint8Array = value => Object.prototype.toString.call(value) === '[object Uint8Array]' && !Buffer.isBuffer(value);17-18-const textDecoder = new TextDecoder();19-export const uint8ArrayToString = uint8Array => textDecoder.decode(uint8Array);modified:lib/script.js+1 added-2 removed
1 import isPlainObject from 'is-plain-obj';2-import {isUint8Array, uint8ArrayToString} from './encoding.js';3-import {isSubprocess} from './utils.js';2+import {isUint8Array, uint8ArrayToString, isSubprocess} from './utils.js';3 import {execa} from './async.js';4 import {execaSync} from './sync.js';5 6 export const create$ = options => {170 unmodified linesmodified:lib/utils.js+8 added
1+import {Buffer} from 'node:buffer';2 import {ChildProcess} from 'node:child_process';3 import {addAbortListener} from 'node:events';4 import process from 'node:process';5 6+export const isUint8Array = value => Object.prototype.toString.call(value) === '[object Uint8Array]' && !Buffer.isBuffer(value);7+8+export const bufferToUint8Array = buffer => new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);9+10+const textDecoder = new TextDecoder();11+export const uint8ArrayToString = uint8Array => textDecoder.decode(uint8Array);12+13 export const isStandardStream = stream => STANDARD_STREAMS.includes(stream);14 export const STANDARD_STREAMS = [process.stdin, process.stdout, process.stderr];15 export const STANDARD_STREAMS_ALIASES = ['stdin', 'stdout', 'stderr'];16 13 unmodified linesadded:test/arguments/encoding.js+39 added
1+import test from 'ava';2+import {execa, execaSync} from '../../index.js';3+import {setFixtureDir} from '../helpers/fixtures-dir.js';4+5+setFixtureDir();6+7+const testInvalidEncoding = (t, encoding, message, execaMethod) => {8+ const error = t.throws(() => {9+ execaMethod('empty.js', {encoding});10+ });11+ t.true(error.message.includes(message));12+};13+14+const UNKNOWN_ENCODING_MESSAGE = 'Please rename it to one of';15+const getCorrectEncodingMessage = correctEncoding => `Please rename it to "${correctEncoding}"`;16+17+test('cannot pass unknown encodings', testInvalidEncoding, 'unknown', UNKNOWN_ENCODING_MESSAGE, execa);18+test('cannot pass unknown encodings, sync', testInvalidEncoding, 'unknown', UNKNOWN_ENCODING_MESSAGE, execaSync);19+test('cannot pass empty encodings', testInvalidEncoding, '', UNKNOWN_ENCODING_MESSAGE, execa);20+test('cannot pass encoding: false', testInvalidEncoding, false, UNKNOWN_ENCODING_MESSAGE, execa);21+test('cannot pass encoding: Symbol', testInvalidEncoding, Symbol('test'), UNKNOWN_ENCODING_MESSAGE, execa);22+test('cannot pass encoding: null', testInvalidEncoding, null, getCorrectEncodingMessage('buffer'), execa);23+test('cannot pass encoding: null, sync', testInvalidEncoding, null, getCorrectEncodingMessage('buffer'), execaSync);24+/* eslint-disable unicorn/text-encoding-identifier-case */25+test('cannot pass encoding: utf-8', testInvalidEncoding, 'utf-8', getCorrectEncodingMessage('utf8'), execa);26+test('cannot pass encoding: utf-8, sync', testInvalidEncoding, 'utf-8', getCorrectEncodingMessage('utf8'), execaSync);27+test('cannot pass encoding: UTF-8', testInvalidEncoding, 'UTF-8', getCorrectEncodingMessage('utf8'), execa);28+test('cannot pass encoding: UTF-8, sync', testInvalidEncoding, 'UTF-8', getCorrectEncodingMessage('utf8'), execaSync);29+test('cannot pass encoding: UTF8', testInvalidEncoding, 'UTF8', getCorrectEncodingMessage('utf8'), execa);30+test('cannot pass encoding: UTF8, sync', testInvalidEncoding, 'UTF8', getCorrectEncodingMessage('utf8'), execaSync);31+/* eslint-enable unicorn/text-encoding-identifier-case */32+test('cannot pass encoding: utf-16le', testInvalidEncoding, 'utf-16le', getCorrectEncodingMessage('utf16le'), execa);33+test('cannot pass encoding: UTF-16LE', testInvalidEncoding, 'UTF-16LE', getCorrectEncodingMessage('utf16le'), execa);34+test('cannot pass encoding: UTF16LE', testInvalidEncoding, 'UTF16LE', getCorrectEncodingMessage('utf16le'), execa);35+test('cannot pass encoding: ucs2', testInvalidEncoding, 'ucs2', getCorrectEncodingMessage('utf16le'), execa);36+test('cannot pass encoding: UCS2', testInvalidEncoding, 'UCS2', getCorrectEncodingMessage('utf16le'), execa);37+test('cannot pass encoding: ucs-2', testInvalidEncoding, 'ucs-2', getCorrectEncodingMessage('utf16le'), execa);38+test('cannot pass encoding: UCS-2', testInvalidEncoding, 'UCS-2', getCorrectEncodingMessage('utf16le'), execa);39+test('cannot pass encoding: binary', testInvalidEncoding, 'binary', getCorrectEncodingMessage('latin1'), execa);modified:test/stdio/encoding-final.js-38 removed
45 unmodified lines46 // This string gives different outputs with each encoding type47 const STRING_TO_ENCODE = '\u1000.';48 const BUFFER_TO_ENCODE = Buffer.from(STRING_TO_ENCODE);49 50-/* eslint-disable unicorn/text-encoding-identifier-case */50 test('can pass encoding "buffer" to stdout', checkEncoding, 'buffer', 1, execa);51 test('can pass encoding "utf8" to stdout', checkEncoding, 'utf8', 1, execa);53-test('can pass encoding "utf-8" to stdout', checkEncoding, 'utf-8', 1, execa);52 test('can pass encoding "utf16le" to stdout', checkEncoding, 'utf16le', 1, execa);55-test('can pass encoding "utf-16le" to stdout', checkEncoding, 'utf-16le', 1, execa);56-test('can pass encoding "ucs2" to stdout', checkEncoding, 'ucs2', 1, execa);57-test('can pass encoding "ucs-2" to stdout', checkEncoding, 'ucs-2', 1, execa);53 test('can pass encoding "latin1" to stdout', checkEncoding, 'latin1', 1, execa);59-test('can pass encoding "binary" to stdout', checkEncoding, 'binary', 1, execa);54 test('can pass encoding "ascii" to stdout', checkEncoding, 'ascii', 1, execa);55 test('can pass encoding "hex" to stdout', checkEncoding, 'hex', 1, execa);56 test('can pass encoding "base64" to stdout', checkEncoding, 'base64', 1, execa);57 test('can pass encoding "base64url" to stdout', checkEncoding, 'base64url', 1, execa);58 test('can pass encoding "buffer" to stderr', checkEncoding, 'buffer', 2, execa);59 test('can pass encoding "utf8" to stderr', checkEncoding, 'utf8', 2, execa);66-test('can pass encoding "utf-8" to stderr', checkEncoding, 'utf-8', 2, execa);60 test('can pass encoding "utf16le" to stderr', checkEncoding, 'utf16le', 2, execa);68-test('can pass encoding "utf-16le" to stderr', checkEncoding, 'utf-16le', 2, execa);69-test('can pass encoding "ucs2" to stderr', checkEncoding, 'ucs2', 2, execa);70-test('can pass encoding "ucs-2" to stderr', checkEncoding, 'ucs-2', 2, execa);61 test('can pass encoding "latin1" to stderr', checkEncoding, 'latin1', 2, execa);72-test('can pass encoding "binary" to stderr', checkEncoding, 'binary', 2, execa);62 test('can pass encoding "ascii" to stderr', checkEncoding, 'ascii', 2, execa);63 test('can pass encoding "hex" to stderr', checkEncoding, 'hex', 2, execa);64 test('can pass encoding "base64" to stderr', checkEncoding, 'base64', 2, execa);65 test('can pass encoding "base64url" to stderr', checkEncoding, 'base64url', 2, execa);66 test('can pass encoding "buffer" to stdio[*]', checkEncoding, 'buffer', 3, execa);67 test('can pass encoding "utf8" to stdio[*]', checkEncoding, 'utf8', 3, execa);79-test('can pass encoding "utf-8" to stdio[*]', checkEncoding, 'utf-8', 3, execa);68 test('can pass encoding "utf16le" to stdio[*]', checkEncoding, 'utf16le', 3, execa);81-test('can pass encoding "utf-16le" to stdio[*]', checkEncoding, 'utf-16le', 3, execa);82-test('can pass encoding "ucs2" to stdio[*]', checkEncoding, 'ucs2', 3, execa);83-test('can pass encoding "ucs-2" to stdio[*]', checkEncoding, 'ucs-2', 3, execa);69 test('can pass encoding "latin1" to stdio[*]', checkEncoding, 'latin1', 3, execa);85-test('can pass encoding "binary" to stdio[*]', checkEncoding, 'binary', 3, execa);70 test('can pass encoding "ascii" to stdio[*]', checkEncoding, 'ascii', 3, execa);71 test('can pass encoding "hex" to stdio[*]', checkEncoding, 'hex', 3, execa);72 test('can pass encoding "base64" to stdio[*]', checkEncoding, 'base64', 3, execa);73 test('can pass encoding "base64url" to stdio[*]', checkEncoding, 'base64url', 3, execa);74 test('can pass encoding "buffer" to stdout - sync', checkEncoding, 'buffer', 1, execaSync);75 test('can pass encoding "utf8" to stdout - sync', checkEncoding, 'utf8', 1, execaSync);92-test('can pass encoding "utf-8" to stdout - sync', checkEncoding, 'utf-8', 1, execaSync);76 test('can pass encoding "utf16le" to stdout - sync', checkEncoding, 'utf16le', 1, execaSync);94-test('can pass encoding "utf-16le" to stdout - sync', checkEncoding, 'utf-16le', 1, execaSync);95-test('can pass encoding "ucs2" to stdout - sync', checkEncoding, 'ucs2', 1, execaSync);96-test('can pass encoding "ucs-2" to stdout - sync', checkEncoding, 'ucs-2', 1, execaSync);77 test('can pass encoding "latin1" to stdout - sync', checkEncoding, 'latin1', 1, execaSync);98-test('can pass encoding "binary" to stdout - sync', checkEncoding, 'binary', 1, execaSync);78 test('can pass encoding "ascii" to stdout - sync', checkEncoding, 'ascii', 1, execaSync);79 test('can pass encoding "hex" to stdout - sync', checkEncoding, 'hex', 1, execaSync);80 test('can pass encoding "base64" to stdout - sync', checkEncoding, 'base64', 1, execaSync);81 test('can pass encoding "base64url" to stdout - sync', checkEncoding, 'base64url', 1, execaSync);82 test('can pass encoding "buffer" to stderr - sync', checkEncoding, 'buffer', 2, execaSync);83 test('can pass encoding "utf8" to stderr - sync', checkEncoding, 'utf8', 2, execaSync);105-test('can pass encoding "utf-8" to stderr - sync', checkEncoding, 'utf-8', 2, execaSync);84 test('can pass encoding "utf16le" to stderr - sync', checkEncoding, 'utf16le', 2, execaSync);107-test('can pass encoding "utf-16le" to stderr - sync', checkEncoding, 'utf-16le', 2, execaSync);108-test('can pass encoding "ucs2" to stderr - sync', checkEncoding, 'ucs2', 2, execaSync);109-test('can pass encoding "ucs-2" to stderr - sync', checkEncoding, 'ucs-2', 2, execaSync);85 test('can pass encoding "latin1" to stderr - sync', checkEncoding, 'latin1', 2, execaSync);111-test('can pass encoding "binary" to stderr - sync', checkEncoding, 'binary', 2, execaSync);86 test('can pass encoding "ascii" to stderr - sync', checkEncoding, 'ascii', 2, execaSync);87 test('can pass encoding "hex" to stderr - sync', checkEncoding, 'hex', 2, execaSync);88 test('can pass encoding "base64" to stderr - sync', checkEncoding, 'base64', 2, execaSync);89 test('can pass encoding "base64url" to stderr - sync', checkEncoding, 'base64url', 2, execaSync);90 test('can pass encoding "buffer" to stdio[*] - sync', checkEncoding, 'buffer', 3, execaSync);91 test('can pass encoding "utf8" to stdio[*] - sync', checkEncoding, 'utf8', 3, execaSync);118-test('can pass encoding "utf-8" to stdio[*] - sync', checkEncoding, 'utf-8', 3, execaSync);92 test('can pass encoding "utf16le" to stdio[*] - sync', checkEncoding, 'utf16le', 3, execaSync);120-test('can pass encoding "utf-16le" to stdio[*] - sync', checkEncoding, 'utf-16le', 3, execaSync);121-test('can pass encoding "ucs2" to stdio[*] - sync', checkEncoding, 'ucs2', 3, execaSync);122-test('can pass encoding "ucs-2" to stdio[*] - sync', checkEncoding, 'ucs-2', 3, execaSync);93 test('can pass encoding "latin1" to stdio[*] - sync', checkEncoding, 'latin1', 3, execaSync);124-test('can pass encoding "binary" to stdio[*] - sync', checkEncoding, 'binary', 3, execaSync);94 test('can pass encoding "ascii" to stdio[*] - sync', checkEncoding, 'ascii', 3, execaSync);95 test('can pass encoding "hex" to stdio[*] - sync', checkEncoding, 'hex', 3, execaSync);96 test('can pass encoding "base64" to stdio[*] - sync', checkEncoding, 'base64', 3, execaSync);97 test('can pass encoding "base64url" to stdio[*] - sync', checkEncoding, 'base64url', 3, execaSync);129-/* eslint-enable unicorn/text-encoding-identifier-case */98 131-test('validate unknown encodings', t => {132- t.throws(() => {133- execa('noop.js', {encoding: 'unknownEncoding'});134- }, {code: 'ERR_UNKNOWN_ENCODING'});135-});136-99 const foobarArray = ['fo', 'ob', 'ar', '..'];100 101 const testMultibyteCharacters = async (t, objectMode, addNoopTransform) => {102 const {stdout} = await execa('noop.js', {66 unmodified linesmodified:index.d.ts+1 added-7 removed
85 unmodified lines86 87 type DefaultEncodingOption = 'utf8';88 type TextEncodingOption =89 | DefaultEncodingOption90- // eslint-disable-next-line unicorn/text-encoding-identifier-case91- | 'utf-8'92- | 'utf16le'90+ | 'utf16le';93- | 'utf-16le'94- | 'ucs2'95- | 'ucs-2';91 type BufferEncodingOption = 'buffer';92 type BinaryEncodingOption =93 | BufferEncodingOption94 | 'hex'95 | 'base64'96 | 'base64url'97 | 'latin1'103- | 'binary'98 | 'ascii';99 type EncodingOption =100 | TextEncodingOption101 | BinaryEncodingOption1487 unmodified linesmodified:index.test-d.ts+20 added-12 removed
1061 unmodified lines1062 execa('unicorns', {localDir: '.'});1063 execaSync('unicorns', {localDir: '.'});1064 execa('unicorns', {localDir: fileUrl});1065 execaSync('unicorns', {localDir: fileUrl});1066-// eslint-disable-next-line unicorn/text-encoding-identifier-case1067-execa('unicorns', {encoding: 'utf-8'});1068-// eslint-disable-next-line unicorn/text-encoding-identifier-case1069-execaSync('unicorns', {encoding: 'utf-8'});1066+execa('unicorns', {encoding: 'utf8'});1067+execaSync('unicorns', {encoding: 'utf8'});1068+/* eslint-disable unicorn/text-encoding-identifier-case */1069+expectError(execa('unicorns', {encoding: 'utf-8'}));1070+expectError(execaSync('unicorns', {encoding: 'utf-8'}));1071+expectError(execa('unicorns', {encoding: 'UTF8'}));1072+expectError(execaSync('unicorns', {encoding: 'UTF8'}));1073+/* eslint-enable unicorn/text-encoding-identifier-case */1074 execa('unicorns', {encoding: 'utf16le'});1075 execaSync('unicorns', {encoding: 'utf16le'});1072-execa('unicorns', {encoding: 'utf-16le'});1073-execaSync('unicorns', {encoding: 'utf-16le'});1074-execa('unicorns', {encoding: 'ucs2'});1075-execaSync('unicorns', {encoding: 'ucs2'});1076-execa('unicorns', {encoding: 'ucs-2'});1077-execaSync('unicorns', {encoding: 'ucs-2'});1076+expectError(execa('unicorns', {encoding: 'utf-16le'}));1077+expectError(execaSync('unicorns', {encoding: 'utf-16le'}));1078+expectError(execa('unicorns', {encoding: 'ucs2'}));1079+expectError(execaSync('unicorns', {encoding: 'ucs2'}));1080+expectError(execa('unicorns', {encoding: 'ucs-2'}));1081+expectError(execaSync('unicorns', {encoding: 'ucs-2'}));1082+execa('unicorns', {encoding: 'buffer'});1083+execaSync('unicorns', {encoding: 'buffer'});1084+expectError(execa('unicorns', {encoding: null}));1085+expectError(execaSync('unicorns', {encoding: null}));1086 execa('unicorns', {encoding: 'hex'});1087 execaSync('unicorns', {encoding: 'hex'});1088 execa('unicorns', {encoding: 'base64'});1089 execaSync('unicorns', {encoding: 'base64'});1090 execa('unicorns', {encoding: 'base64url'});1091 execaSync('unicorns', {encoding: 'base64url'});1092 execa('unicorns', {encoding: 'latin1'});1093 execaSync('unicorns', {encoding: 'latin1'});1086-execa('unicorns', {encoding: 'binary'});1087-execaSync('unicorns', {encoding: 'binary'});1094+expectError(execa('unicorns', {encoding: 'binary'}));1095+expectError(execaSync('unicorns', {encoding: 'binary'}));1096 execa('unicorns', {encoding: 'ascii'});1097 execaSync('unicorns', {encoding: 'ascii'});1098 expectError(execa('unicorns', {encoding: 'unknownEncoding'}));1099 expectError(execaSync('unicorns', {encoding: 'unknownEncoding'}));689 unmodified lines