From 2d8ede3436ba28e96b20e2719de573fa9ea998f0 Mon Sep 17 00:00:00 2001 From: Luke Page Date: Wed, 15 Aug 2012 21:14:06 +0100 Subject: [PATCH] remove process.exit calls as they do not guarentee a flushed stdout --- bin/lessc | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/bin/lessc b/bin/lessc index 8e4733d2..357bbe8e 100755 --- a/bin/lessc +++ b/bin/lessc @@ -16,6 +16,12 @@ var options = { color: true, strictImports: false }; +var continueProcessing = true, + currentErrorcode; + +// calling process.exit does not flush stdout always +// so use this to set the exit code +process.on('exit', function() { process.reallyExit(currentErrorcode) }); args = args.filter(function (arg) { var match; @@ -32,7 +38,7 @@ args = args.filter(function (arg) { case 'v': case 'version': sys.puts("lessc " + less.version.join('.') + " (LESS Compiler) [JavaScript]"); - process.exit(0); + continueProcessing = false; case 'verbose': options.verbose = true; break; @@ -46,7 +52,7 @@ args = args.filter(function (arg) { case 'h': case 'help': require('../lib/less/lessc_helper').printUsage(); - process.exit(0); + continueProcessing = false; case 'x': case 'compress': options.compress = true; @@ -61,7 +67,7 @@ args = args.filter(function (arg) { options.paths = match[2].split(os.type().match(/Windows/) ? ';' : ':') .map(function(p) { if (p) { - return path.resolve(process.cwd(), p); + return path.resolve(process.cwd(), p); } }); break; @@ -71,6 +77,10 @@ args = args.filter(function (arg) { } }); +if (!continueProcessing) { + return; +} + var input = args[1]; if (input && input != '-') { input = path.resolve(process.cwd(), input); @@ -80,17 +90,21 @@ if (output) { output = path.resolve(process.cwd(), output); } -var css, fd, tree; - if (! input) { sys.puts("lessc: no input files"); - process.exit(1); + sys.puts(""); + require('../lib/less/lessc_helper').printUsage(); + currentErrorcode = 1; + return; } +var css, fd, tree; + var parseLessFile = function (e, data) { if (e) { sys.puts("lessc: " + e.message); - process.exit(1); + currentErrorcode = 1; + return; } new(less.Parser)({ @@ -101,7 +115,8 @@ var parseLessFile = function (e, data) { }).parse(data, function (err, tree) { if (err) { less.writeError(err, options); - process.exit(1); + currentErrorcode = 1; + return; } else { try { css = tree.toCSS({ @@ -117,7 +132,8 @@ var parseLessFile = function (e, data) { } } catch (e) { less.writeError(e, options); - process.exit(2); + currentErrorcode = 2; + return; } } });