broccolijs / broccoli

Browser compilation library ā€“ an asset pipeline for applications that run in the browser
https://broccoli.build
MIT License
3.33k stars 217 forks source link

Watcher reporting (in)correct file names when saving in IntelliJ & co. #484

Open vlascik opened 3 years ago

vlascik commented 3 years ago

So, IntelliJ / WebStorm / PHPStorm family of IDEs have an option in Settings -> Appearance & Behavior -> System Settings -> Back up files before saving. What it does is to save the edited file as <filename.ext>~, filename with a tilde appended to the end before saving to the original.

Sound innocuous enough, but this creates a problem with broccoli / ember-cli on rebuilds - broccoli watcher notices this change first, reports the changed file as e.g. broccoli:watcherAdapter change P:\Project\app/components\test1\template.hbs~ to the system, and "swallows" the consecutive change to the original file.

This is an issue for ember-cli addons that match the file extensions to decide if they should act on the file, e.g. https://github.com/lifeart/ember-ast-hot-load, probably also https://github.com/typed-ember/ember-cli-typescript, maybe also others.

E.g. https://github.com/lifeart/ember-ast-hot-load/blob/e006fad067e7bf818db0b498b4a3fd6ae7f337e6/lib/hot-reloader.js#L6 matches for js/ts/hbs extensions, but gets js~/ts~/hbs~ instead, and fails.

Now, this is definitely an edge case, but given how easy to miss it is and how used IntelliJ IDEs are (#ā 1 or #ā 2 spot along VS Code), maybe it deserves some attention - either as a fix/special case in watcher adapter, or at least a mention of a workaround (disabling the IntelliJ back up setting) in documentation?

NullVoxPopuli commented 3 years ago

Vim has a similar issue by default. And since this is a problem with all file watching systems in js -- even with webpack, parcel, etc (Last I used them anyway), the solution, for me, was to move the temp files to a different directory.

In my vim config, I have the ability to do this:

set backupdir=~/.local/share/nvim/_backup/    " where to put backup files.
set directory=~/.local/share/nvim/_temp/      " where to put swap files.

So now all my editor specific temp files can't affect any project I'm, regardless of what tools I'm using! šŸŽ‰

Maybe the webstorm family of IDEs has a similar option?


Though, a more robust fix would be to find all ecosystem plugins that do file watching and add a $ to their regexes so that the .swp, or in your case, ~ are ignored.

But if your editor has a way to not pollute your project, that'd be a quicker fix