import { LoggerConfig, LoggerScopeId } from "../types/index.js"; import * as _$unplugin from "unplugin"; //#region ../../node_modules/.pnpm/magic-string@0.30.21/node_modules/magic-string/dist/magic-string.es.d.mts type SourceMapSegment = [number] | [number, number, number, number] | [number, number, number, number, number]; interface DecodedSourceMap { file: string; sources: string[]; sourcesContent?: string[]; names: string[]; mappings: SourceMapSegment[][]; x_google_ignoreList?: number[]; } declare class SourceMap { constructor(properties: DecodedSourceMap); version: number; file: string; sources: string[]; sourcesContent?: string[]; names: string[]; mappings: string; x_google_ignoreList?: number[]; debugId?: string; /** * Returns the equivalent of `JSON.stringify(map)` */ toString(): string; /** * Returns a DataURI containing the sourcemap. Useful for doing this sort of thing: * `generateMap(options?: SourceMapOptions): SourceMap;` */ toUrl(): string; } //#endregion //#region src/plugin/transform.d.ts /** * The name identifier for the logger tree-shaking plugin. * * Used internally to identify the tree-shaking transformation plugin * in the plugin pipeline. */ declare const LOGGER_TREE_SHAKING_PLUGIN_NAME = "docs-islands:logger-tree-shaking"; declare const DEFAULT_LOGGER_MODULE_ID = "logaria"; interface LoggerTreeShakingTransformOptions { loggerModuleId: string; loggerScopeId: LoggerScopeId; } interface LoggerTreeShakingTransformResult { code: string; map: SourceMap; } /** * Performs build-time tree-shaking of logger calls based on configuration. * * This function analyzes source code and removes logger calls that are statically * determined to be suppressed by the active logger configuration. It uses Babel * AST analysis to: * * 1. Identify static `createLogger()` calls and their logger bindings * 2. Track logger.getLoggerByGroup() expressions to extract group information * 3. Find logger method calls with static string messages * 4. Check if each call would be suppressed using shouldSuppressLog() * 5. Remove suppressed calls from the generated code * * Returns null if no transformations were made or if parsing/analysis fails. * * @param code - The source code to analyze and transform * @param id - The file identifier/path for source map generation * @param options - Configuration including logger module ID and scope ID * @returns Transformed code with source map if changes were made, null otherwise * * @example * ```ts * const result = await transformLoggerTreeShaking(code, 'app.ts', { * loggerModuleId: 'logaria', * loggerScopeId: 'build', * }); * * if (result) { * // Use result.code and result.map * } * ``` */ declare function transformLoggerTreeShaking(code: string, id: string, options: LoggerTreeShakingTransformOptions): Promise; //#endregion //#region src/plugin/index.d.ts interface LoggerPluginOptions { config?: LoggerConfig | null; /** * Enable build-time tree-shaking of logger calls. * * When enabled, the plugin removes statically provable logger calls that are hidden by the resolved logger config. * * Only applies during build mode; has no effect in dev/watch mode. * * @default false */ treeshake?: boolean; } /** * Universal bundler plugin for logger configuration and optimization. * * This plugin integrates with multiple build systems (Vite, Webpack, Rollup, esbuild, Rolldown, Farm, rspack) * to: * * 1. **Inject logger configuration** - Embeds the resolved logger config as compile-time constants, * enabling build-time optimization and controlling which logs are shown at runtime * 2. **Perform tree-shaking** (when enabled) - Removes logger calls that would be suppressed by the * current configuration, reducing bundle size and improving performance * * The plugin automatically detects the build environment (development vs production) and adjusts * tree-shaking behavior accordingly. Tree-shaking only runs during production builds. * * @param options - Configuration options * @param options.config - The logger configuration to use (defaults to DEFAULT_LOGGER_CONFIG) * @param options.treeshake - Enable build-time tree-shaking of suppressed logger calls (default: false) * @returns A universal plugin compatible with Vite, Webpack, Rollup, and other bundlers * * @example * ```ts * // Vite configuration * import { loggerPlugin } from 'logaria'; * * export default { * plugins: [ * loggerPlugin({ * config: { * levels: ['error', 'warn'], * }, * treeshake: true, * }), * ], * }; * ``` */ declare const loggerPlugin: _$unplugin.UnpluginInstance; //#endregion export { DEFAULT_LOGGER_MODULE_ID, LOGGER_TREE_SHAKING_PLUGIN_NAME, LoggerPluginOptions, loggerPlugin, transformLoggerTreeShaking };