rizowski / eslint-watch

ESLint with simple watching capabilities
https://www.npmjs.com/package/eslint-watch
MIT License
193 stars 29 forks source link

Changing branches on git triggers dozens of concurrent `eslint` processes to be created #150

Closed Ameobea closed 5 years ago

Ameobea commented 5 years ago

Environment

Basic Description of the problem

Whenever operations that create many file changes such as a bit checkout or git pull occur while eslint-watch is running, eslint-watch triggers dozens of concurrent eslint processes to be created for what I assume is each of the individual file changes. If the --changed option is not specified, this has the effect of making the system close to unusable due to the high resource usage of the eslint processes.

How to reproduce it

  1. Run esw
  2. Run a command such as git checkout develop that introduces changes to many (50+, for example) files

Debug output:

...
  esw:events:watch Detected change: src/components/Forms/SignInEmail/SignInEmail.js +10ms
  esw:eslint Executing [ '--report-unused-disable-directives', '--color', '--ext', [ 'js', 'jsx' ], '--eslintrc', '--ignore', '--inline-config', '.' ] +0ms
  esw:events:watch Detected change: src/components/EntityPage/Inventory/InactiveProducts.jsx +12ms
  esw:eslint Executing [ '--report-unused-disable-directives', '--color', '--ext', [ 'js', 'jsx' ], '--eslintrc', '--ignore', '--inline-config', '.' ] +0ms
website (dcc00b85) »                                                                                                                                                                                                       ~/website 130 ↵
  esw:events:watch Detected change: src/components/EntityPage/Layout/SearchPageLayout.js +161ms
  esw:eslint Executing [ '--report-unused-disable-directives', '--color', '--ext', [ 'js', 'jsx' ], '--eslintrc', '--ignore', '--inline-config', '.' ] +0ms
  esw:events:watch Detected change: src/components/Export/DownloadList/DownloadList.jsx +13ms
  esw:eslint Executing [ '--report-unused-disable-directives', '--color', '--ext', [ 'js', 'jsx' ], '--eslintrc', '--ignore', '--inline-config', '.' ] +0ms
  esw:events:watch Detected change: src/components/EntityPage/EntityPage.jsx +12ms
  esw:eslint Executing [ '--report-unused-disable-directives', '--color', '--ext', [ 'js', 'jsx' ], '--eslintrc', '--ignore', '--inline-config', '.' ] +0ms
  esw:events:watch Detected change: src/components/Export/DownloadList/ExportTable.jsx +10ms
  esw:eslint Executing [ '--report-unused-disable-directives', '--color', '--ext', [ 'js', 'jsx' ], '--eslintrc', '--ignore', '--inline-config', '.' ] +0ms
...

In the case that the --changed option is not specified, file changes should be debounced. Just waiting ~50ms after a file change and watching for other file changes in that time period (resetting the timer after each one) and then only spawning the eslint process once they've all completed should solve this.

rizowski commented 5 years ago

@Ameobea Thanks for posting this. Seems to be related to: #145 . Although I believe this is a bigger issue. I think part of the issue is that since the watcher now executes a child_process of eslint executable and no longer uses Eslint's API, that ESW has started to take more resources than in previous versions.

Debounce will work for me for this case.

rizowski commented 5 years ago

156 will have debounce included. I'll try to get a release out this week.

rizowski commented 5 years ago

This should be fixed with v5.1.0