TypeStrong / fork-ts-checker-webpack-plugin

Webpack plugin that runs typescript type checker on a separate process.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

High CPU usage with modern Typescript versions and 4.x versions of this plugin

francisu opened this issue · comments

Current behavior

The Typescript file polling does not respect the watchOptions and defaults to a 1/4 second polling for all files.

Expected behavior

The Typescript file polling respects the watch options in the tsconfig.json file

Steps to reproduce the issue

Run anything with the versions specified below; it will peg the CPU

Issue reproduction repository

Environment

  • fork-ts-checker-webpack-plugin: 4.2.1
  • typescript: 4.3.5
  • eslint: 7.32.0
  • webpack: 4.44.2
  • os: Mac OS 11.5.1

The fix is in CompilerHost. The watchFile and watchDirectory methods have a 4th parameter which is the options, which needs to be passed back to the tsHost.watchFile/watchDirectory.

Because the options parameter is missing, the tsHost watchFile/watchDirectory just assume it should do polling, with disastrous results.

This must have changed in a Typescript version after 3.0 (perhaps 3.8, when the watchOptions where added: https://www.typescriptlang.org/docs/handbook/configuring-watch.html)

Unfortunately the source change to support both versions of Typescript is not that straightforward, since the 3.0.1 definitions do not account for this extra parameter.

As a side node, a peerDependency should be added to the package.json to specify the required typescript version (this helps yarn 2 check things more carefully).

It would be nice if you could do a fix to the 4.x line for this, as that's the only version that's compatible with the current (4.0.3) version of CRA, which is very widely used.

See: facebook/create-react-app#11336

Currently, I'm on vacations and will be back in 3 weeks. Feel free to open a PR to fix that - I can approve and merge fix from my phone. You would have to checkout the latest 4.x tag and use it as a base for the fix :)

Sorry, I forgot about this :/
The CRA team updated the plugin version 6. Because of that, I'm closing this issue.