Registry / devops / typescript-cached-transpile

typescript-cached-transpile

JSON →
library0.0.6jsnpmunverified

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.

npm install typescript-cached-transpile
INSTALL
IMPORT
SIG · TYPESCRIPT-CACHED-
T
typescript-cached-transpile
devopsjavascriptv0.0.6
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

create
const { create } = require('typescript-cached-transpile');
import { create } from 'typescript-cached-transpile';
The `create` function is used for programmatic customization of the cached compiler and is typically imported via CommonJS `require`.
module.exports
module.exports = create(/* options */);
export default create(/* options */);
When used as a custom `ts-node` compiler, the custom compiler file is expected to `module.exports` the configured compiler instance.

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');
Debug
Known issues
gotchaCaching only works if specific requirements are met, including no transformers, no diagnostics returned, same compiler version, same filename, same source code, sourcemaps enabled, and same config object. If these are not met, caching is silently skipped, leading to no performance improvement.
fix
Review the README's requirements list and ensure your `ts-node` configuration adheres to them. Use `tsc --noEmit` for type-checking separately.
affects: >=0.0.1
gotchaThe package monkey-patches the TypeScript compiler. This can lead to unexpected behavior or conflicts with other tools that also modify TypeScript's internal functions.
fix
Be aware of potential interactions with other tools or plugins that modify TypeScript's compiler. Isolate its usage if conflicts arise.
affects: >=0.0.1
gotchaWhen using a portable cache, `TS_CACHED_TRANSPILE_PORTABLE=true` must be set. This changes how filenames are stored in cache keys from absolute to relative paths. Forgetting this will make pre-generated caches non-portable.
fix
Always set `TS_CACHED_TRANSPILE_PORTABLE=true` when creating or consuming a cache intended for distribution or relocation. Ensure cache directory paths are absolute (e.g., `$PWD/.cache`).
affects: >=0.0.1
deprecatedThe package is in early stages (v0.0.6) and is intended for a very specific use case with `ts-node`'s `transpileOnly` mode. Its direct integration method via `TS_NODE_COMPILER` is somewhat unconventional and might not be supported in future `ts-node` versions or other build tools.
fix
Monitor `ts-node` and `typescript` updates for breaking changes to their compiler API or custom compiler integration points. Be prepared for potential refactoring if underlying APIs change.
affects: >=0.0.1
Errors
Common errors & fixes
Error: Cannot find module 'typescript-cached-transpile'
The package is not installed or not resolvable in the current environment.
fix
Run `npm install typescript-cached-transpile` or `yarn add typescript-cached-transpile`.
TypeError: create is not a function (when using import { create } from 'typescript-cached-transpile')
The package primarily uses CommonJS `module.exports` and `require` for its `create` function, not ESM named imports.
fix
Use CommonJS syntax: `const { create } = require('typescript-cached-transpile');`
Builds are not getting faster even with TS_NODE_TRANSPILE_ONLY=true and TS_NODE_COMPILER=typescript-cached-transpile
The caching requirements are not met, causing the cache to be silently skipped.
fix
Verify that no transformers are used, no diagnostics are returned, sourcemaps are enabled, and the config object and source code remain consistent. Ensure you are not relying on type-checking, which this package does not accelerate.
Upgrade
Version history
0.0.6latest on npm
Audit
Dependencies
typescriptrequiredPeer dependency; the package monkey-patches the `typescript` compiler itself.
Agent activity
2 hits · last 30 days
node
2
Resources
typescript-cached-transpile — npm install typescript-cached-transpile · libregistry