Repository navigation
feat: expose programmatic watch controls - #1062
Conversation
✅ Deploy Preview for tsdown-main ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
tsdown
create-tsdown
@tsdown/css
@tsdown/exe
tsdown-migrate
commit: |
There was a problem hiding this comment.
🟡 Changes recommended
Automatic and shortcut-triggered restarts can currently create unhandled promise rejections because async restart() calls are invoked without proper awaiting/catching in watch flows.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR exposes programmatic watch lifecycle controls by introducing a TsdownHandle return type (instead of TsdownBundle[]) and threading watch controls into config-function context so programmatic consumers can restart/close watch builds.
Changes:
- Changed
build()to returnTsdownHandlewith{ bundles, watch: { restart, close } }and added restart/close proxying and watch-mode guards. - Added
UserConfigFnContext.watchand propagated context (includingrootConfig) through config loading and workspace resolution. - Updated docs, tests, and public
.d.tssnapshots to reflect the new API surface.
File summaries
| File | Description |
|---|---|
| tests/utils.ts | Updates test helper typings to accept the new TsdownHandle return type. |
| tests/e2e.test.ts | Adapts tests to the new resolveConfig signature by providing a dummy watch controller. |
| src/utils/chunks.ts | Introduces TsdownHandle interface to represent programmatic build/watch handles. |
| src/features/shortcuts.ts | Adjusts shortcut types/signature to accept async restart actions. |
| src/features/plugin.test.ts | Adapts tests to the new resolveConfig signature with a dummy watch controller. |
| src/config/workspace.ts | Threads UserConfigFnContext through workspace config loading and sets rootConfig. |
| src/config/types.ts | Defines UserConfigFnContext (including watch) and exports TsdownHandle types. |
| src/config/index.ts | Changes resolveConfig() to accept watch controls and pass them into config loading context. |
| src/config/file.ts | Updates loadConfigFile() to accept UserConfigFnContext and pass it to config functions. |
| src/config.ts | Re-exports UserConfigFnContext from the public config module. |
| src/build.ts | Implements new TsdownHandle return shape and watch restart/close lifecycle behavior. |
| package.json | Bumps inlined pkg-types version. |
| docs/zh-CN/advanced/programmatic-usage.md | Updates programmatic usage docs to describe TsdownHandle and watch controls. |
| docs/advanced/programmatic-usage.md | Updates English programmatic usage docs for TsdownHandle and watch controls. |
| snapshots/tsnapi/index.snapshot.d.ts | Updates API snapshot to include TsdownHandle, UserConfigFnContext, and new build signatures. |
| snapshots/tsnapi/config.snapshot.d.ts | Updates config API snapshot to include UserConfigFnContext. |
Review details
Suppressed comments (1)
src/build.ts:149
restart()can reject (e.g. rebuild failure or repeated restart). Because the readline handler inshortcuts()awaits the action without its own try/catch, passingrestartdirectly can lead to unhandled promise rejections during watch shortcuts. Wrappingrestart()here to log-and-swallow errors keeps the watch UI stable.
if (hasWatchConfig) {
// Watch mode with shortcuts
disposeCbs.push(shortcuts(restart))
- Files reviewed: 14/16 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| () => { | ||
| if (!restarted) restart() | ||
| }, |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
1f7d098 to
03633c9
Compare
03633c9 to
866ef37
Compare
AI usage
Description
Expose watch lifecycle controls to programmatic consumers through
TsdownHandleandUserConfigFnContext.{ bundles, watch }frombuild().watch.restart(), returning the next handle, andwatch.close()for graceful cleanup.This is a breaking change to the return type of
build().Linked Issues
N/A
Additional context
Verified with
pnpm format,pnpm lint,pnpm typecheck,pnpm test run,pnpm build, and local watch lifecycle checks covering rebuild, restart, close, config reload, multiple watchers, and CLI shortcuts.