Skip to content

Commit 6a44062

Browse files
committed
Auto merge of #1857 - hbina:fix_version_suggestion, r=locks
Fixed versions suggestion Previously, if it had searched everything and found nothing. However, this also means it cannot find `maxVersion`, which was what it was set to before. Thus, this commit's solution is to provide another fallback when there are no stable and non-yanked versions available. It will simply find anything that is not yet yanked even if it is unstable. If even this fails, then we truly have nothing to offer thereby offering an empty page. The code could be improved imo, but I am not especially well-versed in JavaScript.
2 parents e48470f + e7abdfc commit 6a44062

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

app/routes/crate/version.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,29 @@ export default Route.extend({
4343
.get('versions')
4444
.then(versions => {
4545
const latestStableVersion = versions.find(version => {
46+
// Find the latest version that is stable AND not-yanked.
4647
if (!isUnstableVersion(version.get('num')) && !version.get('yanked')) {
4748
return version;
4849
}
4950
});
5051

5152
if (latestStableVersion == null) {
52-
// If no stable version exists, fallback to `maxVersion`
53-
params.version_num = maxVersion;
53+
// Cannot find any version that is stable AND not-yanked.
54+
// The fact that "maxVersion" itself cannot be found means that
55+
// we have to fall back to the latest one that is unstable....
56+
const latestUnyankedVersion = versions.find(version => {
57+
// Find the latest version that is stable AND not-yanked.
58+
if (!version.get('yanked')) {
59+
return version;
60+
}
61+
});
62+
63+
if (latestStableVersion == null) {
64+
// There's not even any unyanked version...
65+
params.version_num = maxVersion;
66+
} else {
67+
params.version_num = latestUnyankedVersion;
68+
}
5469
} else {
5570
params.version_num = latestStableVersion.get('num');
5671
}

0 commit comments

Comments
 (0)