diff --git a/__tests__/bin.test.js b/__tests__/bin.test.js index a9a6b31e2..52f1f3703 100644 --- a/__tests__/bin.test.js +++ b/__tests__/bin.test.js @@ -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', () => { diff --git a/__tests__/lib/getNodeVersion.test.js b/__tests__/lib/getNodeVersion.test.js new file mode 100644 index 000000000..2fc7c60d0 --- /dev/null +++ b/__tests__/lib/getNodeVersion.test.js @@ -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); + }); +}); diff --git a/__tests__/lib/nodeVersionUtils.test.js b/__tests__/lib/isSupportedNodeVersion.test.js similarity index 50% rename from __tests__/lib/nodeVersionUtils.test.js rename to __tests__/lib/isSupportedNodeVersion.test.js index abc9c1e84..16d13cd03 100644 --- a/__tests__/lib/nodeVersionUtils.test.js +++ b/__tests__/lib/isSupportedNodeVersion.test.js @@ -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', () => { @@ -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); - }); -}); diff --git a/bin/rdme b/bin/rdme index d870fdcb9..7e12550c7 100755 --- a/bin/rdme +++ b/bin/rdme @@ -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(); diff --git a/bin/set-version-output b/bin/set-version-output index 76b0bf32a..0779ff36b 100755 --- a/bin/set-version-output +++ b/bin/set-version-output @@ -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'; diff --git a/src/lib/getNodeVersion.js b/src/lib/getNodeVersion.js new file mode 100644 index 000000000..fd6b4dfce --- /dev/null +++ b/src/lib/getNodeVersion.js @@ -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(); +}; diff --git a/src/lib/isSupportedNodeVersion.js b/src/lib/isSupportedNodeVersion.js new file mode 100644 index 000000000..84f93c84a --- /dev/null +++ b/src/lib/isSupportedNodeVersion.js @@ -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); +}; diff --git a/src/lib/nodeVersionUtils.js b/src/lib/nodeVersionUtils.js deleted file mode 100644 index 33b9b3bc3..000000000 --- a/src/lib/nodeVersionUtils.js +++ /dev/null @@ -1,21 +0,0 @@ -const semver = require('semver'); -const pkg = require('../../package.json'); - -module.exports = { - /** - * Determine if the current version of Node is one that we explicitly support. - * - */ - isSupportedNodeVersion(version) { - return semver.satisfies(semver.coerce(version), pkg.engines.node); - }, - - /** - * @example 14 - * @returns {String} The maximum major Node.js version specified in the package.json - */ - getNodeVersion() { - const { node } = pkg.engines; - return Array.from(node.matchAll(/\d+/g)).pop(); - }, -};