Skip to content

Commit

Permalink
refactor: use semver to parse out major version
Browse files Browse the repository at this point in the history
we were previously using a zero-deps approach but now that we need to install deps for the set-version-output step, we might as well use a safer approach here.
  • Loading branch information
kanadgupta committed Nov 29, 2022
1 parent 580b4f1 commit d8351d0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion __tests__/lib/getPkgVersion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
3 changes: 2 additions & 1 deletion src/lib/getPkgVersion.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fetch from 'node-fetch';
import semver from 'semver';

import pkg from '../../package.json';

Expand All @@ -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;
}

/**
Expand Down

0 comments on commit d8351d0

Please sign in to comment.