fix: respect latest only if ignoring unstable

This commit is contained in:
Rhys Arkins 2018-05-29 09:32:15 +02:00
parent 9ec45c7acf
commit 1271414cb0

View file

@ -6,7 +6,6 @@ const {
module.exports = {
filterVersions,
filterUnstable,
filterLatest,
};
@ -15,42 +14,40 @@ function filterVersions(config, fromVersion, latestVersion, versions) {
if (!fromVersion) {
return [];
}
// Leave only versions greater than current
let filteredVersions = versions.filter(version =>
isGreaterThan(version, fromVersion)
);
filteredVersions = filterUnstable(
ignoreUnstable,
fromVersion,
filteredVersions
// Return all versions if we aren't ignore unstable. Also ignore latest
if (ignoreUnstable === false) {
return filteredVersions;
}
// if current is unstable then allow unstable in the current major only
if (!isStable(fromVersion)) {
// Allow unstable only in current major
return filteredVersions.filter(
version =>
isStable(version) || getMajor(version) === getMajor(fromVersion)
);
filteredVersions = filterLatest(
}
// Normal case: remove all unstable
filteredVersions = filteredVersions.filter(isStable);
return filterLatest(
respectLatest,
fromVersion,
latestVersion,
filteredVersions
);
return filteredVersions;
}
function filterUnstable(ignoreUnstable, fromVersion, versions) {
// Filter nothing out if we are not ignoring unstable
if (ignoreUnstable === false) {
return versions;
}
// Filter out all unstable if fromVersion is stable
if (isStable(fromVersion)) {
// Remove all unstable
return versions.filter(isStable);
}
// Allow unstable only in current major
return versions.filter(
version => isStable(version) || getMajor(version) === getMajor(fromVersion)
);
}
function filterLatest(respectLatest, fromVersion, latestVersion, versions) {
// No filtering if no latest
// istanbul ignore if
if (!latestVersion) {
return versions;
}