import { existsSync, realpathSync } from 'node:fs'; import { dirname, join } from 'node:path'; /** * The real directory of installed package `name` as Node finds it from `fromDir`: up the `node_modules` folders, or * null when none holds it. It is found by its folder rather than by resolving `/package.json`, which fails for a * package whose `exports` does not list that file (`@volter/sdk`). */ export function installedPackageDir(fromDir: string, name: string): string | null { for (let dir = fromDir; ; dir = dirname(dir)) { const candidate = join(dir, 'node_modules', ...name.split('/')); if (existsSync(join(candidate, 'package.json'))) return realpathSync(candidate); if (dirname(dir) === dir) return null; } }