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 --yes

Flags

FlagDescriptionDefault
--applyWrite changes to diskfalse (dry-run preview)
--include <glob>Glob pattern for files to migrate (repeatable)src/**/*.ts
--tsconfig <path>Path to tsconfig.jsontsconfig.json
--cwd <path>Working directorycurrent directory
--forceRun even if git working directory has uncommitted changesfalse
--yes, -yAccept all prompts (non-interactive mode)false

Supported Sources

SourceWhat gets migrated
class-validatorClass 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/swaggerRemoves redundant decorators (@ApiProperty, @ApiTags, etc.), auto-detects security schemes
Nestia@TypedRoute.Get() to @Get(), @TypedBody() to @Body(), @TypedFormData.Body() to @FormDataBody()
Typiaimport { tags } from 'typia' to import { tags } from '@tsgonest/types', removes typia.assert<T>() calls

What Happens

  1. Git check — Requires a clean working directory (use --force to skip)
  2. Detection — Scans imports to determine which migration sources are present
  3. Migration plan — In interactive mode, asks for confirmation on each step
  4. baseUrl import rewriting — If tsconfig.json has baseUrl, bare imports are rewritten to relative paths before baseUrl is removed
  5. Source transforms — Runs AST codemods for each detected source
  6. Import cleanup — Removes empty/unused imports left by transforms
  7. Dependency management — Removes old packages, adds tsgonest packages
  8. Script updates — Updates build and dev scripts in package.json
  9. Config generation — Creates tsgonest.config.ts with auto-detected settings
  10. tsconfig cleanup — Removes baseUrl and 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 --force

Detailed Guides

For source-specific migration details:

On this page