UNPKG

vite-plugin-component-instrumentation

Version:

A professional Vite plugin that automatically adds identifying data attributes to React components for debugging, testing, and analytics

81 lines (78 loc) 2.35 kB
import { Plugin } from 'vite'; /** * Runtime tracking mode */ type TrackStateMode = 'off' | 'events' | 'summary'; /** * Configuration options for the component instrumentation plugin */ interface ComponentInstrumentationOptions { /** * Prefix for data attributes * @default 'data-ct' */ attributePrefix?: string; /** * File extensions to process * @default ['.jsx', '.tsx'] */ extensions?: string[]; /** * Whether to enable the plugin in production builds * @default false */ enableInProduction?: boolean; /** * Patterns to exclude from processing * @default ['node_modules'] */ excludePatterns?: string[]; /** * Whether to include the tag name in attributes * @default true */ includeTagName?: boolean; /** * Custom ID generator function */ customIdGenerator?: (fileRelative: string, loc: { line: number; column: number; }) => string; /** * Whether to enable debug logging * @default false */ debug?: boolean; /** * Dev-only: runtime state tracking mode * - 'events': batched CustomEvents with minimal info * - 'summary': writes redacted summaries to DOM attributes * - 'off': disabled * @default 'off' */ trackState?: TrackStateMode; /** Explicit allowlist of state keys to expose values for */ allowKeys?: string[]; /** Max attribute length for summaries (default 160) */ maxAttrLength?: number; /** Throttle interval for runtime updates in ms (default 120) */ throttleMs?: number; /** Show full object contents in dev mode instead of redacted summaries (default false) */ showFullObjects?: boolean; } /** * Exported function for testing state summarization logic */ declare function buildSummaryDev(state: any, config: { allowKeys?: string[]; maxAttrLength?: number; showFullObjects?: boolean; }): string; /** * Creates a Vite plugin that provides comprehensive React component instrumentation * for debugging, testing, analytics, and observability */ declare function componentInstrumentation(userOptions?: ComponentInstrumentationOptions): Plugin; export { buildSummaryDev, componentInstrumentation as default }; export type { ComponentInstrumentationOptions, TrackStateMode };