MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / readNpmPathDeps

Function readNpmPathDeps

src/resolution/workspace-packages.ts:651–669  ·  view source on GitHub ↗

A package.json's dependencies on a path (`file:`, `link:`, `portal:`), from every dependency field → [name, target].

(manifestAbs: string)

Source from the content-addressed store, hash-verified

649
650/** A package.json's dependencies on a path (`file:`, `link:`, `portal:`), from every dependency field → [name, target]. */
651function readNpmPathDeps(manifestAbs: string): Array<[string, string]> {
652 let pkg: Record<string, unknown> | null;
653 try {
654 pkg = JSON.parse(fs.readFileSync(manifestAbs, 'utf-8')) as Record<string, unknown> | null;
655 } catch {
656 return [];
657 }
658 if (!pkg || typeof pkg !== 'object') return [];
659 const out: Array<[string, string]> = [];
660 for (const field of ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies']) {
661 const deps = pkg[field];
662 if (!deps || typeof deps !== 'object') continue;
663 for (const [name, value] of Object.entries(deps as Record<string, unknown>)) {
664 const m = typeof value === 'string' ? /^(?:file|link|portal):(.+)$/.exec(value.trim()) : null;
665 if (m && m[1]!.trim()) out.push([name, m[1]!.trim()]);
666 }
667 }
668 return out;
669}
670
671/** Parse one oh-package.json5's dependencies → [name, file-target] pairs. */
672function readOhpmFileDeps(manifestAbs: string): Array<[string, string]> {

Callers 1

collectPathDepsFunction · 0.85

Calls 3

parseMethod · 0.80
pushMethod · 0.80
execMethod · 0.65

Tested by

no test coverage detected