Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(integration): resolvePackageRoot error on v-prefixed tag #224

Merged
merged 2 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions integration/commits.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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)));
Expand All @@ -45,15 +45,6 @@ export async function compareCommits(
return commits;
}

async function _getTags(repo: Repository): Promise<string[]> {
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,
Expand Down
2 changes: 1 addition & 1 deletion integration/deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@molt/integration",
"version": "0.19.4",
"version": "0.19.5",
"exports": {
".": "./mod.ts",
"./commits": "./commits.ts",
Expand Down
14 changes: 10 additions & 4 deletions integration/packages.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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<string | undefined> {
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}`);
}
Expand Down
18 changes: 18 additions & 0 deletions integration/packages_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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",
),
".",
);
});
10 changes: 10 additions & 0 deletions integration/repository.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -14,6 +15,15 @@ export interface Repository<

export type KnownGitHostingPlatform = "github";

export async function getTags(repo: Repository): Promise<string[]> {
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
*/
Expand Down