-
Notifications
You must be signed in to change notification settings - Fork 26
/
main.d.ts
136 lines (123 loc) · 4.07 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
import type {
Options as NodeVersionAliasOptions,
SemverVersion,
} from 'node-version-alias'
export type { SemverVersion }
export interface Options {
/**
* Start looking for a Node.js version file from this directory.
*
* @default `process.cwd()``
*/
cwd?: string | URL
/**
* If `true`, find the global Node.js version instead:
* - use only the home directory and environment variables
* - ignore the current directory and parent directories
*
* @default false
*/
global?: boolean
/**
* Additional files to lookup.
* Their filenames must be one of `package.json`, `.nvmrc`, etc.
*
* @default []
*/
files?: string[]
/**
* Base URL.
* 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?: NodeVersionAliasOptions['mirror']
/**
* Cancels when the signal is aborted.
*/
signal?: NodeVersionAliasOptions['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?: NodeVersionAliasOptions['fetch']
}
export type PreferredNodeVersion = Partial<{
/**
* Full Node.js version. For example `12.16.2`.
* `undefined` if no preferred Node.js version was found.
*/
version: SemverVersion
/**
* Node.js version as specified in the Node.js version file.
* This might include aliases or version ranges.
* For example `latest`, `lts/erbium`, `12` or `12.16.2`.
* `undefined` if no preferred Node.js version was found.
*/
rawVersion: string
/**
* Absolute path to the Node.js version file.
* Either `filePath` or `envVariable` is defined.
*/
filePath: string
/**
* Name of the environment variable containing the version.
* For example `NODE_VERSION`.
* Either `filePath` or `envVariable` is defined.
*/
envVariable: string
}>
/**
* Get the preferred Node.js version of a user or project.
*
* This looks for any [`.nvmrc`](https://github.com/nvm-sh/nvm#nvmrc) or
* [`package.json` (`engines.node` field)](https://docs.npmjs.com/files/package.json#engines)
* in the current directory, parent directories or home directory.
*
* `nvm` aliases (like `current` or `lts/erbium`) and version ranges (like `12` or
* `>=12`) are resolved to regular `"major.minor.patch"` version strings.
*
* This also looks for any
* [`.node-version`](https://github.com/jasongin/nvs#automatic-switching-per-directory),
* [`.n-node-version`](https://github.com/tj/n#specifying-node-versions),
* [`.naverc`](https://github.com/isaacs/nave#automagical),
* [`.nodeenvrc`](https://github.com/ekalinin/nodeenv#configuration) file or
* [`NODE_VERSION`](https://docs.netlify.com/configure-builds/manage-dependencies/#node-js-and-javascript),
* [`NODIST_NODE_VERSION`](https://github.com/nullivex/nodist#scope-precedence)
* environment variable.
*
* If a file cannot be read or if it contains an invalid version, the promise is
* rejected with an error.
*
* @example
* ```js
* // Look for any `.nvmrc` or `package.json` (`engines.node` field)
* const { version } = await preferredNodeVersion()
* console.log(version) // 12.10.0
*
* // Search only the home directory and environment variables
* const { version } = await preferredNodeVersion({ global: true })
*
* // Start looking for a Node.js version file from this directory instead
* const { version } = await preferredNodeVersion({ cwd: '/path/to/cwd' })
*
* // Search for specific files
* await preferredNodeVersion({
* files: ['/path/to/.nvmrc', '/path/to/package.json'],
* })
* ```
*/
export default function preferredNodeVersion(
options?: Options,
): Promise<PreferredNodeVersion>
/**
* List of filenames being searched: `.nvmrc`, `package.json`, etc.
*/
export declare const NODE_VERSION_FILES: string[]