( cwd: string, filename: string )
| 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)) { |
| 794 | return { |
| 795 | _tag: "Failure", |
| 796 | error: `${relativeFilename} is not under ${normalizePathName(path.relative(cwd, metadata.value.sourceRoot))}` |
| 797 | } |
| 798 | } |
| 799 | if (path.basename(absoluteFilename) === "index.ts") { |
| 800 | return { |
| 801 | _tag: "Failure", |
| 802 | error: `${relativeFilename} is a barrel file; exclude it from jsdocs` |
| 803 | } |
| 804 | } |
| 805 | if (path.extname(absoluteFilename) !== ".ts" || absoluteFilename.endsWith(".d.ts")) { |
| 806 | return { |
| 807 | _tag: "Failure", |
| 808 | error: `${relativeFilename} is not a TypeScript source module` |
| 809 | } |
| 810 | } |
| 811 | const moduleSubpath = relativeToSourceRoot.slice(0, -".ts".length) |
| 812 | const moduleExportSubpath = `./${moduleSubpath}` |
| 813 | const moduleExportTarget = `./src/${relativeToSourceRoot}` |
| 814 | if (!isPackageSubpathExported(metadata.value.exports, moduleExportSubpath, moduleExportTarget)) { |
| 815 | return { |
| 816 | _tag: "Failure", |
| 817 | error: `package.json exports do not expose ${ |
| 818 | packageSpecifier(metadata.value.name, moduleSubpath) |
| 819 | } for ${relativeFilename}` |
| 820 | } |
| 821 | } |
| 822 | const barrel = resolveBarrelImport(metadata.value, absoluteFilename) |
| 823 | if (barrel._tag === "Failure") { |
| 824 | return barrel |
| 825 | } |
| 826 | return { |
| 827 | _tag: "Success", |
| 828 | value: { |
| 829 | module: packageSpecifier(metadata.value.name, moduleSubpath), |
| 830 | barrel: barrel.value.barrel, |
| 831 | flatNames: barrel.value.flatNames |
| 832 | } |
| 833 | } |
| 834 | } |
| 835 |
no test coverage detected