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

Function parseBarrelExports

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

Source from the content-addressed store, hash-verified

624}
625
626function parseBarrelExports(indexPath: string): Result<ParsedBarrelExports, string> {
627 const normalizedIndexPath = path.resolve(indexPath)
628 const cached = barrelExportCache.get(normalizedIndexPath)
629 if (cached !== undefined) {
630 return cached
631 }
632 let source: string
633 try {
634 source = fs.readFileSync(normalizedIndexPath, "utf8")
635 } catch (error) {
636 const result = {
637 _tag: "Failure",
638 error: `unable to read barrel file ${normalizedIndexPath}: ${String(error)}`
639 } as const
640 barrelExportCache.set(normalizedIndexPath, result)
641 return result
642 }
643 const sourceFile = ts.createSourceFile(normalizedIndexPath, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS)
644 const namespace = new Map<string, string>()
645 const flat = new Set<string>()
646 const named = new Map<string, Set<string>>()
647 for (const statement of sourceFile.statements) {
648 if (
649 ts.isExportDeclaration(statement) &&
650 statement.moduleSpecifier !== undefined &&
651 ts.isStringLiteralLike(statement.moduleSpecifier)
652 ) {
653 const moduleSpecifier = normalizePathName(statement.moduleSpecifier.text)
654 if (statement.exportClause === undefined) {
655 flat.add(moduleSpecifier)
656 } else if (ts.isNamespaceExport(statement.exportClause)) {
657 namespace.set(moduleSpecifier, statement.exportClause.name.text)
658 } else if (ts.isNamedExports(statement.exportClause)) {
659 const names = named.get(moduleSpecifier) ?? new Set<string>()
660 for (const specifier of statement.exportClause.elements) {
661 names.add(specifier.name.text)
662 }
663 named.set(moduleSpecifier, names)
664 }
665 }
666 }
667 const result = { _tag: "Success", value: { namespace, flat, named } } as const
668 barrelExportCache.set(normalizedIndexPath, result)
669 return result
670}
671
672function getPackageExportMatch(exports: unknown, subpath: string): PackageExportMatch | undefined {
673 if (!isRecord(exports)) {

Callers 1

resolveBarrelImportFunction · 0.85

Calls 6

resolveMethod · 0.80
normalizePathNameFunction · 0.70
getMethod · 0.65
setMethod · 0.65
addMethod · 0.65
StringFunction · 0.50

Tested by

no test coverage detected