@goodie-ts/transformer
v2.0.0
Published
Compile-time TypeScript transformer for goodie-ts dependency injection
Downloads
138
Readme
@goodie-ts/transformer
Compile-time TypeScript transformer for goodie-ts dependency injection.
Install
pnpm add -D @goodie-ts/transformerOverview
Scans your TypeScript source for decorated classes at build time using ts-morph, resolves the dependency graph, and generates a typed wiring file (AppContext.generated.ts). No runtime reflection needed.
Pipeline
Scanner → Resolver → GraphBuilder → Codegen- Scanner — reads ts-morph AST, discovers
@Singleton,@Injectable,@Module,@Provides - Resolver — resolves types, constructor params, field injections, and
InjectionTokenreferences - GraphBuilder — validates the dependency graph, expands modules, detects cycles
- Codegen — emits typed
ComponentDefinition[], factory functions, and token exports
The transformer includes built-in plugins for AOP (@Around, @Before, @After) and config (@ConfigurationProperties) that are always active — no manual plugin configuration needed.
Usage
Most users should use @goodie-ts/vite-plugin which calls the transformer automatically. For direct use:
import { transform } from '@goodie-ts/transformer';
await transform({
tsConfigPath: './tsconfig.json',
outputPath: './src/AppContext.generated.ts',
});Generated Output
The generated file exports:
- Typed
InjectionTokendeclarations for interfaces, generics, and primitives - A
definitionsarray ofComponentDefinition[] createContext()— async factory returning anApplicationContextapp— aGoodie.build(definitions)instance ready to.start()
Error Messages
Missing provider errors include fuzzy matching suggestions ("Did you mean: UserService?") and plugin errors are wrapped with the plugin name for context. Set GOODIE_DEBUG=true to print the full component graph, resolution order, and active plugins during build.
Library Mode
For packages that ship pre-scanned components, use transformLibrary() (via goodie generate --mode library). It serializes all component definitions (including conditional ones) to components.json and also scans for createAopDecorator<{...}>() calls, including AOP config in the manifest. Conditional components are not filtered at build time -- evaluation of @ConditionalOnProperty, @ConditionalOnEnv, and @ConditionalOnMissingComponent happens at runtime in ApplicationContext.create(). Consumers auto-discover components and AOP mappings at build time.
