Skip to content

fix(clean): resolve clean patterns against the config cwd - #1080

Open
giaBaoJS wants to merge 1 commit into
rolldown:mainfrom
giaBaoJS:fix/clean-config-cwd
Open

giaBaoJS wants to merge 1 commit into
rolldown:mainfrom
giaBaoJS:fix/clean-config-cwd

Conversation

@giaBaoJS

@giaBaoJS giaBaoJS commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

AI usage

  • No AI was used in this PR.
  • AI was used: Claude Code + Opus 5
    • I have carefully reviewed the AI-generated content myself.

Description

cleanOutDir globs the clean patterns with cwd: config.cwd (src/features/clean.ts:28-33), but resolveClean validates them with path.resolve(item), which resolves against process.cwd() (src/features/clean.ts:66). The two ends of the same option disagree about what the patterns are relative to.

cwd defaults to the package directory in workspace mode (src/config/types.ts:471-477), so config.cwd !== process.cwd() is a normal state, and in it the guard can never match. clean: ['.'] in a package config stops throwing and globs to every file under that package, each of which goes to fsRemove. The new test reproduces it: without the fix it fails with [UNRESOLVED_ENTRY] Cannot resolve entry module index.ts, because the entry was deleted before the build read it.

The mismatch fires the other way too. With cwd at <root>/pkg and clean: ['pkg'], path.resolve('pkg') equals the cwd, so the build aborts with "Cannot clean the current working directory" even though that pattern means <root>/pkg/pkg once cleanOutDir globs it.

The fix resolves the pattern the way cleanOutDir will, matching the exe.outDir line just above it.

Linked Issues

None open describes this.

Additional context

Per-format overrides have the same hole and I left them alone. format: { es: { clean: ['.'] } } replaces the resolved array at src/config/options.ts:311-320 after resolveClean has already run, so the guard is skipped even when cwd === process.cwd(); I checked, and index.ts is deleted. #920 is already moving resolveClean into that loop and passes cwd, so it inherits this fix unchanged.

`cleanOutDir` globs `clean` with `cwd: config.cwd`, but the guard that
rejects a pattern pointing at the working directory resolved it against
`process.cwd()`. Workspace mode sets `cwd` to the package directory, so
the two differ and the guard stops matching: `clean: ['.']` in a package
config deletes that package's sources instead of throwing.

The same mismatch rejects a pattern that only resolves to the cwd when
read from `process.cwd()`, aborting a build that asked for nothing of
the kind.
@netlify

netlify Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for tsdown-main ready!

Name Link
🔨 Latest commit dcfff3f
🔍 Latest deploy log https://app.netlify.com/projects/tsdown-main/deploys/6aafa07e781e0a00087d7d92
😎 Deploy Preview https://deploy-preview-1080--tsdown-main.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

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

@pkg-pr-new

pkg-pr-new Bot commented Sep 20, 2026

Copy link
Copy Markdown

Open in StackBlitz

tsdown

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

create-tsdown

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

@tsdown/css

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

@tsdown/exe

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

tsdown-migrate

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

commit: dcfff3f

This branch has not been deployed

No deployments
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