Skip to content
Snippets Groups Projects
Commit ffbf332a authored by Rhys Arkins's avatar Rhys Arkins
Browse files

fix: prune past latest versions earlier

parent 5b3d7a9f
Branches
No related tags found
No related merge requests found
......@@ -25,9 +25,23 @@ function determineUpgrades(npmDep, config) {
logger.warn({ dependency }, result.message);
return [result];
}
const versionList = Object.keys(versions);
let versionList = Object.keys(versions);
const allUpgrades = {};
let { currentVersion } = config;
// filter out versions past latest
const currentIsPastLatest = isPastLatest(
npmDep,
semver.minSatisfying(versionList, currentVersion)
);
if (currentIsPastLatest) {
logger.debug({ name: npmDep.name, currentVersion }, 'currentIsPastLatest');
}
versionList = versionList.filter(
version =>
currentIsPastLatest || // if current is past latest then don't filter any
config.respectLatest === false || // if user has configured respectLatest to false
isPastLatest(npmDep, version) === false // if the version is less than or equal to latest
);
let rangeOperator;
if (config.upgradeInRange && semver.validRange(currentVersion)) {
logger.debug({ currentVersion }, 'upgradeInRange is true');
......@@ -124,13 +138,6 @@ function determineUpgrades(npmDep, config) {
!stable.is(version) &&
semver.major(version) > semver.major(changeLogFromVersion)
)
// Ignore versions newer than "latest", unless current version is newer than the "latest"
.reject(
version =>
config.respectLatest &&
isPastLatest(npmDep, version) &&
!isPastLatest(npmDep, changeLogFromVersion)
)
// Loop through all possible versions
.forEach(newVersion => {
// Group by major versions
......@@ -447,6 +454,9 @@ function isValidVersion(input) {
}
function isPastLatest(npmDep, version) {
if (!version) {
return false;
}
if (npmDep['dist-tags'] && npmDep['dist-tags'].latest) {
return semver.gt(version, npmDep['dist-tags'].latest);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment