Skip to content

Commit

Permalink
fix: messy issues with nodeVersionUtils helper needing semver install…
Browse files Browse the repository at this point in the history
…ed (#489)
  • Loading branch information
erunion authored Apr 1, 2022
1 parent 736e981 commit bccff2c
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 35 deletions.
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.

0 comments on commit bccff2c

Please sign in to comment.