Seamless integration between Rollup and TypeScript with comprehensive error reporting.
—
Verbosity control and diagnostic message reporting system for comprehensive build feedback.
Configure logging levels to control the amount of build information displayed.
/**
* Verbosity levels for controlling log output
*/
enum VerbosityLevel {
/** Only show critical errors that stop the build */
Error = 0,
/** Show errors and warnings (default) */
Warning = 1,
/** Show errors, warnings, and informational messages */
Info = 2,
/** Show all messages including debug information */
Debug = 3
}Verbosity Level Examples:
// Production build - minimal output
typescript({
verbosity: 0 // VerbosityLevel.Error
})
// Development build - warnings and errors
typescript({
verbosity: 1 // VerbosityLevel.Warning (default)
})
// Detailed development - include build info
typescript({
verbosity: 2 // VerbosityLevel.Info
})
// Debug build issues - full diagnostic output
typescript({
verbosity: 3 // VerbosityLevel.Debug
})Logging system that integrates with Rollup's warning and error reporting.
/**
* Rollup context wrapper for consistent logging
*/
class RollupContext {
/**
* Create logging context
* @param verbosity - Current verbosity level
* @param bail - Whether to throw errors or convert to warnings
* @param context - Rollup plugin context
* @param prefix - Message prefix for identification
*/
constructor(
verbosity: VerbosityLevel,
bail: boolean,
context: PluginContext,
prefix?: string
);
/**
* Log warning message (shown at Warning level and above)
* @param message - Warning message or lazy message function
*/
warn(message: string | (() => string)): void;
/**
* Log error message (shown at Error level and above)
* May throw error if abortOnError is true
* @param message - Error message or lazy message function
*/
error(message: string | (() => string)): void | never;
/**
* Log informational message (shown at Info level and above)
* @param message - Info message or lazy message function
*/
info(message: string | (() => string)): void;
/**
* Log debug message (shown at Debug level only)
* @param message - Debug message or lazy message function
*/
debug(message: string | (() => string)): void;
}Comprehensive handling of TypeScript compiler diagnostics and error messages.
/**
* Convert TypeScript diagnostics to plugin format
* @param type - Diagnostic category identifier
* @param diagnostics - Raw TypeScript diagnostics
* @returns Converted diagnostic objects
*/
function convertDiagnostic(
type: string,
diagnostics: readonly tsTypes.Diagnostic[]
): PluginDiagnostic[];
/**
* Plugin diagnostic format
*/
interface PluginDiagnostic {
/** Source file where diagnostic occurred */
fileName?: string;
/** Line number (1-based) */
line?: number;
/** Column number (1-based) */
column?: number;
/** Diagnostic message text */
messageText: string;
/** TypeScript diagnostic category */
category: tsTypes.DiagnosticCategory;
/** TypeScript diagnostic code */
code: number;
/** Diagnostic type (syntax, semantic, options, etc.) */
type: string;
}
/**
* Print diagnostics with formatting and colors
* @param context - Rollup context for output
* @param diagnostics - Diagnostics to display
* @param pretty - Enable colored/formatted output
*/
function printDiagnostics(
context: RollupContext,
diagnostics: PluginDiagnostic[],
pretty: boolean
): void;TypeScript provides several categories of diagnostic messages:
/**
* TypeScript diagnostic categories
*/
enum DiagnosticCategory {
/** Warning messages that don't prevent compilation */
Warning = 0,
/** Error messages that may prevent compilation */
Error = 1,
/** Suggestion messages for code improvements */
Suggestion = 2,
/** Informational messages */
Message = 3
}
/**
* Common diagnostic types processed by the plugin
*/
interface DiagnosticTypes {
/** Syntax errors in TypeScript code */
syntax: 'syntax';
/** Type checking and semantic errors */
semantic: 'semantic';
/** Compiler configuration errors */
options: 'options';
/** Global errors not tied to specific files */
global: 'global';
}Detailed logging of build process information and configuration.
/**
* Build information logged at various verbosity levels
*/
interface BuildInformation {
/** TypeScript version being used */
typescriptVersion: string;
/** Rollup version being used */
rollupVersion: string;
/** Plugin version */
pluginVersion: string;
/** TSLib version for helper functions */
tslibVersion: string;
/** Current plugin configuration */
pluginOptions: IOptions;
/** Rollup configuration object */
rollupConfig: InputOptions;
/** Path to tsconfig file being used */
tsconfigPath?: string;
/** Parsed TypeScript configuration */
parsedTsconfig: tsTypes.ParsedCommandLine;
}Example Build Information Output:
rpt2: typescript version: 5.1.3
rpt2: tslib version: 2.6.2
rpt2: rollup version: 2.70.2
rpt2: rollup-plugin-typescript2 version: 0.36.0
rpt2: running in watch modeConfigure how errors are handled during the build process.
/**
* Error handling configuration
*/
interface ErrorHandling {
/** Stop build on first error vs collect all errors */
abortOnError: boolean;
/** Enable comprehensive type checking */
check: boolean;
/** Control diagnostic output verbosity */
verbosity: VerbosityLevel;
}
/**
* Error processing flow
*/
interface ErrorProcessingFlow {
/** Collect syntax diagnostics from TypeScript */
syntaxDiagnostics: tsTypes.Diagnostic[];
/** Collect semantic diagnostics from TypeScript */
semanticDiagnostics: tsTypes.Diagnostic[];
/** Collect compiler option diagnostics */
optionsDiagnostics: tsTypes.Diagnostic[];
/** Convert to plugin format */
pluginDiagnostics: PluginDiagnostic[];
/** Format and display to user */
formattedOutput: string;
}Control how diagnostic messages are formatted and displayed.
/**
* Diagnostic formatting options
*/
interface DiagnosticFormatting {
/** Enable colored output with ANSI codes */
pretty: boolean;
/** Include file paths in output */
showFilePaths: boolean;
/** Include line and column numbers */
showPositions: boolean;
/** Include TypeScript error codes */
showErrorCodes: boolean;
/** Group diagnostics by file */
groupByFile: boolean;
}Pretty Formatted Output Example:
src/main.ts(15,7): error TS2322: Type 'string' is not assignable to type 'number'.
15 const count: number = "hello";
~~~~~
src/utils.ts(8,12): warning TS6133: 'unused' is declared but its value is never read.
8 const unused = 42;
~~~~~~Monitor build performance and identify bottlenecks.
/**
* Performance monitoring capabilities
*/
interface PerformanceMonitoring {
/** Track compilation time per file */
fileCompilationTimes: Map<string, number>;
/** Track cache hit/miss ratios */
cacheStatistics: {
hits: number;
misses: number;
hitRatio: number;
};
/** Track type checking time */
typeCheckingTime: number;
/** Track total build time */
totalBuildTime: number;
}Advanced logging customization for specialized use cases.
/**
* Custom diagnostic processing
*/
interface CustomDiagnosticHandler {
/** Filter diagnostics before display */
filterDiagnostics?: (diagnostics: PluginDiagnostic[]) => PluginDiagnostic[];
/** Custom formatting function */
formatDiagnostic?: (diagnostic: PluginDiagnostic) => string;
/** Custom output handler */
outputHandler?: (formattedMessage: string) => void;
}Usage Examples:
// Minimal logging for CI builds
typescript({
verbosity: 0, // Errors only
abortOnError: true, // Fail fast
check: true // Still check types
})
// Development with detailed feedback
typescript({
verbosity: 2, // Info level
abortOnError: false, // Continue on errors
check: true // Full type checking
})
// Debug build issues
typescript({
verbosity: 3, // Debug level
clean: true, // Fresh cache
abortOnError: false // See all issues
})
// Production build - fast and quiet
typescript({
verbosity: 1, // Warnings and errors
check: false, // Transpile only (fastest)
clean: false // Use cache
})Optimize performance by only evaluating expensive debug messages when needed.
/**
* Lazy message evaluation for performance
*/
type LazyMessage = string | (() => string);
/**
* Example usage of lazy messages
*/
const examples = {
// Expensive string operations only run if debug level is active
debug: () => `Detailed analysis: ${JSON.stringify(complexObject, null, 2)}`,
// Simple string - always evaluated
info: "Build completed successfully",
// Conditional message based on state
warning: () => errors.length > 0 ? `Found ${errors.length} errors` : "No errors found"
};This lazy evaluation pattern ensures that expensive string operations (like JSON serialization) only occur when the message will actually be displayed, improving performance at lower verbosity levels.
Install with Tessl CLI
npx tessl i tessl/npm-rollup-plugin-typescript2