diff --git a/integration/commits.ts b/integration/commits.ts index bbccaa7..4a447b5 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/deno.json b/integration/deno.json index d73e87b..7603569 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", diff --git a/integration/packages.ts b/integration/packages.ts index 6cff33e..38edc70 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 d7835f4..289506c 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 06d7cf1..7fb9a4e 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 */