0no-co / gql.tada

🪄 Magical GraphQL query engine for TypeScript
https://gql-tada.0no.co
MIT License
2.52k stars 41 forks source link

fix(internal): Use TypeScript's built-in file watcher for SDL loader #340

Closed kitten closed 1 month ago

kitten commented 1 month ago

Resolves #339

Summary

TODO

This switches the SDL loader over to using ts.sys.watchFile in favour of other, similar file watchers that work around some issues. Generally, there are some conditions under which the built-in file watcher in Node fails. It's suspected that swap-writing in some editors breaks the file watcher, for example.

Instead of working around this ourselves, we can use TypeScript's implementation, which implements all known workarounds and approaches, including polling fallbacks.

Set of changes

changeset-bot[bot] commented 1 month ago

🦋 Changeset detected

Latest commit: bdc32bd41d30e9cbf4a30b28b349f05d7e585fcf

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

mrazauskas commented 1 month ago

It seems that ts.sys.watchFile watchers are not unrefed. Opposite to fs.watch watcher that are created with persistent: false.

The unrefed watchers do not allow process to exit. That is fine for TypeScript language service, but that is troublesome in cases where gql.tada is used as stand alone package.


I bumped into this limitation while debugging this issue: https://github.com/tstyche/tstyche/pull/276

Reproduction repo can be found here: https://github.com/tstyche/tstyche/pull/276#issuecomment-2267647218

Not sure what could be the solution. Just wanted to draw your attention.

mrazauskas commented 4 weeks ago

Generally, there are some conditions under which the built-in file watcher in Node fails. It's suspected that swap-writing in some editors breaks the file watcher, for example.

@kitten The other difference previous implementation was using the async version of fs.watch. In contrary TypeScript's watchers are wrapped around sync fs.watch. I was experimenting with both of them while implementing watch mode for TSTyche. Indeed sometimes events were missing in the async fs.watch.

I was wondering if you tried using the sync fs.watch implementation instead?