-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathaliases.ts
More file actions
30 lines (22 loc) · 871 Bytes
/
aliases.ts
File metadata and controls
30 lines (22 loc) · 871 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { readFileSync } from "node:fs";
import { resolve } from "node:path";
const root = import.meta.dirname;
interface PackageJson {
name: string;
workspaces?: string[];
}
const rootPkg: PackageJson = JSON.parse(readFileSync(resolve(root, "package.json"), "utf-8"));
/**
* Resolve aliases for all workspace packages to their `src/index.ts` entry
* points. Optionally exclude the current package (to avoid self-aliasing).
*/
export function aliases(exclude?: string): Record<string, string> {
const result: Record<string, string> = {};
for (const workspace of rootPkg.workspaces ?? []) {
const pkgPath = resolve(root, workspace, "package.json");
const pkg: PackageJson = JSON.parse(readFileSync(pkgPath, "utf-8"));
if (pkg.name === exclude) continue;
result[pkg.name] = resolve(root, workspace, "src/index.ts");
}
return result;
}