Integration with Vitest (Vite)
Vitest — and any Vite-based pipeline — compiles TypeScript with esbuild, which does not run tsconfig plugins transformers. Forger ships a Vite plugin that applies the same compile-time transformer in these pipelines.
How it works
defineForgerVitestPlugin() compiles the project once with the TypeScript compiler, caches the program, and rewrites every Forger.create<T>()/Forger.createWith<T>() call exactly like the ts-jest and Angular (webpack) integrations do.
1. Install dependencies
No ts-patch is needed on this route — the plugin drives the TypeScript compiler directly.
2. Register the plugin
The plugin is published on the dedicated @artstesh/forger/vitest subpath, not on the package root: it loads Node-only modules (path, the TypeScript compiler) at import time, and the root entry has to stay browser-safe so Karma/webpack browser bundles that merely include Forger keep working.
The plugin runs as a pre transform: every .ts file with Forger.create/Forger.createWith calls is rewritten before esbuild transpiles it.
3. Point the plugin at the right tsconfig
tsconfig must cover every file that calls Forger — the type checker can only resolve types of files the compiler program owns. For an Angular workspace that is usually tsconfig.spec.json; files missing from the config are added on first sight, but a complete include list is faster.
Angular on esbuild builders
The esbuild-based Angular builders (@angular/build:karma, @angular/build:unit-test, @angular/build:application) do not run custom TypeScript transformers and offer no hook for them — the webpack patch from Integration with Angular does not apply there. The supported route for specs on these builders is a standalone Vitest setup with this plugin, as described above.
Notes
The rewritten code is returned without a source map: stack traces of rewritten lines may be slightly offset.
If a call reaches runtime unrewritten anyway,
Forger.create<T>()throws a descriptive error (see Caveats) — it no longer fails silently.