readPackage

tcmts.core.analyze.readPackage · #46injy2y · term · runs on the server

uses node:fs

import fs from "node:fs";
import path from "node:path";

export function readPackage(dir: string): { name: string; version: string } | undefined {
  try {
    const json = JSON.parse(fs.readFileSync(path.join(dir, "package.json"), "utf8")) as { name: string; version: string };
    return { name: json.name, version: json.version };
  } catch {
    return undefined;
  }
}

used by