[Pkg-javascript-devel] Bug#1003039: node-terser: Please update node-commander dependency to version 8

Yadd yadd at debian.org
Mon Jan 3 07:08:31 GMT 2022


Package: node-terser
Version: 4.1.2-9
Severity: important
Tags: patch

Hi,

node-commander 8 changed option parsing. Here is a proposed patch to be
used in replacement of 1001_use_commander_4.patch
-------------- next part --------------
Description: support node module commander release 8
 same patch than uglifyjs
Author: Yadd <yadd at debian.org>
Forwarded: no
Last-Update: 2022-01-03

--- a/bin/uglifyjs
+++ b/bin/uglifyjs
@@ -28,6 +28,15 @@
 program.version(info.name + " " + info.version);
 program.parseArgv = program.parse;
 program.parse = undefined;
+var argv = [];
+process.argv.forEach(function(arg){
+  if(arg.match(/^-([pcmbode]+)$/)) {
+    argv = argv.concat(RegExp.$1.split('').map(s => { return '-'+s }));
+  }
+  else argv.push(arg);
+});
+process.argv = argv;
+
 if (process.argv.includes("ast")) program.helpInformation = describe_ast;
 else if (process.argv.includes("options")) program.helpInformation = function() {
     var text = [];
@@ -65,10 +74,11 @@
 program.option("--warn", "Print warning messages.");
 program.option("--wrap <name>", "Embed everything as a function with ?exports? corresponding to ?name? globally.");
 program.arguments("[files...]").parseArgv(process.argv);
-if (program.configFile) {
-    options = JSON.parse(read_file(program.configFile));
+const opts = program.opts();
+if (opts.configFile) {
+    options = JSON.parse(read_file(opts.configFile));
 }
-if (!program.output && program.sourceMap && program.sourceMap.url != "inline") {
+if (!opts.output && opts.sourceMap && opts.sourceMap.url != "inline") {
     fatal("ERROR: cannot write source map to STDOUT");
 }
 [
@@ -82,83 +92,83 @@
     "toplevel",
     "wrap"
 ].forEach(function(name) {
-    if (name in program) {
-        options[name] = program[name];
+    if (name in opts) {
+        options[name] = opts[name];
     }
 });
-if ("ecma" in program) {
-    if (program.ecma != (program.ecma | 0)) fatal("ERROR: ecma must be an integer");
-    options.ecma = program.ecma | 0;
+if ("ecma" in opts) {
+    if (opts.ecma != (opts.ecma | 0)) fatal("ERROR: ecma must be an integer");
+    options.ecma = opts.ecma | 0;
 }
-if (program.beautify) {
-    options.output = typeof program.beautify == "object" ? program.beautify : {};
+if (opts.beautify) {
+    options.output = typeof opts.beautify == "object" ? opts.beautify : {};
     if (!("beautify" in options.output)) {
         options.output.beautify = true;
     }
 }
-if (program.comments) {
+if (opts.comments) {
     if (typeof options.output != "object") options.output = {};
-    options.output.comments = typeof program.comments == "string" ? program.comments : "some";
+    options.output.comments = typeof opts.comments == "string" ? opts.comments : "some";
 }
-if (program.define) {
+if (opts.define) {
     if (typeof options.compress != "object") options.compress = {};
     if (typeof options.compress.global_defs != "object") options.compress.global_defs = {};
-    for (var expr in program.define) {
-        options.compress.global_defs[expr] = program.define[expr];
+    for (var expr in opts.define) {
+        options.compress.global_defs[expr] = opts.define[expr];
     }
 }
-if (program.keepClassnames) {
+if (opts.keepClassnames) {
     options.keep_classnames = true;
 }
-if (program.keepFnames) {
+if (opts.keepFnames) {
     options.keep_fnames = true;
 }
-if (program.mangleProps) {
-    if (program.mangleProps.domprops) {
-        delete program.mangleProps.domprops;
+if (opts.mangleProps) {
+    if (opts.mangleProps.domprops) {
+        delete opts.mangleProps.domprops;
     } else {
-        if (typeof program.mangleProps != "object") program.mangleProps = {};
-        if (!Array.isArray(program.mangleProps.reserved)) program.mangleProps.reserved = [];
+        if (typeof opts.mangleProps != "object") opts.mangleProps = {};
+        if (!Array.isArray(opts.mangleProps.reserved)) opts.mangleProps.reserved = [];
     }
     if (typeof options.mangle != "object") options.mangle = {};
-    options.mangle.properties = program.mangleProps;
+    options.mangle.properties = opts.mangleProps;
 }
-if (program.nameCache) {
-    options.nameCache = JSON.parse(read_file(program.nameCache, "{}"));
+if (opts.nameCache) {
+    options.nameCache = JSON.parse(read_file(opts.nameCache, "{}"));
 }
-if (program.output == "ast") {
+if (opts.output == "ast") {
     options.output = {
         ast: true,
         code: false
     };
 }
-if (program.parse) {
-    if (!program.parse.acorn && !program.parse.spidermonkey) {
-        options.parse = program.parse;
-    } else if (program.sourceMap && program.sourceMap.content == "inline") {
+if (opts.parse) {
+    if (!opts.parse.acorn && !opts.parse.spidermonkey) {
+        options.parse = opts.parse;
+    } else if (opts.sourceMap && opts.sourceMap.content == "inline") {
         fatal("ERROR: inline source map only works with built-in parser");
     }
 }
 if (~program.rawArgs.indexOf("--rename")) {
     options.rename = true;
-} else if (!program.rename) {
+} else if (!opts.rename) {
     options.rename = false;
 }
 var convert_path = function(name) {
     return name;
 };
-if (typeof program.sourceMap == "object" && "base" in program.sourceMap) {
+if (typeof opts.sourceMap == "object" && "base" in opts.sourceMap) {
     convert_path = function() {
-        var base = program.sourceMap.base;
+        var base = opts.sourceMap.base;
         delete options.sourceMap.base;
         return function(name) {
             return path.relative(base, name);
         };
     }();
 }
-if (program.verbose) {
+if (opts.verbose) {
     options.warnings = "verbose";
-} else if (program.warn) {
+} else if (opts.warn) {
     options.warnings = true;
 }
 
@@ -196,24 +206,24 @@
     UglifyJS.AST_Node.warn_function = function(msg) {
         print_error("WARN: " + msg);
     };
-    var content = program.sourceMap && program.sourceMap.content;
+    var content = opts.sourceMap && opts.sourceMap.content;
     if (content && content !== "inline") {
         options.sourceMap.content = read_file(content, content);
     }
-    if (program.timings) options.timings = true;
+    if (opts.timings) options.timings = true;
     try {
-        if (program.parse) {
-            if (program.parse.acorn) {
+        if (opts.parse) {
+            if (opts.parse.acorn) {
                 files = convert_ast(function(toplevel, name) {
                     return require("acorn").parse(files[name], {
                         ecmaVersion: 2018,
                         locations: true,
                         program: toplevel,
                         sourceFile: name,
-                        sourceType: options.module || program.parse.module ? "module" : "script"
+                        sourceType: options.module || opts.parse.module ? "module" : "script"
                     });
                 });
-            } else if (program.parse.spidermonkey) {
+            } else if (opts.parse.spidermonkey) {
                 files = convert_ast(function(toplevel, name) {
                     var obj = JSON.parse(files[name]);
                     if (!toplevel) return obj;
@@ -252,7 +262,7 @@
             print_error(format_object(ex.defs));
         }
         fatal(ex);
-    } else if (program.output == "ast") {
+    } else if (opts.output == "ast") {
         if (!options.compress && !options.mangle) {
             result.ast.figure_out_scope({});
         }
@@ -286,7 +296,7 @@
             }
             return value;
         }, 2));
-    } else if (program.output == "spidermonkey") {
+    } else if (opts.output == "spidermonkey") {
         print(JSON.stringify(UglifyJS.minify(result.code, {
             compress: false,
             mangle: false,
@@ -295,16 +305,16 @@
                 code: false
             }
         }).ast.to_mozilla_ast(), null, 2));
-    } else if (program.output) {
-        fs.writeFileSync(program.output, result.code);
+    } else if (opts.output) {
+        fs.writeFileSync(opts.output, result.code);
         if (result.map) {
-            fs.writeFileSync(program.output + ".map", result.map);
+            fs.writeFileSync(opts.output + ".map", result.map);
         }
     } else {
         print(result.code);
     }
-    if (program.nameCache) {
-        fs.writeFileSync(program.nameCache, JSON.stringify(options.nameCache));
+    if (opts.nameCache) {
+        fs.writeFileSync(opts.nameCache, JSON.stringify(options.nameCache));
     }
     if (result.timings) for (var phase in result.timings) {
         print_error("- " + phase + ": " + result.timings[phase].toFixed(3) + "s");


More information about the Pkg-javascript-devel mailing list