Skip to content

feat(plugin): add tsdownConfig and tsdownConfigResolved plugin hooks#918

Merged
sxzz merged 8 commits intomainfrom
sxzz/tsdown-config-hooks
Apr 16, 2026
Merged

feat(plugin): add tsdownConfig and tsdownConfigResolved plugin hooks#918
sxzz merged 8 commits intomainfrom
sxzz/tsdown-config-hooks

Conversation

@sxzz
Copy link
Copy Markdown
Member

@sxzz sxzz commented Apr 16, 2026

  • This PR contains AI-generated code, but I have carefully reviewed it myself. Otherwise, my PR may be closed.

Description

Adds two tsdown-specific per-plugin lifecycle hooks modeled on Vite's config and configResolved:

  • tsdownConfig(config, env) — called before the user config is resolved. May mutate in place or return a partial UserConfig to be deep-merged. Async supported.
  • tsdownConfigResolved(resolvedConfig) — read-only notification fired once per produced ResolvedConfig (per output format). Async supported.

Both hooks are detected on user plugins via duck-typing, so existing Rolldown plugins continue to work unchanged. A new TsdownPlugin interface, TsdownConfigEnv interface, and flattenPlugins helper are exported from tsdown/plugins.

Linked Issues

Additional context

  • Plugins injected via fromVite participate in tsdownConfigResolved but not tsdownConfig (they are loaded after the dispatch).
  • Plugins are snapshotted before tsdownConfig dispatch so plugins added by a hook do not re-trigger themselves (matches Vite semantics, prevents infinite recursion).
  • mergeConfig replaces arrays — to append plugins from tsdownConfig, mutate config.plugins in place.
  • 15 new unit tests in src/features/plugin.test.ts cover mutation, partial-return merge, env shape, plugin order, async, dual-format firing, ordering guarantee (tsdownConfig finishes before tsdownConfigResolved), and flattenPlugins edge cases.

Introduce two tsdown-specific per-plugin lifecycle hooks modeled on Vite's
`config` and `configResolved`:

- `tsdownConfig(config, env)` — called before the user config is resolved.
  May mutate in place or return a partial `UserConfig` to be deep-merged.
- `tsdownConfigResolved(resolvedConfig)` — read-only notification fired once
  per produced `ResolvedConfig` (per output format).

Both hooks are detected on user plugins via duck-typing, so existing
Rolldown plugins continue to work unchanged. A `TsdownPlugin` interface,
`TsdownConfigEnv` interface, and `flattenPlugins` helper are exported
from `tsdown/plugins`.
@netlify
Copy link
Copy Markdown

netlify bot commented Apr 16, 2026

Deploy Preview for tsdown-main ready!

Name Link
🔨 Latest commit 54caed5
🔍 Latest deploy log https://app.netlify.com/projects/tsdown-main/deploys/69e0974d9d96c90008f63ac5
😎 Deploy Preview https://deploy-preview-918--tsdown-main.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 16, 2026

Open in StackBlitz

tsdown

pnpm add https://pkg.pr.new/tsdown@918 -D
npm i https://pkg.pr.new/tsdown@918 -D
yarn add https://pkg.pr.new/tsdown@918.tgz -D

create-tsdown

pnpm add https://pkg.pr.new/create-tsdown@918 -D
npm i https://pkg.pr.new/create-tsdown@918 -D
yarn add https://pkg.pr.new/create-tsdown@918.tgz -D

@tsdown/css

pnpm add https://pkg.pr.new/@tsdown/css@918 -D
npm i https://pkg.pr.new/@tsdown/css@918 -D
yarn add https://pkg.pr.new/@tsdown/css@918.tgz -D

@tsdown/exe

pnpm add https://pkg.pr.new/@tsdown/exe@918 -D
npm i https://pkg.pr.new/@tsdown/exe@918 -D
yarn add https://pkg.pr.new/@tsdown/exe@918.tgz -D

tsdown-migrate

pnpm add https://pkg.pr.new/tsdown-migrate@918 -D
npm i https://pkg.pr.new/tsdown-migrate@918 -D
yarn add https://pkg.pr.new/tsdown-migrate@918.tgz -D

commit: 54caed5

sxzz added 3 commits April 16, 2026 16:42
`watch` and `cwd` are already reachable via the first `config` argument
passed to `tsdownConfig`, so keeping them in env duplicates data and risks
going stale. Drop both — `inlineConfig` remains because it is the only
piece of context that cannot be derived from `UserConfig`.
The env object only wrapped a single `inlineConfig` field, so pass the
`InlineConfig` directly as the second argument instead. Drops the
`TsdownConfigEnv` interface and its re-exports.
@sxzz sxzz force-pushed the sxzz/tsdown-config-hooks branch from f9ebb82 to 75601ed Compare April 16, 2026 07:52
Mirrors Rolldown's `RolldownPluginOption` but with `TsdownPlugin` as the
atom, so that `UserConfig.plugins` entries get proper type-checking for
the new `tsdownConfig` / `tsdownConfigResolved` hooks.
@sxzz sxzz force-pushed the sxzz/tsdown-config-hooks branch from 75601ed to a31dbe2 Compare April 16, 2026 07:52
@sxzz sxzz merged commit 665e5ac into main Apr 16, 2026
15 checks passed
@sxzz sxzz deleted the sxzz/tsdown-config-hooks branch April 16, 2026 08:02
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 this pull request may close these issues.

1 participant