Skip to content
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

tsc --watch via directory-level fsevents not working on macOS 14.4 #57792

Closed
nfarina opened this issue Mar 15, 2024 · 4 comments Β· Fixed by #57938
Closed

tsc --watch via directory-level fsevents not working on macOS 14.4 #57792

nfarina opened this issue Mar 15, 2024 · 4 comments Β· Fixed by #57938
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@nfarina
Copy link

nfarina commented Mar 15, 2024

πŸ”Ž Search Terms

fsevents tsc watch macOS 14.4 not watching working detecting changes found 0 errors

πŸ•— Version & Regression Information

  • This changed between versions 5.3.3 and 5.4.2 (also occurs in 5.5 dev latest)

⏯ Playground Link

https://gist.github.com/nfarina/d5538d16343830e41c9f3e031a65237e

πŸ’» Code

Reproducible with just this package.json and an arbitrary test.ts file (see Gist link):

{
  "name": "tsc-test",
  "version": "1.0.0",
  "description": "tsc watch problem repro",
  "license": "ISC",
  "scripts": {
    "start": "tsc test.ts --watch"
  },
  "dependencies": {
    "typescript": "^5.4.2"
  }
}

πŸ™ Actual behavior

This is confusing to me because it seems like many people would be experiencing this right now, but I have tested quite a lot and, for me, TypeScript 5.4.2 broke folder watching completely on my system. (This is a brand new M3 MacBook Air running macOS 14.4).

This works:

"watchFile": "useFsEvents"

And this doesn't:

"watchFile": "useFsEventsOnParentDirectory"

On TypeScript 5.3.3 and below, both work as expected.

πŸ™‚ Expected behavior

tsc --watch should observe file changes using fsevents folder watching

Additional information about the issue

I did some digging in the tsc codebase to find where fsevents is being used but was unsuccessful - I'm happy to investigate further if anyone can give me a lead.

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Mar 15, 2024
@NMinhNguyen
Copy link
Contributor

Just to add an observation: I think this issue is Sonoma specific as watch seems to work on 13.6.4 (Ventura).

@llllvvuu
Copy link

llllvvuu commented Mar 21, 2024

When testing this issue, make sure you don't use Vim. Creating/deleting files seems to trigger the file watcher, so it's possible for Vim users to not notice this issue (possibly due to swap files) while VSCode users do.

Consistent repro can be done like:

tsc --watch --watchFile usefseventsonparentdirectory
echo "console.log('Hello world!')" > main.ts
cat main.js
echo "console.log('Hello world 2!')" > main.ts
cat main.js

@llllvvuu
Copy link

llllvvuu commented Mar 21, 2024

I found the bisect:

git checkout dc113f8170 // latest `main` as of this post
git revert e40730f
npm run build && npm run build:compiler

I suspect the issue is that the modifiedTime is the modified time of the directory, not the file. At least when I console.log it and compare with stat this seems to be the case, and fileOrDirectory is printing as the directory and only relativeFileName has the file.

sheetalkamat added a commit that referenced this issue Mar 25, 2024
Directories generate change event in multiple scenarios and should not filter events based on modified time
Fixes #57792
@sheetalkamat sheetalkamat added Bug A bug in TypeScript Fix Available A PR has been opened for this issue and removed Needs Investigation This issue needs a team member to investigate its status. labels Mar 25, 2024
sheetalkamat added a commit that referenced this issue Mar 25, 2024
Directories generate change event in multiple scenarios and should not filter events based on modified time
Fixes #57792
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 5.4.32 milestone Mar 28, 2024
@o-alexandrov
Copy link

For anyone (like me just now) who stumbles on this, the fix hasn't been released on npm yet in non-next tags.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
7 participants