Skip to content
Myr

Allow template strings with all methods (#933)

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

authored by ehmicky · committed by GitHub · parent a480e1d · Browse files · 25 files+1651 added−1083 removed
This commit

State

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

Diff stats

25 files+1651 added−1083 removed

  • tests:+754 added−469 removed
  • other:+897 added−614 removed

25 files+1651 added−1083 removed

modified:docs/scripts.md+16 added-1 removed
26 unmodified lines
27const dirName = 'foo bar';28await $`mkdir /tmp/${dirName}`;29```3031## Template string syntax3233The examples below use the [template string syntax](../readme.md#template-string-syntax). However, the other syntax using [an array of arguments](../readme.md#execafile-arguments-options) is also available as `$(file, arguments?, options?)`.3435Also, the template string syntax can be used outside of script files: `$` is not required to use that syntax. For example, `execa` can use it too.3637The only difference between `$` and `execa` is that the former includes [script-friendly default options](../readme.md#file-arguments-options).3839```js40import {execa, $} from 'execa';4142const branch = await execa`git branch --show-current`;43await $('dep', ['deploy', `--branch=${branch}`]);44```4546## Examples4748### Main binary49
768 unmodified lines
818If you really need a shell though, the [`shell` option](../readme.md#shell) can be used.819820### Simplicity821807Execa's scripting API mostly consists of only two methods: [`` $`command` ``](../readme.md#command) and [`$(options)`](../readme.md#options).822Execa's scripting API mostly consists of only two methods: [`` $`command` ``](../readme.md#file-arguments-options) and [`$(options)`](../readme.md#execaoptions).823824[No special binary](#main-binary) is recommended, no [global variable](#global-variables) is injected: scripts are regular Node.js files.825826Execa is a thin wrapper around the core Node.js [`child_process` module](https://nodejs.org/api/child_process.html). Unlike zx, it lets you use [any of its native features](#background-subprocesses): [`pid`](#pid), [IPC](https://nodejs.org/api/child_process.html#subprocesssendmessage-sendhandle-options-callback), [`unref()`](https://nodejs.org/api/child_process.html#subprocessunref), [`detached`](https://nodejs.org/api/child_process.html#child_processspawncommand-args-options), [`uid`](https://nodejs.org/api/child_process.html#child_processspawncommand-args-options), [`gid`](https://nodejs.org/api/child_process.html#child_processspawncommand-args-options), [`cancelSignal`](https://nodejs.org/api/child_process.html#child_processspawncommand-args-options), etc.
20 unmodified lines
added:lib/arguments/create.js+42 added
modified:lib/arguments/node.js+3 added-7 removed
added:lib/arguments/normalize.js+29 added
modified:lib/arguments/options.js+2 added-30 removed
added:lib/arguments/template.js+132 added
1import {isUint8Array, uint8ArrayToString, isSubprocess} from '../utils.js';23export const isTemplateString = templates => Array.isArray(templates) && Array.isArray(templates.raw);45export const parseTemplates = (templates, expressions) => {6 let tokens = [];78 for (const [index, template] of templates.entries()) {9 tokens = parseTemplate({templates, expressions, tokens, index, template});10 }1112 if (tokens.length === 0) {13 throw new TypeError('Template script must not be empty');14 }1516 const [file, ...args] = tokens;17 return [file, args, {}];18};1920const parseTemplate = ({templates, expressions, tokens, index, template}) => {21 if (template === undefined) {22 throw new TypeError(`Invalid backslash sequence: ${templates.raw[index]}`);23 }2425 const {nextTokens, leadingWhitespaces, trailingWhitespaces} = splitByWhitespaces(template, templates.raw[index]);26 const newTokens = concatTokens(tokens, nextTokens, leadingWhitespaces);2728 if (index === expressions.length) {29 return newTokens;30 }3132 const expression = expressions[index];33 const expressionTokens = Array.isArray(expression)34 ? expression.map(expression => parseExpression(expression))35 : [parseExpression(expression)];36 return concatTokens(newTokens, expressionTokens, trailingWhitespaces);37};3839// Like `string.split(/[ \t\r\n]+/)` except newlines and tabs are:40// - ignored when input as a backslash sequence like: `echo foo\n bar`41// - not ignored when input directly42// The only way to distinguish those in JavaScript is to use a tagged template and compare:43// - the first array argument, which does not escape backslash sequences44// - its `raw` property, which escapes them45const splitByWhitespaces = (template, rawTemplate) => {46 if (rawTemplate.length === 0) {47 return {nextTokens: [], leadingWhitespaces: false, trailingWhitespaces: false};48 }4950 const nextTokens = [];51 let templateStart = 0;52 const leadingWhitespaces = DELIMITERS.has(rawTemplate[0]);5354 for (55 let templateIndex = 0, rawIndex = 0;56 templateIndex < template.length;57 templateIndex += 1, rawIndex += 158 ) {59 const rawCharacter = rawTemplate[rawIndex];60 if (DELIMITERS.has(rawCharacter)) {61 if (templateStart !== templateIndex) {62 nextTokens.push(template.slice(templateStart, templateIndex));63 }6465 templateStart = templateIndex + 1;66 } else if (rawCharacter === '\\') {67 const nextRawCharacter = rawTemplate[rawIndex + 1];68 if (nextRawCharacter === 'u' && rawTemplate[rawIndex + 2] === '{') {69 rawIndex = rawTemplate.indexOf('}', rawIndex + 3);70 } else {71 rawIndex += ESCAPE_LENGTH[nextRawCharacter] ?? 1;72 }73 }74 }7576 const trailingWhitespaces = templateStart === template.length;77 if (!trailingWhitespaces) {78 nextTokens.push(template.slice(templateStart));79 }8081 return {nextTokens, leadingWhitespaces, trailingWhitespaces};82};8384const DELIMITERS = new Set([' ', '\t', '\r', '\n']);8586// Number of characters in backslash escape sequences: \0 \xXX or \uXXXX87// \cX is allowed in RegExps but not in strings88// Octal sequences are not allowed in strict mode89const ESCAPE_LENGTH = {x: 3, u: 5};9091const concatTokens = (tokens, nextTokens, isSeparated) => isSeparated92 || tokens.length === 093 || nextTokens.length === 094 ? [...tokens, ...nextTokens]95 : [96 ...tokens.slice(0, -1),97 `${tokens.at(-1)}${nextTokens[0]}`,98 ...nextTokens.slice(1),99 ];100101const parseExpression = expression => {102 const typeOfExpression = typeof expression;103104 if (typeOfExpression === 'string') {105 return expression;106 }107108 if (typeOfExpression === 'number') {109 return String(expression);110 }111112 if (113 typeOfExpression === 'object'114 && expression !== null115 && !isSubprocess(expression)116 && 'stdout' in expression117 ) {118 const typeOfStdout = typeof expression.stdout;119120 if (typeOfStdout === 'string') {121 return expression.stdout;122 }123124 if (isUint8Array(expression.stdout)) {125 return uint8ArrayToString(expression.stdout);126 }127128 throw new TypeError(`Unexpected "${typeOfStdout}" stdout in template expression`);129 }130131 throw new TypeError(`Unexpected "${typeOfExpression}" in template expression`);132};
modified:lib/pipe/validate.js+9 added-11 removed
1import {execa} from '../async.js';2import {create$} from '../script.js';3import {normalizeArguments} from '../arguments/options.js';1import {normalizeArguments} from '../arguments/normalize.js';2import {STANDARD_STREAMS_ALIASES} from '../utils.js';3import {getStartTime} from '../return/duration.js';47export const normalizePipeArguments = ({source, sourcePromise, boundOptions}, ...args) => {5export const normalizePipeArguments = ({source, sourcePromise, boundOptions, createNested}, ...args) => {6 const startTime = getStartTime();7 const {8 destination,9 destinationStream,10 destinationError,11 from,12 unpipeSignal,15 } = getDestinationStream(boundOptions, args);13 } = getDestinationStream(boundOptions, createNested, args);14 const {sourceStream, sourceError} = getSourceStream(source, from);15 const {options: sourceOptions, fileDescriptors} = SUBPROCESS_OPTIONS.get(source);16 return {17 sourcePromise,
8 unmodified lines
26 startTime,27 };28};2932const getDestinationStream = (boundOptions, args) => {30const getDestinationStream = (boundOptions, createNested, args) => {31 try {32 const {33 destination,34 pipeOptions: {from, to, unpipeSignal} = {},37 } = getDestination(boundOptions, ...args);35 } = getDestination(boundOptions, createNested, ...args);36 const destinationStream = getWritable(destination, to);37 return {destination, destinationStream, from, unpipeSignal};38 } catch (error) {39 return {destinationError: error};40 }41};4245const getDestination = (boundOptions, firstArgument, ...args) => {43const getDestination = (boundOptions, createNested, firstArgument, ...args) => {44 if (Array.isArray(firstArgument)) {47 const destination = create$({...boundOptions, ...PIPED_SUBPROCESS_OPTIONS})(firstArgument, ...args);45 const destination = createNested(mapDestinationArguments, boundOptions)(firstArgument, ...args);46 return {destination, pipeOptions: boundOptions};47 }4849 if (typeof firstArgument === 'string' || firstArgument instanceof URL) {
1 unmodified line
51 throw new TypeError('Please use .pipe("file", ..., options) or .pipe(execa("file", ..., options)) instead of .pipe(options)("file", ...).');52 }5354 const [rawFile, rawArgs, rawOptions] = normalizeArguments(firstArgument, ...args);57 const destination = execa(rawFile, rawArgs, {...rawOptions, ...PIPED_SUBPROCESS_OPTIONS});55 const destination = createNested(mapDestinationArguments)(rawFile, rawArgs, rawOptions);56 return {destination, pipeOptions: rawOptions};57 }5859 if (SUBPROCESS_OPTIONS.has(firstArgument)) {
6 unmodified lines
6667 throw new TypeError(`The first argument must be a template string, an options object, or an Execa subprocess: ${firstArgument}`);68};6972const PIPED_SUBPROCESS_OPTIONS = {stdin: 'pipe', piped: true};70const mapDestinationArguments = ({options}) => ({options: {...options, stdin: 'pipe', piped: true}});7172export const SUBPROCESS_OPTIONS = new WeakMap();7374export const getWritable = (destination, to = 'stdin') => {
120 unmodified lines
modified:lib/async.js+4 added-5 removed
1import {setMaxListeners} from 'node:events';2import {spawn} from 'node:child_process';3import {normalizeArguments, handleCommand, handleArguments} from './arguments/options.js';3import {handleCommand, handleOptions} from './arguments/options.js';4import {makeError, makeSuccessResult} from './return/error.js';5import {handleOutput, handleResult} from './return/output.js';6import {handleEarlyError} from './return/early-error.js';7import {handleInputAsync, pipeOutputAsync} from './stdio/async.js';
6 unmodified lines
14import {addConvertedStreams} from './convert/add.js';15import {getSubprocessResult} from './stream/resolve.js';16import {mergePromise} from './promise.js';1718export const execa = (rawFile, rawArgs, rawOptions) => {18export const execaCoreAsync = (rawFile, rawArgs, rawOptions, createNested) => {19 const {file, args, command, escapedCommand, startTime, verboseInfo, options, fileDescriptors, stdioState} = handleAsyncArguments(rawFile, rawArgs, rawOptions);20 const {subprocess, promise} = spawnSubprocessAsync({file, args, options, startTime, verboseInfo, command, escapedCommand, fileDescriptors, stdioState});21 subprocess.pipe = pipeToSubprocess.bind(undefined, {source: subprocess, sourcePromise: promise, boundOptions: {}});21 subprocess.pipe = pipeToSubprocess.bind(undefined, {source: subprocess, sourcePromise: promise, boundOptions: {}, createNested});22 mergePromise(subprocess, promise);23 SUBPROCESS_OPTIONS.set(subprocess, {options, fileDescriptors});24 return subprocess;25};2627const handleAsyncArguments = (rawFile, rawArgs, rawOptions) => {28 [rawFile, rawArgs, rawOptions] = normalizeArguments(rawFile, rawArgs, rawOptions);28 const {command, escapedCommand, startTime, verboseInfo} = handleCommand(rawFile, rawArgs, rawOptions);2930 try {32 const {file, args, options: normalizedOptions} = handleArguments(rawFile, rawArgs, rawOptions);31 const {file, args, options: normalizedOptions} = handleOptions(rawFile, rawArgs, rawOptions);32 const options = handleAsyncOptions(normalizedOptions);33 const {fileDescriptors, stdioState} = handleInputAsync(options, verboseInfo);34 return {file, args, command, escapedCommand, startTime, verboseInfo, options, fileDescriptors, stdioState};35 } catch (error) {
70 unmodified lines
modified:lib/command.js+7 added-21 removed
1import isPlainObj from 'is-plain-obj';2import {execa} from './async.js';3import {execaSync} from './sync.js';1export const mapCommandAsync = ({file, args}) => parseCommand(file, args);2export const mapCommandSync = ({file, args}) => ({...parseCommand(file, args), isSync: true});35export function execaCommand(command, options) {6 const [file, ...args] = parseCommand(command, options);7 return execa(file, args, options);8}910export function execaCommandSync(command, options) {11 const [file, ...args] = parseCommand(command, options);12 return execaSync(file, args, options);13}1415const parseCommand = (command, options) => {16 if (typeof command !== 'string') {17 throw new TypeError(`First argument must be a string: ${command}.`);4const parseCommand = (command, unusedArgs) => {5 if (unusedArgs.length > 0) {6 throw new TypeError(`The command and its arguments must be passed as a single string: ${command} ${unusedArgs}.`);7 }820 if (options !== undefined && !isPlainObj(options)) {21 throw new TypeError(`The command and its arguments must be passed as a single string: ${command} ${options}.`);22 }239 const tokens = [];10 for (const token of command.trim().split(SPACES_REGEXP)) {11 // Allow spaces to be escaped by a backslash if not meant as a delimiter12 const previousToken = tokens.at(-1);
4 unmodified lines
17 tokens.push(token);18 }19 }2036 return tokens;21 const [file, ...args] = tokens;22 return {file, args};23};2425const SPACES_REGEXP = / +/g;
modified:lib/script.js+9 added-170 removed
1import isPlainObject from 'is-plain-obj';2import {isUint8Array, uint8ArrayToString, isSubprocess} from './utils.js';3import {execa} from './async.js';4import {execaSync} from './sync.js';56export const create$ = options => {7 function $(templatesOrOptions, ...expressions) {8 if (isPlainObject(templatesOrOptions)) {9 return create$({...options, ...templatesOrOptions});10 }1112 if (!Array.isArray(templatesOrOptions)) {13 throw new TypeError('Please use either $(option) or $`command`.');14 }1516 const [file, ...args] = parseTemplates(templatesOrOptions, expressions);17 return execa(file, args, normalizeScriptOptions(options));18 }1920 $.sync = (templates, ...expressions) => {21 if (isPlainObject(templates)) {22 throw new TypeError('Please use $(options).sync`command` instead of $.sync(options)`command`.');23 }2425 if (!Array.isArray(templates)) {26 throw new TypeError('A template string must be used: $.sync`command`.');27 }2829 const [file, ...args] = parseTemplates(templates, expressions);30 return execaSync(file, args, normalizeScriptOptions(options));31 };3233 $.s = $.sync;3435 return $;1export const setScriptSync = (boundExeca, createNested, boundOptions) => {2 boundExeca.sync = createNested(mapScriptSync, boundOptions);3 boundExeca.s = boundExeca.sync;4};538export const $ = create$();6export const mapScriptAsync = ({options}) => getScriptOptions(options);7const mapScriptSync = ({options}) => ({...getScriptOptions(options), isSync: true});840const parseTemplates = (templates, expressions) => {41 let tokens = [];9const getScriptOptions = options => ({options: {...getScriptStdinOption(options), ...options}});1043 for (const [index, template] of templates.entries()) {44 tokens = parseTemplate({templates, expressions, tokens, index, template});45 }4647 if (tokens.length === 0) {48 throw new TypeError('Template script must not be empty');49 }5051 return tokens;52};5354const parseTemplate = ({templates, expressions, tokens, index, template}) => {55 if (template === undefined) {56 throw new TypeError(`Invalid backslash sequence: ${templates.raw[index]}`);57 }5859 const {nextTokens, leadingWhitespaces, trailingWhitespaces} = splitByWhitespaces(template, templates.raw[index]);60 const newTokens = concatTokens(tokens, nextTokens, leadingWhitespaces);6162 if (index === expressions.length) {63 return newTokens;64 }6566 const expression = expressions[index];67 const expressionTokens = Array.isArray(expression)68 ? expression.map(expression => parseExpression(expression))69 : [parseExpression(expression)];70 return concatTokens(newTokens, expressionTokens, trailingWhitespaces);71};7273// Like `string.split(/[ \t\r\n]+/)` except newlines and tabs are:74// - ignored when input as a backslash sequence like: `echo foo\n bar`75// - not ignored when input directly76// The only way to distinguish those in JavaScript is to use a tagged template and compare:77// - the first array argument, which does not escape backslash sequences78// - its `raw` property, which escapes them79const splitByWhitespaces = (template, rawTemplate) => {80 if (rawTemplate.length === 0) {81 return {nextTokens: [], leadingWhitespaces: false, trailingWhitespaces: false};82 }8384 const nextTokens = [];85 let templateStart = 0;86 const leadingWhitespaces = DELIMITERS.has(rawTemplate[0]);8788 for (89 let templateIndex = 0, rawIndex = 0;90 templateIndex < template.length;91 templateIndex += 1, rawIndex += 192 ) {93 const rawCharacter = rawTemplate[rawIndex];94 if (DELIMITERS.has(rawCharacter)) {95 if (templateStart !== templateIndex) {96 nextTokens.push(template.slice(templateStart, templateIndex));97 }9899 templateStart = templateIndex + 1;100 } else if (rawCharacter === '\\') {101 const nextRawCharacter = rawTemplate[rawIndex + 1];102 if (nextRawCharacter === 'u' && rawTemplate[rawIndex + 2] === '{') {103 rawIndex = rawTemplate.indexOf('}', rawIndex + 3);104 } else {105 rawIndex += ESCAPE_LENGTH[nextRawCharacter] ?? 1;106 }107 }108 }109110 const trailingWhitespaces = templateStart === template.length;111 if (!trailingWhitespaces) {112 nextTokens.push(template.slice(templateStart));113 }114115 return {nextTokens, leadingWhitespaces, trailingWhitespaces};116};117118const DELIMITERS = new Set([' ', '\t', '\r', '\n']);119120// Number of characters in backslash escape sequences: \0 \xXX or \uXXXX121// \cX is allowed in RegExps but not in strings122// Octal sequences are not allowed in strict mode123const ESCAPE_LENGTH = {x: 3, u: 5};124125const concatTokens = (tokens, nextTokens, isSeparated) => isSeparated126 || tokens.length === 0127 || nextTokens.length === 0128 ? [...tokens, ...nextTokens]129 : [130 ...tokens.slice(0, -1),131 `${tokens.at(-1)}${nextTokens[0]}`,132 ...nextTokens.slice(1),133 ];134135const parseExpression = expression => {136 const typeOfExpression = typeof expression;137138 if (typeOfExpression === 'string') {139 return expression;140 }141142 if (typeOfExpression === 'number') {143 return String(expression);144 }145146 if (147 typeOfExpression === 'object'148 && expression !== null149 && !isSubprocess(expression)150 && 'stdout' in expression151 ) {152 const typeOfStdout = typeof expression.stdout;153154 if (typeOfStdout === 'string') {155 return expression.stdout;156 }157158 if (isUint8Array(expression.stdout)) {159 return uint8ArrayToString(expression.stdout);160 }161162 throw new TypeError(`Unexpected "${typeOfStdout}" stdout in template expression`);163 }164165 throw new TypeError(`Unexpected "${typeOfExpression}" in template expression`);166};167168const normalizeScriptOptions = (options = {}) => ({169 preferLocal: true,170 ...normalizeScriptStdin(options),171 ...options,172});173174const normalizeScriptStdin = ({input, inputFile, stdio}) => input === undefined && inputFile === undefined && stdio === undefined11const getScriptStdinOption = ({input, inputFile, stdio}) => input === undefined && inputFile === undefined && stdio === undefined12 ? {stdin: 'inherit'}13 : {};1415export const deepScriptOptions = {preferLocal: true};
modified:lib/sync.js+3 added-4 removed
1import {spawnSync} from 'node:child_process';2import {normalizeArguments, handleCommand, handleArguments} from './arguments/options.js';2import {handleCommand, handleOptions} from './arguments/options.js';3import {makeError, makeEarlyError, makeSuccessResult} from './return/error.js';4import {handleOutput, handleResult} from './return/output.js';5import {handleInputSync, pipeOutputSync} from './stdio/sync.js';6import {logEarlyResult} from './verbose/complete.js';7import {getSyncExitResult} from './exit/code.js';89export const execaSync = (rawFile, rawArgs, rawOptions) => {9export const execaCoreSync = (rawFile, rawArgs, rawOptions) => {10 const {file, args, command, escapedCommand, startTime, verboseInfo, options, fileDescriptors} = handleSyncArguments(rawFile, rawArgs, rawOptions);11 const result = spawnSubprocessSync({file, args, options, command, escapedCommand, fileDescriptors, startTime});12 return handleResult(result, verboseInfo, options);13};1415const handleSyncArguments = (rawFile, rawArgs, rawOptions) => {16 [rawFile, rawArgs, rawOptions] = normalizeArguments(rawFile, rawArgs, rawOptions);16 const {command, escapedCommand, startTime, verboseInfo} = handleCommand(rawFile, rawArgs, rawOptions);1718 try {19 const syncOptions = normalizeSyncOptions(rawOptions);21 const {file, args, options} = handleArguments(rawFile, rawArgs, syncOptions);20 const {file, args, options} = handleOptions(rawFile, rawArgs, syncOptions);21 validateSyncOptions(options);22 const fileDescriptors = handleInputSync(options, verboseInfo);23 return {file, args, command, escapedCommand, startTime, verboseInfo, options, fileDescriptors};24 } catch (error) {
44 unmodified lines
added:test/arguments/create.js+85 added
1import {join} from 'node:path';2import test from 'ava';3import {execa, execaSync, execaNode, $} from '../../index.js';4import {foobarString, foobarArray} from '../helpers/input.js';5import {setFixtureDir, FIXTURES_DIR} from '../helpers/fixtures-dir.js';67setFixtureDir();8const NOOP_PATH = join(FIXTURES_DIR, 'noop.js');910const testTemplate = async (t, execaMethod) => {11 const {stdout} = await execaMethod`${NOOP_PATH} ${foobarString}`;12 t.is(stdout, foobarString);13};1415test('execa() can use template strings', testTemplate, execa);16test('execaNode() can use template strings', testTemplate, execaNode);17test('$ can use template strings', testTemplate, $);1819const testTemplateSync = (t, execaMethod) => {20 const {stdout} = execaMethod`${NOOP_PATH} ${foobarString}`;21 t.is(stdout, foobarString);22};2324test('execaSync() can use template strings', testTemplateSync, execaSync);25test('$.sync can use template strings', testTemplateSync, $.sync);2627const testTemplateOptions = async (t, execaMethod) => {28 const {stdout} = await execaMethod({stripFinalNewline: false})`${NOOP_PATH} ${foobarString}`;29 t.is(stdout, `${foobarString}\n`);30};3132test('execa() can use template strings with options', testTemplateOptions, execa);33test('execaNode() can use template strings with options', testTemplateOptions, execaNode);34test('$ can use template strings with options', testTemplateOptions, $);3536const testTemplateOptionsSync = (t, execaMethod) => {37 const {stdout} = execaMethod({stripFinalNewline: false})`${NOOP_PATH} ${foobarString}`;38 t.is(stdout, `${foobarString}\n`);39};4041test('execaSync() can use template strings with options', testTemplateOptionsSync, execaSync);42test('$.sync can use template strings with options', testTemplateOptionsSync, $.sync);4344const testBindOptions = async (t, execaMethod) => {45 const {stdout} = await execaMethod({stripFinalNewline: false})(NOOP_PATH, [foobarString]);46 t.is(stdout, `${foobarString}\n`);47};4849test('execa() can bind options', testBindOptions, execa);50test('execaNode() can bind options', testBindOptions, execaNode);51test('$ can bind options', testBindOptions, $);5253const testBindOptionsSync = (t, execaMethod) => {54 const {stdout} = execaMethod({stripFinalNewline: false})(NOOP_PATH, [foobarString]);55 t.is(stdout, `${foobarString}\n`);56};5758test('execaSync() can bind options', testBindOptionsSync, execaSync);59test('$.sync can bind options', testBindOptionsSync, $.sync);6061const testBindPriority = async (t, execaMethod) => {62 const {stdout} = await execaMethod({stripFinalNewline: false})(NOOP_PATH, [foobarString], {stripFinalNewline: true});63 t.is(stdout, foobarString);64};6566test('execa() bound options have lower priority', testBindPriority, execa);67test('execaSync() bound options have lower priority', testBindPriority, execaSync);68test('execaNode() bound options have lower priority', testBindPriority, execaNode);69test('$ bound options have lower priority', testBindPriority, $);70test('$.sync bound options have lower priority', testBindPriority, $.sync);7172const testSpacedCommand = async (t, args, execaMethod) => {73 const {stdout} = await execaMethod('command with space.js', args);74 const expectedStdout = args === undefined ? '' : args.join('\n');75 t.is(stdout, expectedStdout);76};7778test('allow commands with spaces and no array arguments', testSpacedCommand, undefined, execa);79test('allow commands with spaces and array arguments', testSpacedCommand, foobarArray, execa);80test('allow commands with spaces and no array arguments, execaSync', testSpacedCommand, undefined, execaSync);81test('allow commands with spaces and array arguments, execaSync', testSpacedCommand, foobarArray, execaSync);82test('allow commands with spaces and no array arguments, $', testSpacedCommand, undefined, $);83test('allow commands with spaces and array arguments, $', testSpacedCommand, foobarArray, $);84test('allow commands with spaces and no array arguments, $.sync', testSpacedCommand, undefined, $.sync);85test('allow commands with spaces and array arguments, $.sync', testSpacedCommand, foobarArray, $.sync);
modified:test/arguments/escape.js-10 removed
96 unmodified lines
97test('result.escapedCommand - \\uE000', testEscapedCommand, ['\uE000'], '\'\\ue000\'', '"\\ue000"');98test('result.escapedCommand - \\U1D172', testEscapedCommand, ['\u{1D172}'], '\'\u{1D172}\'', '"\u{1D172}"');99test('result.escapedCommand - \\U1D173', testEscapedCommand, ['\u{1D173}'], '\'\\U1d173\'', '"\\U1d173"');100test('result.escapedCommand - \\U10FFFD', testEscapedCommand, ['\u{10FFFD}'], '\'\\U10fffd\'', '"\\U10fffd"');101102test('allow commands with spaces and no array arguments', async t => {103 const {stdout} = await execa('command with space.js');104 t.is(stdout, '');105});106107test('allow commands with spaces and array arguments', async t => {108 const {stdout} = await execa('command with space.js', ['foo', 'bar']);109 t.is(stdout, 'foo\nbar');110});
modified:test/arguments/node.js+28 added-1 removed
1import {once} from 'node:events';2import {dirname, relative} from 'node:path';3import process from 'node:process';3import process, {version} from 'node:process';4import {pathToFileURL} from 'node:url';5import test from 'ava';6import getNode from 'get-node';7import {pEvent} from 'p-event';
21 unmodified lines
29test('execaNode() succeeds', testNodeSuccess, execaNode);30test('The "node" option succeeds', testNodeSuccess, runWithNodeOption);31test('The "node" option succeeds - sync', testNodeSuccess, runWithNodeOptionSync);3233test('execaNode(options) succeeds', async t => {34 const {stdout} = await execaNode({stripFinalNewline: false})('noop.js', [foobarString]);35 t.is(stdout, `${foobarString}\n`);36});3738test('execaNode`...` succeeds', async t => {39 const {stdout} = await execaNode`noop.js ${foobarString}`;40 t.is(stdout, foobarString);41});4243test('execaNode().pipe(execaNode()) succeeds', async t => {44 const {stdout} = await execaNode('noop.js').pipe(execaNode('--version'));45 t.is(stdout, version);46});4748test('execaNode().pipe(execa()) requires using "node"', async t => {49 await t.throwsAsync(execaNode('noop.js').pipe(execa('--version')));50});5152test('execaNode().pipe(...) requires using "node"', async t => {53 await t.throwsAsync(execaNode('noop.js').pipe('--version'));54});5556test('execaNode().pipe`...` requires using "node"', async t => {57 await t.throwsAsync(execaNode('noop.js').pipe`--version`);58});5960test('execaNode() cannot set the "node" option to false', t => {61 t.throws(() => {62 execaNode('empty.js', {node: false});63 }, {message: /The "node" option cannot be false/});
242 unmodified lines
added:test/arguments/normalize.js+183 added
1import {join, basename} from 'node:path';2import {fileURLToPath} from 'node:url';3import test from 'ava';4import {execa, execaSync, execaCommand, execaCommandSync, execaNode, $} from '../../index.js';5import {setFixtureDir, FIXTURES_DIR, FIXTURES_DIR_URL} from '../helpers/fixtures-dir.js';6import {foobarString} from '../helpers/input.js';78setFixtureDir();9const NOOP_PATH = join(FIXTURES_DIR, 'noop.js');1011const testFileUrl = async (t, execaMethod) => {12 const command = new URL('noop.js', FIXTURES_DIR_URL);13 const {stdout} = await execaMethod(command);14 t.is(stdout, foobarString);15};1617test('execa()\'s command argument can be a file URL', testFileUrl, execa);18test('execaSync()\'s command argument can be a file URL', testFileUrl, execaSync);19test('execaCommand()\'s command argument can be a file URL', testFileUrl, execaCommand);20test('execaCommandSync()\'s command argument can be a file URL', testFileUrl, execaCommandSync);21test('execaNode()\'s command argument can be a file URL', testFileUrl, execaNode);22test('$\'s command argument can be a file URL', testFileUrl, $);23test('$.sync\'s command argument can be a file URL', testFileUrl, $.sync);2425const testInvalidFileUrl = async (t, execaMethod) => {26 const invalidUrl = new URL('https://invalid.com');27 t.throws(() => {28 execaMethod(invalidUrl);29 }, {code: 'ERR_INVALID_URL_SCHEME'});30};3132test('execa()\'s command argument cannot be a non-file URL', testInvalidFileUrl, execa);33test('execaSync()\'s command argument cannot be a non-file URL', testInvalidFileUrl, execaSync);34test('execaCommand()\'s command argument cannot be a non-file URL', testInvalidFileUrl, execaCommand);35test('execaCommandSync()\'s command argument cannot be a non-file URL', testInvalidFileUrl, execaCommandSync);36test('execaNode()\'s command argument cannot be a non-file URL', testInvalidFileUrl, execaNode);37test('$\'s command argument cannot be a non-file URL', testInvalidFileUrl, $);38test('$.sync\'s command argument cannot be a non-file URL', testInvalidFileUrl, $.sync);3940const testInvalidCommand = async (t, arg, execaMethod) => {41 t.throws(() => {42 execaMethod(arg);43 }, {message: /First argument must be a string or a file URL/});44};4546test('execa()\'s first argument must be defined', testInvalidCommand, undefined, execa);47test('execaSync()\'s first argument must be defined', testInvalidCommand, undefined, execaSync);48test('execaCommand()\'s first argument must be defined', testInvalidCommand, undefined, execaCommand);49test('execaCommandSync()\'s first argument must be defined', testInvalidCommand, undefined, execaCommandSync);50test('execaNode()\'s first argument must be defined', testInvalidCommand, undefined, execaNode);51test('$\'s first argument must be defined', testInvalidCommand, undefined, $);52test('$.sync\'s first argument must be defined', testInvalidCommand, undefined, $.sync);53test('execa()\'s first argument must be valid', testInvalidCommand, true, execa);54test('execaSync()\'s first argument must be valid', testInvalidCommand, true, execaSync);55test('execaCommand()\'s first argument must be valid', testInvalidCommand, true, execaCommand);56test('execaCommandSync()\'s first argument must be valid', testInvalidCommand, true, execaCommandSync);57test('execaNode()\'s first argument must be valid', testInvalidCommand, true, execaNode);58test('$\'s first argument must be valid', testInvalidCommand, true, $);59test('$.sync\'s first argument must be valid', testInvalidCommand, true, $.sync);60test('execa()\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], execa);61test('execaSync()\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], execaSync);62test('execaCommand()\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], execaCommand);63test('execaCommandSync()\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], execaCommandSync);64test('execaNode()\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], execaNode);65test('$\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], $);66test('$.sync\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], $.sync);6768const testInvalidArgs = async (t, execaMethod) => {69 t.throws(() => {70 execaMethod('echo', true);71 }, {message: /Second argument must be either/});72};7374test('execa()\'s second argument must be valid', testInvalidArgs, execa);75test('execaSync()\'s second argument must be valid', testInvalidArgs, execaSync);76test('execaCommand()\'s second argument must be valid', testInvalidArgs, execaCommand);77test('execaCommandSync()\'s second argument must be valid', testInvalidArgs, execaCommandSync);78test('execaNode()\'s second argument must be valid', testInvalidArgs, execaNode);79test('$\'s second argument must be valid', testInvalidArgs, $);80test('$.sync\'s second argument must be valid', testInvalidArgs, $.sync);8182const testInvalidArgsItems = async (t, execaMethod) => {83 t.throws(() => {84 execaMethod('echo', [{}]);85 }, {message: 'Second argument must be an array of strings: [object Object]'});86};8788test('execa()\'s second argument must not be objects', testInvalidArgsItems, execa);89test('execaSync()\'s second argument must not be objects', testInvalidArgsItems, execaSync);90test('execaCommand()\'s second argument must not be objects', testInvalidArgsItems, execaCommand);91test('execaCommandSync()\'s second argument must not be objects', testInvalidArgsItems, execaCommandSync);92test('execaNode()\'s second argument must not be objects', testInvalidArgsItems, execaNode);93test('$\'s second argument must not be objects', testInvalidArgsItems, $);94test('$.sync\'s second argument must not be objects', testInvalidArgsItems, $.sync);9596const testNullByteArg = async (t, execaMethod) => {97 t.throws(() => {98 execaMethod('echo', ['a\0b']);99 }, {message: /null bytes/});100};101102test('execa()\'s second argument must not include \\0', testNullByteArg, execa);103test('execaSync()\'s second argument must not include \\0', testNullByteArg, execaSync);104test('execaCommand()\'s second argument must not include \\0', testNullByteArg, execaCommand);105test('execaCommandSync()\'s second argument must not include \\0', testNullByteArg, execaCommandSync);106test('execaNode()\'s second argument must not include \\0', testNullByteArg, execaNode);107test('$\'s second argument must not include \\0', testNullByteArg, $);108test('$.sync\'s second argument must not include \\0', testNullByteArg, $.sync);109110const testSerializeArg = async (t, arg, execaMethod) => {111 const {stdout} = await execaMethod(NOOP_PATH, [arg]);112 t.is(stdout, String(arg));113};114115test('execa()\'s arguments can be numbers', testSerializeArg, 1, execa);116test('execa()\'s arguments can be booleans', testSerializeArg, true, execa);117test('execa()\'s arguments can be NaN', testSerializeArg, Number.NaN, execa);118test('execa()\'s arguments can be Infinity', testSerializeArg, Number.POSITIVE_INFINITY, execa);119test('execa()\'s arguments can be null', testSerializeArg, null, execa);120test('execa()\'s arguments can be undefined', testSerializeArg, undefined, execa);121test('execa()\'s arguments can be bigints', testSerializeArg, 1n, execa);122test('execa()\'s arguments can be symbols', testSerializeArg, Symbol('test'), execa);123test('execaSync()\'s arguments can be numbers', testSerializeArg, 1, execaSync);124test('execaSync()\'s arguments can be booleans', testSerializeArg, true, execaSync);125test('execaSync()\'s arguments can be NaN', testSerializeArg, Number.NaN, execaSync);126test('execaSync()\'s arguments can be Infinity', testSerializeArg, Number.POSITIVE_INFINITY, execaSync);127test('execaSync()\'s arguments can be null', testSerializeArg, null, execaSync);128test('execaSync()\'s arguments can be undefined', testSerializeArg, undefined, execaSync);129test('execaSync()\'s arguments can be bigints', testSerializeArg, 1n, execaSync);130test('execaSync()\'s arguments can be symbols', testSerializeArg, Symbol('test'), execaSync);131test('execaNode()\'s arguments can be numbers', testSerializeArg, 1, execaNode);132test('execaNode()\'s arguments can be booleans', testSerializeArg, true, execaNode);133test('execaNode()\'s arguments can be NaN', testSerializeArg, Number.NaN, execaNode);134test('execaNode()\'s arguments can be Infinity', testSerializeArg, Number.POSITIVE_INFINITY, execaNode);135test('execaNode()\'s arguments can be null', testSerializeArg, null, execaNode);136test('execaNode()\'s arguments can be undefined', testSerializeArg, undefined, execaNode);137test('execaNode()\'s arguments can be bigints', testSerializeArg, 1n, execaNode);138test('execaNode()\'s arguments can be symbols', testSerializeArg, Symbol('test'), execaNode);139test('$\'s arguments can be numbers', testSerializeArg, 1, $);140test('$\'s arguments can be booleans', testSerializeArg, true, $);141test('$\'s arguments can be NaN', testSerializeArg, Number.NaN, $);142test('$\'s arguments can be Infinity', testSerializeArg, Number.POSITIVE_INFINITY, $);143test('$\'s arguments can be null', testSerializeArg, null, $);144test('$\'s arguments can be undefined', testSerializeArg, undefined, $);145test('$\'s arguments can be bigints', testSerializeArg, 1n, $);146test('$\'s arguments can be symbols', testSerializeArg, Symbol('test'), $);147test('$.sync\'s arguments can be numbers', testSerializeArg, 1, $.sync);148test('$.sync\'s arguments can be booleans', testSerializeArg, true, $.sync);149test('$.sync\'s arguments can be NaN', testSerializeArg, Number.NaN, $.sync);150test('$.sync\'s arguments can be Infinity', testSerializeArg, Number.POSITIVE_INFINITY, $.sync);151test('$.sync\'s arguments can be null', testSerializeArg, null, $.sync);152test('$.sync\'s arguments can be undefined', testSerializeArg, undefined, $.sync);153test('$.sync\'s arguments can be bigints', testSerializeArg, 1n, $.sync);154test('$.sync\'s arguments can be symbols', testSerializeArg, Symbol('test'), $.sync);155156const testInvalidOptions = async (t, execaMethod) => {157 t.throws(() => {158 execaMethod('echo', [], new Map());159 }, {message: /Last argument must be an options object/});160};161162test('execa()\'s third argument must be a plain object', testInvalidOptions, execa);163test('execaSync()\'s third argument must be a plain object', testInvalidOptions, execaSync);164test('execaCommand()\'s third argument must be a plain object', testInvalidOptions, execaCommand);165test('execaCommandSync()\'s third argument must be a plain object', testInvalidOptions, execaCommandSync);166test('execaNode()\'s third argument must be a plain object', testInvalidOptions, execaNode);167test('$\'s third argument must be a plain object', testInvalidOptions, $);168test('$.sync\'s third argument must be a plain object', testInvalidOptions, $.sync);169170const testRelativePath = async (t, execaMethod) => {171 const rootDir = basename(fileURLToPath(new URL('../..', import.meta.url)));172 const pathViaParentDir = join('..', rootDir, 'test', 'fixtures', 'noop.js');173 const {stdout} = await execaMethod(pathViaParentDir);174 t.is(stdout, foobarString);175};176177test('execa() use relative path with \'..\' chars', testRelativePath, execa);178test('execaSync() use relative path with \'..\' chars', testRelativePath, execaSync);179test('execaCommand() use relative path with \'..\' chars', testRelativePath, execaCommand);180test('execaCommandSync() use relative path with \'..\' chars', testRelativePath, execaCommandSync);181test('execaNode() use relative path with \'..\' chars', testRelativePath, execaNode);182test('$ use relative path with \'..\' chars', testRelativePath, $);183test('$.sync use relative path with \'..\' chars', testRelativePath, $.sync);
modified:test/arguments/options.js+27 added-100 removed
1import {delimiter, join, basename} from 'node:path';1import {delimiter} from 'node:path';2import process from 'node:process';3import {pathToFileURL, fileURLToPath} from 'node:url';3import {pathToFileURL} from 'node:url';4import test from 'ava';5import which from 'which';6import {execa, $, execaSync, execaNode} from '../../index.js';7import {setFixtureDir, FIXTURES_DIR_URL, PATH_KEY} from '../helpers/fixtures-dir.js';6import {execa, $} from '../../index.js';7import {setFixtureDir, PATH_KEY} from '../helpers/fixtures-dir.js';8import {identity} from '../helpers/stdio.js';910setFixtureDir();11process.env.FOO = 'foo';
7 unmodified lines
19};2021const BIN_DIR_REGEXP = /node_modules[\\/]\.bin/;2223const pathWitoutLocalDir = getPathWithoutLocalDir();2425test('preferLocal: true', async t => {24 await t.notThrowsAsync(execa('ava', ['--version'], {preferLocal: true, env: getPathWithoutLocalDir()}));26 await t.notThrowsAsync(execa('ava', ['--version'], {preferLocal: true, env: pathWitoutLocalDir}));27});2829test('preferLocal: false', async t => {28 await t.throwsAsync(execa('ava', ['--version'], {preferLocal: false, env: getPathWithoutLocalDir()}), {message: ENOENT_REGEXP});30 await t.throwsAsync(execa('ava', ['--version'], {preferLocal: false, env: pathWitoutLocalDir}), {message: ENOENT_REGEXP});31});3233test('preferLocal: undefined', async t => {32 await t.throwsAsync(execa('ava', ['--version'], {env: getPathWithoutLocalDir()}), {message: ENOENT_REGEXP});34 await t.throwsAsync(execa('ava', ['--version'], {env: pathWitoutLocalDir}), {message: ENOENT_REGEXP});35});3637test('preferLocal: undefined with $', async t => {36 await t.notThrowsAsync($({env: getPathWithoutLocalDir()})`ava --version`);38 await t.notThrowsAsync($('ava', ['--version'], {env: pathWitoutLocalDir}));39});4041test('preferLocal: undefined with $.sync', t => {40 t.notThrows(() => $({env: getPathWithoutLocalDir()}).sync`ava --version`);42 t.notThrows(() => $.sync('ava', ['--version'], {env: pathWitoutLocalDir}));43});4445test('preferLocal: undefined with execa.pipe`...`', async t => {46 await t.throwsAsync(() => execa('node', ['--version']).pipe({env: pathWitoutLocalDir})`ava --version`);47});4849test('preferLocal: undefined with $.pipe`...`', async t => {50 await t.notThrows(() => $('node', ['--version']).pipe({env: pathWitoutLocalDir})`ava --version`);51});5253test('preferLocal: undefined with execa.pipe()', async t => {54 await t.throwsAsync(() => execa('node', ['--version']).pipe('ava', ['--version'], {env: pathWitoutLocalDir}));55});5657test('preferLocal: undefined with $.pipe()', async t => {58 await t.notThrows(() => $('node', ['--version']).pipe('ava', ['--version'], {env: pathWitoutLocalDir}));59});6061test('localDir option', async t => {62 const command = isWindows ? 'echo %PATH%' : 'echo $PATH';63 const {stdout} = await execa(command, {shell: true, preferLocal: true, localDir: '/test'});64 const envPaths = stdout.split(delimiter);
43 unmodified lines
108};109110test('can use `options.shell: string`', testShellPath, identity);111test('can use `options.shell: file URL`', testShellPath, pathToFileURL);9495const testFileUrl = async (t, execaMethod) => {96 const command = new URL('noop.js', FIXTURES_DIR_URL);97 const {stdout} = await execaMethod(command, ['foobar']);98 t.is(stdout, 'foobar');99};100101test('execa()\'s command argument can be a file URL', testFileUrl, execa);102test('execaSync()\'s command argument can be a file URL', testFileUrl, execaSync);103test('execaNode()\'s command argument can be a file URL', testFileUrl, execaNode);104105const testInvalidFileUrl = async (t, execaMethod) => {106 const invalidUrl = new URL('https://invalid.com');107 t.throws(() => {108 execaMethod(invalidUrl);109 }, {code: 'ERR_INVALID_URL_SCHEME'});110};111112test('execa()\'s command argument cannot be a non-file URL', testInvalidFileUrl, execa);113test('execaSync()\'s command argument cannot be a non-file URL', testInvalidFileUrl, execaSync);114test('execaNode()\'s command argument cannot be a non-file URL', testInvalidFileUrl, execaNode);115116const testInvalidCommand = async (t, execaMethod) => {117 t.throws(() => {118 execaMethod(['command', 'arg']);119 }, {message: /First argument must be a string or a file URL/});120};121122test('execa()\'s command argument must be a string or file URL', testInvalidCommand, execa);123test('execaSync()\'s command argument must be a string or file URL', testInvalidCommand, execaSync);124test('execaNode()\'s command argument must be a string or file URL', testInvalidCommand, execaNode);125126const testInvalidArgs = async (t, execaMethod) => {127 t.throws(() => {128 execaMethod('echo', true);129 }, {message: /Second argument must be either/});130};131132test('execa()\'s second argument must be an array', testInvalidArgs, execa);133test('execaSync()\'s second argument must be an array', testInvalidArgs, execaSync);134test('execaNode()\'s second argument must be an array', testInvalidArgs, execaNode);135136const testInvalidArgsItems = async (t, execaMethod) => {137 t.throws(() => {138 execaMethod('echo', [{}]);139 }, {message: 'Second argument must be an array of strings: [object Object]'});140};141142test('execa()\'s second argument must not be objects', testInvalidArgsItems, execa);143test('execaSync()\'s second argument must not be objects', testInvalidArgsItems, execaSync);144test('execaNode()\'s second argument must not be objects', testInvalidArgsItems, execaNode);145146const testNullByteArg = async (t, execaMethod) => {147 t.throws(() => {148 execaMethod('echo', ['a\0b']);149 }, {message: /null bytes/});150};151152test('execa()\'s second argument must not include \\0', testNullByteArg, execa);153test('execaSync()\'s second argument must not include \\0', testNullByteArg, execaSync);154test('execaNode()\'s second argument must not include \\0', testNullByteArg, execaNode);155156const testSerializeArg = async (t, arg) => {157 const {stdout} = await execa('noop.js', [arg]);158 t.is(stdout, String(arg));159};160161test('execa()\'s arguments can be numbers', testSerializeArg, 1);162test('execa()\'s arguments can be booleans', testSerializeArg, true);163test('execa()\'s arguments can be NaN', testSerializeArg, Number.NaN);164test('execa()\'s arguments can be Infinity', testSerializeArg, Number.POSITIVE_INFINITY);165test('execa()\'s arguments can be null', testSerializeArg, null);166test('execa()\'s arguments can be undefined', testSerializeArg, undefined);167test('execa()\'s arguments can be bigints', testSerializeArg, 1n);168test('execa()\'s arguments can be symbols', testSerializeArg, Symbol('test'));169170const testInvalidOptions = async (t, execaMethod) => {171 t.throws(() => {172 execaMethod('echo', [], new Map());173 }, {message: /Last argument must be an options object/});174};175176test('execa()\'s third argument must be a plain object', testInvalidOptions, execa);177test('execaSync()\'s third argument must be a plain object', testInvalidOptions, execaSync);178test('execaNode()\'s third argument must be a plain object', testInvalidOptions, execaNode);179180test('use relative path with \'..\' chars', async t => {181 const pathViaParentDir = join('..', basename(fileURLToPath(new URL('../..', import.meta.url))), 'test', 'fixtures', 'noop.js');182 const {stdout} = await execa(pathViaParentDir, ['foo']);183 t.is(stdout, 'foo');184});
added:test/arguments/template.js+329 added
1import test from 'ava';2import {$} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';45setFixtureDir();67// Workaround since some text editors or IDEs do not allow inputting \r directly8const escapedCall = string => {9 const templates = [string];10 templates.raw = [string];11 return $(templates);12};1314const testScriptStdout = async (t, getSubprocess, expectedStdout) => {15 const {stdout} = await getSubprocess();16 t.is(stdout, expectedStdout);17};1819test('$ allows number interpolation', testScriptStdout, () => $`echo.js 1 ${2}`, '1\n2');20test('$ can concatenate multiple tokens', testScriptStdout, () => $`echo.js ${'foo'}bar${'foo'}`, 'foobarfoo');21test('$ can use newlines and tab indentations', testScriptStdout, () => $`echo.js foo22 bar`, 'foo\nbar');23test('$ can use newlines and space indentations', testScriptStdout, () => $`echo.js foo24 bar`, 'foo\nbar');25test('$ can use Windows newlines and tab indentations', testScriptStdout, () => escapedCall('echo.js foo\r\n\tbar'), 'foo\nbar');26test('$ can use Windows newlines and space indentations', testScriptStdout, () => escapedCall('echo.js foo\r\n bar'), 'foo\nbar');27test('$ does not ignore comments in expressions', testScriptStdout, () => $`echo.js foo28 ${/* This is a comment */''}29 bar30 ${/* This is another comment */''}31 baz32`, 'foo\n\nbar\n\nbaz');33test('$ allows escaping spaces with interpolation', testScriptStdout, () => $`echo.js ${'foo bar'}`, 'foo bar');34test('$ allows escaping spaces in commands with interpolation', testScriptStdout, () => $`${'command with space.js'} foo bar`, 'foo\nbar');35test('$ trims', testScriptStdout, () => $` echo.js foo bar `, 'foo\nbar');36test('$ allows array interpolation', testScriptStdout, () => $`echo.js ${['foo', 'bar']}`, 'foo\nbar');37test('$ allows empty array interpolation', testScriptStdout, () => $`echo.js foo ${[]} bar`, 'foo\nbar');38test('$ allows space escaped values in array interpolation', testScriptStdout, () => $`echo.js ${['foo', 'bar baz']}`, 'foo\nbar baz');39test('$ can concatenate at the end of tokens followed by an array', testScriptStdout, () => $`echo.js foo${['bar', 'foo']}`, 'foobar\nfoo');40test('$ can concatenate at the start of tokens followed by an array', testScriptStdout, () => $`echo.js ${['foo', 'bar']}foo`, 'foo\nbarfoo');41test('$ can concatenate at the start and end of tokens followed by an array', testScriptStdout, () => $`echo.js foo${['bar', 'foo']}bar`, 'foobar\nfoobar');42test('$ handles escaped newlines', testScriptStdout, () => $`echo.js a\43b`, 'ab');44test('$ handles backslashes at end of lines', testScriptStdout, () => $`echo.js a\\45 b`, 'a\\\nb');46test('$ handles double backslashes at end of lines', testScriptStdout, () => $`echo.js a\\\\47 b`, 'a\\\\\nb');48test('$ handles tokens - a', testScriptStdout, () => $`echo.js a`, 'a');49test('$ handles expressions - a', testScriptStdout, () => $`echo.js ${'a'}`, 'a');50test('$ handles tokens - abc', testScriptStdout, () => $`echo.js abc`, 'abc');51test('$ handles expressions - abc', testScriptStdout, () => $`echo.js ${'abc'}`, 'abc');52test('$ handles tokens - ""', testScriptStdout, () => $`echo.js`, '');53test('$ handles expressions - ""', testScriptStdout, () => $`echo.js a ${''} b`, 'a\n\nb');54test('$ splits tokens - ""', testScriptStdout, () => $`echo.js ab`, 'ab');55test('$ splits expressions - ""', testScriptStdout, () => $`echo.js ${'a'}${'b'}`, 'ab');56test('$ concatenates expressions - ""', testScriptStdout, () => $`echo.js a${'b'}c`, 'abc');57test('$ handles tokens - " "', testScriptStdout, () => $`echo.js `, '');58test('$ handles expressions - " "', testScriptStdout, () => $`echo.js ${' '}`, ' ');59test('$ splits tokens - " "', testScriptStdout, () => $`echo.js a b`, 'a\nb');60test('$ splits expressions - " "', testScriptStdout, () => $`echo.js ${'a'} ${'b'}`, 'a\nb');61test('$ concatenates tokens - " "', testScriptStdout, () => $`echo.js a `, 'a');62test('$ concatenates expressions - " "', testScriptStdout, () => $`echo.js ${'a'} `, 'a');63test('$ handles tokens - " " (2 spaces)', testScriptStdout, () => $`echo.js `, '');64test('$ handles expressions - " " (2 spaces)', testScriptStdout, () => $`echo.js ${' '}`, ' ');65test('$ splits tokens - " " (2 spaces)', testScriptStdout, () => $`echo.js a b`, 'a\nb');66test('$ splits expressions - " " (2 spaces)', testScriptStdout, () => $`echo.js ${'a'} ${'b'}`, 'a\nb');67test('$ concatenates tokens - " " (2 spaces)', testScriptStdout, () => $`echo.js a `, 'a');68test('$ concatenates expressions - " " (2 spaces)', testScriptStdout, () => $`echo.js ${'a'} `, 'a');69test('$ handles tokens - " " (3 spaces)', testScriptStdout, () => $`echo.js `, '');70test('$ handles expressions - " " (3 spaces)', testScriptStdout, () => $`echo.js ${' '}`, ' ');71test('$ splits tokens - " " (3 spaces)', testScriptStdout, () => $`echo.js a b`, 'a\nb');72test('$ splits expressions - " " (3 spaces)', testScriptStdout, () => $`echo.js ${'a'} ${'b'}`, 'a\nb');73test('$ concatenates tokens - " " (3 spaces)', testScriptStdout, () => $`echo.js a `, 'a');74test('$ concatenates expressions - " " (3 spaces)', testScriptStdout, () => $`echo.js ${'a'} `, 'a');75test('$ handles tokens - \\t (no escape)', testScriptStdout, () => $`echo.js `, '');76test('$ handles expressions - \\t (no escape)', testScriptStdout, () => $`echo.js ${' '}`, '\t');77test('$ splits tokens - \\t (no escape)', testScriptStdout, () => $`echo.js a b`, 'a\nb');78test('$ splits expressions - \\t (no escape)', testScriptStdout, () => $`echo.js ${'a'} ${'b'}`, 'a\nb');79test('$ concatenates tokens - \\t (no escape)', testScriptStdout, () => $`echo.js a b`, 'a\nb');80test('$ concatenates expressions - \\t (no escape)', testScriptStdout, () => $`echo.js ${'a'} b`, 'a\nb');81test('$ handles tokens - \\t (escape)', testScriptStdout, () => $`echo.js \t`, '\t');82test('$ handles expressions - \\t (escape)', testScriptStdout, () => $`echo.js ${'\t'}`, '\t');83test('$ splits tokens - \\t (escape)', testScriptStdout, () => $`echo.js a\tb`, 'a\tb');84test('$ splits expressions - \\t (escape)', testScriptStdout, () => $`echo.js ${'a'}\t${'b'}`, 'a\tb');85test('$ concatenates tokens - \\t (escape)', testScriptStdout, () => $`echo.js \ta\t b`, '\ta\t\nb');86test('$ concatenates expressions - \\t (escape)', testScriptStdout, () => $`echo.js \t${'a'}\t b`, '\ta\t\nb');87test('$ handles tokens - \\n (no escape)', testScriptStdout, () => $`echo.js88 `, '');89test('$ handles expressions - \\n (no escape)', testScriptStdout, () => $`echo.js ${`90`} `, '\n');91test('$ splits tokens - \\n (no escape)', testScriptStdout, () => $`echo.js a92 b`, 'a\nb');93test('$ splits expressions - \\n (no escape)', testScriptStdout, () => $`echo.js ${'a'}94 ${'b'}`, 'a\nb');95test('$ concatenates tokens - \\n (no escape)', testScriptStdout, () => $`echo.js96a97 b`, 'a\nb');98test('$ concatenates expressions - \\n (no escape)', testScriptStdout, () => $`echo.js99${'a'}100 b`, 'a\nb');101test('$ handles tokens - \\n (escape)', testScriptStdout, () => $`echo.js \n `, '\n');102test('$ handles expressions - \\n (escape)', testScriptStdout, () => $`echo.js ${'\n'} `, '\n');103test('$ splits tokens - \\n (escape)', testScriptStdout, () => $`echo.js a\n b`, 'a\n\nb');104test('$ splits expressions - \\n (escape)', testScriptStdout, () => $`echo.js ${'a'}\n ${'b'}`, 'a\n\nb');105test('$ concatenates tokens - \\n (escape)', testScriptStdout, () => $`echo.js \na\n b`, '\na\n\nb');106test('$ concatenates expressions - \\n (escape)', testScriptStdout, () => $`echo.js \n${'a'}\n b`, '\na\n\nb');107test('$ handles tokens - \\r (no escape)', testScriptStdout, () => escapedCall('echo.js \r '), '');108test('$ splits tokens - \\r (no escape)', testScriptStdout, () => escapedCall('echo.js a\rb'), 'a\nb');109test('$ splits expressions - \\r (no escape)', testScriptStdout, () => escapedCall(`echo.js ${'a'}\r${'b'}`), 'a\nb');110test('$ concatenates tokens - \\r (no escape)', testScriptStdout, () => escapedCall('echo.js \ra\r b'), 'a\nb');111test('$ concatenates expressions - \\r (no escape)', testScriptStdout, () => escapedCall(`echo.js \r${'a'}\r b`), 'a\nb');112test('$ splits tokens - \\r (escape)', testScriptStdout, () => $`echo.js a\r b`, 'a\r\nb');113test('$ splits expressions - \\r (escape)', testScriptStdout, () => $`echo.js ${'a'}\r ${'b'}`, 'a\r\nb');114test('$ concatenates tokens - \\r (escape)', testScriptStdout, () => $`echo.js \ra\r b`, '\ra\r\nb');115test('$ concatenates expressions - \\r (escape)', testScriptStdout, () => $`echo.js \r${'a'}\r b`, '\ra\r\nb');116test('$ handles tokens - \\r\\n (no escape)', testScriptStdout, () => escapedCall('echo.js \r\n '), '');117test('$ splits tokens - \\r\\n (no escape)', testScriptStdout, () => escapedCall('echo.js a\r\nb'), 'a\nb');118test('$ splits expressions - \\r\\n (no escape)', testScriptStdout, () => escapedCall(`echo.js ${'a'}\r\n${'b'}`), 'a\nb');119test('$ concatenates tokens - \\r\\n (no escape)', testScriptStdout, () => escapedCall('echo.js \r\na\r\n b'), 'a\nb');120test('$ concatenates expressions - \\r\\n (no escape)', testScriptStdout, () => escapedCall(`echo.js \r\n${'a'}\r\n b`), 'a\nb');121test('$ handles tokens - \\r\\n (escape)', testScriptStdout, () => $`echo.js \r\n `, '\r\n');122test('$ handles expressions - \\r\\n (escape)', testScriptStdout, () => $`echo.js ${'\r\n'} `, '\r\n');123test('$ splits tokens - \\r\\n (escape)', testScriptStdout, () => $`echo.js a\r\n b`, 'a\r\n\nb');124test('$ splits expressions - \\r\\n (escape)', testScriptStdout, () => $`echo.js ${'a'}\r\n ${'b'}`, 'a\r\n\nb');125test('$ concatenates tokens - \\r\\n (escape)', testScriptStdout, () => $`echo.js \r\na\r\n b`, '\r\na\r\n\nb');126test('$ concatenates expressions - \\r\\n (escape)', testScriptStdout, () => $`echo.js \r\n${'a'}\r\n b`, '\r\na\r\n\nb');127/* eslint-disable no-irregular-whitespace */128test('$ handles expressions - \\f (no escape)', testScriptStdout, () => $`echo.js ${' '}`, '\f');129test('$ splits tokens - \\f (no escape)', testScriptStdout, () => $`echo.js a b`, 'a\fb');130test('$ splits expressions - \\f (no escape)', testScriptStdout, () => $`echo.js ${'a'} ${'b'}`, 'a\fb');131test('$ concatenates tokens - \\f (no escape)', testScriptStdout, () => $`echo.js a b`, '\fa\f\nb');132test('$ concatenates expressions - \\f (no escape)', testScriptStdout, () => $`echo.js ${'a'} b`, '\fa\f\nb');133/* eslint-enable no-irregular-whitespace */134test('$ handles tokens - \\f (escape)', testScriptStdout, () => $`echo.js \f`, '\f');135test('$ handles expressions - \\f (escape)', testScriptStdout, () => $`echo.js ${'\f'}`, '\f');136test('$ splits tokens - \\f (escape)', testScriptStdout, () => $`echo.js a\fb`, 'a\fb');137test('$ splits expressions - \\f (escape)', testScriptStdout, () => $`echo.js ${'a'}\f${'b'}`, 'a\fb');138test('$ concatenates tokens - \\f (escape)', testScriptStdout, () => $`echo.js \fa\f b`, '\fa\f\nb');139test('$ concatenates expressions - \\f (escape)', testScriptStdout, () => $`echo.js \f${'a'}\f b`, '\fa\f\nb');140test('$ handles tokens - \\', testScriptStdout, () => $`echo.js \\`, '\\');141test('$ handles expressions - \\', testScriptStdout, () => $`echo.js ${'\\'}`, '\\');142test('$ splits tokens - \\', testScriptStdout, () => $`echo.js a\\b`, 'a\\b');143test('$ splits expressions - \\', testScriptStdout, () => $`echo.js ${'a'}\\${'b'}`, 'a\\b');144test('$ concatenates tokens - \\', testScriptStdout, () => $`echo.js \\a\\ b`, '\\a\\\nb');145test('$ concatenates expressions - \\', testScriptStdout, () => $`echo.js \\${'a'}\\ b`, '\\a\\\nb');146test('$ handles tokens - \\\\', testScriptStdout, () => $`echo.js \\\\`, '\\\\');147test('$ handles expressions - \\\\', testScriptStdout, () => $`echo.js ${'\\\\'}`, '\\\\');148test('$ splits tokens - \\\\', testScriptStdout, () => $`echo.js a\\\\b`, 'a\\\\b');149test('$ splits expressions - \\\\', testScriptStdout, () => $`echo.js ${'a'}\\\\${'b'}`, 'a\\\\b');150test('$ concatenates tokens - \\\\', testScriptStdout, () => $`echo.js \\\\a\\\\ b`, '\\\\a\\\\\nb');151test('$ concatenates expressions - \\\\', testScriptStdout, () => $`echo.js \\\\${'a'}\\\\ b`, '\\\\a\\\\\nb');152test('$ handles tokens - `', testScriptStdout, () => $`echo.js \``, '`');153test('$ handles expressions - `', testScriptStdout, () => $`echo.js ${'`'}`, '`');154test('$ splits tokens - `', testScriptStdout, () => $`echo.js a\`b`, 'a`b');155test('$ splits expressions - `', testScriptStdout, () => $`echo.js ${'a'}\`${'b'}`, 'a`b');156test('$ concatenates tokens - `', testScriptStdout, () => $`echo.js \`a\` b`, '`a`\nb');157test('$ concatenates expressions - `', testScriptStdout, () => $`echo.js \`${'a'}\` b`, '`a`\nb');158test('$ handles tokens - \\v', testScriptStdout, () => $`echo.js \v`, '\v');159test('$ handles expressions - \\v', testScriptStdout, () => $`echo.js ${'\v'}`, '\v');160test('$ splits tokens - \\v', testScriptStdout, () => $`echo.js a\vb`, 'a\vb');161test('$ splits expressions - \\v', testScriptStdout, () => $`echo.js ${'a'}\v${'b'}`, 'a\vb');162test('$ concatenates tokens - \\v', testScriptStdout, () => $`echo.js \va\v b`, '\va\v\nb');163test('$ concatenates expressions - \\v', testScriptStdout, () => $`echo.js \v${'a'}\v b`, '\va\v\nb');164test('$ handles tokens - \\u2028', testScriptStdout, () => $`echo.js \u2028`, '\u2028');165test('$ handles expressions - \\u2028', testScriptStdout, () => $`echo.js ${'\u2028'}`, '\u2028');166test('$ splits tokens - \\u2028', testScriptStdout, () => $`echo.js a\u2028b`, 'a\u2028b');167test('$ splits expressions - \\u2028', testScriptStdout, () => $`echo.js ${'a'}\u2028${'b'}`, 'a\u2028b');168test('$ concatenates tokens - \\u2028', testScriptStdout, () => $`echo.js \u2028a\u2028 b`, '\u2028a\u2028\nb');169test('$ concatenates expressions - \\u2028', testScriptStdout, () => $`echo.js \u2028${'a'}\u2028 b`, '\u2028a\u2028\nb');170test('$ handles tokens - \\a', testScriptStdout, () => $`echo.js \a`, 'a');171test('$ splits tokens - \\a', testScriptStdout, () => $`echo.js a\ab`, 'aab');172test('$ splits expressions - \\a', testScriptStdout, () => $`echo.js ${'a'}\a${'b'}`, 'aab');173test('$ concatenates tokens - \\a', testScriptStdout, () => $`echo.js \aa\a b`, 'aaa\nb');174test('$ concatenates expressions - \\a', testScriptStdout, () => $`echo.js \a${'a'}\a b`, 'aaa\nb');175test('$ handles tokens - \\cJ', testScriptStdout, () => $`echo.js \cJ`, 'cJ');176test('$ splits tokens - \\cJ', testScriptStdout, () => $`echo.js a\cJb`, 'acJb');177test('$ splits expressions - \\cJ', testScriptStdout, () => $`echo.js ${'a'}\cJ${'b'}`, 'acJb');178test('$ concatenates tokens - \\cJ', testScriptStdout, () => $`echo.js \cJa\cJ b`, 'cJacJ\nb');179test('$ concatenates expressions - \\cJ', testScriptStdout, () => $`echo.js \cJ${'a'}\cJ b`, 'cJacJ\nb');180test('$ handles tokens - \\.', testScriptStdout, () => $`echo.js \.`, '.');181test('$ splits tokens - \\.', testScriptStdout, () => $`echo.js a\.b`, 'a.b');182test('$ splits expressions - \\.', testScriptStdout, () => $`echo.js ${'a'}\.${'b'}`, 'a.b');183test('$ concatenates tokens - \\.', testScriptStdout, () => $`echo.js \.a\. b`, '.a.\nb');184test('$ concatenates expressions - \\.', testScriptStdout, () => $`echo.js \.${'a'}\. b`, '.a.\nb');185/* eslint-disable unicorn/no-hex-escape */186test('$ handles tokens - \\x63', testScriptStdout, () => $`echo.js \x63`, 'c');187test('$ splits tokens - \\x63', testScriptStdout, () => $`echo.js a\x63b`, 'acb');188test('$ splits expressions - \\x63', testScriptStdout, () => $`echo.js ${'a'}\x63${'b'}`, 'acb');189test('$ concatenates tokens - \\x63', testScriptStdout, () => $`echo.js \x63a\x63 b`, 'cac\nb');190test('$ concatenates expressions - \\x63', testScriptStdout, () => $`echo.js \x63${'a'}\x63 b`, 'cac\nb');191/* eslint-enable unicorn/no-hex-escape */192test('$ handles tokens - \\u0063', testScriptStdout, () => $`echo.js \u0063`, 'c');193test('$ splits tokens - \\u0063', testScriptStdout, () => $`echo.js a\u0063b`, 'acb');194test('$ splits expressions - \\u0063', testScriptStdout, () => $`echo.js ${'a'}\u0063${'b'}`, 'acb');195test('$ concatenates tokens - \\u0063', testScriptStdout, () => $`echo.js \u0063a\u0063 b`, 'cac\nb');196test('$ concatenates expressions - \\u0063', testScriptStdout, () => $`echo.js \u0063${'a'}\u0063 b`, 'cac\nb');197test('$ handles tokens - \\u{1}', testScriptStdout, () => $`echo.js \u{1}`, '\u0001');198test('$ splits tokens - \\u{1}', testScriptStdout, () => $`echo.js a\u{1}b`, 'a\u0001b');199test('$ splits expressions - \\u{1}', testScriptStdout, () => $`echo.js ${'a'}\u{1}${'b'}`, 'a\u0001b');200test('$ concatenates tokens - \\u{1}', testScriptStdout, () => $`echo.js \u{1}a\u{1} b`, '\u0001a\u0001\nb');201test('$ concatenates expressions - \\u{1}', testScriptStdout, () => $`echo.js \u{1}${'a'}\u{1} b`, '\u0001a\u0001\nb');202test('$ handles tokens - \\u{63}', testScriptStdout, () => $`echo.js \u{63}`, 'c');203test('$ splits tokens - \\u{63}', testScriptStdout, () => $`echo.js a\u{63}b`, 'acb');204test('$ splits expressions - \\u{63}', testScriptStdout, () => $`echo.js ${'a'}\u{63}${'b'}`, 'acb');205test('$ concatenates tokens - \\u{63}', testScriptStdout, () => $`echo.js \u{63}a\u{63} b`, 'cac\nb');206test('$ concatenates expressions - \\u{63}', testScriptStdout, () => $`echo.js \u{63}${'a'}\u{63} b`, 'cac\nb');207test('$ handles tokens - \\u{063}', testScriptStdout, () => $`echo.js \u{063}`, 'c');208test('$ splits tokens - \\u{063}', testScriptStdout, () => $`echo.js a\u{063}b`, 'acb');209test('$ splits expressions - \\u{063}', testScriptStdout, () => $`echo.js ${'a'}\u{063}${'b'}`, 'acb');210test('$ concatenates tokens - \\u{063}', testScriptStdout, () => $`echo.js \u{063}a\u{063} b`, 'cac\nb');211test('$ concatenates expressions - \\u{063}', testScriptStdout, () => $`echo.js \u{063}${'a'}\u{063} b`, 'cac\nb');212test('$ handles tokens - \\u{0063}', testScriptStdout, () => $`echo.js \u{0063}`, 'c');213test('$ splits tokens - \\u{0063}', testScriptStdout, () => $`echo.js a\u{0063}b`, 'acb');214test('$ splits expressions - \\u{0063}', testScriptStdout, () => $`echo.js ${'a'}\u{0063}${'b'}`, 'acb');215test('$ concatenates tokens - \\u{0063}', testScriptStdout, () => $`echo.js \u{0063}a\u{0063} b`, 'cac\nb');216test('$ concatenates expressions - \\u{0063}', testScriptStdout, () => $`echo.js \u{0063}${'a'}\u{0063} b`, 'cac\nb');217test('$ handles tokens - \\u{00063}', testScriptStdout, () => $`echo.js \u{00063}`, 'c');218test('$ splits tokens - \\u{00063}', testScriptStdout, () => $`echo.js a\u{00063}b`, 'acb');219test('$ splits expressions - \\u{00063}', testScriptStdout, () => $`echo.js ${'a'}\u{00063}${'b'}`, 'acb');220test('$ concatenates tokens - \\u{00063}', testScriptStdout, () => $`echo.js \u{00063}a\u{00063} b`, 'cac\nb');221test('$ concatenates expressions - \\u{00063}', testScriptStdout, () => $`echo.js \u{00063}${'a'}\u{00063} b`, 'cac\nb');222test('$ handles tokens - \\u{000063}', testScriptStdout, () => $`echo.js \u{000063}`, 'c');223test('$ splits tokens - \\u{000063}', testScriptStdout, () => $`echo.js a\u{000063}b`, 'acb');224test('$ splits expressions - \\u{000063}', testScriptStdout, () => $`echo.js ${'a'}\u{000063}${'b'}`, 'acb');225test('$ concatenates tokens - \\u{000063}', testScriptStdout, () => $`echo.js \u{000063}a\u{000063} b`, 'cac\nb');226test('$ concatenates expressions - \\u{000063}', testScriptStdout, () => $`echo.js \u{000063}${'a'}\u{000063} b`, 'cac\nb');227test('$ handles tokens - \\u{0000063}', testScriptStdout, () => $`echo.js \u{0000063}`, 'c');228test('$ splits tokens - \\u{0000063}', testScriptStdout, () => $`echo.js a\u{0000063}b`, 'acb');229test('$ splits expressions - \\u{0000063}', testScriptStdout, () => $`echo.js ${'a'}\u{0000063}${'b'}`, 'acb');230test('$ concatenates tokens - \\u{0000063}', testScriptStdout, () => $`echo.js \u{0000063}a\u{0000063} b`, 'cac\nb');231test('$ concatenates expressions - \\u{0000063}', testScriptStdout, () => $`echo.js \u{0000063}${'a'}\u{0000063} b`, 'cac\nb');232test('$ handles tokens - \\u{0063}}', testScriptStdout, () => $`echo.js \u{0063}}`, 'c}');233test('$ splits tokens - \\u{0063}}', testScriptStdout, () => $`echo.js a\u{0063}}b`, 'ac}b');234test('$ splits expressions - \\u{0063}}', testScriptStdout, () => $`echo.js ${'a'}\u{0063}}${'b'}`, 'ac}b');235test('$ concatenates tokens - \\u{0063}}', testScriptStdout, () => $`echo.js \u{0063}}a\u{0063}} b`, 'c}ac}\nb');236test('$ concatenates expressions - \\u{0063}}', testScriptStdout, () => $`echo.js \u{0063}}${'a'}\u{0063}} b`, 'c}ac}\nb');237238const testScriptErrorStdout = async (t, getSubprocess) => {239 t.throws(getSubprocess, {message: /null bytes/});240};241242test('$ handles tokens - \\0', testScriptErrorStdout, () => $`echo.js \0`);243test('$ splits tokens - \\0', testScriptErrorStdout, () => $`echo.js a\0b`);244test('$ splits expressions - \\0', testScriptErrorStdout, () => $`echo.js ${'a'}\0${'b'}`);245test('$ concatenates tokens - \\0', testScriptErrorStdout, () => $`echo.js \0a\0 b`);246test('$ concatenates expressions - \\0', testScriptErrorStdout, () => $`echo.js \0${'a'}\0 b`);247248const testReturnInterpolate = async (t, getSubprocess, expectedStdout, options = {}) => {249 const foo = await $(options)`echo.js foo`;250 const {stdout} = await getSubprocess(foo);251 t.is(stdout, expectedStdout);252};253254test('$ allows execa return value interpolation', testReturnInterpolate, foo => $`echo.js ${foo} bar`, 'foo\nbar');255test('$ allows execa return value buffer interpolation', testReturnInterpolate, foo => $`echo.js ${foo} bar`, 'foo\nbar', {encoding: 'buffer'});256test('$ allows execa return value array interpolation', testReturnInterpolate, foo => $`echo.js ${[foo, 'bar']}`, 'foo\nbar');257test('$ allows execa return value buffer array interpolation', testReturnInterpolate, foo => $`echo.js ${[foo, 'bar']}`, 'foo\nbar', {encoding: 'buffer'});258259const testReturnInterpolateSync = (t, getSubprocess, expectedStdout, options = {}) => {260 const foo = $(options).sync`echo.js foo`;261 const {stdout} = getSubprocess(foo);262 t.is(stdout, expectedStdout);263};264265test('$.sync allows execa return value interpolation', testReturnInterpolateSync, foo => $.sync`echo.js ${foo} bar`, 'foo\nbar');266test('$.sync allows execa return value buffer interpolation', testReturnInterpolateSync, foo => $.sync`echo.js ${foo} bar`, 'foo\nbar', {encoding: 'buffer'});267test('$.sync allows execa return value array interpolation', testReturnInterpolateSync, foo => $.sync`echo.js ${[foo, 'bar']}`, 'foo\nbar');268test('$.sync allows execa return value buffer array interpolation', testReturnInterpolateSync, foo => $.sync`echo.js ${[foo, 'bar']}`, 'foo\nbar', {encoding: 'buffer'});269270const testInvalidSequence = (t, getSubprocess) => {271 t.throws(getSubprocess, {message: /Invalid backslash sequence/});272};273274test('$ handles invalid escape sequence - \\1', testInvalidSequence, () => $`echo.js \1`);275test('$ handles invalid escape sequence - \\u', testInvalidSequence, () => $`echo.js \u`);276test('$ handles invalid escape sequence - \\u0', testInvalidSequence, () => $`echo.js \u0`);277test('$ handles invalid escape sequence - \\u00', testInvalidSequence, () => $`echo.js \u00`);278test('$ handles invalid escape sequence - \\u000', testInvalidSequence, () => $`echo.js \u000`);279test('$ handles invalid escape sequence - \\ug', testInvalidSequence, () => $`echo.js \ug`);280test('$ handles invalid escape sequence - \\u{', testInvalidSequence, () => $`echo.js \u{`);281test('$ handles invalid escape sequence - \\u{0000', testInvalidSequence, () => $`echo.js \u{0000`);282test('$ handles invalid escape sequence - \\u{g}', testInvalidSequence, () => $`echo.js \u{g}`);283/* eslint-disable unicorn/no-hex-escape */284test('$ handles invalid escape sequence - \\x', testInvalidSequence, () => $`echo.js \x`);285test('$ handles invalid escape sequence - \\x0', testInvalidSequence, () => $`echo.js \x0`);286test('$ handles invalid escape sequence - \\xgg', testInvalidSequence, () => $`echo.js \xgg`);287/* eslint-enable unicorn/no-hex-escape */288289const testEmptyScript = (t, getSubprocess) => {290 t.throws(getSubprocess, {message: /Template script must not be empty/});291};292293test('$``', testEmptyScript, () => $``);294test('$` `', testEmptyScript, () => $` `);295test('$` ` (2 spaces)', testEmptyScript, () => $` `);296test('$`\\t`', testEmptyScript, () => $` `);297test('$`\\n`', testEmptyScript, () => $`298`);299300const testInvalidExpression = (t, invalidExpression, execaMethod) => {301 const expression = typeof invalidExpression === 'function' ? invalidExpression() : invalidExpression;302 t.throws(303 () => execaMethod`echo.js ${expression}`,304 {message: /in template expression/},305 );306};307308test('$ throws on invalid expression - undefined', testInvalidExpression, undefined, $);309test('$ throws on invalid expression - null', testInvalidExpression, null, $);310test('$ throws on invalid expression - true', testInvalidExpression, true, $);311test('$ throws on invalid expression - {}', testInvalidExpression, {}, $);312test('$ throws on invalid expression - {foo: "bar"}', testInvalidExpression, {foo: 'bar'}, $);313test('$ throws on invalid expression - {stdout: undefined}', testInvalidExpression, {stdout: undefined}, $);314test('$ throws on invalid expression - {stdout: 1}', testInvalidExpression, {stdout: 1}, $);315test('$ throws on invalid expression - Promise.resolve()', testInvalidExpression, Promise.resolve(), $);316test('$ throws on invalid expression - Promise.resolve({stdout: "foo"})', testInvalidExpression, Promise.resolve({foo: 'bar'}), $);317test('$ throws on invalid expression - $', testInvalidExpression, () => $`noop.js`, $);318test('$ throws on invalid expression - $(options).sync', testInvalidExpression, () => $({stdio: 'ignore'}).sync`noop.js`, $);319test('$ throws on invalid expression - [undefined]', testInvalidExpression, [undefined], $);320test('$ throws on invalid expression - [null]', testInvalidExpression, [null], $);321test('$ throws on invalid expression - [true]', testInvalidExpression, [true], $);322test('$ throws on invalid expression - [{}]', testInvalidExpression, [{}], $);323test('$ throws on invalid expression - [{foo: "bar"}]', testInvalidExpression, [{foo: 'bar'}], $);324test('$ throws on invalid expression - [{stdout: undefined}]', testInvalidExpression, [{stdout: undefined}], $);325test('$ throws on invalid expression - [{stdout: 1}]', testInvalidExpression, [{stdout: 1}], $);326test('$ throws on invalid expression - [Promise.resolve()]', testInvalidExpression, [Promise.resolve()], $);327test('$ throws on invalid expression - [Promise.resolve({stdout: "foo"})]', testInvalidExpression, [Promise.resolve({stdout: 'foo'})], $);328test('$ throws on invalid expression - [$]', testInvalidExpression, () => [$`noop.js`], $);329test('$ throws on invalid expression - [$(options).sync]', testInvalidExpression, () => [$({stdio: 'ignore'}).sync`noop.js`], $);
modified:test/fixtures/noop.js+2 added-1 removed
1#!/usr/bin/env node2import process from 'node:process';3import {foobarString} from '../helpers/input.js';44const bytes = process.argv[2];5const bytes = process.argv[2] || foobarString;6console.log(bytes);
modified:test/helpers/input.js+1 added
3 unmodified lines
45export const bufferToUint8Array = buffer => new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);67export const foobarString = 'foobar';8export const foobarArray = ['foo', 'bar'];9export const foobarUint8Array = textEncoder.encode('foobar');10export const foobarArrayBuffer = foobarUint8Array.buffer;11export const foobarUint16Array = new Uint16Array(foobarArrayBuffer);12export const foobarBuffer = Buffer.from(foobarString);
5 unmodified lines
modified:test/command.js+69 added-19 removed
1import {join} from 'node:path';2import test from 'ava';3import {execaCommand, execaCommandSync} from '../index.js';3import {setFixtureDir} from './helpers/fixtures-dir.js';4import {setFixtureDir, FIXTURES_DIR} from './helpers/fixtures-dir.js';5import {QUOTE} from './helpers/verbose.js';67setFixtureDir();8const STDIN_FIXTURE = join(FIXTURES_DIR, 'stdin.js');910test('execaCommand()', async t => {11 const {stdout} = await execaCommand('echo.js foo bar');12 t.is(stdout, 'foo\nbar');13});1415test('execaCommandSync()', t => {16 const {stdout} = execaCommandSync('echo.js foo bar');17 t.is(stdout, 'foo\nbar');18});1920test('execaCommand`...`', async t => {21 const {stdout} = await execaCommand`${'echo.js foo bar'}`;22 t.is(stdout, 'foo\nbar');23});2425test('execaCommandSync`...`', t => {26 const {stdout} = execaCommandSync`${'echo.js foo bar'}`;27 t.is(stdout, 'foo\nbar');28});2930test('execaCommand(options)`...`', async t => {31 const {stdout} = await execaCommand({stripFinalNewline: false})`${'echo.js foo bar'}`;32 t.is(stdout, 'foo\nbar\n');33});3435test('execaCommandSync(options)`...`', t => {36 const {stdout} = execaCommandSync({stripFinalNewline: false})`${'echo.js foo bar'}`;37 t.is(stdout, 'foo\nbar\n');38});3940test('execaCommand(options)()', async t => {41 const {stdout} = await execaCommand({stripFinalNewline: false})('echo.js foo bar');42 t.is(stdout, 'foo\nbar\n');43});4445test('execaCommandSync(options)()', t => {46 const {stdout} = execaCommandSync({stripFinalNewline: false})('echo.js foo bar');47 t.is(stdout, 'foo\nbar\n');48});4950test('execaCommand().pipe(execaCommand())', async t => {51 const {stdout} = await execaCommand('echo.js foo bar').pipe(execaCommand(`node ${STDIN_FIXTURE}`));52 t.is(stdout, 'foo\nbar');53});5455test('execaCommand().pipe(...) does not use execaCommand', async t => {56 const {escapedCommand} = await execaCommand('echo.js foo bar').pipe(`node ${STDIN_FIXTURE}`, {reject: false});57 t.true(escapedCommand.startsWith(`${QUOTE}node `));58});5960test('execaCommand() bound options have lower priority', async t => {61 const {stdout} = await execaCommand({stripFinalNewline: false})('echo.js foo bar', {stripFinalNewline: true});62 t.is(stdout, 'foo\nbar');63});6465test('execaCommandSync() bound options have lower priority', t => {66 const {stdout} = execaCommandSync({stripFinalNewline: false})('echo.js foo bar', {stripFinalNewline: true});67 t.is(stdout, 'foo\nbar');68});6970test('execaCommand() ignores consecutive spaces', async t => {71 const {stdout} = await execaCommand('echo.js foo bar');72 t.is(stdout, 'foo\nbar');73});
17 unmodified lines
91 const {stdout} = await execaCommand(' echo.js foo bar ');92 t.is(stdout, 'foo\nbar');93});9437test('execaCommandSync()', t => {38 const {stdout} = execaCommandSync('echo.js foo bar');39 t.is(stdout, 'foo\nbar');40});4142const testInvalidCommand = (t, execaCommand, invalidArgument) => {95const testInvalidArgsArray = (t, execaMethod) => {96 t.throws(() => {44 execaCommand(invalidArgument);45 }, {message: /First argument must be a string/});97 execaMethod('echo', ['foo']);98 }, {message: /The command and its arguments must be passed as a single string/});99};10048test('execaCommand() must use a string', testInvalidCommand, execaCommand, true);49test('execaCommandSync() must use a string', testInvalidCommand, execaCommandSync, true);50test('execaCommand() must have an argument', testInvalidCommand, execaCommand, undefined);51test('execaCommandSync() must have an argument', testInvalidCommand, execaCommandSync, undefined);101test('execaCommand() must not pass an array of arguments', testInvalidArgsArray, execaCommand);102test('execaCommandSync() must not pass an array of arguments', testInvalidArgsArray, execaCommandSync);10353const testInvalidArgs = (t, secondArgument, execaCommand) => {104const testInvalidArgsTemplate = (t, execaMethod) => {105 t.throws(() => {55 execaCommand('echo', secondArgument);106 // eslint-disable-next-line no-unused-expressions107 execaMethod`echo foo`;108 }, {message: /The command and its arguments must be passed as a single string/});109};11059test('execaCommand() must not pass an array of arguments', testInvalidArgs, [''], execaCommand);60test('execaCommandSync() must not pass an array of arguments', testInvalidArgs, [''], execaCommandSync);61test('execaCommand() must not pass non-options as second argument', testInvalidArgs, '', execaCommand);62test('execaCommandSync() must not pass non-options as second argument', testInvalidArgs, '', execaCommandSync);111test('execaCommand() must not pass an array of arguments with a template string', testInvalidArgsTemplate, execaCommand);112test('execaCommandSync() must not pass an array of arguments with a template string', testInvalidArgsTemplate, execaCommandSync);
modified:test/script.js+30 added-338 removed
1import test from 'ava';2import {isStream} from 'is-stream';3import {$} from '../index.js';4import {setFixtureDir} from './helpers/fixtures-dir.js';5import {foobarString} from './helpers/input.js';67setFixtureDir();88// Workaround since some text editors or IDEs do not allow inputting \r directly9const escapedCall = string => {10 const templates = [string];11 templates.raw = [string];12 return $(templates);13};1415const testScriptStdout = async (t, getSubprocess, expectedStdout) => {16 const {stdout} = await getSubprocess();17 t.is(stdout, expectedStdout);18};1920test('$ executes command', testScriptStdout, () => $`echo.js foo bar`, 'foo\nbar');21test('$ accepts options', testScriptStdout, () => $({stripFinalNewline: true})`noop.js foo`, 'foo');22test('$ allows number interpolation', testScriptStdout, () => $`echo.js 1 ${2}`, '1\n2');23test('$ can concatenate multiple tokens', testScriptStdout, () => $`echo.js ${'foo'}bar${'foo'}`, 'foobarfoo');24test('$ can use newlines and tab indentations', testScriptStdout, () => $`echo.js foo25 bar`, 'foo\nbar');26test('$ can use newlines and space indentations', testScriptStdout, () => $`echo.js foo27 bar`, 'foo\nbar');28test('$ can use Windows newlines and tab indentations', testScriptStdout, () => escapedCall('echo.js foo\r\n\tbar'), 'foo\nbar');29test('$ can use Windows newlines and space indentations', testScriptStdout, () => escapedCall('echo.js foo\r\n bar'), 'foo\nbar');30test('$ does not ignore comments in expressions', testScriptStdout, () => $`echo.js foo31 ${/* This is a comment */''}32 bar33 ${/* This is another comment */''}34 baz35`, 'foo\n\nbar\n\nbaz');36test('$ allows escaping spaces with interpolation', testScriptStdout, () => $`echo.js ${'foo bar'}`, 'foo bar');37test('$ allows escaping spaces in commands with interpolation', testScriptStdout, () => $`${'command with space.js'} foo bar`, 'foo\nbar');38test('$ trims', testScriptStdout, () => $` echo.js foo bar `, 'foo\nbar');39test('$ allows array interpolation', testScriptStdout, () => $`echo.js ${['foo', 'bar']}`, 'foo\nbar');40test('$ allows empty array interpolation', testScriptStdout, () => $`echo.js foo ${[]} bar`, 'foo\nbar');41test('$ allows space escaped values in array interpolation', testScriptStdout, () => $`echo.js ${['foo', 'bar baz']}`, 'foo\nbar baz');42test('$ can concatenate at the end of tokens followed by an array', testScriptStdout, () => $`echo.js foo${['bar', 'foo']}`, 'foobar\nfoo');43test('$ can concatenate at the start of tokens followed by an array', testScriptStdout, () => $`echo.js ${['foo', 'bar']}foo`, 'foo\nbarfoo');44test('$ can concatenate at the start and end of tokens followed by an array', testScriptStdout, () => $`echo.js foo${['bar', 'foo']}bar`, 'foobar\nfoobar');45test('$ handles escaped newlines', testScriptStdout, () => $`echo.js a\46b`, 'ab');47test('$ handles backslashes at end of lines', testScriptStdout, () => $`echo.js a\\48 b`, 'a\\\nb');49test('$ handles double backslashes at end of lines', testScriptStdout, () => $`echo.js a\\\\50 b`, 'a\\\\\nb');51test('$ handles tokens - a', testScriptStdout, () => $`echo.js a`, 'a');52test('$ handles expressions - a', testScriptStdout, () => $`echo.js ${'a'}`, 'a');53test('$ handles tokens - abc', testScriptStdout, () => $`echo.js abc`, 'abc');54test('$ handles expressions - abc', testScriptStdout, () => $`echo.js ${'abc'}`, 'abc');55test('$ handles tokens - ""', testScriptStdout, () => $`echo.js`, '');56test('$ handles expressions - ""', testScriptStdout, () => $`echo.js a ${''} b`, 'a\n\nb');57test('$ splits tokens - ""', testScriptStdout, () => $`echo.js ab`, 'ab');58test('$ splits expressions - ""', testScriptStdout, () => $`echo.js ${'a'}${'b'}`, 'ab');59test('$ concatenates expressions - ""', testScriptStdout, () => $`echo.js a${'b'}c`, 'abc');60test('$ handles tokens - " "', testScriptStdout, () => $`echo.js `, '');61test('$ handles expressions - " "', testScriptStdout, () => $`echo.js ${' '}`, ' ');62test('$ splits tokens - " "', testScriptStdout, () => $`echo.js a b`, 'a\nb');63test('$ splits expressions - " "', testScriptStdout, () => $`echo.js ${'a'} ${'b'}`, 'a\nb');64test('$ concatenates tokens - " "', testScriptStdout, () => $`echo.js a `, 'a');65test('$ concatenates expressions - " "', testScriptStdout, () => $`echo.js ${'a'} `, 'a');66test('$ handles tokens - " " (2 spaces)', testScriptStdout, () => $`echo.js `, '');67test('$ handles expressions - " " (2 spaces)', testScriptStdout, () => $`echo.js ${' '}`, ' ');68test('$ splits tokens - " " (2 spaces)', testScriptStdout, () => $`echo.js a b`, 'a\nb');69test('$ splits expressions - " " (2 spaces)', testScriptStdout, () => $`echo.js ${'a'} ${'b'}`, 'a\nb');70test('$ concatenates tokens - " " (2 spaces)', testScriptStdout, () => $`echo.js a `, 'a');71test('$ concatenates expressions - " " (2 spaces)', testScriptStdout, () => $`echo.js ${'a'} `, 'a');72test('$ handles tokens - " " (3 spaces)', testScriptStdout, () => $`echo.js `, '');73test('$ handles expressions - " " (3 spaces)', testScriptStdout, () => $`echo.js ${' '}`, ' ');74test('$ splits tokens - " " (3 spaces)', testScriptStdout, () => $`echo.js a b`, 'a\nb');75test('$ splits expressions - " " (3 spaces)', testScriptStdout, () => $`echo.js ${'a'} ${'b'}`, 'a\nb');76test('$ concatenates tokens - " " (3 spaces)', testScriptStdout, () => $`echo.js a `, 'a');77test('$ concatenates expressions - " " (3 spaces)', testScriptStdout, () => $`echo.js ${'a'} `, 'a');78test('$ handles tokens - \\t (no escape)', testScriptStdout, () => $`echo.js `, '');79test('$ handles expressions - \\t (no escape)', testScriptStdout, () => $`echo.js ${' '}`, '\t');80test('$ splits tokens - \\t (no escape)', testScriptStdout, () => $`echo.js a b`, 'a\nb');81test('$ splits expressions - \\t (no escape)', testScriptStdout, () => $`echo.js ${'a'} ${'b'}`, 'a\nb');82test('$ concatenates tokens - \\t (no escape)', testScriptStdout, () => $`echo.js a b`, 'a\nb');83test('$ concatenates expressions - \\t (no escape)', testScriptStdout, () => $`echo.js ${'a'} b`, 'a\nb');84test('$ handles tokens - \\t (escape)', testScriptStdout, () => $`echo.js \t`, '\t');85test('$ handles expressions - \\t (escape)', testScriptStdout, () => $`echo.js ${'\t'}`, '\t');86test('$ splits tokens - \\t (escape)', testScriptStdout, () => $`echo.js a\tb`, 'a\tb');87test('$ splits expressions - \\t (escape)', testScriptStdout, () => $`echo.js ${'a'}\t${'b'}`, 'a\tb');88test('$ concatenates tokens - \\t (escape)', testScriptStdout, () => $`echo.js \ta\t b`, '\ta\t\nb');89test('$ concatenates expressions - \\t (escape)', testScriptStdout, () => $`echo.js \t${'a'}\t b`, '\ta\t\nb');90test('$ handles tokens - \\n (no escape)', testScriptStdout, () => $`echo.js91 `, '');92test('$ handles expressions - \\n (no escape)', testScriptStdout, () => $`echo.js ${`93`} `, '\n');94test('$ splits tokens - \\n (no escape)', testScriptStdout, () => $`echo.js a95 b`, 'a\nb');96test('$ splits expressions - \\n (no escape)', testScriptStdout, () => $`echo.js ${'a'}97 ${'b'}`, 'a\nb');98test('$ concatenates tokens - \\n (no escape)', testScriptStdout, () => $`echo.js99a100 b`, 'a\nb');101test('$ concatenates expressions - \\n (no escape)', testScriptStdout, () => $`echo.js102${'a'}103 b`, 'a\nb');104test('$ handles tokens - \\n (escape)', testScriptStdout, () => $`echo.js \n `, '\n');105test('$ handles expressions - \\n (escape)', testScriptStdout, () => $`echo.js ${'\n'} `, '\n');106test('$ splits tokens - \\n (escape)', testScriptStdout, () => $`echo.js a\n b`, 'a\n\nb');107test('$ splits expressions - \\n (escape)', testScriptStdout, () => $`echo.js ${'a'}\n ${'b'}`, 'a\n\nb');108test('$ concatenates tokens - \\n (escape)', testScriptStdout, () => $`echo.js \na\n b`, '\na\n\nb');109test('$ concatenates expressions - \\n (escape)', testScriptStdout, () => $`echo.js \n${'a'}\n b`, '\na\n\nb');110test('$ handles tokens - \\r (no escape)', testScriptStdout, () => escapedCall('echo.js \r '), '');111test('$ splits tokens - \\r (no escape)', testScriptStdout, () => escapedCall('echo.js a\rb'), 'a\nb');112test('$ splits expressions - \\r (no escape)', testScriptStdout, () => escapedCall(`echo.js ${'a'}\r${'b'}`), 'a\nb');113test('$ concatenates tokens - \\r (no escape)', testScriptStdout, () => escapedCall('echo.js \ra\r b'), 'a\nb');114test('$ concatenates expressions - \\r (no escape)', testScriptStdout, () => escapedCall(`echo.js \r${'a'}\r b`), 'a\nb');115test('$ splits tokens - \\r (escape)', testScriptStdout, () => $`echo.js a\r b`, 'a\r\nb');116test('$ splits expressions - \\r (escape)', testScriptStdout, () => $`echo.js ${'a'}\r ${'b'}`, 'a\r\nb');117test('$ concatenates tokens - \\r (escape)', testScriptStdout, () => $`echo.js \ra\r b`, '\ra\r\nb');118test('$ concatenates expressions - \\r (escape)', testScriptStdout, () => $`echo.js \r${'a'}\r b`, '\ra\r\nb');119test('$ handles tokens - \\r\\n (no escape)', testScriptStdout, () => escapedCall('echo.js \r\n '), '');120test('$ splits tokens - \\r\\n (no escape)', testScriptStdout, () => escapedCall('echo.js a\r\nb'), 'a\nb');121test('$ splits expressions - \\r\\n (no escape)', testScriptStdout, () => escapedCall(`echo.js ${'a'}\r\n${'b'}`), 'a\nb');122test('$ concatenates tokens - \\r\\n (no escape)', testScriptStdout, () => escapedCall('echo.js \r\na\r\n b'), 'a\nb');123test('$ concatenates expressions - \\r\\n (no escape)', testScriptStdout, () => escapedCall(`echo.js \r\n${'a'}\r\n b`), 'a\nb');124test('$ handles tokens - \\r\\n (escape)', testScriptStdout, () => $`echo.js \r\n `, '\r\n');125test('$ handles expressions - \\r\\n (escape)', testScriptStdout, () => $`echo.js ${'\r\n'} `, '\r\n');126test('$ splits tokens - \\r\\n (escape)', testScriptStdout, () => $`echo.js a\r\n b`, 'a\r\n\nb');127test('$ splits expressions - \\r\\n (escape)', testScriptStdout, () => $`echo.js ${'a'}\r\n ${'b'}`, 'a\r\n\nb');128test('$ concatenates tokens - \\r\\n (escape)', testScriptStdout, () => $`echo.js \r\na\r\n b`, '\r\na\r\n\nb');129test('$ concatenates expressions - \\r\\n (escape)', testScriptStdout, () => $`echo.js \r\n${'a'}\r\n b`, '\r\na\r\n\nb');130/* eslint-disable no-irregular-whitespace */131test('$ handles expressions - \\f (no escape)', testScriptStdout, () => $`echo.js ${' '}`, '\f');132test('$ splits tokens - \\f (no escape)', testScriptStdout, () => $`echo.js a b`, 'a\fb');133test('$ splits expressions - \\f (no escape)', testScriptStdout, () => $`echo.js ${'a'} ${'b'}`, 'a\fb');134test('$ concatenates tokens - \\f (no escape)', testScriptStdout, () => $`echo.js a b`, '\fa\f\nb');135test('$ concatenates expressions - \\f (no escape)', testScriptStdout, () => $`echo.js ${'a'} b`, '\fa\f\nb');136/* eslint-enable no-irregular-whitespace */137test('$ handles tokens - \\f (escape)', testScriptStdout, () => $`echo.js \f`, '\f');138test('$ handles expressions - \\f (escape)', testScriptStdout, () => $`echo.js ${'\f'}`, '\f');139test('$ splits tokens - \\f (escape)', testScriptStdout, () => $`echo.js a\fb`, 'a\fb');140test('$ splits expressions - \\f (escape)', testScriptStdout, () => $`echo.js ${'a'}\f${'b'}`, 'a\fb');141test('$ concatenates tokens - \\f (escape)', testScriptStdout, () => $`echo.js \fa\f b`, '\fa\f\nb');142test('$ concatenates expressions - \\f (escape)', testScriptStdout, () => $`echo.js \f${'a'}\f b`, '\fa\f\nb');143test('$ handles tokens - \\', testScriptStdout, () => $`echo.js \\`, '\\');144test('$ handles expressions - \\', testScriptStdout, () => $`echo.js ${'\\'}`, '\\');145test('$ splits tokens - \\', testScriptStdout, () => $`echo.js a\\b`, 'a\\b');146test('$ splits expressions - \\', testScriptStdout, () => $`echo.js ${'a'}\\${'b'}`, 'a\\b');147test('$ concatenates tokens - \\', testScriptStdout, () => $`echo.js \\a\\ b`, '\\a\\\nb');148test('$ concatenates expressions - \\', testScriptStdout, () => $`echo.js \\${'a'}\\ b`, '\\a\\\nb');149test('$ handles tokens - \\\\', testScriptStdout, () => $`echo.js \\\\`, '\\\\');150test('$ handles expressions - \\\\', testScriptStdout, () => $`echo.js ${'\\\\'}`, '\\\\');151test('$ splits tokens - \\\\', testScriptStdout, () => $`echo.js a\\\\b`, 'a\\\\b');152test('$ splits expressions - \\\\', testScriptStdout, () => $`echo.js ${'a'}\\\\${'b'}`, 'a\\\\b');153test('$ concatenates tokens - \\\\', testScriptStdout, () => $`echo.js \\\\a\\\\ b`, '\\\\a\\\\\nb');154test('$ concatenates expressions - \\\\', testScriptStdout, () => $`echo.js \\\\${'a'}\\\\ b`, '\\\\a\\\\\nb');155test('$ handles tokens - `', testScriptStdout, () => $`echo.js \``, '`');156test('$ handles expressions - `', testScriptStdout, () => $`echo.js ${'`'}`, '`');157test('$ splits tokens - `', testScriptStdout, () => $`echo.js a\`b`, 'a`b');158test('$ splits expressions - `', testScriptStdout, () => $`echo.js ${'a'}\`${'b'}`, 'a`b');159test('$ concatenates tokens - `', testScriptStdout, () => $`echo.js \`a\` b`, '`a`\nb');160test('$ concatenates expressions - `', testScriptStdout, () => $`echo.js \`${'a'}\` b`, '`a`\nb');161test('$ handles tokens - \\v', testScriptStdout, () => $`echo.js \v`, '\v');162test('$ handles expressions - \\v', testScriptStdout, () => $`echo.js ${'\v'}`, '\v');163test('$ splits tokens - \\v', testScriptStdout, () => $`echo.js a\vb`, 'a\vb');164test('$ splits expressions - \\v', testScriptStdout, () => $`echo.js ${'a'}\v${'b'}`, 'a\vb');165test('$ concatenates tokens - \\v', testScriptStdout, () => $`echo.js \va\v b`, '\va\v\nb');166test('$ concatenates expressions - \\v', testScriptStdout, () => $`echo.js \v${'a'}\v b`, '\va\v\nb');167test('$ handles tokens - \\u2028', testScriptStdout, () => $`echo.js \u2028`, '\u2028');168test('$ handles expressions - \\u2028', testScriptStdout, () => $`echo.js ${'\u2028'}`, '\u2028');169test('$ splits tokens - \\u2028', testScriptStdout, () => $`echo.js a\u2028b`, 'a\u2028b');170test('$ splits expressions - \\u2028', testScriptStdout, () => $`echo.js ${'a'}\u2028${'b'}`, 'a\u2028b');171test('$ concatenates tokens - \\u2028', testScriptStdout, () => $`echo.js \u2028a\u2028 b`, '\u2028a\u2028\nb');172test('$ concatenates expressions - \\u2028', testScriptStdout, () => $`echo.js \u2028${'a'}\u2028 b`, '\u2028a\u2028\nb');173test('$ handles tokens - \\a', testScriptStdout, () => $`echo.js \a`, 'a');174test('$ splits tokens - \\a', testScriptStdout, () => $`echo.js a\ab`, 'aab');175test('$ splits expressions - \\a', testScriptStdout, () => $`echo.js ${'a'}\a${'b'}`, 'aab');176test('$ concatenates tokens - \\a', testScriptStdout, () => $`echo.js \aa\a b`, 'aaa\nb');177test('$ concatenates expressions - \\a', testScriptStdout, () => $`echo.js \a${'a'}\a b`, 'aaa\nb');178test('$ handles tokens - \\cJ', testScriptStdout, () => $`echo.js \cJ`, 'cJ');179test('$ splits tokens - \\cJ', testScriptStdout, () => $`echo.js a\cJb`, 'acJb');180test('$ splits expressions - \\cJ', testScriptStdout, () => $`echo.js ${'a'}\cJ${'b'}`, 'acJb');181test('$ concatenates tokens - \\cJ', testScriptStdout, () => $`echo.js \cJa\cJ b`, 'cJacJ\nb');182test('$ concatenates expressions - \\cJ', testScriptStdout, () => $`echo.js \cJ${'a'}\cJ b`, 'cJacJ\nb');183test('$ handles tokens - \\.', testScriptStdout, () => $`echo.js \.`, '.');184test('$ splits tokens - \\.', testScriptStdout, () => $`echo.js a\.b`, 'a.b');185test('$ splits expressions - \\.', testScriptStdout, () => $`echo.js ${'a'}\.${'b'}`, 'a.b');186test('$ concatenates tokens - \\.', testScriptStdout, () => $`echo.js \.a\. b`, '.a.\nb');187test('$ concatenates expressions - \\.', testScriptStdout, () => $`echo.js \.${'a'}\. b`, '.a.\nb');188/* eslint-disable unicorn/no-hex-escape */189test('$ handles tokens - \\x63', testScriptStdout, () => $`echo.js \x63`, 'c');190test('$ splits tokens - \\x63', testScriptStdout, () => $`echo.js a\x63b`, 'acb');191test('$ splits expressions - \\x63', testScriptStdout, () => $`echo.js ${'a'}\x63${'b'}`, 'acb');192test('$ concatenates tokens - \\x63', testScriptStdout, () => $`echo.js \x63a\x63 b`, 'cac\nb');193test('$ concatenates expressions - \\x63', testScriptStdout, () => $`echo.js \x63${'a'}\x63 b`, 'cac\nb');194/* eslint-enable unicorn/no-hex-escape */195test('$ handles tokens - \\u0063', testScriptStdout, () => $`echo.js \u0063`, 'c');196test('$ splits tokens - \\u0063', testScriptStdout, () => $`echo.js a\u0063b`, 'acb');197test('$ splits expressions - \\u0063', testScriptStdout, () => $`echo.js ${'a'}\u0063${'b'}`, 'acb');198test('$ concatenates tokens - \\u0063', testScriptStdout, () => $`echo.js \u0063a\u0063 b`, 'cac\nb');199test('$ concatenates expressions - \\u0063', testScriptStdout, () => $`echo.js \u0063${'a'}\u0063 b`, 'cac\nb');200test('$ handles tokens - \\u{1}', testScriptStdout, () => $`echo.js \u{1}`, '\u0001');201test('$ splits tokens - \\u{1}', testScriptStdout, () => $`echo.js a\u{1}b`, 'a\u0001b');202test('$ splits expressions - \\u{1}', testScriptStdout, () => $`echo.js ${'a'}\u{1}${'b'}`, 'a\u0001b');203test('$ concatenates tokens - \\u{1}', testScriptStdout, () => $`echo.js \u{1}a\u{1} b`, '\u0001a\u0001\nb');204test('$ concatenates expressions - \\u{1}', testScriptStdout, () => $`echo.js \u{1}${'a'}\u{1} b`, '\u0001a\u0001\nb');205test('$ handles tokens - \\u{63}', testScriptStdout, () => $`echo.js \u{63}`, 'c');206test('$ splits tokens - \\u{63}', testScriptStdout, () => $`echo.js a\u{63}b`, 'acb');207test('$ splits expressions - \\u{63}', testScriptStdout, () => $`echo.js ${'a'}\u{63}${'b'}`, 'acb');208test('$ concatenates tokens - \\u{63}', testScriptStdout, () => $`echo.js \u{63}a\u{63} b`, 'cac\nb');209test('$ concatenates expressions - \\u{63}', testScriptStdout, () => $`echo.js \u{63}${'a'}\u{63} b`, 'cac\nb');210test('$ handles tokens - \\u{063}', testScriptStdout, () => $`echo.js \u{063}`, 'c');211test('$ splits tokens - \\u{063}', testScriptStdout, () => $`echo.js a\u{063}b`, 'acb');212test('$ splits expressions - \\u{063}', testScriptStdout, () => $`echo.js ${'a'}\u{063}${'b'}`, 'acb');213test('$ concatenates tokens - \\u{063}', testScriptStdout, () => $`echo.js \u{063}a\u{063} b`, 'cac\nb');214test('$ concatenates expressions - \\u{063}', testScriptStdout, () => $`echo.js \u{063}${'a'}\u{063} b`, 'cac\nb');215test('$ handles tokens - \\u{0063}', testScriptStdout, () => $`echo.js \u{0063}`, 'c');216test('$ splits tokens - \\u{0063}', testScriptStdout, () => $`echo.js a\u{0063}b`, 'acb');217test('$ splits expressions - \\u{0063}', testScriptStdout, () => $`echo.js ${'a'}\u{0063}${'b'}`, 'acb');218test('$ concatenates tokens - \\u{0063}', testScriptStdout, () => $`echo.js \u{0063}a\u{0063} b`, 'cac\nb');219test('$ concatenates expressions - \\u{0063}', testScriptStdout, () => $`echo.js \u{0063}${'a'}\u{0063} b`, 'cac\nb');220test('$ handles tokens - \\u{00063}', testScriptStdout, () => $`echo.js \u{00063}`, 'c');221test('$ splits tokens - \\u{00063}', testScriptStdout, () => $`echo.js a\u{00063}b`, 'acb');222test('$ splits expressions - \\u{00063}', testScriptStdout, () => $`echo.js ${'a'}\u{00063}${'b'}`, 'acb');223test('$ concatenates tokens - \\u{00063}', testScriptStdout, () => $`echo.js \u{00063}a\u{00063} b`, 'cac\nb');224test('$ concatenates expressions - \\u{00063}', testScriptStdout, () => $`echo.js \u{00063}${'a'}\u{00063} b`, 'cac\nb');225test('$ handles tokens - \\u{000063}', testScriptStdout, () => $`echo.js \u{000063}`, 'c');226test('$ splits tokens - \\u{000063}', testScriptStdout, () => $`echo.js a\u{000063}b`, 'acb');227test('$ splits expressions - \\u{000063}', testScriptStdout, () => $`echo.js ${'a'}\u{000063}${'b'}`, 'acb');228test('$ concatenates tokens - \\u{000063}', testScriptStdout, () => $`echo.js \u{000063}a\u{000063} b`, 'cac\nb');229test('$ concatenates expressions - \\u{000063}', testScriptStdout, () => $`echo.js \u{000063}${'a'}\u{000063} b`, 'cac\nb');230test('$ handles tokens - \\u{0000063}', testScriptStdout, () => $`echo.js \u{0000063}`, 'c');231test('$ splits tokens - \\u{0000063}', testScriptStdout, () => $`echo.js a\u{0000063}b`, 'acb');232test('$ splits expressions - \\u{0000063}', testScriptStdout, () => $`echo.js ${'a'}\u{0000063}${'b'}`, 'acb');233test('$ concatenates tokens - \\u{0000063}', testScriptStdout, () => $`echo.js \u{0000063}a\u{0000063} b`, 'cac\nb');234test('$ concatenates expressions - \\u{0000063}', testScriptStdout, () => $`echo.js \u{0000063}${'a'}\u{0000063} b`, 'cac\nb');235test('$ handles tokens - \\u{0063}}', testScriptStdout, () => $`echo.js \u{0063}}`, 'c}');236test('$ splits tokens - \\u{0063}}', testScriptStdout, () => $`echo.js a\u{0063}}b`, 'ac}b');237test('$ splits expressions - \\u{0063}}', testScriptStdout, () => $`echo.js ${'a'}\u{0063}}${'b'}`, 'ac}b');238test('$ concatenates tokens - \\u{0063}}', testScriptStdout, () => $`echo.js \u{0063}}a\u{0063}} b`, 'c}ac}\nb');239test('$ concatenates expressions - \\u{0063}}', testScriptStdout, () => $`echo.js \u{0063}}${'a'}\u{0063}} b`, 'c}ac}\nb');240241const testScriptErrorStdout = async (t, getSubprocess) => {242 t.throws(getSubprocess, {message: /null bytes/});243};244245test('$ handles tokens - \\0', testScriptErrorStdout, () => $`echo.js \0`);246test('$ splits tokens - \\0', testScriptErrorStdout, () => $`echo.js a\0b`);247test('$ splits expressions - \\0', testScriptErrorStdout, () => $`echo.js ${'a'}\0${'b'}`);248test('$ concatenates tokens - \\0', testScriptErrorStdout, () => $`echo.js \0a\0 b`);249test('$ concatenates expressions - \\0', testScriptErrorStdout, () => $`echo.js \0${'a'}\0 b`);2509const testScriptStdoutSync = (t, getSubprocess, expectedStdout) => {10 const {stdout} = getSubprocess();11 t.is(stdout, expectedStdout);12};13256test('$.sync', testScriptStdoutSync, () => $.sync`echo.js foo bar`, 'foo\nbar');257test('$.sync can be called $.s', testScriptStdoutSync, () => $.s`echo.js foo bar`, 'foo\nbar');258test('$.sync accepts options', testScriptStdoutSync, () => $({stripFinalNewline: true}).sync`noop.js foo`, 'foo');14test('$.sync`...`', testScriptStdoutSync, () => $.sync`echo.js foo bar`, 'foo\nbar');15test('$.s`...`', testScriptStdoutSync, () => $.s`echo.js foo bar`, 'foo\nbar');16test('$(options).sync`...`', testScriptStdoutSync, () => $({stripFinalNewline: false}).sync`echo.js ${foobarString}`, `${foobarString}\n`);17test('$.sync(options)`...`', testScriptStdoutSync, () => $.sync({stripFinalNewline: false})`echo.js ${foobarString}`, `${foobarString}\n`);18260const testReturnInterpolate = async (t, getSubprocess, expectedStdout, options = {}) => {261 const foo = await $(options)`echo.js foo`;262 const {stdout} = await getSubprocess(foo);263 t.is(stdout, expectedStdout);264};19test('Cannot call $.sync.sync', t => {20 t.false('sync' in $.sync);21});22266test('$ allows execa return value interpolation', testReturnInterpolate, foo => $`echo.js ${foo} bar`, 'foo\nbar');267test('$ allows execa return value buffer interpolation', testReturnInterpolate, foo => $`echo.js ${foo} bar`, 'foo\nbar', {encoding: 'buffer'});268test('$ allows execa return value array interpolation', testReturnInterpolate, foo => $`echo.js ${[foo, 'bar']}`, 'foo\nbar');269test('$ allows execa return value buffer array interpolation', testReturnInterpolate, foo => $`echo.js ${[foo, 'bar']}`, 'foo\nbar', {encoding: 'buffer'});23test('Cannot call $.sync(options).sync', t => {24 t.false('sync' in $.sync({}));25});26271const testReturnInterpolateSync = (t, getSubprocess, expectedStdout, options = {}) => {272 const foo = $(options).sync`echo.js foo`;273 const {stdout} = getSubprocess(foo);274 t.is(stdout, expectedStdout);275};27test('$(options)() stdin defaults to "inherit"', async t => {28 const {stdout} = await $({input: foobarString})('stdin-script.js');29 t.is(stdout, foobarString);30});31277test('$.sync allows execa return value interpolation', testReturnInterpolateSync, foo => $.sync`echo.js ${foo} bar`, 'foo\nbar');278test('$.sync allows execa return value buffer interpolation', testReturnInterpolateSync, foo => $.sync`echo.js ${foo} bar`, 'foo\nbar', {encoding: 'buffer'});279test('$.sync allows execa return value array interpolation', testReturnInterpolateSync, foo => $.sync`echo.js ${[foo, 'bar']}`, 'foo\nbar');280test('$.sync allows execa return value buffer array interpolation', testReturnInterpolateSync, foo => $.sync`echo.js ${[foo, 'bar']}`, 'foo\nbar', {encoding: 'buffer'});281282const testInvalidSequence = (t, getSubprocess) => {283 t.throws(getSubprocess, {message: /Invalid backslash sequence/});284};285286test('$ handles invalid escape sequence - \\1', testInvalidSequence, () => $`echo.js \1`);287test('$ handles invalid escape sequence - \\u', testInvalidSequence, () => $`echo.js \u`);288test('$ handles invalid escape sequence - \\u0', testInvalidSequence, () => $`echo.js \u0`);289test('$ handles invalid escape sequence - \\u00', testInvalidSequence, () => $`echo.js \u00`);290test('$ handles invalid escape sequence - \\u000', testInvalidSequence, () => $`echo.js \u000`);291test('$ handles invalid escape sequence - \\ug', testInvalidSequence, () => $`echo.js \ug`);292test('$ handles invalid escape sequence - \\u{', testInvalidSequence, () => $`echo.js \u{`);293test('$ handles invalid escape sequence - \\u{0000', testInvalidSequence, () => $`echo.js \u{0000`);294test('$ handles invalid escape sequence - \\u{g}', testInvalidSequence, () => $`echo.js \u{g}`);295/* eslint-disable unicorn/no-hex-escape */296test('$ handles invalid escape sequence - \\x', testInvalidSequence, () => $`echo.js \x`);297test('$ handles invalid escape sequence - \\x0', testInvalidSequence, () => $`echo.js \x0`);298test('$ handles invalid escape sequence - \\xgg', testInvalidSequence, () => $`echo.js \xgg`);299/* eslint-enable unicorn/no-hex-escape */300301const testEmptyScript = (t, getSubprocess) => {302 t.throws(getSubprocess, {message: /Template script must not be empty/});303};304305test('$``', testEmptyScript, () => $``);306test('$` `', testEmptyScript, () => $` `);307test('$` ` (2 spaces)', testEmptyScript, () => $` `);308test('$`\\t`', testEmptyScript, () => $` `);309test('$`\\n`', testEmptyScript, () => $`310`);311312test('$.sync must be used after options binding, not before', t => {313 t.throws(() => $.sync({})`noop.js`, {message: /Please use/});32test('$.sync(options)() stdin defaults to "inherit"', t => {33 const {stdout} = $.sync({input: foobarString})('stdin-script.js');34 t.is(stdout, foobarString);35});36316test('$ must only use options or templates', t => {317 t.throws(() => $(true)`noop.js`, {message: /Please use either/});37test('$(options).sync() stdin defaults to "inherit"', t => {38 const {stdout} = $({input: foobarString}).sync('stdin-script.js');39 t.is(stdout, foobarString);40});41320test('$.sync must only templates', t => {321 t.throws(() => $.sync(true)`noop.js`, {message: /A template string must be used/});42test('$(options)`...` stdin defaults to "inherit"', async t => {43 const {stdout} = await $({input: foobarString})`stdin-script.js`;44 t.is(stdout, foobarString);45});46324const testInvalidExpression = (t, invalidExpression, execaMethod) => {325 const expression = typeof invalidExpression === 'function' ? invalidExpression() : invalidExpression;326 t.throws(327 () => execaMethod`echo.js ${expression}`,328 {message: /in template expression/},329 );330};331332test('$ throws on invalid expression - undefined', testInvalidExpression, undefined, $);333test('$ throws on invalid expression - null', testInvalidExpression, null, $);334test('$ throws on invalid expression - true', testInvalidExpression, true, $);335test('$ throws on invalid expression - {}', testInvalidExpression, {}, $);336test('$ throws on invalid expression - {foo: "bar"}', testInvalidExpression, {foo: 'bar'}, $);337test('$ throws on invalid expression - {stdout: undefined}', testInvalidExpression, {stdout: undefined}, $);338test('$ throws on invalid expression - {stdout: 1}', testInvalidExpression, {stdout: 1}, $);339test('$ throws on invalid expression - Promise.resolve()', testInvalidExpression, Promise.resolve(), $);340test('$ throws on invalid expression - Promise.resolve({stdout: "foo"})', testInvalidExpression, Promise.resolve({foo: 'bar'}), $);341test('$ throws on invalid expression - $', testInvalidExpression, () => $`noop.js`, $);342test('$ throws on invalid expression - $(options).sync', testInvalidExpression, () => $({stdio: 'ignore'}).sync`noop.js`, $);343test('$ throws on invalid expression - [undefined]', testInvalidExpression, [undefined], $);344test('$ throws on invalid expression - [null]', testInvalidExpression, [null], $);345test('$ throws on invalid expression - [true]', testInvalidExpression, [true], $);346test('$ throws on invalid expression - [{}]', testInvalidExpression, [{}], $);347test('$ throws on invalid expression - [{foo: "bar"}]', testInvalidExpression, [{foo: 'bar'}], $);348test('$ throws on invalid expression - [{stdout: undefined}]', testInvalidExpression, [{stdout: undefined}], $);349test('$ throws on invalid expression - [{stdout: 1}]', testInvalidExpression, [{stdout: 1}], $);350test('$ throws on invalid expression - [Promise.resolve()]', testInvalidExpression, [Promise.resolve()], $);351test('$ throws on invalid expression - [Promise.resolve({stdout: "foo"})]', testInvalidExpression, [Promise.resolve({stdout: 'foo'})], $);352test('$ throws on invalid expression - [$]', testInvalidExpression, () => [$`noop.js`], $);353test('$ throws on invalid expression - [$(options).sync]', testInvalidExpression, () => [$({stdio: 'ignore'}).sync`noop.js`], $);354355test('$ stdin defaults to "inherit"', async t => {356 const {stdout} = await $({input: 'foo'})`stdin-script.js`;357 t.is(stdout, 'foo');47test('$.sync(options)`...` stdin defaults to "inherit"', t => {48 const {stdout} = $.sync({input: foobarString})`stdin-script.js`;49 t.is(stdout, foobarString);50});51360test('$.sync stdin defaults to "inherit"', t => {361 const {stdout} = $({input: 'foo'}).sync`stdin-script.js`;362 t.is(stdout, 'foo');52test('$(options).sync`...` stdin defaults to "inherit"', t => {53 const {stdout} = $({input: foobarString}).sync`stdin-script.js`;54 t.is(stdout, foobarString);55});5657test('$ stdin has no default value when stdio is set', t => {58 t.true(isStream($({stdio: 'pipe'})`noop.js`.stdin));
1 unmodified line
modified:index.d.ts+209 added-213 removed
950 unmodified lines
951952 This can be called multiple times to chain a series of subprocesses.953954 Multiple subprocesses can be piped to the same subprocess. Conversely, the same subprocess can be piped to multiple other subprocesses.955956 This is usually the preferred method to pipe subprocesses.955 */956 pipe<OptionsType extends Options & PipeOptions = {}>(957 file: string | URL,958 arguments?: readonly string[],
5 unmodified lines
964 ): Promise<ExecaResult<OptionsType>> & PipableSubprocess;965966 /**967 Like `.pipe(file, arguments?, options?)` but using a `command` template string instead. This follows the same syntax as `$`.970971 This is the preferred method to pipe subprocesses when using `$`.968 */969 pipe(templates: TemplateStringsArray, ...expressions: readonly TemplateExpression[]):970 Promise<ExecaResult<{}>> & PipableSubprocess;971 pipe<OptionsType extends Options & PipeOptions = {}>(options: OptionsType):
135 unmodified lines
1107export type ExecaSubprocess<OptionsType extends Options = Options> = ChildProcess &1108ExecaResultPromise<OptionsType> &1109Promise<ExecaResult<OptionsType>>;11101111type TemplateExpression = string | number | CommonResultInstance1112| Array<string | number | CommonResultInstance>;11131114type TemplateString = [TemplateStringsArray, ...readonly TemplateExpression[]];1115type SimpleTemplateString = [TemplateStringsArray, string?];11161117type Execa<OptionsType extends Options> = {1118 <NewOptionsType extends Options = {}>(options: NewOptionsType): Execa<OptionsType & NewOptionsType>;11191120 (...templateString: TemplateString): ExecaSubprocess<OptionsType>;11211122 <NewOptionsType extends Options = {}>(1123 file: string | URL,1124 arguments?: readonly string[],1125 options?: NewOptionsType,1126 ): ExecaSubprocess<OptionsType & NewOptionsType>;11271128 <NewOptionsType extends Options = {}>(1129 file: string | URL,1130 options?: NewOptionsType,1131 ): ExecaSubprocess<OptionsType & NewOptionsType>;1132};11331134/**1135Executes a command using `file ...arguments`.11361118Arguments are automatically escaped. They can contain any character, including spaces.1137Arguments are automatically escaped. They can contain any character, including spaces, tabs and newlines.11381120This is the preferred method when executing single commands.1139When `command` is a template string, it includes both the `file` and its `arguments`.11401141The `command` template string can inject any `${value}` with the following types: string, number, `subprocess` or an array of those types. For example: `` execa`echo one ${'two'} ${3} ${['four', 'five']}` ``. For `${subprocess}`, the subprocess's `stdout` is used.11421143When `command` is a template string, arguments can contain any character, but spaces, tabs and newlines must use `${}` like `` execa`echo ${'has space'}` ``.11441145The `command` template string can use multiple lines and indentation.11461147`execa(options)` can be used to return a new instance of Execa but with different default `options`. Consecutive calls are merged to previous ones. This allows setting global options or sharing options between multiple commands.11481149@param file - The program/script to execute, as a string or file URL1150@param arguments - Arguments to pass to `file` on execution.1151@returns An `ExecaSubprocess` that is both:1152- a `Promise` resolving or rejecting with a `subprocessResult`.
8 unmodified lines
1161console.log(stdout);1162//=> 'unicorns'1163```11641165@example <caption>Global/shared options</caption>1166```1167import {execa as execa_} from 'execa';11681169const execa = execa_({verbose: 'full'});11701171await execa('echo', ['unicorns']);1172//=> 'unicorns'1173```11741175@example <caption>Template string interface</caption>11761177```1178import {execa} from 'execa';11791180const arg = 'unicorns'1181const {stdout} = await execa`echo ${arg} & rainbows!`;1182console.log(stdout);1183//=> 'unicorns & rainbows!'1184```11851186@example <caption>Template string multiple arguments</caption>11871188```1189import {execa} from 'execa';11901191const args = ['unicorns', '&', 'rainbows!'];1192const {stdout} = await execa`echo ${args}`;1193console.log(stdout);1194//=> 'unicorns & rainbows!'1195```11961197@example <caption>Template string with options</caption>11981199```1200import {execa} from 'execa';12011202await execa({verbose: 'full'})`echo unicorns`;1203//=> 'unicorns'1204```12051206@example <caption>Redirect output to a file</caption>1207```1208import {execa} from 'execa';1209
36 unmodified lines
1246console.log(stdout);1247//=> 'unicorns'1248```12491250@example <caption>Pipe with template strings</caption>1251```1252import {execa} from 'execa';12531254await execa`npm run build`1255 .pipe`sort`1256 .pipe`head -n2`;1257```12581259@example <caption>Iterate over output lines</caption>1260```1261import {execa} from 'execa';12621263for await (const line of execa`npm run build`)) {1264 if (line.includes('ERROR')) {1265 console.log(line);1266 }1267}1268```12691270@example <caption>Handling errors</caption>1271```1272import {execa} from 'execa';1273
35 unmodified lines
1309 \*\/1310}1311```1312*/1225export function execa<OptionsType extends Options = {}>(1226 file: string | URL,1227 arguments?: readonly string[],1228 options?: OptionsType,1229): ExecaSubprocess<OptionsType>;1230export function execa<OptionsType extends Options = {}>(1231 file: string | URL,1232 options?: OptionsType,1233): ExecaSubprocess<OptionsType>;1313declare const execa: Execa<{}>;13141315type ExecaSync<OptionsType extends SyncOptions> = {1316 <NewOptionsType extends SyncOptions = {}>(options: NewOptionsType): ExecaSync<OptionsType & NewOptionsType>;13171318 (...templateString: TemplateString): ExecaSyncResult<OptionsType>;13191320 <NewOptionsType extends SyncOptions = {}>(1321 file: string | URL,1322 arguments?: readonly string[],1323 options?: NewOptionsType,1324 ): ExecaSyncResult<OptionsType & NewOptionsType>;13251326 <NewOptionsType extends SyncOptions = {}>(1327 file: string | URL,1328 options?: NewOptionsType,1329 ): ExecaSyncResult<OptionsType & NewOptionsType>;1330};13311332/**1333Same as `execa()` but synchronous.13341238Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `ipc`, `serialization`, `cancelSignal`, `lines` and `verbose: 'full'`. Also, the `stdin`, `stdout`, `stderr`, `stdio` and `input` options cannot be an array, an iterable, a transform or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.12391335Returns or throws a `subprocessResult`. The `subprocess` is not returned: its methods and properties are not available. This includes [`.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal), [`.pid`](https://nodejs.org/api/child_process.html#subprocesspid), `.pipe()` and the [`.stdin`/`.stdout`/`.stderr`](https://nodejs.org/api/child_process.html#subprocessstdout) streams.13361337Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `ipc`, `serialization`, `cancelSignal`, `lines` and `verbose: 'full'`. Also, the `stdin`, `stdout`, `stderr`, `stdio` and `input` options cannot be an array, an iterable, a transform or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.13381339@param file - The program/script to execute, as a string or file URL1340@param arguments - Arguments to pass to `file` on execution.1341@returns A `subprocessResult` object1342@throws A `subprocessResult` error
49 unmodified lines
1392 \*\/1393}1394```1395*/1299export function execaSync<OptionsType extends SyncOptions = {}>(1300 file: string | URL,1301 arguments?: readonly string[],1302 options?: OptionsType,1303): ExecaSyncResult<OptionsType>;1304export function execaSync<OptionsType extends SyncOptions = {}>(1305 file: string | URL,1306 options?: OptionsType,1307): ExecaSyncResult<OptionsType>;1396declare const execaSync: ExecaSync<{}>;13971398type ExecaCommand<OptionsType extends Options> = {1399 <NewOptionsType extends Options = {}>(options: NewOptionsType): ExecaCommand<OptionsType & NewOptionsType>;14001401 (...templateString: SimpleTemplateString): ExecaSubprocess<OptionsType>;14021403 <NewOptionsType extends Options = {}>(1404 command: string,1405 options?: NewOptionsType,1406 ): ExecaSubprocess<OptionsType & NewOptionsType>;1407};14081409/**1310Executes a command. The `command` string includes both the `file` and its `arguments`.1410`execa` with the template string syntax allows the `file` or the `arguments` to be user-defined (by injecting them with `${}`). However, if _both_ the `file` and the `arguments` are user-defined, _and_ those are supplied as a single string, then `execaCommand(command)` must be used instead.14111312Arguments are automatically escaped. They can contain any character, but spaces must be escaped with a backslash like `execaCommand('echo has\\ space')`.1412This is only intended for very specific cases, such as a REPL. This should be avoided otherwise.14131314This is the preferred method when executing a user-supplied `command` string, such as in a REPL.1414Just like `execa()`, this can bind options. It can also be run synchronously using `execaCommandSync()`.14151416Arguments are automatically escaped. They can contain any character, but spaces must be escaped with a backslash like `execaCommand('echo has\\ space')`.14171418@param command - The program/script to execute and its arguments.1419@returns An `ExecaSubprocess` that is both:1420- a `Promise` resolving or rejecting with a `subprocessResult`.1421- a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with some additional methods and properties.
7 unmodified lines
1429console.log(stdout);1430//=> 'unicorns'1431```1432*/1331export function execaCommand<OptionsType extends Options = {}>(1332 command: string,1333 options?: OptionsType1334): ExecaSubprocess<OptionsType>;1433declare const execaCommand: ExecaCommand<{}>;14341435type ExecaCommandSync<OptionsType extends SyncOptions> = {1436 <NewOptionsType extends SyncOptions = {}>(options: NewOptionsType): ExecaCommandSync<OptionsType & NewOptionsType>;14371438 (...templateString: SimpleTemplateString): ExecaSyncResult<OptionsType>;14391440 <NewOptionsType extends SyncOptions = {}>(1441 command: string,1442 options?: NewOptionsType,1443 ): ExecaSyncResult<OptionsType & NewOptionsType>;1444};14451446/**1447Same as `execaCommand()` but synchronous.14481339Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `ipc`, `serialization`, `cancelSignal`, `lines` and `verbose: 'full'`. Also, the `stdin`, `stdout`, `stderr`, `stdio` and `input` options cannot be an array, an iterable, a transform or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.13401449Returns or throws a `subprocessResult`. The `subprocess` is not returned: its methods and properties are not available. This includes [`.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal), [`.pid`](https://nodejs.org/api/child_process.html#subprocesspid), `.pipe()` and the [`.stdin`/`.stdout`/`.stderr`](https://nodejs.org/api/child_process.html#subprocessstdout) streams.14501451Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `ipc`, `serialization`, `cancelSignal`, `lines` and `verbose: 'full'`. Also, the `stdin`, `stdout`, `stderr`, `stdio` and `input` options cannot be an array, an iterable, a transform or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.14521453@param command - The program/script to execute and its arguments.1454@returns A `subprocessResult` object1455@throws A `subprocessResult` error1456
5 unmodified lines
1462console.log(stdout);1463//=> 'unicorns'1464```1465*/1356export function execaCommandSync<OptionsType extends SyncOptions = {}>(1357 command: string,1358 options?: OptionsType1359): ExecaSyncResult<OptionsType>;1466declare const execaCommandSync: ExecaCommandSync<{}>;14671361type TemplateExpression = string | number | CommonResultInstance1362| Array<string | number | CommonResultInstance>;1468type ExecaScriptCommon<OptionsType extends CommonOptions> = {1469 <NewOptionsType extends CommonOptions = {}>(options: NewOptionsType): ExecaScript<OptionsType & NewOptionsType>;14701364type Execa$<OptionsType extends CommonOptions = {}> = {1365 /**1366 Returns a new instance of `$` but with different default `options`. Consecutive calls are merged to previous ones.1471 (...templateString: TemplateString): ExecaSubprocess<StricterOptions<OptionsType, Options>>;14721368 This can be used to either:1369 - Set options for a specific command: `` $(options)`command` ``1370 - Share options for multiple commands: `` const $$ = $(options); $$`command`; $$`otherCommand` ``1473 <NewOptionsType extends Options = {}>(1474 file: string | URL,1475 arguments?: readonly string[],1476 options?: NewOptionsType,1477 ): ExecaSubprocess<OptionsType & NewOptionsType>;14781372 @param options - Options to set1373 @returns A new instance of `$` with those `options` set1479 <NewOptionsType extends Options = {}>(1480 file: string | URL,1481 options?: NewOptionsType,1482 ): ExecaSubprocess<OptionsType & NewOptionsType>;1483};14841375 @example1376 ```1377 import {$} from 'execa';1485type ExecaScriptSync<OptionsType extends CommonOptions> = {1486 <NewOptionsType extends SyncOptions = {}>(options: NewOptionsType): ExecaScriptSync<OptionsType & NewOptionsType>;14871379 const $$ = $({stdio: 'inherit'});1488 (...templateString: TemplateString): ExecaSyncResult<StricterOptions<OptionsType, SyncOptions>>;14891381 await $$`echo unicorns`;1382 //=> 'unicorns'1490 <NewOptionsType extends SyncOptions = {}>(1491 file: string | URL,1492 arguments?: readonly string[],1493 options?: NewOptionsType,1494 ): ExecaSyncResult<OptionsType & NewOptionsType>;14951384 await $$`echo rainbows`;1385 //=> 'rainbows'1386 ```1387 */1388 <NewOptionsType extends CommonOptions = {}>1389 (options: NewOptionsType): Execa$<OptionsType & NewOptionsType>;13901391 (templates: TemplateStringsArray, ...expressions: readonly TemplateExpression[]):1392 ExecaSubprocess<StricterOptions<OptionsType, Options>> & PipableSubprocess;13931394 /**1395 Same as $\`command\` but synchronous.13961397 Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `ipc`, `serialization`, `cancelSignal`, `lines` and `verbose: 'full'`. Also, the `stdin`, `stdout`, `stderr`, `stdio` and `input` options cannot be an array, an iterable, a transform or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.13981399 Returns or throws a `subprocessResult`. The `subprocess` is not returned: its methods and properties are not available. This includes [`.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal), [`.pid`](https://nodejs.org/api/child_process.html#subprocesspid), `.pipe()` and the [`.stdin`/`.stdout`/`.stderr`](https://nodejs.org/api/child_process.html#subprocessstdout) streams.14001401 @returns A `subprocessResult` object1402 @throws A `subprocessResult` error14031404 @example <caption>Basic</caption>1405 ```1406 import {$} from 'execa';14071408 const branch = $.sync`git branch --show-current`;1409 $.sync`dep deploy --branch=${branch}`;1410 ```14111412 @example <caption>Multiple arguments</caption>1413 ```1414 import {$} from 'execa';14151416 const args = ['unicorns', '&', 'rainbows!'];1417 const {stdout} = $.sync`echo ${args}`;1418 console.log(stdout);1419 //=> 'unicorns & rainbows!'1420 ```14211422 @example <caption>With options</caption>1423 ```1424 import {$} from 'execa';14251426 $.sync({stdio: 'inherit'})`echo unicorns`;1427 //=> 'unicorns'1428 ```14291430 @example <caption>Shared options</caption>1431 ```1432 import {$} from 'execa';14331434 const $$ = $({stdio: 'inherit'});14351436 $$.sync`echo unicorns`;1437 //=> 'unicorns'14381439 $$.sync`echo rainbows`;1440 //=> 'rainbows'1441 ```1442 */1443 sync(1444 templates: TemplateStringsArray,1445 ...expressions: readonly TemplateExpression[]1446 ): ExecaSyncResult<StricterOptions<OptionsType, SyncOptions>>;14471448 /**1449 Same as $\`command\` but synchronous.14501451 Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `ipc`, `serialization`, `cancelSignal`, `lines` and `verbose: 'full'`. Also, the `stdin`, `stdout`, `stderr`, `stdio` and `input` options cannot be an array, an iterable, a transform or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.14521453 Returns or throws a `subprocessResult`. The `subprocess` is not returned: its methods and properties are not available. This includes [`.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal), [`.pid`](https://nodejs.org/api/child_process.html#subprocesspid), `.pipe()` and the [`.stdin`/`.stdout`/`.stderr`](https://nodejs.org/api/child_process.html#subprocessstdout) streams.14541455 @returns A `subprocessResult` object1456 @throws A `subprocessResult` error14571458 @example <caption>Basic</caption>1459 ```1460 import {$} from 'execa';14611462 const branch = $.s`git branch --show-current`;1463 $.s`dep deploy --branch=${branch}`;1464 ```14651466 @example <caption>Multiple arguments</caption>1467 ```1468 import {$} from 'execa';14691470 const args = ['unicorns', '&', 'rainbows!'];1471 const {stdout} = $.s`echo ${args}`;1472 console.log(stdout);1473 //=> 'unicorns & rainbows!'1474 ```14751476 @example <caption>With options</caption>1477 ```1478 import {$} from 'execa';14791480 $.s({stdio: 'inherit'})`echo unicorns`;1481 //=> 'unicorns'1482 ```14831484 @example <caption>Shared options</caption>1485 ```1486 import {$} from 'execa';14871488 const $$ = $({stdio: 'inherit'});14891490 $$.s`echo unicorns`;1491 //=> 'unicorns'14921493 $$.s`echo rainbows`;1494 //=> 'rainbows'1495 ```1496 */1497 s(1498 templates: TemplateStringsArray,1499 ...expressions: readonly TemplateExpression[]1500 ): ExecaSyncResult<StricterOptions<OptionsType, SyncOptions>>;1496 <NewOptionsType extends SyncOptions = {}>(1497 file: string | URL,1498 options?: NewOptionsType,1499 ): ExecaSyncResult<OptionsType & NewOptionsType>;1500};15011502type ExecaScript<OptionsType extends CommonOptions> = {1503 sync: ExecaScriptSync<OptionsType>;1504 s: ExecaScriptSync<OptionsType>;1505} & ExecaScriptCommon<OptionsType>;15061507/**1504Executes a command. The `command` string includes both the `file` and its `arguments`.1508Same as `execa()` but using the `stdin: 'inherit'` and `preferLocal: true` options.15091506Arguments are automatically escaped. They can contain any character, but spaces, tabs and newlines must use `${}` like `` $`echo ${'has space'}` ``.1510Just like `execa()`, this can use the template string syntax or bind options. It can also be run synchronously using `$.sync()` or `$.s()`.15111512This is the preferred method when executing multiple commands in a script file.15131510The `command` string can inject any `${value}` with the following types: string, number, `subprocess` or an array of those types. For example: `` $`echo one ${'two'} ${3} ${['four', 'five']}` ``. For `${subprocess}`, the subprocess's `stdout` is used.15111514@returns An `ExecaSubprocess` that is both:1515 - a `Promise` resolving or rejecting with a `subprocessResult`.1516 - a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with some additional methods and properties.1517@throws A `subprocessResult` error
5 unmodified lines
1523const branch = await $`git branch --show-current`;1524await $`dep deploy --branch=${branch}`;1525```15261525@example <caption>Multiple arguments</caption>1527@example <caption>Verbose mode</caption>1528```1527import {$} from 'execa';1529> node file.js1530unicorns1531rainbows15321529const args = ['unicorns', '&', 'rainbows!'];1530const {stdout} = await $`echo ${args}`;1531console.log(stdout);1532//=> 'unicorns & rainbows!'1533> NODE_DEBUG=execa node file.js1534[19:49:00.360] [0] $ echo unicorns1535unicorns1536[19:49:00.383] [0] √ (done in 23ms)1537[19:49:00.383] [1] $ echo rainbows1538rainbows1539[19:49:00.404] [1] √ (done in 21ms)1540```1541*/1542export const $: ExecaScript<{}>;15431535@example <caption>With options</caption>1536```1537import {$} from 'execa';1544type ExecaNode<OptionsType extends Options> = {1545 <NewOptionsType extends Options = {}>(options: NewOptionsType): ExecaNode<OptionsType & NewOptionsType>;15461539await $({stdio: 'inherit'})`echo unicorns`;1540//=> 'unicorns'1541```1547 (...templateString: TemplateString): ExecaSubprocess<OptionsType>;15481543@example <caption>Shared options</caption>1544```1545import {$} from 'execa';1549 <NewOptionsType extends Options = {}>(1550 scriptPath: string | URL,1551 arguments?: readonly string[],1552 options?: NewOptionsType,1553 ): ExecaSubprocess<OptionsType & NewOptionsType>;15541547const $$ = $({stdio: 'inherit'});1555 <NewOptionsType extends Options = {}>(1556 scriptPath: string | URL,1557 options?: NewOptionsType,1558 ): ExecaSubprocess<OptionsType & NewOptionsType>;1559};15601549await $$`echo unicorns`;1550//=> 'unicorns'15511552await $$`echo rainbows`;1553//=> 'rainbows'1554```1555*/1556export const $: Execa$;15571561/**1559Same as `execa()` but using the `node` option.15601562Same as `execa()` but using the `node: true` option.1563Executes a Node.js file using `node scriptPath ...arguments`.15641565Just like `execa()`, this can use the template string syntax or bind options.15661567This is the preferred method when executing Node.js files.15681569@param scriptPath - Node.js script to execute, as a string or file URL1570@param arguments - Arguments to pass to `scriptPath` on execution.
3 unmodified lines
1574@throws A `subprocessResult` error15751576@example1577```1574import {execa} from 'execa';1578import {execaNode} from 'execa';15791580await execaNode('scriptPath', ['argument']);1581```1582*/1579export function execaNode<OptionsType extends Options = {}>(1580 scriptPath: string | URL,1581 arguments?: readonly string[],1582 options?: OptionsType1583): ExecaSubprocess<OptionsType>;1584export function execaNode<OptionsType extends Options = {}>(1585 scriptPath: string | URL,1586 options?: OptionsType1587): ExecaSubprocess<OptionsType>;1583export const execaNode: ExecaNode<{}>;
modified:index.js+12 added-5 removed
1export {execa} from './lib/async.js';2export {execaSync} from './lib/sync.js';3export {execaCommand, execaCommandSync} from './lib/command.js';4export {execaNode} from './lib/arguments/node.js';5export {$} from './lib/script.js';1import {createExeca} from './lib/arguments/create.js';2import {mapCommandAsync, mapCommandSync} from './lib/command.js';3import {mapNode} from './lib/arguments/node.js';4import {mapScriptAsync, setScriptSync, deepScriptOptions} from './lib/script.js';56export {ExecaError, ExecaSyncError} from './lib/return/cause.js';78export const execa = createExeca(() => ({}));9export const execaSync = createExeca(() => ({isSync: true}));10export const execaCommand = createExeca(mapCommandAsync);11export const execaCommandSync = createExeca(mapCommandSync);12export const execaNode = createExeca(mapNode);13export const $ = createExeca(mapScriptAsync, {}, deepScriptOptions, setScriptSync);
modified:index.test-d.ts+332 added-68 removed
1693 unmodified lines
1694expectError(execa('unicorns').kill(undefined, {}));1695expectError(execa('unicorns').kill('SIGKILL', {}));1696expectError(execa('unicorns').kill(null, new Error('test')));16971698expectError(execa());1699expectError(execa(true));1700expectError(execa(['unicorns', 'arg']));1701expectAssignable<ExecaSubprocess>(execa('unicorns'));1702expectAssignable<ExecaSubprocess>(execa(fileUrl));1703expectAssignable<ExecaSubprocess>(execa('unicorns', []));1704expectAssignable<ExecaSubprocess>(execa('unicorns', ['foo']));1705expectAssignable<ExecaSubprocess>(execa('unicorns', {}));1706expectAssignable<ExecaSubprocess>(execa('unicorns', [], {}));1707expectError(execa('unicorns', 'foo'));1708expectError(execa('unicorns', [true]));1709expectError(execa('unicorns', [], []));1710expectError(execa('unicorns', {other: true}));1711expectAssignable<ExecaSubprocess>(execa`unicorns`);1712expectAssignable<typeof execa>(execa({}));1713expectAssignable<ExecaSubprocess>(execa({})('unicorns'));1714expectAssignable<ExecaSubprocess>(execa({})`unicorns`);1701expectType<ExecaResult>(await execa('unicorns'));1715expectType<ExecaResult<{}>>(await execa('unicorns'));1716expectType<ExecaResult<{}>>(await execa`unicorns`);1717expectAssignable<{stdout: string}>(await execa('unicorns'));1718expectAssignable<{stdout: Uint8Array}>(await execa('unicorns', {encoding: 'buffer'}));1719expectAssignable<{stdout: string}>(await execa('unicorns', ['foo']));1720expectAssignable<{stdout: Uint8Array}>(await execa('unicorns', ['foo'], {encoding: 'buffer'}));1721expectAssignable<{stdout: string}>(await execa({})('unicorns'));1722expectAssignable<{stdout: Uint8Array}>(await execa({encoding: 'buffer'})('unicorns'));1723expectAssignable<{stdout: Uint8Array}>(await execa({})({encoding: 'buffer'})('unicorns'));1724expectAssignable<{stdout: Uint8Array}>(await execa({encoding: 'buffer'})({})('unicorns'));1725expectAssignable<{stdout: string}>(await execa({})`unicorns`);1726expectAssignable<{stdout: Uint8Array}>(await execa({encoding: 'buffer'})`unicorns`);1727expectAssignable<{stdout: Uint8Array}>(await execa({})({encoding: 'buffer'})`unicorns`);1728expectAssignable<{stdout: Uint8Array}>(await execa({encoding: 'buffer'})({})`unicorns`);1729expectType<ExecaResult<{}>>(await execa`${'unicorns'}`);1730expectType<ExecaResult<{}>>(await execa`unicorns ${'foo'}`);1731expectType<ExecaResult<{}>>(await execa`unicorns ${'foo'} ${'bar'}`);1732expectType<ExecaResult<{}>>(await execa`unicorns ${1}`);1733expectType<ExecaResult<{}>>(await execa`unicorns ${['foo', 'bar']}`);1734expectType<ExecaResult<{}>>(await execa`unicorns ${[1, 2]}`);1735expectType<ExecaResult<{}>>(await execa`unicorns ${await execa`echo foo`}`);1736expectError(await execa`unicorns ${execa`echo foo`}`);1737expectType<ExecaResult<{}>>(await execa`unicorns ${[await execa`echo foo`, 'bar']}`);1738expectError(await execa`unicorns ${[execa`echo foo`, 'bar']}`);1739expectType<ExecaResult<{}>>(await execa`unicorns ${true.toString()}`);1740expectError(await execa`unicorns ${true}`);17411742expectError(execaSync());1743expectError(execaSync(true));1744expectError(execaSync(['unicorns', 'arg']));1708expectAssignable<ExecaSyncResult>(execaSync('unicorns'));1709expectAssignable<ExecaSyncResult>(execaSync(fileUrl));1745expectType<ExecaSyncResult<{}>>(execaSync('unicorns'));1746expectType<ExecaSyncResult<{}>>(execaSync(fileUrl));1747expectType<ExecaSyncResult<{}>>(execaSync('unicorns', []));1748expectType<ExecaSyncResult<{}>>(execaSync('unicorns', ['foo']));1749expectType<ExecaSyncResult<{}>>(execaSync('unicorns', {}));1750expectType<ExecaSyncResult<{}>>(execaSync('unicorns', [], {}));1751expectError(execaSync('unicorns', 'foo'));1752expectError(execaSync('unicorns', [true]));1753expectError(execaSync('unicorns', [], []));1754expectError(execaSync('unicorns', {other: true}));1755expectType<ExecaSyncResult<{}>>(execaSync`unicorns`);1756expectAssignable<typeof execaSync>(execaSync({}));1757expectType<ExecaSyncResult<{}>>(execaSync({})('unicorns'));1758expectType<ExecaSyncResult<{}>>(execaSync({})`unicorns`);1759expectType<ExecaSyncResult<{}>>(execaSync('unicorns'));1760expectType<ExecaSyncResult<{}>>(execaSync`unicorns`);1761expectAssignable<{stdout: string}>(execaSync('unicorns'));1762expectAssignable<{stdout: Uint8Array}>(execaSync('unicorns', {encoding: 'buffer'}));1763expectAssignable<{stdout: string}>(execaSync('unicorns', ['foo']));1764expectAssignable<{stdout: Uint8Array}>(execaSync('unicorns', ['foo'], {encoding: 'buffer'}));1765expectAssignable<{stdout: string}>(execaSync({})('unicorns'));1766expectAssignable<{stdout: Uint8Array}>(execaSync({encoding: 'buffer'})('unicorns'));1767expectAssignable<{stdout: Uint8Array}>(execaSync({})({encoding: 'buffer'})('unicorns'));1768expectAssignable<{stdout: Uint8Array}>(execaSync({encoding: 'buffer'})({})('unicorns'));1769expectAssignable<{stdout: string}>(execaSync({})`unicorns`);1770expectAssignable<{stdout: Uint8Array}>(execaSync({encoding: 'buffer'})`unicorns`);1771expectAssignable<{stdout: Uint8Array}>(execaSync({})({encoding: 'buffer'})`unicorns`);1772expectAssignable<{stdout: Uint8Array}>(execaSync({encoding: 'buffer'})({})`unicorns`);1773expectType<ExecaSyncResult<{}>>(execaSync`${'unicorns'}`);1774expectType<ExecaSyncResult<{}>>(execaSync`unicorns ${'foo'}`);1775expectType<ExecaSyncResult<{}>>(execaSync`unicorns ${'foo'} ${'bar'}`);1776expectType<ExecaSyncResult<{}>>(execaSync`unicorns ${1}`);1777expectType<ExecaSyncResult<{}>>(execaSync`unicorns ${['foo', 'bar']}`);1778expectType<ExecaSyncResult<{}>>(execaSync`unicorns ${[1, 2]}`);1779expectType<ExecaSyncResult<{}>>(execaSync`unicorns ${execaSync`echo foo`}`);1780expectType<ExecaSyncResult<{}>>(execaSync`unicorns ${[execaSync`echo foo`, 'bar']}`);1781expectType<ExecaSyncResult<{}>>(execaSync`unicorns ${false.toString()}`);1782expectError(execaSync`unicorns ${false}`);17831784expectError(execaCommand());1785expectError(execaCommand(true));1786expectError(execaCommand(['unicorns', 'arg']));1787expectAssignable<ExecaSubprocess>(execaCommand('unicorns'));1788expectError(execaCommand(fileUrl));1789expectError(execaCommand('unicorns', []));1790expectError(execaCommand('unicorns', ['foo']));1791expectAssignable<ExecaSubprocess>(execaCommand('unicorns', {}));1792expectError(execaCommand('unicorns', [], {}));1793expectError(execaCommand('unicorns', 'foo'));1794expectError(execaCommand('unicorns', [true]));1795expectError(execaCommand('unicorns', [], []));1796expectError(execaCommand('unicorns', {other: true}));1797expectAssignable<ExecaSubprocess>(execaCommand`unicorns`);1798expectAssignable<typeof execaCommand>(execaCommand({}));1799expectAssignable<ExecaSubprocess>(execaCommand({})('unicorns'));1800expectAssignable<ExecaSubprocess>(execaCommand({})`unicorns`);1716expectType<ExecaResult>(await execaCommand('unicorns'));1801expectType<ExecaResult<{}>>(await execaCommand('unicorns'));1802expectType<ExecaResult<{}>>(await execaCommand`unicorns`);1803expectAssignable<{stdout: string}>(await execaCommand('unicorns'));1804expectAssignable<{stdout: Uint8Array}>(await execaCommand('unicorns', {encoding: 'buffer'}));1719expectAssignable<{stdout: string}>(await execaCommand('unicorns foo'));1720expectAssignable<{stdout: Uint8Array}>(await execaCommand('unicorns foo', {encoding: 'buffer'}));1805expectAssignable<{stdout: string}>(await execaCommand({})('unicorns'));1806expectAssignable<{stdout: Uint8Array}>(await execaCommand({encoding: 'buffer'})('unicorns'));1807expectAssignable<{stdout: Uint8Array}>(await execaCommand({})({encoding: 'buffer'})('unicorns'));1808expectAssignable<{stdout: Uint8Array}>(await execaCommand({encoding: 'buffer'})({})('unicorns'));1809expectAssignable<{stdout: string}>(await execaCommand({})`unicorns`);1810expectAssignable<{stdout: Uint8Array}>(await execaCommand({encoding: 'buffer'})`unicorns`);1811expectAssignable<{stdout: Uint8Array}>(await execaCommand({})({encoding: 'buffer'})`unicorns`);1812expectAssignable<{stdout: Uint8Array}>(await execaCommand({encoding: 'buffer'})({})`unicorns`);1813expectType<ExecaResult<{}>>(await execaCommand`${'unicorns'}`);1814expectType<ExecaResult<{}>>(await execaCommand`unicorns ${'foo'}`);1815expectError(await execaCommand`unicorns ${'foo'} ${'bar'}`);1816expectError(await execaCommand`unicorns ${1}`);1817expectError(await execaCommand`unicorns ${['foo', 'bar']}`);1818expectError(await execaCommand`unicorns ${[1, 2]}`);1819expectError(await execaCommand`unicorns ${await execaCommand`echo foo`}`);1820expectError(await execaCommand`unicorns ${execaCommand`echo foo`}`);1821expectError(await execaCommand`unicorns ${[await execaCommand`echo foo`, 'bar']}`);1822expectError(await execaCommand`unicorns ${[execaCommand`echo foo`, 'bar']}`);1823expectType<ExecaResult<{}>>(await execaCommand`unicorns ${true.toString()}`);1824expectError(await execaCommand`unicorns ${true}`);18251722expectAssignable<ExecaSyncResult>(execaCommandSync('unicorns'));1826expectError(execaCommandSync());1827expectError(execaCommandSync(true));1828expectError(execaCommandSync(['unicorns', 'arg']));1829expectType<ExecaSyncResult<{}>>(execaCommandSync('unicorns'));1830expectError(execaCommandSync(fileUrl));1831expectError(execaCommandSync('unicorns', []));1832expectError(execaCommandSync('unicorns', ['foo']));1833expectType<ExecaSyncResult<{}>>(execaCommandSync('unicorns', {}));1834expectError(execaCommandSync('unicorns', [], {}));1835expectError(execaCommandSync('unicorns', 'foo'));1836expectError(execaCommandSync('unicorns', [true]));1837expectError(execaCommandSync('unicorns', [], []));1838expectError(execaCommandSync('unicorns', {other: true}));1839expectType<ExecaSyncResult<{}>>(execaCommandSync`unicorns`);1840expectAssignable<typeof execaCommandSync>(execaCommandSync({}));1841expectType<ExecaSyncResult<{}>>(execaCommandSync({})('unicorns'));1842expectType<ExecaSyncResult<{}>>(execaCommandSync({})`unicorns`);1843expectType<ExecaSyncResult<{}>>(execaCommandSync('unicorns'));1844expectType<ExecaSyncResult<{}>>(execaCommandSync`unicorns`);1845expectAssignable<{stdout: string}>(execaCommandSync('unicorns'));1846expectAssignable<{stdout: Uint8Array}>(execaCommandSync('unicorns', {encoding: 'buffer'}));1725expectAssignable<{stdout: string}>(execaCommandSync('unicorns foo'));1726expectAssignable<{stdout: Uint8Array}>(execaCommandSync('unicorns foo', {encoding: 'buffer'}));1847expectAssignable<{stdout: string}>(execaCommandSync({})('unicorns'));1848expectAssignable<{stdout: Uint8Array}>(execaCommandSync({encoding: 'buffer'})('unicorns'));1849expectAssignable<{stdout: Uint8Array}>(execaCommandSync({})({encoding: 'buffer'})('unicorns'));1850expectAssignable<{stdout: Uint8Array}>(execaCommandSync({encoding: 'buffer'})({})('unicorns'));1851expectAssignable<{stdout: string}>(execaCommandSync({})`unicorns`);1852expectAssignable<{stdout: Uint8Array}>(execaCommandSync({encoding: 'buffer'})`unicorns`);1853expectAssignable<{stdout: Uint8Array}>(execaCommandSync({})({encoding: 'buffer'})`unicorns`);1854expectAssignable<{stdout: Uint8Array}>(execaCommandSync({encoding: 'buffer'})({})`unicorns`);1855expectType<ExecaSyncResult<{}>>(execaCommandSync`${'unicorns'}`);1856expectType<ExecaSyncResult<{}>>(execaCommandSync`unicorns ${'foo'}`);1857expectError(execaCommandSync`unicorns ${'foo'} ${'bar'}`);1858expectError(execaCommandSync`unicorns ${1}`);1859expectError(execaCommandSync`unicorns ${['foo', 'bar']}`);1860expectError(execaCommandSync`unicorns ${[1, 2]}`);1861expectError(execaCommandSync`unicorns ${execaCommandSync`echo foo`}`);1862expectError(execaCommandSync`unicorns ${[execaCommandSync`echo foo`, 'bar']}`);1863expectType<ExecaSyncResult<{}>>(execaCommandSync`unicorns ${false.toString()}`);1864expectError(execaCommandSync`unicorns ${false}`);18651866expectError($());1867expectError($(true));1868expectError($(['unicorns', 'arg']));1869expectAssignable<ExecaSubprocess>($('unicorns'));1870expectAssignable<ExecaSubprocess>($(fileUrl));1871expectAssignable<ExecaSubprocess>($('unicorns', []));1872expectAssignable<ExecaSubprocess>($('unicorns', ['foo']));1873expectAssignable<ExecaSubprocess>($('unicorns', {}));1874expectAssignable<ExecaSubprocess>($('unicorns', [], {}));1875expectError($('unicorns', 'foo'));1876expectError($('unicorns', [true]));1877expectError($('unicorns', [], []));1878expectError($('unicorns', {other: true}));1879expectAssignable<ExecaSubprocess>($`unicorns`);1880expectAssignable<typeof $>($({}));1881expectAssignable<ExecaSubprocess>($({})('unicorns'));1882expectAssignable<ExecaSubprocess>($({})`unicorns`);1883expectType<ExecaResult<{}>>(await $('unicorns'));1884expectType<ExecaResult<{}>>(await $`unicorns`);1885expectAssignable<{stdout: string}>(await $('unicorns'));1886expectAssignable<{stdout: Uint8Array}>(await $('unicorns', {encoding: 'buffer'}));1887expectAssignable<{stdout: string}>(await $('unicorns', ['foo']));1888expectAssignable<{stdout: Uint8Array}>(await $('unicorns', ['foo'], {encoding: 'buffer'}));1889expectAssignable<{stdout: string}>(await $({})('unicorns'));1890expectAssignable<{stdout: Uint8Array}>(await $({encoding: 'buffer'})('unicorns'));1891expectAssignable<{stdout: Uint8Array}>(await $({})({encoding: 'buffer'})('unicorns'));1892expectAssignable<{stdout: Uint8Array}>(await $({encoding: 'buffer'})({})('unicorns'));1893expectAssignable<{stdout: string}>(await $({})`unicorns`);1894expectAssignable<{stdout: Uint8Array}>(await $({encoding: 'buffer'})`unicorns`);1895expectAssignable<{stdout: Uint8Array}>(await $({})({encoding: 'buffer'})`unicorns`);1896expectAssignable<{stdout: Uint8Array}>(await $({encoding: 'buffer'})({})`unicorns`);1897expectType<ExecaResult<{}>>(await $`${'unicorns'}`);1898expectType<ExecaResult<{}>>(await $`unicorns ${'foo'}`);1899expectType<ExecaResult<{}>>(await $`unicorns ${'foo'} ${'bar'}`);1900expectType<ExecaResult<{}>>(await $`unicorns ${1}`);1901expectType<ExecaResult<{}>>(await $`unicorns ${['foo', 'bar']}`);1902expectType<ExecaResult<{}>>(await $`unicorns ${[1, 2]}`);1903expectType<ExecaResult<{}>>(await $`unicorns ${await $`echo foo`}`);1904expectError(await $`unicorns ${$`echo foo`}`);1905expectType<ExecaResult<{}>>(await $`unicorns ${[await $`echo foo`, 'bar']}`);1906expectError(await $`unicorns ${[$`echo foo`, 'bar']}`);1907expectType<ExecaResult<{}>>(await $`unicorns ${true.toString()}`);1908expectError(await $`unicorns ${true}`);19091910expectError($.sync());1911expectError($.sync(true));1912expectError($.sync(['unicorns', 'arg']));1913expectType<ExecaSyncResult<{}>>($.sync('unicorns'));1914expectType<ExecaSyncResult<{}>>($.sync(fileUrl));1915expectType<ExecaSyncResult<{}>>($.sync('unicorns', []));1916expectType<ExecaSyncResult<{}>>($.sync('unicorns', ['foo']));1917expectType<ExecaSyncResult<{}>>($.sync('unicorns', {}));1918expectType<ExecaSyncResult<{}>>($.sync('unicorns', [], {}));1919expectError($.sync('unicorns', 'foo'));1920expectError($.sync('unicorns', [true]));1921expectError($.sync('unicorns', [], []));1922expectError($.sync('unicorns', {other: true}));1923expectType<ExecaSyncResult<{}>>($.sync`unicorns`);1924expectAssignable<typeof $.sync>($.sync({}));1925expectType<ExecaSyncResult<{}>>($.sync({})('unicorns'));1926expectType<ExecaSyncResult<{}>>($({}).sync('unicorns'));1927expectType<ExecaSyncResult<{}>>($.sync({})`unicorns`);1928expectType<ExecaSyncResult<{}>>($({}).sync`unicorns`);1929expectType<ExecaSyncResult<{}>>($.sync('unicorns'));1930expectType<ExecaSyncResult<{}>>($.sync`unicorns`);1931expectAssignable<{stdout: string}>($.sync('unicorns'));1932expectAssignable<{stdout: Uint8Array}>($.sync('unicorns', {encoding: 'buffer'}));1933expectAssignable<{stdout: string}>($.sync('unicorns', ['foo']));1934expectAssignable<{stdout: Uint8Array}>($.sync('unicorns', ['foo'], {encoding: 'buffer'}));1935expectAssignable<{stdout: string}>($.sync({})('unicorns'));1936expectAssignable<{stdout: string}>($({}).sync('unicorns'));1937expectAssignable<{stdout: Uint8Array}>($.sync({encoding: 'buffer'})('unicorns'));1938expectAssignable<{stdout: Uint8Array}>($({encoding: 'buffer'}).sync('unicorns'));1939expectAssignable<{stdout: Uint8Array}>($.sync({})({encoding: 'buffer'})('unicorns'));1940expectAssignable<{stdout: Uint8Array}>($({})({encoding: 'buffer'}).sync('unicorns'));1941expectAssignable<{stdout: Uint8Array}>($.sync({encoding: 'buffer'})({})('unicorns'));1942expectAssignable<{stdout: Uint8Array}>($({encoding: 'buffer'}).sync({})('unicorns'));1943expectAssignable<{stdout: string}>($.sync({})`unicorns`);1944expectAssignable<{stdout: string}>($({}).sync`unicorns`);1945expectAssignable<{stdout: Uint8Array}>($.sync({encoding: 'buffer'})`unicorns`);1946expectAssignable<{stdout: Uint8Array}>($({encoding: 'buffer'}).sync`unicorns`);1947expectAssignable<{stdout: Uint8Array}>($.sync({})({encoding: 'buffer'})`unicorns`);1948expectAssignable<{stdout: Uint8Array}>($({})({encoding: 'buffer'}).sync`unicorns`);1949expectAssignable<{stdout: Uint8Array}>($.sync({encoding: 'buffer'})({})`unicorns`);1950expectAssignable<{stdout: Uint8Array}>($({encoding: 'buffer'}).sync({})`unicorns`);1951expectType<ExecaSyncResult<{}>>($.sync`${'unicorns'}`);1952expectType<ExecaSyncResult<{}>>($.sync`unicorns ${'foo'}`);1953expectType<ExecaSyncResult<{}>>($.sync`unicorns ${'foo'} ${'bar'}`);1954expectType<ExecaSyncResult<{}>>($.sync`unicorns ${1}`);1955expectType<ExecaSyncResult<{}>>($.sync`unicorns ${['foo', 'bar']}`);1956expectType<ExecaSyncResult<{}>>($.sync`unicorns ${[1, 2]}`);1957expectType<ExecaSyncResult<{}>>($.sync`unicorns ${$.sync`echo foo`}`);1958expectType<ExecaSyncResult<{}>>($.sync`unicorns ${[$.sync`echo foo`, 'bar']}`);1959expectType<ExecaSyncResult<{}>>($.sync`unicorns ${false.toString()}`);1960expectError($.sync`unicorns ${false}`);19611962expectError($.s());1963expectError($.s(true));1964expectError($.s(['unicorns', 'arg']));1965expectType<ExecaSyncResult<{}>>($.s('unicorns'));1966expectType<ExecaSyncResult<{}>>($.s(fileUrl));1967expectType<ExecaSyncResult<{}>>($.s('unicorns', []));1968expectType<ExecaSyncResult<{}>>($.s('unicorns', ['foo']));1969expectType<ExecaSyncResult<{}>>($.s('unicorns', {}));1970expectType<ExecaSyncResult<{}>>($.s('unicorns', [], {}));1971expectError($.s('unicorns', 'foo'));1972expectError($.s('unicorns', [true]));1973expectError($.s('unicorns', [], []));1974expectError($.s('unicorns', {other: true}));1975expectType<ExecaSyncResult<{}>>($.s`unicorns`);1976expectAssignable<typeof $.s>($.s({}));1977expectType<ExecaSyncResult<{}>>($.s({})('unicorns'));1978expectType<ExecaSyncResult<{}>>($({}).s('unicorns'));1979expectType<ExecaSyncResult<{}>>($.s({})`unicorns`);1980expectType<ExecaSyncResult<{}>>($({}).s`unicorns`);1981expectType<ExecaSyncResult<{}>>($.s('unicorns'));1982expectType<ExecaSyncResult<{}>>($.s`unicorns`);1983expectAssignable<{stdout: string}>($.s('unicorns'));1984expectAssignable<{stdout: Uint8Array}>($.s('unicorns', {encoding: 'buffer'}));1985expectAssignable<{stdout: string}>($.s('unicorns', ['foo']));1986expectAssignable<{stdout: Uint8Array}>($.s('unicorns', ['foo'], {encoding: 'buffer'}));1987expectAssignable<{stdout: string}>($.s({})('unicorns'));1988expectAssignable<{stdout: string}>($({}).s('unicorns'));1989expectAssignable<{stdout: Uint8Array}>($.s({encoding: 'buffer'})('unicorns'));1990expectAssignable<{stdout: Uint8Array}>($({encoding: 'buffer'}).s('unicorns'));1991expectAssignable<{stdout: Uint8Array}>($.s({})({encoding: 'buffer'})('unicorns'));1992expectAssignable<{stdout: Uint8Array}>($({})({encoding: 'buffer'}).s('unicorns'));1993expectAssignable<{stdout: Uint8Array}>($.s({encoding: 'buffer'})({})('unicorns'));1994expectAssignable<{stdout: Uint8Array}>($({encoding: 'buffer'}).s({})('unicorns'));1995expectAssignable<{stdout: string}>($.s({})`unicorns`);1996expectAssignable<{stdout: string}>($({}).s`unicorns`);1997expectAssignable<{stdout: Uint8Array}>($.s({encoding: 'buffer'})`unicorns`);1998expectAssignable<{stdout: Uint8Array}>($({encoding: 'buffer'}).s`unicorns`);1999expectAssignable<{stdout: Uint8Array}>($.s({})({encoding: 'buffer'})`unicorns`);2000expectAssignable<{stdout: Uint8Array}>($({})({encoding: 'buffer'}).s`unicorns`);2001expectAssignable<{stdout: Uint8Array}>($.s({encoding: 'buffer'})({})`unicorns`);2002expectAssignable<{stdout: Uint8Array}>($({encoding: 'buffer'}).s({})`unicorns`);2003expectType<ExecaSyncResult<{}>>($.s`${'unicorns'}`);2004expectType<ExecaSyncResult<{}>>($.s`unicorns ${'foo'}`);2005expectType<ExecaSyncResult<{}>>($.s`unicorns ${'foo'} ${'bar'}`);2006expectType<ExecaSyncResult<{}>>($.s`unicorns ${1}`);2007expectType<ExecaSyncResult<{}>>($.s`unicorns ${['foo', 'bar']}`);2008expectType<ExecaSyncResult<{}>>($.s`unicorns ${[1, 2]}`);2009expectType<ExecaSyncResult<{}>>($.s`unicorns ${$.s`echo foo`}`);2010expectType<ExecaSyncResult<{}>>($.s`unicorns ${[$.s`echo foo`, 'bar']}`);2011expectType<ExecaSyncResult<{}>>($.s`unicorns ${false.toString()}`);2012expectError($.s`unicorns ${false}`);20132014expectError(execaNode());2015expectError(execaNode(true));2016expectError(execaNode(['unicorns', 'arg']));2017expectAssignable<ExecaSubprocess>(execaNode('unicorns'));2018expectAssignable<ExecaSubprocess>(execaNode(fileUrl));2019expectAssignable<ExecaSubprocess>(execaNode('unicorns', []));2020expectAssignable<ExecaSubprocess>(execaNode('unicorns', ['foo']));2021expectAssignable<ExecaSubprocess>(execaNode('unicorns', {}));2022expectAssignable<ExecaSubprocess>(execaNode('unicorns', [], {}));2023expectError(execaNode('unicorns', 'foo'));2024expectError(execaNode('unicorns', [true]));2025expectError(execaNode('unicorns', [], []));2026expectError(execaNode('unicorns', {other: true}));2027expectAssignable<ExecaSubprocess>(execaNode`unicorns`);2028expectAssignable<typeof execaNode>(execaNode({}));2029expectAssignable<ExecaSubprocess>(execaNode({})('unicorns'));2030expectAssignable<ExecaSubprocess>(execaNode({})`unicorns`);1730expectType<ExecaResult>(await execaNode('unicorns'));1731expectType<ExecaResult>(await execaNode(fileUrl));2031expectType<ExecaResult<{}>>(await execaNode('unicorns'));2032expectType<ExecaResult<{}>>(await execaNode`unicorns`);2033expectAssignable<{stdout: string}>(await execaNode('unicorns'));2034expectAssignable<{stdout: Uint8Array}>(await execaNode('unicorns', {encoding: 'buffer'}));2035expectAssignable<{stdout: string}>(await execaNode('unicorns', ['foo']));2036expectAssignable<{stdout: Uint8Array}>(await execaNode('unicorns', ['foo'], {encoding: 'buffer'}));2037expectAssignable<{stdout: string}>(await execaNode({})('unicorns'));2038expectAssignable<{stdout: Uint8Array}>(await execaNode({encoding: 'buffer'})('unicorns'));2039expectAssignable<{stdout: Uint8Array}>(await execaNode({})({encoding: 'buffer'})('unicorns'));2040expectAssignable<{stdout: Uint8Array}>(await execaNode({encoding: 'buffer'})({})('unicorns'));2041expectAssignable<{stdout: string}>(await execaNode({})`unicorns`);2042expectAssignable<{stdout: Uint8Array}>(await execaNode({encoding: 'buffer'})`unicorns`);2043expectAssignable<{stdout: Uint8Array}>(await execaNode({})({encoding: 'buffer'})`unicorns`);2044expectAssignable<{stdout: Uint8Array}>(await execaNode({encoding: 'buffer'})({})`unicorns`);2045expectType<ExecaResult<{}>>(await execaNode`${'unicorns'}`);2046expectType<ExecaResult<{}>>(await execaNode`unicorns ${'foo'}`);2047expectType<ExecaResult<{}>>(await execaNode`unicorns ${'foo'} ${'bar'}`);2048expectType<ExecaResult<{}>>(await execaNode`unicorns ${1}`);2049expectType<ExecaResult<{}>>(await execaNode`unicorns ${['foo', 'bar']}`);2050expectType<ExecaResult<{}>>(await execaNode`unicorns ${[1, 2]}`);2051expectType<ExecaResult<{}>>(await execaNode`unicorns ${await execaNode`echo foo`}`);2052expectError(await execaNode`unicorns ${execaNode`echo foo`}`);2053expectType<ExecaResult<{}>>(await execaNode`unicorns ${[await execaNode`echo foo`, 'bar']}`);2054expectError(await execaNode`unicorns ${[execaNode`echo foo`, 'bar']}`);2055expectType<ExecaResult<{}>>(await execaNode`unicorns ${true.toString()}`);2056expectError(await execaNode`unicorns ${true}`);20572058expectAssignable<ExecaSubprocess>(execaNode('unicorns', {nodePath: './node'}));2059expectAssignable<ExecaSubprocess>(execaNode('unicorns', {nodePath: fileUrl}));17392060expectAssignable<{stdout: string}>(await execaNode('unicorns', {nodeOptions: ['--async-stack-traces']}));2061expectAssignable<{stdout: Uint8Array}>(await execaNode('unicorns', {nodeOptions: ['--async-stack-traces'], encoding: 'buffer'}));2062expectAssignable<{stdout: string}>(await execaNode('unicorns', ['foo'], {nodeOptions: ['--async-stack-traces']}));2063expectAssignable<{stdout: Uint8Array}>(await execaNode('unicorns', ['foo'], {nodeOptions: ['--async-stack-traces'], encoding: 'buffer'}));17441745expectAssignable<ExecaSubprocess>($`unicorns`);1746expectAssignable<ExecaResult>(await $`unicorns`);1747expectAssignable<ExecaSyncResult>($.sync`unicorns`);1748expectAssignable<ExecaSyncResult>($.s`unicorns`);17491750expectAssignable<ExecaSubprocess>($({})`unicorns`);1751expectAssignable<{stdout: string}>(await $({})`unicorns`);1752expectAssignable<{stdout: string}>($({}).sync`unicorns`);17531754expectAssignable<ExecaSubprocess>($({})`unicorns foo`);1755expectAssignable<{stdout: string}>(await $({})`unicorns foo`);1756expectAssignable<{stdout: string}>($({}).sync`unicorns foo`);17571758expectAssignable<ExecaSubprocess>($({encoding: 'buffer'})`unicorns`);1759expectAssignable<{stdout: Uint8Array}>(await $({encoding: 'buffer'})`unicorns`);1760expectAssignable<{stdout: Uint8Array}>($({encoding: 'buffer'}).sync`unicorns`);17611762expectAssignable<ExecaSubprocess>($({encoding: 'buffer'})`unicorns foo`);1763expectAssignable<{stdout: Uint8Array}>(await $({encoding: 'buffer'})`unicorns foo`);1764expectAssignable<{stdout: Uint8Array}>($({encoding: 'buffer'}).sync`unicorns foo`);17651766expectAssignable<ExecaSubprocess>($({encoding: 'buffer'})({})`unicorns`);1767expectAssignable<{stdout: Uint8Array}>(await $({encoding: 'buffer'})({})`unicorns`);1768expectAssignable<{stdout: Uint8Array}>($({encoding: 'buffer'})({}).sync`unicorns`);17691770expectAssignable<ExecaSubprocess>($({encoding: 'buffer'})({})`unicorns foo`);1771expectAssignable<{stdout: Uint8Array}>(await $({encoding: 'buffer'})({})`unicorns foo`);1772expectAssignable<{stdout: Uint8Array}>($({encoding: 'buffer'})({}).sync`unicorns foo`);17731774expectAssignable<ExecaSubprocess>($({})({encoding: 'buffer'})`unicorns`);1775expectAssignable<{stdout: Uint8Array}>(await $({})({encoding: 'buffer'})`unicorns`);1776expectAssignable<{stdout: Uint8Array}>($({})({encoding: 'buffer'}).sync`unicorns`);17771778expectAssignable<ExecaSubprocess>($({})({encoding: 'buffer'})`unicorns foo`);1779expectAssignable<{stdout: Uint8Array}>(await $({})({encoding: 'buffer'})`unicorns foo`);1780expectAssignable<{stdout: Uint8Array}>($({})({encoding: 'buffer'}).sync`unicorns foo`);17811782expectAssignable<ExecaResult>(await $`unicorns ${'foo'}`);1783expectAssignable<ExecaSyncResult>($.sync`unicorns ${'foo'}`);1784expectAssignable<ExecaResult>(await $`unicorns ${1}`);1785expectAssignable<ExecaSyncResult>($.sync`unicorns ${1}`);1786expectAssignable<ExecaResult>(await $`unicorns ${['foo', 'bar']}`);1787expectAssignable<ExecaSyncResult>($.sync`unicorns ${['foo', 'bar']}`);1788expectAssignable<ExecaResult>(await $`unicorns ${[1, 2]}`);1789expectAssignable<ExecaSyncResult>($.sync`unicorns ${[1, 2]}`);1790expectAssignable<ExecaResult>(await $`unicorns ${await $`echo foo`}`);1791expectError<ExecaResult>(await $`unicorns ${$`echo foo`}`);1792expectAssignable<ExecaSyncResult>($.sync`unicorns ${$.sync`echo foo`}`);1793expectAssignable<ExecaResult>(await $`unicorns ${[await $`echo foo`, 'bar']}`);1794expectError<ExecaResult>(await $`unicorns ${[$`echo foo`, 'bar']}`);1795expectAssignable<ExecaSyncResult>($.sync`unicorns ${[$.sync`echo foo`, 'bar']}`);1796expectAssignable<ExecaResult>(await $`unicorns ${true.toString()}`);1797expectAssignable<ExecaSyncResult>($.sync`unicorns ${false.toString()}`);1798expectError<ExecaResult>(await $`unicorns ${true}`);1799expectError<ExecaSyncResult>($.sync`unicorns ${false}`);
modified:readme.md+88 added-79 removed
45 unmodified lines
46## Why4748This package improves [`child_process`](https://nodejs.org/api/child_process.html) methods with:4950- [Promise interface](#execacommandcommand-options).51- [Scripts interface](#scripts-interface), like `zx`.50- [Promise interface](#execafile-arguments-options).51- [Script interface](docs/scripts.md) and [template strings](#template-string-syntax), like `zx`.52- Improved [Windows support](https://github.com/IndigoUnited/node-cross-spawn#why), including [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)) binaries.53- Executes [locally installed binaries](#preferlocal) without `npx`.54- [Cleans up](#cleanup) subprocesses when the current process ends.55- Redirect [`stdin`](#stdin)/[`stdout`](#stdout-1)/[`stderr`](#stderr-1) from/to files, streams, iterables, strings, `Uint8Array` or [objects](docs/transform.md#object-mode).
2 unmodified lines
58- [Fail-safe subprocess termination](#forcekillafterdelay).59- Get [interleaved output](#all) from `stdout` and `stderr` similar to what is printed on the terminal.60- [Strips the final newline](#stripfinalnewline) from the output so you don't have to do `stdout.trim()`.61- Convenience methods to pipe subprocesses' [input](#input) and [output](#redirect-output-to-a-file).62- Can specify file and arguments [as a single string](#execacommandcommand-options) without a shell.62- [Verbose mode](#verbose-mode) for debugging.63- More descriptive errors.64- Higher max buffer: 100 MB instead of 1 MB.65
14 unmodified lines
80console.log(stdout);81//=> 'unicorns'82```8385### Scripts interface84#### Global/shared options8587For more information about Execa scripts, please see [this page](docs/scripts.md).86```js87import {execa as execa_} from 'execa';8889const execa = execa_({verbose: 'full'});9091await execa('echo', ['unicorns']);92//=> 'unicorns'93```9495### Template string syntax9697#### Basic9899```js92import {$} from 'execa';100import {execa} from 'execa';10194const branch = await $`git branch --show-current`;95await $`dep deploy --branch=${branch}`;102const arg = 'unicorns'103const {stdout} = await execa`echo ${arg} & rainbows!`;104console.log(stdout);105//=> 'unicorns & rainbows!'106```107108#### Multiple arguments109110```js101import {$} from 'execa';111import {execa} from 'execa';112113const args = ['unicorns', '&', 'rainbows!'];104const {stdout} = await $`echo ${args}`;114const {stdout} = await execa`echo ${args}`;115console.log(stdout);116//=> 'unicorns & rainbows!'117```118119#### With options120121```js112import {$} from 'execa';122import {execa} from 'execa';123114await $({stdio: 'inherit'})`echo unicorns`;124await execa({verbose: 'full'})`echo unicorns`;125//=> 'unicorns'126```127118#### Global/shared options128### Scripts129120```js121import {$ as $_} from 'execa';130For more information about Execa scripts, please see [this page](docs/scripts.md).131123const $ = $_({stdio: 'inherit'});132#### Basic133125await $`echo unicorns`;126//=> 'unicorns'127128await $`echo rainbows`;129//=> 'rainbows'130```131132#### Piping133134```js135import {$} from 'execa';136137await $`npm run build`138 .pipe`sort`139 .pipe`head -n2`;137const branch = await $`git branch --show-current`;138await $`dep deploy --branch=${branch}`;139```140141#### Verbose mode142
63 unmodified lines
206console.log(pipedFrom[0]); // Result of `sort`207console.log(pipedFrom[0].pipedFrom[0]); // Result of `npm run build`208```209210#### Pipe with template strings211212```js213import {execa} from 'execa';214215await execa`npm run build`216 .pipe`sort`217 .pipe`head -n2`;218```219220#### Iterate over output lines221222```js223import {execa} from 'execa';224216for await (const line of execa('npm', ['run', 'build'])) {225for await (const line of execa`npm run build`)) {226 if (line.includes('ERROR')) {227 console.log(line);228 }229}
50 unmodified lines
280#### execa(file, arguments?, options?)281282`file`: `string | URL`\283`arguments`: `string[]`\275`options`: [`Options`](#options-1)\284`options`: [`Options`](#options)\285_Returns_: [`Subprocess`](#subprocess)286287Executes a command using `file ...arguments`.288280Arguments are [automatically escaped](#shell-syntax). They can contain any character, including spaces.289Arguments are [automatically escaped](#shell-syntax). They can contain any character, including spaces, tabs and newlines.290282This is the preferred method when executing single commands.291#### execa\`command\`292#### execa(options)\`command\`293284#### $\`command\`285#### $(options)\`command\`286294`command`: `string`\288`options`: [`Options`](#options-1)\295`options`: [`Options`](#options)\296_Returns_: [`Subprocess`](#subprocess)297291Executes a command. The `command` string includes both the `file` and its `arguments`.298Executes a command. `command` is a [template string](#template-string-syntax) and includes both the `file` and its `arguments`.299293Arguments are [automatically escaped](#shell-syntax). They can contain any character, but spaces, tabs and newlines must use `${}` like `` $`echo ${'has space'}` ``.300The `command` template string can inject any `${value}` with the following types: string, number, [`subprocess`](#subprocess) or an array of those types. For example: `` execa`echo one ${'two'} ${3} ${['four', 'five']}` ``. For `${subprocess}`, the subprocess's [`stdout`](#stdout) is used.301295This is the preferred method when executing multiple commands in a script file.302Arguments are [automatically escaped](#shell-syntax). They can contain any character, but spaces, tabs and newlines must use `${}` like `` execa`echo ${'has space'}` ``.303297The `command` string can inject any `${value}` with the following types: string, number, [`subprocess`](#subprocess) or an array of those types. For example: `` $`echo one ${'two'} ${3} ${['four', 'five']}` ``. For `${subprocess}`, the subprocess's `stdout` is used.304The `command` template string can use [multiple lines and indentation](docs/scripts.md#multiline-commands).305299The `command` string can use [multiple lines and indentation](docs/scripts.md#multiline-commands).306#### execa(options)307301For more information, please see [this section](#scripts-interface) and [this page](docs/scripts.md).308`options`: [`Options`](#options)\309_Returns_: [`execa`](#execafile-arguments-options)310303#### $(options)311Returns a new instance of Execa but with different default [`options`](#options). Consecutive calls are merged to previous ones.312305`options`: [`Options`](#options-1)\306_Returns_: [`$`](#command)313This allows setting global options or [sharing options](#globalshared-options) between multiple commands.314308Returns a new instance of [`$`](#command) but with different default [`options`](#options-1). Consecutive calls are merged to previous ones.315#### execaSync(file, arguments?, options?)316#### execaSync\`command\`317310This can be used to either:311- Set options for a specific command: `` $(options)`command` ``312- Share options for multiple commands: `` const $$ = $(options); $$`command`; $$`otherCommand`; ``318Same as [`execa()`](#execafile-arguments-options) but synchronous.319314#### execaCommand(command, options?)320Returns or throws a [`subprocessResult`](#subprocessResult). The [`subprocess`](#subprocess) is not returned: its methods and properties are not available. This includes [`.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal), [`.pid`](https://nodejs.org/api/child_process.html#subprocesspid), [`.pipe()`](#pipefile-arguments-options) and the [`.stdin`/`.stdout`/`.stderr`](https://nodejs.org/api/child_process.html#subprocessstdout) streams.321322Cannot use the following options: [`all`](#all-2), [`cleanup`](#cleanup), [`buffer`](#buffer), [`detached`](#detached), [`ipc`](#ipc), [`serialization`](#serialization), [`cancelSignal`](#cancelsignal), [`lines`](#lines) and [`verbose: 'full'`](#verbose). Also, the [`stdin`](#stdin), [`stdout`](#stdout-1), [`stderr`](#stderr-1), [`stdio`](#stdio-1) and [`input`](#input) options cannot be an array, an iterable, a [transform](docs/transform.md) or a web stream. Node.js streams [must have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr) unless the `input` option is used.323324#### $(file, arguments?, options?)325326`file`: `string | URL`\316`command`: `string`\317`options`: [`Options`](#options-1)\327`arguments`: `string[]`\328`options`: [`Options`](#options)\329_Returns_: [`Subprocess`](#subprocess)330320Executes a command. The `command` string includes both the `file` and its `arguments`.331Same as [`execa()`](#execafile-arguments-options) but using the [`stdin: 'inherit'`](#stdin) and [`preferLocal: true`](#preferlocal) options.332322Arguments are [automatically escaped](#shell-syntax). They can contain any character, but spaces must be escaped with a backslash like `execaCommand('echo has\\ space')`.333Just like `execa()`, this can use the [template string syntax](#execacommand) or [bind options](#execaoptions). It can also be [run synchronously](#execasyncfile-arguments-options) using `$.sync()` or `$.s()`.334324This is the preferred method when executing a user-supplied `command` string, such as in a REPL.335This is the preferred method when executing multiple commands in a script file. For more information, please see [this page](docs/scripts.md).336337#### execaNode(scriptPath, arguments?, options?)338328`file`: `string | URL`\339`scriptPath`: `string | URL`\340`arguments`: `string[]`\330`options`: [`Options`](#options-1)\341`options`: [`Options`](#options)\342_Returns_: [`Subprocess`](#subprocess)343333Same as [`execa()`](#execacommandcommand-options) but using the [`node`](#node) option.334344Same as [`execa()`](#execafile-arguments-options) but using the [`node: true`](#node) option.345Executes a Node.js file using `node scriptPath ...arguments`.346347Just like `execa()`, this can use the [template string syntax](#execacommand) or [bind options](#execaoptions).348349This is the preferred method when executing Node.js files.350339#### execaSync(file, arguments?, options?)340#### execaCommandSync(command, options?)341#### $.sync\`command\`342#### $.s\`command\`343#### $.sync(options)\`command\`344#### $.s(options)\`command\`351#### execaCommand(command, options?)352346Same as [`execa()`](#execacommandcommand-options), [`execaCommand()`](#execacommand-command-options), [$\`command\`](#command) but synchronous.353`command`: `string`\354`options`: [`Options`](#options)\355_Returns_: [`Subprocess`](#subprocess)356348Cannot use the following options: [`all`](#all-2), [`cleanup`](#cleanup), [`buffer`](#buffer), [`detached`](#detached), [`ipc`](#ipc), [`serialization`](#serialization), [`cancelSignal`](#cancelsignal), [`lines`](#lines) and [`verbose: 'full'`](#verbose). Also, the [`stdin`](#stdin), [`stdout`](#stdout-1), [`stderr`](#stderr-1), [`stdio`](#stdio-1) and [`input`](#input) options cannot be an array, an iterable, a [transform](docs/transform.md) or a web stream. Node.js streams [must have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr) unless the `input` option is used.357[`execa`](#execafile-arguments-options) with the [template string syntax](#execacommand) allows the `file` or the `arguments` to be user-defined (by injecting them with `${}`). However, if _both_ the `file` and the `arguments` are user-defined, _and_ those are supplied as a single string, then `execaCommand(command)` must be used instead.358350Returns or throws a [`subprocessResult`](#subprocessResult). The [`subprocess`](#subprocess) is not returned: its methods and properties are not available. This includes [`.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal), [`.pid`](https://nodejs.org/api/child_process.html#subprocesspid), [`.pipe()`](#pipefile-arguments-options) and the [`.stdin`/`.stdout`/`.stderr`](https://nodejs.org/api/child_process.html#subprocessstdout) streams.359This is only intended for very specific cases, such as a REPL. This should be avoided otherwise.360361Just like `execa()`, this can [bind options](#execaoptions). It can also be [run synchronously](#execasyncfile-arguments-options) using `execaCommandSync()`.362363Arguments are [automatically escaped](#shell-syntax). They can contain any character, but spaces must be escaped with a backslash like `execaCommand('echo has\\ space')`.364365### Shell syntax366367For all the [methods above](#methods), no shell interpreter (Bash, cmd.exe, etc.) is used unless the [`shell` option](#shell) is set. This means shell-specific characters and expressions (`$variable`, `&&`, `||`, `;`, `|`, etc.) have no special meaning and do not need to be escaped.368
16 unmodified lines
385#### pipe(file, arguments?, options?)386387`file`: `string | URL`\388`arguments`: `string[]`\376`options`: [`Options`](#options-1) and [`PipeOptions`](#pipeoptions)\389`options`: [`Options`](#options) and [`PipeOptions`](#pipeoptions)\390_Returns_: [`Promise<SubprocessResult>`](#subprocessresult)391392[Pipe](https://nodejs.org/api/stream.html#readablepipedestination-options) the subprocess' `stdout` to a second Execa subprocess' `stdin`. This resolves with that second subprocess' [result](#subprocessresult). If either subprocess is rejected, this is rejected with that subprocess' [error](#execaerror) instead.393381This follows the same syntax as [`execa(file, arguments?, options?)`](#execafile-arguments-options) except both [regular options](#options-1) and [pipe-specific options](#pipeoptions) can be specified.394This follows the same syntax as [`execa(file, arguments?, options?)`](#execafile-arguments-options) except both [regular options](#options) and [pipe-specific options](#pipeoptions) can be specified.395396This can be called multiple times to chain a series of subprocesses.397398Multiple subprocesses can be piped to the same subprocess. Conversely, the same subprocess can be piped to multiple other subprocesses.399387This is usually the preferred method to pipe subprocesses.388400#### pipe\`command\`401#### pipe(options)\`command\`402403`command`: `string`\393`options`: [`Options`](#options-1) and [`PipeOptions`](#pipeoptions)\404`options`: [`Options`](#options) and [`PipeOptions`](#pipeoptions)\405_Returns_: [`Promise<SubprocessResult>`](#subprocessresult)406396Like [`.pipe(file, arguments?, options?)`](#pipefile-arguments-options) but using a [`command` template string](docs/scripts.md#piping-stdout-to-another-command) instead. This follows the same syntax as [`$`](#command).407Like [`.pipe(file, arguments?, options?)`](#pipefile-arguments-options) but using a [`command` template string](docs/scripts.md#piping-stdout-to-another-command) instead. This follows the same syntax as `execa` [template strings](#execacommand).408398This is the preferred method to pipe subprocesses when using [`$`](#command).399409#### pipe(secondSubprocess, pipeOptions?)410411`secondSubprocess`: [`execa()` return value](#subprocess)\412`pipeOptions`: [`PipeOptions`](#pipeoptions)\
155 unmodified lines
568#### escapedCommand569570Type: `string`571563Same as [`command`](#command-1) but escaped.572Same as [`command`](#command) but escaped.573574Unlike `command`, control characters are escaped, which makes it safe to print in a terminal.575576This can also be copied and pasted into a shell, for debugging purposes.
210 unmodified lines
787788#### preferLocal789790Type: `boolean`\782Default: `true` with [`$`](#command), `false` otherwise791Default: `true` with [`$`](#file-arguments-options), `false` otherwise792793Prefer locally installed binaries when looking for a binary to execute.\794If you `$ npm install foo`, you can then `execa('foo')`.795
74 unmodified lines
870871#### stdin872873Type: `string | number | stream.Readable | ReadableStream | URL | Uint8Array | Iterable<string> | Iterable<Uint8Array> | Iterable<unknown> | AsyncIterable<string> | AsyncIterable<Uint8Array> | AsyncIterable<unknown> | GeneratorFunction<string> | GeneratorFunction<Uint8Array> | GeneratorFunction<unknown>| AsyncGeneratorFunction<string> | AsyncGeneratorFunction<Uint8Array> | AsyncGeneratorFunction<unknown>` (or a tuple of those types)\865Default: `inherit` with [`$`](#command), `pipe` otherwise874Default: `inherit` with [`$`](#file-arguments-options), `pipe` otherwise875876[How to setup](https://nodejs.org/api/child_process.html#child_process_options_stdio) the subprocess' standard input. This can be:877- `'pipe'`: Sets [`subprocess.stdin`](https://nodejs.org/api/child_process.html#subprocessstdin) stream.878- `'overlapped'`: Like `'pipe'` but asynchronous on Windows.
347 unmodified lines