From 08c70041231a45eaa74e74fe9f549cad440a0ea0 Mon Sep 17 00:00:00 2001 From: eight Date: Thu, 9 Nov 2017 05:48:54 +0800 Subject: [PATCH] Fix: use switch for version compare --- background/update.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/background/update.js b/background/update.js index d9bfd4be..eef3b9cd 100644 --- a/background/update.js +++ b/background/update.js @@ -107,13 +107,16 @@ var updater = { const json = usercss.buildMeta(text); const {usercssData: {version}} = style; const {usercssData: {version: newVersion}} = json; - // re-install is invalid in a soft upgrade - if (semverCompare(version, newVersion) === 0 && !ignoreDigest) { - return Promise.reject(updater.SAME_VERSION); - } - // downgrade is always invalid - if (semverCompare(version, newVersion) > 0) { - return Promise.reject(updater.ERROR_VERSION); + switch (Math.sign(semverCompare(version, newVersion))) { + case 0: + // re-install is invalid in a soft upgrade + if (!ignoreDigest) { + return Promise.reject(updater.SAME_VERSION); + } + break; + case 1: + // downgrade is always invalid + return Promise.reject(updater.ERROR_VERSION); } return usercss.buildCode(json); });