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

file-processing.mddocs/

File Processing

File filtering, caching, and transformation system for handling TypeScript source files.

Capabilities

File Filtering

Configure which files are included or excluded from TypeScript compilation.

interface FilterOptions {
  /** File patterns to include for compilation */
  include: string | string[];
  
  /** File patterns to exclude from compilation */
  exclude: string | string[];
  
  /** Current working directory for pattern resolution */
  cwd: string;
}

/**
 * Create file filter function based on include/exclude patterns
 * @param context - Rollup context for logging
 * @param pluginOptions - Plugin configuration
 * @param parsedConfig - Parsed TypeScript configuration
 * @returns Filter function for file paths
 */
function createFilter(
  context: RollupContext,
  pluginOptions: IOptions,
  parsedConfig: tsTypes.ParsedCommandLine
): (id: string) => boolean;

Default Filter Patterns:

const defaultPatterns = {
  include: [
    "*.ts+(|x)",     // .ts and .tsx files in root
    "**/*.ts+(|x)",  // .ts and .tsx files in subdirectories
    "**/*.cts",      // CommonJS TypeScript files
    "**/*.mts"       // ES Module TypeScript files
  ],
  exclude: [
    "*.d.ts",        // Type declaration files in root
    "**/*.d.ts",     // Type declaration files in subdirectories
    "**/*.d.cts",    // CommonJS declaration files
    "**/*.d.mts"     // ES Module declaration files
  ]
};

Filter Usage Examples:

// Custom file patterns
typescript({
  include: ['src/**/*.ts', 'lib/**/*.tsx'],
  exclude: ['**/*.test.ts', '**/*.spec.ts', 'node_modules/**']
})

// Include JavaScript files (requires allowJs in tsconfig)
typescript({
  include: [
    '*.ts+(|x)', '**/*.ts+(|x)',  // TypeScript files
    '*.js+(|x)', '**/*.js+(|x)'   // JavaScript files
  ],
  exclude: ['**/node_modules/**/*']  // Exclude node_modules for performance
})

Caching System

Intelligent caching system for improved build performance across builds.

/**
 * TypeScript compilation cache
 */
class TsCache {
  /**
   * Create cache instance
   * @param noCache - Disable caching entirely
   * @param runClean - Clean existing cache on startup
   * @param objectHashIgnoreUnknownHack - Ignore unknown objects in cache keys
   * @param host - Language service host
   * @param cacheRoot - Cache directory path
   * @param options - Compiler options
   * @param rollupOptions - Rollup configuration
   * @param rootFileNames - Root files for compilation
   * @param context - Rollup context
   */
  constructor(
    noCache: boolean,
    runClean: boolean,
    objectHashIgnoreUnknownHack: boolean,
    host: LanguageServiceHost,
    cacheRoot: string,
    options: tsTypes.CompilerOptions,
    rollupOptions: InputOptions,
    rootFileNames: string[],
    context: RollupContext
  );
  
  /** Get compiled output from cache or compile if needed */
  getCompiled(
    id: string, 
    snapshot: tsTypes.IScriptSnapshot, 
    getOutput: () => ICode
  ): ICode | undefined;
  
  /** Get syntactic diagnostics from cache */
  getSyntacticDiagnostics(
    id: string,
    snapshot: tsTypes.IScriptSnapshot,
    getDiagnostics: () => readonly tsTypes.Diagnostic[]
  ): readonly tsTypes.Diagnostic[];
  
  /** Get semantic diagnostics from cache */
  getSemanticDiagnostics(
    id: string,
    snapshot: tsTypes.IScriptSnapshot,
    getDiagnostics: () => readonly tsTypes.Diagnostic[]
  ): readonly tsTypes.Diagnostic[];
  
  /** Set file dependency relationship */
  setDependency(importee: string, importer: string): void;
  
  /** Walk dependency tree and execute callback */
  walkTree(callback: (id: string) => void): void;
  
  /** Finalize cache operations */
  done(): void;
}

Cache Configuration:

// Custom cache settings
typescript({
  clean: false,              // Use existing cache (default)
  cacheRoot: './build-cache', // Custom cache directory
  
  // For cache debugging
  objectHashIgnoreUnknownHack: false, // Strict cache key generation
  verbosity: 3  // Log cache operations
})

