Skip to content

Commit c4bfb53

Browse files
committed
Fixed version suggestion logic.
Previously, if it had search everything and found nothing, that means it also cannot find `maxVersion`. Thus, this commit's solution is to 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.
1 parent 08e2e68 commit c4bfb53

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

app/routes/crate/version.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default Route.extend({
1111

1212
flashMessages: service(),
1313

14-
refreshAfterLogin: observer('session.isLoggedIn', function() {
14+
refreshAfterLogin: observer('session.isLoggedIn', function () {
1515
this.refresh();
1616
}),
1717

@@ -43,14 +43,28 @@ 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+
if (latestStableVersion == null) {
63+
// There's not even any unyanked version...
64+
params.version_num = maxVersion;
65+
} else {
66+
params.version_num = latestUnyankedVersion;
67+
}
5468
} else {
5569
params.version_num = latestStableVersion.get('num');
5670
}

0 commit comments

Comments
 (0)