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;
prevStats = 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) {
if (e.code === 'ENOENT') {
removeSource(source, base, true);
@ -215,6 +199,22 @@
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 {
return watcher = fs.watch(source, callback = function(event) {
if (event === 'change') {
@ -311,7 +311,7 @@
return path.exists(jsPath, function(exists) {
if (exists) {
return fs.unlink(jsPath, function(err) {
if (err) throw err;
if (err && err.code !== 'ENOENT') throw err;
return timeLog("removed " + source);
});
}

View file

@ -170,25 +170,25 @@ watch = (source, base) ->
prevStats = 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) ->
if e.code is 'ENOENT'
removeSource source, base, yes
compileJoin()
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
watcher = fs.watch source, callback = (event) ->
if event is 'change'
@ -240,7 +240,7 @@ removeSource = (source, base, removeJs) ->
path.exists jsPath, (exists) ->
if exists
fs.unlink jsPath, (err) ->
throw err if err
throw err if err and err.code isnt 'ENOENT'
timeLog "removed #{source}"
# Get the corresponding output JavaScript path for a source file.