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

Function readOhpmMain

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

* Read an ohpm member's declared entry file: ` /oh-package.json5`'s * `main`, normalized to a projectRoot-relative posix path. Null when the * manifest or field is missing/escaping.

(projectRoot: string, dirRel: string)

Source from the content-addressed store, hash-verified

89 * manifest or field is missing/escaping.
90 */
91function readOhpmMain(projectRoot: string, dirRel: string): string | null {
92 let parsed: unknown;
93 try {
94 // eslint-disable-next-line @typescript-eslint/no-require-imports
95 parsed = require('jsonc-parser').parse(
96 fs.readFileSync(path.join(projectRoot, dirRel, OHPM_MANIFEST), 'utf-8')
97 );
98 } catch {
99 return null;
100 }
101 const main = (parsed as { main?: unknown } | null)?.main;
102 if (typeof main !== 'string' || !main.trim()) return null;
103 const entryAbs = path.resolve(projectRoot, dirRel, main.trim());
104 const entryRel = path.relative(projectRoot, entryAbs).replace(/\\/g, '/');
105 if (entryRel.startsWith('..')) return null;
106 return entryRel;
107}
108
109/**
110 * Scan the project for `oh-package.json5` manifests and collect their

Callers 1

loadWorkspacePackagesFunction · 0.85

Calls 2

resolveMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected