Skip to content

Commit

Permalink
Node option fix (#136)
Browse files Browse the repository at this point in the history
* Revert "don't pass node-options explicitly"

This reverts commit 537b9f3.

* add a new flag in js
  • Loading branch information
khemrajrathore authored Nov 6, 2024
1 parent 898897b commit 8bbbbd7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@ import scopt.OParser

import java.nio.file.Paths

final case class Config(tsTypes: Boolean = true) extends X2CpgConfig[Config] with TypeRecoveryParserConfig[Config] {
final case class Config(tsTypes: Boolean = true, nodeOptions: String = "")
extends X2CpgConfig[Config]
with TypeRecoveryParserConfig[Config] {

def withTsTypes(value: Boolean): Config = {
copy(tsTypes = value).withInheritedFields(this)
}

def withNodeOptions(value: String): Config = {
copy(nodeOptions = value).withInheritedFields(this)
}

}

object Frontend {
Expand All @@ -28,6 +34,10 @@ object Frontend {
.hidden()
.action((_, c) => c.withTsTypes(false))
.text("disable generation of types via Typescript"),
opt[String]("node-options")
.hidden()
.action((nodeOptions, c) => c.withNodeOptions(nodeOptions))
.text("node options to be used with astGen"),
XTypeRecovery.parserOptions
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ object AstGenRunner {

private val LineLengthThreshold: Int = 10000

// private val NODE_OPTIONS: Map[String, String] = Map("NODE_OPTIONS" -> "--max-old-space-size=8192")

private val TypeDefinitionFileExtensions = List(".t.ts", ".d.ts")

private val MinifiedPathRegex: Regex = ".*([.-]min\\..*js|bundle\\.js)".r
Expand Down Expand Up @@ -177,6 +175,9 @@ class AstGenRunner(config: Config) {
import io.joern.jssrc2cpg.utils.AstGenRunner._

private val executableArgs = if (!config.tsTypes) " --no-tsTypes" else ""
private val nodeOptionsFromConfig =
if config.nodeOptions.nonEmpty then config.nodeOptions else "--max-old-space-size=8192"
private val NODE_OPTIONS: Map[String, String] = Map("NODE_OPTIONS" -> nodeOptionsFromConfig)

private def skippedFiles(astGenOut: List[String]): List[String] = {
val skipped = astGenOut.collect {
Expand Down Expand Up @@ -300,7 +301,7 @@ class AstGenRunner(config: Config) {
}

val result =
ExternalCommand.run(s"$astGenCommand$executableArgs -t ts -o $out", out.toString())
ExternalCommand.run(s"$astGenCommand$executableArgs -t ts -o $out", out.toString(), extraEnv = NODE_OPTIONS)

val jsons = SourceFiles.determine(out.toString(), Set(".json"))
jsons.foreach { jsonPath =>
Expand All @@ -327,12 +328,12 @@ class AstGenRunner(config: Config) {
private def vueFiles(in: File, out: File): Try[Seq[String]] = {
val files = SourceFiles.determine(in.pathAsString, Set(".vue"))
if (files.nonEmpty)
ExternalCommand.run(s"$astGenCommand$executableArgs -t vue -o $out", in.toString())
ExternalCommand.run(s"$astGenCommand$executableArgs -t vue -o $out", in.toString(), extraEnv = NODE_OPTIONS)
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())
ExternalCommand.run(s"$astGenCommand$executableArgs -t ts -o $out", 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 8bbbbd7

Please sign in to comment.