Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to use https://github.com/wessberg/DI-compiler with ts-patch #120

Closed
gravypower opened this issue Aug 13, 2023 · 7 comments

Comments

@gravypower
Copy link

I have been trying to get the transformer @wessberg/di-compiler to work but just end up with an error

throw new tsp.TsPatchError(`Invalid plugin entry point! Expected a transformer factory function or an object with a '${transformerKind}' property`);
                      ^
TsPatchError: Invalid plugin entry point! Expected a transformer factory function or an object with a 'before' property

I have logged out the object it is returning an object with a before property. I am not sure what the issue is

{
  before: [ [Function (anonymous)] ],
  after: [ [Function (anonymous)] ]
}

my transformer:

import type { Program } from 'typescript'
import { di } from "@wessberg/di-compiler";

const transformer = (program: Program) => {

  const diTransformer = di({ program });

  console.log(diTransformer);

  return diTransformer.before;
}

export default transformer

my compilerOptions:


 "compilerOptions": {
    "declarationDir": "../dist",
    "outDir": "../dist",
    "plugins": [{
      "transform": "./transformer.ts"
    }]

I am not sure what to do to resolve the issue, I looked at breaking down what its doing try creating a program transformer but before I started this I thought I would raise an issue in case I am missing something.

Thanks

@nonara
Copy link
Owner

nonara commented Aug 14, 2023

Hello!

If I'm reading that correctly, it looks like before is an array with a function in it. If that's correct, you can return di.before[0].

You may also be able to simply return diTransformer, as it looks like it's in the expected alternative format. I'm not able to confirm atm, but I'd suggest checking both options.

Let me know if that helps!

Edit:

I just saw your issue. Did this work with ttypescript before, and if so, can you show me what the original code was that worked?

Tsp should be fully compatible without needing to change anything.

@gravypower
Copy link
Author

i was not able to get things to work with ttypescript because of the typescript version I am working with, i can only assume it did as the read-me calls it out https://github.com/wessberg/DI-compiler#usage-with-ttypescript. I will give your suggestions ago and report back. thanks for the reply

@gravypower
Copy link
Author

i just saw that my example was incorrect, it is in a form where I was playing with things try to work out the issue.

should be:

import type { Program } from 'typescript'
import { di } from "@wessberg/di-compiler";

const transformer = (program: Program) => {

  const diTransformer = di({ program });

  console.log(diTransformer);

  return diTransformer;
}

export default transformer

its in this form where I get the error

throw new tsp.TsPatchError(`Invalid plugin entry point! Expected a transformer factory function or an object with a '${transformerKind}' property`);
                      ^
TsPatchError: Invalid plugin entry point! Expected a transformer factory function or an object with a 'before' property

@nonara
Copy link
Owner

nonara commented Aug 14, 2023

I appreciate the update.

I recently fixed a bug in that same area. It's possible we need to also add array support there. I'll take a look at it.

In the mean time, does returning diTransformer.before[0] work for you?

@gravypower
Copy link
Author

BOOM! yes it worked.

I had to do this:

import type { Program } from 'typescript'
import { di } from "@wessberg/di-compiler";

const transformer = (program: Program) => {

  const diTransformer = di({ program });

  console.log(diTransformer);

  return {
    before: diTransformer.before[0],
    after: diTransformer.after[0]
  };
}

export default transformer

@gravypower
Copy link
Author

i will see what i can do with getting an MR to fix the issue for you; I am still only new to TypeScript so will see.

@nonara nonara closed this as completed in aabf389 Dec 5, 2023
@nonara
Copy link
Owner

nonara commented Dec 5, 2023

Array support added in v3.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants