egoist / tsup

The simplest and fastest way to bundle your TypeScript libraries.
https://tsup.egoist.dev
MIT License
9.24k stars 218 forks source link

watch mode for dts builds doesnt track changes to indirectly referenced imports #833

Closed rayzr522 closed 1 year ago

rayzr522 commented 1 year ago

it looks like tsup doesn't actually watch files that are only imported for their types

this is a huge DX issue when dealing with tRPC, because in order to avoid including a bunch of server-only dependencies in my client package that I'm building, I have to reference & export only the type of my routers, but not the actual router itself

here's a minimal reproduction repro along w a video demonstrating the issue: https://github.com/rayzr522/tsup-watch-type-imports-bug

https://user-images.githubusercontent.com/15263431/218244417-6be2a6cf-0300-47bd-8b23-c35eb2599d02.mp4

npm -v
# 8.19.3
pnpm -v
# 7.26.3
tsup -v
# tsup/6.6.0 linux-x64 node-v18.13.0

EDIT: I just realized the bug wasn't exactly what I thought it was, and am having a hard time reproducing the issue in my MVP repo. I will post an update here once I've figured it out, so sorry for the confusion!

rayzr522 commented 1 year ago

(the original bug report was actually inaccurate as I misunderstood the reproduction steps -- please see new report below)

the title is a bit long winded, wasn't sure exactly how to best describe the issue. but tl;dr, if I import a const from a file, take the type of it, and then export that and then re-export it in my entry file, watch mode behaves as expected. however, if I take that initially imported const, reassign it to a new variable, and then take the type of it, the file it was originally imported from is no longer watched.

I've updated the repo repo here with a more minimal repro: https://github.com/rayzr522/tsup-watch-type-imports-bug

and here's a demo video of the issue:

https://user-images.githubusercontent.com/15263431/218289220-6a2f0892-feb7-4ba3-a191-fa9fc161fd49.mp4

I have been digging around in the codebase a bit trying to repro, but I can't quite tell where the issue is.

p.s.: in case you were wondering, I did try repro'ing this without the in-between file and the re-export in my entry, and doing the typeof directly in my entry file and I couldn't reproduce it; watching always worked correctly:

https://user-images.githubusercontent.com/15263431/218289330-2b556d43-17d5-4838-b0c0-e6d764b3f4e6.mp4

rayzr522 commented 1 year ago

damn. i repro'd the issue w just rollup & rollup-plugin-dts, so it's a rollup-plugin-dts issue it seems. I'll go open an issue over there!

thanks for the amazing lib :)

https://user-images.githubusercontent.com/15263431/218289687-e92e8b85-e1e6-4a88-9555-da9cedb0b26d.mp4

rayzr522 commented 1 year ago

in case anyone stumbles across this and wants to know what came of this issue, you can follow the corresponding rollup-plugin-dts issue here: https://github.com/Swatinem/rollup-plugin-dts/issues/248