1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

Fixes #1803 -- use fs.watch instead of fs.watchFile ... more of a PITA, but hey.

This commit is contained in:
Jeremy Ashkenas 2011-11-08 16:13:45 -05:00
parent 78491b3a58
commit d592d2c9cb
2 changed files with 29 additions and 16 deletions

View file

@ -196,16 +196,22 @@
};
watch = function(source, base) {
return fs.watchFile(source, {
persistent: true,
interval: 500
}, function(curr, prev) {
if (curr.size === prev.size && curr.mtime.getTime() === prev.mtime.getTime()) {
return;
}
return fs.readFile(source, function(err, code) {
if (err) throw err;
return compileScript(source, code.toString(), base);
return fs.stat(source, function(err, prevStats) {
if (err) throw err;
return fs.watch(source, function(event) {
if (event === 'change') {
return fs.stat(source, function(err, stats) {
if (err) throw err;
if (stats.size === prevStats.size && stats.mtime.getTime() === prevStats.mtime.getTime()) {
return;
}
prevStats = stats;
return fs.readFile(source, function(err, code) {
if (err) throw err;
return compileScript(source, code.toString(), base);
});
});
}
});
});
};