Skip to content

Commit

Permalink
More memory for Babel transpilation (#287)
Browse files Browse the repository at this point in the history
Set NODE_OPTIONS=--max_old_space_size$MEM automatically.
For: https://shiftleftinc.atlassian.net/browse/SEN-1133
  • Loading branch information
max-leuthaeuser committed Jul 3, 2023
1 parent 687821b commit bffcbea
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class BabelTranspiler(
"--source-maps true " + babelPresets + babelPlugins +
s"--out-dir '$outDir' $constructIgnoreDirArgs"
logger.debug(s"\t+ Babel transpiling '$projectPath' to '$outDir' with command '$command'")
ExternalCommand.run(command, in.toString) match {
ExternalCommand.run(command, in.toString, extraEnv = NODE_OPTIONS) match {
case Success(_) => logger.debug("\t+ Babel transpiling finished")
case Failure(exception) => logger.debug("\t- Babel transpiling failed", exception)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import java.nio.file.Path

trait Transpiler extends TranspilingEnvironment {

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

protected val DEFAULT_IGNORED_DIRS: List[String] = List(
"build",
"dist",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ case class TranspilerGroup(override val config: Config, override val projectPath
}
logger.info("Installing project dependencies and plugins. That will take a while.")
logger.debug(s"\t+ Installing plugins with command '$command' in path '$projectPath'")
ExternalCommand.run(command, projectPath.toString) match {
ExternalCommand.run(command, projectPath.toString, extraEnv = NODE_OPTIONS) match {
case Success(_) =>
logger.info("\t+ Plugins installed")
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ trait TranspilingEnvironment {
case None =>
nodeVersion()
isValid = Some(pnpmAvailable(dir) || yarnAvailable() || npmAvailable())
logger.debug(s"\t+ additional node ENV settings: '${NODE_OPTIONS.mkString}'")
isValid.get
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ class TypescriptTranspiler(override val config: Config, override val projectPath

private val logger = LoggerFactory.getLogger(getClass)

private val NODE_OPTIONS: Map[String, String] = Map("NODE_OPTIONS" -> "--max_old_space_size=4096")

private val tsc = Paths.get(projectPath.toString, "node_modules", ".bin", "tsc").toString
private val typescriptAndVersion = Versions.nameAndVersion("typescript")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class VueTranspiler(override val config: Config, override val projectPath: Path)

private val logger = LoggerFactory.getLogger(getClass)

private lazy val NODE_OPTIONS: Map[String, String] = nodeOptions()
private lazy val VUE_NODE_OPTIONS: Map[String, String] = nodeOptions()

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

0 comments on commit bffcbea

Please sign in to comment.