From b830882359d706fd7f000554f3ec8af994c03678 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Mon, 21 Mar 2022 13:38:10 +0100 Subject: [PATCH 1/3] Add .bsp to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index db97f80..c3618ae 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ target/ +/.bsp/ /pack/ /cli-test/ From 008b1b8b080b1dc4ccec2b1694fa599a16c550a6 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Mon, 21 Mar 2022 13:38:23 +0100 Subject: [PATCH 2/3] Default to Scala 2.13.x --- build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index 742c377..679c456 100644 --- a/build.sbt +++ b/build.sbt @@ -15,7 +15,7 @@ inThisBuild(Def.settings( organization := "org.scala-js", crossScalaVersions := Seq("2.11.12", "2.12.15", "2.13.6"), - scalaVersion := crossScalaVersions.value.head, + scalaVersion := crossScalaVersions.value.last, scalacOptions ++= Seq("-deprecation", "-feature", "-Xfatal-warnings"), scalaJSVersion := "1.7.1", From 05316ba48ac9bd21cc7988363e70f85b9d5ea773 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Mon, 21 Mar 2022 13:38:47 +0100 Subject: [PATCH 3/3] Allow users to pass no-args main methods Useful to run tests for example --- .../scala/org/scalajs/cli/Scalajsld.scala | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/main/scala/org/scalajs/cli/Scalajsld.scala b/src/main/scala/org/scalajs/cli/Scalajsld.scala index b2dc9ae..3ed3c7a 100644 --- a/src/main/scala/org/scalajs/cli/Scalajsld.scala +++ b/src/main/scala/org/scalajs/cli/Scalajsld.scala @@ -50,15 +50,16 @@ object Scalajsld { logLevel: Level = Level.Info ) - private implicit object MainMethodRead extends scopt.Read[ModuleInitializer] { - val arity = 1 - val reads = { (s: String) => - val lastDot = s.lastIndexOf('.') - if (lastDot < 0) - throw new IllegalArgumentException(s"$s is not a valid main method") - ModuleInitializer.mainMethodWithArgs(s.substring(0, lastDot), - s.substring(lastDot + 1)) - } + private def moduleInitializer(s: String, hasArgs: Boolean): ModuleInitializer = { + val lastDot = s.lastIndexOf('.') + if (lastDot < 0) + throw new IllegalArgumentException(s"$s is not a valid main method") + val className = s.substring(0, lastDot) + val mainMethodName = s.substring(lastDot + 1) + if (hasArgs) + ModuleInitializer.mainMethodWithArgs(className, mainMethodName) + else + ModuleInitializer.mainMethod(className, mainMethodName) } private implicit object ModuleKindRead extends scopt.Read[ModuleKind] { @@ -85,12 +86,24 @@ object Scalajsld { .unbounded() .action { (x, c) => c.copy(cp = c.cp :+ x) } .text("Entries of Scala.js classpath to link") - opt[ModuleInitializer]("mainMethod") + opt[String]("mainMethod") .valueName("") .abbr("mm") .unbounded() - .action { (x, c) => c.copy(moduleInitializers = c.moduleInitializers :+ x) } + .action { (x, c) => + val newModule = moduleInitializer(x, hasArgs = true) + c.copy(moduleInitializers = c.moduleInitializers :+ newModule) + } .text("Execute the specified main(Array[String]) method on startup") + opt[String]("mainMethodWithNoArgs") + .valueName("") + .abbr("mma") + .unbounded() + .action { (x, c) => + val newModule = moduleInitializer(x, hasArgs = false) + c.copy(moduleInitializers = c.moduleInitializers :+ newModule) + } + .text("Execute the specified main() method on startup") opt[File]('o', "output") .valueName("") .action { (x, c) => c.copy(output = Some(x)) }