-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.d.ts
170 lines (153 loc) · 5.55 KB
/
main.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import type { Options as ExecaOptions, ResultPromise } from 'execa'
import type { Options as GetNodeOptions, SemverVersion } from 'get-node'
export interface ProcessInfo {
/**
* [`childProcess` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess).
* It is also a `Promise` resolving or rejecting with a
* [`Result`](https://github.com/sindresorhus/execa/blob/main/docs/api.md#result).
* The `Promise` should be awaited if you want to wait for the process to
* complete.
* This is `undefined` when the `dry` option is `true`.
*/
childProcess?: ResultPromise
/**
* Node.js version passed as input, such as `"v10"`.
*/
versionRange: string
/**
* Normalized Node.js version
* For example if `"v10"` was passed as input, `version` will be `"10.17.0"`.
*/
version: SemverVersion
/**
* File or command that was executed.
*/
command: string
/**
* Arguments that were passed to the `command`.
*/
args: string[]
/**
* [Options](https://github.com/sindresorhus/execa/blob/main/docs/api.md#options)
* that were passed to [Execa](https://github.com/sindresorhus/execa).
*/
execaOptions: ExecaOptions
}
/**
* All Execa options are available. Please refer to Execa for the list of
* [possible options](https://github.com/sindresorhus/execa/blob/main/docs/api.md#options).
* The
* [`preferLocal` option](https://github.com/sindresorhus/execa/blob/main/docs/api.md#optionspreferlocal)
* is always `true`.
*/
export type Options =
| ExecaOptions
| Partial<{
/**
* Do not execute the command.
* This can be used to cache the initial Node.js binary download.
*
* @default false
*/
dry: boolean
/**
* Whether to show a progress bar.
*
* @default false
*/
progress: GetNodeOptions['progress']
/**
* Base URL to retrieve Node.js binaries.
* Can be customized (for example `https://npmmirror.com/mirrors/node`).
* The following environment variables can also be used: `NODE_MIRROR`,
* `NVM_NODEJS_ORG_MIRROR`, `N_NODE_MIRROR` or `NODIST_NODE_MIRROR`.
*
* @default "https://nodejs.org/dist"
*/
mirror: GetNodeOptions['mirror']
/**
* The list of available Node.js versions is cached for one hour by default.
* If the `fetch` option is:
* - `true`: the cache will not be used
* - `false`: the cache will be used even if it's older than one hour
*
* @default undefined
*/
fetch: GetNodeOptions['fetch']
/**
* Node.js binary's CPU architecture. This is useful for example when you're
* on x64 but would like to run Node.js x32.
* All the values from
* [`process.arch`](https://nodejs.org/api/process.html#process_process_arch)
* are allowed except `mips` and `mipsel`.
*
* @default `process.arch`
*/
arch: GetNodeOptions['arch']
/**
* Current working directory of the child process.
* When using the `local` alias, start looking for a Node.js version file
* from this directory.
*
* @default "."
*/
cwd: GetNodeOptions['cwd']
}>
/**
* Executes `command ...args` with a specific Node.js `versionRange`.
*
* @example
* ```js
* const { childProcess, versionRange, version } = await nvexeca('8', 'node', [
* '--version',
* ])
* console.log(`Node ${versionRange} (${version})`) // Node 8 (8.16.2)
* const { exitCode, stdout, stderr } = await childProcess
* console.log(`Exit code: ${exitCode}`) // 0
* console.log(stdout) // v8.16.2
* ```
*/
export default function nvexeca(
/**
* This can be:
* - any [version range](https://github.com/npm/node-semver) such as `12`,
* `12.6.0` or `<12`
* - `latest`: Latest available Node version
* - `lts`: Latest LTS Node version
* - `global`: Global Node version
* - Using the home directory
* [`.nvmrc`](https://github.com/nvm-sh/nvm#nvmrc) or
* [`package.json` (`engines.node` field)](https://docs.npmjs.com/files/package.json#engines)
* - [Some similar files](https://github.com/ehmicky/preferred-node-version/blob/main/README.md)
* used by other Node.js version managers are also searched for
* - If nothing is found, defaults to the current process's Node version
* - `local`: Current directory's Node version
* - Using the current directory or parent directories
* [`.nvmrc`](https://github.com/nvm-sh/nvm#nvmrc),
* [`package.json` (`engines.node` field)](https://docs.npmjs.com/files/package.json#engines)
* or
* [similar files](https://github.com/ehmicky/preferred-node-version/blob/main/README.md)
* - Defaults to the `global` version
* - a file path towards a [`.nvmrc`](https://github.com/nvm-sh/nvm#nvmrc),
* [`package.json` (`engines.node` field)](https://docs.npmjs.com/files/package.json#engines)
* or
* [similar files](https://github.com/ehmicky/preferred-node-version/blob/main/README.md)
*/
versionRange: string,
/**
* File or command to execute. Both global and local binaries can be executed.
* Must be compatible with the specific Node `versionRange`. For example `npm`
* is [only compatible with Node `>=6`](https://github.com/npm/cli#important).
*/
command: string,
/**
* Arguments passed to the `command`.
*/
args: string[],
options?: Options,
): Promise<ProcessInfo>
export default function nvexeca(
versionRange: string,
command: string,
options?: Options,
): Promise<ProcessInfo>