forked from ehmicky/preferred-node-version
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.d.ts
113 lines (103 loc) · 3.57 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
import type {
SemverVersion,
Options as NodeVersionAliasOptions,
} 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
/**
* 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']
/**
* 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' })
* ```
*/
export default function preferredNodeVersion(
options?: Options,
): Promise<PreferredNodeVersion>