From caafafcf4d0ca12859f4eca192a365c5eace6e8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20H=C3=A4fner?= Date: Sat, 23 Nov 2013 06:49:13 +0100 Subject: [PATCH] Simplify `removeSource` and make it synchronous --- lib/coffee-script/command.js | 19 +++++++++---------- src/command.coffee | 10 +++++----- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/lib/coffee-script/command.js b/lib/coffee-script/command.js index 2e6ab84d..a012b19f 100644 --- a/lib/coffee-script/command.js +++ b/lib/coffee-script/command.js @@ -375,22 +375,21 @@ }; removeSource = function(source, base, removeJs) { - var index, jsPath; + var err, index, jsPath; index = sources.indexOf(source); sources.splice(index, 1); sourceCode.splice(index, 1); if (removeJs && !opts.join) { jsPath = outputPath(source, base); - return fs.exists(jsPath, function(itExists) { - if (itExists) { - return fs.unlink(jsPath, function(err) { - if (err && err.code !== 'ENOENT') { - throw err; - } - return timeLog("removed " + source); - }); + try { + fs.unlinkSync(jsPath); + } catch (_error) { + err = _error; + if (err.code !== 'ENOENT') { + throw err; } - }); + } + return timeLog("removed " + source); } }; diff --git a/src/command.coffee b/src/command.coffee index 170bfd83..3005b4a9 100644 --- a/src/command.coffee +++ b/src/command.coffee @@ -259,11 +259,11 @@ removeSource = (source, base, removeJs) -> sourceCode.splice index, 1 if removeJs and not opts.join jsPath = outputPath source, base - fs.exists jsPath, (itExists) -> - if itExists - fs.unlink jsPath, (err) -> - throw err if err and err.code isnt 'ENOENT' - timeLog "removed #{source}" + try + fs.unlinkSync jsPath + catch err + throw err unless err.code is 'ENOENT' + timeLog "removed #{source}" # Get the corresponding output JavaScript path for a source file. outputPath = (source, base, extension=".js") ->