CLI
tsgonest migrate
Automated codemod to migrate from class-validator, Nestia, Typia, and @nestjs/swagger to tsgonest.
tsgonest migrate is an AST-based codemod that rewrites your NestJS project to use tsgonest in a single command. It handles decorator replacement, class-to-interface conversion, branded type insertion, import cleanup, and dependency management.
Usage
# Preview changes (dry-run, no files modified)
npx tsgonest migrate
# Apply changes (interactive)
npx tsgonest migrate --apply
# Apply changes (non-interactive, accept all defaults)
npx tsgonest migrate --apply --yesFlags
| Flag | Description | Default |
|---|---|---|
--apply | Write changes to disk | false (dry-run preview) |
--include <glob> | Glob pattern for files to migrate (repeatable) | src/**/*.ts |
--tsconfig <path> | Path to tsconfig.json | tsconfig.json |
--cwd <path> | Working directory | current directory |
--force | Run even if git working directory has uncommitted changes | false |
--yes, -y | Accept all prompts (non-interactive mode) | false |
Supported Sources
| Source | What gets migrated |
|---|---|
| class-validator | Class DTOs to interfaces with branded types (tags.Email, tags.MinLength<N>, etc.) |
| class-transformer | @Type(() => Number) to tags.Coerce, @Transform trim/case to tags.Trim/tags.ToLowerCase |
| @nestjs/swagger | Removes redundant decorators (@ApiProperty, @ApiTags, etc.), auto-detects security schemes |
| Nestia | @TypedRoute.Get() to @Get(), @TypedBody() to @Body(), @TypedFormData.Body() to @FormDataBody() |
| Typia | import { tags } from 'typia' to import { tags } from '@tsgonest/types', removes typia.assert<T>() calls |
What Happens
- Git check — Requires a clean working directory (use
--forceto skip) - Detection — Scans imports to determine which migration sources are present
- Migration plan — In interactive mode, asks for confirmation on each step
- baseUrl import rewriting — If
tsconfig.jsonhasbaseUrl, bare imports are rewritten to relative paths beforebaseUrlis removed - Source transforms — Runs AST codemods for each detected source
- Import cleanup — Removes empty/unused imports left by transforms
- Dependency management — Removes old packages, adds tsgonest packages
- Script updates — Updates
buildanddevscripts inpackage.json - Config generation — Creates
tsgonest.config.tswith auto-detected settings - tsconfig cleanup — Removes
baseUrland compiler plugins
Migration Report
After --apply, a tsgonest-migrate-report.md file is written to your project root containing:
- Summary — Transform counts by category
- Auto-generated changes — Config files created, tsconfig modifications
- Package changes — Dependencies added/removed, scripts updated
- Manual TODOs — Items needing human review (custom validators,
@Exclude,SwaggerModule, etc.) - Warnings — Non-critical issues (packages still imported, parse errors)
Examples
# Migrate only DTO files
npx tsgonest migrate --apply --include "src/**/*.dto.ts"
# Migrate with a custom tsconfig
npx tsgonest migrate --apply --tsconfig tsconfig.build.json
# CI-friendly: non-interactive, force run
npx tsgonest migrate --apply --yes --forceDetailed Guides
For source-specific migration details: