installed

tcmts.cli.provided.installed · #awvci57z · term · runs on the server

uses node:path

An installed copy of name seen from dir (the project's node_modules, as Node would find it).

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

export function installed(name: string, dir: string): string | undefined {
  for (let d = dir; ; d = path.dirname(d)) {
    const pj = path.join(d, "node_modules", name, "package.json");
    if (fs.existsSync(pj)) return (JSON.parse(fs.readFileSync(pj, "utf8")) as { version: string }).version;
    if (path.dirname(d) === d) return undefined;
  }
}

used by