Skip to content

Commit

Permalink
Address comments: Add Module Splitting support in the sbt-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
gzm0 committed Sep 30, 2020
1 parent 50f1a78 commit d291eab
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
Expand Up @@ -123,15 +123,15 @@ private[sbtplugin] object ScalaJSPluginInternal {

scalaJSLinkerBox in key := new CacheBox,

scalaJSLinker in key := {
scalaJSLinker in legacyKey := {
val config = (scalaJSLinkerConfig in key).value
val box = (scalaJSLinkerBox in key).value
val linkerImpl = (scalaJSLinkerImpl in key).value

box.ensure(linkerImpl.clearableLinker(config))
},

scalaJSLinker in legacyKey := (scalaJSLinker in key).value,
scalaJSLinker in key := (scalaJSLinker in legacyKey).value,

// Have `clean` reset the state of the incremental linker
clean in (This, Zero, This) := {
Expand All @@ -140,7 +140,7 @@ private[sbtplugin] object ScalaJSPluginInternal {
()
},

usesScalaJSLinkerTag in key := {
usesScalaJSLinkerTag in legacyKey := {
val projectPart = thisProject.value.id
val configPart = configuration.value.name

Expand All @@ -152,7 +152,7 @@ private[sbtplugin] object ScalaJSPluginInternal {
Tags.Tag(s"uses-scalajs-linker-$projectPart-$configPart-$stagePart")
},

usesScalaJSLinkerTag in legacyKey := (usesScalaJSLinkerTag in key).value,
usesScalaJSLinkerTag in key := (usesScalaJSLinkerTag in legacyKey).value,

// Prevent this linker from being used concurrently
concurrentRestrictions in Global +=
Expand All @@ -164,7 +164,7 @@ private[sbtplugin] object ScalaJSPluginInternal {
scalaJSLinkerConfigFingerprint in key :=
StandardConfig.fingerprint((scalaJSLinkerConfig in key).value),

moduleName in legacyKey := (moduleName in key).value,
moduleName in key := (moduleName in legacyKey).value,

key := Def.taskDyn {
/* It is very important that we evaluate all of those `.value`s from
Expand Down Expand Up @@ -309,7 +309,7 @@ private[sbtplugin] object ScalaJSPluginInternal {
scalaJSStageSettings(Stage.FastOpt, linkJSDev, fastOptJS) ++
scalaJSStageSettings(Stage.FullOpt, linkJSProd, fullOptJS)
) ++ (
Seq(linkJSDev, linkJSProd).map { key =>
Seq(fastOptJS, fullOptJS).map { key =>
moduleName in key := {
val configSuffix = configuration.value match {
case Compile => ""
Expand Down Expand Up @@ -410,14 +410,17 @@ private[sbtplugin] object ScalaJSPluginInternal {
((crossTarget in fullOptJS).value /
((moduleName in fullOptJS).value + "-opt.js")),

scalaJSLinkerConfig in linkJSProd ~= { prevConfig =>
scalaJSLinkerConfig in fullOptJS ~= { prevConfig =>
val useClosure = prevConfig.moduleKind != ModuleKind.ESModule
prevConfig
.withSemantics(_.optimized)
.withClosureCompiler(useClosure)
.withCheckIR(true) // for safety, fullOpt is slow anyways.
},

scalaJSLinkerConfig in linkJSDev := (scalaJSLinkerConfig in fastOptJS).value,
scalaJSLinkerConfig in linkJSProd := (scalaJSLinkerConfig in fullOptJS).value,

scalaJSLinkerResult := Def.settingDyn {
scalaJSStage.value match {
case Stage.FastOpt => linkJSDev
Expand Down
Expand Up @@ -52,7 +52,7 @@ object QuickLinker {

@JSImport("fs", "promises")
@js.native
object PromisesFS extends js.Object {
private object PromisesFS extends js.Object {
def writeFile(path: String, data: Uint8Array): js.Promise[Unit] = js.native
}
}
Expand Up @@ -1472,7 +1472,7 @@ class ExportsTest {
}
}

@Test def top_level_export_field_is_writiable_accross_modules(): Unit = {
@Test def top_level_export_field_is_writable_accross_modules(): Unit = {
/* We write to basicVar exported above from a different object to test writing
* of static fields accross module boundaries (when module splitting is
* enabled).
Expand Down

0 comments on commit d291eab

Please sign in to comment.