Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add volta as node-version-file #532

Merged
merged 21 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: volta check
  • Loading branch information
jef committed Jul 27, 2022
commit 57cec77d94c8910e67960b27121ac8f968c37ccc
3 changes: 3 additions & 0 deletions __tests__/data/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"engines": {
"node": ">=14.0.0"
},
"volta": {
"node": "14.0.0"
}
}
28 changes: 0 additions & 28 deletions __tests__/installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,34 +592,6 @@ describe('setup-node', () => {
);
});

it('reads node-version-file if provided (package.json, volta)', async () => {
// Arrange
const versionFile = 'package.json';
const versionSpec = fs.readFileSync(
path.join(__dirname, 'data', versionFile),
'utf8'
);
const expectedVersionSpec = '16.15.1';
process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data');
inputs['node-version-file'] = versionFile;

parseNodeVersionSpy.mockImplementation(() => expectedVersionSpec);
existsSpy.mockImplementationOnce(
input => input === path.join(__dirname, 'data', versionFile)
);

// Act
await main.run();

// Assert
expect(existsSpy).toHaveBeenCalledTimes(1);
expect(existsSpy).toHaveReturnedWith(true);
expect(parseNodeVersionSpy).toHaveBeenCalledWith(versionSpec);
expect(logSpy).toHaveBeenCalledWith(
`Resolved ${versionFile} as ${expectedVersionSpec}`
);
});

it('reads package.json as node-version-file if provided', async () => {
// Arrange
const versionSpec = fs.readFileSync(
Expand Down
2 changes: 1 addition & 1 deletion src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ export function parseNodeVersionFile(contents: string): string {
// Try parsing the file as an NPM `package.json`
// file.
nodeVersion = JSON.parse(contents).engines?.node;

if (!nodeVersion) JSON.parse(contents).volta?.node;
if (!nodeVersion) throw new Error();
} catch (err) {
// In the case of an unknown format,
Expand Down