Skip to content

Commit

Permalink
JS minified hot fix (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
ankit-privado authored Dec 6, 2024
1 parent 3144d5d commit c4cdc6b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
jssrc2cpg {
astgen_version: "3.14.0"
astgen_version: "3.22.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c4cdc6b

Please sign in to comment.