import { readFileSync, existsSync } from "node:fs";
import { fileURLToPath } from "node:url";
import path from "node:path";
export function getPackageVersion(): string {
const __dirname = path.dirname(fileURLToPath(import.meta.url));
// Adjust path if this util is called from dist/version.mjs, it needs to find package.json at ../package.json relative to dist/
const packageJsonPath = path.resolve(__dirname, "../package.json");
let version = "0.0.0"; // Default or fallback version
try {
if (existsSync(packageJsonPath)) {
const pkg = JSON.parse(readFileSync(packageJsonPath, "utf8"));
if (pkg.version) version = pkg.version;
}
} catch (e) {
console.error("Warning: Could not read package.json version", e);
}
return version;
}