浏览代码

Fix SemVersion.isGtOrEq

corpglory-dev 6 年之前
父节点
当前提交
ee132c1091
共有 1 个文件被更改,包括 14 次插入1 次删除
  1. 14 1
      public/app/core/utils/version.ts

+ 14 - 1
public/app/core/utils/version.ts

@@ -20,12 +20,25 @@ export class SemVersion {
 
   isGtOrEq(version: string): boolean {
     const compared = new SemVersion(version);
-    return !(this.major < compared.major || this.minor < compared.minor || this.patch < compared.patch);
+
+    for (let i = 0; i < this.comparable.length; ++i) {
+      if (this.comparable[i] > compared.comparable[i]) {
+        return true;
+      }
+      if (this.comparable[i] < compared.comparable[i]) {
+        return false;
+      }
+    }
+    return true;
   }
 
   isValid(): boolean {
     return _.isNumber(this.major);
   }
+
+  get comparable() {
+    return [this.major, this.minor, this.patch];
+  }
 }
 
 export function isVersionGtOrEq(a: string, b: string): boolean {