browserify / watchify

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

watchify - bad handling of file delete/move #136

Closed tugend closed 9 years ago

tugend commented 9 years ago

Hi, I use Watchify (not gulp-watchify) in a gulp file and I have observed the following behavior.

    If you add the file "goblins.cjsx" and in the existing compile tree add a 
    require("goblins") statement everything is okay and watchify do as expected.

    If you delete a file, "pixies.cjsx" on the other hand, you will NOT always get
    a commandline error for the sources that do reference the file - unless I 
    restart the script. The same goes for adding files in the case where existing references
    fails i.e. having a require('pixieland/pixies') and then after starting watchify adding the 
    pixies file.

    The same goes for moving files around, if you forget to change a reference,
    you may continue development while one or more files reference the old path and
    use the cached version of the file.

The behavior remain consistent regardless of whether I add a watcher on file deleted/rename/added to call rebundle when this happens. It seems that watchify does not notice not check whether the files are still there - so maybe this is a caching issue? I suppose this is not the intended behavior.

I am using Windows 8.1, Node v0.10.35 and Watchify 2.2.1.

-- Regards

zertosh commented 9 years ago

That's how the cache works. Only the file that changes gets invalidated and reprocessed - the rest are pulled from the cache. And only those files are that explicitly referenced by the build are monitored. So adding or deleting a file that nothing references doesn't do anything.

tugend commented 9 years ago

Considering how watchify is often used I would claim it practical if it supported add/remove of files in this intuitive manner. As far as I know (I may be mistaken), it would be entirely possible to monitor for files added or removed within a given folder - and respectively update the cache such that deleted files are invalidated in the cache and added files are added to the list of monitored files.

Regardless I appriciate your reply, thank you.

zertosh commented 9 years ago

Hey @tugend, I'm currently exploring a move to that model in https://github.com/substack/watchify/issues/210. The main issue right now, is figuring out what folder to watch exactly. Finding the lowest common dir for a "bundle" is actually kinda weird for these purposes because it's not a value you give browserify. You'd think that the most obvious choice would be the basedir, but you can still require files outside of it (even really "far" a away files like global modules). This is a tricky issue because whatever I end up implementing will surely make someone unhappy :(

tugend commented 9 years ago

I have not thought that, a very valid point! I.. am afraid I no concrete suggestions to solve the problem. =/ (#thinking hard)