Skip to content

Commit a4fbaa7

Browse files
committed
Don't consider versions with build metadata to be unstable
Our backend was behaving properly in this regard, but the front end was considering any version that had build metadata to be unstable. There's no reason for us to have this detection be hand-rolled, we can use a proper semver library to determine whether something is a prerelease or not.
1 parent 66c60dc commit a4fbaa7

File tree

4 files changed

+194
-44
lines changed

4 files changed

+194
-44
lines changed

app/routes/crate/version.js

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { observer } from '@ember/object';
22
import Route from '@ember/routing/route';
33
import { inject as service } from '@ember/service';
4+
import semver from 'semver';
45

56
import fetch from 'fetch';
67
import ajax from 'ember-fetch/ajax';
@@ -20,27 +21,7 @@ export default Route.extend({
2021
const controller = this.controllerFor(this.routeName);
2122
const maxVersion = crate.get('max_version');
2223

23-
const isUnstableVersion = version => {
24-
const versionLen = version.length;
25-
let majorMinorPatchChars = 0;
26-
let result = false;
27-
28-
for (let i = 0; i < versionLen; i++) {
29-
const char = version.charAt(i);
30-
31-
if (!isNaN(parseInt(char)) || char === '.') {
32-
majorMinorPatchChars++;
33-
} else {
34-
break;
35-
}
36-
}
37-
38-
if (versionLen !== majorMinorPatchChars) {
39-
result = true;
40-
}
41-
42-
return result;
43-
};
24+
const isUnstableVersion = version => !!semver.prerelease(version);
4425

4526
const fetchCrateDocumentation = () => {
4627
if (!crate.get('documentation') || crate.get('documentation').substr(0, 16) === 'https://docs.rs/') {

ember-cli-build.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ module.exports = function(defaults) {
5151
app.import('node_modules/timekeeper/lib/timekeeper.js', {
5252
using: [{ transformation: 'cjs', as: 'timekeeper' }],
5353
});
54+
app.import('node_modules/semver/semver.js', {
55+
using: [{ transformation: 'cjs', as: 'semver' }],
56+
});
5457

5558
return app.toTree();
5659
};

0 commit comments

Comments
 (0)