-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.d.ts
180 lines (165 loc) · 5.4 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
171
172
173
174
175
176
177
178
179
180
import type { Options as FetchNodeWebsiteOptions } from 'fetch-node-website'
import type { Options as NodeVersionAliasOptions } from 'node-version-alias'
import type {
Options as PreferredVersionOptions,
SemverVersion,
} from 'preferred-node-version'
export type { SemverVersion }
export interface NodeBinary {
/**
* Absolute path to the `node` executable
*/
path: string
/**
* Normalized Node.js version
*/
version: SemverVersion
}
/**
* CPU architecture
*/
type Arch =
| 'arm'
| 'arm64'
| 'ia32'
| 'mips'
| 'mipsel'
| 'ppc'
| 'ppc64'
| 's390'
| 's390x'
| 'x64'
// @ts-error @typescript-eslint/no-duplicate-type-constituents
type UpstreamOptions = FetchNodeWebsiteOptions & NodeVersionAliasOptions
// @ts-error @typescript-eslint/no-duplicate-type-constituents
type AllUpstreamOptions = UpstreamOptions & PreferredVersionOptions
export type Options = Partial<{
/**
* Output directory for the `node` executable.
* It the directory already has a `node` executable, no download is
* performed. This enables caching.
*
* @default Global cache directory such as `/home/user/.cache/nve/`
*/
output: string
/**
* Whether to show a progress bar.
*
* @default false
*/
progress: FetchNodeWebsiteOptions['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: AllUpstreamOptions['mirror']
/**
* Cancels when the signal is aborted.
*/
signal?: AllUpstreamOptions['signal']
/**
* 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: UpstreamOptions['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: Arch
/**
* When using the `local` alias, start looking for a Node.js version file
* from this directory.
*
* @default "."
*/
cwd: string | URL
}>
/**
* Download a specific version of Node.js.
* The Node.js release is downloaded, uncompressed and untared to an executable
* file ready to run.
*
* @example
* ```js
* // Download a specific Node.js release
* const { path, version } = await getNode('8')
* console.log(path) // /home/user/.cache/nve/8.17.0/node
* console.log(version) // 8.17.0
*
* // Download Node.js latest release
* const { path, version } = await getNode('latest')
* console.log(path) // /home/user/.cache/nve/16.3.0/node
* console.log(version) // 16.3.0
*
* // Any version range can be used
* await getNode('8.12.0')
* await getNode('<7')
*
* // Download latest LTS Node.js version
* await getNode('lts')
*
* // Download Node.js version from `~/.nvmrc` or the current process version
* await getNode('global')
*
* // Download current directory's Node.js version using its `.nvmrc` or `package.json` (`engines.node` field)
* await getNode('local')
*
* // Download Node.js version from a specific file like `.nvmrc` or `package.json`
* await getNode('/path/to/.nvmrc')
*
* // Specify the output directory
* const { path } = await getNode('8', {
* output: '/home/user/.cache/node_releases/',
* })
* console.log(path) // /home/user/.cache/node_releases/13.0.1/node
*
* // Use a mirror website
* await getNode('8', { mirror: 'https://npmmirror.com/mirrors/node' })
*
* // Specify the CPU architecture
* await getNode('8', { arch: 'x32' })
* ```
*/
export default function getNode(
/**
* 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,
options?: Options,
): Promise<NodeBinary>