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

Function readOhpmMain

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

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