|
1 | | -import type { ExportedDeclarations, ModuleDeclaration, Project, SourceFile } from "ts-morph"; |
2 | | - |
3 | | -/** `ExtractPackageApiOptions` contains the options for calling {@link extractPackageApi}. */ |
4 | | -export interface ExtractPackageApiOptions { |
5 | | - /** |
6 | | - Package to extract the API from. |
7 | | -
|
8 | | - This can be either a package name (e.g., `foo`, `@foo/bar`) or |
9 | | - any other query that can be passed to `bun add` (e.g., `foo@1.0.0`). |
10 | | -
|
11 | | - @see {@link https://bun.sh/docs/cli/add | Bun docs} |
12 | | - */ |
13 | | - pkg: string; |
14 | | - |
15 | | - /** |
16 | | - Specific subpath to consider in a package. |
17 | | -
|
18 | | - If a package has multiple entrypoints listed in the `exports` property |
19 | | - of its `package.json`, use `subpath` to select a specific one by its name |
20 | | - (e.g., `someFeature`). |
21 | | -
|
22 | | - @defaultValue `.` (package root) |
23 | | -
|
24 | | - @see {@link https://nodejs.org/api/packages.html#subpath-exports | Node.js docs} |
25 | | - @see {@link https://github.com/lukeed/resolve.exports | resolve.exports docs} |
26 | | - */ |
27 | | - subpath?: string; |
28 | | - |
29 | | - /** |
30 | | - Packages can have deeply nested modules and namespaces. |
31 | | -
|
32 | | - Use `maxDepth` to limit the depth of the extraction. |
33 | | - Declarations nested at levels deeper than this value will be ignored. |
34 | | -
|
35 | | - @defaultValue 5 |
36 | | - */ |
37 | | - maxDepth?: number; |
38 | | - |
39 | | - /** |
40 | | - Absolute path to the `bun` executable. |
41 | | -
|
42 | | - @defaultValue `bun` |
43 | | - */ |
44 | | - bunPath?: string; |
45 | | -} |
46 | | - |
47 | | -/** `ExtractPackageApiEffectOptions` contains the options for calling {@link extractPackageApiEffect}. */ |
48 | | -export type ExtractPackageApiEffectOptions = Omit<ExtractPackageApiOptions, "bunPath">; |
49 | | - |
50 | | -/** `PackageApi` contains all the information extracted from a package. */ |
51 | | -export interface PackageApi { |
52 | | - /** Package name (e.g., `foo`, `@foo/bar`). */ |
53 | | - name: string; |
54 | | - |
55 | | - /** Package version number (e.g., `1.0.0`). */ |
56 | | - version: string; |
57 | | - |
58 | | - /** |
59 | | - Package subpath selected when extracting the API (e.g., `.`, `someFeature`). |
60 | | -
|
61 | | - @see {@link ExtractPackageApiOptions.subpath} |
62 | | - @see {@link https://nodejs.org/api/packages.html#subpath-exports | Node.js docs} |
63 | | - */ |
64 | | - subpath: string; |
65 | | - |
66 | | - /** |
67 | | - Type declarations file, resolved from the selected `subpath`, |
68 | | - that acts as the entrypoint for the package (e.g., `index.d.ts`). |
69 | | - */ |
70 | | - types: string; |
71 | | - |
72 | | - /** |
73 | | - Package description extracted from the `types` file if a |
74 | | - JSDoc comment with the `@packageDocumentation` tag is found. |
75 | | - */ |
76 | | - overview?: string; |
77 | | - |
78 | | - /** Declarations exported (or re-exported) by the package. */ |
79 | | - declarations: ExtractedDeclaration[]; |
80 | | - |
81 | | - /** |
82 | | - All packages resolved and installed when installing the package (included). |
83 | | -
|
84 | | - @example |
85 | | - ```ts |
86 | | - // Installing `foo` brings in also `bar` and `baz` as dependencies. |
87 | | - ["foo@1.0.0", "bar@2.0.0", "baz@3.0.0"] |
88 | | - ``` |
89 | | - */ |
90 | | - packages: string[]; |
91 | | - |
92 | | - /** Timestamp of when the package was analyzed. */ |
93 | | - analyzedAt: string; |
94 | | - |
95 | | - /** Package analysis duration in milliseconds. */ |
96 | | - analyzedIn: number; |
97 | | -} |
98 | | - |
99 | | -/** `ExtractDeclarationsOptions` contains the options for calling {@link extractDeclarations}. */ |
100 | | -export interface ExtractDeclarationsOptions { |
101 | | - /** Container that exports the top-level declarations. */ |
102 | | - container: SourceFile | ModuleDeclaration; |
103 | | - |
104 | | - /** |
105 | | - Container name (e.g., the name of a namespace), used to generate declaration IDs. |
106 | | - */ |
107 | | - containerName: string; |
108 | | - |
109 | | - /** Maximum extraction depth for nested namespaces. */ |
110 | | - maxDepth: number; |
111 | | - |
112 | | - /** Instance of a `ts-morph` `Project`, used to find ambient modules. */ |
113 | | - project?: Project; |
114 | | - |
115 | | - /** Name of the package being analyzed, used to filter ambient modules. */ |
116 | | - pkgName?: string; |
117 | | -} |
118 | | - |
119 | 1 | /** `BaseDeclaration` contains the properties common to extracted declarations. */ |
120 | 2 | export interface BaseDeclaration { |
121 | 3 | /** Unique ID. */ |
@@ -270,66 +152,3 @@ export type AllExtractedDeclaration = |
270 | 152 | used to detect the kind of declaration. |
271 | 153 | */ |
272 | 154 | export type AllExtractedDeclarationKind = AllExtractedDeclaration["kind"]; |
273 | | - |
274 | | -/** `InstallPackageOptions` contains the options for calling {@link PackageManager.installPackage}. */ |
275 | | -export interface InstallPackageOptions { |
276 | | - /** Package to install. */ |
277 | | - pkg: string; |
278 | | - |
279 | | - /** Directory where to install the package as a dependency. */ |
280 | | - cwd: string; |
281 | | -} |
282 | | - |
283 | | -/** `WorkDir` represents a temporary directory resource. */ |
284 | | -export interface WorkDir { |
285 | | - /** Directory path. */ |
286 | | - path: string; |
287 | | - |
288 | | - /** Cleanup function to remove the directory. */ |
289 | | - close: () => Promise<void>; |
290 | | -} |
291 | | - |
292 | | -/** `CreateProjectOptions` contains the options for calling {@link createProject}. */ |
293 | | -export interface CreateProjectOptions { |
294 | | - /** Path to the types entry point file. */ |
295 | | - indexFilePath: string; |
296 | | - |
297 | | - /** Directory where the analyzed package is installed. */ |
298 | | - cwd: string; |
299 | | -} |
300 | | - |
301 | | -/** `CreateProjectReturn` represents the return value of {@link createProject}. */ |
302 | | -export interface CreateProjectReturn { |
303 | | - /** `Project` created with `ts-morph`. */ |
304 | | - project: Project; |
305 | | - |
306 | | - /** `SourceFile` created with `ts-morph` representing the index file. */ |
307 | | - indexFile: SourceFile; |
308 | | -} |
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 | | -} |
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