Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

watch mode does not watch for changes to files when using indirectly inferred types #248

Closed
2 of 3 tasks
rayzr522 opened this issue Feb 12, 2023 · 4 comments · Fixed by #249
Closed
2 of 3 tasks

Comments

@rayzr522
Copy link
Contributor

Checklist

  • I can reproduce this issue when running this plugin on its own.
    Other plugins, such as node-resolve are known to cause issues.
  • I am running this plugin on .d.ts files generated by TypeScript.
    The plugin can consume .ts and even .js files (with allowJs: true), but this is known to cause issues.
  • This issue is not related to rolling up @types.
    The plugin ignores these by default, unless respectExternal is set. @types can contain hand-crafted code which is known to cause issues.

Code Snipped

a minimum reproduction repo can be found here: https://github.com/rayzr522/rollup-plugin-dts-watch-bug

// index.ts
export type { MyRouter as test } from "./types";

// types.ts
import { myRouter } from "./router";

const x = myRouter;
export type MyRouter = typeof x;

// router.ts
export const myRouter = { someProcedure: () => 2 + 2 };

Issue

when exporting a type that is inferred indirectly from an import, watch mode does not trigger a rebuild when changing the indirectly referenced file. this can be seen in the following demo video:

Code_Qq3F0qKfqI.mp4

the code used in this video is also included in my minimal repro repo: https://github.com/rayzr522/rollup-plugin-dts-watch-bug

I understand using this plugin directly on .ts files isn't necessarily recommended, but it seems like it should be relatively trivial to tell Rollup to watch every file that ends up being handled by this plugin. i did a little digging to see if I could open a quick PR, but didn't get very far before realizing it was probably most efficient to just open an issue report and give all the context I've gained so far.

as far as I understand, since you're using the typescript compilation API programmatically, it should be somewhat trivial to get a list of files that ended up being imported, and then perhaps using addWatchFile to tell rollup to watch them?

this bug makes it a huge pain in the ass when trying to bundle a client package for a tRPC router, as the idea is that you define your tRPC router in-code, take the typeof that router, and export that in your client package so that consumers can have a type-safe client without you having to bundle all your server-side-only router code into your client bundle

in the interim, I am just going to add an unused direct export of my sub-routers so that watch mode picks them up, but this feels like 100% unintentional behavior

happy to help in any way I can! :3

@Swatinem
Copy link
Owner

There is #35 about watch mode not working for .ts mode, since forever basically.

The problem is not only the rollup APIs, but rather the typescript APIs that were very painful to work with back then.

@rayzr522
Copy link
Contributor Author

rayzr522 commented Feb 12, 2023

aha, i see. is the sentiment of "I don't want to pour much effort into supporting this" still applicable? if so, I might take another stab at this again tomorrow, as the only alternative would be to switch out my build tool from tsup to something else or convince the tsup dev to change their setup... neither of which is ideal

edit: fwiw, watch mode seems to work almost flawlessly as long as I'm not doing the specific weird edge case described above of exporting the inferred type of an indirectly referenced import. if I'm doing anything else, I've so far had no issues w watch mode

@Swatinem
Copy link
Owner

is the sentiment of "I don't want to pour much effort into supporting this" still applicable?

Very much so I’m afraid. I’m off doing Rust development for quite some time. This plugin here only receives the occasional uplift of new syntax in new TS releases every now and then. So its pretty much in maintenance mode.

So I would very much appreciate help with anything :-)

@rayzr522
Copy link
Contributor Author

here's a demo of the aforementioned issue being fixed by #249 :3 (more context in the PR description)

Code_79JcnHOill.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants