Skip to content

Commit eb7fca7

Browse files
committed
feat: add resolvePackage
1 parent 69ad07e commit eb7fca7

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/utils/resolve-package.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { expect, test } from "vitest";
2+
import { resolvePackage } from "./resolve-package";
3+
4+
test("bare name", () => {
5+
expect(resolvePackage("foo", ["foo@1.0.0", "bar@1.0.0", "@foo/bar@1.0.0"])).toMatchInlineSnapshot(
6+
`"foo@1.0.0"`,
7+
);
8+
});
9+
10+
test("scoped name", () => {
11+
expect(
12+
resolvePackage("@foo/bar", ["foo@1.0.0", "bar@1.0.0", "@foo/bar@1.0.0"]),
13+
).toMatchInlineSnapshot(`"@foo/bar@1.0.0"`);
14+
});

lib/utils/resolve-package.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export function resolvePackage(pkgName: string, packages: string[]): string {
2+
// For the given package name (e.g., `foo`), find the corresponding installed
3+
// version ID (e.g., `foo@1.0.0`) in the list of installed packages.
4+
return packages.find((pkg) => pkg.startsWith(`${pkgName}@`))!;
5+
}

0 commit comments

Comments
 (0)