From 8170f89279a3102b192479edf0900f387c0b9808 Mon Sep 17 00:00:00 2001 From: Domantas Petrauskas Date: Sat, 14 May 2022 10:39:46 +0300 Subject: [PATCH] Refactor webpack stats module names in warning and error to optional --- .../src/main/scala/scalajsbundler/Stats.scala | 8 ++++---- .../src/main/scala/scalajsbundler/Webpack.scala | 5 +++-- .../webpack-stats/src/main/scala/example/Main.scala | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/sbt-scalajs-bundler/src/main/scala/scalajsbundler/Stats.scala b/sbt-scalajs-bundler/src/main/scala/scalajsbundler/Stats.scala index 9f0ab4e1..2d9fa51a 100644 --- a/sbt-scalajs-bundler/src/main/scala/scalajsbundler/Stats.scala +++ b/sbt-scalajs-bundler/src/main/scala/scalajsbundler/Stats.scala @@ -50,9 +50,9 @@ object Stats { } - final case class WebpackError(moduleName: String, message: String, loc: String) + final case class WebpackError(moduleName: Option[String], message: String, loc: String) - final case class WebpackWarning(moduleName: String, message: String) + final case class WebpackWarning(moduleName: Option[String], message: String) final case class WebpackStats( version: String, @@ -115,13 +115,13 @@ object Stats { )(Asset.apply _) implicit val errorReads: Reads[WebpackError] = ( - (JsPath \ "moduleName").read[String] and + (JsPath \ "moduleName").readNullable[String] and (JsPath \ "message").read[String] and (JsPath \ "loc").read[String] )(WebpackError.apply _) implicit val warningReads: Reads[WebpackWarning] = ( - (JsPath \ "moduleName").read[String] and + (JsPath \ "moduleName").readNullable[String] and (JsPath \ "message").read[String] )(WebpackWarning.apply _) diff --git a/sbt-scalajs-bundler/src/main/scala/scalajsbundler/Webpack.scala b/sbt-scalajs-bundler/src/main/scala/scalajsbundler/Webpack.scala index cc5786fc..38ef6ea4 100644 --- a/sbt-scalajs-bundler/src/main/scala/scalajsbundler/Webpack.scala +++ b/sbt-scalajs-bundler/src/main/scala/scalajsbundler/Webpack.scala @@ -249,12 +249,12 @@ object Webpack { logger.info("") // Filtering is a workaround for #111 p.warnings.filterNot(_.message.contains("https://raw.githubusercontent.com")).foreach { warning => - logger.warn(s"WARNING in ${warning.moduleName}") + logger.warn(s"WARNING${warning.moduleName.map("in "+_).getOrElse("")}") logger.warn(warning.message) logger.warn("\n") } p.errors.foreach { error => - logger.error(s"ERROR in ${error.moduleName} ${error.loc}") + logger.error(s"ERROR${error.moduleName.map("in "+_).getOrElse("")} ${error.loc}") logger.error(error.message) logger.error("\n") } @@ -277,6 +277,7 @@ object Webpack { val webpackBin = workingDir / "node_modules" / "webpack" / "bin" / "webpack" val params = nodeArgs ++ Seq(webpackBin.absolutePath, "--profile", "--json") ++ args val cmd = "node" +: params + log.debug(s"Running command [${cmd.mkString(" ")}]") Commands.run(cmd, workingDir, log, jsonOutput(cmd, log)) .fold( sys.error, diff --git a/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/webpack-stats/src/main/scala/example/Main.scala b/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/webpack-stats/src/main/scala/example/Main.scala index 1397038d..96e71fb6 100644 --- a/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/webpack-stats/src/main/scala/example/Main.scala +++ b/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/webpack-stats/src/main/scala/example/Main.scala @@ -2,6 +2,6 @@ package example object Main { def main(args: Array[String]): Unit = { - println("yarn-interactive main") + println("webpack-stats main") } }