Skip to content

Commit

Permalink
fix: Correct minVersion required (#15)
Browse files Browse the repository at this point in the history
* fix minVersion required

* x
  • Loading branch information
sylc authored Feb 1, 2023
1 parent 816b5bd commit 720fd2c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/utils/versions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { assert } from "../../deps_test.ts";
import { assertMinVersion } from "./versions.ts";

Deno.test("assertMinVersion", () => {
// should be good
assert(assertMinVersion("1.1.5", "1.0.1"));
assert(assertMinVersion("2.0.5", "1.0.1"));
assert(assertMinVersion("1.30.0", "1.29.1"));
// not good
assert(!assertMinVersion("1.0.5", "2.0.0"));
assert(!assertMinVersion("1.27.5", "1.30.0"));
});
20 changes: 14 additions & 6 deletions src/utils/versions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
// ** does not handee '- name'
export function assertMinVersion(version: string, minRequired: string) {
const minArr = minRequired.split(".");
return version.split(".").every((v, i) => {
if (i < 3 && +v >= +minArr[i]) return true;
return false;
});
const minArr = minRequired.split(".").map((v) => +v);
const versionArr = version.split(".").map((v) => +v);

// compare major
if (versionArr[0] < minArr[0]) return false;
if (versionArr[0] > minArr[0]) return true;

// compare minor
if (versionArr[1] < minArr[1]) return false;
if (versionArr[1] > minArr[1]) return true;

// compare patch
if (versionArr[2] < minArr[2]) return false;
return true;
}

0 comments on commit 720fd2c

Please sign in to comment.