mirror of
https://github.com/johndoe6345789/tsmorph.git
synced 2026-04-24 13:54:58 +00:00
dependabot/npm_and_yarn/npm_and_yarn-dea2cac87d
Bumps the npm_and_yarn group with 1 update in the / directory: [next](https://github.com/vercel/next.js). Updates `next` from 14.2.35 to 15.5.10 - [Release notes](https://github.com/vercel/next.js/releases) - [Changelog](https://github.com/vercel/next.js/blob/canary/release.js) - [Commits](https://github.com/vercel/next.js/compare/v14.2.35...v15.5.10) --- updated-dependencies: - dependency-name: next dependency-version: 15.5.10 dependency-type: direct:production dependency-group: npm_and_yarn ... Signed-off-by: dependabot[bot] <support@github.com>
tsmorph
Automated TSX/TypeScript refactoring toolkit using ts-morph to intelligently extract code blocks into separate, well-typed, lint-compliant files with automatic import management. The goal is to support smaller components (e.g., 50/100/150 LOC thresholds) and push more logic into hooks/utilities via a feedback loop.
🚀 Quick Start
# Install dependencies
npm install
# Run the complete refactoring pipeline
npm run refactor # Extract types & interfaces
npm run refactor:pass2 # Extract utility functions
npm run analyze-types # Add missing types & improve type safety
npm run fix-lint # Auto-fix lint issues & format code
npm run type-check # Verify everything compiles
✨ Features
- Automated Code Extraction: Extracts types, interfaces, and utility functions to separate files
- Smaller Component Targets: Supports tighter LOC targets (e.g., 50/100/150) by encouraging extraction into hooks and utilities
- Feedback Loop Friendly: Re-run the pipeline to keep shrinking components after each extraction pass
- Smart Import Management: Automatically adds, removes, and organizes imports
- Type Analysis: Infers and adds missing return types, parameter types, and fixes
anytypes - Lint Auto-Fixing: Integrates with ESLint and Prettier for consistent code quality
- Type Safety: Achieves 100% type coverage with precise union types
📊 Results
Starting with a monolithic TSX component, the tools automatically refactor it into:
| File | LOC | Purpose |
|---|---|---|
UserManagementDashboard.tsx |
Varies | Main component logic |
UserManagementDashboard.types.ts |
22 | Type definitions & interfaces |
UserManagementDashboard.utils.ts |
50 | Utility functions with precise types |
All with:
- ✅ Automatically managed imports
- ✅ 100% type coverage
- ✅ Lint-compliant code
- ✅ Precise union types (e.g.,
"#ff6b6b" | "#4ecdc4" | "#95a5a6")
📖 Documentation
See DOCUMENTATION.md for comprehensive guides on:
- How each refactoring tool works
- Customizing extraction patterns
- Type analysis details
- Configuration options
- Best practices
🛠️ Available Commands
| Command | Description |
|---|---|
npm run refactor |
Extract types and interfaces (pass 1) |
npm run refactor:pass2 |
Extract utility functions (pass 2) |
npm run analyze-types |
Analyze and fix type annotations |
npm run fix-lint |
Auto-fix lint issues and format code |
npm run type-check |
Verify TypeScript compilation |
npm run lint |
Check for lint issues |
npm run format |
Format all files with Prettier |
🧰 CLI Usage for Another App
Target any TSX file by passing file paths and thresholds directly to the scripts:
ts-node scripts/refactor-tsx.ts --file path/to/Dashboard.tsx --min-function-lines 50 --min-variable-lines 25
ts-node scripts/refactor-tsx-pass2.ts --file path/to/Dashboard.tsx --helper-pattern "^(validate|get|format|handle)"
ts-node scripts/analyze-types.ts --files path/to/Dashboard.types.ts,path/to/Dashboard.utils.ts,path/to/Dashboard.tsx
📦 Example Output
Type Analysis Report
📊 Type Analysis: UserManagementDashboard.utils.ts
✓ Added return type to getRoleBadgeColor: "#ff6b6b" | "#4ecdc4" | "#95a5a6" | "#7f8c8d"
✓ Added return type to getStatusBadgeColor: "#2ecc71" | "#e74c3c"
✓ Added return type to formatDate: string
💾 Saved 3 type improvements
📈 Type Coverage Report: 100% (4/4 declarations typed)
✅ No 'any' types found
🎯 Key Technologies
- ts-morph: TypeScript AST manipulation
- TypeScript: Type inference and analysis
- ESLint: Code quality enforcement
- Prettier: Code formatting
- ts-node: Direct TypeScript execution
📝 License
MIT
Languages
TypeScript
100%