fix: semver comparison

chore: bump dependencies
This commit is contained in:
James Ross 2023-12-09 18:27:18 +00:00
parent 65996a5230
commit fe8fdd7fbd
No known key found for this signature in database
GPG key ID: 49E8B07166BE49AB
4 changed files with 1106 additions and 601 deletions

1655
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -29,17 +29,18 @@
"check": "prettier --check ."
},
"dependencies": {
"@actions/core": "^1.10.0",
"@actions/core": "^1.10.1",
"@actions/exec": "^1.1.1"
},
"devDependencies": {
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.2",
"@cloudflare/workers-types": "^4.20230814.0",
"@types/node": "^20.5.0",
"@vercel/ncc": "^0.36.1",
"prettier": "^3.0.1",
"typescript": "^5.1.6",
"vitest": "^0.34.1"
"@cloudflare/workers-types": "^4.20231121.0",
"@types/node": "^20.10.4",
"@vercel/ncc": "^0.38.1",
"prettier": "^3.1.0",
"semver": "^7.5.4",
"typescript": "^5.3.3",
"vitest": "^1.0.3"
}
}

View file

@ -30,3 +30,26 @@ describe("checkWorkingDirectory", () => {
);
});
});
describe("semverCompare", () => {
test.each([
["1.2.3", "1.2.3", false],
["1.2.2", "1.2.3", true],
["2.0.0", "3.0.0", true],
["3.1.0", "3.1.1", true],
["3.1.0", "3.5.0", true],
["3.1.0", "3.10.0", true],
["3.1.0", "3.15.0", true],
["3.10.0", "3.1.0", false],
["3.20.0", "3.2.0", false],
["3.1.0", "latest", true],
["4.0.0", "latest", true],
])(
"should semver compare %s vs %s correctly, expecting %s",
(version1, version2, expected) => {
const isVersion1LessThanVersion2 = semverCompare(version1, version2);
expect(isVersion1LessThanVersion2).toBe(expected);
},
);
});

View file

@ -1,5 +1,6 @@
import { existsSync } from "node:fs";
import * as path from "node:path";
import semverGt from "semver/functions/gt";
/**
* A helper function to compare two semver versions. If the second arg is greater than the first arg, it returns true.
@ -7,18 +8,7 @@ import * as path from "node:path";
export function semverCompare(version1: string, version2: string) {
if (version2 === "latest") return true;
const version1Parts = version1.split(".");
const version2Parts = version2.split(".");
for (const version1Part of version1Parts) {
const version2Part = version2Parts.shift();
if (version1Part !== version2Part && version2Part) {
return version1Part < version2Part ? true : false;
}
}
return false;
return semverGt(version2, version1);
}
export function checkWorkingDirectory(workingDirectory = ".") {