@stacksjs/dtsx 0.9.9 → 0.9.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/README.md +243 -15
- package/dist/bin/cli.js +10 -22
- package/dist/branded-types.d.ts +150 -0
- package/dist/bundler.d.ts +55 -0
- package/dist/cache.d.ts +43 -0
- package/dist/checker.d.ts +107 -0
- package/dist/chunk-1bav913n.js +6 -0
- package/dist/chunk-2wbhe1k8.js +2 -0
- package/dist/chunk-3d18fhrg.js +3 -0
- package/dist/chunk-3g2v2ns2.js +2 -0
- package/dist/chunk-3j7r0fxz.js +2 -0
- package/dist/chunk-4qpg9xnt.js +3 -0
- package/dist/chunk-57agx6g8.js +3 -0
- package/dist/chunk-5vqtjws2.js +2 -0
- package/dist/chunk-6mwq397e.js +2 -0
- package/dist/chunk-6qv7p9sg.js +170 -0
- package/dist/chunk-6s7n1gt0.js +2 -0
- package/dist/chunk-74j5mydx.js +3 -0
- package/dist/chunk-7cpp6v8f.js +2 -0
- package/dist/chunk-9a6yn7sv.js +75 -0
- package/dist/chunk-axb2kjeq.js +2 -0
- package/dist/chunk-begk3j01.js +33 -0
- package/dist/chunk-cmenkst5.js +3 -0
- package/dist/chunk-d0p3jzwb.js +34 -0
- package/dist/chunk-f18nyrrb.js +32 -0
- package/dist/chunk-fb4c98h2.js +2 -0
- package/dist/chunk-ggmn4a8c.js +4 -0
- package/dist/chunk-hrmnrn4p.js +3 -0
- package/dist/chunk-j0y71ank.js +2 -0
- package/dist/chunk-j6aqdbc4.js +2 -0
- package/dist/chunk-jm5ywn4e.js +13 -0
- package/dist/chunk-knkfbqze.js +2 -0
- package/dist/chunk-n28rjf9h.js +3 -0
- package/dist/chunk-p1d09y82.js +449 -0
- package/dist/chunk-r1m3q3dj.js +2 -0
- package/dist/chunk-r1ywapeb.js +6 -0
- package/dist/chunk-rnt0wkrk.js +23 -0
- package/dist/chunk-rw6j20e2.js +3 -0
- package/dist/chunk-v96rjx7x.js +134 -0
- package/dist/chunk-w9abhtgg.js +22 -0
- package/dist/chunk-wfevdmvd.js +19 -0
- package/dist/chunk-ws2dmfvj.js +2 -0
- package/dist/chunk-xnq1xw73.js +15 -0
- package/dist/chunk-xyctgc6x.js +102 -0
- package/dist/chunk-y3q50bn2.js +2 -0
- package/dist/chunk-ywd4k4hn.js +3 -0
- package/dist/circular.d.ts +82 -0
- package/dist/compat.d.ts +108 -0
- package/dist/config.d.ts +33 -3
- package/dist/diff.d.ts +82 -0
- package/dist/docs.d.ts +97 -0
- package/dist/errors.d.ts +113 -0
- package/dist/extractor/builders.d.ts +38 -0
- package/dist/extractor/cache.d.ts +47 -0
- package/dist/extractor/declarations.d.ts +50 -0
- package/dist/extractor/directives.d.ts +9 -0
- package/dist/extractor/extract.d.ts +10 -0
- package/dist/extractor/hash.d.ts +1 -0
- package/dist/extractor/helpers.d.ts +39 -0
- package/dist/extractor/index.d.ts +70 -0
- package/dist/extractor/scanner.d.ts +6 -0
- package/dist/extractor.d.ts +3 -4
- package/dist/formats.d.ts +50 -0
- package/dist/formatter.d.ts +61 -0
- package/dist/generator.d.ts +12 -3
- package/dist/import-sorter.d.ts +99 -0
- package/dist/incremental.d.ts +84 -0
- package/dist/index.d.ts +54 -1
- package/dist/logger.d.ts +57 -0
- package/dist/lsp.d.ts +317 -0
- package/dist/memory.d.ts +110 -0
- package/dist/merger.d.ts +38 -0
- package/dist/optimizer.d.ts +52 -0
- package/dist/output-normalizer.d.ts +123 -0
- package/dist/parallel-processor.d.ts +63 -0
- package/dist/parser.d.ts +24 -15
- package/dist/plugins/bun.d.ts +58 -0
- package/dist/plugins/esbuild.d.ts +63 -0
- package/dist/plugins/index.d.ts +14 -0
- package/dist/plugins/tsup.d.ts +53 -0
- package/dist/plugins/vite.d.ts +49 -0
- package/dist/plugins/webpack.d.ts +66 -0
- package/dist/plugins.d.ts +83 -0
- package/dist/process-source.d.ts +11 -0
- package/dist/processor/cache.d.ts +16 -0
- package/dist/processor/comments.d.ts +7 -0
- package/dist/processor/declarations.d.ts +37 -0
- package/dist/processor/imports.d.ts +65 -0
- package/dist/processor/index.d.ts +34 -0
- package/dist/processor/type-inference.d.ts +106 -0
- package/dist/processor.d.ts +3 -43
- package/dist/profiling.d.ts +101 -0
- package/dist/security.d.ts +100 -0
- package/dist/sourcemap.d.ts +125 -0
- package/dist/src/index.js +55 -2
- package/dist/src/plugins/bun.js +2 -0
- package/dist/src/plugins/esbuild.js +2 -0
- package/dist/src/plugins/index.js +2 -0
- package/dist/src/plugins/tsup.js +2 -0
- package/dist/src/plugins/vite.js +2 -0
- package/dist/src/plugins/webpack.js +2 -0
- package/dist/tracking.d.ts +89 -0
- package/dist/transformers.d.ts +173 -0
- package/dist/tree-shaker.d.ts +69 -0
- package/dist/type-mappings.d.ts +124 -0
- package/dist/types.d.ts +137 -7
- package/dist/utils.d.ts +53 -1
- package/dist/watcher.d.ts +64 -0
- package/dist/worker.d.ts +84 -0
- package/dist/workspace.d.ts +62 -0
- package/package.json +49 -11
- package/dist/chunk-qsyn1k3w.js +0 -504
package/dist/docs.d.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { Declaration } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Parse JSDoc comments from a declaration
|
|
4
|
+
*/
|
|
5
|
+
export declare function parseJSDoc(comments: string[] | undefined): JSDocInfo;
|
|
6
|
+
/**
|
|
7
|
+
* Extract documentation from source files
|
|
8
|
+
*/
|
|
9
|
+
export declare function extractDocumentation(files: string[], config?: Partial<DocsConfig>): Promise<Documentation>;
|
|
10
|
+
/**
|
|
11
|
+
* Generate markdown documentation
|
|
12
|
+
*/
|
|
13
|
+
export declare function generateMarkdown(docs: Documentation, config?: Partial<DocsConfig>): string;
|
|
14
|
+
/**
|
|
15
|
+
* Generate HTML documentation
|
|
16
|
+
*/
|
|
17
|
+
export declare function generateHTML(docs: Documentation, config?: Partial<DocsConfig>): string;
|
|
18
|
+
/**
|
|
19
|
+
* Generate JSON documentation
|
|
20
|
+
*/
|
|
21
|
+
export declare function generateJSON(docs: Documentation, config?: Partial<DocsConfig>): string;
|
|
22
|
+
/**
|
|
23
|
+
* Generate documentation in TypeDoc-compatible JSON format
|
|
24
|
+
*/
|
|
25
|
+
export declare function generateTypeDocJSON(docs: Documentation): string;
|
|
26
|
+
/**
|
|
27
|
+
* Generate and write documentation files
|
|
28
|
+
*/
|
|
29
|
+
export declare function generateDocs(files: string[], config: DocsConfig): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Create a documentation generator with preset configuration
|
|
32
|
+
*/
|
|
33
|
+
export declare function createDocsGenerator(config?: Partial<DocsConfig>): {
|
|
34
|
+
extract: (files: string[]) => Promise<Documentation>
|
|
35
|
+
generateMarkdown: (docs: Documentation) => string
|
|
36
|
+
generateHTML: (docs: Documentation) => string
|
|
37
|
+
generateJSON: (docs: Documentation) => string
|
|
38
|
+
parseJSDoc: typeof parseJSDoc
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Documentation configuration
|
|
42
|
+
*/
|
|
43
|
+
export declare interface DocsConfig {
|
|
44
|
+
format: 'markdown' | 'html' | 'json'
|
|
45
|
+
outdir: string
|
|
46
|
+
includePrivate?: boolean
|
|
47
|
+
includeInternal?: boolean
|
|
48
|
+
groupByCategory?: boolean
|
|
49
|
+
title?: string
|
|
50
|
+
description?: string
|
|
51
|
+
includeSourceLinks?: boolean
|
|
52
|
+
sourceBaseUrl?: string
|
|
53
|
+
includeTypes?: boolean
|
|
54
|
+
splitByModule?: boolean
|
|
55
|
+
template?: 'default' | 'minimal' | 'detailed'
|
|
56
|
+
customCss?: string
|
|
57
|
+
includeSidebar?: boolean
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Parsed JSDoc information
|
|
61
|
+
*/
|
|
62
|
+
export declare interface JSDocInfo {
|
|
63
|
+
description: string
|
|
64
|
+
params: Array<{ name: string, type?: string, description: string, optional?: boolean }>
|
|
65
|
+
returns?: { type?: string, description: string }
|
|
66
|
+
examples: string[]
|
|
67
|
+
tags: Record<string, string[]>
|
|
68
|
+
deprecated?: string
|
|
69
|
+
since?: string
|
|
70
|
+
see: string[]
|
|
71
|
+
throws: Array<{ type?: string, description: string }>
|
|
72
|
+
category?: string
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Documentation entry for a declaration
|
|
76
|
+
*/
|
|
77
|
+
export declare interface DocEntry {
|
|
78
|
+
name: string
|
|
79
|
+
kind: Declaration['kind']
|
|
80
|
+
signature: string
|
|
81
|
+
jsdoc: JSDocInfo
|
|
82
|
+
isExported: boolean
|
|
83
|
+
isDefault?: boolean
|
|
84
|
+
sourceFile?: string
|
|
85
|
+
sourceLine?: number
|
|
86
|
+
members?: DocEntry[]
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Documentation output structure
|
|
90
|
+
*/
|
|
91
|
+
export declare interface Documentation {
|
|
92
|
+
title: string
|
|
93
|
+
description?: string
|
|
94
|
+
entries: DocEntry[]
|
|
95
|
+
categories: Map<string, DocEntry[]>
|
|
96
|
+
generatedAt: Date
|
|
97
|
+
}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { DtsError, SourceLocation } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Type guards for error types
|
|
4
|
+
*/
|
|
5
|
+
export declare function isDtsxError(error: unknown): error is DtsxError;
|
|
6
|
+
export declare function isParseError(error: unknown): error is ParseError;
|
|
7
|
+
export declare function isFileError(error: unknown): error is FileError;
|
|
8
|
+
export declare function isConfigError(error: unknown): error is ConfigError;
|
|
9
|
+
/**
|
|
10
|
+
* Wrap an unknown error in a DtsxError
|
|
11
|
+
*/
|
|
12
|
+
export declare function wrapError(error: unknown, code?: ErrorCode, message?: string): DtsxError;
|
|
13
|
+
/**
|
|
14
|
+
* Calculate line and column from source code offset
|
|
15
|
+
*/
|
|
16
|
+
export declare function getLocationFromOffset(sourceCode: string, offset: number): SourceLocation;
|
|
17
|
+
/**
|
|
18
|
+
* Create a formatted error message with source location context
|
|
19
|
+
*/
|
|
20
|
+
export declare function formatErrorWithContext(sourceCode: string, location: SourceLocation, message: string, filePath?: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Create a DtsError from an exception
|
|
23
|
+
*/
|
|
24
|
+
export declare function createDtsError(error: unknown, file: string, _sourceCode?: string): DtsError;
|
|
25
|
+
/**
|
|
26
|
+
* Format a DtsError for display
|
|
27
|
+
*/
|
|
28
|
+
export declare function formatDtsError(error: DtsError, sourceCode?: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* Aggregate multiple errors into a summary
|
|
31
|
+
*/
|
|
32
|
+
export declare function summarizeErrors(errors: DtsError[]): string;
|
|
33
|
+
/**
|
|
34
|
+
* Error codes for categorizing errors
|
|
35
|
+
*/
|
|
36
|
+
export declare const ErrorCodes: {
|
|
37
|
+
PARSE_ERROR: 'PARSE_ERROR';
|
|
38
|
+
SYNTAX_ERROR: 'SYNTAX_ERROR';
|
|
39
|
+
FILE_NOT_FOUND: 'FILE_NOT_FOUND';
|
|
40
|
+
FILE_READ_ERROR: 'FILE_READ_ERROR';
|
|
41
|
+
FILE_WRITE_ERROR: 'FILE_WRITE_ERROR';
|
|
42
|
+
TYPE_INFERENCE_ERROR: 'TYPE_INFERENCE_ERROR';
|
|
43
|
+
UNRESOLVED_TYPE: 'UNRESOLVED_TYPE';
|
|
44
|
+
EXTRACTION_ERROR: 'EXTRACTION_ERROR';
|
|
45
|
+
PROCESSING_ERROR: 'PROCESSING_ERROR';
|
|
46
|
+
VALIDATION_ERROR: 'VALIDATION_ERROR';
|
|
47
|
+
INVALID_DECLARATION: 'INVALID_DECLARATION';
|
|
48
|
+
CONFIG_ERROR: 'CONFIG_ERROR';
|
|
49
|
+
INVALID_ENTRYPOINT: 'INVALID_ENTRYPOINT';
|
|
50
|
+
CIRCULAR_DEPENDENCY: 'CIRCULAR_DEPENDENCY';
|
|
51
|
+
TIMEOUT_ERROR: 'TIMEOUT_ERROR';
|
|
52
|
+
NOT_SUPPORTED: 'NOT_SUPPORTED';
|
|
53
|
+
UNKNOWN_ERROR: 'UNKNOWN_ERROR'
|
|
54
|
+
};
|
|
55
|
+
export type ErrorCode = typeof ErrorCodes[keyof typeof ErrorCodes];
|
|
56
|
+
/**
|
|
57
|
+
* Base error class for dtsx errors
|
|
58
|
+
*/
|
|
59
|
+
export declare class DtsxError extends Error {
|
|
60
|
+
readonly code: ErrorCode;
|
|
61
|
+
readonly context?: Record<string, unknown>;
|
|
62
|
+
constructor(message: string, code?: ErrorCode, context?: Record<string, unknown>);
|
|
63
|
+
toString(): string;
|
|
64
|
+
toJSON(): Record<string, unknown>;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Error during file parsing
|
|
68
|
+
*/
|
|
69
|
+
export declare class ParseError extends DtsxError {
|
|
70
|
+
readonly filePath: string;
|
|
71
|
+
readonly line?: number;
|
|
72
|
+
readonly column?: number;
|
|
73
|
+
constructor(message: string, filePath: string, options?: { line?: number, column?: number, cause?: Error });
|
|
74
|
+
get locationString(): string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Error during declaration extraction
|
|
78
|
+
*/
|
|
79
|
+
export declare class ExtractionError extends DtsxError {
|
|
80
|
+
readonly filePath: string;
|
|
81
|
+
readonly declarationKind?: string;
|
|
82
|
+
constructor(message: string, filePath: string, declarationKind?: string, cause?: Error);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Error during type processing
|
|
86
|
+
*/
|
|
87
|
+
export declare class ProcessingError extends DtsxError {
|
|
88
|
+
readonly declarationName?: string;
|
|
89
|
+
constructor(message: string, declarationName?: string, cause?: Error);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Error during file I/O operations
|
|
93
|
+
*/
|
|
94
|
+
export declare class FileError extends DtsxError {
|
|
95
|
+
readonly filePath: string;
|
|
96
|
+
readonly operation: 'read' | 'write' | 'delete' | 'stat' | 'glob';
|
|
97
|
+
constructor(message: string, filePath: string, operation: 'read' | 'write' | 'delete' | 'stat' | 'glob', cause?: Error);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Error during configuration loading or validation
|
|
101
|
+
*/
|
|
102
|
+
export declare class ConfigError extends DtsxError {
|
|
103
|
+
readonly configPath?: string;
|
|
104
|
+
readonly invalidKey?: string;
|
|
105
|
+
constructor(message: string, options?: { configPath?: string, invalidKey?: string, cause?: Error });
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Error when circular dependency is detected
|
|
109
|
+
*/
|
|
110
|
+
export declare class CircularDependencyError extends DtsxError {
|
|
111
|
+
readonly cycle: string[];
|
|
112
|
+
constructor(cycle: string[]);
|
|
113
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ClassDeclaration, FunctionDeclaration, InterfaceDeclaration, ModuleDeclaration, SourceFile, TypeAliasDeclaration } from 'typescript';
|
|
2
|
+
/**
|
|
3
|
+
* Build clean function signature for DTS output
|
|
4
|
+
*/
|
|
5
|
+
export declare function buildFunctionSignature(node: FunctionDeclaration, sf: SourceFile): string;
|
|
6
|
+
/**
|
|
7
|
+
* Build clean variable declaration for DTS
|
|
8
|
+
*/
|
|
9
|
+
export declare function buildVariableDeclaration(name: string, type: string | undefined, kind: string, isExported: boolean): string;
|
|
10
|
+
/**
|
|
11
|
+
* Build clean interface declaration for DTS
|
|
12
|
+
*/
|
|
13
|
+
export declare function buildInterfaceDeclaration(node: InterfaceDeclaration, isExported: boolean, sf: SourceFile): string;
|
|
14
|
+
/**
|
|
15
|
+
* Get interface body with proper formatting
|
|
16
|
+
*/
|
|
17
|
+
export declare function getInterfaceBody(node: InterfaceDeclaration, sf: SourceFile): string;
|
|
18
|
+
/**
|
|
19
|
+
* Build clean type declaration for DTS
|
|
20
|
+
*/
|
|
21
|
+
export declare function buildTypeDeclaration(node: TypeAliasDeclaration, isExported: boolean, sf: SourceFile): string;
|
|
22
|
+
/**
|
|
23
|
+
* Build clean class declaration for DTS
|
|
24
|
+
*/
|
|
25
|
+
export declare function buildClassDeclaration(node: ClassDeclaration, isExported: boolean, sf: SourceFile): string;
|
|
26
|
+
/**
|
|
27
|
+
* Build clean class body for DTS (signatures only, no implementations)
|
|
28
|
+
* Excludes: private fields (#field), private methods (#method), static blocks
|
|
29
|
+
*/
|
|
30
|
+
export declare function buildClassBody(node: ClassDeclaration, sf: SourceFile): string;
|
|
31
|
+
/**
|
|
32
|
+
* Build clean module declaration for DTS
|
|
33
|
+
*/
|
|
34
|
+
export declare function buildModuleDeclaration(node: ModuleDeclaration, isExported: boolean, sf: SourceFile): string;
|
|
35
|
+
/**
|
|
36
|
+
* Build clean module body for DTS (signatures only, no implementations)
|
|
37
|
+
*/
|
|
38
|
+
export declare function buildModuleBody(node: ModuleDeclaration, sf: SourceFile): string;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { hashContent } from './hash';
|
|
2
|
+
import type { SourceFile } from 'typescript';
|
|
3
|
+
/**
|
|
4
|
+
* Evict oldest entry if cache exceeds max size
|
|
5
|
+
* Uses O(n) scan instead of O(n log n) sort since we add one entry at a time
|
|
6
|
+
*/
|
|
7
|
+
export declare function evictOldestEntries(): void;
|
|
8
|
+
/**
|
|
9
|
+
* Get or create a cached SourceFile
|
|
10
|
+
* Accepts an optional pre-computed contentHash to avoid re-hashing
|
|
11
|
+
*/
|
|
12
|
+
export declare function getSourceFile(filePath: string, sourceCode: string, precomputedHash?: number | bigint): SourceFile;
|
|
13
|
+
/**
|
|
14
|
+
* Clear the SourceFile cache (useful for testing or memory management)
|
|
15
|
+
*/
|
|
16
|
+
export declare function clearSourceFileCache(): void;
|
|
17
|
+
/**
|
|
18
|
+
* Get the current cache size (useful for debugging)
|
|
19
|
+
*/
|
|
20
|
+
export declare function getSourceFileCacheSize(): number;
|
|
21
|
+
/**
|
|
22
|
+
* Async version of getSourceFile that yields to the event loop for large files
|
|
23
|
+
* Prevents blocking when processing many large files in parallel
|
|
24
|
+
*/
|
|
25
|
+
export declare function getSourceFileAsync(filePath: string, sourceCode: string, config?: AsyncParseConfig): Promise<SourceFile>;
|
|
26
|
+
/**
|
|
27
|
+
* Batch parse multiple files asynchronously with concurrency control
|
|
28
|
+
* Useful for processing many files while keeping the event loop responsive
|
|
29
|
+
*/
|
|
30
|
+
export declare function batchParseSourceFiles(files: Array<{ filePath: string, sourceCode: string }>, config?: AsyncParseConfig & { concurrency?: number }): Promise<Map<string, SourceFile>>;
|
|
31
|
+
/**
|
|
32
|
+
* Check if a file should use async parsing based on size
|
|
33
|
+
*/
|
|
34
|
+
export declare function shouldUseAsyncParsing(sourceCode: string, config?: AsyncParseConfig): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Get statistics about pending parse operations
|
|
37
|
+
*/
|
|
38
|
+
export declare function getPendingParseCount(): number;
|
|
39
|
+
/**
|
|
40
|
+
* Configuration for async parsing
|
|
41
|
+
*/
|
|
42
|
+
export declare interface AsyncParseConfig {
|
|
43
|
+
asyncThreshold?: number
|
|
44
|
+
chunkSize?: number
|
|
45
|
+
yieldInterval?: number
|
|
46
|
+
}
|
|
47
|
+
export { hashContent } from './hash';
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { ClassDeclaration, EnumDeclaration, ExportAssignment, ExportDeclaration, FunctionDeclaration, ImportDeclaration, InterfaceDeclaration, ModuleDeclaration, SourceFile, TypeAliasDeclaration, VariableStatement } from 'typescript';
|
|
2
|
+
import type { Declaration } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Extract import declaration
|
|
5
|
+
*/
|
|
6
|
+
export declare function extractImportDeclaration(node: ImportDeclaration, sourceCode: string, sourceFile: SourceFile): Declaration;
|
|
7
|
+
/**
|
|
8
|
+
* Extract export declaration
|
|
9
|
+
*/
|
|
10
|
+
export declare function extractExportDeclaration(node: ExportDeclaration, sourceCode: string, sourceFile: SourceFile, keepComments?: boolean): Declaration;
|
|
11
|
+
/**
|
|
12
|
+
* Extract export assignment (export default)
|
|
13
|
+
*/
|
|
14
|
+
export declare function extractExportAssignment(node: ExportAssignment, sourceCode: string, sourceFile: SourceFile, keepComments?: boolean): Declaration;
|
|
15
|
+
/**
|
|
16
|
+
* Extract function declaration with proper signature
|
|
17
|
+
*/
|
|
18
|
+
export declare function extractFunctionDeclaration(node: FunctionDeclaration, _sourceCode: string, sourceFile: SourceFile, keepComments: boolean): Declaration | null;
|
|
19
|
+
/**
|
|
20
|
+
* Extract variable statement (only exported ones for DTS)
|
|
21
|
+
*/
|
|
22
|
+
export declare function extractVariableStatement(node: VariableStatement, _sourceCode: string, sourceFile: SourceFile, keepComments: boolean): Declaration[];
|
|
23
|
+
/**
|
|
24
|
+
* Extract interface declaration
|
|
25
|
+
*/
|
|
26
|
+
export declare function extractInterfaceDeclaration(node: InterfaceDeclaration, _sourceCode: string, sourceFile: SourceFile, keepComments: boolean): Declaration;
|
|
27
|
+
/**
|
|
28
|
+
* Extract type alias declaration
|
|
29
|
+
*/
|
|
30
|
+
export declare function extractTypeAliasDeclaration(node: TypeAliasDeclaration, _sourceCode: string, sourceFile: SourceFile, keepComments: boolean): Declaration;
|
|
31
|
+
/**
|
|
32
|
+
* Extract class declaration
|
|
33
|
+
*/
|
|
34
|
+
export declare function extractClassDeclaration(node: ClassDeclaration, _sourceCode: string, sourceFile: SourceFile, keepComments: boolean): Declaration;
|
|
35
|
+
/**
|
|
36
|
+
* Extract enum declaration
|
|
37
|
+
*/
|
|
38
|
+
export declare function extractEnumDeclaration(node: EnumDeclaration, sourceCode: string, sourceFile: SourceFile, keepComments: boolean): Declaration;
|
|
39
|
+
/**
|
|
40
|
+
* Extract module/namespace declaration
|
|
41
|
+
*/
|
|
42
|
+
export declare function extractModuleDeclaration(node: ModuleDeclaration, _sourceCode: string, sourceFile: SourceFile, keepComments: boolean): Declaration;
|
|
43
|
+
/**
|
|
44
|
+
* Find types that are referenced in declarations but not imported or declared
|
|
45
|
+
*/
|
|
46
|
+
export declare function findReferencedTypes(declarations: Declaration[], _sourceCode: string): Set<string>;
|
|
47
|
+
/**
|
|
48
|
+
* Extract declarations for referenced types by searching the entire source file
|
|
49
|
+
*/
|
|
50
|
+
export declare function extractReferencedTypeDeclarations(sourceFile: SourceFile, referencedTypes: Set<string>, sourceCode: string, keepComments?: boolean): Declaration[];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Triple-slash directive extraction — NO TypeScript dependency.
|
|
3
|
+
* Pure string processing for maximum startup speed.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Extract triple-slash directives from source code.
|
|
7
|
+
* These are special comments like /// <reference types="..." />
|
|
8
|
+
*/
|
|
9
|
+
export declare function extractTripleSlashDirectives(sourceCode: string): string[];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Declaration } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Extract declarations using the fast string scanner (no TS parser).
|
|
4
|
+
* Results are cached by file path + keepComments flag.
|
|
5
|
+
*/
|
|
6
|
+
export declare function extractDeclarations(sourceCode: string, filePath: string, keepComments?: boolean, isolatedDeclarations?: boolean): Declaration[];
|
|
7
|
+
/**
|
|
8
|
+
* Clear the declaration cache (for benchmarks and testing)
|
|
9
|
+
*/
|
|
10
|
+
export declare function clearDeclarationCache(): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function hashContent(content: string): number | bigint;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { FunctionDeclaration, Node, ParameterDeclaration, SourceFile } from 'typescript';
|
|
2
|
+
/**
|
|
3
|
+
* Get the text of a node from source code
|
|
4
|
+
*/
|
|
5
|
+
export declare function getNodeText(node: Node, sourceCode: string, sf?: SourceFile): string;
|
|
6
|
+
/**
|
|
7
|
+
* Extract JSDoc comments from a node
|
|
8
|
+
*/
|
|
9
|
+
export declare function extractJSDocComments(node: Node, sourceFile: SourceFile): string[];
|
|
10
|
+
/**
|
|
11
|
+
* Get parameter name without default values for DTS
|
|
12
|
+
*/
|
|
13
|
+
export declare function getParameterName(param: ParameterDeclaration, sf?: SourceFile): string;
|
|
14
|
+
/**
|
|
15
|
+
* Check if a node has export modifier
|
|
16
|
+
*/
|
|
17
|
+
export declare function hasExportModifier(node: Node): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Check if a function has async modifier
|
|
20
|
+
*/
|
|
21
|
+
export declare function hasAsyncModifier(node: FunctionDeclaration): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Check if a non-exported function should be included (e.g., if it's referenced by exported items)
|
|
24
|
+
*/
|
|
25
|
+
export declare function shouldIncludeNonExportedFunction(_functionName?: string, _sourceCode?: string): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Check if a non-exported interface should be included (e.g., if it's used by exported items)
|
|
28
|
+
*/
|
|
29
|
+
export declare function shouldIncludeNonExportedInterface(interfaceName: string, sourceCode: string): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Check if a type is a built-in TypeScript type
|
|
32
|
+
*/
|
|
33
|
+
export declare function isBuiltInType(typeName: string): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Extract type names from module/namespace text
|
|
36
|
+
*/
|
|
37
|
+
export declare function extractTypesFromModuleText(moduleText: string): string[];
|
|
38
|
+
// Re-exported from directives.ts for backward compatibility
|
|
39
|
+
export { extractTripleSlashDirectives } from './directives';
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { extractClassDeclaration, extractEnumDeclaration, extractExportAssignment, extractExportDeclaration, extractFunctionDeclaration, extractImportDeclaration, extractInterfaceDeclaration, extractModuleDeclaration, extractTypeAliasDeclaration, extractVariableStatement, findReferencedTypes } from './declarations';
|
|
2
|
+
import { getSourceFileAsync } from './cache';
|
|
3
|
+
import { shouldIncludeNonExportedFunction, shouldIncludeNonExportedInterface } from './helpers';
|
|
4
|
+
import type { AsyncParseConfig } from './cache';
|
|
5
|
+
import type { Declaration } from '../types';
|
|
6
|
+
export type { AsyncParseConfig } from './cache';
|
|
7
|
+
/**
|
|
8
|
+
* Clear all extractor caches (source files and declarations)
|
|
9
|
+
*/
|
|
10
|
+
export declare function clearSourceFileCache(): void;
|
|
11
|
+
/**
|
|
12
|
+
* Extract only public API declarations from TypeScript source code
|
|
13
|
+
* Uses fast string-based scanner (no TypeScript parser) for maximum performance.
|
|
14
|
+
* Delegates to extract.ts which owns the shared declaration cache with proper LRU eviction.
|
|
15
|
+
*/
|
|
16
|
+
export declare function extractDeclarations(sourceCode: string, filePath: string, keepComments?: boolean, isolatedDeclarations?: boolean): Declaration[];
|
|
17
|
+
/**
|
|
18
|
+
* Async version of extractDeclarations that yields to the event loop for large files
|
|
19
|
+
* Use this when processing many files in parallel to prevent blocking
|
|
20
|
+
*/
|
|
21
|
+
export declare function extractDeclarationsAsync(sourceCode: string, filePath: string, keepComments?: boolean, config?: AsyncParseConfig): Promise<Declaration[]>;
|
|
22
|
+
/**
|
|
23
|
+
* Batch extract declarations from multiple files asynchronously
|
|
24
|
+
* Useful for processing many files while keeping the event loop responsive
|
|
25
|
+
*/
|
|
26
|
+
export declare function batchExtractDeclarations(files: Array<{ filePath: string, sourceCode: string, keepComments?: boolean }>, config?: AsyncParseConfig & { concurrency?: number }): Promise<Map<string, Declaration[]>>;
|
|
27
|
+
export {
|
|
28
|
+
buildClassBody,
|
|
29
|
+
buildClassDeclaration,
|
|
30
|
+
buildFunctionSignature,
|
|
31
|
+
buildInterfaceDeclaration,
|
|
32
|
+
buildModuleBody,
|
|
33
|
+
buildModuleDeclaration,
|
|
34
|
+
buildTypeDeclaration,
|
|
35
|
+
buildVariableDeclaration,
|
|
36
|
+
getInterfaceBody,
|
|
37
|
+
} from './builders';
|
|
38
|
+
export {
|
|
39
|
+
batchParseSourceFiles,
|
|
40
|
+
getPendingParseCount,
|
|
41
|
+
getSourceFileAsync,
|
|
42
|
+
getSourceFileCacheSize,
|
|
43
|
+
shouldUseAsyncParsing,
|
|
44
|
+
} from './cache';
|
|
45
|
+
export {
|
|
46
|
+
extractClassDeclaration,
|
|
47
|
+
extractEnumDeclaration,
|
|
48
|
+
extractExportAssignment,
|
|
49
|
+
extractExportDeclaration,
|
|
50
|
+
extractFunctionDeclaration,
|
|
51
|
+
extractImportDeclaration,
|
|
52
|
+
extractInterfaceDeclaration,
|
|
53
|
+
extractModuleDeclaration,
|
|
54
|
+
extractReferencedTypeDeclarations,
|
|
55
|
+
extractTypeAliasDeclaration,
|
|
56
|
+
extractVariableStatement,
|
|
57
|
+
findReferencedTypes,
|
|
58
|
+
} from './declarations';
|
|
59
|
+
export {
|
|
60
|
+
extractJSDocComments,
|
|
61
|
+
extractTripleSlashDirectives,
|
|
62
|
+
extractTypesFromModuleText,
|
|
63
|
+
getNodeText,
|
|
64
|
+
getParameterName,
|
|
65
|
+
hasAsyncModifier,
|
|
66
|
+
hasExportModifier,
|
|
67
|
+
isBuiltInType,
|
|
68
|
+
shouldIncludeNonExportedFunction,
|
|
69
|
+
shouldIncludeNonExportedInterface,
|
|
70
|
+
} from './helpers';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Declaration } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Scan TypeScript source code and extract declarations without using the TypeScript parser.
|
|
4
|
+
* This is the fast path that replaces createSourceFile() + AST walk.
|
|
5
|
+
*/
|
|
6
|
+
export declare function scanDeclarations(_source: string, _filename: string, _keepComments?: boolean, _isolatedDeclarations?: boolean): Declaration[];
|
package/dist/extractor.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { Declaration } from './types';
|
|
2
1
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Extractor module - re-exports from modular structure
|
|
3
|
+
* @deprecated Import from './extractor/index' directly for better tree-shaking
|
|
5
4
|
*/
|
|
6
|
-
export
|
|
5
|
+
export * from './extractor/index';
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Declaration } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Convert declarations to JSON Schema
|
|
4
|
+
*/
|
|
5
|
+
export declare function toJsonSchema(declarations: Declaration[], options?: Partial<FormatOptions>): string;
|
|
6
|
+
/**
|
|
7
|
+
* Convert declarations to Zod schema
|
|
8
|
+
*/
|
|
9
|
+
export declare function toZod(declarations: Declaration[], options?: Partial<FormatOptions>): string;
|
|
10
|
+
/**
|
|
11
|
+
* Convert declarations to Valibot schema
|
|
12
|
+
*/
|
|
13
|
+
export declare function toValibot(declarations: Declaration[], options?: Partial<FormatOptions>): string;
|
|
14
|
+
/**
|
|
15
|
+
* Convert declarations to io-ts codec
|
|
16
|
+
*/
|
|
17
|
+
export declare function toIoTs(declarations: Declaration[], options?: Partial<FormatOptions>): string;
|
|
18
|
+
/**
|
|
19
|
+
* Convert declarations to Yup schema
|
|
20
|
+
*/
|
|
21
|
+
export declare function toYup(declarations: Declaration[], options?: Partial<FormatOptions>): string;
|
|
22
|
+
/**
|
|
23
|
+
* Convert declarations to ArkType schema
|
|
24
|
+
*/
|
|
25
|
+
export declare function toArkType(declarations: Declaration[], options?: Partial<FormatOptions>): string;
|
|
26
|
+
/**
|
|
27
|
+
* Convert declarations to the specified format
|
|
28
|
+
*/
|
|
29
|
+
export declare function convertToFormat(declarations: Declaration[], options: FormatOptions): string;
|
|
30
|
+
/**
|
|
31
|
+
* Get file extension for output format
|
|
32
|
+
*/
|
|
33
|
+
export declare function getFormatExtension(format: OutputFormat): string;
|
|
34
|
+
/**
|
|
35
|
+
* Options for format conversion
|
|
36
|
+
*/
|
|
37
|
+
export declare interface FormatOptions {
|
|
38
|
+
format: OutputFormat
|
|
39
|
+
includeSchema?: boolean
|
|
40
|
+
jsonSchemaDraft?: '2020-12' | '2019-09' | 'draft-07'
|
|
41
|
+
allOptional?: boolean
|
|
42
|
+
includeDescriptions?: boolean
|
|
43
|
+
indent?: number
|
|
44
|
+
exportName?: string
|
|
45
|
+
useInfer?: boolean
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Supported output formats
|
|
49
|
+
*/
|
|
50
|
+
export type OutputFormat = 'dts' | 'json-schema' | 'zod' | 'io-ts' | 'yup' | 'valibot' | 'arktype';
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format declaration file content
|
|
3
|
+
*/
|
|
4
|
+
export declare function formatDts(content: string, config?: FormatterConfig, filePath?: string): Promise<FormatResult>;
|
|
5
|
+
/**
|
|
6
|
+
* Format multiple files
|
|
7
|
+
*/
|
|
8
|
+
export declare function formatFiles(files: Map<string, string>, config?: FormatterConfig): Promise<Map<string, FormatResult>>;
|
|
9
|
+
/**
|
|
10
|
+
* Create a formatter with preset configuration
|
|
11
|
+
*/
|
|
12
|
+
export declare function createFormatter(config?: FormatterConfig): {
|
|
13
|
+
format: (content: string, filePath?: string) => Promise<FormatResult>
|
|
14
|
+
formatMany: (files: Map<string, string>) => Promise<Map<string, FormatResult>>
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Quick format with sensible defaults
|
|
18
|
+
*/
|
|
19
|
+
export declare function quickFormat(content: string): Promise<string>;
|
|
20
|
+
/**
|
|
21
|
+
* Formatter configuration options
|
|
22
|
+
*/
|
|
23
|
+
export declare interface FormatterConfig {
|
|
24
|
+
usePrettier?: boolean
|
|
25
|
+
prettierConfigPath?: string
|
|
26
|
+
prettierOptions?: PrettierOptions
|
|
27
|
+
builtIn?: BuiltInFormatterOptions
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Prettier-compatible options
|
|
31
|
+
*/
|
|
32
|
+
export declare interface PrettierOptions {
|
|
33
|
+
printWidth?: number
|
|
34
|
+
tabWidth?: number
|
|
35
|
+
useTabs?: boolean
|
|
36
|
+
semi?: boolean
|
|
37
|
+
singleQuote?: boolean
|
|
38
|
+
trailingComma?: 'none' | 'es5' | 'all'
|
|
39
|
+
bracketSpacing?: boolean
|
|
40
|
+
parser?: string
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Built-in formatter options (when Prettier is not available)
|
|
44
|
+
*/
|
|
45
|
+
export declare interface BuiltInFormatterOptions {
|
|
46
|
+
indentSize?: number
|
|
47
|
+
useTabs?: boolean
|
|
48
|
+
maxLineWidth?: number
|
|
49
|
+
trailingNewline?: boolean
|
|
50
|
+
normalizeWhitespace?: boolean
|
|
51
|
+
sortImports?: boolean
|
|
52
|
+
groupImports?: boolean
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Result of formatting operation
|
|
56
|
+
*/
|
|
57
|
+
export declare interface FormatResult {
|
|
58
|
+
content: string
|
|
59
|
+
usedPrettier: boolean
|
|
60
|
+
warnings?: string[]
|
|
61
|
+
}
|
package/dist/generator.d.ts
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
|
-
import type { DtsGenerationConfig } from './types';
|
|
1
|
+
import type { DtsGenerationConfig, GenerationStats } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* Generate DTS files from TypeScript source files
|
|
4
4
|
*/
|
|
5
|
-
export declare function generate(options?: Partial<DtsGenerationConfig>): Promise<
|
|
5
|
+
export declare function generate(options?: Partial<DtsGenerationConfig>): Promise<GenerationStats>;
|
|
6
6
|
/**
|
|
7
7
|
* Process a single TypeScript file and generate its DTS
|
|
8
8
|
*/
|
|
9
|
-
export declare function processFile(filePath: string, config: DtsGenerationConfig): Promise<string>;
|
|
9
|
+
export declare function processFile(filePath: string, config: DtsGenerationConfig): Promise<string>;
|
|
10
|
+
/**
|
|
11
|
+
* Watch mode - regenerate DTS files on source changes
|
|
12
|
+
*/
|
|
13
|
+
export declare function watch(options?: Partial<DtsGenerationConfig>): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Process TypeScript source code from a string (for stdin support)
|
|
16
|
+
* Re-exported from process-source.ts for backward compatibility
|
|
17
|
+
*/
|
|
18
|
+
export { processSource } from './process-source';
|