@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
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import type { Declaration, DeclarationKind, ParameterDeclaration } from './types';
|
|
2
|
+
import type { Plugin } from './plugins';
|
|
3
|
+
/**
|
|
4
|
+
* Create a new declaration with defaults
|
|
5
|
+
*/
|
|
6
|
+
export declare function createDeclaration(kind: DeclarationKind, name: string, text: string, options?: Partial<Omit<Declaration, 'kind' | 'name' | 'text'>>): Declaration;
|
|
7
|
+
/**
|
|
8
|
+
* Clone a declaration (deep copy)
|
|
9
|
+
*/
|
|
10
|
+
export declare function cloneDeclaration(decl: Declaration): Declaration;
|
|
11
|
+
/**
|
|
12
|
+
* Walk declarations with a visitor
|
|
13
|
+
*/
|
|
14
|
+
export declare function walkDeclarations(declarations: Declaration[], visitor: DeclarationVisitor, parent?: Declaration | null): void;
|
|
15
|
+
/**
|
|
16
|
+
* Find declarations matching a predicate
|
|
17
|
+
*/
|
|
18
|
+
export declare function findDeclarations(declarations: Declaration[], predicate: (decl: Declaration) => boolean): Declaration[];
|
|
19
|
+
/**
|
|
20
|
+
* Map declarations with a transformer
|
|
21
|
+
*/
|
|
22
|
+
export declare function mapDeclarations(declarations: Declaration[], transformer: Transformer, context: Omit<TransformerContext, 'index' | 'total' | 'allDeclarations'>): Promise<Declaration[]>;
|
|
23
|
+
/**
|
|
24
|
+
* Compose multiple transformers into one
|
|
25
|
+
*/
|
|
26
|
+
export declare function composeTransformers(...transformers: Transformer[]): Transformer;
|
|
27
|
+
/**
|
|
28
|
+
* Create a transformer that only applies to specific declaration kinds
|
|
29
|
+
*/
|
|
30
|
+
export declare function filterByKind(kinds: DeclarationKind | DeclarationKind[], transformer: Transformer): Transformer;
|
|
31
|
+
/**
|
|
32
|
+
* Create a transformer that only applies when a predicate is true
|
|
33
|
+
*/
|
|
34
|
+
export declare function filterByPredicate(predicate: (decl: Declaration) => boolean, transformer: Transformer): Transformer;
|
|
35
|
+
/**
|
|
36
|
+
* Create a transformer plugin from transformers
|
|
37
|
+
*/
|
|
38
|
+
export declare function createTransformerPlugin(options: {
|
|
39
|
+
name: string
|
|
40
|
+
version?: string
|
|
41
|
+
description?: string
|
|
42
|
+
/** Transform source code before parsing */
|
|
43
|
+
beforeParse?: TextTransformer
|
|
44
|
+
/** Transform declarations */
|
|
45
|
+
transform?: Transformer
|
|
46
|
+
/** Transform generated .d.ts content after generation */
|
|
47
|
+
afterGenerate?: TextTransformer
|
|
48
|
+
}): Plugin;
|
|
49
|
+
/**
|
|
50
|
+
* Rename declarations matching a pattern
|
|
51
|
+
*/
|
|
52
|
+
export declare function createRenameTransformer(pattern: string | RegExp, replacement: string | ((_match: string, _decl: Declaration) => string)): Transformer;
|
|
53
|
+
/**
|
|
54
|
+
* Add a prefix to declaration names
|
|
55
|
+
*/
|
|
56
|
+
export declare function createPrefixTransformer(prefix: string, filter?: (decl: Declaration) => boolean): Transformer;
|
|
57
|
+
/**
|
|
58
|
+
* Add a suffix to declaration names
|
|
59
|
+
*/
|
|
60
|
+
export declare function createSuffixTransformer(suffix: string, filter?: (decl: Declaration) => boolean): Transformer;
|
|
61
|
+
/**
|
|
62
|
+
* Remove declarations by name pattern
|
|
63
|
+
*/
|
|
64
|
+
export declare function createRemoveTransformer(pattern: string | RegExp | ((_decl: Declaration) => boolean)): Transformer;
|
|
65
|
+
/**
|
|
66
|
+
* Add JSDoc comments to declarations
|
|
67
|
+
*/
|
|
68
|
+
export declare function createJSDocTransformer(getJSDoc: (decl: Declaration) => string | string[] | null | undefined): Transformer;
|
|
69
|
+
/**
|
|
70
|
+
* Modify type annotations
|
|
71
|
+
*/
|
|
72
|
+
export declare function createTypeTransformer(transformer: (type: string, decl: Declaration) => string | null | undefined): Transformer;
|
|
73
|
+
/**
|
|
74
|
+
* Modify return types of functions
|
|
75
|
+
*/
|
|
76
|
+
export declare function createReturnTypeTransformer(transformer: (returnType: string, decl: Declaration) => string | null | undefined): Transformer;
|
|
77
|
+
/**
|
|
78
|
+
* Transform function parameters
|
|
79
|
+
*/
|
|
80
|
+
export declare function createParameterTransformer(transformer: (
|
|
81
|
+
params: ParameterDeclaration[],
|
|
82
|
+
decl: Declaration,
|
|
83
|
+
) => ParameterDeclaration[] | null | undefined): Transformer;
|
|
84
|
+
/**
|
|
85
|
+
* Add modifiers (export, declare, etc.)
|
|
86
|
+
*/
|
|
87
|
+
export declare function createModifierTransformer(modifier: string, filter?: (decl: Declaration) => boolean): Transformer;
|
|
88
|
+
/**
|
|
89
|
+
* Strip specific JSDoc tags
|
|
90
|
+
*/
|
|
91
|
+
export declare function createStripTagsTransformer(tags: string[]): Transformer;
|
|
92
|
+
/**
|
|
93
|
+
* Wrap types in a utility type
|
|
94
|
+
*/
|
|
95
|
+
export declare function createWrapTypeTransformer(utilityType: string, filter?: (decl: Declaration) => boolean): Transformer;
|
|
96
|
+
/**
|
|
97
|
+
* Plugin that prefixes all exported types with a namespace
|
|
98
|
+
*/
|
|
99
|
+
export declare function createNamespacePrefixPlugin(namespace: string): Plugin;
|
|
100
|
+
/**
|
|
101
|
+
* Plugin that makes all interface properties readonly
|
|
102
|
+
*/
|
|
103
|
+
export declare const readonlyPlugin: Plugin;
|
|
104
|
+
/**
|
|
105
|
+
* Plugin that strips @internal, @private, and @hidden tags
|
|
106
|
+
*/
|
|
107
|
+
export declare const stripPrivatePlugin: Plugin;
|
|
108
|
+
/**
|
|
109
|
+
* Plugin that adds 'declare' keyword to all declarations
|
|
110
|
+
*/
|
|
111
|
+
export declare const declarePlugin: Plugin;
|
|
112
|
+
/**
|
|
113
|
+
* Context available to transformers
|
|
114
|
+
*/
|
|
115
|
+
export declare interface TransformerContext {
|
|
116
|
+
filePath: string
|
|
117
|
+
sourceCode: string
|
|
118
|
+
index: number
|
|
119
|
+
total: number
|
|
120
|
+
allDeclarations: readonly Declaration[]
|
|
121
|
+
createDeclaration: typeof createDeclaration
|
|
122
|
+
cloneDeclaration: typeof cloneDeclaration
|
|
123
|
+
modifyText: (decl: Declaration, text: string) => Declaration
|
|
124
|
+
addModifier: (decl: Declaration, modifier: string) => Declaration
|
|
125
|
+
removeModifier: (decl: Declaration, modifier: string) => Declaration
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Context for text transformers
|
|
129
|
+
*/
|
|
130
|
+
export declare interface TextTransformerContext {
|
|
131
|
+
filePath: string
|
|
132
|
+
phase: 'before' | 'after'
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Visitor pattern for walking declaration trees
|
|
136
|
+
*/
|
|
137
|
+
export declare interface DeclarationVisitor {
|
|
138
|
+
enter?: (decl: Declaration, parent: Declaration | null) => void
|
|
139
|
+
leave?: (decl: Declaration, parent: Declaration | null) => void
|
|
140
|
+
function?: (_decl: Declaration, _parent: Declaration | null) => void
|
|
141
|
+
variable?: (decl: Declaration, parent: Declaration | null) => void
|
|
142
|
+
interface?: (decl: Declaration, parent: Declaration | null) => void
|
|
143
|
+
type?: (decl: Declaration, parent: Declaration | null) => void
|
|
144
|
+
class?: (decl: Declaration, parent: Declaration | null) => void
|
|
145
|
+
enum?: (decl: Declaration, parent: Declaration | null) => void
|
|
146
|
+
import?: (decl: Declaration, parent: Declaration | null) => void
|
|
147
|
+
export?: (decl: Declaration, parent: Declaration | null) => void
|
|
148
|
+
module?: (decl: Declaration, parent: Declaration | null) => void
|
|
149
|
+
namespace?: (decl: Declaration, parent: Declaration | null) => void
|
|
150
|
+
unknown?: (decl: Declaration, parent: Declaration | null) => void
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Result of a transformer, can be:
|
|
154
|
+
* - Declaration: replaced declaration
|
|
155
|
+
* - Declaration[]: multiple declarations (split)
|
|
156
|
+
* - null: remove the declaration
|
|
157
|
+
* - undefined: no change
|
|
158
|
+
*/
|
|
159
|
+
export type TransformResult = Declaration | Declaration[] | null | undefined;
|
|
160
|
+
/**
|
|
161
|
+
* Transformer function that operates on a single declaration
|
|
162
|
+
*/
|
|
163
|
+
export type Transformer = (
|
|
164
|
+
declaration: Declaration,
|
|
165
|
+
context: TransformerContext,
|
|
166
|
+
) => TransformResult | Promise<TransformResult>;
|
|
167
|
+
/**
|
|
168
|
+
* Text transformer operates on the raw text before/after processing
|
|
169
|
+
*/
|
|
170
|
+
export type TextTransformer = (
|
|
171
|
+
content: string,
|
|
172
|
+
context: TextTransformerContext,
|
|
173
|
+
) => string | Promise<string>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { Declaration, DeclarationKind } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Shake unused declarations from the tree
|
|
4
|
+
*/
|
|
5
|
+
export declare function treeShake(declarations: Declaration[], config?: TreeShakeConfig): TreeShakeResult;
|
|
6
|
+
/**
|
|
7
|
+
* Build a declaration dependency graph for tree shaking
|
|
8
|
+
*/
|
|
9
|
+
export declare function buildDeclarationDependencyGraph(declarations: Declaration[]): Map<string, Set<string>>;
|
|
10
|
+
/**
|
|
11
|
+
* Extract type references from a declaration
|
|
12
|
+
*/
|
|
13
|
+
export declare function extractTypeReferences(decl: Declaration): Set<string>;
|
|
14
|
+
/**
|
|
15
|
+
* Tree shake content string
|
|
16
|
+
*/
|
|
17
|
+
export declare function treeShakeContent(content: string, config?: TreeShakeConfig): { content: string, removed: string[] };
|
|
18
|
+
/**
|
|
19
|
+
* Get unused declarations (those that could be removed)
|
|
20
|
+
*/
|
|
21
|
+
export declare function findUnusedDeclarations(declarations: Declaration[], config?: Omit<TreeShakeConfig, 'debug'>): string[];
|
|
22
|
+
/**
|
|
23
|
+
* Analyze dependencies for a declaration
|
|
24
|
+
*/
|
|
25
|
+
export declare function analyzeDependencies(declarationName: string, declarations: Declaration[]): {
|
|
26
|
+
directDependencies: string[]
|
|
27
|
+
transitiveDependencies: string[]
|
|
28
|
+
dependents: string[]
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Create a tree shaker with preset configuration
|
|
32
|
+
*/
|
|
33
|
+
export declare function createTreeShaker(config?: TreeShakeConfig): {
|
|
34
|
+
shake: (declarations: Declaration[]) => TreeShakeResult
|
|
35
|
+
shakeContent: (content: string) => { content: string, removed: string[] }
|
|
36
|
+
findUnused: (declarations: Declaration[]) => string[]
|
|
37
|
+
analyzeDependencies: (name: string, declarations: Declaration[]) => { directDependencies: string[], transitiveDependencies: string[], dependents: string[] }
|
|
38
|
+
buildGraph: typeof buildDeclarationDependencyGraph
|
|
39
|
+
extractRefs: typeof extractTypeReferences
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Tree shaking configuration
|
|
43
|
+
*/
|
|
44
|
+
export declare interface TreeShakeConfig {
|
|
45
|
+
entryPoints?: string[]
|
|
46
|
+
keepExported?: boolean
|
|
47
|
+
keep?: (string | RegExp)[]
|
|
48
|
+
remove?: (string | RegExp)[]
|
|
49
|
+
shakableKinds?: DeclarationKind[]
|
|
50
|
+
debug?: boolean
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Result of tree shaking
|
|
54
|
+
*/
|
|
55
|
+
export declare interface TreeShakeResult {
|
|
56
|
+
declarations: Declaration[]
|
|
57
|
+
removed: string[]
|
|
58
|
+
dependencyGraph: Map<string, Set<string>>
|
|
59
|
+
stats: TreeShakeStats
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Tree shaking statistics
|
|
63
|
+
*/
|
|
64
|
+
export declare interface TreeShakeStats {
|
|
65
|
+
totalBefore: number
|
|
66
|
+
totalAfter: number
|
|
67
|
+
removedCount: number
|
|
68
|
+
reductionPercent: number
|
|
69
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get preset mappings
|
|
3
|
+
*/
|
|
4
|
+
export declare function getPresetMappings(preset: TypeMappingPreset): TypeMappingRule[];
|
|
5
|
+
/**
|
|
6
|
+
* Create a type mapper with configuration
|
|
7
|
+
*/
|
|
8
|
+
export declare function createTypeMapper(config?: TypeMappingConfig): TypeMapper;
|
|
9
|
+
/**
|
|
10
|
+
* Apply type mappings to declaration text
|
|
11
|
+
*/
|
|
12
|
+
export declare function applyTypeMappings(declarationText: string, mapper: TypeMapper, context?: Partial<TypeMappingContext>): string;
|
|
13
|
+
/**
|
|
14
|
+
* Default type mapper instance
|
|
15
|
+
*/
|
|
16
|
+
export declare const defaultTypeMapper: TypeMapper;
|
|
17
|
+
/**
|
|
18
|
+
* Strict type mapper instance
|
|
19
|
+
*/
|
|
20
|
+
export declare const strictTypeMapper: TypeMapper;
|
|
21
|
+
/**
|
|
22
|
+
* Built-in type transformers
|
|
23
|
+
* @defaultValue
|
|
24
|
+
* ```ts
|
|
25
|
+
* {
|
|
26
|
+
* makeReadonly: (type: string) => any,
|
|
27
|
+
* makeNullable: (type: string) => any,
|
|
28
|
+
* makeOptional: (type: string) => any,
|
|
29
|
+
* makeRequired: (type: string) => any,
|
|
30
|
+
* promisify: (type: string) => any,
|
|
31
|
+
* unpromisify: (type: string) => any,
|
|
32
|
+
* arrayify: (type: string) => any,
|
|
33
|
+
* unarrayify: (type: string) => any
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare const TypeTransformers: {
|
|
38
|
+
/**
|
|
39
|
+
* Make all types readonly
|
|
40
|
+
*/
|
|
41
|
+
makeReadonly: (type: string) => any;
|
|
42
|
+
/**
|
|
43
|
+
* Make type nullable
|
|
44
|
+
*/
|
|
45
|
+
makeNullable: (type: string) => any;
|
|
46
|
+
/**
|
|
47
|
+
* Make type optional (add undefined)
|
|
48
|
+
*/
|
|
49
|
+
makeOptional: (type: string) => any;
|
|
50
|
+
/**
|
|
51
|
+
* Remove null/undefined from type
|
|
52
|
+
*/
|
|
53
|
+
makeRequired: (type: string) => any;
|
|
54
|
+
/**
|
|
55
|
+
* Wrap in Promise
|
|
56
|
+
*/
|
|
57
|
+
promisify: (type: string) => any;
|
|
58
|
+
/**
|
|
59
|
+
* Unwrap Promise
|
|
60
|
+
*/
|
|
61
|
+
unpromisify: (type: string) => any;
|
|
62
|
+
/**
|
|
63
|
+
* Convert to array type
|
|
64
|
+
*/
|
|
65
|
+
arrayify: (type: string) => any;
|
|
66
|
+
/**
|
|
67
|
+
* Unwrap array type
|
|
68
|
+
*/
|
|
69
|
+
unarrayify: (type: string) => any
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Custom type mappings for DTS generation
|
|
73
|
+
* Allows users to specify type replacements and transformations
|
|
74
|
+
*/
|
|
75
|
+
/**
|
|
76
|
+
* Type mapping rule
|
|
77
|
+
*/
|
|
78
|
+
export declare interface TypeMappingRule {
|
|
79
|
+
pattern: string | RegExp
|
|
80
|
+
replacement: string
|
|
81
|
+
condition?: (context: TypeMappingContext) => boolean
|
|
82
|
+
global?: boolean
|
|
83
|
+
priority?: number
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Context passed to type mapping functions
|
|
87
|
+
*/
|
|
88
|
+
export declare interface TypeMappingContext {
|
|
89
|
+
type: string
|
|
90
|
+
declarationName?: string
|
|
91
|
+
declarationKind?: string
|
|
92
|
+
filePath?: string
|
|
93
|
+
isReturnType?: boolean
|
|
94
|
+
isParameterType?: boolean
|
|
95
|
+
isPropertyType?: boolean
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Type mapping configuration
|
|
99
|
+
*/
|
|
100
|
+
export declare interface TypeMappingConfig {
|
|
101
|
+
rules: TypeMappingRule[]
|
|
102
|
+
presets?: TypeMappingPreset[]
|
|
103
|
+
includeDefaults?: boolean
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Available type mapping presets
|
|
107
|
+
*/
|
|
108
|
+
export type TypeMappingPreset = | 'strict' // Convert 'any' to 'unknown'
|
|
109
|
+
| 'readonly' // Add readonly to array types
|
|
110
|
+
| 'nullable' // Convert undefined unions to optional
|
|
111
|
+
| 'branded' // Use branded types for primitives
|
|
112
|
+
| 'simplified' // Simplify complex utility types;
|
|
113
|
+
/**
|
|
114
|
+
* Type mapper class for applying transformations
|
|
115
|
+
*/
|
|
116
|
+
export declare class TypeMapper {
|
|
117
|
+
constructor(config?: TypeMappingConfig);
|
|
118
|
+
map(type: string, context?: Partial<TypeMappingContext>): string;
|
|
119
|
+
mapAll(types: string[], context?: Partial<TypeMappingContext>): string[];
|
|
120
|
+
addRule(rule: TypeMappingRule): void;
|
|
121
|
+
removeRules(pattern: string | RegExp): number;
|
|
122
|
+
clearCache(): void;
|
|
123
|
+
getRules(): readonly TypeMappingRule[];
|
|
124
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -13,6 +13,131 @@ export declare interface DtsGenerationConfig {
|
|
|
13
13
|
tsconfigPath: string
|
|
14
14
|
verbose: boolean | string[]
|
|
15
15
|
outputStructure?: 'mirror' | 'flat'
|
|
16
|
+
importOrder?: string[]
|
|
17
|
+
dryRun?: boolean
|
|
18
|
+
stats?: boolean
|
|
19
|
+
continueOnError?: boolean
|
|
20
|
+
logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'silent'
|
|
21
|
+
exclude?: string[]
|
|
22
|
+
outputFormat?: 'text' | 'json'
|
|
23
|
+
progress?: boolean
|
|
24
|
+
diff?: boolean
|
|
25
|
+
validate?: boolean
|
|
26
|
+
watch?: boolean
|
|
27
|
+
parallel?: boolean
|
|
28
|
+
concurrency?: number
|
|
29
|
+
declarationMap?: boolean
|
|
30
|
+
plugins?: import('./plugins').Plugin[]
|
|
31
|
+
bundle?: boolean
|
|
32
|
+
bundleOutput?: string
|
|
33
|
+
incremental?: boolean
|
|
34
|
+
clearCache?: boolean
|
|
35
|
+
indentStyle?: 'spaces' | 'tabs'
|
|
36
|
+
indentSize?: number
|
|
37
|
+
prettier?: boolean
|
|
38
|
+
include?: string[]
|
|
39
|
+
isolatedDeclarations?: boolean
|
|
40
|
+
typeMappings?: import('./type-mappings').TypeMappingConfig
|
|
41
|
+
lineEnding?: 'lf' | 'crlf' | 'auto'
|
|
42
|
+
normalizeOutput?: boolean
|
|
43
|
+
declarationOrder?: {
|
|
44
|
+
kinds?: import('./types').DeclarationKind[]
|
|
45
|
+
alphabetize?: boolean
|
|
46
|
+
groupExports?: boolean
|
|
47
|
+
}
|
|
48
|
+
tracking?: TrackingConfig
|
|
49
|
+
profiling?: ProfilingConfig
|
|
50
|
+
typeInference?: TypeInferenceConfig
|
|
51
|
+
typeChecking?: TypeCheckingConfig
|
|
52
|
+
typeValidation?: TypeValidationConfig
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Tracking configuration for debugging type and import usage
|
|
56
|
+
*/
|
|
57
|
+
export declare interface TrackingConfig {
|
|
58
|
+
types?: boolean
|
|
59
|
+
relationships?: boolean
|
|
60
|
+
usage?: boolean
|
|
61
|
+
imports?: boolean
|
|
62
|
+
importUsage?: boolean
|
|
63
|
+
importRelationships?: boolean
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Profiling configuration for performance analysis
|
|
67
|
+
*/
|
|
68
|
+
export declare interface ProfilingConfig {
|
|
69
|
+
memory?: boolean
|
|
70
|
+
memoryLimit?: number
|
|
71
|
+
cpu?: boolean
|
|
72
|
+
samplingInterval?: number
|
|
73
|
+
io?: boolean
|
|
74
|
+
trackOperations?: ('read' | 'write')[]
|
|
75
|
+
outputFile?: string
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Type inference configuration
|
|
79
|
+
*/
|
|
80
|
+
export declare interface TypeInferenceConfig {
|
|
81
|
+
enabled?: boolean
|
|
82
|
+
strictness?: 'loose' | 'normal' | 'strict'
|
|
83
|
+
inferReturnTypes?: boolean
|
|
84
|
+
inferConstTypes?: boolean
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Type checking configuration
|
|
88
|
+
*/
|
|
89
|
+
export declare interface TypeCheckingConfig {
|
|
90
|
+
enabled?: boolean
|
|
91
|
+
strictness?: 'loose' | 'normal' | 'strict'
|
|
92
|
+
warningsAsErrors?: boolean
|
|
93
|
+
maxErrors?: number
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Type validation configuration
|
|
97
|
+
*/
|
|
98
|
+
export declare interface TypeValidationConfig {
|
|
99
|
+
enabled?: boolean
|
|
100
|
+
rules?: {
|
|
101
|
+
noAny?: boolean
|
|
102
|
+
noUnknown?: boolean
|
|
103
|
+
noImplicitAny?: boolean
|
|
104
|
+
explicitReturnTypes?: boolean
|
|
105
|
+
explicitParameterTypes?: boolean
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Source location for error reporting
|
|
110
|
+
*/
|
|
111
|
+
export declare interface SourceLocation {
|
|
112
|
+
line: number
|
|
113
|
+
column: number
|
|
114
|
+
offset?: number
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Detailed error information with source location
|
|
118
|
+
*/
|
|
119
|
+
export declare interface DtsError {
|
|
120
|
+
file: string
|
|
121
|
+
message: string
|
|
122
|
+
code?: string
|
|
123
|
+
location?: SourceLocation
|
|
124
|
+
stack?: string
|
|
125
|
+
suggestion?: string
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Generation statistics
|
|
129
|
+
*/
|
|
130
|
+
export declare interface GenerationStats {
|
|
131
|
+
filesProcessed: number
|
|
132
|
+
filesGenerated: number
|
|
133
|
+
filesFailed: number
|
|
134
|
+
filesValidated: number
|
|
135
|
+
validationErrors: number
|
|
136
|
+
declarationsFound: number
|
|
137
|
+
importsProcessed: number
|
|
138
|
+
exportsProcessed: number
|
|
139
|
+
durationMs: number
|
|
140
|
+
errors: DtsError[]
|
|
16
141
|
}
|
|
17
142
|
/**
|
|
18
143
|
* Declaration
|
|
@@ -20,7 +145,7 @@ export declare interface DtsGenerationConfig {
|
|
|
20
145
|
* Represents a parsed declaration from TypeScript source
|
|
21
146
|
*/
|
|
22
147
|
export declare interface Declaration {
|
|
23
|
-
kind:
|
|
148
|
+
kind: DeclarationKind
|
|
24
149
|
name: string
|
|
25
150
|
text: string
|
|
26
151
|
leadingComments?: string[]
|
|
@@ -34,10 +159,11 @@ export declare interface Declaration {
|
|
|
34
159
|
members?: Declaration[]
|
|
35
160
|
parameters?: ParameterDeclaration[]
|
|
36
161
|
returnType?: string
|
|
37
|
-
value?:
|
|
162
|
+
value?: unknown
|
|
38
163
|
source?: string
|
|
39
164
|
specifiers?: ImportSpecifier[]
|
|
40
165
|
isTypeOnly?: boolean
|
|
166
|
+
isSideEffect?: boolean
|
|
41
167
|
isAsync?: boolean
|
|
42
168
|
isGenerator?: boolean
|
|
43
169
|
overloads?: string[]
|
|
@@ -71,19 +197,23 @@ export declare interface ProcessingContext {
|
|
|
71
197
|
filePath: string
|
|
72
198
|
sourceCode: string
|
|
73
199
|
declarations: Declaration[]
|
|
74
|
-
imports
|
|
75
|
-
exports
|
|
76
|
-
usedTypes
|
|
200
|
+
imports?: Map<string, Set<string>>
|
|
201
|
+
exports?: Set<string>
|
|
202
|
+
usedTypes?: Set<string>
|
|
77
203
|
}
|
|
78
204
|
/**
|
|
79
205
|
* DtsGenerationOption
|
|
80
206
|
*
|
|
81
207
|
* This is the configuration object for the DTS generation process.
|
|
82
208
|
*/
|
|
83
|
-
export type DtsGenerationOption = Partial<DtsGenerationConfig
|
|
209
|
+
export type DtsGenerationOption = Partial<DtsGenerationConfig>;
|
|
84
210
|
/**
|
|
85
211
|
* DtsGenerationOptions
|
|
86
212
|
*
|
|
87
213
|
* This is the configuration object for the DTS generation process.
|
|
88
214
|
*/
|
|
89
|
-
export type DtsGenerationOptions = DtsGenerationOption | DtsGenerationOption[]
|
|
215
|
+
export type DtsGenerationOptions = DtsGenerationOption | DtsGenerationOption[];
|
|
216
|
+
/**
|
|
217
|
+
* Declaration kind - all possible declaration types
|
|
218
|
+
*/
|
|
219
|
+
export type DeclarationKind = 'function' | 'variable' | 'interface' | 'type' | 'class' | 'enum' | 'import' | 'export' | 'module' | 'namespace' | 'unknown';
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,5 +1,57 @@
|
|
|
1
1
|
import type { DtsGenerationConfig } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Exhaustive check helper for switch statements
|
|
4
|
+
* This function should never be called if all cases are handled
|
|
5
|
+
* TypeScript will error if a case is missing
|
|
6
|
+
*/
|
|
7
|
+
export declare function assertNever(value: never, message?: string): never;
|
|
2
8
|
export declare function writeToFile(filePath: string, content: string): Promise<void>;
|
|
3
9
|
export declare function getAllTypeScriptFiles(directory?: string): Promise<string[]>;
|
|
4
10
|
// only checks for 2 potentially nested levels
|
|
5
|
-
export declare function
|
|
11
|
+
export declare function checkIsolatedDeclarationsConfig(options?: DtsGenerationConfig): Promise<boolean>;
|
|
12
|
+
/**
|
|
13
|
+
* Validate a .d.ts file content against TypeScript compiler
|
|
14
|
+
*/
|
|
15
|
+
export declare function validateDtsContent(content: string, filename: string): ValidationResult;
|
|
16
|
+
/**
|
|
17
|
+
* Simple line-by-line diff between two strings
|
|
18
|
+
* Returns formatted diff output with +/- prefixes
|
|
19
|
+
*/
|
|
20
|
+
export declare function createDiff(oldContent: string, newContent: string, filename: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Generate a simple source map for a declaration file
|
|
23
|
+
* This creates a basic 1:1 mapping since we're doing declaration extraction
|
|
24
|
+
*/
|
|
25
|
+
export declare function generateDeclarationMap(dtsContent: string, dtsFilename: string, sourceFilename: string, sourceContent: string): DeclarationSourceMap;
|
|
26
|
+
/**
|
|
27
|
+
* Add source map URL comment to declaration content
|
|
28
|
+
*/
|
|
29
|
+
export declare function addSourceMapComment(dtsContent: string, mapFilename: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* Validation error details
|
|
32
|
+
*/
|
|
33
|
+
export declare interface ValidationError {
|
|
34
|
+
line: number
|
|
35
|
+
column: number
|
|
36
|
+
message: string
|
|
37
|
+
code?: string
|
|
38
|
+
suggestion?: string
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Validation result for a .d.ts file
|
|
42
|
+
*/
|
|
43
|
+
export declare interface ValidationResult {
|
|
44
|
+
isValid: boolean
|
|
45
|
+
errors: ValidationError[]
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Source map for declaration files
|
|
49
|
+
*/
|
|
50
|
+
export declare interface DeclarationSourceMap {
|
|
51
|
+
version: 3
|
|
52
|
+
file: string
|
|
53
|
+
sourceRoot: string
|
|
54
|
+
sources: string[]
|
|
55
|
+
sourcesContent: string[]
|
|
56
|
+
mappings: string
|
|
57
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { DtsGenerationConfig } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Create a file watcher for .d.ts generation
|
|
4
|
+
*/
|
|
5
|
+
export declare function createWatcher(config: WatchConfig, buildFn: (files?: string[]) => Promise<WatchBuildResult>): Watcher;
|
|
6
|
+
/**
|
|
7
|
+
* Watch and generate .d.ts files
|
|
8
|
+
*/
|
|
9
|
+
export declare function watchAndGenerate(config: DtsGenerationConfig & WatchConfig, generator: (config: DtsGenerationConfig) => Promise<{ filesProcessed: number, errors: string[] }>): Promise<Watcher>;
|
|
10
|
+
/**
|
|
11
|
+
* Format watch build result for display
|
|
12
|
+
*/
|
|
13
|
+
export declare function formatWatchResult(result: WatchBuildResult): string;
|
|
14
|
+
/**
|
|
15
|
+
* Create a simple console logger for watch mode
|
|
16
|
+
*/
|
|
17
|
+
export declare function createWatchLogger(): {
|
|
18
|
+
onChange: (event: WatchEvent) => void
|
|
19
|
+
onBuildStart: () => void
|
|
20
|
+
onBuildComplete: (result: WatchBuildResult) => void
|
|
21
|
+
onError: (error: Error) => void
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Watch configuration
|
|
25
|
+
*/
|
|
26
|
+
export declare interface WatchConfig {
|
|
27
|
+
root: string
|
|
28
|
+
include?: string[]
|
|
29
|
+
exclude?: string[]
|
|
30
|
+
debounce?: number
|
|
31
|
+
initialBuild?: boolean
|
|
32
|
+
clearScreen?: boolean
|
|
33
|
+
onChange?: (event: WatchEvent) => void | Promise<void>
|
|
34
|
+
onBuildStart?: () => void | Promise<void>
|
|
35
|
+
onBuildComplete?: (result: WatchBuildResult) => void | Promise<void>
|
|
36
|
+
onError?: (error: Error) => void | Promise<void>
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Watch event
|
|
40
|
+
*/
|
|
41
|
+
export declare interface WatchEvent {
|
|
42
|
+
type: 'add' | 'change' | 'unlink'
|
|
43
|
+
path: string
|
|
44
|
+
relativePath: string
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Build result from watch
|
|
48
|
+
*/
|
|
49
|
+
export declare interface WatchBuildResult {
|
|
50
|
+
success: boolean
|
|
51
|
+
duration: number
|
|
52
|
+
filesProcessed: number
|
|
53
|
+
errors: string[]
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Watcher instance
|
|
57
|
+
*/
|
|
58
|
+
export declare interface Watcher {
|
|
59
|
+
start: () => Promise<void>
|
|
60
|
+
stop: () => void
|
|
61
|
+
rebuild: () => Promise<WatchBuildResult>
|
|
62
|
+
isWatching: () => boolean
|
|
63
|
+
getWatchedFiles: () => string[]
|
|
64
|
+
}
|