mirror of
https://gitea.com/actions/setup-node.git
synced 2024-11-25 11:39:32 +01:00
Merge pull request #532 from jef/main
feat: add volta as node-version-file
This commit is contained in:
commit
9f3a02bbd1
8 changed files with 64 additions and 33 deletions
18
.github/workflows/versions.yml
vendored
18
.github/workflows/versions.yml
vendored
|
@ -102,6 +102,24 @@ jobs:
|
|||
- name: Verify node
|
||||
run: __tests__/verify-node.sh 14
|
||||
|
||||
version-file-volta:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ ubuntu-latest, windows-latest, macos-latest ]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Remove engines from package.json
|
||||
shell: bash
|
||||
run: cat <<< "$(jq 'del(.engines)' ./__tests__/data/package.json)" > ./__tests__/data/package.json
|
||||
- name: Setup node from node version file
|
||||
uses: ./
|
||||
with:
|
||||
node-version-file: '__tests__/data/package.json'
|
||||
- name: Verify node
|
||||
run: __tests__/verify-node.sh 14
|
||||
|
||||
node-dist:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
{
|
||||
"engines": {
|
||||
"node": "^14.0.0"
|
||||
},
|
||||
"volta": {
|
||||
"node": "14.0.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -579,6 +579,7 @@ describe('setup-node', () => {
|
|||
existsSpy.mockImplementationOnce(
|
||||
input => input === path.join(__dirname, 'data', versionFile)
|
||||
);
|
||||
|
||||
// Act
|
||||
await main.run();
|
||||
|
||||
|
|
28
dist/setup/index.js
vendored
28
dist/setup/index.js
vendored
|
@ -73530,29 +73530,25 @@ function translateArchToDistUrl(arch) {
|
|||
}
|
||||
}
|
||||
function parseNodeVersionFile(contents) {
|
||||
var _a, _b;
|
||||
var _a, _b, _c;
|
||||
let nodeVersion;
|
||||
// Try parsing the file as an NPM `package.json`
|
||||
// file.
|
||||
// Try parsing the file as an NPM `package.json` file.
|
||||
try {
|
||||
nodeVersion = (_a = JSON.parse(contents).engines) === null || _a === void 0 ? void 0 : _a.node;
|
||||
nodeVersion = (_a = JSON.parse(contents).volta) === null || _a === void 0 ? void 0 : _a.node;
|
||||
if (!nodeVersion)
|
||||
nodeVersion = (_b = JSON.parse(contents).engines) === null || _b === void 0 ? void 0 : _b.node;
|
||||
}
|
||||
catch (_c) {
|
||||
catch (_d) {
|
||||
core.warning('Node version file is not JSON file');
|
||||
}
|
||||
if (!nodeVersion) {
|
||||
try {
|
||||
const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m);
|
||||
nodeVersion = (_b = found === null || found === void 0 ? void 0 : found.groups) === null || _b === void 0 ? void 0 : _b.version;
|
||||
if (!nodeVersion)
|
||||
throw new Error();
|
||||
}
|
||||
catch (err) {
|
||||
// In the case of an unknown format,
|
||||
// return as is and evaluate the version separately.
|
||||
nodeVersion = contents.trim();
|
||||
}
|
||||
const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m);
|
||||
nodeVersion = (_c = found === null || found === void 0 ? void 0 : found.groups) === null || _c === void 0 ? void 0 : _c.version;
|
||||
}
|
||||
// In the case of an unknown format,
|
||||
// return as is and evaluate the version separately.
|
||||
if (!nodeVersion)
|
||||
nodeVersion = contents.trim();
|
||||
return nodeVersion;
|
||||
}
|
||||
exports.parseNodeVersionFile = parseNodeVersionFile;
|
||||
|
|
|
@ -48,7 +48,7 @@ steps:
|
|||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: '14'
|
||||
node-version: '16'
|
||||
check-latest: true
|
||||
- run: npm ci
|
||||
- run: npm test
|
||||
|
@ -56,8 +56,9 @@ steps:
|
|||
|
||||
## Node version file
|
||||
|
||||
The `node-version-file` input accepts a path to a file containing the version of Node.js to be used by a project, for example `.nvmrc`, `.node-version` or `.tool-versions`. If both the `node-version` and the `node-version-file` inputs are provided then the `node-version` input is used.
|
||||
See [supported version syntax](https://github.com/actions/setup-node#supported-version-syntax)
|
||||
The `node-version-file` input accepts a path to a file containing the version of Node.js to be used by a project, for example `.nvmrc`, `.node-version`, `.tool-versions`, or `package.json`. If both the `node-version` and the `node-version-file` inputs are provided then the `node-version` input is used.
|
||||
See [supported version syntax](https://github.com/actions/setup-node#supported-version-syntax).
|
||||
|
||||
> The action will search for the node version file relative to the repository root.
|
||||
|
||||
```yaml
|
||||
|
@ -70,6 +71,19 @@ steps:
|
|||
- run: npm test
|
||||
```
|
||||
|
||||
When using the `package.json` input, the action will look for `volta.node` first. If `volta.node` isn't defined, then it will look for `engines.node`.
|
||||
|
||||
```json
|
||||
{
|
||||
"engines": {
|
||||
"node": ">=16.0.0"
|
||||
},
|
||||
"volta": {
|
||||
"node": "16.0.0"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Architecture
|
||||
|
||||
You can use any of the [supported operating systems](https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners), and the compatible `architecture` can be selected using `architecture`. Values are `x86`, `x64`, `arm64`, `armv6l`, `armv7l`, `ppc64le`, `s390x` (not all of the architectures are available on all platforms).
|
||||
|
|
|
@ -497,27 +497,23 @@ function translateArchToDistUrl(arch: string): string {
|
|||
export function parseNodeVersionFile(contents: string): string {
|
||||
let nodeVersion: string | undefined;
|
||||
|
||||
// Try parsing the file as an NPM `package.json`
|
||||
// file.
|
||||
// Try parsing the file as an NPM `package.json` file.
|
||||
try {
|
||||
nodeVersion = JSON.parse(contents).engines?.node;
|
||||
nodeVersion = JSON.parse(contents).volta?.node;
|
||||
if (!nodeVersion) nodeVersion = JSON.parse(contents).engines?.node;
|
||||
} catch {
|
||||
core.warning('Node version file is not JSON file');
|
||||
}
|
||||
|
||||
if (!nodeVersion) {
|
||||
try {
|
||||
const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m);
|
||||
nodeVersion = found?.groups?.version;
|
||||
|
||||
if (!nodeVersion) throw new Error();
|
||||
} catch (err) {
|
||||
// In the case of an unknown format,
|
||||
// return as is and evaluate the version separately.
|
||||
nodeVersion = contents.trim();
|
||||
}
|
||||
const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m);
|
||||
nodeVersion = found?.groups?.version;
|
||||
}
|
||||
|
||||
// In the case of an unknown format,
|
||||
// return as is and evaluate the version separately.
|
||||
if (!nodeVersion) nodeVersion = contents.trim();
|
||||
|
||||
return nodeVersion as string;
|
||||
}
|
||||
|
||||
|
|
|
@ -95,14 +95,17 @@ function resolveVersionInput(): string {
|
|||
process.env.GITHUB_WORKSPACE!,
|
||||
versionFileInput
|
||||
);
|
||||
|
||||
if (!fs.existsSync(versionFilePath)) {
|
||||
throw new Error(
|
||||
`The specified node version file at: ${versionFilePath} does not exist`
|
||||
);
|
||||
}
|
||||
|
||||
version = installer.parseNodeVersionFile(
|
||||
fs.readFileSync(versionFilePath, 'utf8')
|
||||
);
|
||||
|
||||
core.info(`Resolved ${versionFileInput} as ${version}`);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
"sourceMap": true,
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
"noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||
"noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
},
|
||||
"exclude": ["__tests__", "lib", "node_modules"]
|
||||
|
|
Loading…
Reference in a new issue