Skip to content

Commit

Permalink
moved array wrapper to getLatestVersions
Browse files Browse the repository at this point in the history
  • Loading branch information
Lam, Anson committed Oct 20, 2021
1 parent aae99e4 commit 58b6a7f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ async function getLatestVersions(name) {
isValidNpmPackageName(name);
const { stdout } = await execAsync(`npm view ${name} versions --json`);
try {
return JSON.parse(stdout);
const versions = JSON.parse(stdout);
return Array.isArray(versions) ? versions : [versions];
} catch (err) {
throw new Error(`Failed to parse output from NPM view - ${err.toString()}`);
}
Expand All @@ -46,12 +47,11 @@ async function getLatestTag(name) {
async function getLatestVersion(name, wanted) {
const versions = await getLatestVersions(name);
const latest = await getLatestTag(name);
const versionsArray = typeof versions === 'string' ? [versions] : versions;
let applicableVersions = versionsArray.filter((i) => semver.satisfies(i, wanted));
let applicableVersions = versions.filter((i) => semver.satisfies(i, wanted));

const prereleases = [];
if (semverPrerelease(wanted.slice(1))) {
for (const version of versionsArray) {
for (const version of versions) {
if (semverPrerelease(version)) {
prereleases.push(version);
}
Expand Down

0 comments on commit 58b6a7f

Please sign in to comment.