From d5ecadd17b7925f4d138435f36ca2ea28ca9e4ce Mon Sep 17 00:00:00 2001 From: Richard van Velzen Date: Tue, 3 Mar 2015 21:32:17 +0100 Subject: [PATCH] Move deprecated util.* calls to proper console.* calls Fixes #641 and #542. --- bin/uglifyjs | 44 ++++++++++++++++++++++---------------------- tools/node.js | 4 ++-- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/bin/uglifyjs b/bin/uglifyjs index 31133c93..72f145db 100755 --- a/bin/uglifyjs +++ b/bin/uglifyjs @@ -116,24 +116,24 @@ normalize(ARGS); if (ARGS.noerr) { UglifyJS.DefaultsError.croak = function(msg, defs) { - sys.error("WARN: " + msg); + console.error("WARN: " + msg); }; } if (ARGS.version || ARGS.V) { var json = require("../package.json"); - sys.puts(json.name + ' ' + json.version); + console.log(json.name + ' ' + json.version); process.exit(0); } if (ARGS.ast_help) { var desc = UglifyJS.describe_ast(); - sys.puts(typeof desc == "string" ? desc : JSON.stringify(desc, null, 2)); + console.log(typeof desc == "string" ? desc : JSON.stringify(desc, null, 2)); process.exit(0); } if (ARGS.h || ARGS.help) { - sys.puts(yargs.help()); + console.log(yargs.help()); process.exit(0); } @@ -183,7 +183,7 @@ if (ARGS.comments) { try { OUTPUT_OPTIONS.comments = new RegExp(ARGS.comments.substr(1, regex_pos - 1), ARGS.comments.substr(regex_pos + 1)); } catch (e) { - sys.error("ERROR: Invalid --comments: " + e.message); + console.error("ERROR: Invalid --comments: " + e.message); } } else if (ARGS.comments == "all") { OUTPUT_OPTIONS.comments = true; @@ -203,7 +203,7 @@ var files = ARGS._.slice(); if (ARGS.self) { if (files.length > 0) { - sys.error("WARN: Ignoring input files since --self was passed"); + console.error("WARN: Ignoring input files since --self was passed"); } files = UglifyJS.FILES; if (!ARGS.wrap) ARGS.wrap = "UglifyJS"; @@ -215,7 +215,7 @@ var ORIG_MAP = ARGS.in_source_map; if (ORIG_MAP) { ORIG_MAP = JSON.parse(fs.readFileSync(ORIG_MAP)); if (files.length == 0) { - sys.error("INFO: Using file from the input source map: " + ORIG_MAP.file); + console.error("INFO: Using file from the input source map: " + ORIG_MAP.file); files = [ ORIG_MAP.file ]; } if (ARGS.source_map_root == null) { @@ -228,12 +228,12 @@ if (files.length == 0) { } if (files.indexOf("-") >= 0 && ARGS.source_map) { - sys.error("ERROR: Source map doesn't work with input from STDIN"); + console.error("ERROR: Source map doesn't work with input from STDIN"); process.exit(1); } if (files.filter(function(el){ return el == "-" }).length > 1) { - sys.error("ERROR: Can read a single file from STDIN (two or more dashes specified)"); + console.error("ERROR: Can read a single file from STDIN (two or more dashes specified)"); process.exit(1); } @@ -256,9 +256,9 @@ try { var compressor = COMPRESS && UglifyJS.Compressor(COMPRESS); } catch(ex) { if (ex instanceof UglifyJS.DefaultsError) { - sys.error(ex.msg); - sys.error("Supported options:"); - sys.error(sys.inspect(ex.defs)); + console.error(ex.msg); + console.error("Supported options:"); + console.error(sys.inspect(ex.defs)); process.exit(1); } } @@ -266,7 +266,7 @@ try { async.eachLimit(files, 1, function (file, cb) { read_whole_file(file, function (err, code) { if (err) { - sys.error("ERROR: can't read file: " + file); + console.error("ERROR: can't read file: " + file); process.exit(1); } if (ARGS.p != null) { @@ -303,9 +303,9 @@ async.eachLimit(files, 1, function (file, cb) { }); } catch(ex) { if (ex instanceof UglifyJS.JS_Parse_Error) { - sys.error("Parse error at " + file + ":" + ex.line + "," + ex.col); - sys.error(ex.message); - sys.error(ex.stack); + console.error("Parse error at " + file + ":" + ex.line + "," + ex.col); + console.error(ex.message); + console.error(ex.stack); process.exit(1); } throw ex; @@ -391,15 +391,15 @@ async.eachLimit(files, 1, function (file, cb) { if (OUTPUT_FILE) { fs.writeFileSync(OUTPUT_FILE, output, "utf8"); } else { - sys.print(output); + console.log(output); } if (ARGS.stats) { - sys.error(UglifyJS.string_template("Timing information (compressed {count} files):", { + console.error(UglifyJS.string_template("Timing information (compressed {count} files):", { count: files.length })); for (var i in STATS) if (STATS.hasOwnProperty(i)) { - sys.error(UglifyJS.string_template("- {name}: {time}s", { + console.error(UglifyJS.string_template("- {name}: {time}s", { name: i, time: (STATS[i] / 1000).toFixed(3) })); @@ -426,7 +426,7 @@ function getOptions(x, constants) { ast = UglifyJS.parse(x, { expression: true }); } catch(ex) { if (ex instanceof UglifyJS.JS_Parse_Error) { - sys.error("Error parsing arguments in: " + x); + console.error("Error parsing arguments in: " + x); process.exit(1); } } @@ -445,8 +445,8 @@ function getOptions(x, constants) { ret[name] = true; return true; // no descend } - sys.error(node.TYPE) - sys.error("Error parsing arguments in: " + x); + console.error(node.TYPE) + console.error("Error parsing arguments in: " + x); process.exit(1); })); } diff --git a/tools/node.js b/tools/node.js index 1ae69da8..e0aeadab 100644 --- a/tools/node.js +++ b/tools/node.js @@ -19,7 +19,7 @@ function load_global(file) { } catch(ex) { // XXX: in case of a syntax error, the message is kinda // useless. (no location information). - sys.debug("ERROR in file: " + file + " / " + ex); + console.error("ERROR in file: " + file + " / " + ex); process.exit(1); } }; @@ -41,7 +41,7 @@ var FILES = exports.FILES = [ FILES.forEach(load_global); UglifyJS.AST_Node.warn_function = function(txt) { - sys.error("WARN: " + txt); + console.error("WARN: " + txt); }; // XXX: perhaps we shouldn't export everything but heck, I'm lazy.