From c4cdc6b9d6300f174e42d6cecafc0fd4ebe92ebc Mon Sep 17 00:00:00 2001 From: Ankit Kumar <118803988+ankit-privado@users.noreply.github.com> Date: Sat, 7 Dec 2024 02:10:07 +0530 Subject: [PATCH] JS minified hot fix (#156) --- .../src/main/resources/application.conf | 2 +- .../joern/jssrc2cpg/utils/AstGenRunner.scala | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/joern-cli/frontends/jssrc2cpg/src/main/resources/application.conf b/joern-cli/frontends/jssrc2cpg/src/main/resources/application.conf index caa918ef495a..00ba2dbc35b7 100644 --- a/joern-cli/frontends/jssrc2cpg/src/main/resources/application.conf +++ b/joern-cli/frontends/jssrc2cpg/src/main/resources/application.conf @@ -1,3 +1,3 @@ jssrc2cpg { - astgen_version: "3.14.0" + astgen_version: "3.22.0" } diff --git a/joern-cli/frontends/jssrc2cpg/src/main/scala/io/joern/jssrc2cpg/utils/AstGenRunner.scala b/joern-cli/frontends/jssrc2cpg/src/main/scala/io/joern/jssrc2cpg/utils/AstGenRunner.scala index 1b4ce6488d75..c02bf998931f 100644 --- a/joern-cli/frontends/jssrc2cpg/src/main/scala/io/joern/jssrc2cpg/utils/AstGenRunner.scala +++ b/joern-cli/frontends/jssrc2cpg/src/main/scala/io/joern/jssrc2cpg/utils/AstGenRunner.scala @@ -222,7 +222,7 @@ class AstGenRunner(config: Config) { } } - def isMinifiedFile(filePath: String): Boolean = filePath match { + private def isMinifiedFile(filePath: String): Boolean = filePath match { case p if MinifiedPathRegex.matches(p) => true case p if File(p).exists && p.endsWith(".js") => val lines = File(filePath).lines.toSeq @@ -360,8 +360,21 @@ class AstGenRunner(config: Config) { else Success(Seq.empty) } - private def jsFiles(in: File, out: File): Try[Seq[String]] = - ExternalCommand.run(s"$astGenCommand$executableArgs -t ts -o $out", in.toString(), extraEnv = NODE_OPTIONS) + private def jsFiles(in: File, out: File): Try[Seq[String]] = { + val skipList = in.listRecursively + .filterNot(_.isDirectory) + .filter(file => isMinifiedFile(file.path.toString)) + .map(path => in.path.relativize(path).toString) + .toSet + val regexSkipFile = s".*(${skipList.mkString("|")}|libphonenumber.js).*" + + logger.debug("JS skiplist size: " + skipList.size) + logger.debug("JS skip regex: " + regexSkipFile) + val command = s"$astGenCommand$executableArgs -t ts -o $out --exclude-regex \"$regexSkipFile\"" + + logger.debug("AST Gen command: " + command) + ExternalCommand.run(command, in.toString(), extraEnv = NODE_OPTIONS) + } private def runAstGenNative(in: File, out: File): Try[Seq[String]] = for { ejsResult <- ejsFiles(in, out)