Skip to content

Commit

Permalink
Merge pull request #87 from KristianAN/main
Browse files Browse the repository at this point in the history
Added configuration for setting module split style for the JS linker
  • Loading branch information
tgodzik authored Jun 18, 2024
2 parents 1377904 + bdd4003 commit 4003978
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ library meant to help reading and writing configuration files.
- If you're looking for the Bloop codebase, look [here](https://github.com/scalacenter/bloop)
- If you're looking to contribute, check our [CONTRIBUTING.md](./CONTRIBUTING.md)
- If you're unfamiliar with Bloop and want to learn more, please check out our full [site](https://scalacenter.github.io/bloop/)

## Binary compatibility

bloop-config uses [unroll](https://github.com/com-lihaoyi/unroll/tree/main) to maintain binary compatibility.
If you add an option that breaks binary compatibility import scala.annotation.unroll and annotate the field with @unroll.
Give the field a reasonable default value.
9 changes: 8 additions & 1 deletion build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,23 @@ trait CommonPublish extends CiReleaseModule with Mima {
trait Common extends CrossScalaModule with ScalafmtModule with ScalafixModule {

val jsoniterVersion = "2.4.0"
val unrollVersion = "0.1.12"

override def ivyDeps = Agg(
ivy"com.github.plokhotnyuk.jsoniter-scala::jsoniter-scala-core::$jsoniterVersion"
ivy"com.github.plokhotnyuk.jsoniter-scala::jsoniter-scala-core::$jsoniterVersion",
ivy"com.lihaoyi::unroll-annotation:$unrollVersion"
)

override def compileIvyDeps = Agg(
ivy"com.github.plokhotnyuk.jsoniter-scala::jsoniter-scala-macros::$jsoniterVersion"
)

override def scalacOptions = Seq("-Ywarn-unused", "-deprecation")

override def scalacPluginIvyDeps = T {
super.scalacPluginIvyDeps() ++
Agg(ivy"com.lihaoyi::unroll-plugin:$unrollVersion")
}
}

trait CommonTest extends ScalaModule with TestModule.Munit {
Expand Down
14 changes: 13 additions & 1 deletion config/src/bloop/config/Config.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package bloop.config

import scala.annotation.unroll

import bloop.config.PlatformFiles.Path
import bloop.config.PlatformFiles.emptyPath

Expand Down Expand Up @@ -164,6 +166,15 @@ object Config {
val All: List[String] = List(NoModule.id, CommonJSModule.id, ESModule.id)
}

sealed abstract class ModuleSplitStyleJS(val id: String)
object ModuleSplitStyleJS {
case object FewestModules extends ModuleSplitStyleJS("FewestModules")
case object SmallestModules extends ModuleSplitStyleJS("SmallestModules")
case object SmallModulesFor extends ModuleSplitStyleJS("SmallModulesFor")
val All: List[String] =
List(FewestModules.id, SmallestModules.id, SmallModulesFor.id)
}

case class JsConfig(
version: String,
mode: LinkerMode,
Expand All @@ -172,7 +183,8 @@ object Config {
jsdom: Option[Boolean],
output: Option[Path],
nodePath: Option[Path],
toolchain: List[Path]
toolchain: List[Path],
@unroll moduleSplitStyle: Option[ModuleSplitStyleJS] = None
) extends PlatformConfig

object JsConfig {
Expand Down
42 changes: 42 additions & 0 deletions config/src/bloop/config/ConfigCodecs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,48 @@ object ConfigCodecs {
}
}

implicit val codecModuleSplitStyleJS
: JsonValueCodec[Config.ModuleSplitStyleJS] = {
new JsonValueCodec[Config.ModuleSplitStyleJS] {
val nullValue: Config.ModuleSplitStyleJS =
null.asInstanceOf[Config.ModuleSplitStyleJS]
def encodeValue(x: Config.ModuleSplitStyleJS, out: JsonWriter): Unit = {
val str = x match {
case Config.ModuleSplitStyleJS.FewestModules =>
Config.ModuleSplitStyleJS.FewestModules.id
case Config.ModuleSplitStyleJS.SmallestModules =>
Config.ModuleSplitStyleJS.SmallestModules.id
case Config.ModuleSplitStyleJS.SmallModulesFor =>
Config.ModuleSplitStyleJS.SmallModulesFor.id
}
out.writeVal(str)
}
def decodeValue(
in: JsonReader,
default: Config.ModuleSplitStyleJS
): Config.ModuleSplitStyleJS =
if (in.isNextToken('"')) {
in.rollbackToken()
in.readString(null) match {
case Config.ModuleSplitStyleJS.FewestModules.id =>
Config.ModuleSplitStyleJS.FewestModules
case Config.ModuleSplitStyleJS.SmallestModules.id =>
Config.ModuleSplitStyleJS.SmallestModules
case Config.ModuleSplitStyleJS.SmallModulesFor.id =>
Config.ModuleSplitStyleJS.SmallModulesFor
case _ =>
in.decodeError(
s"Expected module split style ${Config.ModuleSplitStyleJS.All
.mkString("'", "', '", "'")}"
)
}
} else {
in.rollbackToken()
nullValue
}
}
}

implicit val codecJvmConfig: JsonValueCodec[Config.JvmConfig] =
JsonCodecMaker.makeWithRequiredCollectionFields[Config.JvmConfig]

Expand Down

0 comments on commit 4003978

Please sign in to comment.