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

Removing remaining ENOENT throws

This commit is contained in:
Trevor Burnham 2011-12-18 14:15:33 -05:00
parent dfc602159e
commit 988dedd08d
2 changed files with 31 additions and 31 deletions

View file

@ -191,22 +191,6 @@
var callback, compile, compileTimeout, prevStats, watchErr, watcher; var callback, compile, compileTimeout, prevStats, watchErr, watcher;
prevStats = null; prevStats = null;
compileTimeout = null; compileTimeout = null;
compile = function() {
clearTimeout(compileTimeout);
return compileTimeout = setTimeout(function() {
return fs.stat(source, function(err, stats) {
if (err) throw err;
if (prevStats && (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);
});
});
}, 25);
};
watchErr = function(e) { watchErr = function(e) {
if (e.code === 'ENOENT') { if (e.code === 'ENOENT') {
removeSource(source, base, true); removeSource(source, base, true);
@ -215,6 +199,22 @@
throw e; throw e;
} }
}; };
compile = function() {
clearTimeout(compileTimeout);
return compileTimeout = setTimeout(function() {
return fs.stat(source, function(err, stats) {
if (err) return watchErr(err);
if (prevStats && (stats.size === prevStats.size && stats.mtime.getTime() === prevStats.mtime.getTime())) {
return;
}
prevStats = stats;
return fs.readFile(source, function(err, code) {
if (err) return watchErr(err);
return compileScript(source, code.toString(), base);
});
});
}, 25);
};
try { try {
return watcher = fs.watch(source, callback = function(event) { return watcher = fs.watch(source, callback = function(event) {
if (event === 'change') { if (event === 'change') {
@ -311,7 +311,7 @@
return path.exists(jsPath, function(exists) { return path.exists(jsPath, function(exists) {
if (exists) { if (exists) {
return fs.unlink(jsPath, function(err) { return fs.unlink(jsPath, function(err) {
if (err) throw err; if (err && err.code !== 'ENOENT') throw err;
return timeLog("removed " + source); return timeLog("removed " + source);
}); });
} }

View file

@ -170,25 +170,25 @@ watch = (source, base) ->
prevStats = null prevStats = null
compileTimeout = null compileTimeout = null
compile = ->
clearTimeout compileTimeout
compileTimeout = setTimeout ->
fs.stat source, (err, stats) ->
throw err if err
return if prevStats and (stats.size is prevStats.size and
stats.mtime.getTime() is prevStats.mtime.getTime())
prevStats = stats
fs.readFile source, (err, code) ->
throw err if err
compileScript(source, code.toString(), base)
, 25
watchErr = (e) -> watchErr = (e) ->
if e.code is 'ENOENT' if e.code is 'ENOENT'
removeSource source, base, yes removeSource source, base, yes
compileJoin() compileJoin()
else throw e else throw e
compile = ->
clearTimeout compileTimeout
compileTimeout = setTimeout ->
fs.stat source, (err, stats) ->
return watchErr err if err
return if prevStats and (stats.size is prevStats.size and
stats.mtime.getTime() is prevStats.mtime.getTime())
prevStats = stats
fs.readFile source, (err, code) ->
return watchErr err if err
compileScript(source, code.toString(), base)
, 25
try try
watcher = fs.watch source, callback = (event) -> watcher = fs.watch source, callback = (event) ->
if event is 'change' if event is 'change'
@ -240,7 +240,7 @@ removeSource = (source, base, removeJs) ->
path.exists jsPath, (exists) -> path.exists jsPath, (exists) ->
if exists if exists
fs.unlink jsPath, (err) -> fs.unlink jsPath, (err) ->
throw err if err throw err if err and err.code isnt 'ENOENT'
timeLog "removed #{source}" timeLog "removed #{source}"
# Get the corresponding output JavaScript path for a source file. # Get the corresponding output JavaScript path for a source file.