Skip to content

Commit bffcbea

Browse files
More memory for Babel transpilation (#287)
Set NODE_OPTIONS=--max_old_space_size$MEM automatically. For: https://shiftleftinc.atlassian.net/browse/SEN-1133
1 parent 687821b commit bffcbea

File tree

6 files changed

+8
-7
lines changed

6 files changed

+8
-7
lines changed

src/main/scala/io/shiftleft/js2cpg/preprocessing/BabelTranspiler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class BabelTranspiler(
4848
"--source-maps true " + babelPresets + babelPlugins +
4949
s"--out-dir '$outDir' $constructIgnoreDirArgs"
5050
logger.debug(s"\t+ Babel transpiling '$projectPath' to '$outDir' with command '$command'")
51-
ExternalCommand.run(command, in.toString) match {
51+
ExternalCommand.run(command, in.toString, extraEnv = NODE_OPTIONS) match {
5252
case Success(_) => logger.debug("\t+ Babel transpiling finished")
5353
case Failure(exception) => logger.debug("\t- Babel transpiling failed", exception)
5454
}

src/main/scala/io/shiftleft/js2cpg/preprocessing/Transpiler.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import java.nio.file.Path
66

77
trait Transpiler extends TranspilingEnvironment {
88

9+
protected val NODE_OPTIONS: Map[String, String] = Map("NODE_OPTIONS" -> "--max-old-space-size=8192")
10+
911
protected val DEFAULT_IGNORED_DIRS: List[String] = List(
1012
"build",
1113
"dist",

src/main/scala/io/shiftleft/js2cpg/preprocessing/TranspilerGroup.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ case class TranspilerGroup(override val config: Config, override val projectPath
2525
}
2626
logger.info("Installing project dependencies and plugins. That will take a while.")
2727
logger.debug(s"\t+ Installing plugins with command '$command' in path '$projectPath'")
28-
ExternalCommand.run(command, projectPath.toString) match {
28+
ExternalCommand.run(command, projectPath.toString, extraEnv = NODE_OPTIONS) match {
2929
case Success(_) =>
3030
logger.info("\t+ Plugins installed")
3131
true

src/main/scala/io/shiftleft/js2cpg/preprocessing/TranspilingEnvironment.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ trait TranspilingEnvironment {
127127
case None =>
128128
nodeVersion()
129129
isValid = Some(pnpmAvailable(dir) || yarnAvailable() || npmAvailable())
130+
logger.debug(s"\t+ additional node ENV settings: '${NODE_OPTIONS.mkString}'")
130131
isValid.get
131132
}
132133

src/main/scala/io/shiftleft/js2cpg/preprocessing/TypescriptTranspiler.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ class TypescriptTranspiler(override val config: Config, override val projectPath
3333

3434
private val logger = LoggerFactory.getLogger(getClass)
3535

36-
private val NODE_OPTIONS: Map[String, String] = Map("NODE_OPTIONS" -> "--max_old_space_size=4096")
37-
3836
private val tsc = Paths.get(projectPath.toString, "node_modules", ".bin", "tsc").toString
3937
private val typescriptAndVersion = Versions.nameAndVersion("typescript")
4038

src/main/scala/io/shiftleft/js2cpg/preprocessing/VueTranspiler.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class VueTranspiler(override val config: Config, override val projectPath: Path)
3232

3333
private val logger = LoggerFactory.getLogger(getClass)
3434

35-
private lazy val NODE_OPTIONS: Map[String, String] = nodeOptions()
35+
private lazy val VUE_NODE_OPTIONS: Map[String, String] = nodeOptions()
3636

3737
private val vue = Paths.get(projectPath.toString, "node_modules", ".bin", "vue-cli-service").toString
3838
private val vueAndVersion = Versions.nameAndVersion("@vue/cli-service-global")
@@ -62,7 +62,7 @@ class VueTranspiler(override val config: Config, override val projectPath: Path)
6262
}
6363
logger.info("Installing Vue.js dependencies and plugins. That will take a while.")
6464
logger.debug(s"\t+ Installing Vue.js plugins with command '$command' in path '$projectPath'")
65-
ExternalCommand.run(command, projectPath.toString, extraEnv = NODE_OPTIONS) match {
65+
ExternalCommand.run(command, projectPath.toString, extraEnv = VUE_NODE_OPTIONS) match {
6666
case Success(_) =>
6767
logger.info("\t+ Vue.js plugins installed")
6868
true
@@ -88,7 +88,7 @@ class VueTranspiler(override val config: Config, override val projectPath: Path)
8888
createCustomBrowserslistFile()
8989
val command = s"${ExternalCommand.toOSCommand(vue)} build --dest '$tmpTranspileDir' --mode development --no-clean"
9090
logger.debug(s"\t+ Vue.js transpiling $projectPath to '$tmpTranspileDir'")
91-
ExternalCommand.run(command, projectPath.toString, extraEnv = NODE_OPTIONS) match {
91+
ExternalCommand.run(command, projectPath.toString, extraEnv = VUE_NODE_OPTIONS) match {
9292
case Success(_) => logger.debug("\t+ Vue.js transpiling finished")
9393
case Failure(exception) => logger.debug("\t- Vue.js transpiling failed", exception)
9494
}

0 commit comments

Comments
 (0)