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

fix: messy issues with nodeVersionUtils helper needing semver installed #489

Merged
merged 1 commit into from
Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion __tests__/bin.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { exec } = require('child_process');
const { isSupportedNodeVersion } = require('../src/lib/nodeVersionUtils');
const isSupportedNodeVersion = require('../src/lib/isSupportedNodeVersion');
const pkg = require('../package.json');

describe('bin', () => {
Expand Down
11 changes: 11 additions & 0 deletions __tests__/lib/getNodeVersion.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const getNodeVersion = require('../../src/lib/getNodeVersion');
const pkg = require('../../package.json');
const semver = require('semver');

describe('#getNodeVersion()', () => {
it('should extract version that matches range in package.json', () => {
const version = parseInt(getNodeVersion(), 10);
const cleanedVersion = semver.valid(semver.coerce(version));
expect(semver.satisfies(cleanedVersion, pkg.engines.node)).toBe(true);
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const { isSupportedNodeVersion, getNodeVersion } = require('../../src/lib/nodeVersionUtils');
const pkg = require('../../package.json');
const semver = require('semver');
const isSupportedNodeVersion = require('../../src/lib/isSupportedNodeVersion');

describe('#isSupportedNodeVersion()', () => {
it('should return true for a supported version of node', () => {
Expand All @@ -14,11 +12,3 @@ describe('#isSupportedNodeVersion()', () => {
expect(isSupportedNodeVersion('18.0.0')).toBe(false);
});
});

describe('#getNodeVersion()', () => {
it('should extract version that matches range in package.json', () => {
const version = parseInt(getNodeVersion(), 10);
const cleanedVersion = semver.valid(semver.coerce(version));
expect(semver.satisfies(cleanedVersion, pkg.engines.node)).toBe(true);
});
});
2 changes: 1 addition & 1 deletion bin/rdme
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const updateNotifier = require('update-notifier');
const pkg = require('../package.json');

const isGHA = require('../src/lib/isGitHub');
const { isSupportedNodeVersion } = require('../src/lib/nodeVersionUtils');
const isSupportedNodeVersion = require('../src/lib/isSupportedNodeVersion');

updateNotifier({ pkg }).notify();

Expand Down
2 changes: 1 addition & 1 deletion bin/set-version-output
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /usr/bin/env node

const { getNodeVersion } = require('../src/lib/nodeVersionUtils');
const getNodeVersion = require('../src/lib/getNodeVersion');
const pkg = require('../package.json');

const name1 = 'RDME_VERSION';
Expand Down
10 changes: 10 additions & 0 deletions src/lib/getNodeVersion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const pkg = require('../../package.json');

/**
* @example 14
* @returns {String} The maximum major Node.js version specified in the package.json
*/
module.exports = function getNodeVersion() {
const { node } = pkg.engines;
return Array.from(node.matchAll(/\d+/g)).pop();
};
10 changes: 10 additions & 0 deletions src/lib/isSupportedNodeVersion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const semver = require('semver');
const pkg = require('../../package.json');

/**
* Determine if the current version of Node is one that we explicitly support.
*
*/
module.exports = function isSupportedNodeVersion(version) {
return semver.satisfies(semver.coerce(version), pkg.engines.node);
};
21 changes: 0 additions & 21 deletions src/lib/nodeVersionUtils.js

This file was deleted.