|
1 | | -import { ModuleDeclaration, Node, type Project } from "ts-morph"; |
| 1 | +import { Node, type Project } from "ts-morph"; |
2 | 2 | import { isHidden } from "./is-hidden.ts"; |
3 | 3 | import { sourceFilePath } from "./source-file-path.ts"; |
4 | | - |
5 | | -export type AmbientModulesDeclarationsReturn = { |
6 | | - containerName: string; |
7 | | - exportName: string; |
8 | | - declaration: ModuleDeclaration; |
9 | | -}[]; |
| 4 | +import type { FoundDeclaration } from "./types.ts"; |
10 | 5 |
|
11 | 6 | export function ambientModulesDeclarations( |
12 | 7 | containerName: string, |
13 | 8 | project: Project, |
14 | 9 | pkgName?: string, |
15 | | -): AmbientModulesDeclarationsReturn { |
| 10 | +): FoundDeclaration[] { |
16 | 11 | const ambientModulesDeclarations = []; |
17 | 12 | for (const symbol of project.getAmbientModules()) { |
18 | 13 | for (const declaration of symbol.getDeclarations()) { |
19 | | - if (isHidden(declaration) || !Node.isModuleDeclaration(declaration)) { |
20 | | - continue; |
21 | | - } |
22 | | - if (pkgName && !sourceFilePath(declaration).startsWith(`/${pkgName}`)) { |
23 | | - // Ignore ambient modules that are not from the analyzed package. |
24 | | - continue; |
25 | | - } |
| 14 | + if (!Node.isModuleDeclaration(declaration)) continue; |
| 15 | + if (isHidden(declaration)) continue; |
| 16 | + |
| 17 | + // Ignore ambient modules that are not from the analyzed package. |
| 18 | + if (pkgName && !sourceFilePath(declaration).startsWith(`/${pkgName}`)) continue; |
| 19 | + |
26 | 20 | const exportName = declaration.getName(); |
27 | | - ambientModulesDeclarations.push({ |
28 | | - containerName, |
29 | | - exportName, |
30 | | - declaration, |
31 | | - }); |
| 21 | + ambientModulesDeclarations.push({ containerName, exportName, declaration }); |
32 | 22 | } |
33 | 23 | } |
34 | 24 | return ambientModulesDeclarations; |
|
0 commit comments