Skip to content

Commit e678200

Browse files
committed
feat: add FoundDeclaration type and update ambientModulesDeclarations
1 parent ec9b914 commit e678200

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

src/ambient-modules-declarations.ts

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,24 @@
1-
import { ModuleDeclaration, Node, type Project } from "ts-morph";
1+
import { Node, type Project } from "ts-morph";
22
import { isHidden } from "./is-hidden.ts";
33
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";
105

116
export function ambientModulesDeclarations(
127
containerName: string,
138
project: Project,
149
pkgName?: string,
15-
): AmbientModulesDeclarationsReturn {
10+
): FoundDeclaration[] {
1611
const ambientModulesDeclarations = [];
1712
for (const symbol of project.getAmbientModules()) {
1813
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+
2620
const exportName = declaration.getName();
27-
ambientModulesDeclarations.push({
28-
containerName,
29-
exportName,
30-
declaration,
31-
});
21+
ambientModulesDeclarations.push({ containerName, exportName, declaration });
3222
}
3323
}
3424
return ambientModulesDeclarations;

src/types.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ModuleDeclaration, Project, SourceFile } from "ts-morph";
1+
import type { ExportedDeclarations, ModuleDeclaration, Project, SourceFile } from "ts-morph";
22

33
/** `ExtractPackageApiOptions` contains the options for calling {@link extractPackageApi}. */
44
export interface ExtractPackageApiOptions {
@@ -321,3 +321,15 @@ export interface PackageDeclarationsOptions {
321321
/** Depth limit for the extraction. */
322322
maxDepth: number;
323323
}
324+
325+
/** `FoundDeclaration` represents a declaration found during the initial extraction process. */
326+
export interface FoundDeclaration {
327+
/** Declaration container name. */
328+
containerName: string;
329+
330+
/** Export name (may differ from the original name). */
331+
exportName: string;
332+
333+
/** Declaration. */
334+
declaration: ExportedDeclarations;
335+
}

0 commit comments

Comments
 (0)