CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-rollup-plugin-typescript2

Seamless integration between Rollup and TypeScript with comprehensive error reporting.

Pending
Overview
Eval results
Files

typescript-integration.mddocs/

TypeScript Integration

TypeScript compiler integration with language service, diagnostics, and type checking capabilities.

Capabilities

TypeScript Service Management

The plugin creates and manages a TypeScript Language Service for compilation and type checking.

/**
 * TypeScript module interface (can be customized via options.typescript)
 */
interface TypeScriptModule {
  /** TypeScript version string */
  version: string;
  
  /** Create a language service instance */
  createLanguageService(host: LanguageServiceHost, documentRegistry?: DocumentRegistry): LanguageService;
  
  /** Create a document registry for caching */
  createDocumentRegistry(): DocumentRegistry;
  
  /** Resolve module names using Node.js resolution */
  nodeModuleNameResolver(moduleName: string, containingFile: string, options: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations;
  
  /** System interface for file operations */
  sys: System;
}

Language Service Host

Custom language service host implementation for Rollup integration.

/**
 * Language service host that bridges Rollup and TypeScript
 */
class LanguageServiceHost implements tsTypes.LanguageServiceHost {
  /** Set source code snapshot for a file */
  setSnapshot(id: string, code: string): tsTypes.IScriptSnapshot;
  
  /** Get script snapshot for a file */
  getScriptSnapshot(fileName: string): tsTypes.IScriptSnapshot | undefined;
  
  /** Get TypeScript compilation options */
  getCompilationSettings(): tsTypes.CompilerOptions;
  
  /** Get list of script file names */
  getScriptFileNames(): string[];
  
  /** Get script version for caching */
  getScriptVersion(fileName: string): string;
  
  /** Set language service reference */
  setLanguageService(service: tsTypes.LanguageService): void;
}

Configuration Parsing

TSConfig file parsing and option merging functionality.

/**
 * Parse and merge TypeScript configuration
 * @param context - Rollup context for logging
 * @param pluginOptions - Plugin configuration options
 * @returns Parsed configuration and file name
 */
function parseTsConfig(
  context: RollupContext, 
  pluginOptions: IOptions
): {
  parsedTsConfig: tsTypes.ParsedCommandLine;
  fileName: string | undefined;
};

/**
 * Parsed TypeScript configuration result
 */
interface ParsedCommandLine {
  /** Compiler options after all merging */
  options: tsTypes.CompilerOptions;
  
  /** List of files to include in compilation */
  fileNames: string[];
  
  /** Type reference directives */
  typeReferenceDirectives: tsTypes.FileReference[];
  
  /** Configuration errors */
  errors: tsTypes.Diagnostic[];
}

Diagnostic Processing

TypeScript diagnostic message collection and formatting.

/**
 * Convert TypeScript diagnostics to plugin format
 * @param type - Diagnostic type identifier
 * @param diagnostics - Array of TypeScript diagnostics
 * @returns Converted diagnostic objects
 */
function convertDiagnostic(
  type: string, 
  diagnostics: readonly tsTypes.Diagnostic[]
): PluginDiagnostic[];

/**
 * Print diagnostics to console with formatting
 * @param context - Rollup context for output
 * @param diagnostics - Diagnostics to display
 * @param pretty - Enable pretty printing
 */
function printDiagnostics(
  context: RollupContext, 
  diagnostics: PluginDiagnostic[], 
  pretty: boolean
): void;

interface PluginDiagnostic {
  /** Source file name */
  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;
  
  /** Diagnostic code number */
  code: number;
}

Compilation and Emit

TypeScript compilation and JavaScript/declaration file generation.

/**
 * Emit output from TypeScript compiler
 */
interface EmitOutput {
  /** Files generated by compilation */
  outputFiles: OutputFile[];
  
  /** Whether emit was skipped due to errors */
  emitSkipped: boolean;
}

interface OutputFile {
  /** Output file name */
  name: string;
  
  /** File content text */
  text: string;
  
  /** Whether to write byte order mark */
  writeByteOrderMark: boolean;
}

/**
 * Convert emit output to plugin format
 * @param output - TypeScript emit output
 * @param references - File references for dependency tracking
 * @returns Converted code result
 */
function convertEmitOutput(
  output: tsTypes.EmitOutput, 
  references?: string[]
): ICode;

interface ICode {
  /** Generated JavaScript code */
  code: string;
  
  /** Source map content */
  map?: string;
  
  /** Declaration file content */
  dts?: tsTypes.OutputFile;
  
  /** Declaration map content */
  dtsmap?: tsTypes.OutputFile;
  
  /** Referenced files for dependency tracking */
  references?: string[];
}

Usage Examples:

// Custom TypeScript version
import ttypescript from 'ttypescript';

typescript({
  typescript: ttypescript,  // Use ttypescript instead of typescript
  transformers: [
    // Custom transformers work with alternative TS implementations
    (service) => ({
      before: [myCustomTransformer(service.getProgram())]
    })
  ]
})

// Version checking and compatibility
typescript({
  // Plugin automatically validates TypeScript version
  // Supported range: TypeScript 2.4+
  // Rollup 1.26.3+
  
  verbosity: 2  // Will log version information
})

Error Handling and Recovery

Comprehensive error handling for compilation failures and diagnostic reporting.

/**
 * Error recovery strategies
 */
interface ErrorHandling {
  /** Continue compilation despite syntax errors */
  abortOnError: boolean;
  
  /** Skip emit for files with errors */
  emitSkipped: boolean;
  
  /** Collect diagnostics without stopping build */
  diagnosticCollection: PluginDiagnostic[];
}

Error Handling Examples:

// Strict error handling (default)
typescript({
  abortOnError: true,    // Stop on first error
  check: true           // Enable type checking
})

// Lenient error handling
typescript({
  abortOnError: false,   // Continue despite errors
  check: true,          // Still collect diagnostics
  verbosity: 1          // Show warnings and errors
})

// Transpile-only mode (fastest)
typescript({
  check: false,         // Skip all type checking
  verbosity: 0         // Only show critical errors
})

Module Resolution

Integration with TypeScript's module resolution system for proper import handling.

/**
 * Module resolution integration
 */
interface ModuleResolution {
  /** Resolve import statements */
  nodeModuleNameResolver(
    importee: string, 
    importer: string, 
    options: tsTypes.CompilerOptions,
    host: tsTypes.ModuleResolutionHost
  ): tsTypes.ResolvedModuleWithFailedLookupLocations;
  
  /** Supported module resolution strategies */
  strategies: 'node10' | 'node16' | 'nodenext' | 'bundler';
}

The plugin automatically handles:

  • TypeScript file extensions (.ts, .tsx, .cts, .mts)
  • Declaration file exclusion (.d.ts files)
  • Import resolution through TypeScript's resolver
  • Type-only import handling for watch mode compatibility

Install with Tessl CLI

npx tessl i tessl/npm-rollup-plugin-typescript2

docs

custom-transformers.md

file-processing.md

index.md

logging-diagnostics.md

plugin-configuration.md

typescript-integration.md

tile.json