// Development mode - fresh builds
typescript({
  clean: true,    // Always clean cache
  verbosity: 2   // Show cache operations
})

// Production mode - optimized caching
typescript({
  clean: false,           // Preserve cache
  cacheRoot: undefined,   // Use default location
  verbosity: 0           // Minimal logging
})

Build Lifecycle Management

Integration with Rollup's build lifecycle for proper initialization and cleanup.

/**
 * Build lifecycle hooks
 */
interface BuildLifecycle {
  /** Initialize plugin state and TypeScript service */
  buildStart(): void;
  
  /** Handle file changes in watch mode */
  watchChange(id: string): void;
  
  /** Finalize build and report diagnostics */
  buildEnd(err?: Error): void;
  
  /** Generate declaration files and assets */
  generateBundle(options: OutputOptions, bundle: OutputBundle): void;
}

File Transformation Pipeline

Core transformation logic for converting TypeScript to JavaScript.

/**
 * Transform TypeScript file to JavaScript
 * @param code - Source TypeScript code
 * @param id - File identifier/path
 * @returns Transformed result with source maps
 */
interface TransformResult {
  /** Generated JavaScript code */
  code: string;
  
  /** Source map for debugging */
  map?: SourceMap;
}

/**
 * Source map callback for custom processing
 */
type SourceMapCallback = (id: string, map: string) => void;

Transform Process:

  1. File Filtering: Check if file should be processed
  2. Snapshot Creation: Create TypeScript source snapshot
  3. Cache Lookup: Check for cached compilation result
  4. Compilation: Compile TypeScript to JavaScript if not cached
  5. Diagnostics: Collect and report type errors
  6. Declaration Generation: Generate .d.ts files if enabled
  7. Reference Tracking: Track file dependencies for watch mode
// Custom transformation handling
typescript({
  sourceMapCallback: (id, map) => {
    // Custom source map processing
    console.log(`Generated source map for ${id}`);
    // Could save to custom location, post-process, etc.
  }
})

Watch Mode Support

Enhanced watch mode integration for development workflows.

/**
 * Watch mode capabilities
 */
interface WatchMode {
  /** Detect watch mode from environment */
  watchMode: boolean;
  
  /** Add files to Rollup's watch list */
  addWatchFile(id: string): void;
  
  /** Handle type-only imports that Rollup can't see */
  handleTypeOnlyImports: boolean;
  
  /** Support for Rollup 2.60.0+ this.load API */
  supportsThisLoad: boolean;
}

Watch Mode Features:

  • Automatic tsconfig.json watching
  • Type-only import handling
  • Incremental type checking
  • Cache preservation between builds
  • File dependency tracking
// Watch mode configuration
typescript({
  // These options are automatically optimized for watch mode:
  clean: false,        // Preserve cache between builds
  check: true,         // Enable incremental type checking
  
  verbosity: 1,        // Show warnings during development
  abortOnError: false  // Continue despite type errors
})

Error Recovery and Reporting

Comprehensive error handling for build failures and type errors.

/**
 * Error handling configuration
 */
interface ErrorHandling {
  /** Stop build on first error vs continue */
  abortOnError: boolean;
  
  /** Enable/disable type checking entirely */
  check: boolean;
  
  /** Control diagnostic verbosity */
  verbosity: VerbosityLevel;
}

/**
 * Error recovery strategies
 */
interface RecoveryStrategies {
  /** Skip emit for files with errors */
  emitSkipped: boolean;
  
  /** Continue processing other files */
  continueOnError: boolean;
  
  /** Collect all diagnostics before reporting */
  batchDiagnostics: boolean;
}

Error Handling Examples:

// Strict mode - stop on any error
typescript({
  abortOnError: true,
  check: true,
  verbosity: 1
})

// Lenient mode - collect all errors
typescript({
  abortOnError: false,  // Don't stop build
  check: true,         // Still check types
  verbosity: 2        // Show detailed info
})

// Fast mode - skip type checking
typescript({
  check: false,        // Transpile only
  abortOnError: true,  // Stop on syntax errors only
  verbosity: 0        // Minimal output
})

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