Skip to content

Commit

Permalink
Refactor getLatestTag to return latest version only
Browse files Browse the repository at this point in the history
  • Loading branch information
jennyEckstein committed Jan 8, 2021
1 parent 9097341 commit 494c95b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@ async function getLatestVersions(name) {
}

async function getLatestTag(name) {
const { stdout } = await execAsync(`npm view ${name} dist-tags --json`);
try {
return JSON.parse(stdout);
const { stdout } = await execAsync(`npm view ${name} dist-tags --json`);
const { latest } = JSON.parse(stdout);
return latest;
} catch (err) {
throw new Error(`Failed to parse output from NPM view - ${err.toString()}`);
}
}

async function getLatestVersion(name, wanted) {
const versions = await getLatestVersions(name);
const { latest } = await getLatestTag(name);
const latest = await getLatestTag(name);
const applicableVersions = versions.filter(i => semver.satisfies(i, wanted));
applicableVersions.sort((a, b) => semver.rcompare(a, b));

Expand Down

0 comments on commit 494c95b

Please sign in to comment.