1 | import type {Options, SyncOptions} from '../arguments/options.js';
|
2 | import type {SyncResult} from '../return/result.js';
|
3 | import type {ResultPromise} from '../subprocess/subprocess.js';
|
4 | import type {SimpleTemplateString} from './template.js';
|
5 |
|
6 | /**
|
7 | Executes a command. `command` is a string that includes both the `file` and its `arguments`.
|
8 |
|
9 | When `command` is a template string, it includes both the `file` and its `arguments`.
|
10 |
|
11 | `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.
|
12 |
|
13 | This is only intended for very specific cases, such as a REPL. This should be avoided otherwise.
|
14 |
|
15 | @param command - The program/script to execute and its arguments.
|
16 | @returns A `ResultPromise` that is both:
|
17 | - the subprocess.
|
18 | - a `Promise` either resolving with its successful `result`, or rejecting with its `error`.
|
19 | @throws `ExecaError`
|
20 |
|
21 | @example
|
22 | ```
|
23 | import {execaCommand} from 'execa';
|
24 |
|
25 | for await (const commandAndArguments of getReplLine()) {
|
26 | await execaCommand(commandAndArguments);
|
27 | }
|
28 | ```
|
29 | */
|
30 | export declare const execaCommand: ExecaCommandMethod<{}>;
|
31 |
|
32 | type ExecaCommandMethod<OptionsType extends Options> =
|
33 | & ExecaCommandBind<OptionsType>
|
34 | & ExecaCommandTemplate<OptionsType>
|
35 | & ExecaCommandArray<OptionsType>;
|
36 |
|
37 | // `execaCommand(options)` binding
|
38 | type ExecaCommandBind<OptionsType extends Options> =
|
39 | <NewOptionsType extends Options = {}>(options: NewOptionsType)
|
40 | => ExecaCommandMethod<OptionsType & NewOptionsType>;
|
41 |
|
42 | // `execaCommand`command`` template syntax
|
43 | type ExecaCommandTemplate<OptionsType extends Options> =
|
44 | (...templateString: SimpleTemplateString)
|
45 | => ResultPromise<OptionsType>;
|
46 |
|
47 | // `execaCommand('command', {})` array syntax
|
48 | type ExecaCommandArray<OptionsType extends Options> =
|
49 | <NewOptionsType extends Options = {}>(command: string, options?: NewOptionsType)
|
50 | => ResultPromise<OptionsType & NewOptionsType>;
|
51 |
|
52 | /**
|
53 | Same as `execaCommand()` but synchronous.
|
54 |
|
55 | When `command` is a template string, it includes both the `file` and its `arguments`.
|
56 |
|
57 | `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.
|
58 |
|
59 | Returns a subprocess `result` or throws an `error`. The `subprocess` is not returned: its methods and properties are not available.
|
60 |
|
61 | @param command - The program/script to execute and its arguments.
|
62 | @returns `SyncResult`
|
63 | @throws `ExecaSyncError`
|
64 |
|
65 | @example
|
66 | ```
|
67 | import {execaCommandSync} from 'execa';
|
68 |
|
69 | for (const commandAndArguments of getReplLine()) {
|
70 | execaCommandSync(commandAndArguments);
|
71 | }
|
72 | ```
|
73 | */
|
74 | export declare const execaCommandSync: ExecaCommandSyncMethod<{}>;
|
75 |
|
76 | type ExecaCommandSyncMethod<OptionsType extends SyncOptions> =
|
77 | & ExecaCommandSyncBind<OptionsType>
|
78 | & ExecaCommandSyncTemplate<OptionsType>
|
79 | & ExecaCommandSyncArray<OptionsType>;
|
80 |
|
81 | // `execaCommandSync(options)` binding
|
82 | type ExecaCommandSyncBind<OptionsType extends SyncOptions> =
|
83 | <NewOptionsType extends SyncOptions = {}>(options: NewOptionsType)
|
84 | => ExecaCommandSyncMethod<OptionsType & NewOptionsType>;
|
85 |
|
86 | // `execaCommandSync`command`` template syntax
|
87 | type ExecaCommandSyncTemplate<OptionsType extends SyncOptions> =
|
88 | (...templateString: SimpleTemplateString)
|
89 | => SyncResult<OptionsType>;
|
90 |
|
91 | // `execaCommandSync('command', {})` array syntax
|
92 | type ExecaCommandSyncArray<OptionsType extends SyncOptions> =
|
93 | <NewOptionsType extends SyncOptions = {}>(command: string, options?: NewOptionsType)
|
94 | => SyncResult<OptionsType & NewOptionsType>;
|
95 |
|
96 | /**
|
97 | Split a `command` string into an array. For example, `'npm run build'` returns `['npm', 'run', 'build']` and `'argument otherArgument'` returns `['argument', 'otherArgument']`.
|
98 |
|
99 | @param command - The file to execute and/or its arguments.
|
100 | @returns fileOrArgument[]
|
101 |
|
102 | @example
|
103 | ```
|
104 | import {execa, parseCommandString} from 'execa';
|
105 |
|
106 | const commandString = 'npm run task';
|
107 | const commandArray = parseCommandString(commandString);
|
108 | await execa`${commandArray}`;
|
109 |
|
110 | const [file, ...commandArguments] = commandArray;
|
111 | await execa(file, commandArguments);
|
112 | ```
|
113 | */
|
114 | export function parseCommandString(command: string): string[];
|