You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(clean): skip paths outside the project root - #1124
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.
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
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.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AI usage
Description
cleancan remove paths outside the project root. Acleanpattern with../, an absolute path, anoutDiroutside the root (whichclean: truecleans by default), or a path reached through a symbolic link is removed withrm -rf. The existing guard inresolveCleanblocks only the current working directory itself.This PR extends that guard:
cleanOutDirnow skips any matched path whose location is outsideconfig.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
outDiroutside 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:
outDiris outside the project root, tsdown no longer empties it before the build.outDirornode_modulesis 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.