hasTypes
uses node:path
Whether an installed package carries its own types.
import type { Layout } from "#codebase/tcmts/loader"; import fs from "node:fs"; import path from "node:path"; export function hasTypes(lay: Layout, alias: string): boolean { const dir = path.join(lay.cacheDir, "node_modules", alias); try { const pkg = JSON.parse(fs.readFileSync(path.join(dir, "package.json"), "utf8")) as Record<string, unknown>; return !!(pkg.types || pkg.typings) || JSON.stringify(pkg.exports ?? "").includes('"types"') || fs.existsSync(path.join(dir, "index.d.ts")); } catch { return true; } }