24 lines
725 B
TypeScript
24 lines
725 B
TypeScript
import fs from "node:fs/promises";
|
|
import path from "node:path";
|
|
|
|
export async function readPackageVersion(root: string): Promise<string | null> {
|
|
try {
|
|
const raw = await fs.readFile(path.join(root, "package.json"), "utf-8");
|
|
const parsed = JSON.parse(raw) as { version?: string };
|
|
return typeof parsed?.version === "string" ? parsed.version : null;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export async function readPackageName(root: string): Promise<string | null> {
|
|
try {
|
|
const raw = await fs.readFile(path.join(root, "package.json"), "utf-8");
|
|
const parsed = JSON.parse(raw) as { name?: string };
|
|
const name = parsed?.name?.trim();
|
|
return name ? name : null;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|