(indexPath: string)
| 568 | } |
| 569 | const packageJsonPath = path.join(normalizedRoot, "package.json") |
| 570 | let parsed: unknown |
| 571 | try { |
| 572 | parsed = JSON.parse(fs.readFileSync(packageJsonPath, "utf8")) |
| 573 | } catch (error) { |
| 574 | const result = { |
| 575 | _tag: "Failure", |
| 576 | error: `unable to read package.json at ${packageJsonPath}: ${String(error)}` |
| 577 | } as const |
| 578 | packageMetadataCache.set(normalizedRoot, result) |
| 579 | return result |
| 580 | } |
| 581 | if (!isRecord(parsed)) { |
| 582 | const result = { _tag: "Failure", error: `package.json at ${packageJsonPath} must be an object` } as const |
| 583 | packageMetadataCache.set(normalizedRoot, result) |
| 584 | return result |
| 585 | } |
| 586 | if (typeof parsed.name !== "string" || parsed.name.length === 0) { |
| 587 | const result = { |
| 588 | _tag: "Failure", |
| 589 | error: `package.json at ${packageJsonPath} must include a non-empty name` |
| 590 | } as const |
| 591 | packageMetadataCache.set(normalizedRoot, result) |
| 592 | return result |
| 593 | } |
| 594 | if (parsed.exports === undefined) { |
| 595 | const result = { _tag: "Failure", error: `package.json at ${packageJsonPath} must include exports` } as const |
| 596 | packageMetadataCache.set(normalizedRoot, result) |
| 597 | return result |
| 598 | } |
| 599 | const result = { |
| 600 | _tag: "Success", |
| 601 | value: { |
| 602 | root: normalizedRoot, |
| 603 | sourceRoot: path.join(normalizedRoot, "src"), |
| 604 | name: parsed.name, |
| 605 | exports: parsed.exports |
| 606 | } |
| 607 | } as const |
| 608 | packageMetadataCache.set(normalizedRoot, result) |
| 609 | return result |
| 610 | } |
| 611 | |
| 612 | function parseBarrelExports(indexPath: string): Result<ParsedBarrelExports, string> { |
| 613 | const normalizedIndexPath = path.resolve(indexPath) |
| 614 | const cached = barrelExportCache.get(normalizedIndexPath) |
| 615 | if (cached !== undefined) { |
| 616 | return cached |
| 617 | } |
no test coverage detected
searching dependent graphs…