TypeScript Cached Transpile

0.0.6 · active · verified Sun Apr 19

typescript-cached-transpile is a utility designed to accelerate TypeScript compilation in `transpileOnly` mode by monkey-patching the `typescript` compiler's `transpileModule` function to utilize a disk cache. It is currently at version 0.0.6, indicating an early development stage, and its release cadence is likely tied to the maintainer's personal monorepo updates. Its primary differentiator is its targeted optimization for `ts-node`'s `transpileOnly` mode, significantly reducing build times for repetitive compilations of unchanged files by persisting transpilation results to disk. It transparently integrates by being specified as `ts-node`'s compiler, and offers configuration via environment variables or a custom JS file for cache directory and portable cache settings. It explicitly states limitations, such as not working with transformers, diagnostics, or type-checking.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates the command-line usage of `typescript-cached-transpile` with `ts-node` for faster `transpileOnly` execution, including how to use a custom compiler file and specify a cache directory.

import { readFileSync } from 'fs';
import { join } from 'path';

// Create a dummy TypeScript file for demonstration
const tsContent = `
  interface MyInterface {
    name: string;
    age: number;
  }

  const greeter = (person: MyInterface) => {
    return `Hello, ${person.name}! You are ${person.age} years old.`;
  };

  console.log(greeter({ name: 'Alice', age: 30 }));
`;

// This script demonstrates how to use `typescript-cached-transpile` via ts-node
// For this to run, you'd typically save the above tsContent to a file (e.g., `src/index.ts`)
// and then execute a shell command.

console.log('To run with caching, execute in your terminal:');
console.log('\nTS_NODE_TRANSPILE_ONLY=true TS_NODE_COMPILER=typescript-cached-transpile ts-node src/index.ts');
console.log('\nOr for a custom compiler configuration:');
console.log('// ./my-cached-compiler.js');
console.log('// const { create } = require(\'typescript-cached-transpile\');');
console.log('// module.exports = create({ cacheDir: process.env.TS_CACHED_TRANSPILE_CACHE ?? \'/tmp/ts-cache\' });');
console.log('\nTS_NODE_TRANSPILE_ONLY=true TS_NODE_COMPILER=$PWD/my-cached-compiler.js TS_CACHED_TRANSPILE_CACHE=$PWD/.cache ts-node src/index.ts');

console.log('\nEnsure you have ts-node and typescript-cached-transpile installed:');
console.log('npm install -g ts-node typescript typescript-cached-transpile');

view raw JSON →