Skip to content

Commit

Permalink
Minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrdom committed May 15, 2022
1 parent bee2882 commit 8196b31
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 39 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ val manual =
val `scalajs-bundler` =
project.in(file("."))
.settings(noPublishSettings: _*)
.aggregate(`sbt-scalajs-bundler`, `sbt-web-scalajs-bundler`)
.aggregate(`sbt-scalajs-bundler`, `sbt-web-scalajs-bundler`, `scalajs-bundler-linker`)

inThisBuild(List(
scalacOptions ++= Seq(
Expand Down
81 changes: 47 additions & 34 deletions sbt-scalajs-bundler/src/main/scala/scalajsbundler/Stats.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,48 @@ object Stats {

}

final case class WebpackError(moduleName: Option[String], message: String, loc: String)
sealed trait Issue {
val message: String
val moduleName: Option[String]
val loc: Option[String]
val stack: Option[String]
val details: Option[String]

def format(): String = {
List(
moduleName.map("in "+_),
Some("Message: "+_),
loc.map("Loc: "+_),
stack.map("Stack: "+_),
details.map("Details: "+_)
).flatten.mkString("\n")
}
}

final case class WebpackWarning(moduleName: Option[String], message: String)
final case class WebpackError(
message: String,
moduleName: Option[String],
loc: Option[String],
stack: Option[String],
details: Option[String]
) extends Issue

final case class WebpackWarning(
message: String,
moduleName: Option[String],
loc: Option[String],
stack: Option[String],
details: Option[String]
) extends Issue

final case class WebpackStats(
version: String,
hash: String,
time: Long,
time: Option[Long],
outputPath: Option[Path],
errors: List[WebpackError],
warnings: List[WebpackWarning],
assets: List[Asset]
errors: List[WebpackError] = Nil,
warnings: List[WebpackWarning] = Nil,
assets: List[Asset] = Nil
) {

/**
Expand All @@ -70,7 +100,12 @@ object Stats {
def print(log: Logger): Unit = {
import formatting._
// Print base info
List(s"Version: $version", s"Hash: $hash", s"Time: ${time}ms", s"Path: ${outputPath.getOrElse("<default>")}").foreach(x => log.info(x))
List(
Some(s"Version: $version"),
Some(s"Hash: $hash"),
time.map(time => s"Time: ${time}ms"),
outputPath.map(s"Path: "+_)
).flatten.foreach(x => log.info(x))
log.info("")
// Print the assets
assets.map { a =>
Expand Down Expand Up @@ -107,32 +142,10 @@ object Stats {
assets.map(a => outputPath.getOrElse(altDir).resolve(a.name).toFile)
}

implicit val assetsReads: Reads[Asset] = (
(JsPath \ "name").read[String] and
(JsPath \ "size").read[Long] and
(JsPath \ "emitted").read[Boolean] and
(JsPath \ "chunkNames").read[List[String]]
)(Asset.apply _)

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

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

implicit val statsReads: Reads[WebpackStats] = (
(JsPath \ "version").read[String] and
(JsPath \ "hash").read[String] and
(JsPath \ "time").read[Long] and
(JsPath \ "outputPath").readNullable[String].map(x => x.map(new File(_).toPath)) and // It seems webpack 2 doesn't produce outputPath
(JsPath \ "errors").read[List[WebpackError]] and
(JsPath \ "warnings").read[List[WebpackWarning]] and
(JsPath \ "assets").read[List[Asset]]
)(WebpackStats.apply _)
implicit val assetsReads: Reads[Asset] = Json.reads[Asset]
implicit val errorReads: Reads[WebpackError] = Json.reads[WebpackError]
implicit val warningReads: Reads[WebpackWarning] = Json.reads[WebpackWarning]
implicit val pathReads: Reads[Path] = Reads.StringReads.map(new File(_).toPath)
implicit val statsReads: Reads[WebpackStats] = Json.using[Json.WithDefaultValues].reads[WebpackStats]

}
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,13 @@ 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${warning.moduleName.map("in "+_).getOrElse("")}")
logger.warn(warning.message)
logger.warn(s"WARNING")
logger.warn(warning.format())
logger.warn("\n")
}
p.errors.foreach { error =>
logger.error(s"ERROR${error.moduleName.map("in "+_).getOrElse("")} ${error.loc}")
logger.error(error.message)
logger.error(s"ERROR")
logger.error(error.format())
logger.error("\n")
}
}
Expand Down

0 comments on commit 8196b31

Please sign in to comment.