Skip to content

Commit c7017d8

Browse files
CopilotQuafadas
andauthored
Parallelize terser minification in processTerserFullLink (#59)
* Initial plan * Parallelize terser minification in processTerserFullLink using Future Agent-Logs-Url: https://github.com/Quafadas/live-server-scala-cli-js/sessions/e0c02233-278a-4021-baa6-33221cf7b97b Co-authored-by: Quafadas <24899792+Quafadas@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Quafadas <24899792+Quafadas@users.noreply.github.com>
1 parent 849fd84 commit c7017d8

1 file changed

Lines changed: 26 additions & 21 deletions

File tree

plugin/src/FileBasedContentHashScalaJSModule.scala

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package io.github.quafadas.sjsls
33
import java.security.MessageDigest
44

55
import scala.collection.mutable
6+
import scala.concurrent.{Await, Future}
7+
import scala.concurrent.duration.Duration
68

79
import mill.*
810
import mill.api.Result
@@ -209,29 +211,32 @@ object FileBasedContentHashScalaJSModule:
209211
val tempDir = os.temp.dir(deleteOnExit = false)
210212
try
211213
val jsFiles = os.list(srcDir).filter(p => os.isFile(p) && p.ext == "js")
212-
jsFiles.foreach {
214+
val futures = jsFiles.map {
213215
f =>
214-
val outPath = tempDir / f.last
215-
val smArgs: Seq[String] =
216-
if sourceMap then Seq("--source-map", s"content='${f}.map',url='${f.last}.map'")
217-
else Seq.empty
218-
os.proc(
219-
"terser",
220-
f.toString,
221-
"-o",
222-
outPath.toString,
223-
"--config-file",
224-
terserConfigPath.toString,
225-
smArgs
226-
)
227-
.call(
228-
cwd = tempDir,
229-
mergeErrIntoOut = true,
230-
stdin = os.Inherit,
231-
stdout = os.Inherit,
232-
stderr = os.Inherit
233-
)
216+
Future {
217+
val outPath = tempDir / f.last
218+
val smArgs: Seq[String] =
219+
if sourceMap then Seq("--source-map", s"content='${f}.map',url='${f.last}.map'")
220+
else Seq.empty
221+
os.proc(
222+
"terser",
223+
f.toString,
224+
"-o",
225+
outPath.toString,
226+
"--config-file",
227+
terserConfigPath.toString,
228+
smArgs
229+
)
230+
.call(
231+
cwd = tempDir,
232+
mergeErrIntoOut = true,
233+
stdin = os.Inherit,
234+
stdout = os.Inherit,
235+
stderr = os.Inherit
236+
)
237+
}
234238
}
239+
Await.result(Future.sequence(futures), Duration.Inf)
235240
// Copy non-JS files (e.g. source maps not produced by terser) to temp dir.
236241
os.list(srcDir)
237242
.filter(p => os.isFile(p) && p.ext != "js")

0 commit comments

Comments
 (0)