When watching failed lookups, watch packageDir if its a symlink otherwise the path we use to watch by sheetalkamat · Pull Request #58139 · microsoft/TypeScript (original) (raw)
In mono repo scenarios the packages are linked using symlink.
So when trying to resolve package1
from package2
in the test we look for locations like: /home/src/projects/project/node_modules/package1/dist/index.d.ts
As a result when package1
fails to resolve, we want to watch if this path will exists.
Before this PR, we would be watching /home/src/projects/project/node_modules
as its a node_modules
folder and we dont want to be watching too many packages or folders. This results in issues because /home/src/projects/project/node_modules/package1
is a symlink and any changes to the target are not percolated to the watcher we create. So without this PR we would not see the changes and miss the package build and report errors about package1
not found and never be able to resolve that unless offcourse if you start fresh by restarting tsserver
Now when we calculate dir to watch, we also find the packageDir
if this happens to be symlink, we will watch it otherwise we will watch the node_modules
like we use to watch before.
Other change needed for this to work on linux was that when we are watching this symlink dir, we need to ensure we are watching the target recursively as that is the expectation for native watchers that support symlink watching.
We already had test case which didnt update the diagnostics on tsserver when paths
was not used and with my other prototype changes to treat file create and delete as change and retain things more, it becomes more evident and those tests just start to fail. So this is cruicial fix for that change to go in as well
Fixes #55450