dominikg / tsconfck

A utility to find and parse tsconfig files without depending on typescript
Other
290 stars 14 forks source link

fix: add a temporary property '_isRootFile_' for each promise result of cache to prevent i… #165

Closed daihere1993 closed 6 months ago

daihere1993 commented 6 months ago

I've just came across the issue of https://github.com/vitest-dev/vitest/issues/5182. Then found out the RC is https://github.com/dominikg/tsconfck/issues/154. So I spent some times to read relevant codes and put my correction out to try to push this issue forward. The tests based on https://github.com/dominikg/tsconfck/pull/157.

My considerations about this fix: this fix is based on the current design and as few changes as possible to just add a patch to prevent into the deadlock situation you've described in https://github.com/aleclarson/vite-tsconfig-paths/issues/132#issuecomment-1902718694.

In the correction, I add an internal property _isRootFile_ for each cached file and this new property means if the file is invoked by the public api parese() which used to distingust another type of cache which created by parseFile(). Then using _isRootFile_ prevent into the deadlock in parseFile().

@dominikg let me know if you have some comments.

dominikg commented 6 months ago

great, will have a closer look soon. is it possible to hide the flag with a non enumerable ?

daihere1993 commented 6 months ago

great, will have a closer look soon. is it possible to hide the flag with a non enumerable ?

Done.

By the way, this flag is just bound to the "promise result" would not exist in the result returned to user, it's more like a temporary flag druing the parse process.

dominikg commented 6 months ago

Thanks! looks like you also have to run pnpm generate and commit the changes.

The reason for hiding is that the promise can be accessed from the cache. Yes its temporary and users shouldn't enumerate the promise, but better safe than sorry ;) The changes to the cache test look clean to :rainbow: Have to see if they fit future plans though. The complete eager parsing of referenced is hurting performance, so tsconfck 4.0 might change that to lazy referenced parse.

see also https://github.com/dominikg/tsconfck/pull/162 that would be a breaking change so it didn't move forward yet

daihere1993 commented 6 months ago

CI passed now. Yeah, to persue better performance then we need some refactor. I'll have a look of https://github.com/dominikg/tsconfck/pull/162 and would like try to have another PR about speed imprevement.

dominikg commented 6 months ago

added a changeset and made the flag readonly, planning to release a patch with it soon.