mirror of
https://github.com/cloudflare/wrangler-action.git
synced 2024-11-25 03:14:46 +01:00
fix: semver comparison
chore: bump dependencies
This commit is contained in:
parent
65996a5230
commit
fe8fdd7fbd
4 changed files with 1106 additions and 601 deletions
1655
package-lock.json
generated
1655
package-lock.json
generated
File diff suppressed because it is too large
Load diff
15
package.json
15
package.json
|
@ -29,17 +29,18 @@
|
||||||
"check": "prettier --check ."
|
"check": "prettier --check ."
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.0",
|
"@actions/core": "^1.10.1",
|
||||||
"@actions/exec": "^1.1.1"
|
"@actions/exec": "^1.1.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@changesets/changelog-github": "^0.4.8",
|
"@changesets/changelog-github": "^0.4.8",
|
||||||
"@changesets/cli": "^2.26.2",
|
"@changesets/cli": "^2.26.2",
|
||||||
"@cloudflare/workers-types": "^4.20230814.0",
|
"@cloudflare/workers-types": "^4.20231121.0",
|
||||||
"@types/node": "^20.5.0",
|
"@types/node": "^20.10.4",
|
||||||
"@vercel/ncc": "^0.36.1",
|
"@vercel/ncc": "^0.38.1",
|
||||||
"prettier": "^3.0.1",
|
"prettier": "^3.1.0",
|
||||||
"typescript": "^5.1.6",
|
"semver": "^7.5.4",
|
||||||
"vitest": "^0.34.1"
|
"typescript": "^5.3.3",
|
||||||
|
"vitest": "^1.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
14
src/utils.ts
14
src/utils.ts
|
@ -1,5 +1,6 @@
|
||||||
import { existsSync } from "node:fs";
|
import { existsSync } from "node:fs";
|
||||||
import * as path from "node:path";
|
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.
|
* 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) {
|
export function semverCompare(version1: string, version2: string) {
|
||||||
if (version2 === "latest") return true;
|
if (version2 === "latest") return true;
|
||||||
|
|
||||||
const version1Parts = version1.split(".");
|
return semverGt(version2, version1);
|
||||||
const version2Parts = version2.split(".");
|
|
||||||
|
|
||||||
for (const version1Part of version1Parts) {
|
|
||||||
const version2Part = version2Parts.shift();
|
|
||||||
|
|
||||||
if (version1Part !== version2Part && version2Part) {
|
|
||||||
return version1Part < version2Part ? true : false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function checkWorkingDirectory(workingDirectory = ".") {
|
export function checkWorkingDirectory(workingDirectory = ".") {
|
||||||
|
|
Loading…
Reference in a new issue