1
0
Fork 0
mirror of https://github.com/actions/setup-node synced 2024-11-09 23:22:41 +00:00

feat: add volta as node-version-file

This commit is contained in:
Jef LeCompte 2022-06-29 12:01:42 -07:00
parent 7d610f0c26
commit 1a4ff5493d
No known key found for this signature in database
GPG key ID: 7F5BA322B5DC170C
4 changed files with 938 additions and 923 deletions

8
dist/setup/index.js vendored
View file

@ -71862,7 +71862,8 @@ function run() {
exports.run = run; exports.run = run;
function resolveVersionInput() { function resolveVersionInput() {
let version = core.getInput('node-version'); let version = core.getInput('node-version');
const versionFileInput = core.getInput('node-version-file'); const nodeVersionFile = core.getInput('node-version-file');
const versionFileInput = nodeVersionFile === 'volta' ? 'package.json' : nodeVersionFile;
if (version && versionFileInput) { if (version && versionFileInput) {
core.warning('Both node-version and node-version-file inputs are specified, only node-version will be used'); core.warning('Both node-version and node-version-file inputs are specified, only node-version will be used');
} }
@ -71874,7 +71875,12 @@ function resolveVersionInput() {
if (!fs_1.default.existsSync(versionFilePath)) { if (!fs_1.default.existsSync(versionFilePath)) {
throw new Error(`The specified node version file at: ${versionFilePath} does not exist`); throw new Error(`The specified node version file at: ${versionFilePath} does not exist`);
} }
if (nodeVersionFile === 'volta') {
version = JSON.parse(fs_1.default.readFileSync(versionFilePath, 'utf8')).volta.node;
}
else {
version = installer.parseNodeVersionFile(fs_1.default.readFileSync(versionFilePath, 'utf8')); version = installer.parseNodeVersionFile(fs_1.default.readFileSync(versionFilePath, 'utf8'));
}
core.info(`Resolved ${versionFileInput} as ${version}`); core.info(`Resolved ${versionFileInput} as ${version}`);
} }
return version; return version;

View file

@ -65,7 +65,9 @@ export async function run() {
function resolveVersionInput(): string { function resolveVersionInput(): string {
let version = core.getInput('node-version'); let version = core.getInput('node-version');
const versionFileInput = core.getInput('node-version-file'); const nodeVersionFile = core.getInput('node-version-file');
const versionFileInput =
nodeVersionFile === 'volta' ? 'package.json' : nodeVersionFile;
if (version && versionFileInput) { if (version && versionFileInput) {
core.warning( core.warning(
@ -82,14 +84,21 @@ function resolveVersionInput(): string {
process.env.GITHUB_WORKSPACE!, process.env.GITHUB_WORKSPACE!,
versionFileInput versionFileInput
); );
if (!fs.existsSync(versionFilePath)) { if (!fs.existsSync(versionFilePath)) {
throw new Error( throw new Error(
`The specified node version file at: ${versionFilePath} does not exist` `The specified node version file at: ${versionFilePath} does not exist`
); );
} }
if (nodeVersionFile === 'volta') {
version = JSON.parse(fs.readFileSync(versionFilePath, 'utf8')).volta.node;
} else {
version = installer.parseNodeVersionFile( version = installer.parseNodeVersionFile(
fs.readFileSync(versionFilePath, 'utf8') fs.readFileSync(versionFilePath, 'utf8')
); );
}
core.info(`Resolved ${versionFileInput} as ${version}`); core.info(`Resolved ${versionFileInput} as ${version}`);
} }