mirror of
https://github.com/actions/setup-node.git
synced 2025-04-21 19:18:43 +00:00
check for node version from config files
This commit is contained in:
parent
25316bbc1f
commit
90861df21e
5 changed files with 43215 additions and 468 deletions
19
README.md
19
README.md
|
@ -26,7 +26,24 @@ steps:
|
|||
- run: npm test
|
||||
```
|
||||
|
||||
The `node-version` input is optional. If not supplied, the node version from PATH will be used. However, it is recommended to always specify Node.js version and don't rely on the system one.
|
||||
The `node-version` input is optional. If not supplied, the following files are checked:
|
||||
|
||||
1. `.n-node-version`
|
||||
2. `.naverc`
|
||||
3. `.node-version`
|
||||
4. `.nodeenvrc`
|
||||
5. `.nvmrc` (accurately [parsing nvm versions](https://github.com/ehmicky/node-version-alias))
|
||||
6. `package.json#engines.node`
|
||||
|
||||
and finally the following environment variables:
|
||||
|
||||
7. `NODIST_NODE_VERSION`
|
||||
8. `NODE_VERSION`
|
||||
9. `DEFAULT_NODE_VERSION`
|
||||
|
||||
If none of these are present, finally the node version from PATH will be used. However, it is recommended to always specify Node.js version and don't rely on the system one.
|
||||
|
||||
> Behind the scenes, it uses [@ehmicky](https://github.com/ehmicky)'s [`preferred-node-version`](https://www.npmjs.com/package/) 😍.
|
||||
|
||||
The action will first check the local cache for a semver match. If unable to find a specific version in the cache, the action will attempt to download a version of Node.js. It will pull LTS versions from [node-versions releases](https://github.com/actions/node-versions/releases) and on miss or failure will fall back to the previous behavior of downloading directly from [node dist](https://nodejs.org/dist/).
|
||||
|
||||
|
|
42640
dist/setup/index.js
vendored
42640
dist/setup/index.js
vendored
File diff suppressed because one or more lines are too long
1019
package-lock.json
generated
1019
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -31,6 +31,7 @@
|
|||
"@actions/http-client": "^1.0.6",
|
||||
"@actions/io": "^1.0.2",
|
||||
"@actions/tool-cache": "^1.5.4",
|
||||
"preferred-node-version": "^1.1.0",
|
||||
"semver": "^6.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
@ -5,6 +5,7 @@ import * as path from 'path';
|
|||
import {restoreCache} from './cache-restore';
|
||||
import {URL} from 'url';
|
||||
import os = require('os');
|
||||
import preferredNodeVersion from 'preferred-node-version';
|
||||
|
||||
export async function run() {
|
||||
try {
|
||||
|
@ -13,6 +14,9 @@ export async function run() {
|
|||
// If not supplied then task is still used to setup proxy, auth, etc...
|
||||
//
|
||||
let version = core.getInput('node-version');
|
||||
if (!version) {
|
||||
version = (await preferredNodeVersion()).version;
|
||||
}
|
||||
if (!version) {
|
||||
version = core.getInput('version');
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue