woutervh- / typescript-is

MIT License
956 stars 35 forks source link

Non-deterministic code generated #113

Closed dko-slapdash closed 2 years ago

dko-slapdash commented 2 years ago

Hi.

I was debugging the reason of why so many compiled files are changed in our project when a (seemingly unrelated) file change is made, and I found out that typescript-is re-generate the validators code on every change, even when the file isn't changed itself:

image

It's fine that it rebuilds the file (because all in all, we can't predict what parts of an is<> type was changed and in what file), but what we can do better here is to generate temporary function names in a deterministic way, so the file generated during the sequential runs would be byte-to-byte identical to the previous version if nothing changed. At least this is what tsc does itself when compiling TypeScript: the output generated from the same set of src files is byte-to-byte identical to the previous output of the same files.

I want to submit a PR about this (I'm thinking about seeding the random generator which is used to generate these _15081 names in a deterministic way, maybe per-file or so); would appreciate any hints or shortcuts @woutervh- before I started.

dko-slapdash commented 2 years ago

I submitted a PR which resolves this here: https://github.com/woutervh-/typescript-is/pull/114

@woutervh- Could you please take a look? It currently helps our build environment a lot (typescript-is is a key component in our system, we have hundreds of types enforced with it).