egoist / egoist/tsup

[8.5.1] Watch mode: include plugin-returned watchFiles in rebuild trigger set

Open
#1,382 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
11.3k
Forks
275
PR merge metrics
No merged PRs in 30d

Description

### Describe the bug

In watch mode (`--watch`), tsup only triggers rebuilds when files from `result.metafile.inputs` change. It ignores `watchFiles` returned by esbuild plugins from their `onLoad` callbacks.

Plugins like `@vanilla-extract/esbuild-plugin` correctly return `watchFiles` with all dependencies (e.g. `.css.ts` imports like `tokens.ts`). Those files never appear in the main build's `metafile.inputs` because they're only loaded inside the plugin's internal compilation. As a result, changing a dependency of a `.css.ts` file does not trigger a rebuild.

### Reproduction

1. Create a library with vanilla-extract: a `.css.ts` file imports from `tokens.ts`
2. Run `tsup --watch`
3. Change `tokens.ts` — no rebuild
4. Change `.css.ts` directly — rebuild works

### Expected behavior

When any file in `watchFiles` (returned by plugins) changes, tsup should trigger a rebuild.

### Suggested solution

Add a plugin that wraps `build.onLoad` and collects `watchFiles` from plugin results, then merge them into `buildDependencies` (the set used when deciding whether to rebuild). Path normalization may be needed for cross-platform compatibility (relative vs absolute, slash vs backslash).

### Environment

- tsup version: 8.5.1

Contributor guide

Open the contributing guide

Research direction

Start by tracing the watch-mode rebuild decision that uses buildDependencies and metafile.inputs, then inspect the build.onLoad plugin entry point described in the issue. Reproduce the vanilla-extract case by changing tokens.ts under tsup --watch; done means plugin-returned watchFiles trigger rebuilds while direct .css.ts changes continue to work, including across path formats.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
build-system, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.