sjrd on 0.6.x
Remove dead code: specific coll… Adapt the signature of `js.Arra… Merge pull request #3554 from s… (compare)
sjrd on master
Fix analyzer cycle detection to… Add toString methods to analyze… Do not provide linked ClassInfo… and 1 more (compare)
sjrd on master
Remove Logger.success It is un… Make level helpers final Clean-up ScalaConsoleLogger cod… and 1 more (compare)
Could not run test MainSpec: org.scalajs.testcommon.RPCCore$RPCException: scala.scalajs.js.JavaScriptException: TypeError: Cannot read property 'MainSpec' of undefined
. I stumbled upon this thread: https://www.reddit.com/r/scala/comments/c84rae/unit_testing_in_scalajs/ but the solutions proposed there don't change anything for me
.settings()
(resp. .jsSettings()
) of the relevant project
(resp. crossProject
)
global.process.exitcode
to a non-zero value and then allow my program to exit gracefully. I am expecting to exit with a failure in that case but I am still exiting with a success. I have confirmed that I am using the node.js environment. Am I doing something wrong?
@JSExportAll
@JSExportTopLevel("Main")
object Main {
def main(args: Array[String]): Unit = {
println("abc")
args.foreach(println)
}
}
node my-script-opt.js 3123 12312 12312312 3123123 12321312 1231231 12312312 123123
abc
val args = process.argv.drop(2)
to access the first arg. I typically have a separate project with 2-3 lines in it representing "main" and handling some major "context" instance specific to the environment. Same on the JVM side.
Well, I got something working here.
@JSExportAll
@JSExportTopLevel("Main")
object Main {
def test(s: Array[String]): Unit = {
println("ABC")
s.foreach(println)
}
}
var main = require("./test.js");
main.Main.test(process.argv);
It prints the ABC
but on the foreach
it's giving me a TypeError: Cannot read property 'length' of undefined
. I'm using .jsSettings(scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.CommonJSModule) })
and calling it using:
node myScript.js 123 123 123
Any ideas?
Build.properties
sbt.version = 1.2.8
Plugins.sbt
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.6.1")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.28")
build.sbt
import sbtcrossproject.CrossPlugin.autoImport.crossProject
val sharedSettings = Seq(
name := "arithmetic-interpreter",
version := "0.1.0-SNAPSHOT",
libraryDependencies += "com.lihaoyi" %%% "fastparse" % "2.1.3"
)
lazy val arithmeticInterpreter = crossProject(JSPlatform, JVMPlatform)
.in(file("."))
.settings(sharedSettings)
Project Structure
https://imgur.com/dlJsydi
When I do a publishLocal
and try to run it I'm running into a ClassNotFoundException
, so somehow it's not getting the scalalib and packaging together with my jar, any idea why?
Exception in thread "main" java.lang.NoClassDefFoundError: scala/collection/mutable/ArrayOps$ofRef
at Main$.main(Main.scala:6)
at Main.main(Main.scala)
Caused by: java.lang.ClassNotFoundException: scala.collection.mutable.ArrayOps$ofRef
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 2 more
Tried to call using java -cp <scalalib> -jar <myjar>
and java -jar <myjar>
trait NotificationOptions extends js.Object
where you set the members that you can set being js.UndefOr[T]
for T
the type you need. For example val title: js.UndefOr[String] = js.undefined
.def setDefaults(options: NotificationOptions): Unit = js.native
. And you can feed the argument by instantiated new instances of NotificationOptions
(a method apply
in the companion object is not a bad idea in general)