From 51f1ab6d0c61506923ffd168b8ce2c5141dd8e9f Mon Sep 17 00:00:00 2001 From: hasundue Date: Sat, 3 Aug 2024 22:18:53 +0900 Subject: [PATCH 1/2] fix(integration): `resolvePackageRoot` error on v-prefixed tag --- integration/commits.ts | 13 ++----------- integration/packages.ts | 14 ++++++++++---- integration/packages_test.ts | 18 ++++++++++++++++++ integration/repository.ts | 10 ++++++++++ 4 files changed, 40 insertions(+), 15 deletions(-) diff --git a/integration/commits.ts b/integration/commits.ts index bbccaa71..4a447b59 100644 --- a/integration/commits.ts +++ b/integration/commits.ts @@ -1,4 +1,4 @@ -import type { Repository } from "./repository.ts"; +import { getTags, type Repository } from "./repository.ts"; import * as github from "./github.ts"; import { equals, parse } from "@std/semver"; @@ -30,7 +30,7 @@ export async function compareCommits( // // Otherwise, fetch the commits from the Git hosting platform // - const tags = await _getTags(repo); + const tags = await getTags(repo); // Tags and versions not necessarily include the "v" prefix consistently const base = tags.find((it) => equals(parse(it), parse(from))); const head = tags.find((it) => equals(parse(it), parse(to))); @@ -45,15 +45,6 @@ export async function compareCommits( return commits; } -async function _getTags(repo: Repository): Promise { - switch (repo.host) { - case "github": - return await github.getTags(repo); - default: - throw new Error(`Unsupported Git hosting platform: ${repo.host}`); - } -} - async function _compareCommits( repo: Repository, base: string, diff --git a/integration/packages.ts b/integration/packages.ts index 6cff33e9..38edc700 100644 --- a/integration/packages.ts +++ b/integration/packages.ts @@ -1,8 +1,9 @@ import { match, placeholder as _ } from "@core/match"; import type { DependencySpec } from "@molt/core/specs"; import * as Spec from "@molt/core/specs"; -import type { Repository } from "./repository.ts"; +import { getTags, type Repository } from "./repository.ts"; import * as github from "./github.ts"; +import { equals, parse as SemVer } from "@std/semver"; /** * A known package registry. @@ -136,14 +137,19 @@ export function fromDependency( return tryParse(Spec.stringify(dependency, "kind", "name")); } -export function resolvePackageRoot( +export async function resolvePackageRoot( repo: Repository, pkg: Package, - ref?: string, + version?: string, ): Promise { + const tags = await getTags(repo); + const ref = version + ? tags.find((it) => equals(SemVer(it), SemVer(version))) + : undefined; switch (repo.host) { - case "github": + case "github": { return github.resolvePackageRoot(repo, pkg, ref); + } default: throw new Error(`Unsupported hosting platform: ${repo.host}`); } diff --git a/integration/packages_test.ts b/integration/packages_test.ts index d7835f4a..289506ce 100644 --- a/integration/packages_test.ts +++ b/integration/packages_test.ts @@ -4,9 +4,11 @@ import { is, type Package, parse, + resolvePackageRoot, stringify, tryParse, } from "./packages.ts"; +import type { Repository } from "./repository.ts"; Deno.test("parse", () => { assertEquals( @@ -92,3 +94,19 @@ Deno.test("fromDependency - deno.land", () => { }); assertEquals(result, undefined); }); + +Deno.test("resolvePackageRoot - @core/unknownutil", async () => { + const repo: Repository = { + host: "github", + owner: "jsr-core", + name: "unknownutil", + }; + assertEquals( + await resolvePackageRoot( + repo, + parse("jsr:@core/unknownutil"), + "4.0.0", + ), + ".", + ); +}); diff --git a/integration/repository.ts b/integration/repository.ts index 06d7cf1d..7fb9a4e0 100644 --- a/integration/repository.ts +++ b/integration/repository.ts @@ -1,5 +1,6 @@ import { ensure, is } from "@core/unknownutil"; import { type Package, stringify } from "./packages.ts"; +import * as github from "./github.ts"; /** * A git repository on a hosting platform. @@ -14,6 +15,15 @@ export interface Repository< export type KnownGitHostingPlatform = "github"; +export async function getTags(repo: Repository): Promise { + switch (repo.host) { + case "github": + return await github.getTags(repo); + default: + throw new Error(`Unsupported Git hosting platform: ${repo.host}`); + } +} + /** * Resolve the repository of the given package */ From f50797239c5e0389ee3e53bb2a6a6c74c46bb504 Mon Sep 17 00:00:00 2001 From: hasundue Date: Sat, 3 Aug 2024 22:19:06 +0900 Subject: [PATCH 2/2] chore: release 0.19.5 --- integration/deno.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration/deno.json b/integration/deno.json index d73e87b7..76035696 100644 --- a/integration/deno.json +++ b/integration/deno.json @@ -1,6 +1,6 @@ { "name": "@molt/integration", - "version": "0.19.4", + "version": "0.19.5", "exports": { ".": "./mod.ts", "./commits": "./commits.ts",