Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated js-bridge with newest configuration #167

Closed
wants to merge 2 commits into from
Closed
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
28 changes: 21 additions & 7 deletions bridges/scalajs-1/src/main/scala/bloop/scalajs/JsBridge.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv
import org.scalajs.jsenv.nodejs.NodeJSEnv
import org.scalajs.linker.PathIRContainer
import org.scalajs.linker.PathOutputDirectory
import org.scalajs.linker.PathOutputFile
import org.scalajs.linker.StandardImpl
import org.scalajs.linker.interface.{ModuleKind => ScalaJSModuleKind, _}
import org.scalajs.linker.interface.{ModuleKind => ScalaJSModuleKind}
import org.scalajs.linker.interface.{ModuleSplitStyle => ScalaJSModuleKindSplitStyle, _}
import org.scalajs.logging.Level
import org.scalajs.logging.{Logger => JsLogger}
import org.scalajs.testing.adapter.TestAdapter
import org.scalajs.testing.adapter.TestAdapterInitializer
import java.nio.file.Files
import bloop.config.Config.ModuleSplitStyleJS

/**
* Defines operations provided by the Scala.JS 1.x toolchain.
Expand Down Expand Up @@ -66,6 +66,14 @@ object JsBridge {
case ModuleKindJS.ESModule => ScalaJSModuleKind.ESModule
}

val scalaJSModuleKindSplitStyle: Option[ScalaJSModuleKindSplitStyle] =
config.moduleSplitStyle.map {
case ModuleSplitStyleJS.FewestModules => ScalaJSModuleKindSplitStyle.FewestModules
case ModuleSplitStyleJS.SmallestModules => ScalaJSModuleKindSplitStyle.SmallestModules
case ModuleSplitStyleJS.SmallModulesFor(packages) =>
ScalaJSModuleKindSplitStyle.SmallModulesFor(packages)
}

val useClosure = isFullLinkJS && config.kind != ModuleKindJS.ESModule

val linkerConfig = StandardConfig()
Expand All @@ -74,7 +82,13 @@ object JsBridge {
.withModuleKind(scalaJSModuleKind)
.withSourceMap(config.emitSourceMaps)

StandardImpl.clearableLinker(linkerConfig)
(config.kind, scalaJSModuleKindSplitStyle) match {
case (ModuleKindJS.ESModule, Some(value)) =>
StandardImpl.clearableLinker(
linkerConfig.withModuleSplitStyle(value)
)
case (_, _) => StandardImpl.clearableLinker(linkerConfig)
}
}
}

Expand All @@ -98,15 +112,15 @@ object JsBridge {

val moduleInitializers = mainClass match {
case Some(mainClass) if runMain =>
logger.debug(s"Setting up main module initializers for ${project}")
logger.debug(s"Setting up main module initializers for $project")
List(ModuleInitializer.mainMethodWithArgs(mainClass, "main"))
case _ =>
if (runMain) {
logger.debug(s"Setting up no module initializers, commonjs module detected ${project}")
logger.debug(s"Setting up no module initializers, commonjs module detected $project")
Nil // If run is disabled, it's a commonjs module and we link with exports
} else {
// There is no main class, install the test module initializers
logger.debug(s"Setting up test module initializers for ${project}")
logger.debug(s"Setting up test module initializers for $project")
List(
ModuleInitializer.mainMethod(
TestAdapterInitializer.ModuleClassName,
Expand Down
2 changes: 1 addition & 1 deletion build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object Dependencies {

def asm = ivy"org.ow2.asm:asm:$asmVersion"
def asmUtil = ivy"org.ow2.asm:asm-util:$asmVersion"
def bloopConfig = ivy"ch.epfl.scala::bloop-config:2.0.0"
def bloopConfig = ivy"ch.epfl.scala::bloop-config:2.0.2"
def brave = ivy"io.zipkin.brave:brave:5.18.1"
def bsp4j = ivy"ch.epfl.scala:bsp4j:2.1.1"
def bsp4s = ivy"ch.epfl.scala::bsp4s:2.1.1"
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/test/scala/bloop/LoadProjectSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class LoadProjectSpec extends BloopHelpers {
@Test def LoadJavaProject(): Unit = {
// Make sure that when no scala setup is configured the project load succeeds (and no scala instance is defined)
val logger = new RecordingLogger()
val config0 = Config.File.dummyForTests
val config0 = Config.File.dummyForTests("JVM")
val project = config0.project
val configWithNoScala = config0.copy(config0.version, project.copy(scala = None))
val origin = TestUtil.syntheticOriginFor(AbsolutePath.completelyUnsafe(""))
Expand All @@ -25,7 +25,7 @@ class LoadProjectSpec extends BloopHelpers {

@Test def CustomWorkingDirectory(): Unit = {
val logger = new RecordingLogger()
val dummyForTest = Config.File.dummyForTests
val dummyForTest = Config.File.dummyForTests("JVM")
val origin = TestUtil.syntheticOriginFor(AbsolutePath.completelyUnsafe(""))
val project = Project.fromConfig(dummyForTest, origin, logger)
assert(
Expand Down
Loading