From 599afd6b31dd2b1c165f9f8a3a447a50129fbeff Mon Sep 17 00:00:00 2001 From: Simon Parten Date: Wed, 3 Apr 2024 09:08:29 +0200 Subject: [PATCH 01/27] Tidy up some deprecation warninga --- scalajslib/test/src/mill/scalajslib/MultiModuleTests.scala | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scalajslib/test/src/mill/scalajslib/MultiModuleTests.scala b/scalajslib/test/src/mill/scalajslib/MultiModuleTests.scala index b4adc5d2f2d..d6edd64e8bf 100644 --- a/scalajslib/test/src/mill/scalajslib/MultiModuleTests.scala +++ b/scalajslib/test/src/mill/scalajslib/MultiModuleTests.scala @@ -6,6 +6,7 @@ import mill.eval.EvaluatorPaths import mill.util._ import mill.scalalib._ import utest._ +import mill.scalajslib.internal.ScalaJSUtils object MultiModuleTests extends TestSuite { val workspacePath = TestUtil.getOutPathStatic() / "multi-module" val sourcePath = os.pwd / "scalajslib" / "test" / "resources" / "multi-module" @@ -39,10 +40,11 @@ object MultiModuleTests extends TestSuite { prepareWorkspace() def checkOpt(optimize: Boolean) = { - val task = if (optimize) MultiModule.client.fullOpt else MultiModule.client.fastOpt + val task = if (optimize) MultiModule.client.fullLinkJS else MultiModule.client.fastLinkJS val Right((linked, evalCount)) = evaluator(task) + val processedReport = ScalaJSUtils.getReportMainFilePathRef(linked) - val runOutput = ScalaJsUtils.runJS(linked.path) + val runOutput = ScalaJsUtils.runJS(processedReport.path) assert( evalCount > 0, runOutput == "Hello from Scala.js, result is: 3\n" From 9ea5bea22f3892505bf8778ab9a073a53daceed2 Mon Sep 17 00:00:00 2001 From: Simon Parten Date: Fri, 5 Apr 2024 08:02:46 +0200 Subject: [PATCH 02/27] . --- .devcontainer/devcontainer.json | 35 +++++++++++++++++++ build.sc | 4 ++- .../scalajslib/FullOptESModuleTests.scala | 2 +- .../worker/api/ScalaJSWorkerApi.scala | 1 + .../scalajslib/worker/ScalaJSWorkerImpl.scala | 4 +++ 5 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000000..35f7d65b0ae --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,35 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu +{ + "name": "Ubuntu", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "image": "mcr.microsoft.com/devcontainers/base:jammy", + "customizations": { + "vscode": { + "extensions": [ + "scalameta.metals", + "usernamehw.errorlens", + "vscjava.vscode-java-pack" + ] + } + }, + + // Features to add to the dev container. More info: https://containers.dev/features. + "features": { + "ghcr.io/devcontainers/features/java:1": { + "version":17 + } + }, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "yarn install & ./mill -v && ./millw __.prepareOffline && ./mill mill.bsp.BSP/install" + + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} \ No newline at end of file diff --git a/build.sc b/build.sc index 0c1f9e4a070..86196ed7bd2 100644 --- a/build.sc +++ b/build.sc @@ -189,6 +189,7 @@ object Deps { val fansi = ivy"com.lihaoyi::fansi:0.4.0" val jarjarabrams = ivy"com.eed3si9n.jarjarabrams::jarjar-abrams-core:1.14.0" val requests = ivy"com.lihaoyi::requests:0.8.0" + val esModuleRemap = ivy"com.armanbilge::scalajs-importmap:0.1.1" /** Used to manage transitive versions. */ val transitiveDeps = Seq( @@ -816,7 +817,8 @@ object scalajslib extends MillStableScalaModule with BuildInfo { Deps.Scalajs_1.scalajsEnvJsdomNodejs, Deps.Scalajs_1.scalajsEnvExoegoJsdomNodejs, Deps.Scalajs_1.scalajsEnvPhantomjs, - Deps.Scalajs_1.scalajsEnvSelenium + Deps.Scalajs_1.scalajsEnvSelenium, + Deps.esModuleRemap ) } } diff --git a/scalajslib/test/src/mill/scalajslib/FullOptESModuleTests.scala b/scalajslib/test/src/mill/scalajslib/FullOptESModuleTests.scala index 903975d8709..48c3a5ba61b 100644 --- a/scalajslib/test/src/mill/scalajslib/FullOptESModuleTests.scala +++ b/scalajslib/test/src/mill/scalajslib/FullOptESModuleTests.scala @@ -29,7 +29,7 @@ object FullOptESModuleTests extends TestSuite { test("fullOpt with ESModule moduleKind") { val result = - fullOptESModuleModuleEvaluator(FullOptESModuleModule.fullOptESModuleModule.fullOpt) + fullOptESModuleModuleEvaluator(FullOptESModuleModule.fullOptESModuleModule.fullLinkJS) assert(result.isRight) } } diff --git a/scalajslib/worker-api/src/mill/scalajslib/worker/api/ScalaJSWorkerApi.scala b/scalajslib/worker-api/src/mill/scalajslib/worker/api/ScalaJSWorkerApi.scala index d5d12345a24..74db2c5643c 100644 --- a/scalajslib/worker-api/src/mill/scalajslib/worker/api/ScalaJSWorkerApi.scala +++ b/scalajslib/worker-api/src/mill/scalajslib/worker/api/ScalaJSWorkerApi.scala @@ -18,6 +18,7 @@ private[scalajslib] trait ScalaJSWorkerApi { moduleSplitStyle: ModuleSplitStyle, outputPatterns: OutputPatterns, minify: Boolean + // esModuleMap: Map[String, String] ): Either[String, Report] def run(config: JsEnvConfig, report: Report): Unit diff --git a/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala b/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala index ce1b58ee70b..996a18f7a53 100644 --- a/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala +++ b/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala @@ -25,6 +25,8 @@ import org.scalajs.testing.adapter.{TestAdapterInitializer => TAI} import scala.collection.mutable import scala.ref.SoftReference +import com.armanbilge.sjsimportmap.ImportMappedIRFile + class ScalaJSWorkerImpl extends ScalaJSWorkerApi { private case class LinkerInput( isFullLinkJS: Boolean, @@ -200,6 +202,8 @@ class ScalaJSWorkerImpl extends ScalaJSWorkerApi { testInitializer } + val importMap = Map[String, String]() + val resultFuture = (for { (irContainers, _) <- irContainersAndPathsFuture irFiles <- irFileCacheCache.cached(irContainers) From d19c56b214ea6bd52e7e9c46ec8af0c46bdece23 Mon Sep 17 00:00:00 2001 From: Simon Parten Date: Fri, 5 Apr 2024 08:07:12 +0200 Subject: [PATCH 03/27] . --- .devcontainer/devcontainer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 35f7d65b0ae..9244e2d420b 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -25,7 +25,7 @@ // "forwardPorts": [], // Use 'postCreateCommand' to run commands after the container is created. - "postCreateCommand": "yarn install & ./mill -v && ./millw __.prepareOffline && ./mill mill.bsp.BSP/install" + "postCreateCommand": "./mill -v && ./millw __.prepareOffline && ./mill mill.bsp.BSP/install" // Configure tool-specific properties. // "customizations": {}, From 1e12f193b3cb6fffdefa8af6eff481934ae8be07 Mon Sep 17 00:00:00 2001 From: Simon Parten Date: Fri, 5 Apr 2024 06:29:37 +0000 Subject: [PATCH 04/27] . --- .devcontainer/devcontainer.json | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 9244e2d420b..39d0ba8600b 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -9,7 +9,11 @@ "extensions": [ "scalameta.metals", "usernamehw.errorlens", - "vscjava.vscode-java-pack" + "vscjava.vscode-java-pack", + "github.copilot", + "github.vscode-github-actions", + "github.vscode-pull-request-github", + "eamodio.gitlens" ] } }, @@ -25,7 +29,7 @@ // "forwardPorts": [], // Use 'postCreateCommand' to run commands after the container is created. - "postCreateCommand": "./mill -v && ./millw __.prepareOffline && ./mill mill.bsp.BSP/install" + "postCreateCommand": "./mill -v && ./millw __.prepareOffline && ./mill mill.bsp.BSP/install && ./mill __.compile" // Configure tool-specific properties. // "customizations": {}, From ff2f43431e99ef7b3c452e6553308c11d5abf590 Mon Sep 17 00:00:00 2001 From: Simon Parten Date: Fri, 5 Apr 2024 06:48:39 +0000 Subject: [PATCH 05/27] add node --- .devcontainer/devcontainer.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 39d0ba8600b..dc36e81f7a8 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -22,6 +22,8 @@ "features": { "ghcr.io/devcontainers/features/java:1": { "version":17 + }, + "ghcr.io/devcontainers/features/node:1":{ } }, @@ -29,7 +31,7 @@ // "forwardPorts": [], // Use 'postCreateCommand' to run commands after the container is created. - "postCreateCommand": "./mill -v && ./millw __.prepareOffline && ./mill mill.bsp.BSP/install && ./mill __.compile" + "postCreateCommand": "./mill -v && ./mill __.prepareOffline && ./mill mill.bsp.BSP/install && ./mill __.compile" // Configure tool-specific properties. // "customizations": {}, From 5b191f47fa000d13b19aa193c32566ba0a18297e Mon Sep 17 00:00:00 2001 From: Simon Parten Date: Fri, 5 Apr 2024 10:26:13 +0000 Subject: [PATCH 06/27] Add ability to remap ES module imports at link time --- .../src/mill/scalajslib/ScalaJSModule.scala | 17 +++-- .../scalajslib/worker/ScalaJSWorker.scala | 6 +- .../resources/esModuleRemap/src/app/App.scala | 16 +++++ .../mill/scalajslib/RemapEsModuleTests.scala | 58 +++++++++++++++++ .../worker/api/ScalaJSWorkerApi.scala | 4 +- .../scalajslib/worker/ScalaJSWorkerImpl.scala | 62 ++++++++++++------- 6 files changed, 132 insertions(+), 31 deletions(-) create mode 100644 scalajslib/test/resources/esModuleRemap/src/app/App.scala create mode 100644 scalajslib/test/src/mill/scalajslib/RemapEsModuleTests.scala diff --git a/scalajslib/src/mill/scalajslib/ScalaJSModule.scala b/scalajslib/src/mill/scalajslib/ScalaJSModule.scala index 0772733cd92..70fc84e10f4 100644 --- a/scalajslib/src/mill/scalajslib/ScalaJSModule.scala +++ b/scalajslib/src/mill/scalajslib/ScalaJSModule.scala @@ -73,7 +73,8 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => def scalaJSLinkerClasspath: T[Loose.Agg[PathRef]] = T { val commonDeps = Seq( - ivy"org.scala-js::scalajs-sbt-test-adapter:${scalaJSVersion()}" + ivy"org.scala-js::scalajs-sbt-test-adapter:${scalaJSVersion()}", + ivy"com.armanbilge::scalajs-importmap:0.1.1" ) val envDeps = scalaJSBinaryVersion() match { case "0.6" => @@ -130,7 +131,8 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => esFeatures = esFeatures(), moduleSplitStyle = moduleSplitStyle(), outputPatterns = scalaJSOutputPatterns(), - minify = scalaJSMinify() + minify = scalaJSMinify(), + esModuleMap = esModuleRemap() ) } @@ -172,7 +174,8 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => esFeatures: ESFeatures, moduleSplitStyle: ModuleSplitStyle, outputPatterns: OutputPatterns, - minify: Boolean + minify: Boolean, + esModuleMap: Map[String, String] )(implicit ctx: mill.api.Ctx): Result[Report] = { val outputPath = ctx.dest @@ -192,7 +195,8 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => esFeatures = esFeatures, moduleSplitStyle = moduleSplitStyle, outputPatterns = outputPatterns, - minify = minify + minify = minify, + esModuleMap = esModuleMap ) } @@ -266,6 +270,8 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => def scalaJSOptimizer: Target[Boolean] = T { true } + def esModuleRemap: Target[Map[String, String]] = T { Map.empty[String, String] } + /** Whether to emit a source map. */ def scalaJSSourceMap: Target[Boolean] = T { true } @@ -346,7 +352,8 @@ trait TestScalaJSModule extends ScalaJSModule with TestModule { esFeatures = esFeatures(), moduleSplitStyle = moduleSplitStyle(), outputPatterns = scalaJSOutputPatterns(), - minify = scalaJSMinify() + minify = scalaJSMinify(), + esModuleMap = esModuleRemap() ) } diff --git a/scalajslib/src/mill/scalajslib/worker/ScalaJSWorker.scala b/scalajslib/src/mill/scalajslib/worker/ScalaJSWorker.scala index 29c3f5aa3c9..f0120829541 100644 --- a/scalajslib/src/mill/scalajslib/worker/ScalaJSWorker.scala +++ b/scalajslib/src/mill/scalajslib/worker/ScalaJSWorker.scala @@ -161,7 +161,8 @@ private[scalajslib] class ScalaJSWorker extends AutoCloseable { esFeatures: api.ESFeatures, moduleSplitStyle: api.ModuleSplitStyle, outputPatterns: api.OutputPatterns, - minify: Boolean + minify: Boolean, + esModuleMap : Map[String, String] )(implicit ctx: Ctx.Home): Result[api.Report] = { bridge(toolsClasspath).link( runClasspath = runClasspath.iterator.map(_.path.toNIO).toSeq, @@ -176,7 +177,8 @@ private[scalajslib] class ScalaJSWorker extends AutoCloseable { esFeatures = toWorkerApi(esFeatures), moduleSplitStyle = toWorkerApi(moduleSplitStyle), outputPatterns = toWorkerApi(outputPatterns), - minify = minify + minify = minify, + esModuleMap = esModuleMap ) match { case Right(report) => Result.Success(fromWorkerApi(report)) case Left(message) => Result.Failure(message) diff --git a/scalajslib/test/resources/esModuleRemap/src/app/App.scala b/scalajslib/test/resources/esModuleRemap/src/app/App.scala new file mode 100644 index 00000000000..d2cc0b36475 --- /dev/null +++ b/scalajslib/test/resources/esModuleRemap/src/app/App.scala @@ -0,0 +1,16 @@ +package app + +import scala.scalajs.js +import scala.scalajs.js.annotation._ + +object App { + def main(args: Array[String]): Unit = { + println(linspace(-10.0, 10.0, 10)) + } +} + +@js.native +@JSImport("@stdlib/linspace", JSImport.Default) +object linspace extends js.Object { + def apply(start: Double, stop: Double, num: Int): Any = js.native +} diff --git a/scalajslib/test/src/mill/scalajslib/RemapEsModuleTests.scala b/scalajslib/test/src/mill/scalajslib/RemapEsModuleTests.scala new file mode 100644 index 00000000000..9042b1c77a7 --- /dev/null +++ b/scalajslib/test/src/mill/scalajslib/RemapEsModuleTests.scala @@ -0,0 +1,58 @@ +package mill.scalajslib + +import mill.define.Discover +import mill.util.{TestEvaluator, TestUtil} +import utest._ +import mill.define.Target +import mill.scalajslib.api.ModuleKind + +object EsModuleRemapTests extends TestSuite { + val workspacePath = TestUtil.getOutPathStatic() / "esModuleRemap" + + val remapTo = "https://cdn.jsdelivr.net/gh/stdlib-js/array-base-linspace@esm/index.mjs" + + object EsModuleRemap extends TestUtil.BaseModule { + + object sourceMapModule extends ScalaJSModule { + override def millSourcePath = workspacePath + override def scalaVersion = sys.props.getOrElse("TEST_SCALA_2_13_VERSION", ???) + override def scalaJSVersion = "1.16.0" + override def scalaJSSourceMap = false + override def moduleKind = ModuleKind.ESModule + + override def esModuleRemap: Target[Map[String,String]] = Map( + "@stdlib/linspace" -> remapTo + ) + } + + override lazy val millDiscover = Discover[this.type] + } + + val millSourcePath = os.pwd / "scalajslib" / "test" / "resources" / "esModuleRemap" + + val evaluator = TestEvaluator.static(EsModuleRemap) + + val tests: Tests = Tests { + prepareWorkspace() + + test("should remap the esmodule") { + val Right((report, _)) = + evaluator(EsModuleRemap.sourceMapModule.fastLinkJS) + val publicModules = report.publicModules.toSeq + assert(publicModules.length == 1) + val main = publicModules.head + assert(main.jsFileName == "main.js") + val mainPath = report.dest.path / "main.js" + assert(os.exists(mainPath)) + val rawJs = os.read.lines(mainPath) + assert(rawJs(1).contains(remapTo)) + } + } + + def prepareWorkspace(): Unit = { + os.remove.all(workspacePath) + os.makeDir.all(workspacePath / os.up) + os.copy(millSourcePath, workspacePath) + } + +} diff --git a/scalajslib/worker-api/src/mill/scalajslib/worker/api/ScalaJSWorkerApi.scala b/scalajslib/worker-api/src/mill/scalajslib/worker/api/ScalaJSWorkerApi.scala index 74db2c5643c..be8d6316409 100644 --- a/scalajslib/worker-api/src/mill/scalajslib/worker/api/ScalaJSWorkerApi.scala +++ b/scalajslib/worker-api/src/mill/scalajslib/worker/api/ScalaJSWorkerApi.scala @@ -17,8 +17,8 @@ private[scalajslib] trait ScalaJSWorkerApi { esFeatures: ESFeatures, moduleSplitStyle: ModuleSplitStyle, outputPatterns: OutputPatterns, - minify: Boolean - // esModuleMap: Map[String, String] + minify: Boolean, + esModuleMap: Map[String, String] ): Either[String, Report] def run(config: JsEnvConfig, report: Report): Unit diff --git a/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala b/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala index 996a18f7a53..00bcd8e58cb 100644 --- a/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala +++ b/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala @@ -171,7 +171,8 @@ class ScalaJSWorkerImpl extends ScalaJSWorkerApi { esFeatures: ESFeatures, moduleSplitStyle: ModuleSplitStyle, outputPatterns: OutputPatterns, - minify: Boolean + minify: Boolean, + esModuleMap: Map[String, String] = Map[String, String]() ): Either[String, Report] = { // On Scala.js 1.2- we want to use the legacy mode either way since // the new mode is not supported and in tests we always use legacy = false @@ -202,25 +203,39 @@ class ScalaJSWorkerImpl extends ScalaJSWorkerApi { testInitializer } - val importMap = Map[String, String]() - val resultFuture = (for { (irContainers, _) <- irContainersAndPathsFuture - irFiles <- irFileCacheCache.cached(irContainers) + irFiles0 <- irFileCacheCache.cached(irContainers) + irFiles = if (esModuleMap.isEmpty) { + irFiles0 + } else { + val remapFct = esModuleMap.toSeq.foldLeft((in: String) => in){ case(fct, (s1, s2)) => + val fct2 : (String => String) = (in => in.replace(s1, s2)) + (in => fct(fct2(in))) + } + irFiles0.map{ImportMappedIRFile.fromIRFile(_)(remapFct) + } + } report <- if (useLegacy) { + // This uses the legacy linker interface, which is deprecated. The compiler will warn us about it, but the warnings are intentional in a legacy block. Suppress them. val jsFileName = "out.js" val jsFile = new File(dest, jsFileName).toPath() - var linkerOutput = LinkerOutput(PathOutputFile(jsFile)) + @annotation.nowarn + var linkerOutput = LinkerOutput(PathOutputFile(jsFile)) .withJSFileURI(java.net.URI.create(jsFile.getFileName.toString)) + val sourceMapNameOpt = Option.when(sourceMap)(s"${jsFile.getFileName}.map") - sourceMapNameOpt.foreach { sourceMapName => + sourceMapNameOpt.foreach { sourceMapName => val sourceMapFile = jsFile.resolveSibling(sourceMapName) + @annotation.nowarn + val outFct = PathOutputFile(sourceMapFile) linkerOutput = linkerOutput - .withSourceMap(PathOutputFile(sourceMapFile)) + .withSourceMap( outFct ) .withSourceMapURI(java.net.URI.create(sourceMapFile.getFileName.toString)) - } - linker.link(irFiles, moduleInitializers, linkerOutput, logger).map { + } + @annotation.nowarn + val report = linker.link(irFiles, moduleInitializers, linkerOutput, logger).map { file => Report( publicModules = Seq(Report.Module( @@ -232,6 +247,7 @@ class ScalaJSWorkerImpl extends ScalaJSWorkerApi { dest = dest ) } + report } else { val linkerOutput = PathOutputDirectory(dest.toPath()) linker.link( @@ -274,20 +290,22 @@ class ScalaJSWorkerImpl extends ScalaJSWorkerApi { else runConfig0 .withInheritErr(false) .withInheritOut(false) - .withOnOutputStream { case (Some(processOut), Some(processErr)) => - val sources = Seq( - (processOut, System.out, "spawnSubprocess.stdout", false, () => true), - (processErr, System.err, "spawnSubprocess.stderr", false, () => true) - ) - - for ((std, dest, name, checkAvailable, runningCheck) <- sources) { - val t = new Thread( - new mill.main.client.InputPumper(std, dest, checkAvailable, () => runningCheck()), - name + .withOnOutputStream { + case (Some(processOut), Some(processErr)) => + val sources = Seq( + (processOut, System.out, "spawnSubprocess.stdout", false, () => true), + (processErr, System.err, "spawnSubprocess.stderr", false, () => true) ) - t.setDaemon(true) - t.start() - } + + for ((std, dest, name, checkAvailable, runningCheck) <- sources) { + val t = new Thread( + new mill.main.client.InputPumper(std, dest, checkAvailable, () => runningCheck()), + name + ) + t.setDaemon(true) + t.start() + } + case _ => ??? // should not happen } Run.runInterruptible(env, input, runConfig) } From 96addd75ff59fb9e23b515020532e3865c1b347c Mon Sep 17 00:00:00 2001 From: Simon Parten Date: Fri, 5 Apr 2024 10:56:49 +0000 Subject: [PATCH 07/27] reformat --- .../scalajslib/worker/ScalaJSWorker.scala | 2 +- .../mill/scalajslib/RemapEsModuleTests.scala | 2 +- .../scalajslib/worker/ScalaJSWorkerImpl.scala | 29 +++++++++---------- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/scalajslib/src/mill/scalajslib/worker/ScalaJSWorker.scala b/scalajslib/src/mill/scalajslib/worker/ScalaJSWorker.scala index f0120829541..26a21c41e18 100644 --- a/scalajslib/src/mill/scalajslib/worker/ScalaJSWorker.scala +++ b/scalajslib/src/mill/scalajslib/worker/ScalaJSWorker.scala @@ -162,7 +162,7 @@ private[scalajslib] class ScalaJSWorker extends AutoCloseable { moduleSplitStyle: api.ModuleSplitStyle, outputPatterns: api.OutputPatterns, minify: Boolean, - esModuleMap : Map[String, String] + esModuleMap: Map[String, String] )(implicit ctx: Ctx.Home): Result[api.Report] = { bridge(toolsClasspath).link( runClasspath = runClasspath.iterator.map(_.path.toNIO).toSeq, diff --git a/scalajslib/test/src/mill/scalajslib/RemapEsModuleTests.scala b/scalajslib/test/src/mill/scalajslib/RemapEsModuleTests.scala index 9042b1c77a7..c429aed556d 100644 --- a/scalajslib/test/src/mill/scalajslib/RemapEsModuleTests.scala +++ b/scalajslib/test/src/mill/scalajslib/RemapEsModuleTests.scala @@ -20,7 +20,7 @@ object EsModuleRemapTests extends TestSuite { override def scalaJSSourceMap = false override def moduleKind = ModuleKind.ESModule - override def esModuleRemap: Target[Map[String,String]] = Map( + override def esModuleRemap: Target[Map[String, String]] = Map( "@stdlib/linspace" -> remapTo ) } diff --git a/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala b/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala index 00bcd8e58cb..0c5c7fc23c9 100644 --- a/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala +++ b/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala @@ -209,32 +209,31 @@ class ScalaJSWorkerImpl extends ScalaJSWorkerApi { irFiles = if (esModuleMap.isEmpty) { irFiles0 } else { - val remapFct = esModuleMap.toSeq.foldLeft((in: String) => in){ case(fct, (s1, s2)) => - val fct2 : (String => String) = (in => in.replace(s1, s2)) - (in => fct(fct2(in))) - } - irFiles0.map{ImportMappedIRFile.fromIRFile(_)(remapFct) + val remapFct = esModuleMap.toSeq.foldLeft((in: String) => in) { case (fct, (s1, s2)) => + val fct2: (String => String) = (in => in.replace(s1, s2)) + (in => fct(fct2(in))) } + irFiles0.map { ImportMappedIRFile.fromIRFile(_)(remapFct) } } report <- if (useLegacy) { - // This uses the legacy linker interface, which is deprecated. The compiler will warn us about it, but the warnings are intentional in a legacy block. Suppress them. + // This uses the legacy linker interface, which is deprecated. The compiler will warn us about it, but the warnings are intentional in a legacy block. Suppress them. val jsFileName = "out.js" val jsFile = new File(dest, jsFileName).toPath() - @annotation.nowarn - var linkerOutput = LinkerOutput(PathOutputFile(jsFile)) + @annotation.nowarn + var linkerOutput = LinkerOutput(PathOutputFile(jsFile)) .withJSFileURI(java.net.URI.create(jsFile.getFileName.toString)) - + val sourceMapNameOpt = Option.when(sourceMap)(s"${jsFile.getFileName}.map") - sourceMapNameOpt.foreach { sourceMapName => + sourceMapNameOpt.foreach { sourceMapName => val sourceMapFile = jsFile.resolveSibling(sourceMapName) - @annotation.nowarn + @annotation.nowarn val outFct = PathOutputFile(sourceMapFile) linkerOutput = linkerOutput - .withSourceMap( outFct ) + .withSourceMap(outFct) .withSourceMapURI(java.net.URI.create(sourceMapFile.getFileName.toString)) - } - @annotation.nowarn + } + @annotation.nowarn val report = linker.link(irFiles, moduleInitializers, linkerOutput, logger).map { file => Report( @@ -290,7 +289,7 @@ class ScalaJSWorkerImpl extends ScalaJSWorkerApi { else runConfig0 .withInheritErr(false) .withInheritOut(false) - .withOnOutputStream { + .withOnOutputStream { case (Some(processOut), Some(processErr)) => val sources = Seq( (processOut, System.out, "spawnSubprocess.stdout", false, () => true), From e524bc3eecc21c57bd4bba9bcf502b1d8d381b20 Mon Sep 17 00:00:00 2001 From: Simon Parten Date: Fri, 5 Apr 2024 13:29:09 +0000 Subject: [PATCH 08/27] Let's see if this fixes classpath issues. --- .../src/mill/scalajslib/ScalaJSModule.scala | 17 ++++++++++++----- .../mill/scalajslib/RemapEsModuleTests.scala | 19 +++++++++++++++++++ .../scalajslib/worker/ScalaJSWorkerImpl.scala | 3 +++ 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/scalajslib/src/mill/scalajslib/ScalaJSModule.scala b/scalajslib/src/mill/scalajslib/ScalaJSModule.scala index 70fc84e10f4..ae686867feb 100644 --- a/scalajslib/src/mill/scalajslib/ScalaJSModule.scala +++ b/scalajslib/src/mill/scalajslib/ScalaJSModule.scala @@ -74,8 +74,13 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => def scalaJSLinkerClasspath: T[Loose.Agg[PathRef]] = T { val commonDeps = Seq( ivy"org.scala-js::scalajs-sbt-test-adapter:${scalaJSVersion()}", - ivy"com.armanbilge::scalajs-importmap:0.1.1" + ) + val maybeImportMap = scalaJSVersion() match { + case s"1.$n.$_" if n.toIntOption.exists(_ < 16) => Seq[Dep]() + case _ => Seq(ivy"com.armanbilge::scalajs-importmap:0.1.1") + } + val envDeps = scalaJSBinaryVersion() match { case "0.6" => Seq( @@ -90,13 +95,13 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => // we need to use the scala-library of the currently running mill resolveDependencies( repositoriesTask(), - (commonDeps.iterator ++ envDeps) + (commonDeps.iterator ++ envDeps ++ maybeImportMap) .map(Lib.depToBoundDep(_, mill.main.BuildInfo.scalaVersion, "")), ctx = Some(T.log) ) } - def scalaJSToolsClasspath = T { scalaJSWorkerClasspath() ++ scalaJSLinkerClasspath() } + def scalaJSToolsClasspath = T { scalaJSWorkerClasspath() ++ scalaJSLinkerClasspath()} def fastLinkJS: Target[Report] = T.persistent { linkTask(isFullLinkJS = false, forceOutJs = false)() @@ -268,9 +273,11 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => def moduleSplitStyle: Target[ModuleSplitStyle] = T { ModuleSplitStyle.FewestModules } - def scalaJSOptimizer: Target[Boolean] = T { true } + def scalaJSOptimizer: Target[Boolean] = T { true } - def esModuleRemap: Target[Map[String, String]] = T { Map.empty[String, String] } + def esModuleRemap: Target[Map[String, String]] = T { + Map.empty[String, String] + } /** Whether to emit a source map. */ def scalaJSSourceMap: Target[Boolean] = T { true } diff --git a/scalajslib/test/src/mill/scalajslib/RemapEsModuleTests.scala b/scalajslib/test/src/mill/scalajslib/RemapEsModuleTests.scala index c429aed556d..be64bb8eadc 100644 --- a/scalajslib/test/src/mill/scalajslib/RemapEsModuleTests.scala +++ b/scalajslib/test/src/mill/scalajslib/RemapEsModuleTests.scala @@ -25,6 +25,18 @@ object EsModuleRemapTests extends TestSuite { ) } + object OldJsModule extends ScalaJSModule { + override def millSourcePath = workspacePath + override def scalaVersion = sys.props.getOrElse("TEST_SCALA_2_13_VERSION", ???) + override def scalaJSVersion = "1.15.0" + override def scalaJSSourceMap = false + override def moduleKind = ModuleKind.ESModule + + override def esModuleRemap: Target[Map[String, String]] = Map( + "@stdlib/linspace" -> remapTo + ) + } + override lazy val millDiscover = Discover[this.type] } @@ -47,6 +59,13 @@ object EsModuleRemapTests extends TestSuite { val rawJs = os.read.lines(mainPath) assert(rawJs(1).contains(remapTo)) } + + test("should throw for older scalaJS versions") { + val Left(ex) = evaluator(EsModuleRemap.OldJsModule.fastLinkJS) + val error = ex.asFailing.get.toString() + assert(error.contains("will work with scalaJS 1.16 and above. You are using scalaJS 1.15.0")) + } + } def prepareWorkspace(): Unit = { diff --git a/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala b/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala index 0c5c7fc23c9..7cc5b6fa90c 100644 --- a/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala +++ b/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala @@ -209,6 +209,9 @@ class ScalaJSWorkerImpl extends ScalaJSWorkerApi { irFiles = if (esModuleMap.isEmpty) { irFiles0 } else { + if (!minorIsGreaterThanOrEqual(16)) { + throw new Exception(s"Remapping EsModule imports will work with scalaJS 1.16 and above. You are using scalaJS ${ScalaJSVersions.current} - consider upgrading?") + } val remapFct = esModuleMap.toSeq.foldLeft((in: String) => in) { case (fct, (s1, s2)) => val fct2: (String => String) = (in => in.replace(s1, s2)) (in => fct(fct2(in))) From fccc71543ba5f14c4daa15aee43998129b849e41 Mon Sep 17 00:00:00 2001 From: Simon Parten Date: Fri, 5 Apr 2024 13:31:09 +0000 Subject: [PATCH 09/27] formatting --- scalajslib/src/mill/scalajslib/ScalaJSModule.scala | 13 ++++++------- .../src/mill/scalajslib/RemapEsModuleTests.scala | 2 +- .../mill/scalajslib/worker/ScalaJSWorkerImpl.scala | 4 +++- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/scalajslib/src/mill/scalajslib/ScalaJSModule.scala b/scalajslib/src/mill/scalajslib/ScalaJSModule.scala index ae686867feb..f3eef5f5e1a 100644 --- a/scalajslib/src/mill/scalajslib/ScalaJSModule.scala +++ b/scalajslib/src/mill/scalajslib/ScalaJSModule.scala @@ -73,14 +73,13 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => def scalaJSLinkerClasspath: T[Loose.Agg[PathRef]] = T { val commonDeps = Seq( - ivy"org.scala-js::scalajs-sbt-test-adapter:${scalaJSVersion()}", - + ivy"org.scala-js::scalajs-sbt-test-adapter:${scalaJSVersion()}" ) val maybeImportMap = scalaJSVersion() match { case s"1.$n.$_" if n.toIntOption.exists(_ < 16) => Seq[Dep]() case _ => Seq(ivy"com.armanbilge::scalajs-importmap:0.1.1") } - + val envDeps = scalaJSBinaryVersion() match { case "0.6" => Seq( @@ -101,7 +100,7 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => ) } - def scalaJSToolsClasspath = T { scalaJSWorkerClasspath() ++ scalaJSLinkerClasspath()} + def scalaJSToolsClasspath = T { scalaJSWorkerClasspath() ++ scalaJSLinkerClasspath() } def fastLinkJS: Target[Report] = T.persistent { linkTask(isFullLinkJS = false, forceOutJs = false)() @@ -273,10 +272,10 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => def moduleSplitStyle: Target[ModuleSplitStyle] = T { ModuleSplitStyle.FewestModules } - def scalaJSOptimizer: Target[Boolean] = T { true } + def scalaJSOptimizer: Target[Boolean] = T { true } - def esModuleRemap: Target[Map[String, String]] = T { - Map.empty[String, String] + def esModuleRemap: Target[Map[String, String]] = T { + Map.empty[String, String] } /** Whether to emit a source map. */ diff --git a/scalajslib/test/src/mill/scalajslib/RemapEsModuleTests.scala b/scalajslib/test/src/mill/scalajslib/RemapEsModuleTests.scala index be64bb8eadc..7d6c136a1d1 100644 --- a/scalajslib/test/src/mill/scalajslib/RemapEsModuleTests.scala +++ b/scalajslib/test/src/mill/scalajslib/RemapEsModuleTests.scala @@ -62,7 +62,7 @@ object EsModuleRemapTests extends TestSuite { test("should throw for older scalaJS versions") { val Left(ex) = evaluator(EsModuleRemap.OldJsModule.fastLinkJS) - val error = ex.asFailing.get.toString() + val error = ex.asFailing.get.toString() assert(error.contains("will work with scalaJS 1.16 and above. You are using scalaJS 1.15.0")) } diff --git a/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala b/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala index 7cc5b6fa90c..f8a3879b73d 100644 --- a/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala +++ b/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala @@ -210,7 +210,9 @@ class ScalaJSWorkerImpl extends ScalaJSWorkerApi { irFiles0 } else { if (!minorIsGreaterThanOrEqual(16)) { - throw new Exception(s"Remapping EsModule imports will work with scalaJS 1.16 and above. You are using scalaJS ${ScalaJSVersions.current} - consider upgrading?") + throw new Exception( + s"Remapping EsModule imports will work with scalaJS 1.16 and above. You are using scalaJS ${ScalaJSVersions.current} - consider upgrading?" + ) } val remapFct = esModuleMap.toSeq.foldLeft((in: String) => in) { case (fct, (s1, s2)) => val fct2: (String => String) = (in => in.replace(s1, s2)) From 666fadedd12f7f419f28ca4c346827a4c5a2cc25 Mon Sep 17 00:00:00 2001 From: Simon Parten Date: Sat, 6 Apr 2024 15:53:54 +0000 Subject: [PATCH 10/27] Remove this unncessary default as per conversation --- .../worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala b/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala index f8a3879b73d..cb8d932ff03 100644 --- a/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala +++ b/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala @@ -172,7 +172,7 @@ class ScalaJSWorkerImpl extends ScalaJSWorkerApi { moduleSplitStyle: ModuleSplitStyle, outputPatterns: OutputPatterns, minify: Boolean, - esModuleMap: Map[String, String] = Map[String, String]() + esModuleMap: Map[String, String] ): Either[String, Report] = { // On Scala.js 1.2- we want to use the legacy mode either way since // the new mode is not supported and in tests we always use legacy = false From c41b15f37d0c114b24d2a7f7b65f0297b28047bd Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Tue, 9 Apr 2024 13:53:34 +0200 Subject: [PATCH 11/27] Update junixsocket from 2.9.0 to 2.9.1 (#3113) Pull request: https://github.com/com-lihaoyi/mill/pull/3113 --- build.sc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sc b/build.sc index 74cf0942618..db2be2bd917 100644 --- a/build.sc +++ b/build.sc @@ -138,7 +138,7 @@ object Deps { val fastparse = ivy"com.lihaoyi::fastparse:3.0.2" val flywayCore = ivy"org.flywaydb:flyway-core:8.5.13" val graphvizJava = ivy"guru.nidi:graphviz-java-all-j2v8:0.18.1" - val junixsocket = ivy"com.kohlschutter.junixsocket:junixsocket-core:2.9.0" + val junixsocket = ivy"com.kohlschutter.junixsocket:junixsocket-core:2.9.1" val jgraphtCore = ivy"org.jgrapht:jgrapht-core:1.4.0" // 1.5.0+ dont support JDK8 From e4a672e8c41b94daf74942ff30b9f6b30069a2cd Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Tue, 9 Apr 2024 13:54:02 +0200 Subject: [PATCH 12/27] Update mainargs from 0.6.2 to 0.6.3 (#3114) Pull request: https://github.com/com-lihaoyi/mill/pull/3114 --- build.sc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sc b/build.sc index db2be2bd917..c26270e177d 100644 --- a/build.sc +++ b/build.sc @@ -152,7 +152,7 @@ object Deps { val log4j2Core = ivy"org.apache.logging.log4j:log4j-core:2.23.0" val osLib = ivy"com.lihaoyi::os-lib:0.9.3" val pprint = ivy"com.lihaoyi::pprint:0.8.1" - val mainargs = ivy"com.lihaoyi::mainargs:0.6.2" + val mainargs = ivy"com.lihaoyi::mainargs:0.6.3" val millModuledefsVersion = "0.10.9" val millModuledefsString = s"com.lihaoyi::mill-moduledefs:${millModuledefsVersion}" val millModuledefs = ivy"${millModuledefsString}" From 247bee6ef1d653769a8c392443932ccfd51fde97 Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Tue, 9 Apr 2024 14:11:29 +0200 Subject: [PATCH 13/27] Update asm from 9.6 to 9.7 (#3112) Pull request: https://github.com/com-lihaoyi/mill/pull/3112 --- build.sc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sc b/build.sc index c26270e177d..b128e4d8de3 100644 --- a/build.sc +++ b/build.sc @@ -127,7 +127,7 @@ object Deps { val acyclic = ivy"com.lihaoyi:::acyclic:0.3.11" val ammoniteVersion = "3.0.0-M1" - val asmTree = ivy"org.ow2.asm:asm-tree:9.6" + val asmTree = ivy"org.ow2.asm:asm-tree:9.7" val bloopConfig = ivy"ch.epfl.scala::bloop-config:1.5.5" val coursier = ivy"io.get-coursier::coursier:2.1.9" From c28fd8a24432b4518719e3d58fc9a0954c9438c7 Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Tue, 9 Apr 2024 14:12:03 +0200 Subject: [PATCH 14/27] Update requests from 0.8.0 to 0.8.2 (#3115) Pull request: https://github.com/com-lihaoyi/mill/pull/3115 --- build.sc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sc b/build.sc index b128e4d8de3..3bd74de4a6d 100644 --- a/build.sc +++ b/build.sc @@ -188,7 +188,7 @@ object Deps { val bsp4j = ivy"ch.epfl.scala:bsp4j:2.2.0-M2" val fansi = ivy"com.lihaoyi::fansi:0.4.0" val jarjarabrams = ivy"com.eed3si9n.jarjarabrams::jarjar-abrams-core:1.14.0" - val requests = ivy"com.lihaoyi::requests:0.8.0" + val requests = ivy"com.lihaoyi::requests:0.8.2" val esModuleRemap = ivy"com.armanbilge::scalajs-importmap:0.1.1" /** Used to manage transitive versions. */ From b2d8f10bb86ca494c02a15b0f891d33e3694db00 Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Thu, 11 Apr 2024 08:24:32 +0200 Subject: [PATCH 15/27] Update semanticdb-scalac from 4.9.2 to 4.9.3 (#3116) Pull request: https://github.com/com-lihaoyi/mill/pull/3116 --- build.sc | 2 +- docs/antora.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.sc b/build.sc index 3bd74de4a6d..d7ec649d2a9 100644 --- a/build.sc +++ b/build.sc @@ -177,7 +177,7 @@ object Deps { val scalaparse = ivy"com.lihaoyi::scalaparse:${fastparse.version}" val scalatags = ivy"com.lihaoyi::scalatags:0.12.0" // keep in sync with doc/antora/antory.yml - val semanticDBscala = ivy"org.scalameta:::semanticdb-scalac:4.9.2" + val semanticDBscala = ivy"org.scalameta:::semanticdb-scalac:4.9.3" val semanticDbJava = ivy"com.sourcegraph:semanticdb-java:0.9.9" val sourcecode = ivy"com.lihaoyi::sourcecode:0.3.1" val upickle = ivy"com.lihaoyi::upickle:3.2.0" diff --git a/docs/antora.yml b/docs/antora.yml index ecaf7ee21f6..be2054f6274 100644 --- a/docs/antora.yml +++ b/docs/antora.yml @@ -8,6 +8,6 @@ asciidoc: mill-version: '0.11.7' mill-last-tag: '0.11.7' bsp-version: '2.2.0-M1' - example-semanticdb-version: '4.8.15' + example-semanticdb-version: '4.9.3' example-scala-2-13-version: '2.13.12' example-utest-version: '0.8.2' From 927e410a1583e949fc85c0c18db8e9cb5673b6cb Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Thu, 11 Apr 2024 08:24:57 +0200 Subject: [PATCH 16/27] Update transitive commons-io from 2.15.1 to 2.16.1 (#3117) Pull request: https://github.com/com-lihaoyi/mill/pull/3117 --- build.sc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sc b/build.sc index d7ec649d2a9..5a86f3c1ad1 100644 --- a/build.sc +++ b/build.sc @@ -194,7 +194,7 @@ object Deps { /** Used to manage transitive versions. */ val transitiveDeps = Seq( ivy"org.apache.ant:ant:1.10.14", - ivy"commons-io:commons-io:2.15.1", + ivy"commons-io:commons-io:2.16.1", ivy"com.google.code.gson:gson:2.10.1", ivy"com.google.protobuf:protobuf-java:3.25.3", ivy"com.google.guava:guava:33.1.0-jre", From 5023c652c295b0de0aa04136c44e655f1622c521 Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Fri, 12 Apr 2024 08:43:39 +0200 Subject: [PATCH 17/27] Update Scala Native to 0.5.0 (#3120) Pull Request: https://github.com/com-lihaoyi/mill/pull/3120 --- build.sc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sc b/build.sc index 5a86f3c1ad1..c1c0ba1c8e9 100644 --- a/build.sc +++ b/build.sc @@ -89,7 +89,7 @@ object Deps { } object Scalanative_0_5 { - val scalanativeVersion = "0.5.0-RC3" + val scalanativeVersion = "0.5.0" val scalanativeTools = ivy"org.scala-native::tools:${scalanativeVersion}" val scalanativeUtil = ivy"org.scala-native::util:${scalanativeVersion}" val scalanativeNir = ivy"org.scala-native::nir:${scalanativeVersion}" From a68c09b58c01785b8005ddf4518f049a8a9b9f2d Mon Sep 17 00:00:00 2001 From: Romain Gilles <58700468+romain-gilles-ultra@users.noreply.github.com> Date: Fri, 12 Apr 2024 16:30:13 +0200 Subject: [PATCH 18/27] Isolate scoverage modules from their parent modules (#3118) ## Context I encountered an issue with the way scoverage plugin alters the dependency tree of the test module by changing its module dependency from the `outer` module to the `outer.scoverage` module. This shadow modification of the dependency tree produces a side effect that impacts the IDEA configuration generation. When the IDEA configuration generation resolves the dependencies instead of using the outer module as a dependency for the test project it depends on the `outer.scoverage` module which should not be generated as it does not exist factually but more virtually. ## Solution Instead of modifying the dependency tree at compile-time I change it at runtime by removing the `outer.localRunClasspath()` from the `test.runClasspath()` and appending, instead, the `outer.scoverage.localRunClasspath()` This resolves the issue of modifying the dependency tree but introduces one more compilation as when the `outer.localRunClasspath()` is resolved it will force the compilation of the outer module. In the previous version only the `outer.scoverage` was compiled and not both of them. Pull request: https://github.com/com-lihaoyi/mill/pull/3118 --- .../contrib/scoverage/ScoverageModule.scala | 34 +++++------ example/misc/7-contrib-scoverage/build.sc | 60 +++++++++++++++++++ .../misc/7-contrib-scoverage/src/Foo.scala | 16 +++++ .../test/src/FooTests.scala | 16 +++++ 4 files changed, 107 insertions(+), 19 deletions(-) create mode 100644 example/misc/7-contrib-scoverage/build.sc create mode 100644 example/misc/7-contrib-scoverage/src/Foo.scala create mode 100644 example/misc/7-contrib-scoverage/test/src/FooTests.scala diff --git a/contrib/scoverage/src/mill/contrib/scoverage/ScoverageModule.scala b/contrib/scoverage/src/mill/contrib/scoverage/ScoverageModule.scala index fd603983b5b..eee13c22d86 100644 --- a/contrib/scoverage/src/mill/contrib/scoverage/ScoverageModule.scala +++ b/contrib/scoverage/src/mill/contrib/scoverage/ScoverageModule.scala @@ -3,8 +3,8 @@ package mill.contrib.scoverage import coursier.Repository import mill._ import mill.api.{Loose, PathRef, Result} -import mill.main.BuildInfo import mill.contrib.scoverage.api.ScoverageReportWorkerApi.ReportType +import mill.main.BuildInfo import mill.scalalib.api.ZincWorkerUtil import mill.scalalib.{Dep, DepSyntax, JavaModule, ScalaModule} import mill.util.Util.millProjectModule @@ -188,6 +188,7 @@ trait ScoverageModule extends ScalaModule { outer: ScalaModule => PathRef(T.dest) } + override def compileResources: T[Seq[PathRef]] = outer.compileResources override def generatedSources: Target[Seq[PathRef]] = T { outer.generatedSources() } override def allSources: Target[Seq[PathRef]] = T { outer.allSources() } override def moduleDeps: Seq[JavaModule] = outer.moduleDeps @@ -225,30 +226,25 @@ trait ScoverageModule extends ScalaModule { outer: ScalaModule => def xmlCoberturaReport(): Command[Unit] = T.command { doReport(ReportType.XmlCobertura) } def consoleReport(): Command[Unit] = T.command { doReport(ReportType.Console) } - override def skipIdea = outer.skipIdea + override def skipIdea = true } trait ScoverageTests extends ScalaTests { - override def upstreamAssemblyClasspath = T { - super.upstreamAssemblyClasspath() ++ - resolveDeps(T.task { - outer.scoverageRuntimeDeps().map(bindDependency()) - })() - } - override def compileClasspath = T { - super.compileClasspath() ++ - resolveDeps(T.task { - outer.scoverageRuntimeDeps().map(bindDependency()) - })() - } - override def runClasspath = T { - super.runClasspath() ++ + + /** + * Alter classfiles and resources from upstream modules and dependencies + * by removing the ones from outer.localRunClasspath() and replacing them + * with outer.scoverage.localRunClasspath() + */ + override def runClasspath: T[Seq[PathRef]] = T { + val outerLocalRunClasspath = outer.localRunClasspath().toSet + super.runClasspath().filterNot( + outerLocalRunClasspath + ) ++ + outer.scoverage.localRunClasspath() ++ resolveDeps(T.task { outer.scoverageRuntimeDeps().map(bindDependency()) })() } - - // Need the sources compiled with scoverage instrumentation to run. - override def moduleDeps: Seq[JavaModule] = Seq(outer.scoverage) } } diff --git a/example/misc/7-contrib-scoverage/build.sc b/example/misc/7-contrib-scoverage/build.sc new file mode 100644 index 00000000000..24b8a777610 --- /dev/null +++ b/example/misc/7-contrib-scoverage/build.sc @@ -0,0 +1,60 @@ +import mill._, scalalib._ +import $ivy.`com.lihaoyi::mill-contrib-scoverage:` + +import mill.contrib.scoverage._ + +object foo extends RootModule with ScoverageModule { + def scoverageVersion = "2.1.0" + def scalaVersion = "2.13.11" + def ivyDeps = Agg( + ivy"com.lihaoyi::scalatags:0.12.0", + ivy"com.lihaoyi::mainargs:0.6.2" + ) + + object test extends ScoverageTests /*with TestModule.Utest */{ + def ivyDeps = Agg(ivy"com.lihaoyi::utest:0.7.11") + def testFramework = "utest.runner.Framework" + } +} + +// This is a basic Mill build for a single `ScalaModule`, enhanced with +// Scoverage plugin. The root module extends the `ScoverageModule` and +// specifies the version of scoverage version to use here: `2.1.0`. This +// version can be changed if there is a newer one. Now you can call the +// scoverage targets to produce coverage reports. +// The sub test module extends `ScoverageTests` to transform the +// execution of the various testXXX targets to use scoverage and produce +// coverage data. +// This lets us perform the coverage operations but before that you +// must first run the test. +// `./mill test` then `./mill scoverage.consoleReport` and get your +// coverage into your console output. +// +// You can download this example project using the *download* link above +// if you want to try out the commands below yourself. The only requirement is +// that you have some version of the JVM installed; the `./mill` script takes +// care of any further dependencies that need to be downloaded. + +/** Usage + +> ./mill test # Run the tests and produce the coverage data +... ++ foo.FooTests.simple ...

hello

++ foo.FooTests.escaping ...

<hello>

+ +> ./mill resolve scoverage._ # List what tasks are available to run from scoverage +... +scoverage.consoleReport +... +scoverage.htmlReport +... +scoverage.xmlCoberturaReport +... +scoverage.xmlReport +... + +> ./mill scoverage.consoleReport +... +Statement coverage.: 16.67% +Branch coverage....: 100.00% +*/ diff --git a/example/misc/7-contrib-scoverage/src/Foo.scala b/example/misc/7-contrib-scoverage/src/Foo.scala new file mode 100644 index 00000000000..2de577a0280 --- /dev/null +++ b/example/misc/7-contrib-scoverage/src/Foo.scala @@ -0,0 +1,16 @@ +package foo +import scalatags.Text.all._ +import mainargs.{main, ParserForMethods} + +object Foo { + def generateHtml(text: String) = { + h1(text).toString + } + + @main + def main(text: String) = { + println(generateHtml(text)) + } + + def main(args: Array[String]): Unit = ParserForMethods(this).runOrExit(args) +} diff --git a/example/misc/7-contrib-scoverage/test/src/FooTests.scala b/example/misc/7-contrib-scoverage/test/src/FooTests.scala new file mode 100644 index 00000000000..c893d7d3f66 --- /dev/null +++ b/example/misc/7-contrib-scoverage/test/src/FooTests.scala @@ -0,0 +1,16 @@ +package foo +import utest._ +object FooTests extends TestSuite { + def tests = Tests { + test("simple") { + val result = Foo.generateHtml("hello") + assert(result == "

hello

") + result + } + test("escaping") { + val result = Foo.generateHtml("") + assert(result == "

<hello>

") + result + } + } +} From 5e6502787424929fbc4ecd1f68f2f3d5cf0641fc Mon Sep 17 00:00:00 2001 From: Simon Parten Date: Fri, 5 Apr 2024 08:02:46 +0200 Subject: [PATCH 19/27] . --- .devcontainer/devcontainer.json | 41 ------------------- .../scalajslib/worker/ScalaJSWorkerImpl.scala | 2 + 2 files changed, 2 insertions(+), 41 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index dc36e81f7a8..e69de29bb2d 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,41 +0,0 @@ -// For format details, see https://aka.ms/devcontainer.json. For config options, see the -// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu -{ - "name": "Ubuntu", - // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile - "image": "mcr.microsoft.com/devcontainers/base:jammy", - "customizations": { - "vscode": { - "extensions": [ - "scalameta.metals", - "usernamehw.errorlens", - "vscjava.vscode-java-pack", - "github.copilot", - "github.vscode-github-actions", - "github.vscode-pull-request-github", - "eamodio.gitlens" - ] - } - }, - - // Features to add to the dev container. More info: https://containers.dev/features. - "features": { - "ghcr.io/devcontainers/features/java:1": { - "version":17 - }, - "ghcr.io/devcontainers/features/node:1":{ - } - }, - - // Use 'forwardPorts' to make a list of ports inside the container available locally. - // "forwardPorts": [], - - // Use 'postCreateCommand' to run commands after the container is created. - "postCreateCommand": "./mill -v && ./mill __.prepareOffline && ./mill mill.bsp.BSP/install && ./mill __.compile" - - // Configure tool-specific properties. - // "customizations": {}, - - // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. - // "remoteUser": "root" -} \ No newline at end of file diff --git a/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala b/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala index cb8d932ff03..2403cab2b25 100644 --- a/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala +++ b/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala @@ -203,6 +203,8 @@ class ScalaJSWorkerImpl extends ScalaJSWorkerApi { testInitializer } + val importMap = Map[String, String]() + val resultFuture = (for { (irContainers, _) <- irContainersAndPathsFuture irFiles0 <- irFileCacheCache.cached(irContainers) From b307fe01d7e21dae0024e498613d5d93ec8cabd3 Mon Sep 17 00:00:00 2001 From: Simon Parten Date: Mon, 15 Apr 2024 15:08:30 +0000 Subject: [PATCH 20/27] Propogate Module remapping from build.sc to ScalaJsModule --- build.sc | 3 ++- scalajslib/src/mill/scalajslib/ScalaJSModule.scala | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/build.sc b/build.sc index c1c0ba1c8e9..6a506a50366 100644 --- a/build.sc +++ b/build.sc @@ -796,7 +796,8 @@ object scalajslib extends MillStableScalaModule with BuildInfo { formatDep(Deps.Scalajs_1.scalajsEnvExoegoJsdomNodejs) ), BuildInfo.Value("scalajsEnvPhantomJs", formatDep(Deps.Scalajs_1.scalajsEnvPhantomjs)), - BuildInfo.Value("scalajsEnvSelenium", formatDep(Deps.Scalajs_1.scalajsEnvSelenium)) + BuildInfo.Value("scalajsEnvSelenium", formatDep(Deps.Scalajs_1.scalajsEnvSelenium)), + BuildInfo.Value("scalaJsRemapDep", formatDep(Deps.esModuleRemap)) ) } diff --git a/scalajslib/src/mill/scalajslib/ScalaJSModule.scala b/scalajslib/src/mill/scalajslib/ScalaJSModule.scala index f3eef5f5e1a..4d26a19a735 100644 --- a/scalajslib/src/mill/scalajslib/ScalaJSModule.scala +++ b/scalajslib/src/mill/scalajslib/ScalaJSModule.scala @@ -75,9 +75,13 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => val commonDeps = Seq( ivy"org.scala-js::scalajs-sbt-test-adapter:${scalaJSVersion()}" ) - val maybeImportMap = scalaJSVersion() match { - case s"1.$n.$_" if n.toIntOption.exists(_ < 16) => Seq[Dep]() - case _ => Seq(ivy"com.armanbilge::scalajs-importmap:0.1.1") + val maybeImportMap = (scalaJSVersion(), esModuleRemap()) match { + case (s"1.$n.$_", _) if n.toIntOption.exists(_ < 16) => Seq[Dep]() + case (_, importMap) => + if (importMap.isEmpty) + Seq[Dep]() + else + Seq(ivy"${ScalaJSBuildInfo.scalaJsRemapDep}") } val envDeps = scalaJSBinaryVersion() match { From e096503149fe59f0671d607167f106750d53c75c Mon Sep 17 00:00:00 2001 From: Simon Parten Date: Mon, 15 Apr 2024 15:16:02 +0000 Subject: [PATCH 21/27] dev container --- .devcontainer/devcontainer.json | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index e69de29bb2d..dc36e81f7a8 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,41 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu +{ + "name": "Ubuntu", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "image": "mcr.microsoft.com/devcontainers/base:jammy", + "customizations": { + "vscode": { + "extensions": [ + "scalameta.metals", + "usernamehw.errorlens", + "vscjava.vscode-java-pack", + "github.copilot", + "github.vscode-github-actions", + "github.vscode-pull-request-github", + "eamodio.gitlens" + ] + } + }, + + // Features to add to the dev container. More info: https://containers.dev/features. + "features": { + "ghcr.io/devcontainers/features/java:1": { + "version":17 + }, + "ghcr.io/devcontainers/features/node:1":{ + } + }, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "./mill -v && ./mill __.prepareOffline && ./mill mill.bsp.BSP/install && ./mill __.compile" + + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} \ No newline at end of file From 77903ea4352916f3afe3f89ba9c4e849c4aad564 Mon Sep 17 00:00:00 2001 From: Simon Parten Date: Mon, 15 Apr 2024 15:37:46 +0000 Subject: [PATCH 22/27] Remove whitespace - reformat --- scalajslib/src/mill/scalajslib/ScalaJSModule.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scalajslib/src/mill/scalajslib/ScalaJSModule.scala b/scalajslib/src/mill/scalajslib/ScalaJSModule.scala index 4d26a19a735..9c9929b1647 100644 --- a/scalajslib/src/mill/scalajslib/ScalaJSModule.scala +++ b/scalajslib/src/mill/scalajslib/ScalaJSModule.scala @@ -77,10 +77,10 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => ) val maybeImportMap = (scalaJSVersion(), esModuleRemap()) match { case (s"1.$n.$_", _) if n.toIntOption.exists(_ < 16) => Seq[Dep]() - case (_, importMap) => + case (_, importMap) => if (importMap.isEmpty) Seq[Dep]() - else + else Seq(ivy"${ScalaJSBuildInfo.scalaJsRemapDep}") } From f8bba2b544db48fa743cb40faacbfc1528413844 Mon Sep 17 00:00:00 2001 From: Simon Parten Date: Mon, 15 Apr 2024 15:52:29 +0000 Subject: [PATCH 23/27] See if this passes tests --- .devcontainer/devcontainer.json | 41 ------------------- .../scalajslib/FullOptESModuleTests.scala | 2 +- .../mill/scalajslib/MultiModuleTests.scala | 6 +-- .../scalajslib/worker/ScalaJSWorkerImpl.scala | 13 +----- 4 files changed, 5 insertions(+), 57 deletions(-) delete mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json deleted file mode 100644 index dc36e81f7a8..00000000000 --- a/.devcontainer/devcontainer.json +++ /dev/null @@ -1,41 +0,0 @@ -// For format details, see https://aka.ms/devcontainer.json. For config options, see the -// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu -{ - "name": "Ubuntu", - // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile - "image": "mcr.microsoft.com/devcontainers/base:jammy", - "customizations": { - "vscode": { - "extensions": [ - "scalameta.metals", - "usernamehw.errorlens", - "vscjava.vscode-java-pack", - "github.copilot", - "github.vscode-github-actions", - "github.vscode-pull-request-github", - "eamodio.gitlens" - ] - } - }, - - // Features to add to the dev container. More info: https://containers.dev/features. - "features": { - "ghcr.io/devcontainers/features/java:1": { - "version":17 - }, - "ghcr.io/devcontainers/features/node:1":{ - } - }, - - // Use 'forwardPorts' to make a list of ports inside the container available locally. - // "forwardPorts": [], - - // Use 'postCreateCommand' to run commands after the container is created. - "postCreateCommand": "./mill -v && ./mill __.prepareOffline && ./mill mill.bsp.BSP/install && ./mill __.compile" - - // Configure tool-specific properties. - // "customizations": {}, - - // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. - // "remoteUser": "root" -} \ No newline at end of file diff --git a/scalajslib/test/src/mill/scalajslib/FullOptESModuleTests.scala b/scalajslib/test/src/mill/scalajslib/FullOptESModuleTests.scala index 48c3a5ba61b..903975d8709 100644 --- a/scalajslib/test/src/mill/scalajslib/FullOptESModuleTests.scala +++ b/scalajslib/test/src/mill/scalajslib/FullOptESModuleTests.scala @@ -29,7 +29,7 @@ object FullOptESModuleTests extends TestSuite { test("fullOpt with ESModule moduleKind") { val result = - fullOptESModuleModuleEvaluator(FullOptESModuleModule.fullOptESModuleModule.fullLinkJS) + fullOptESModuleModuleEvaluator(FullOptESModuleModule.fullOptESModuleModule.fullOpt) assert(result.isRight) } } diff --git a/scalajslib/test/src/mill/scalajslib/MultiModuleTests.scala b/scalajslib/test/src/mill/scalajslib/MultiModuleTests.scala index d6edd64e8bf..b4adc5d2f2d 100644 --- a/scalajslib/test/src/mill/scalajslib/MultiModuleTests.scala +++ b/scalajslib/test/src/mill/scalajslib/MultiModuleTests.scala @@ -6,7 +6,6 @@ import mill.eval.EvaluatorPaths import mill.util._ import mill.scalalib._ import utest._ -import mill.scalajslib.internal.ScalaJSUtils object MultiModuleTests extends TestSuite { val workspacePath = TestUtil.getOutPathStatic() / "multi-module" val sourcePath = os.pwd / "scalajslib" / "test" / "resources" / "multi-module" @@ -40,11 +39,10 @@ object MultiModuleTests extends TestSuite { prepareWorkspace() def checkOpt(optimize: Boolean) = { - val task = if (optimize) MultiModule.client.fullLinkJS else MultiModule.client.fastLinkJS + val task = if (optimize) MultiModule.client.fullOpt else MultiModule.client.fastOpt val Right((linked, evalCount)) = evaluator(task) - val processedReport = ScalaJSUtils.getReportMainFilePathRef(linked) - val runOutput = ScalaJsUtils.runJS(processedReport.path) + val runOutput = ScalaJsUtils.runJS(linked.path) assert( evalCount > 0, runOutput == "Hello from Scala.js, result is: 3\n" diff --git a/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala b/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala index 2403cab2b25..661418bcb49 100644 --- a/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala +++ b/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala @@ -203,8 +203,6 @@ class ScalaJSWorkerImpl extends ScalaJSWorkerApi { testInitializer } - val importMap = Map[String, String]() - val resultFuture = (for { (irContainers, _) <- irContainersAndPathsFuture irFiles0 <- irFileCacheCache.cached(irContainers) @@ -224,24 +222,18 @@ class ScalaJSWorkerImpl extends ScalaJSWorkerApi { } report <- if (useLegacy) { - // This uses the legacy linker interface, which is deprecated. The compiler will warn us about it, but the warnings are intentional in a legacy block. Suppress them. val jsFileName = "out.js" val jsFile = new File(dest, jsFileName).toPath() - @annotation.nowarn var linkerOutput = LinkerOutput(PathOutputFile(jsFile)) .withJSFileURI(java.net.URI.create(jsFile.getFileName.toString)) - val sourceMapNameOpt = Option.when(sourceMap)(s"${jsFile.getFileName}.map") sourceMapNameOpt.foreach { sourceMapName => val sourceMapFile = jsFile.resolveSibling(sourceMapName) - @annotation.nowarn - val outFct = PathOutputFile(sourceMapFile) linkerOutput = linkerOutput - .withSourceMap(outFct) + .withSourceMap(PathOutputFile(sourceMapFile)) .withSourceMapURI(java.net.URI.create(sourceMapFile.getFileName.toString)) } - @annotation.nowarn - val report = linker.link(irFiles, moduleInitializers, linkerOutput, logger).map { + linker.link(irFiles, moduleInitializers, linkerOutput, logger).map { file => Report( publicModules = Seq(Report.Module( @@ -253,7 +245,6 @@ class ScalaJSWorkerImpl extends ScalaJSWorkerApi { dest = dest ) } - report } else { val linkerOutput = PathOutputDirectory(dest.toPath()) linker.link( From 5eae1190c9cce0586875cfcb0d10ee470192ac3f Mon Sep 17 00:00:00 2001 From: Simon Parten Date: Mon, 15 Apr 2024 15:57:00 +0000 Subject: [PATCH 24/27] No need to change this --- .../1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala b/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala index 661418bcb49..ad253cac232 100644 --- a/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala +++ b/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala @@ -287,8 +287,7 @@ class ScalaJSWorkerImpl extends ScalaJSWorkerApi { else runConfig0 .withInheritErr(false) .withInheritOut(false) - .withOnOutputStream { - case (Some(processOut), Some(processErr)) => + .withOnOutputStream { case (Some(processOut), Some(processErr)) => val sources = Seq( (processOut, System.out, "spawnSubprocess.stdout", false, () => true), (processErr, System.err, "spawnSubprocess.stderr", false, () => true) @@ -302,7 +301,6 @@ class ScalaJSWorkerImpl extends ScalaJSWorkerApi { t.setDaemon(true) t.start() } - case _ => ??? // should not happen } Run.runInterruptible(env, input, runConfig) } From 68b814b7c0adf750285be8c5be3efc8c7b29e204 Mon Sep 17 00:00:00 2001 From: Simon Parten Date: Tue, 16 Apr 2024 05:33:12 +0000 Subject: [PATCH 25/27] reformat --- .../scalajslib/worker/ScalaJSWorkerImpl.scala | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala b/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala index ad253cac232..b228476a240 100644 --- a/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala +++ b/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala @@ -288,19 +288,19 @@ class ScalaJSWorkerImpl extends ScalaJSWorkerApi { .withInheritErr(false) .withInheritOut(false) .withOnOutputStream { case (Some(processOut), Some(processErr)) => - val sources = Seq( - (processOut, System.out, "spawnSubprocess.stdout", false, () => true), - (processErr, System.err, "spawnSubprocess.stderr", false, () => true) - ) + val sources = Seq( + (processOut, System.out, "spawnSubprocess.stdout", false, () => true), + (processErr, System.err, "spawnSubprocess.stderr", false, () => true) + ) - for ((std, dest, name, checkAvailable, runningCheck) <- sources) { - val t = new Thread( - new mill.main.client.InputPumper(std, dest, checkAvailable, () => runningCheck()), - name - ) - t.setDaemon(true) - t.start() - } + for ((std, dest, name, checkAvailable, runningCheck) <- sources) { + val t = new Thread( + new mill.main.client.InputPumper(std, dest, checkAvailable, () => runningCheck()), + name + ) + t.setDaemon(true) + t.start() + } } Run.runInterruptible(env, input, runConfig) } From d44de38fddc6ebbd5d6351ca82a7260fbe8e27c6 Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Fri, 26 Apr 2024 17:43:15 +0200 Subject: [PATCH 26/27] Apply review suggestions --- build.sc | 6 ++--- .../src/mill/scalajslib/ScalaJSModule.scala | 25 ++++++++----------- .../src/mill/scalajslib/api/ScalaJSApi.scala | 8 ++++++ .../scalajslib/worker/ScalaJSWorker.scala | 11 ++++++-- .../mill/scalajslib/RemapEsModuleTests.scala | 10 ++++---- .../worker/api/ScalaJSWorkerApi.scala | 7 +++++- .../scalajslib/worker/ScalaJSWorkerImpl.scala | 21 +++++++++------- 7 files changed, 54 insertions(+), 34 deletions(-) diff --git a/build.sc b/build.sc index 5be7562f6f9..34f5fec0c65 100644 --- a/build.sc +++ b/build.sc @@ -78,6 +78,7 @@ object Deps { val scalajsEnvSelenium = ivy"org.scala-js::scalajs-env-selenium:1.1.1" val scalajsSbtTestAdapter = ivy"org.scala-js::scalajs-sbt-test-adapter:${scalaJsVersion}" val scalajsLinker = ivy"org.scala-js::scalajs-linker:${scalaJsVersion}" + val scalajsImportMap = ivy"com.armanbilge::scalajs-importmap:0.1.1" } object Scalanative_0_4 { @@ -189,7 +190,6 @@ object Deps { val fansi = ivy"com.lihaoyi::fansi:0.4.0" val jarjarabrams = ivy"com.eed3si9n.jarjarabrams::jarjar-abrams-core:1.14.0" val requests = ivy"com.lihaoyi::requests:0.8.2" - val esModuleRemap = ivy"com.armanbilge::scalajs-importmap:0.1.1" /** Used to manage transitive versions. */ @@ -798,7 +798,7 @@ object scalajslib extends MillStableScalaModule with BuildInfo { ), BuildInfo.Value("scalajsEnvPhantomJs", formatDep(Deps.Scalajs_1.scalajsEnvPhantomjs)), BuildInfo.Value("scalajsEnvSelenium", formatDep(Deps.Scalajs_1.scalajsEnvSelenium)), - BuildInfo.Value("scalaJsRemapDep", formatDep(Deps.esModuleRemap)) + BuildInfo.Value("scalajsImportMap", formatDep(Deps.Scalajs_1.scalajsImportMap)) ) } @@ -820,7 +820,7 @@ object scalajslib extends MillStableScalaModule with BuildInfo { Deps.Scalajs_1.scalajsEnvExoegoJsdomNodejs, Deps.Scalajs_1.scalajsEnvPhantomjs, Deps.Scalajs_1.scalajsEnvSelenium, - Deps.esModuleRemap + Deps.Scalajs_1.scalajsImportMap ) } } diff --git a/scalajslib/src/mill/scalajslib/ScalaJSModule.scala b/scalajslib/src/mill/scalajslib/ScalaJSModule.scala index 9c9929b1647..582cdde5cae 100644 --- a/scalajslib/src/mill/scalajslib/ScalaJSModule.scala +++ b/scalajslib/src/mill/scalajslib/ScalaJSModule.scala @@ -75,13 +75,10 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => val commonDeps = Seq( ivy"org.scala-js::scalajs-sbt-test-adapter:${scalaJSVersion()}" ) - val maybeImportMap = (scalaJSVersion(), esModuleRemap()) match { - case (s"1.$n.$_", _) if n.toIntOption.exists(_ < 16) => Seq[Dep]() - case (_, importMap) => - if (importMap.isEmpty) - Seq[Dep]() - else - Seq(ivy"${ScalaJSBuildInfo.scalaJsRemapDep}") + val scalajsImportMapDeps = scalaJSVersion() match { + case s"1.$n.$_" if n.toIntOption.exists(_ >= 16) && scalaJSImportMap().nonEmpty => + Seq(ivy"${ScalaJSBuildInfo.scalajsImportMap}") + case _ => Seq.empty[Dep] } val envDeps = scalaJSBinaryVersion() match { @@ -98,7 +95,7 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => // we need to use the scala-library of the currently running mill resolveDependencies( repositoriesTask(), - (commonDeps.iterator ++ envDeps ++ maybeImportMap) + (commonDeps.iterator ++ envDeps ++ scalajsImportMapDeps) .map(Lib.depToBoundDep(_, mill.main.BuildInfo.scalaVersion, "")), ctx = Some(T.log) ) @@ -140,7 +137,7 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => moduleSplitStyle = moduleSplitStyle(), outputPatterns = scalaJSOutputPatterns(), minify = scalaJSMinify(), - esModuleMap = esModuleRemap() + importMap = scalaJSImportMap() ) } @@ -183,7 +180,7 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => moduleSplitStyle: ModuleSplitStyle, outputPatterns: OutputPatterns, minify: Boolean, - esModuleMap: Map[String, String] + importMap: Seq[ESModuleImportMapping] )(implicit ctx: mill.api.Ctx): Result[Report] = { val outputPath = ctx.dest @@ -204,7 +201,7 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => moduleSplitStyle = moduleSplitStyle, outputPatterns = outputPatterns, minify = minify, - esModuleMap = esModuleMap + importMap = importMap ) } @@ -278,8 +275,8 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => def scalaJSOptimizer: Target[Boolean] = T { true } - def esModuleRemap: Target[Map[String, String]] = T { - Map.empty[String, String] + def scalaJSImportMap: Target[Seq[ESModuleImportMapping]] = T { + Seq.empty[ESModuleImportMapping] } /** Whether to emit a source map. */ @@ -363,7 +360,7 @@ trait TestScalaJSModule extends ScalaJSModule with TestModule { moduleSplitStyle = moduleSplitStyle(), outputPatterns = scalaJSOutputPatterns(), minify = scalaJSMinify(), - esModuleMap = esModuleRemap() + importMap = scalaJSImportMap() ) } diff --git a/scalajslib/src/mill/scalajslib/api/ScalaJSApi.scala b/scalajslib/src/mill/scalajslib/api/ScalaJSApi.scala index fd2412870db..4f6d9751ddc 100644 --- a/scalajslib/src/mill/scalajslib/api/ScalaJSApi.scala +++ b/scalajslib/src/mill/scalajslib/api/ScalaJSApi.scala @@ -270,3 +270,11 @@ object OutputPatterns { implicit val rw: RW[OutputPatterns] = macroRW[OutputPatterns] } + +sealed trait ESModuleImportMapping +object ESModuleImportMapping { + case class Prefix(prefix: String, replacement: String) extends ESModuleImportMapping + + implicit def rwPrefix: RW[Prefix] = macroRW + implicit def rw: RW[ESModuleImportMapping] = macroRW +} diff --git a/scalajslib/src/mill/scalajslib/worker/ScalaJSWorker.scala b/scalajslib/src/mill/scalajslib/worker/ScalaJSWorker.scala index 26a21c41e18..840a9cac005 100644 --- a/scalajslib/src/mill/scalajslib/worker/ScalaJSWorker.scala +++ b/scalajslib/src/mill/scalajslib/worker/ScalaJSWorker.scala @@ -147,6 +147,13 @@ private[scalajslib] class ScalaJSWorker extends AutoCloseable { ) } + private def toWorkerApi(importMap: api.ESModuleImportMapping): workerApi.ESModuleImportMapping = { + importMap match { + case api.ESModuleImportMapping.Prefix(prefix, replacement) => + workerApi.ESModuleImportMapping.Prefix(prefix, replacement) + } + } + def link( toolsClasspath: Agg[mill.PathRef], runClasspath: Agg[mill.PathRef], @@ -162,7 +169,7 @@ private[scalajslib] class ScalaJSWorker extends AutoCloseable { moduleSplitStyle: api.ModuleSplitStyle, outputPatterns: api.OutputPatterns, minify: Boolean, - esModuleMap: Map[String, String] + importMap: Seq[api.ESModuleImportMapping] )(implicit ctx: Ctx.Home): Result[api.Report] = { bridge(toolsClasspath).link( runClasspath = runClasspath.iterator.map(_.path.toNIO).toSeq, @@ -178,7 +185,7 @@ private[scalajslib] class ScalaJSWorker extends AutoCloseable { moduleSplitStyle = toWorkerApi(moduleSplitStyle), outputPatterns = toWorkerApi(outputPatterns), minify = minify, - esModuleMap = esModuleMap + importMap = importMap.map(toWorkerApi) ) match { case Right(report) => Result.Success(fromWorkerApi(report)) case Left(message) => Result.Failure(message) diff --git a/scalajslib/test/src/mill/scalajslib/RemapEsModuleTests.scala b/scalajslib/test/src/mill/scalajslib/RemapEsModuleTests.scala index 7d6c136a1d1..fadb5cb1671 100644 --- a/scalajslib/test/src/mill/scalajslib/RemapEsModuleTests.scala +++ b/scalajslib/test/src/mill/scalajslib/RemapEsModuleTests.scala @@ -4,7 +4,7 @@ import mill.define.Discover import mill.util.{TestEvaluator, TestUtil} import utest._ import mill.define.Target -import mill.scalajslib.api.ModuleKind +import mill.scalajslib.api._ object EsModuleRemapTests extends TestSuite { val workspacePath = TestUtil.getOutPathStatic() / "esModuleRemap" @@ -20,8 +20,8 @@ object EsModuleRemapTests extends TestSuite { override def scalaJSSourceMap = false override def moduleKind = ModuleKind.ESModule - override def esModuleRemap: Target[Map[String, String]] = Map( - "@stdlib/linspace" -> remapTo + override def scalaJSImportMap: Target[Seq[ESModuleImportMapping]] = Seq( + ESModuleImportMapping.Prefix("@stdlib/linspace", remapTo) ) } @@ -32,8 +32,8 @@ object EsModuleRemapTests extends TestSuite { override def scalaJSSourceMap = false override def moduleKind = ModuleKind.ESModule - override def esModuleRemap: Target[Map[String, String]] = Map( - "@stdlib/linspace" -> remapTo + override def scalaJSImportMap: Target[Seq[ESModuleImportMapping]] = Seq( + ESModuleImportMapping.Prefix("@stdlib/linspace", remapTo) ) } diff --git a/scalajslib/worker-api/src/mill/scalajslib/worker/api/ScalaJSWorkerApi.scala b/scalajslib/worker-api/src/mill/scalajslib/worker/api/ScalaJSWorkerApi.scala index be8d6316409..b28a9358d8a 100644 --- a/scalajslib/worker-api/src/mill/scalajslib/worker/api/ScalaJSWorkerApi.scala +++ b/scalajslib/worker-api/src/mill/scalajslib/worker/api/ScalaJSWorkerApi.scala @@ -18,7 +18,7 @@ private[scalajslib] trait ScalaJSWorkerApi { moduleSplitStyle: ModuleSplitStyle, outputPatterns: OutputPatterns, minify: Boolean, - esModuleMap: Map[String, String] + importMap: Seq[ESModuleImportMapping] ): Either[String, Report] def run(config: JsEnvConfig, report: Report): Unit @@ -123,3 +123,8 @@ private[scalajslib] final case class OutputPatterns( jsFileURI: String, sourceMapURI: String ) + +private[scalajslib] sealed trait ESModuleImportMapping +private[scalajslib] object ESModuleImportMapping { + case class Prefix(prefix: String, replacement: String) extends ESModuleImportMapping +} diff --git a/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala b/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala index b228476a240..8b9685e0b98 100644 --- a/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala +++ b/scalajslib/worker/1/src/mill/scalajslib/worker/ScalaJSWorkerImpl.scala @@ -172,7 +172,7 @@ class ScalaJSWorkerImpl extends ScalaJSWorkerApi { moduleSplitStyle: ModuleSplitStyle, outputPatterns: OutputPatterns, minify: Boolean, - esModuleMap: Map[String, String] + importMap: Seq[ESModuleImportMapping] ): Either[String, Report] = { // On Scala.js 1.2- we want to use the legacy mode either way since // the new mode is not supported and in tests we always use legacy = false @@ -206,19 +206,22 @@ class ScalaJSWorkerImpl extends ScalaJSWorkerApi { val resultFuture = (for { (irContainers, _) <- irContainersAndPathsFuture irFiles0 <- irFileCacheCache.cached(irContainers) - irFiles = if (esModuleMap.isEmpty) { + irFiles = if (importMap.isEmpty) { irFiles0 } else { if (!minorIsGreaterThanOrEqual(16)) { - throw new Exception( - s"Remapping EsModule imports will work with scalaJS 1.16 and above. You are using scalaJS ${ScalaJSVersions.current} - consider upgrading?" - ) + throw new Exception("scalaJSImportMap is not supported with Scala.js < 1.16.") } - val remapFct = esModuleMap.toSeq.foldLeft((in: String) => in) { case (fct, (s1, s2)) => - val fct2: (String => String) = (in => in.replace(s1, s2)) - (in => fct(fct2(in))) + val remapFunction = (rawImport: String) => { + importMap + .collectFirst { + case ESModuleImportMapping.Prefix(prefix, replacement) + if rawImport.startsWith(prefix) => + s"$replacement${rawImport.stripPrefix(prefix)}" + } + .getOrElse(rawImport) } - irFiles0.map { ImportMappedIRFile.fromIRFile(_)(remapFct) } + irFiles0.map { ImportMappedIRFile.fromIRFile(_)(remapFunction) } } report <- if (useLegacy) { From cdbfb80e5655a5c73078cf579578f1efd317b8fe Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Mon, 29 Apr 2024 14:38:09 +0200 Subject: [PATCH 27/27] Fix test for error message --- .../test/src/mill/scalajslib/RemapEsModuleTests.scala | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scalajslib/test/src/mill/scalajslib/RemapEsModuleTests.scala b/scalajslib/test/src/mill/scalajslib/RemapEsModuleTests.scala index fadb5cb1671..fe94911cc3f 100644 --- a/scalajslib/test/src/mill/scalajslib/RemapEsModuleTests.scala +++ b/scalajslib/test/src/mill/scalajslib/RemapEsModuleTests.scala @@ -1,5 +1,6 @@ package mill.scalajslib +import mill.api.Result import mill.define.Discover import mill.util.{TestEvaluator, TestUtil} import utest._ @@ -61,9 +62,9 @@ object EsModuleRemapTests extends TestSuite { } test("should throw for older scalaJS versions") { - val Left(ex) = evaluator(EsModuleRemap.OldJsModule.fastLinkJS) - val error = ex.asFailing.get.toString() - assert(error.contains("will work with scalaJS 1.16 and above. You are using scalaJS 1.15.0")) + val Left(Result.Exception(ex, _)) = evaluator(EsModuleRemap.OldJsModule.fastLinkJS) + val error = ex.getMessage + assert(error == "scalaJSImportMap is not supported with Scala.js < 1.16.") } }