import * as fs from "fs";
import * as path from "path";
import { getModuleDirname } from "./getDirname.mjs";
let versionStored = undefined;
/**
 * Get the version of the package
 * @returns the version of the package
 */
export async function getVersion() {
    if (versionStored) {
        return versionStored;
    }
    const pachageJsonPath = path.join(getModuleDirname(), "../", "package.json");
    try {
        const packageJson = await fs.promises.readFile(pachageJsonPath, "utf-8");
        const { version } = JSON.parse(packageJson);
        versionStored = version;
        return version;
    }
    catch (error) {
        throw new Error(`Error reading version from ${pachageJsonPath}: ${error.message}`, {
            cause: error,
        });
    }
}
