Skip to content

Commit 57cec77

Browse files
committed
refactor: volta check
1 parent 5a01179 commit 57cec77

File tree

3 files changed

+4
-29
lines changed

3 files changed

+4
-29
lines changed

__tests__/data/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"engines": {
33
"node": ">=14.0.0"
4+
},
5+
"volta": {
6+
"node": "14.0.0"
47
}
58
}

__tests__/installer.test.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -592,34 +592,6 @@ describe('setup-node', () => {
592592
);
593593
});
594594

595-
it('reads node-version-file if provided (package.json, volta)', async () => {
596-
// Arrange
597-
const versionFile = 'package.json';
598-
const versionSpec = fs.readFileSync(
599-
path.join(__dirname, 'data', versionFile),
600-
'utf8'
601-
);
602-
const expectedVersionSpec = '16.15.1';
603-
process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data');
604-
inputs['node-version-file'] = versionFile;
605-
606-
parseNodeVersionSpy.mockImplementation(() => expectedVersionSpec);
607-
existsSpy.mockImplementationOnce(
608-
input => input === path.join(__dirname, 'data', versionFile)
609-
);
610-
611-
// Act
612-
await main.run();
613-
614-
// Assert
615-
expect(existsSpy).toHaveBeenCalledTimes(1);
616-
expect(existsSpy).toHaveReturnedWith(true);
617-
expect(parseNodeVersionSpy).toHaveBeenCalledWith(versionSpec);
618-
expect(logSpy).toHaveBeenCalledWith(
619-
`Resolved ${versionFile} as ${expectedVersionSpec}`
620-
);
621-
});
622-
623595
it('reads package.json as node-version-file if provided', async () => {
624596
// Arrange
625597
const versionSpec = fs.readFileSync(

src/installer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ export function parseNodeVersionFile(contents: string): string {
505505
// Try parsing the file as an NPM `package.json`
506506
// file.
507507
nodeVersion = JSON.parse(contents).engines?.node;
508-
508+
if (!nodeVersion) JSON.parse(contents).volta?.node;
509509
if (!nodeVersion) throw new Error();
510510
} catch (err) {
511511
// In the case of an unknown format,

0 commit comments

Comments
 (0)