Skip to content

fix(clean): skip paths outside the project root - #1124

Open
magurotuna wants to merge 3 commits into
rolldown:mainfrom
magurotuna:fix/clean-outside-cwd
Open

magurotuna wants to merge 3 commits into
rolldown:mainfrom
magurotuna:fix/clean-outside-cwd

Conversation

@magurotuna

Copy link
Copy Markdown

AI usage

  • No AI was used in this PR.
  • AI was used: Claude Code + Claude Opus 5.5 (code, tests, docs, PR description); reviewed with GPT-6.1 Sol
    • I have carefully reviewed the AI-generated content myself.

Description

clean can remove paths outside the project root. A clean pattern with ../, an absolute path, an outDir outside the root (which clean: true cleans by default), or a path reached through a symbolic link is removed with rm -rf. The existing guard in resolveClean blocks only the current working directory itself.

This PR extends that guard: cleanOutDir now skips any matched path whose location is outside config.cwd, and logs a warning that lists the skipped paths (first 5). The check uses the real path of each match's parent directory, so tsdown does not delete files through a symbolic link, and a symbolic link inside the root is still removed as a link.

This matches Vite's behavior, which does not empty an outDir outside the project root by default (docs, implementation).

Paths inside the project root are cleaned as before.

Linked Issues

None.

Additional context

This changes behavior in two cases:

  • If outDir is outside the project root, tsdown no longer empties it before the build.
  • If outDir or node_modules is a symbolic link to a directory outside the project root, tsdown skips its contents and logs a warning.

If you prefer an explicit opt-in for these cases (similar to Vite's emptyOutDir), I can add it.

Copilot AI balanced review requested due to automatic review settings November 8, 2026 06:04
@netlify

netlify Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for tsdown-main ready!

Name Link
🔨 Latest commit 9719516
🔍 Latest deploy log https://app.netlify.com/projects/tsdown-main/deploys/6af041f93e93716867536850
😎 Deploy Preview https://deploy-preview-1124--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 Nov 8, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

tsdown

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

create-tsdown

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

@tsdown/css

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

@tsdown/exe

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

tsdown-migrate

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

commit: 9719516

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Watch rebuild cleanup can still delete files outside the project root, and skipped-cleaning warnings bypass configured logging behavior.

2 open issues
What changed in this PR

This PR adds project-root containment checks to tsdown’s pre-build cleanup, protecting external paths while preserving cleanup inside the project.

Changes:

  • Check matched paths and their resolved parent directories, warning when cleanup is skipped.
  • Add regression tests for external paths, symlink handling, and directories beginning with ...
  • Document the cleanup boundary in configuration metadata and user guides.
File Description
tests/​clean.test.ts Adds cleanup boundary and symlink regression tests.
tests/​__snapshots__/​clean/​should-not-clean-paths-outside-the-project-root.snap.md Records build output for the external-path test.
src/​features/​clean.ts Adds containment checks and skipped-path warnings.
src/​config/​types.ts Documents the boundary on the clean option.
skills/​tsdown/​references/​option-cleaning.md Explains external-path and symlink cleanup behavior.
schema.json Updates generated cleanup option descriptions.
docs/​zh-CN/​options/​cleaning.md Adds the Chinese cleanup safety note.
docs/​options/​cleaning.md Adds the English cleanup safety note.

Review effort: Balanced

Comment thread src/features/clean.ts Resolved
Comment thread src/features/clean.ts Resolved
Use each config's logger for the warning about skipped paths, so that failOnWarn, suppressWarnings, and customLogger apply to it.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The documentation overstates symlink protection and needs clarification across the cited docs and comment because files reached through in-root symlinks can still be deleted.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Low severity Clarify that the deletion guard blocks symlinks leading outside the root

docs/​options/​cleaning.md:14

The guard allows deletion through a symlink when its parent resolves inside the project root, so the blanket guarantee is inaccurate. Qualify it to symlinks leading outside the root; files reached through in-root links can still be cleaned. Apply the same clarification in docs/zh-CN/options/cleaning.md:14, skills/tsdown/references/option-cleaning.md:62, and src/features/clean.ts:79–80.

2 resolved since last review

Review effort: Balanced

@magurotuna

Copy link
Copy Markdown
Author

Re the Copilot review (docs overstate the symlink protection): fixed in 9719516. The docs and the code comment now say that tsdown skips only symbolic links that point outside the project root. Files reached through a symbolic link that points inside the project root are cleaned as usual. The code does not change.

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.

2 participants