From 26b7d680e7a8cdf70b3f26d4469b06decb6f44b1 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Tue, 14 Apr 2015 18:27:17 +0300 Subject: [PATCH] Replace deprecated `util` functions. --- .travis.yml | 5 +++-- bin/uglifyjs | 44 ++++++++++++++++++++++---------------------- test/run-tests.js | 7 +++---- tools/node.js | 6 ++---- 4 files changed, 30 insertions(+), 32 deletions(-) diff --git a/.travis.yml b/.travis.yml index 82460de5..59d0fa73 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ language: node_js -before_install: "npm install -g npm" node_js: - "0.10" - - "0.11" + - "0.12" +matrix: + fast_finish: true diff --git a/bin/uglifyjs b/bin/uglifyjs index df7b7832..62a577d1 100755 --- a/bin/uglifyjs +++ b/bin/uglifyjs @@ -132,24 +132,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); } @@ -221,7 +221,7 @@ if (ARGS.comments != null) { 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; @@ -241,7 +241,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"; @@ -253,7 +253,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) { @@ -266,12 +266,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); } @@ -294,9 +294,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); } } @@ -304,7 +304,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) { @@ -341,9 +341,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; @@ -443,15 +443,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) })); @@ -478,7 +478,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); } } @@ -497,8 +497,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/test/run-tests.js b/test/run-tests.js index 94bf6ad9..2f4033e6 100755 --- a/test/run-tests.js +++ b/test/run-tests.js @@ -4,7 +4,6 @@ var U = require("../tools/node"); var path = require("path"); var fs = require("fs"); var assert = require("assert"); -var sys = require("util"); var tests_dir = path.dirname(module.filename); var failures = 0; @@ -12,8 +11,8 @@ var failed_files = {}; run_compress_tests(); if (failures) { - sys.error("\n!!! Failed " + failures + " test cases."); - sys.error("!!! " + Object.keys(failed_files).join(", ")); + console.error("\n!!! Failed " + failures + " test cases."); + console.error("!!! " + Object.keys(failed_files).join(", ")); process.exit(1); } @@ -31,7 +30,7 @@ function tmpl() { function log() { var txt = tmpl.apply(this, arguments); - sys.puts(txt); + console.log(txt); } function log_directory(dir) { diff --git a/tools/node.js b/tools/node.js index 054a05c0..b635a701 100644 --- a/tools/node.js +++ b/tools/node.js @@ -1,10 +1,8 @@ var path = require("path"); var fs = require("fs"); var vm = require("vm"); -var sys = require("util"); var UglifyJS = vm.createContext({ - sys : sys, console : console, process : process, Buffer : Buffer, @@ -19,7 +17,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); } }; @@ -42,7 +40,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.