Skip to content

"tsc --project tsconfig.json --incremental" doesn't clean files from output folder. #36648

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
trusktr opened this issue Feb 5, 2020 · 7 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@trusktr
Copy link
Contributor

trusktr commented Feb 5, 2020

TypeScript Version: 3.7.5

Search Terms:

tsc incremental doesn't clean old files

Code

N/A

Expected behavior:

When, for example, refactoring by renaming a file (and VS Code updates all import statements, etc), then the outputDir should not contain the old file.

Actual behavior:

The output directory contains old unused files.

Prior to trying incremental builds (today for the first time) I was simply doing rm -rf dist/ to "clean" it first. This doesn't work with incremental builds (#30602).

I tried running tsc --build --clean and tsc --build ./tsconfig.json --clean but those don't do anything, old files still remain in the output folder.

Note, I have a single tsconfig.json at the root of my project, and compile all my source code into a single output directory all at once with a single tsc command. I'm not "composing projects".

Playground Link:

N/A

Related Issues:

@sheetalkamat
Copy link
Member

tsc --build --clean will only clean the files that are the outputs from current program so if you changed the name of the file or there exists some old file that's not part of the project' its output wont be deleted. For now this is by design and we do not track files that aren't part of compilation

@RyanCavanaugh RyanCavanaugh added the Question An issue which isn't directly actionable in code label Feb 6, 2020
@typescript-bot
Copy link
Collaborator

This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow.

@leotm
Copy link

leotm commented Mar 22, 2020

It's because of VS Code's integrated Git support.

A right-click Rename does a git mv (git rm --cached + mv + git add).

Our TypeScript compiler only sees working directory changes, i.e. mv changes in our outDir, whereas git add is where Git will automatically detect the move/rename.

Both being by Microsoft, it would be nice to see relevant Git support in our compiler presumably before looking at other VCS's.

@trusktr
Copy link
Contributor Author

trusktr commented Aug 4, 2020

For now this is by design and we do not track files that aren't part of compilation

Makes sense, and this makes it possible to output JS and declaration files as siblings to the input TS files, which is a valid use case.

Maybe there can be an option for it though? f.e. cleanNonOutputFilesFromProjectOutput: true or some descriptive name like that.

@croraf
Copy link

croraf commented Sep 13, 2020

This happens not only in --incremental mode.

@trusktr
Copy link
Contributor Author

trusktr commented Nov 3, 2020

@sheetalkamat I suppose someone somewhere if going to accidentally publish files they didn't mean to publish.

@aweebit
Copy link

aweebit commented Feb 27, 2025

@sheetalkamat @RyanCavanaugh can't the .tsbuildinfo file be utilized to only delete output files corresponding to the source files from the previous build that are no longer present? Seems like a pretty reasonable and straightforward use of .tsbuildinfo.

Not having this automatic cleanup has at least two pretty bad implications:

It looks like using a third-party tool like Google's Wireit (see its dedicated TypeScript recipe) is right now the only viable way to avoid these problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

7 participants