Skip to content

Commit 69ad07e

Browse files
committed
feat: add packageId
1 parent 393ff79 commit 69ad07e

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/utils/package-id.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { expect, test } from "vitest";
2+
import { packageId } from "./package-id";
3+
4+
test("bare package, root subpath", () => {
5+
expect(packageId("foo", ".")).toMatchInlineSnapshot(`"foo"`);
6+
});
7+
8+
test("scoped package, root subpath", () => {
9+
expect(packageId("@foo/bar", ".")).toMatchInlineSnapshot(`"@foo/bar"`);
10+
});
11+
12+
test("bare package, other subpath", () => {
13+
expect(packageId("foo", "my/subpath")).toMatchInlineSnapshot(`"foo/my/subpath"`);
14+
});
15+
16+
test("scoped package, other subpath", () => {
17+
expect(packageId("@foo/bar", "my/subpath")).toMatchInlineSnapshot(`"@foo/bar/my/subpath"`);
18+
});

lib/utils/package-id.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export function packageId(pkg: string, subpath: string): string {
2+
// Assume subpath was already normalized.
3+
if (subpath === ".") return pkg;
4+
return `${pkg}/${subpath}`;
5+
}

0 commit comments

Comments
 (0)