mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Handling all ENOENTs potentially thrown by fs.watch (hopefully)
This commit is contained in:
@@ -188,7 +188,7 @@
|
||||
};
|
||||
|
||||
watch = function(source, base) {
|
||||
var callback, compile, prevStats, watcher;
|
||||
var callback, compile, prevStats, watchErr, watcher;
|
||||
prevStats = null;
|
||||
compile = function() {
|
||||
return fs.stat(source, function(err, stats) {
|
||||
@@ -203,41 +203,81 @@
|
||||
});
|
||||
});
|
||||
};
|
||||
return watcher = fs.watch(source, callback = function(event) {
|
||||
if (event === 'change') {
|
||||
return compile();
|
||||
} else if (event === 'rename') {
|
||||
watcher.close();
|
||||
return setTimeout(function() {
|
||||
return path.exists(source, function(exists) {
|
||||
if (exists) {
|
||||
compile();
|
||||
return watcher = fs.watch(source, callback);
|
||||
} else {
|
||||
removeSource(source, base, true);
|
||||
return compileJoin();
|
||||
}
|
||||
});
|
||||
}, 250);
|
||||
watchErr = function(e) {
|
||||
if (e.code === 'ENOENT') {
|
||||
removeSource(source, base, true);
|
||||
return compileJoin();
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
};
|
||||
try {
|
||||
return watcher = fs.watch(source, callback = function(event) {
|
||||
if (event === 'change') {
|
||||
return compile();
|
||||
} else if (event === 'rename') {
|
||||
watcher.close();
|
||||
return setTimeout(function() {
|
||||
compile();
|
||||
try {
|
||||
return watcher = fs.watch(source, callback);
|
||||
} catch (e) {
|
||||
return watchErr(e);
|
||||
}
|
||||
}, 250);
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
return watchErr(e);
|
||||
}
|
||||
};
|
||||
|
||||
watchDir = function(source, base) {
|
||||
var watcher;
|
||||
return watcher = fs.watch(source, function() {
|
||||
return path.exists(source, function(exists) {
|
||||
var file, toRemove, _i, _len;
|
||||
if (exists) {
|
||||
return fs.readdir(source, function(err, files) {
|
||||
var file, _i, _len, _results;
|
||||
if (err) throw err;
|
||||
var watchErr, watcher;
|
||||
watchErr = function(e) {
|
||||
var file, toRemove, _i, _len;
|
||||
toRemove = (function() {
|
||||
var _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = sources.length; _i < _len; _i++) {
|
||||
file = sources[_i];
|
||||
if (file.indexOf(source) >= 0) _results.push(file);
|
||||
}
|
||||
return _results;
|
||||
})();
|
||||
for (_i = 0, _len = toRemove.length; _i < _len; _i++) {
|
||||
file = toRemove[_i];
|
||||
removeSource(file, base, true);
|
||||
}
|
||||
return compileJoin();
|
||||
};
|
||||
try {
|
||||
return watcher = fs.watch(source, function() {
|
||||
return fs.readdir(source, function(err, files) {
|
||||
var file, toRemove, _i, _j, _len, _len2, _results;
|
||||
if (err) {
|
||||
if (err.code !== 'ENOENT') throw err;
|
||||
toRemove = (function() {
|
||||
var _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = sources.length; _i < _len; _i++) {
|
||||
file = sources[_i];
|
||||
if (file.indexOf(source) >= 0) _results.push(file);
|
||||
}
|
||||
return _results;
|
||||
})();
|
||||
for (_i = 0, _len = toRemove.length; _i < _len; _i++) {
|
||||
file = toRemove[_i];
|
||||
removeSource(file, base, true);
|
||||
}
|
||||
return compileJoin();
|
||||
} else {
|
||||
files = files.map(function(file) {
|
||||
return path.join(source, file);
|
||||
});
|
||||
_results = [];
|
||||
for (_i = 0, _len = files.length; _i < _len; _i++) {
|
||||
file = files[_i];
|
||||
for (_j = 0, _len2 = files.length; _j < _len2; _j++) {
|
||||
file = files[_j];
|
||||
if (!(!notSources[file])) continue;
|
||||
if (sources.some(function(s) {
|
||||
return s.indexOf(file) >= 0;
|
||||
@@ -249,26 +289,12 @@
|
||||
_results.push(compilePath(file, false, base));
|
||||
}
|
||||
return _results;
|
||||
});
|
||||
} else {
|
||||
watcher.close();
|
||||
toRemove = (function() {
|
||||
var _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = sources.length; _i < _len; _i++) {
|
||||
file = sources[_i];
|
||||
if (file.indexOf(source) >= 0) _results.push(file);
|
||||
}
|
||||
return _results;
|
||||
})();
|
||||
for (_i = 0, _len = toRemove.length; _i < _len; _i++) {
|
||||
file = toRemove[_i];
|
||||
removeSource(file, base, true);
|
||||
}
|
||||
return compileJoin();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
} catch (e) {
|
||||
if (e.code !== 'ENOENT') throw e;
|
||||
}
|
||||
};
|
||||
|
||||
removeSource = function(source, base, removeJs) {
|
||||
|
||||
Reference in New Issue
Block a user