Registry / serialization / ng-di-transpiler

ng-di-transpiler

JSON →
library0.1.10jsnpmunverified

ng-di-transpiler v0.1.10 is a dependency injection transpiler for Angular that generates platform-specific provider files at build time. It allows developers to define interfaces for tokens and create typed provider configurations, which are then transpiled into compiled provider files. The tool is designed for Angular 2+ applications and aims to reduce boilerplate and improve type safety in DI setup. It is still in early stages (v0.1.x) with experimental features like interface-based tokens. Alternatives include Angular's built-in provider factories or custom AOT compilation setups, but this package provides a dedicated transpilation step. Release cadence is sporadic with occasional bug fixes. Ships TypeScript types and uses a CLI command (ngdt) for integration.

npm install ng-di-transpiler
INSTALL
IMPORT
SIG · NG-DI-TRANSPILER
N
ng-di-transpiler
serializationjavascriptv0.1.10
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

TokenProviders
import { TokenProviders } from 'ng-di-transpiler'
const TokenProviders = require('ng-di-transpiler')
ESM only; library only ships TypeScript types.
TokenProvider
import { TokenProvider } from 'ng-di-transpiler'
Used to create typed provider classes.
ngdtOptions
import { ngdtOptions } from 'ng-di-transpiler'
Configuration object used in tsconfig.json, not imported directly.
default (CLI)
Use CLI command 'ngdt' directly as a script or npx
const ngdt = require('ng-di-transpiler').default
No programmatic API documented; only CLI.

Shows how to define tokens, create a provider file, and run the CLI to transpile.

// 1. Define platform tokens interface import { TokenProviders, TokenProvider } from 'ng-di-transpiler'; import { OpaqueToken } from '@angular/core'; interface ConsoleLike { log(msg: string): void; } export const CONSOLE_TOKEN = new OpaqueToken('console'); export interface PlatformTokens extends TokenProviders { console: ConsoleProvider; } export class ConsoleProvider extends TokenProvider<ConsoleLike> { provider: CONSOLE_TOKEN; } // 2. Create platform provider file: providers.browser.ts import { PlatformTokens, ConsoleProvider } from './platform-tokens'; class BrowserLogger { log(msg: string) { console.log(msg); } } export const TOKENS: PlatformTokens = { console: new ConsoleProvider(BrowserLogger) }; // 3. Run CLI to compile: ngdt --files "src/**/providers.browser.ts" --postfix .compiled // Generates providers.browser.compiled.ts
ngdt --version
Debug
Known issues
gotchaExperimental interface-as-token feature (v0.1.0) lacks tests and may be unstable.
fix
Stick to using OpaqueToken/InjectionToken for token types until feature is stable.
affects: >=0.1.0
gotchaType checking relies on the variable type annotation; incorrect type may cause transpilation to skip or generate wrong code.
fix
Ensure exported const in provider files is explicitly typed with the interface extending TokenProviders.
affects: >=0.0.2
gotchaOnly files matching the glob pattern are transpiled; mismatched patterns result in no output.
fix
Use explicit --files argument or configure ngdtOptions in tsconfig.json.
affects: >=0.0.2
Errors
Common errors & fixes
Cannot find name 'TokenProviders'
Missing import from ng-di-transpiler.
fix
Add import: import { TokenProviders } from 'ng-di-transpiler';
Type 'typeof SomeClass' is not assignable to type 'TokenProvider<T>'
Passing class reference instead of instance to TokenProvider constructor.
fix
Instantiate the provider class: new SomeTokenProvider(ActualClass) instead of new SomeTokenProvider(ActualClass).
ngdt: command not found
Package not installed or not in PATH.
fix
Install locally: npm install ng-di-transpiler --save-dev, then use npx ngdt or add script in package.json.
No provider for TokenProviders
The token interface not extending TokenProviders or variable not typed correctly.
fix
Ensure your platform tokens interface extends TokenProviders and the exported const is typed with that interface.
Upgrade
Version history
0.1.10latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
Amazon
1
OpenAI (training)
1
Resources
ng-di-transpiler — npm install ng-di-transpiler · libregistry