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

Function readOhpmMain

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

289 * manifest or field is missing/escaping.
290 */
291function readOhpmMain(projectRoot: string, dirRel: string): string | null {
292 let parsed: unknown;
293 try {
294 // eslint-disable-next-line @typescript-eslint/no-require-imports
295 parsed = require('jsonc-parser').parse(
296 fs.readFileSync(path.join(projectRoot, dirRel, OHPM_MANIFEST), 'utf-8')
297 );
298 } catch {
299 return null;
300 }
301 const main = (parsed as { main?: unknown } | null)?.main;
302 if (typeof main !== 'string' || !main.trim()) return null;
303 const entryAbs = path.resolve(projectRoot, dirRel, main.trim());
304 const entryRel = path.relative(projectRoot, entryAbs).replace(/\\/g, '/');
305 if (entryRel.startsWith('..')) return null;
306 return entryRel;
307}
308
309/**
310 * Scan the project for `oh-package.json5` manifests and collect their

Callers 1

loadWithManifestsFunction · 0.85

Calls 3

parseMethod · 0.80
resolveMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected