Skip to content

Commit 8636637

Browse files
committed
Auto merge of #1835 - sgrif:sg-proper-prerelease-checking, r=locks
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. I've manually confirmed this has the expected behavior for the crate `openssl-src`, which was reported with incorrect behavior.
2 parents 8b1d937 + 7c3ff21 commit 8636637

File tree

4 files changed

+129
-24
lines changed

4 files changed

+129
-24
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
};

package-lock.json

Lines changed: 123 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
"prettier": "^1.13.4",
8484
"qunit-dom": "^0.8.4",
8585
"sass": "^1.23.0-module.beta.1",
86+
"semver": "^6.3.0",
8687
"timekeeper": "^2.1.0"
8788
},
8889
"engines": {

0 commit comments

Comments
 (0)