UNPKG

2.29 kBTypeScriptView Raw
1import type {SyncOptions} from '../arguments/options.js';
2import type {SyncResult} from '../return/result.js';
3import type {TemplateString} from './template.js';
4
5/**
6Same as `execa()` but synchronous.
7
8Returns a subprocess `result` or throws an `error`. The `subprocess` is not returned: its methods and properties are not available.
9
10When `command` is a template string, it includes both the `file` and its `arguments`.
11
12`execaSync(options)` can be used to return a new instance of this method but with different default `options`. Consecutive calls are merged to previous ones.
13
14This method is discouraged as it holds the CPU and lacks multiple features.
15
16@param file - The program/script to execute, as a string or file URL
17@param arguments - Arguments to pass to `file` on execution.
18@returns `SyncResult`
19@throws `ExecaSyncError`
20
21@example
22
23```
24import {execaSync} from 'execa';
25
26const {stdout} = execaSync`npm run build`;
27// Print command's output
28console.log(stdout);
29```
30*/
31export declare const execaSync: ExecaSyncMethod<{}>;
32
33// For the moment, we purposely do not export `ExecaSyncMethod` and `ExecaScriptSyncMethod`.
34// This is because synchronous invocation is discouraged.
35export type ExecaSyncMethod<OptionsType extends SyncOptions = SyncOptions> =
36 & ExecaSyncBind<OptionsType>
37 & ExecaSyncTemplate<OptionsType>
38 & ExecaSyncArrayLong<OptionsType>
39 & ExecaSyncArrayShort<OptionsType>;
40
41// `execaSync(options)` binding
42type ExecaSyncBind<OptionsType extends SyncOptions> =
43 <NewOptionsType extends SyncOptions = {}>(options: NewOptionsType)
44 => ExecaSyncMethod<OptionsType & NewOptionsType>;
45
46// `execaSync`command`` template syntax
47type ExecaSyncTemplate<OptionsType extends SyncOptions> =
48 (...templateString: TemplateString)
49 => SyncResult<OptionsType>;
50
51// `execaSync('file', ['argument'], {})` array syntax
52type ExecaSyncArrayLong<OptionsType extends SyncOptions> =
53 <NewOptionsType extends SyncOptions = {}>(file: string | URL, arguments?: readonly string[], options?: NewOptionsType)
54 => SyncResult<OptionsType & NewOptionsType>;
55
56// `execaSync('file', {})` array syntax
57type ExecaSyncArrayShort<OptionsType extends SyncOptions> =
58 <NewOptionsType extends SyncOptions = {}>(file: string | URL, options?: NewOptionsType)
59 => SyncResult<OptionsType & NewOptionsType>;