@stacksjs/dtsx
Version:
A modern, fast .d.ts generation tool, powered by Bun.
70 lines (69 loc) • 2.33 kB
TypeScript
import type { Declaration, DeclarationKind } from './types';
/**
* Shake unused declarations from the tree
*/
export declare function treeShake(declarations: Declaration[], config?: TreeShakeConfig): TreeShakeResult;
/**
* Build a declaration dependency graph for tree shaking
*/
export declare function buildDeclarationDependencyGraph(declarations: Declaration[]): Map<string, Set<string>>;
/**
* Extract type references from a declaration
*/
export declare function extractTypeReferences(decl: Declaration): Set<string>;
/**
* Tree shake content string
*/
export declare function treeShakeContent(content: string, config?: TreeShakeConfig): { content: string, removed: string[] };
/**
* Get unused declarations (those that could be removed)
*/
export declare function findUnusedDeclarations(declarations: Declaration[], config?: Omit<TreeShakeConfig, 'debug'>): string[];
/**
* Analyze dependencies for a declaration
*/
export declare function analyzeDependencies(declarationName: string, declarations: Declaration[]): {
directDependencies: string[]
transitiveDependencies: string[]
dependents: string[]
};
/**
* Create a tree shaker with preset configuration
*/
export declare function createTreeShaker(config?: TreeShakeConfig): {
shake: (declarations: Declaration[]) => TreeShakeResult
shakeContent: (content: string) => { content: string, removed: string[] }
findUnused: (declarations: Declaration[]) => string[]
analyzeDependencies: (name: string, declarations: Declaration[]) => { directDependencies: string[], transitiveDependencies: string[], dependents: string[] }
buildGraph: typeof buildDeclarationDependencyGraph
extractRefs: typeof extractTypeReferences
};
/**
* Tree shaking configuration
*/
export declare interface TreeShakeConfig {
entryPoints?: string[]
keepExported?: boolean
keep?: (string | RegExp)[]
remove?: (string | RegExp)[]
shakableKinds?: DeclarationKind[]
debug?: boolean
}
/**
* Result of tree shaking
*/
export declare interface TreeShakeResult {
declarations: Declaration[]
removed: string[]
dependencyGraph: Map<string, Set<string>>
stats: TreeShakeStats
}
/**
* Tree shaking statistics
*/
export declare interface TreeShakeStats {
totalBefore: number
totalAfter: number
removedCount: number
reductionPercent: number
}