wessberg / DI-compiler

A Custom Transformer for Typescript that enables compile-time Dependency Injection
MIT License
82 stars 7 forks source link

Bindings not generated with Parcel #8

Open amanteaux opened 3 years ago

amanteaux commented 3 years ago

Hello,

First I want to say that I am very glad you made this compile time DI library for TS! It does not have many features, it just contains what is necessary, that is perfect :)

I am trying to make the di-compiler work with Parcel (I use Parcel to set up "easily" a React project with di-compiler after that). Almost everything is working (it correctly generates the constructors data), however for some reason the bindings are not generated. Everything works fine if I write:

container.registerSingleton(undefined, {identifier:'ServiceA', implementation:ServiceA});
container.registerSingleton(undefined, {identifier:'ServiceB', implementation:ServiceB});
const serviceB = container.get<ServiceB>({identifier: 'ServiceB'});

However, if I try to use the standard syntax:

container.registerSingleton<ServiceA>();
container.registerSingleton<ServiceB>();
const serviceB = container.get<ServiceB>();

I get a Uncaught ReferenceError: DIContainer could not get service: No arguments were given! for the registerSingleton calls and a Uncaught ReferenceError: DIContainer could not get service: No options was given! for the get call.

Do you have any idea of what is wrong or what is missing?

To make the integration work, I use parcel-plugin-ttypescript that enables me to specify some TS transformers in the tsconfig.json file. After that, I needed to make a small adapter between this parcel plugin and di-compiler:

import { di } from "@wessberg/di-compiler";
import * as ts from 'typescript';

export default function(program: ts.Program) {
  return di({ program });
}

I created a repository with a minimal project to reproduce the issue: https://github.com/amanteaux/poc-parcel-di-compiler The two ways of writing the bindings are in src/index.ts.

Thank you for any help/hints to make the integration works! Cheers

BinaryShrub commented 3 years ago

I was looking to use parcel as well in my AWS lambda, anyone get this working?