Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions sbt-scalajs-bundler/src/main/scala/scalajsbundler/Stats.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import java.io.File
import java.nio.file.Path

/**
* Webpack stats model and json parsers
* Webpack stats model and json parsers.
*
* See:
* https://webpack.js.org/api/stats/
*/
object Stats {

Expand Down Expand Up @@ -50,9 +53,9 @@ object Stats {

}

final case class WebpackError(moduleName: String, message: String, loc: String)
final case class WebpackError(moduleName: Option[String], message: String, loc: Option[String])

final case class WebpackWarning(moduleName: String, message: String)
final case class WebpackWarning(moduleName: Option[String], message: String)

final case class WebpackStats(
version: String,
Expand Down Expand Up @@ -115,13 +118,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]
(JsPath \ "loc").readNullable[String]
)(WebpackError.apply _)

implicit val warningReads: Reads[WebpackWarning] = (
(JsPath \ "moduleName").read[String] and
(JsPath \ "moduleName").readNullable[String] and
(JsPath \ "message").read[String]
)(WebpackWarning.apply _)

Expand Down
49 changes: 25 additions & 24 deletions sbt-scalajs-bundler/src/main/scala/scalajsbundler/Webpack.scala
Original file line number Diff line number Diff line change
Expand Up @@ -231,36 +231,37 @@ object Webpack {
private def jsonOutput(cmd: Seq[String], logger: Logger)(in: InputStream): Option[WebpackStats] = {
Try {
val parsed = Json.parse(in)
parsed.validate[WebpackStats] match {
case JsError(e) =>
logger.error("Error parsing webpack stats output")
// In case of error print the result and return None. it will be ignored upstream
e.foreach {
case (p, v) => logger.error(s"$p: ${v.mkString(",")}")
val p = parsed.as[WebpackStats]
if (p.warnings.nonEmpty || p.errors.nonEmpty) {
logger.info("")
// Filtering is a workaround for #111
p.warnings.filterNot(_.message.contains("https://raw.githubusercontent.com")).foreach { warning =>
warning.moduleName match {
case Some(moduleName) =>
logger.warn(s"WARNING in $moduleName")
case None =>
logger.warn("WARNING")
}
None
case JsSuccess(p, _) =>
if (p.warnings.nonEmpty || p.errors.nonEmpty) {
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(warning.message)
logger.warn("\n")
}
p.errors.foreach { error =>
logger.error(s"ERROR in ${error.moduleName} ${error.loc}")
logger.error(error.message)
logger.error("\n")
}
logger.warn(warning.message)
logger.warn("\n")
}
p.errors.foreach { error =>
error.moduleName match {
case Some(moduleName) =>
logger.error(s"ERROR in $moduleName ${error.loc.getOrElse("")}")
case None =>
logger.error("ERROR")
}
Some(p)
logger.error(error.message)
logger.error("\n")
}
}
p
} match {
case Success(x) =>
x
Some(x)
case Failure(e) =>
// In same cases errors are not reported on the json output but comes on stdout
// In some cases errors are not reported on the json output but comes on stdout
// where they cannot be parsed as json. The best we can do here is to suggest
// running the command manually
logger.error(s"Failure on parsing the output of webpack: ${e.getMessage}")
Expand Down