node icon indicating copy to clipboard operation
node copied to clipboard

--watch should monitor replaced files

Open mbrevda opened this issue 1 year ago • 3 comments

What is the problem this feature will solve?

Currently, --watch watches an inode and not necessarily what the user might consider a "file". This can cause confusion on systems that write to disk by deleting the old file and then creating a new one.

For example, when using Docker Compose's watch mode, the watched file is first deleted and when a new file is created. Node currently fails to restart on file changes, as node is still watching the inode of the deleted file, and doesn't react to the new file being created.

What is the feature you are proposing to solve the problem?

While this behavior makes sense for the lower-level and more "raw" fs.watch(), perhaps the more general --watch behavior can be expanded to be smarter about detecting replaced files. Alternatively, a new flag can be introduced with this behavior.

What alternatives have you considered?

Other alternatives require using one of the different file watcher libs. That seems like a step down from the otherwise awesome native watch feature.

Docker Compose Issue: [BUG] Compose Watch With “node –watch” Only Reloads First Time Docker Issue: node --watch doesn't work well within a container

mbrevda avatar Jan 31 '24 17:01 mbrevda

@MoLow

benjamingr avatar Feb 02 '24 13:02 benjamingr

IIUC the underlying fix for this would probably be in libuv.

MoLow avatar Feb 04 '24 10:02 MoLow

Any ideas on where and libuv apis one can look to modify to implement this would be great to know! giving a shot to investigating this

debadree25 avatar Feb 05 '24 17:02 debadree25

Any updates on this?

mstaicu avatar Jul 23 '24 19:07 mstaicu

As a temporary solution, I use docker compose action: sync+restart instead of action: sync.

ruscon avatar Aug 13 '24 16:08 ruscon