File watcher package?


#1

Is there’s a package which allows file watchers to be easily created?

For instance, I’d like to write a file watcher that detects a change to a LESS file and then runs a script to compile said less file (and others) to the target CSS output.

I realize this is frequently better to do at build-time (rather than at dev time) but I’m not able to make that change at this point to the package.


#2

The ‘Markdown Preview’ package does that (watch for file changes), it uses pathwatcher


#3

Awesome – thx @AbeEstrada


#4

Hi, I’d like to ask if it’s better to use the pathwatcher package or the native fs.watch() of Node? Do you’ve any recommendations on that (wrt. performance, reliability, …)?


#5

#6

Thanks, that answers my question :slight_smile:


#7

I’m using now the pathwatcher package in my project-view package and under Linux everything works as expected. But now I’ve noticed that the installation of my package fails now under Windows due to a node-gyp failure (see below).
Why doesn’t this error gets thrown when installing the tree-view on Windows? Could it be that with the Atom a pre-build version of this package gets shipped? If that’s the case and you need some Windows SDK installed in order to use my package then sadly I’ve to remove the pathwatcher again and replace it against the native fs.watch. Any advices?

@zcbenz

> runas@3.1.1 install C:\Users\Subesokun\AppData\Local\Temp\apm-install-dir-1151113-6412-1joutzg\node_modules\project-view\node_modules\pathwatcher\node_modules\runas
> node-gyp rebuild


C:\Users\Subesokun\AppData\Local\Temp\apm-install-dir-1151113-6412-1joutzg\node_modules\project-view\node_modules\pathwatcher\node_modules\runas>if not defined npm_config_node_gyp (node "C:\Users\Subesokun\AppData\Local\atom\app-1.3.0-beta0\resources\app\apm\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node  rebuild )

gypnpm ERR! Windows_NT 6.2.9200
npm ERR! argv "C:\\Users\\Subesokun\\AppData\\Local\\atom\\app-1.3.0-beta0\\resources\\app\\apm\\bin\\node.exe" "C:\\Users\\Subesokun\\AppData\\Local\\atom\\app-1.3.0-beta0\\resources\\app\\apm\\node_modules\\npm\\bin\\npm-cli.js" "--globalconfig" "C:\\Users\\Subesokun\\.atom\\.apm\\.apmrc" "--userconfig" "C:\\Users\\Subesokun\\.atom\\.apmrc" "install" "C:\\Users\\Subesokun\\AppData\\Local\\Temp\\d-1151113-6412-wlp93s\\package.tgz" "--target=0.34.3" "--arch=ia32"
npm ERR! node v0.10.40
npm ERR! npm  v2.13.3
npm ERR! code ELIFECYCLE

npm ERR! runas@3.1.1 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the runas@3.1.1 install script 'node-gyp rebuild'.
npm ERR! This is most likely a problem with the runas package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls runas
npm ERR! There is likely additional logging output above.


#8

Ah. It’s runas again. I’ve had several npm modules fail with the runas error. I posted an issue on the runas site and I don’t think it has been resolved.


#9

@mark_hahn Thanks for the feeback. To be on the safe side I’ve removed pathwatch and replaced it for the time being with fs.watch.


#10

Sorry to open this up again, but I stepped into a similar issue with pathwatcher. I had a quick look in the Discussion pages, and I did not get very far.

Apparently, I can use pathwatcher within the Atom Dev console as other inbox modules:

var pw = require('pathwatcher');
pw.watch('/home/yolo/file', function(event, path) {
  // do the magic here, this actually works
});

I can also install patwatcher (version 6.5.0) with npm and everything runs smoothly.

I get trouble when I try to require it within an Atom package. Every time I include it, I get this silent and deadly

Cannot find module 'pathwatcher'

I’m running Atom version 1.5.4 from Arch Linux 4.3.3-3 (no success with the latest update, too many bugs, so I’ll stick with 1.5.4 for a while I guess).

Anyone had the same issues about pathwatcher? I’ll fix if by using the regular fs watcher, but it would be nice to use pathwatcher instead.

Cheers guys!