Zhengqbbb / cz-git

cz-git | czg πŸ› οΈ DX first and more engineered, lightweight, customizable, standard output format Commitizen adapter and CLI
https://cz-git.qbb.sh
MIT License
1.05k stars 39 forks source link

refactor: improve build- and typescript configuration #116

Closed jrson83 closed 1 year ago

jrson83 commented 1 year ago

Related ISSUE

None

Type Of Change

Clear Describe

refactor(workspace): improve build- and typescript configuration

Description

There are several solutions to properly set up a monorepo with TypeScript or not. Since this is not already hard enough, bundlers put additional obstacles in your way.

There are issues with both tsup and unbuild when trying to use TypeScript project references. This can probably be traced back to the rollup dts plugin. Some of these issues have existed for several years. However, another approach is to use path aliases. There are also some things to consider like isolated packages but shared type definitions.

I am very happy with czg and would like to make a contribution here to improve the performance of the build scripts. Since I have been working a lot on setting up monorepos lately, I think I can make a useful contribution here.

What does this PR change?

I have tested different approaches, am very happy with this one and hope you like it too. Surely there is still something to improve. Let me know!

Please have a look at the scripts folder and the dev scripts of the package.json. I may have overlooked something.

Test Case

No need for additional test case.

netlify[bot] commented 1 year ago

Deploy request for cz-git rejected.

Name Link
Latest commit b96af913ba3dd06198666859a2138ce86b4c6d78
Zhengqbbb commented 1 year ago

WOW, thanks and understand your thoughts, you can tell me when you are ready.

But for now I have to talk about my design, why my build process is more complicated and why use tsc.

There are two parts here: the core plugin and the result application

The core plugin is not required to be small, but to be fully compiled with d.ts may even cover completely. This will ensure that my subsequent application of bundle

And bundle is also the same need to pay attention to, cz-git is required with d.ts, while czg is the maximum compression bundle. so I am first cz-git compile once and then czg. so czg can get the maximum static analysis. Finally, cz-git is compressed again

This is the best way to reduce bundle application with invisible errors (which is important so I discarded speed) and czg and cz-git will get perfect static analysis

tsc plugins -> tsc cz-git -> tsup czg -> tsup cz-git -> tsup plugins

I can discard speed in packaging, but definitely not compile bundle out an application with problems

jrson83 commented 1 year ago

Ah Okay I understand.

So on the current monorepo, imports are not resolved from source files (.ts) but instead of the compiled lib (.js & .d.ts). You first have to run build once to have working vscode IntelliSense support. In an optimal state, properly configured IntelliSense and auto-completion should lead to a more secure and reliable end result than imports from compiled files, I think. What do you think about this?

you can tell me when you are ready.

It is ready for now, please check out the changes and let me know what you think :)

jrson83 commented 1 year ago

The build fails cause node 14 does not support spread syntax in tsup.config. Thats why I replaced it with Object.assign.

Zhengqbbb commented 1 year ago

The build fails cause node 14 does not support spread syntax in tsup.config. Thats why I replaced it with Object.assign.

Thx ~

Zhengqbbb commented 1 year ago

@jrson83 Github action status is shot down. Wait fix and ready to merge.

I have released v1.6.2-beta.3 and tested in Node v12 docker well. you also can have a try now~

jrson83 commented 1 year ago

@Zhengqbbb great, thx! I will test the release on windows and I will try fix the Github action.

Zhengqbbb commented 1 year ago

wait for github team fix https://twitter.com/githubstatus/status/1641091847735975937

jrson83 commented 1 year ago

build and test from branch running with success on windows 11.

Zhengqbbb commented 1 year ago

@jrson83 Thanks your great work again πŸ€œβœ¨πŸ€›