From d27b5d60be42d3afab21dc32b8bfc4609407482c Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Tue, 24 Jan 2023 01:43:01 +0100 Subject: [PATCH] buildx: optional version for versionSatisfies Signed-off-by: CrazyMax --- __tests__/buildx.test.ts | 3 ++- src/buildx.ts | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/__tests__/buildx.test.ts b/__tests__/buildx.test.ts index 6937d5a..0db98af 100644 --- a/__tests__/buildx.test.ts +++ b/__tests__/buildx.test.ts @@ -191,7 +191,8 @@ describe('versionSatisfies', () => { ['bda4882a65349ca359216b135896bddc1d92461c', '>0.1.0', false], ['f117971', '>0.6.0', true] ])('given %p', async (version, range, expected) => { - expect(Buildx.versionSatisfies(version, range)).toBe(expected); + const buildx = new Buildx(); + expect(await buildx.versionSatisfies(range, version)).toBe(expected); }); }); diff --git a/src/buildx.ts b/src/buildx.ts index 08f6d38..5056598 100644 --- a/src/buildx.ts +++ b/src/buildx.ts @@ -86,8 +86,9 @@ export class Buildx { return matches[1]; } - public static versionSatisfies(version: string, range: string): boolean { - return semver.satisfies(version, range) || /^[0-9a-f]{7}$/.exec(version) !== null; + public async versionSatisfies(range: string, version?: string): Promise { + const ver = version ?? (await this.getVersion()); + return semver.satisfies(ver, range) || /^[0-9a-f]{7}$/.exec(ver) !== null; } public getBuildImageIDFilePath(): string {