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

generate mode passthrough #1252

Open
jff1625 opened this issue Aug 30, 2024 · 7 comments
Open

generate mode passthrough #1252

jff1625 opened this issue Aug 30, 2024 · 7 comments

Comments

@jff1625
Copy link

jff1625 commented Aug 30, 2024

I'm not sure if this is practical, but I think it'd be nice to be able to filter the scope of files that tyipa generate will process, and doing a simple file copy on any that don't match.

We're unable to patch our ts compiler.
The typia generate step is now the slowest part of our build.
Esbuild processes the output from typia generate.
All of our typia functionality is imported from a single file, ts/guards.ts

I'm thinking the generate task could be a lot faster if we could tell typia that it only need to process that one file, and everything else it can just copy.

What do you think? Would it make a difference to build times?

@samchon
Copy link
Owner

samchon commented Sep 2, 2024

How about using unplugin-typia of @ryoppippi

https://typia.io/docs/setup/#unplugin-typia

@jff1625
Copy link
Author

jff1625 commented Sep 2, 2024

I've experimented with unplugin-typia. With bun it works great. With esbuild I couldn't figure out how to get it to do anything without patching typescript. Is it supposed to work without the patch?

@samchon
Copy link
Owner

samchon commented Sep 2, 2024

Yes unplugin-typia also needs ts-patch patching.

@ryoppippi
Copy link
Contributor

ryoppippi commented Sep 2, 2024

@jff1625 Hi!
Actually we don't need to configure ts-patch when you use unplugin-typia, because unpuigin-typia doesn't use transform plugin for tsc.
However, I got some issue with esbuild before. ryoppippi/unplugin-typia#163
I guess this is because of transformation ordering(maybe sometimes esbuild removes type information before executing plugin, but we cannot enforce the order).

To make it works fine, I recommend to use unplugin-typia with vite/rollup/rolldown/bun. I like rolldown these days because it runs fast and the plugins also work fine. Also, the output of rollwodn is cleaner than that of Bun.build.
https://github.com/ryoppippi/pkg-to-jsr/blob/b759fede3cc4395a9bcc8448f9e05671b61f0ed0/tsdown.config.ts

@ryoppippi
Copy link
Contributor

Also, we can implement glob feature for generate command.

@jff1625
Copy link
Author

jff1625 commented Sep 2, 2024

I guess this is because of transformation ordering(maybe sometimes esbuild removes type information before executing plugin, but we cannot enforce the order).

This aligns with my observation.

I recommend to use unplugin-typia with vite/rollup/rolldown/bun

I prefer not to migrate the project to a different build tool at this time because (1) esbuild is otherwise a good fit, and (2) I tried quickly migrating it to bun but it was not so trivial.

Also, we can implement glob feature for generate command.

I saw the similarly named issue Support glob patterns in typia generate #1251 but I'm not sure it's the same use-case.

I want it to behave something like this:

src
├─ index.ts
└─ ts
   └─ guards.ts

typia generate --input src/ --output typia-generated --match guards
...generates to:

typia-generated
├─ index.ts        // typia didn't spend time thinking about this file, only copied
└─ ts
   └─ guards.ts    // typia generated code for this file

The question is - would that actually be any faster?

thanks!

@ryoppippi
Copy link
Contributor

So I added some cache feature to unplugin-typia before. Maybe typia cli should have this

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

3 participants