A fast CLI tool to convert JavaScript and JSX files to TypeScript files using Bun.
.js
and .jsx
files after converting them to .ts
and .tsx
files respectively.
bun install
bun index.ts /path/to/your/project
bun index.ts /path/to/your/project dist build temp
bun index.ts /path/to/your/project [ignore-pattern1] [ignore-pattern2] ...
bun run build
./js2ts /path/to/your/project [ignore-patterns...]
bun link
js2ts /path/to/your/project [ignore-patterns...]
- 🚀 Fast file discovery using
Bun.glob()
- 📁 Recursive directory traversal
- ⚡ Parallel file processing
- 💻 CLI executable
- 🚫 Ignore patterns support (node_modules, dist, build, out ignored by default)
- 🔄 Converts and removes: Creates
.ts
/.tsx
files and removes original.js
/.jsx
files - 🎯 Supports both:
.js
→.ts
and.jsx
→.tsx
conversions - 🧠 Smart JSX detection: Automatically detects JSX syntax in
.js
files and converts to.tsx
- 📝 Simple: copies content then deletes originals
.js
files →.ts
files (or.tsx
if JSX syntax is detected).jsx
files →.tsx
files
The tool automatically detects JSX syntax in JavaScript files by looking for:
- JSX components (
<Component>
) - HTML elements (
<div>
,<span>
, etc.) - JSX fragments (
<>
,</>
) - Self-closing tags (
<Component />
)
If JSX syntax is found in a .js
file, it will be converted to .tsx
instead of .ts
.
By default, node_modules
, dist
, build
, and out
are always ignored. You can specify additional directories or files to ignore:
js2ts ./src temp coverage __tests__
This would ignore:
node_modules/
(default)dist/
(default)build/
(default)out/
(default)temp/
coverage/
__tests__/
$ js2ts ./my-project
🚫 Ignoring patterns: node_modules, dist, build, out
🔍 Found 8 file(s) to convert (5 .js, 3 .jsx)
⚠️ Original .js/.jsx files will be removed after conversion
✅ Converted: ./my-project/index.js -> ./my-project/index.ts
✅ Converted: ./my-project/utils.js -> ./my-project/utils.ts
✅ Converted: ./my-project/components/Button.jsx -> ./my-project/components/Button.tsx
✅ Converted: ./my-project/components/Header.jsx -> ./my-project/components/Header.tsx
✅ Converted: ./my-project/components/App.js -> ./my-project/components/App.tsx
✅ Converted: ./my-project/lib/helper.js -> ./my-project/lib/helper.ts
🎉 Conversion complete - all .js/.jsx files converted to .ts/.tsx and originals removed.
$ js2ts ./my-project temp coverage
🚫 Ignoring patterns: node_modules, dist, build, out, temp, coverage
🔍 Found 6 file(s) to convert (4 .js, 2 .jsx)
⚠️ Original .js/.jsx files will be removed after conversion
✅ Converted: ./my-project/src/index.js -> ./my-project/src/index.ts
✅ Converted: ./my-project/src/utils.js -> ./my-project/src/utils.ts
✅ Converted: ./my-project/src/App.jsx -> ./my-project/src/App.tsx
✅ Converted: ./my-project/lib/helper.js -> ./my-project/lib/helper.ts
🎉 Conversion complete - all .js/.jsx files converted to .ts/.tsx and originals removed.
This tool permanently removes your original .js
and .jsx
files after conversion. Make sure to:
- Backup your code or use version control before running
- Test in a safe environment first
- Review the file list shown before proceeding
The tool only removes .js
/.jsx
files after successfully creating the corresponding .ts
/.tsx
files.
This project was created using bun init
in bun v1.2.15. Bun is a fast all-in-one JavaScript runtime.