doc-typecheck-paths.ts 1.1 KB

12345678910111213141516171819202122
  1. /** Map one workspace source alias target to its declaration-build target. */
  2. export function builtDeclarationPath(candidate: string): string {
  3. // Two workspace path forms exist: whole-package entries end in /src, subpath
  4. // wildcards (browser-safe /types and /client channels) in /src/*.
  5. if (candidate.endsWith('/src')) {
  6. return `${candidate.slice(0, -'/src'.length)}/lib/types`
  7. }
  8. if (candidate.endsWith('/src/*')) {
  9. return `${candidate.slice(0, -'/src/*'.length)}/lib/types/*`
  10. }
  11. const sourceFile = /^(.*)\/src\/(.+)\.ts$/.exec(candidate)
  12. if (sourceFile?.[1] && sourceFile[2]) {
  13. return `${sourceFile[1]}/lib/types/${sourceFile[2]}.d.ts`
  14. }
  15. // Directory subpath entries (for example, runtime's /client): the
  16. // source dir maps to the same dir under lib/types (index resolution applies).
  17. const sourceDir = /^(.*)\/src\/(.+)$/.exec(candidate)
  18. if (sourceDir?.[1] && sourceDir[2]) {
  19. return `${sourceDir[1]}/lib/types/${sourceDir[2]}`
  20. }
  21. throw new Error(`doc-typecheck: cannot map workspace source path to built declarations: ${candidate}`)
  22. }