Skip to content
This repository was archived by the owner on Jan 27, 2018. It is now read-only.

Commit b3aa16c

Browse files
author
Daniel Wirtz
committed
stderr handling
1 parent 4a87878 commit b3aa16c

6 files changed

+427
-18
lines changed

ClosureCompiler.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
/**
3434
* Constructs a new ClosureCompiler.
35-
* @exports ClosureCompiler
35+
* @exports ClosureCompiler.
3636
* @class Bindings for Closure Compiler.
3737
* @constructor
3838
*/
@@ -126,7 +126,8 @@
126126
* @param {Object.<string,*|Array>} options Any options Closure Compiler supports. If an option can occur
127127
* multiple times, simply supply an array. Externs can additionally point to a directory to include all *.js files
128128
* in it.
129-
* @param {function(Error,string)} callback Callback called with the error, if any, and the compiled code
129+
* @param {function((Error|string),string)} callback Callback called with the error, if any, and the compiled code.
130+
* If no error occurred, error contains the string output from stderr besides the result.
130131
* @throws {Error} If the file cannot be compiled
131132
* @expose
132133
*/
@@ -223,12 +224,10 @@
223224
// Run it
224225
function run(java, args) {
225226
exec('"'+java+'" '+args, function(error, stdout, stderr) {
226-
if (stderr.length > 0) {
227-
callback(new Error(""+stderr), null)
228-
} else if (error) {
229-
callback(error, null);
227+
if (stdout.length > 0 || stderr.length > 0) { // If we get output, error basically just contains a copy of stderr
228+
callback(stderr+"", stdout+"");
230229
} else {
231-
callback(null, ""+stdout);
230+
callback(error, null);
232231
}
233232
});
234233
}

ClosureCompiler.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/ccjs

+8-6
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,18 @@ for (var i=2; i<process.argv.length; i++) {
7878

7979
// Run it
8080
ClosureCompiler.compile(files, options, function(error, result) {
81-
if (help) {
82-
help = error.message;
83-
help = help.replace(/(\-\-[a-zA-Z0-9_]+) ([^ ])/g, function($, $1, $2) {
81+
if (help && typeof error == 'string') {
82+
error = error.replace(/(\-\-[a-zA-Z0-9_]+) ([^ ])/g, function($, $1, $2) {
8483
return $1+"="+$2;
8584
});
8685
console.error("ClosureCompiler.js "+pkg.version+" - https://github.com/dcodeIO/ClosureCompiler.js\n");
8786
console.error(" Usage: "+path.basename(process.argv[1])+" sourceFiles ... [--option=value --flagOption ...] [> outFile]\n");
88-
console.error(help);
89-
process.exit(0);
87+
console.error(error);
88+
process.exit(1);
9089
}
91-
if (error) throw(error);
90+
if (error instanceof Error) {
91+
throw(error);
92+
}
93+
process.stderr.write(error);
9294
process.stdout.write(result);
9395
});

0 commit comments

Comments
 (0)