This is the TypeScript runner module of the ZyroHub ecosystem, allowing you to compile and execute TypeScript files on the fly with full decorator metadata and path alias support.
- ZyroHub - TS Runner
- Table of Contents
- Getting Started
- Basic Usage
- Path Aliases
- Why @zyrohub/ts-runner?
To install the TS runner, use one of the following package managers:
# npm
npm install @zyrohub/ts-runner
# yarn
yarn add @zyrohub/ts-runner
# pnpm
pnpm add @zyrohub/ts-runner
# bun
bun add @zyrohub/ts-runner@zyrohub/core), you must enable emitDecoratorMetadata and experimentalDecorators in your tsconfig.json.
{
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
}To run a TypeScript file on the fly, use the ztsc executable followed by your entry file:
ztsc index.tsTo run a file in development mode and watch for changes, use the --watch option:
ztsc --watch index.tsThis will automatically restart the execution whenever any of the imported TypeScript files change.
The runner automatically resolves path aliases defined in your tsconfig.json (paths and baseUrl).
For example, if you have the following tsconfig.json:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
}
}You can import files using your aliases (even specifying .js extensions as required by ESM):
import { MyService } from '@/services/MyService.js';The runner will locate the file at src/services/MyService.ts and resolve the import seamlessly.
Compared to other runners like tsx or ts-node:
- Decorator Metadata Support: Unlike
tsx(which utilizesesbuildand does not supportemitDecoratorMetadataout of the box),@zyrohub/ts-runnercompiles code using SWC configured to output decorator metadata correctly. This is crucial for frameworks that rely on Dependency Injection like@zyrohub/core. - Fast Execution: Unlike
ts-node(which can be slow on larger projects),@zyrohub/ts-runnercompiles files instantly using@swc/core. - Seamless ESM Integration: Fully supports ES Module imports, including
.jsextensions pointing to.tsfiles, without requiring configuration tweaks.
