diff --git a/bridges/scalajs-1/src/main/scala/bloop/scalajs/JsBridge.scala b/bridges/scalajs-1/src/main/scala/bloop/scalajs/JsBridge.scala index b189f22055..e2991dd779 100644 --- a/bridges/scalajs-1/src/main/scala/bloop/scalajs/JsBridge.scala +++ b/bridges/scalajs-1/src/main/scala/bloop/scalajs/JsBridge.scala @@ -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. @@ -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() @@ -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) + } } } @@ -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, diff --git a/build.sc b/build.sc index 991b53d329..9d06ea8786 100644 --- a/build.sc +++ b/build.sc @@ -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" diff --git a/frontend/src/test/scala/bloop/LoadProjectSpec.scala b/frontend/src/test/scala/bloop/LoadProjectSpec.scala index 3a93cf95ff..495ef74acc 100644 --- a/frontend/src/test/scala/bloop/LoadProjectSpec.scala +++ b/frontend/src/test/scala/bloop/LoadProjectSpec.scala @@ -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("")) @@ -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(