Enhanced TypeScript playground powered by tsx - Run .ts files with smart defaults, watch mode, and zero configuration
- 🚀 Zero Config - Works out of the box with sensible defaults
- 👀 Watch Mode - Automatically reload on file changes
- 📁 Smart File Management - Organize files in a playground directory
- 🔧 TypeScript Config - Custom tsconfig.json support
- 📋 File Listing - View all available playground files
- 🐛 Debug Mode - Detailed execution information
- 🌍 Environment Variables - Configure via ENV vars
- 🔄 Auto Install - Automatically install tsx if missing
# npm
npm install -D @king-3/play-tsx
# pnpm
pnpm add -D @king-3/play-tsx
# yarn
yarn add -D @king-3/play-tsx# Run default file (playground/index.ts)
pnpm play
# Run specific file
play play -f other # Run playground/other.ts
# Enable watch mode
pnpm play --watch test # Run playground/test.ts and watch
pnpm play -w -f other # Run playground/other.ts and watch
# List available files
pnpm play --list
pnpm play -l# Run file
play [options] [file]
# Show help
play --help
play -h
# Show version
play --version
play -v| Option | Alias | Description | Default |
|---|---|---|---|
--file <path> |
-f |
File to run | index |
--watch |
-w |
Enable watch mode | false |
--list |
-l |
List available files | false |
--tsconfig <path> |
-t |
Path to tsconfig.json | Auto-detect |
--debug |
-d |
Enable debug output | false |
--version |
-v |
Show version number | - |
--help |
-h |
Show help information | - |
# Basic usage
play # Run playground/index.ts
play -f other # Run playground/other.ts
# Watch mode
play --watch -f file # Enable watch mode
play -w -f other # Watch + specify file
# Custom tsconfig
play --tsconfig ./tsconfig.dev.json -f file
play -t ./tsconfig.dev.json -w -f file
# Debug mode
play --debug -f file # Show debug information
play -d -w -f other # Debug + watch + file
# List files
play --list # List all available .ts files
play -l # Short formimport { play } from 'play-tsx'
play({
name: 'play-tsx',
version: '1.0.0',
description: 'Enhanced TypeScript playground',
rootDir: './playground', // Root directory for files
tsconfig: './tsconfig.json', // Default tsconfig path
autoInstall: true, // Auto-install tsx if missing
flags: {
// Custom flags
myFlag: {
type: Boolean,
alias: 'm',
default: false,
description: 'My custom flag'
}
}
})# Set root directory
PLAY_TSX_ROOT_DIR=./src pnpm play
# Set tsconfig path
PLAY_TSX_TSCONFIG=./tsconfig.dev.json pnpm play
# Enable auto-install
PLAY_TSX_AUTO_INSTALL=true pnpm play{
"scripts": {
"play": "play",
"play:watch": "play --watch",
"play:debug": "play --debug"
}
}your-project/
├── playground/ # Default playground directory
│ ├── index.ts # Default entry file
│ ├── test.ts
│ └── examples/
│ └── demo.ts
├── tsconfig.json # TypeScript configuration
└── package.json
The tool resolves configuration in the following priority:
- Command line arguments (highest)
- Environment variables
- PlayOptions configuration
- Auto-detection (lowest)
--tsconfigcommand line argumentPLAY_TSX_TSCONFIGenvironment variablePlayOptions.tsconfigconfigurationtsconfig.jsonin project root- tsx default configuration
MIT License © 2025 king3
Contributions, issues and feature requests are welcome!
- GitHub: @coderking3
- Issue Feedback: GitHub Issues
Built on top of the amazing tsx by @privatenumber