UNPKG

2.34 kBTypeScriptView Raw
1import type {Options} from '../arguments/options.js';
2import type {ResultPromise} from '../subprocess/subprocess.js';
3import type {TemplateString} from './template.js';
4
5/**
6Same as `execa()` but using the `node: true` option.
7Executes a Node.js file using `node scriptPath ...arguments`.
8
9When `command` is a template string, it includes both the `file` and its `arguments`.
10
11`execaNode(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
13This is the preferred method when executing Node.js files.
14
15@param scriptPath - Node.js script to execute, as a string or file URL
16@param arguments - Arguments to pass to `scriptPath` on execution.
17@returns A `ResultPromise` that is both:
18- the subprocess.
19- a `Promise` either resolving with its successful `result`, or rejecting with its `error`.
20@throws `ExecaError`
21
22@example
23```
24import {execaNode, execa} from 'execa';
25
26await execaNode`file.js argument`;
27// Is the same as:
28await execa({node: true})`file.js argument`;
29// Or:
30await execa`node file.js argument`;
31```
32*/
33export declare const execaNode: ExecaNodeMethod<{}>;
34
35/**
36`execaNode()` method either exported by Execa, or bound using `execaNode(options)`.
37*/
38export type ExecaNodeMethod<OptionsType extends Options = Options> =
39 & ExecaNodeBind<OptionsType>
40 & ExecaNodeTemplate<OptionsType>
41 & ExecaNodeArrayLong<OptionsType>
42 & ExecaNodeArrayShort<OptionsType>;
43
44// `execaNode(options)` binding
45type ExecaNodeBind<OptionsType extends Options> =
46 <NewOptionsType extends Options = {}>(options: NewOptionsType)
47 => ExecaNodeMethod<OptionsType & NewOptionsType>;
48
49// `execaNode`command`` template syntax
50type ExecaNodeTemplate<OptionsType extends Options> =
51 (...templateString: TemplateString)
52 => ResultPromise<OptionsType>;
53
54// `execaNode('script', ['argument'], {})` array syntax
55type ExecaNodeArrayLong<OptionsType extends Options> =
56 <NewOptionsType extends Options = {}>(scriptPath: string | URL, arguments?: readonly string[], options?: NewOptionsType)
57 => ResultPromise<OptionsType & NewOptionsType>;
58
59// `execaNode('script', {})` array syntax
60type ExecaNodeArrayShort<OptionsType extends Options> =
61 <NewOptionsType extends Options = {}>(scriptPath: string | URL, options?: NewOptionsType)
62 => ResultPromise<OptionsType & NewOptionsType>;