Skip to content

Commit

Permalink
Merge pull request #3238 from ubports/fix/version-comparison
Browse files Browse the repository at this point in the history
lib: updater: fix semver comparison
  • Loading branch information
Flohack74 committed Apr 21, 2023
2 parents ee546ee + 35b7168 commit 1f33754
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/lib/updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

const axios = require("axios");
const packageInfo = require("../../package.json");
const semverGt = require("semver/functions/gt");
const semverLt = require("semver/functions/lt");

/**
* UBports Installer version management
Expand Down Expand Up @@ -64,20 +66,18 @@ class Updater {
* resolves update url if the installer is outdated, null otherwise
* @returns {Promise<String>}
*/
isOutdated() {
return this.getLatestVersion().then(latest =>
packageInfo.version < latest ? this.updateUrl : null
);
async isOutdated() {
const latest = await this.getLatestVersion();
return semverLt(packageInfo.version, latest) ? this.updateUrl : null;
}

/**
* resolves update url if the installer is a prerelease, null otherwise
* @returns {Promise<String>}
*/
isPrerelease() {
return this.getLatestVersion().then(latest =>
packageInfo.version > latest ? this.updateUrl : null
);
async isPrerelease() {
const latest = await this.getLatestVersion();
return semverGt(packageInfo.version, latest) ? this.updateUrl : null;
}
}

Expand Down

0 comments on commit 1f33754

Please sign in to comment.