seek-oss / css-modules-typescript-loader

Webpack loader to create TypeScript declarations for CSS Modules
MIT License
198 stars 27 forks source link

Using this alongside Cypress can cause an infinite loop due to Cypresses file watcher #5

Closed silbinarywolf closed 5 years ago

silbinarywolf commented 5 years ago

The problem Cypress is a testing tool that allows you to interactively develop your application. I've hit an issue where because this module always writes type definition files, regardless of whether it changed or not, it will trigger Cypresses file watcher and get caught in an infinite loop.

The solution There are one of two solutions that could be put into place.

1) This module reads/checks for an existing file and only writes the file if it's actually changed. In my opinion, this module should be reading the file first anyway to ensure that it is indeed a generated file before trying to write over it.

2) Cypress adds the ability to ignore certain files in the watcher (unless there's a config I've missed somewhere) - Issue raised here: https://github.com/cypress-io/cypress/issues/3098

I personally prefer option 1 because I feel that it'll help keep this module "just working" alongside others. Happy to do a PR as well if this solution sounds reasonable.

P.S. Thank you so much for open-sourcing this. In a world full of half-baked open-source, you guys seem to deliver tools that solve the problem adequately and improve developer happiness, so thank you!

markdalgleish commented 5 years ago

Thanks so much for your comments, it's very much appreciated! 😄

Also, thanks for the clear issue report. Checking the file on disk before writing definitely makes sense. We're happy to fix this ourselves—should hopefully not take too long.