microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.95k stars 12.48k forks source link

tsc --watch should show file that triggered recompile #7211

Closed MattijsKneppers closed 6 years ago

MattijsKneppers commented 8 years ago

I am trying to find out why the watch task keeps recompiling whenever I bring the window of my git client in focus (my first guess was that .git/index.lock triggered it, it is the only file that fswatch points out as being changed. But it is located higher in the folder hierarchy than the folder that tsc is watching, so I am still puzzled..).

To debug something like this it would be very useful if the watch task would print the file name (perhaps only the first if multiple files changed) of the file that triggered the recompile.

TypeScript Version:

Version 1.8.0-dev.20151204

mhegazy commented 8 years ago

consider using --listFiles to identify the files the compiler is pulling in.

Also where is your tsconfig.json? how can we repro this locally?

MattijsKneppers commented 8 years ago

tsconfig.json is located in the root of the folder that tsc is watching:

the hierarchy looks like this:

repo root
 |_ .git (contains index.lock)
 |_ source
   |_ client
   |_ server
     |_ tsconfig.json
 |_ build

tsc is watching the server folder.

I realize this is not enough to go on, as soon as I find the time to create an example folder structure and test if the issue is reproducible on another system I'll create a new issue.

In the mean time a feature that prints the file that triggered the recompile seems a useful addition.

mhegazy commented 8 years ago

We have changed the implementation of tsc --watch since this issue was filed. we believe it is fixed now. can you please give typescript@next a try and reopen if you are still experiencing the issue.

laurence-myers commented 7 years ago

Looks like this is still not supported by "tsc --watch" or "--listFiles".

Steps to reproduce:

TSC will list all filles: first.ts, second.ts, and third.ts. There does not seem to be a way to get it to only list first.ts, i.e. the file that was changed.

(Sorry, this example might not be comprehensive, it might need actual exports & code in each module.)

weichensw commented 6 years ago

-w still doesn't list which file triggers the recompilation in 2.8.1. As @laurence-myers mentioned, --listFiles list all files instead of just the changed files.

weichensw commented 6 years ago

@mhegazy could you re-open this issue?

natew commented 6 years ago

Would appreciate this, running into issue where for some reason packages keep getting triggered.

trungtin commented 6 years ago

For me, it even recompiles on staging an unrelated file with git. For example, if I modified yarn.lock, it won't recompiles. But if I stage yarn.lock, it will.

sheetalkamat commented 6 years ago

You can run tsc --watch --diagnostics or tsc --watch --extendedDiagnostics and it will let you know which directoryWatcher/file watcher is being invoked. Note that not all triggers lead to recompilation.

weichensw commented 6 years ago

@sheetalkamat thanks for the info. In 2.9.2, --diagnostics doesn't show which file are updated thus triggered the watch. --extendedDiagnostics does, it is very verbose though.