diff --git a/__tests__/lib/getPkgVersion.test.ts b/__tests__/lib/getPkgVersion.test.ts index 87a8e109d..0d957ff76 100644 --- a/__tests__/lib/getPkgVersion.test.ts +++ b/__tests__/lib/getPkgVersion.test.ts @@ -6,7 +6,7 @@ import { getNodeVersion, getPkgVersion } from '../../src/lib/getPkgVersion'; describe('#getNodeVersion()', () => { it('should extract version that matches range in package.json', () => { - const version = parseInt(getNodeVersion(), 10); + const version = getNodeVersion(); const cleanedVersion = semver.valid(semver.coerce(version)); expect(semver.satisfies(cleanedVersion as string, pkg.engines.node)).toBe(true); }); diff --git a/src/lib/getPkgVersion.ts b/src/lib/getPkgVersion.ts index 5682345e9..136f01121 100644 --- a/src/lib/getPkgVersion.ts +++ b/src/lib/getPkgVersion.ts @@ -1,4 +1,5 @@ import fetch from 'node-fetch'; +import semver from 'semver'; import pkg from '../../package.json'; @@ -11,7 +12,7 @@ const registryUrl = 'https://registry.npmjs.com/rdme'; */ export function getNodeVersion() { const { node } = pkg.engines; - return Array.from(node.matchAll(/\d+/g)).pop().toString(); + return semver.minVersion(node).major; } /**