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

Function readNpmPathDeps

src/resolution/workspace-packages.ts:652–670  ·  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

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