( metadata: PackageMetadata, filename: string )
| 742 | } |
| 743 | |
| 744 | function resolveBarrelImport( |
| 745 | metadata: PackageMetadata, |
| 746 | filename: string |
| 747 | ): Result<{ readonly barrel: ParsedJSDocBarrelImport | null; readonly flatNames: ReadonlyArray<string> }, string> { |
| 748 | let directory = path.dirname(filename) |
| 749 | while (isPathInside(metadata.sourceRoot, directory)) { |
| 750 | const indexPath = path.join(directory, "index.ts") |
| 751 | if (indexPath !== filename && fs.existsSync(indexPath)) { |
| 752 | const expectedExport = `./${normalizePathName(path.relative(directory, filename))}` |
| 753 | const parsed = parseBarrelExports(indexPath) |
| 754 | if (parsed._tag === "Failure") { |
| 755 | return parsed |
| 756 | } |
| 757 | const barrelSubpath = normalizePathName(path.relative(metadata.sourceRoot, directory)) |
| 758 | const exportSubpath = barrelSubpath === "" ? "." : `./${barrelSubpath}` |
| 759 | const exportTarget = barrelSubpath === "" ? "./src/index.ts" : `./src/${barrelSubpath}/index.ts` |
| 760 | if (isPackageSubpathExported(metadata.exports, exportSubpath, exportTarget)) { |
| 761 | const moduleSpecifier = packageSpecifier(metadata.name, barrelSubpath) |
| 762 | const flatNames = Array.from(parsed.value.named.get(expectedExport) ?? []) |
| 763 | const namespace = parsed.value.namespace.get(expectedExport) |
| 764 | if (namespace !== undefined) { |
| 765 | return { |
| 766 | _tag: "Success", |
| 767 | value: { barrel: { type: "namespace", module: moduleSpecifier, name: namespace }, flatNames } |
| 768 | } |
| 769 | } |
| 770 | if (parsed.value.flat.has(expectedExport)) { |
| 771 | return { |
| 772 | _tag: "Success", |
| 773 | value: { barrel: { type: "flat", module: moduleSpecifier }, flatNames } |
| 774 | } |
| 775 | } |
| 776 | if (flatNames.length > 0) { |
| 777 | return { |
| 778 | _tag: "Success", |
| 779 | value: { barrel: { type: "flat", module: moduleSpecifier }, flatNames } |
| 780 | } |
| 781 | } |
| 782 | } |
| 783 | } |
| 784 | if (directory === metadata.sourceRoot) { |
| 785 | break |
| 786 | } |
| 787 | directory = path.dirname(directory) |
| 788 | } |
| 789 | return { _tag: "Success", value: { barrel: null, flatNames: [] } } |
| 790 | } |
| 791 | |
| 792 | function resolveJSDocImports( |
| 793 | cwd: string, |
no test coverage detected