Skip to content

Commit 1138897

Browse files
committed
feat: update packageDeclarations
1 parent 31f01fd commit 1138897

File tree

4 files changed

+33
-21
lines changed

4 files changed

+33
-21
lines changed

src/errors.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,8 @@ export class PackageTypesError extends Data.TaggedError("PackageTypesError") {}
1616

1717
/** `ProjectError` occurs when the `ts-morph` project cannot be created. */
1818
export class ProjectError extends Data.TaggedError("ProjectError")<{ readonly cause?: unknown }> {}
19+
20+
/** `PackageDeclarationsError` occurs when the declarations extraction fails. */
21+
export class PackageDeclarationsError extends Data.TaggedError("PackageDeclarationsError")<{
22+
cause?: unknown;
23+
}> {}

src/package-declarations.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import { dedent } from "ts-dedent";
33
import { ModuleKind, ModuleResolutionKind, Project, ScriptTarget } from "ts-morph";
44
import { afterEach, expect, test, vi } from "vitest";
55
import { extractDeclarations } from "./extract-declarations.ts";
6-
import { packageDeclarations, type PackageDeclarationsOptions } from "./package-declarations.ts";
6+
import { packageDeclarations } from "./package-declarations.ts";
7+
import type { PackageDeclarationsOptions } from "./types.ts";
78

8-
const _packageDeclarations = (options: PackageDeclarationsOptions) =>
9-
Effect.runPromise(packageDeclarations(options));
9+
const _packageDeclarations = (opts: PackageDeclarationsOptions) =>
10+
Effect.runPromise(packageDeclarations(opts));
1011

1112
vi.mock("./extract-declarations", () => ({
1213
extractDeclarations: vi.fn(),

src/package-declarations.ts

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,16 @@
1-
import { Data, Effect } from "effect";
2-
import type { Project, SourceFile } from "ts-morph";
1+
import { Effect } from "effect";
2+
import { PackageDeclarationsError } from "./errors.ts";
33
import { extractDeclarations } from "./extract-declarations.ts";
4+
import type { PackageDeclarationsOptions } from "./types.ts";
45

5-
export type PackageDeclarationsOptions = {
6-
pkgName: string;
7-
project: Project;
8-
indexFile: SourceFile;
9-
maxDepth: number;
10-
};
11-
12-
/** @internal */
13-
export class PackageDeclarationsError extends Data.TaggedError("PackageDeclarationsError")<{
14-
cause?: unknown;
15-
}> {}
16-
17-
export const packageDeclarations = ({
6+
/** `packageDeclarations` returns an Effect that extracts declarations from a package. */
7+
export function packageDeclarations({
188
pkgName,
199
project,
2010
indexFile,
2111
maxDepth,
22-
}: PackageDeclarationsOptions) =>
23-
Effect.tryPromise({
12+
}: PackageDeclarationsOptions) {
13+
return Effect.tryPromise({
2414
try: () =>
2515
extractDeclarations({
2616
containerName: "",
@@ -29,5 +19,6 @@ export const packageDeclarations = ({
2919
project,
3020
pkgName,
3121
}),
32-
catch: (e) => new PackageDeclarationsError({ cause: e }),
22+
catch: (err) => new PackageDeclarationsError({ cause: err }),
3323
});
24+
}

src/types.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,3 +306,18 @@ export interface CreateProjectReturn {
306306
/** `SourceFile` created with `ts-morph` representing the index file. */
307307
indexFile: SourceFile;
308308
}
309+
310+
/** `PackageDeclarationsOptions` contains the options for calling {@link packageDeclarations}. */
311+
export interface PackageDeclarationsOptions {
312+
/** Name of the analyzed package. */
313+
pkgName: string;
314+
315+
/** `Project` created with `ts-morph`. */
316+
project: Project;
317+
318+
/** `SourceFile` created with `ts-morph` representing the index file. */
319+
indexFile: SourceFile;
320+
321+
/** Depth limit for the extraction. */
322+
maxDepth: number;
323+
}

0 commit comments

Comments
 (0)