Fix: use switch for version compare

This commit is contained in:
eight 2017-11-09 05:48:54 +08:00
parent 90be1dae25
commit 08c7004123

View File

@ -107,12 +107,15 @@ var updater = {
const json = usercss.buildMeta(text); const json = usercss.buildMeta(text);
const {usercssData: {version}} = style; const {usercssData: {version}} = style;
const {usercssData: {version: newVersion}} = json; const {usercssData: {version: newVersion}} = json;
switch (Math.sign(semverCompare(version, newVersion))) {
case 0:
// re-install is invalid in a soft upgrade // re-install is invalid in a soft upgrade
if (semverCompare(version, newVersion) === 0 && !ignoreDigest) { if (!ignoreDigest) {
return Promise.reject(updater.SAME_VERSION); return Promise.reject(updater.SAME_VERSION);
} }
break;
case 1:
// downgrade is always invalid // downgrade is always invalid
if (semverCompare(version, newVersion) > 0) {
return Promise.reject(updater.ERROR_VERSION); return Promise.reject(updater.ERROR_VERSION);
} }
return usercss.buildCode(json); return usercss.buildCode(json);