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