@stacksjs/dtsx
Version:
A modern, fast .d.ts generation tool, powered by Bun.
85 lines (84 loc) • 2.82 kB
TypeScript
import type { Declaration, DtsGenerationConfig, GenerationStats } from './types';
/**
* Helper to create a plugin
*/
export declare function definePlugin(plugin: Plugin): Plugin;
/**
* Built-in plugin: Add banner comment
* Adds a banner comment to the top of generated files
*/
export declare function createBannerPlugin(banner: string): Plugin;
/**
* Built-in plugin: Filter exports
* Only include declarations matching the filter
*/
export declare function createFilterPlugin(filter: (name: string) => boolean): Plugin;
/**
* Global plugin manager instance
*/
export declare const pluginManager: PluginManager;
/**
* Built-in plugin: Strip internal declarations
* Removes declarations marked with @internal in JSDoc
*/
export declare const stripInternalPlugin: Plugin;
/**
* Context passed to plugin hooks
*/
export declare interface PluginContext {
filePath: string
sourceCode: string
config: DtsGenerationConfig
log: {
debug: (message: string) => void
info: (message: string) => void
warn: (message: string) => void
error: (message: string) => void
}
}
/**
* Transform context with mutable content
*/
export declare interface TransformContext extends PluginContext {
content: string
}
/**
* Declaration context for declaration hooks
*/
export declare interface DeclarationContext extends PluginContext {
declarations: Declaration[]
}
/**
* Plugin hook definitions
*/
export declare interface PluginHooks {
onStart?: (config: DtsGenerationConfig) => DtsGenerationConfig | void | Promise<DtsGenerationConfig | void>
onBeforeFile?: (ctx: TransformContext) => string | void | Promise<string | void>
onDeclarations?: (ctx: DeclarationContext) => Declaration[] | void | Promise<Declaration[] | void>
onAfterFile?: (ctx: TransformContext) => string | void | Promise<string | void>
onEnd?: (stats: GenerationStats) => void | Promise<void>
onError?: (error: Error, ctx: PluginContext) => void | Promise<void>
}
/**
* Plugin definition
*/
export declare interface Plugin extends PluginHooks {
name: string
version?: string
cacheKey?: string
description?: string
}
/**
* Plugin manager for handling multiple plugins
*/
export declare class PluginManager {
register(plugin: Plugin): void;
unregister(name: string): boolean;
getPlugins(): readonly Plugin[];
runOnStart(config: DtsGenerationConfig): Promise<DtsGenerationConfig>;
runOnBeforeFile(filePath: string, sourceCode: string): Promise<string>;
runOnDeclarations(filePath: string, sourceCode: string, declarations: Declaration[]): Promise<Declaration[]>;
runOnAfterFile(filePath: string, sourceCode: string, dtsContent: string): Promise<string>;
runOnEnd(stats: GenerationStats): Promise<void>;
runOnError(error: Error, filePath: string, sourceCode: string): Promise<void>;
}