browserify / watchify

watch mode for browserify builds
Other
1.79k stars 181 forks source link

Support for atomic writes #272

Closed fgnass closed 9 years ago

fgnass commented 9 years ago

I have a dev-server that is watching bundles generated by watchify in order to live-reload the page. Since watchify's write operations are not atomic, I often end up with truncated files as the reload happens too early. Using https://github.com/npm/fs-write-stream-atomic in outpipe would solve this issue (much more elegantly than using delays, which is my current workaround). Would you consider this option if I sent you a PR?

zertosh commented 9 years ago

fs-write-stream-atomic seems to rely on using a temp file in the same directory as the output file. Watchify use to do this, and it caused lots of problems for users running other watchers (look through the issues). At one point, it also wrote out instead to the system tmp dir - and that caused issues for window users and users with output dirs in different partitions.

I like the tmp file in the same directory approach, but behind a flag like --atomic-save or something.

fgnass commented 9 years ago

Ah, good to know, I wasn't aware of that. I found #140 which mentions lineman. I assume it refers to http://linemanjs.com/ which apparently is based on Grunt and provides tasks to watch files. Like most tools it seems to watch only for certain file extensions so I guess that adding a ~ suffix to the dotfile (like vim does) could probably have solved that particular issue.

I'm just wondering if with this tweak atomic writes could be the default again and we could add a --non-atomic option instead?

zertosh commented 9 years ago

@fgnass try watchify@3.5.0, it now waits until there is some data to be written before it actually creates the output file – that should fix your problem.