MCPcopy Create free account
hub / github.com/Effect-TS/effect / parseBarrelExports

Function parseBarrelExports

packages/tools/jsdocs/src/Jsdocs.ts:612–656  ·  view source on GitHub ↗
(indexPath: string)

Source from the content-addressed store, hash-verified

610}
611
612function 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 }
618 let source: string
619 try {
620 source = fs.readFileSync(normalizedIndexPath, "utf8")
621 } catch (error) {
622 const result = {
623 _tag: "Failure",
624 error: `unable to read barrel file ${normalizedIndexPath}: ${String(error)}`
625 } as const
626 barrelExportCache.set(normalizedIndexPath, result)
627 return result
628 }
629 const sourceFile = ts.createSourceFile(normalizedIndexPath, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS)
630 const namespace = new Map<string, string>()
631 const flat = new Set<string>()
632 const named = new Map<string, Set<string>>()
633 for (const statement of sourceFile.statements) {
634 if (
635 ts.isExportDeclaration(statement) &&
636 statement.moduleSpecifier !== undefined &&
637 ts.isStringLiteralLike(statement.moduleSpecifier)
638 ) {
639 const moduleSpecifier = normalizePathName(statement.moduleSpecifier.text)
640 if (statement.exportClause === undefined) {
641 flat.add(moduleSpecifier)
642 } else if (ts.isNamespaceExport(statement.exportClause)) {
643 namespace.set(moduleSpecifier, statement.exportClause.name.text)
644 } else if (ts.isNamedExports(statement.exportClause)) {
645 const names = named.get(moduleSpecifier) ?? new Set<string>()
646 for (const specifier of statement.exportClause.elements) {
647 names.add(specifier.name.text)
648 }
649 named.set(moduleSpecifier, names)
650 }
651 }
652 }
653 const result = { _tag: "Success", value: { namespace, flat, named } } as const
654 barrelExportCache.set(normalizedIndexPath, result)
655 return result
656}
657
658function getPackageExportMatch(exports: unknown, subpath: string): PackageExportMatch | undefined {
659 if (!isRecord(exports)) {

Callers 1

resolveBarrelImportFunction · 0.85

Calls 5

normalizePathNameFunction · 0.70
getMethod · 0.65
setMethod · 0.65
addMethod · 0.65
StringInterface · 0.50

Tested by

no test coverage detected