diff --git a/index.d.ts b/index.d.ts index a227299683..661a6cdd62 100644 --- a/index.d.ts +++ b/index.d.ts @@ -13,7 +13,7 @@ export {ExecaError, ExecaSyncError} from './types/return/final-error.js'; export {execa, type ExecaMethod} from './types/methods/main-async.js'; export {execaSync, type ExecaSyncMethod} from './types/methods/main-sync.js'; -export {execaCommand, execaCommandSync, parseCommandString} from './types/methods/command.js'; +export {parseCommandString} from './types/methods/command.js'; export {$, type ExecaScriptMethod, type ExecaScriptSyncMethod} from './types/methods/script.js'; export {execaNode, type ExecaNodeMethod} from './types/methods/node.js'; diff --git a/index.js b/index.js index 11285d9615..84c59fb9f1 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,4 @@ import {createExeca} from './lib/methods/create.js'; -import {mapCommandAsync, mapCommandSync} from './lib/methods/command.js'; import {mapNode} from './lib/methods/node.js'; import {mapScriptAsync, setScriptSync, deepScriptOptions} from './lib/methods/script.js'; import {getIpcExport} from './lib/ipc/methods.js'; @@ -9,8 +8,6 @@ export {ExecaError, ExecaSyncError} from './lib/return/final-error.js'; export const execa = createExeca(() => ({})); export const execaSync = createExeca(() => ({isSync: true})); -export const execaCommand = createExeca(mapCommandAsync); -export const execaCommandSync = createExeca(mapCommandSync); export const execaNode = createExeca(mapNode); export const $ = createExeca(mapScriptAsync, {}, deepScriptOptions, setScriptSync); diff --git a/lib/methods/command.js b/lib/methods/command.js index add23b29dc..0a65f3cc9c 100644 --- a/lib/methods/command.js +++ b/lib/methods/command.js @@ -1,19 +1,3 @@ -// Main logic for `execaCommand()` -export const mapCommandAsync = ({file, commandArguments}) => parseCommand(file, commandArguments); - -// Main logic for `execaCommandSync()` -export const mapCommandSync = ({file, commandArguments}) => ({...parseCommand(file, commandArguments), isSync: true}); - -// Convert `execaCommand(command)` into `execa(file, ...commandArguments)` -const parseCommand = (command, unusedArguments) => { - if (unusedArguments.length > 0) { - throw new TypeError(`The command and its arguments must be passed as a single string: ${command} ${unusedArguments}.`); - } - - const [file, ...commandArguments] = parseCommandString(command); - return {file, commandArguments}; -}; - // Convert `command` string into an array of file or arguments to pass to $`${...fileOrCommandArguments}` export const parseCommandString = command => { if (typeof command !== 'string') { diff --git a/lib/methods/create.js b/lib/methods/create.js index d59fe0da22..64ae11fdbf 100644 --- a/lib/methods/create.js +++ b/lib/methods/create.js @@ -51,14 +51,12 @@ const parseArguments = ({mapArguments, firstArgument, nextArguments, deepOptions const [initialFile, initialArguments, initialOptions] = normalizeParameters(...callArguments); const mergedOptions = mergeOptions(mergeOptions(deepOptions, boundOptions), initialOptions); const { - file = initialFile, - commandArguments = initialArguments, options = mergedOptions, isSync = false, - } = mapArguments({file: initialFile, commandArguments: initialArguments, options: mergedOptions}); + } = mapArguments({options: mergedOptions}); return { - file, - commandArguments, + file: initialFile, + commandArguments: initialArguments, options, isSync, }; diff --git a/test-d/methods/command.test-d.ts b/test-d/methods/command.test-d.ts index 6305b3ae17..6150e8aa0e 100644 --- a/test-d/methods/command.test-d.ts +++ b/test-d/methods/command.test-d.ts @@ -1,20 +1,14 @@ -import {expectType, expectError, expectAssignable} from 'tsd'; +import {expectType, expectError} from 'tsd'; import { execa, execaSync, $, execaNode, - execaCommand, - execaCommandSync, parseCommandString, type Result, - type ResultPromise, type SyncResult, } from '../../index.js'; -const fileUrl = new URL('file:///test'); -const stringArray = ['foo', 'bar'] as const; - expectError(parseCommandString()); expectError(parseCommandString(true)); expectError(parseCommandString(['unicorns', 'arg'])); @@ -31,93 +25,3 @@ expectType>(await execaNode`${parseCommandString('foo bar')}`); expectType>(await execa`unicorns ${parseCommandString('foo bar')}`); expectType>(await execa('unicorns', parseCommandString('foo bar'))); expectType>(await execa('unicorns', ['foo', ...parseCommandString('bar')])); - -expectError(execaCommand()); -expectError(execaCommand(true)); -expectError(execaCommand(['unicorns', 'arg'])); -expectAssignable(execaCommand('unicorns')); -expectError(execaCommand(fileUrl)); - -expectError(execaCommand('unicorns', [])); -expectError(execaCommand('unicorns', ['foo'])); -expectError(execaCommand('unicorns', 'foo')); -expectError(execaCommand('unicorns', [true])); - -expectAssignable(execaCommand('unicorns', {})); -expectError(execaCommand('unicorns', [], {})); -expectError(execaCommand('unicorns', [], [])); -expectError(execaCommand('unicorns', {other: true})); - -expectAssignable(execaCommand`unicorns`); -expectType>(await execaCommand('unicorns')); -expectType>(await execaCommand`unicorns`); - -expectAssignable(execaCommand({})); -expectAssignable(execaCommand({})('unicorns')); -expectAssignable(execaCommand({})`unicorns`); - -expectAssignable<{stdout: string}>(await execaCommand('unicorns')); -expectAssignable<{stdout: Uint8Array}>(await execaCommand('unicorns', {encoding: 'buffer'})); -expectAssignable<{stdout: string}>(await execaCommand({})('unicorns')); -expectAssignable<{stdout: Uint8Array}>(await execaCommand({encoding: 'buffer'})('unicorns')); -expectAssignable<{stdout: Uint8Array}>(await execaCommand({})({encoding: 'buffer'})('unicorns')); -expectAssignable<{stdout: Uint8Array}>(await execaCommand({encoding: 'buffer'})({})('unicorns')); -expectAssignable<{stdout: string}>(await execaCommand({})`unicorns`); -expectAssignable<{stdout: Uint8Array}>(await execaCommand({encoding: 'buffer'})`unicorns`); -expectAssignable<{stdout: Uint8Array}>(await execaCommand({})({encoding: 'buffer'})`unicorns`); -expectAssignable<{stdout: Uint8Array}>(await execaCommand({encoding: 'buffer'})({})`unicorns`); - -expectType>(await execaCommand`${'unicorns'}`); -expectType>(await execaCommand`unicorns ${'foo'}`); -expectError(await execaCommand`unicorns ${'foo'} ${'bar'}`); -expectError(await execaCommand`unicorns ${1}`); -expectError(await execaCommand`unicorns ${stringArray}`); -expectError(await execaCommand`unicorns ${[1, 2]}`); -expectType>(await execaCommand`unicorns ${false.toString()}`); -expectError(await execaCommand`unicorns ${false}`); - -expectError(await execaCommand`unicorns ${await execaCommand`echo foo`}`); -expectError(await execaCommand`unicorns ${await execaCommand({reject: false})`echo foo`}`); -expectError(await execaCommand`unicorns ${execaCommand`echo foo`}`); -expectError(await execaCommand`unicorns ${[await execaCommand`echo foo`, 'bar']}`); -expectError(await execaCommand`unicorns ${[execaCommand`echo foo`, 'bar']}`); - -expectError(execaCommandSync()); -expectError(execaCommandSync(true)); -expectError(execaCommandSync(['unicorns', 'arg'])); -expectType>(execaCommandSync('unicorns')); -expectError(execaCommandSync(fileUrl)); -expectError(execaCommandSync('unicorns', [])); -expectError(execaCommandSync('unicorns', ['foo'])); -expectType>(execaCommandSync('unicorns', {})); -expectError(execaCommandSync('unicorns', [], {})); -expectError(execaCommandSync('unicorns', 'foo')); -expectError(execaCommandSync('unicorns', [true])); -expectError(execaCommandSync('unicorns', [], [])); -expectError(execaCommandSync('unicorns', {other: true})); -expectType>(execaCommandSync`unicorns`); -expectAssignable(execaCommandSync({})); -expectType>(execaCommandSync({})('unicorns')); -expectType>(execaCommandSync({})`unicorns`); -expectType>(execaCommandSync('unicorns')); -expectType>(execaCommandSync`unicorns`); -expectAssignable<{stdout: string}>(execaCommandSync('unicorns')); -expectAssignable<{stdout: Uint8Array}>(execaCommandSync('unicorns', {encoding: 'buffer'})); -expectAssignable<{stdout: string}>(execaCommandSync({})('unicorns')); -expectAssignable<{stdout: Uint8Array}>(execaCommandSync({encoding: 'buffer'})('unicorns')); -expectAssignable<{stdout: Uint8Array}>(execaCommandSync({})({encoding: 'buffer'})('unicorns')); -expectAssignable<{stdout: Uint8Array}>(execaCommandSync({encoding: 'buffer'})({})('unicorns')); -expectAssignable<{stdout: string}>(execaCommandSync({})`unicorns`); -expectAssignable<{stdout: Uint8Array}>(execaCommandSync({encoding: 'buffer'})`unicorns`); -expectAssignable<{stdout: Uint8Array}>(execaCommandSync({})({encoding: 'buffer'})`unicorns`); -expectAssignable<{stdout: Uint8Array}>(execaCommandSync({encoding: 'buffer'})({})`unicorns`); -expectType>(execaCommandSync`${'unicorns'}`); -expectType>(execaCommandSync`unicorns ${'foo'}`); -expectError(execaCommandSync`unicorns ${'foo'} ${'bar'}`); -expectError(execaCommandSync`unicorns ${1}`); -expectError(execaCommandSync`unicorns ${stringArray}`); -expectError(execaCommandSync`unicorns ${[1, 2]}`); -expectError(execaCommandSync`unicorns ${execaCommandSync`echo foo`}`); -expectError(execaCommandSync`unicorns ${[execaCommandSync`echo foo`, 'bar']}`); -expectType>(execaCommandSync`unicorns ${false.toString()}`); -expectError(execaCommandSync`unicorns ${false}`); diff --git a/test/methods/command.js b/test/methods/command.js index 1e65a7b68e..1f8001bfde 100644 --- a/test/methods/command.js +++ b/test/methods/command.js @@ -1,52 +1,31 @@ -import path from 'node:path'; import test from 'ava'; import { execa, execaSync, $, execaNode, - execaCommand, - execaCommandSync, parseCommandString, } from '../../index.js'; import { setFixtureDirectory, - FIXTURES_DIRECTORY, FIXTURES_DIRECTORY_URL, } from '../helpers/fixtures-directory.js'; -import {QUOTE} from '../helpers/verbose.js'; setFixtureDirectory(); -const STDIN_FIXTURE = path.join(FIXTURES_DIRECTORY, 'stdin.js'); const ECHO_FIXTURE_URL = new URL('echo.js', FIXTURES_DIRECTORY_URL); const parseAndRunCommand = command => execa`${parseCommandString(command)}`; -test('execaCommand()', async t => { - const {stdout} = await execaCommand('echo.js foo bar'); - t.is(stdout, 'foo\nbar'); -}); - test('parseCommandString() + execa()', async t => { const {stdout} = await execa('echo.js', parseCommandString('foo bar')); t.is(stdout, 'foo\nbar'); }); -test('execaCommandSync()', t => { - const {stdout} = execaCommandSync('echo.js foo bar'); - t.is(stdout, 'foo\nbar'); -}); - test('parseCommandString() + execaSync()', t => { const {stdout} = execaSync('echo.js', parseCommandString('foo bar')); t.is(stdout, 'foo\nbar'); }); -test('execaCommand`...`', async t => { - const {stdout} = await execaCommand`${'echo.js foo bar'}`; - t.is(stdout, 'foo\nbar'); -}); - test('parseCommandString() + execa`...`', async t => { const {stdout} = await execa`${parseCommandString('echo.js foo bar')}`; t.is(stdout, 'foo\nbar'); @@ -62,11 +41,6 @@ test('parseCommandString() + execa`...`, only some arguments', async t => { t.is(stdout, 'foo bar\nfoo\nbar'); }); -test('execaCommandSync`...`', t => { - const {stdout} = execaCommandSync`${'echo.js foo bar'}`; - t.is(stdout, 'foo\nbar'); -}); - test('parseCommandString() + execaSync`...`', t => { const {stdout} = execaSync`${parseCommandString('echo.js foo bar')}`; t.is(stdout, 'foo\nbar'); @@ -97,98 +71,32 @@ test('parseCommandString() + execaNode', async t => { t.is(stdout, 'foo\nbar'); }); -test('execaCommand(options)`...`', async t => { - const {stdout} = await execaCommand({stripFinalNewline: false})`${'echo.js foo bar'}`; - t.is(stdout, 'foo\nbar\n'); -}); - -test('execaCommandSync(options)`...`', t => { - const {stdout} = execaCommandSync({stripFinalNewline: false})`${'echo.js foo bar'}`; - t.is(stdout, 'foo\nbar\n'); -}); - -test('execaCommand(options)()', async t => { - const {stdout} = await execaCommand({stripFinalNewline: false})('echo.js foo bar'); - t.is(stdout, 'foo\nbar\n'); -}); - -test('execaCommandSync(options)()', t => { - const {stdout} = execaCommandSync({stripFinalNewline: false})('echo.js foo bar'); - t.is(stdout, 'foo\nbar\n'); -}); - -test('execaCommand().pipe(execaCommand())', async t => { - const {stdout} = await execaCommand('echo.js foo bar').pipe(execaCommand(`node ${STDIN_FIXTURE}`)); - t.is(stdout, 'foo\nbar'); -}); - -test('execaCommand().pipe(...) does not use execaCommand', async t => { - const {escapedCommand} = await execaCommand('echo.js foo bar').pipe(`node ${STDIN_FIXTURE}`, {reject: false}); - t.true(escapedCommand.startsWith(`${QUOTE}node `)); -}); - -test('execaCommand() bound options have lower priority', async t => { - const {stdout} = await execaCommand({stripFinalNewline: false})('echo.js foo bar', {stripFinalNewline: true}); - t.is(stdout, 'foo\nbar'); -}); - -test('execaCommandSync() bound options have lower priority', t => { - const {stdout} = execaCommandSync({stripFinalNewline: false})('echo.js foo bar', {stripFinalNewline: true}); - t.is(stdout, 'foo\nbar'); -}); - -const testInvalidArgumentsArray = (t, execaMethod) => { - t.throws(() => execaMethod('echo', ['foo']), { - message: /The command and its arguments must be passed as a single string/, - }); -}; - -test('execaCommand() must not pass an array of arguments', testInvalidArgumentsArray, execaCommand); -test('execaCommandSync() must not pass an array of arguments', testInvalidArgumentsArray, execaCommandSync); - -const testInvalidArgumentsTemplate = (t, execaMethod) => { - t.throws(() => execaMethod`echo foo`, { - message: /The command and its arguments must be passed as a single string/, - }); -}; - -test('execaCommand() must not pass an array of arguments with a template string', testInvalidArgumentsTemplate, execaCommand); -test('execaCommandSync() must not pass an array of arguments with a template string', testInvalidArgumentsTemplate, execaCommandSync); - const testInvalidArgumentsParse = (t, command) => { t.throws(() => parseCommandString(command), { message: /The command must be a string/, }); }; -test('execaCommand() must not pass a number', testInvalidArgumentsParse, 0); -test('execaCommand() must not pass undefined', testInvalidArgumentsParse, undefined); -test('execaCommand() must not pass null', testInvalidArgumentsParse, null); -test('execaCommand() must not pass a symbol', testInvalidArgumentsParse, Symbol('test')); -test('execaCommand() must not pass an object', testInvalidArgumentsParse, {}); -test('execaCommand() must not pass an array', testInvalidArgumentsParse, []); +test('parseCommandString() must not pass a number', testInvalidArgumentsParse, 0); +test('parseCommandString() must not pass undefined', testInvalidArgumentsParse, undefined); +test('parseCommandString() must not pass null', testInvalidArgumentsParse, null); +test('parseCommandString() must not pass a symbol', testInvalidArgumentsParse, Symbol('test')); +test('parseCommandString() must not pass an object', testInvalidArgumentsParse, {}); +test('parseCommandString() must not pass an array', testInvalidArgumentsParse, []); -const testExecaCommandOutput = async (t, command, expectedOutput, execaMethod) => { +const testParseCommandOutput = async (t, command, expectedOutput, execaMethod) => { const {stdout} = await execaMethod(command); t.is(stdout, expectedOutput); }; -test('execaCommand() allows escaping spaces in commands', testExecaCommandOutput, 'command\\ with\\ space.js foo bar', 'foo\nbar', execaCommand); -test('execaCommand() trims', testExecaCommandOutput, ' echo.js foo bar ', 'foo\nbar', execaCommand); -test('execaCommand() ignores consecutive spaces', testExecaCommandOutput, 'echo.js foo bar', 'foo\nbar', execaCommand); -test('execaCommand() escapes other whitespaces', testExecaCommandOutput, 'echo.js foo\tbar', 'foo\tbar', execaCommand); -test('execaCommand() allows escaping spaces', testExecaCommandOutput, 'echo.js foo\\ bar', 'foo bar', execaCommand); -test('execaCommand() allows escaping backslashes before spaces', testExecaCommandOutput, 'echo.js foo\\\\ bar', 'foo\\ bar', execaCommand); -test('execaCommand() allows escaping multiple backslashes before spaces', testExecaCommandOutput, 'echo.js foo\\\\\\\\ bar', 'foo\\\\\\ bar', execaCommand); -test('execaCommand() allows escaping backslashes not before spaces', testExecaCommandOutput, 'echo.js foo\\bar baz', 'foo\\bar\nbaz', execaCommand); -test('parseCommandString() allows escaping spaces in commands', testExecaCommandOutput, 'command\\ with\\ space.js foo bar', 'foo\nbar', parseAndRunCommand); -test('parseCommandString() trims', testExecaCommandOutput, ' echo.js foo bar ', 'foo\nbar', parseAndRunCommand); -test('parseCommandString() ignores consecutive spaces', testExecaCommandOutput, 'echo.js foo bar', 'foo\nbar', parseAndRunCommand); -test('parseCommandString() escapes other whitespaces', testExecaCommandOutput, 'echo.js foo\tbar', 'foo\tbar', parseAndRunCommand); -test('parseCommandString() allows escaping spaces', testExecaCommandOutput, 'echo.js foo\\ bar', 'foo bar', parseAndRunCommand); -test('parseCommandString() allows escaping backslashes before spaces', testExecaCommandOutput, 'echo.js foo\\\\ bar', 'foo\\ bar', parseAndRunCommand); -test('parseCommandString() allows escaping multiple backslashes before spaces', testExecaCommandOutput, 'echo.js foo\\\\\\\\ bar', 'foo\\\\\\ bar', parseAndRunCommand); -test('parseCommandString() allows escaping backslashes not before spaces', testExecaCommandOutput, 'echo.js foo\\bar baz', 'foo\\bar\nbaz', parseAndRunCommand); +test('parseCommandString() allows escaping spaces in commands', testParseCommandOutput, 'command\\ with\\ space.js foo bar', 'foo\nbar', parseAndRunCommand); +test('parseCommandString() trims', testParseCommandOutput, ' echo.js foo bar ', 'foo\nbar', parseAndRunCommand); +test('parseCommandString() ignores consecutive spaces', testParseCommandOutput, 'echo.js foo bar', 'foo\nbar', parseAndRunCommand); +test('parseCommandString() escapes other whitespaces', testParseCommandOutput, 'echo.js foo\tbar', 'foo\tbar', parseAndRunCommand); +test('parseCommandString() allows escaping spaces', testParseCommandOutput, 'echo.js foo\\ bar', 'foo bar', parseAndRunCommand); +test('parseCommandString() allows escaping backslashes before spaces', testParseCommandOutput, 'echo.js foo\\\\ bar', 'foo\\ bar', parseAndRunCommand); +test('parseCommandString() allows escaping multiple backslashes before spaces', testParseCommandOutput, 'echo.js foo\\\\\\\\ bar', 'foo\\\\\\ bar', parseAndRunCommand); +test('parseCommandString() allows escaping backslashes not before spaces', testParseCommandOutput, 'echo.js foo\\bar baz', 'foo\\bar\nbaz', parseAndRunCommand); test('parseCommandString() can get empty strings', t => { t.deepEqual(parseCommandString(''), []); diff --git a/test/methods/parameters-args.js b/test/methods/parameters-args.js index 9a1c8b7a11..024e9fcd6a 100644 --- a/test/methods/parameters-args.js +++ b/test/methods/parameters-args.js @@ -2,8 +2,6 @@ import test from 'ava'; import { execa, execaSync, - execaCommand, - execaCommandSync, execaNode, $, } from '../../index.js'; @@ -19,8 +17,6 @@ const testInvalidArguments = async (t, execaMethod) => { test('execa()\'s second argument must be valid', testInvalidArguments, execa); test('execaSync()\'s second argument must be valid', testInvalidArguments, execaSync); -test('execaCommand()\'s second argument must be valid', testInvalidArguments, execaCommand); -test('execaCommandSync()\'s second argument must be valid', testInvalidArguments, execaCommandSync); test('execaNode()\'s second argument must be valid', testInvalidArguments, execaNode); test('$\'s second argument must be valid', testInvalidArguments, $); test('$.sync\'s second argument must be valid', testInvalidArguments, $.sync); @@ -33,8 +29,6 @@ const testInvalidArgumentsItems = async (t, execaMethod) => { test('execa()\'s second argument must not be objects', testInvalidArgumentsItems, execa); test('execaSync()\'s second argument must not be objects', testInvalidArgumentsItems, execaSync); -test('execaCommand()\'s second argument must not be objects', testInvalidArgumentsItems, execaCommand); -test('execaCommandSync()\'s second argument must not be objects', testInvalidArgumentsItems, execaCommandSync); test('execaNode()\'s second argument must not be objects', testInvalidArgumentsItems, execaNode); test('$\'s second argument must not be objects', testInvalidArgumentsItems, $); test('$.sync\'s second argument must not be objects', testInvalidArgumentsItems, $.sync); @@ -47,8 +41,6 @@ const testNullByteArgument = async (t, execaMethod) => { test('execa()\'s second argument must not include \\0', testNullByteArgument, execa); test('execaSync()\'s second argument must not include \\0', testNullByteArgument, execaSync); -test('execaCommand()\'s second argument must not include \\0', testNullByteArgument, execaCommand); -test('execaCommandSync()\'s second argument must not include \\0', testNullByteArgument, execaCommandSync); test('execaNode()\'s second argument must not include \\0', testNullByteArgument, execaNode); test('$\'s second argument must not include \\0', testNullByteArgument, $); test('$.sync\'s second argument must not include \\0', testNullByteArgument, $.sync); diff --git a/test/methods/parameters-command.js b/test/methods/parameters-command.js index e24c1afb18..97917a9135 100644 --- a/test/methods/parameters-command.js +++ b/test/methods/parameters-command.js @@ -4,8 +4,6 @@ import test from 'ava'; import { execa, execaSync, - execaCommand, - execaCommandSync, execaNode, $, } from '../../index.js'; @@ -22,8 +20,6 @@ const testFileUrl = async (t, execaMethod) => { test('execa()\'s command argument can be a file URL', testFileUrl, execa); test('execaSync()\'s command argument can be a file URL', testFileUrl, execaSync); -test('execaCommand()\'s command argument can be a file URL', testFileUrl, execaCommand); -test('execaCommandSync()\'s command argument can be a file URL', testFileUrl, execaCommandSync); test('execaNode()\'s command argument can be a file URL', testFileUrl, execaNode); test('$\'s command argument can be a file URL', testFileUrl, $); test('$.sync\'s command argument can be a file URL', testFileUrl, $.sync); @@ -37,8 +33,6 @@ const testInvalidFileUrl = async (t, execaMethod) => { test('execa()\'s command argument cannot be a non-file URL', testInvalidFileUrl, execa); test('execaSync()\'s command argument cannot be a non-file URL', testInvalidFileUrl, execaSync); -test('execaCommand()\'s command argument cannot be a non-file URL', testInvalidFileUrl, execaCommand); -test('execaCommandSync()\'s command argument cannot be a non-file URL', testInvalidFileUrl, execaCommandSync); test('execaNode()\'s command argument cannot be a non-file URL', testInvalidFileUrl, execaNode); test('$\'s command argument cannot be a non-file URL', testInvalidFileUrl, $); test('$.sync\'s command argument cannot be a non-file URL', testInvalidFileUrl, $.sync); @@ -51,22 +45,16 @@ const testInvalidCommand = async (t, commandArgument, execaMethod) => { test('execa()\'s first argument must be defined', testInvalidCommand, undefined, execa); test('execaSync()\'s first argument must be defined', testInvalidCommand, undefined, execaSync); -test('execaCommand()\'s first argument must be defined', testInvalidCommand, undefined, execaCommand); -test('execaCommandSync()\'s first argument must be defined', testInvalidCommand, undefined, execaCommandSync); test('execaNode()\'s first argument must be defined', testInvalidCommand, undefined, execaNode); test('$\'s first argument must be defined', testInvalidCommand, undefined, $); test('$.sync\'s first argument must be defined', testInvalidCommand, undefined, $.sync); test('execa()\'s first argument must be valid', testInvalidCommand, true, execa); test('execaSync()\'s first argument must be valid', testInvalidCommand, true, execaSync); -test('execaCommand()\'s first argument must be valid', testInvalidCommand, true, execaCommand); -test('execaCommandSync()\'s first argument must be valid', testInvalidCommand, true, execaCommandSync); test('execaNode()\'s first argument must be valid', testInvalidCommand, true, execaNode); test('$\'s first argument must be valid', testInvalidCommand, true, $); test('$.sync\'s first argument must be valid', testInvalidCommand, true, $.sync); test('execa()\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], execa); test('execaSync()\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], execaSync); -test('execaCommand()\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], execaCommand); -test('execaCommandSync()\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], execaCommandSync); test('execaNode()\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], execaNode); test('$\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], $); test('$.sync\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], $.sync); @@ -81,8 +69,6 @@ const testRelativePath = async (t, execaMethod) => { test('execa() use relative path with \'..\' chars', testRelativePath, execa); test('execaSync() use relative path with \'..\' chars', testRelativePath, execaSync); -test('execaCommand() use relative path with \'..\' chars', testRelativePath, execaCommand); -test('execaCommandSync() use relative path with \'..\' chars', testRelativePath, execaCommandSync); test('execaNode() use relative path with \'..\' chars', testRelativePath, execaNode); test('$ use relative path with \'..\' chars', testRelativePath, $); test('$.sync use relative path with \'..\' chars', testRelativePath, $.sync); diff --git a/test/methods/parameters-options.js b/test/methods/parameters-options.js index 8c8535b52d..d41a0503d8 100644 --- a/test/methods/parameters-options.js +++ b/test/methods/parameters-options.js @@ -3,8 +3,6 @@ import test from 'ava'; import { execa, execaSync, - execaCommand, - execaCommandSync, execaNode, $, } from '../../index.js'; @@ -68,8 +66,6 @@ const testInvalidOptions = async (t, execaMethod) => { test('execa()\'s third argument must be a plain object', testInvalidOptions, execa); test('execaSync()\'s third argument must be a plain object', testInvalidOptions, execaSync); -test('execaCommand()\'s third argument must be a plain object', testInvalidOptions, execaCommand); -test('execaCommandSync()\'s third argument must be a plain object', testInvalidOptions, execaCommandSync); test('execaNode()\'s third argument must be a plain object', testInvalidOptions, execaNode); test('$\'s third argument must be a plain object', testInvalidOptions, $); test('$.sync\'s third argument must be a plain object', testInvalidOptions, $.sync); diff --git a/types/methods/command.d.ts b/types/methods/command.d.ts index ad2ead0f40..d3d764c4c5 100644 --- a/types/methods/command.d.ts +++ b/types/methods/command.d.ts @@ -1,98 +1,3 @@ -import type {Options, SyncOptions} from '../arguments/options.js'; -import type {SyncResult} from '../return/result.js'; -import type {ResultPromise} from '../subprocess/subprocess.js'; -import type {SimpleTemplateString} from './template.js'; - -/** -Executes a command. `command` is a string that includes both the `file` and its `arguments`. - -When `command` is a template string, it includes both the `file` and its `arguments`. - -`execaCommand(options)` can be used to return a new instance of this method but with different default `options`. Consecutive calls are merged to previous ones. - -This is only intended for very specific cases, such as a REPL. This should be avoided otherwise. - -@param command - The program/script to execute and its arguments. -@returns A `ResultPromise` that is both: -- the subprocess. -- a `Promise` either resolving with its successful `result`, or rejecting with its `error`. -@throws `ExecaError` - -@example -``` -import {execaCommand} from 'execa'; - -for await (const commandAndArguments of getReplLine()) { - await execaCommand(commandAndArguments); -} -``` -*/ -export declare const execaCommand: ExecaCommandMethod<{}>; - -type ExecaCommandMethod = - & ExecaCommandBind - & ExecaCommandTemplate - & ExecaCommandArray; - -// `execaCommand(options)` binding -type ExecaCommandBind = - (options: NewOptionsType) - => ExecaCommandMethod; - -// `execaCommand`command`` template syntax -type ExecaCommandTemplate = - (...templateString: SimpleTemplateString) - => ResultPromise; - -// `execaCommand('command', {})` array syntax -type ExecaCommandArray = - (command: string, options?: NewOptionsType) - => ResultPromise; - -/** -Same as `execaCommand()` but synchronous. - -When `command` is a template string, it includes both the `file` and its `arguments`. - -`execaCommandSync(options)` can be used to return a new instance of this method but with different default `options`. Consecutive calls are merged to previous ones. - -Returns a subprocess `result` or throws an `error`. The `subprocess` is not returned: its methods and properties are not available. - -@param command - The program/script to execute and its arguments. -@returns `SyncResult` -@throws `ExecaSyncError` - -@example -``` -import {execaCommandSync} from 'execa'; - -for (const commandAndArguments of getReplLine()) { - execaCommandSync(commandAndArguments); -} -``` -*/ -export declare const execaCommandSync: ExecaCommandSyncMethod<{}>; - -type ExecaCommandSyncMethod = - & ExecaCommandSyncBind - & ExecaCommandSyncTemplate - & ExecaCommandSyncArray; - -// `execaCommandSync(options)` binding -type ExecaCommandSyncBind = - (options: NewOptionsType) - => ExecaCommandSyncMethod; - -// `execaCommandSync`command`` template syntax -type ExecaCommandSyncTemplate = - (...templateString: SimpleTemplateString) - => SyncResult; - -// `execaCommandSync('command', {})` array syntax -type ExecaCommandSyncArray = - (command: string, options?: NewOptionsType) - => SyncResult; - /** Split a `command` string into an array. For example, `'npm run build'` returns `['npm', 'run', 'build']` and `'argument otherArgument'` returns `['argument', 'otherArgument']`. diff --git a/types/methods/template.d.ts b/types/methods/template.d.ts index f3ffebc3d0..c12fc598ea 100644 --- a/types/methods/template.d.ts +++ b/types/methods/template.d.ts @@ -14,7 +14,4 @@ export type TemplateExpression = TemplateExpressionItem | readonly TemplateExpre // `...${...}...` template syntax export type TemplateString = readonly [TemplateStringsArray, ...readonly TemplateExpression[]]; -// `...${...}...` template syntax, but only allowing a single argument, for `execaCommand()` -export type SimpleTemplateString = readonly [TemplateStringsArray, string?]; - export {};