Skip to content

fix(config): clean per-format outDir when using object format#920

Open
Kyujenius wants to merge 1 commit intorolldown:mainfrom
Kyujenius:fix/clean-per-format-outdir
Open

fix(config): clean per-format outDir when using object format#920
Kyujenius wants to merge 1 commit intorolldown:mainfrom
Kyujenius:fix/clean-per-format-outdir

Conversation

@Kyujenius
Copy link
Copy Markdown

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

Description

With format: { esm: { outDir: 'esm' }, cjs: { outDir: 'cjs' } } and clean: true, the per-format directories are never cleaned. resolveClean runs once against the root outDir at src/config/options.ts:150 and the result is shared across every resolved config via ...config — per-format outDir overrides applied later in the map at L346-358 never make it into that array, so cleanOutDir only globs the root directory.

Deferring resolveClean into the per-format loop gives each config its own clean array derived from that format's effective outDir. A user-supplied per-format clean (overrides?.clean) wins over the top-level one, and overrides.outDir is resolved to an absolute path in the same place to keep override semantics consistent with the root outDir.

Linked Issues

fixes: #843

Additional context

The new test in tests/clean.test.ts fails without the fix and passes with it — it checks that stale files in each per-format outDir get removed and that the build still writes new output into the same directories. All existing clean tests still pass; if you don't use per-format outDir overrides, nothing changes — each resolved config still gets resolveClean(true, outDir, cwd) against the shared root outDir and produces the same [slash(outDir)] as before.

validateSea never reads clean, so its parameter type is narrowed to Omit<ResolvedConfig, 'clean' | 'format'>. This keeps the intermediate config object type accurate once clean moves out.

@netlify
Copy link
Copy Markdown

netlify bot commented Apr 17, 2026

Deploy Preview for tsdown-main ready!

Name Link
🔨 Latest commit 8055d3a
🔍 Latest deploy log https://app.netlify.com/projects/tsdown-main/deploys/69e255776975c30008e664d0
😎 Deploy Preview https://deploy-preview-920--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 17, 2026

Open in StackBlitz

tsdown

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

create-tsdown

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

@tsdown/css

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

@tsdown/exe

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

tsdown-migrate

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

commit: 8055d3a

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.

clean is not respected on format.outDir

1 participant