microsoft / microsoft/TypeScript

Enable chokidar-based watch

Offen
#43,790 6 Kommentare 4 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Awaiting More Feedback Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

Suggestion

🔍 Search Terms

idle watch watcher cpu chokidar

✅ Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.
    Would actually further goal 10, cross-platform development

⭐ Suggestion

Please add one or more of these:

  • chokidar as a new option for tsconfig::watchOptions.watchFile and tsconfig::watchOptions.watchDirectory
  • chokidar as a new option for env::TSC_WATCHFILE and env::TSC_WATCHDIRECTORY
  • chokidar as default watcher – maybe dependent on whether chokidar is available in the project

💻 Use Cases

While working with create-react-app, I noticed that my machine tended to get quite loud. Investigating that, I found the reason to be surprisingly large CPU utilization. That, in turn, I could trace back to this issue:
https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/issues/236

The solution there was to switch TSC to fs.watch instead of fs.watchFile. That works for the most part. However, as @sheetalkamat points out in https://github.com/microsoft/TypeScript/issues/31048#issuecomment-495659901, that implementation is known to be problematic. Which is why it is not the default and won't be in the foreseeable future.

Prior discussions

https://github.com/microsoft/TypeScript/issues/31048 talks about the background to this request. There, @nicoburns already asked about this:

Would you consider switching to Chokidar? It's a battle tested solution used very widely throughout the Node ecosystem. We're in the process of switching to TypeScript at work, and the watch processes are taking ~45% cpu each on my 2015 MacBook Pro. As far as I am aware Node's built-in file watching capabilities are generally considered broken and not suitable for production use.

In response, @jasonwilliams pointed out that webpack had switched back to fs.watch, which might indicate that it had been fixed by now. Unfortunately, node v16 still has the same warnings, and webpack's switch seems to have been less thoroughly investigated than we would have desired: https://github.com/webpack/watchpack/issues/130

https://github.com/microsoft/TypeScript/issues/19762 and https://github.com/microsoft/TypeScript/issues/17506 also showed performance issues. https://github.com/microsoft/TypeScript/issues/19762 actually has the same resolution as https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/issues/236, and https://github.com/microsoft/TypeScript/issues/17506 seems to have prompted some intensive work.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Das Issue nennt keine spezifischen Dateien, Tests oder Einstiegspunkte. Beginne mit der Durchsicht der bestehenden Watch-Optionen von TypeScript und der verlinkten früheren Diskussionen und ermittle anschließend, ob chokidar eine Option oder ein Standard sein sollte und wie die Konfiguration funktionieren sollte; für den Abschluss wären ein abgestimmtes Design und ein festgelegter Implementierungsumfang erforderlich.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
node.js, typescript
Bereich
devtools
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.