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

Scala.js - package command - support for multi modules #530

Closed
lwronski opened this issue Jan 7, 2022 · 3 comments · Fixed by #816
Closed

Scala.js - package command - support for multi modules #530

lwronski opened this issue Jan 7, 2022 · 3 comments · Fixed by #816
Assignees
Labels
bug Something isn't working Scala.js

Comments

@lwronski
Copy link
Contributor

lwronski commented Jan 7, 2022

It would be nice to support js modules in package command

  @JSExportTopLevel(name = "onRequest", moduleID = "request_type")
  def func(...)

  @JSExportTopLevel(name = "onRequest", moduleID = "request_headers")
  def func(...)

for now, package ... --js throws error, that main class is missing.

@lwronski lwronski added the bug Something isn't working label Jan 31, 2022
@armanbilge
Copy link
Contributor

armanbilge commented Mar 28, 2022

I started opening a new issue, but I think it's a duplicate of this one.

Besides the issue with main class missing, it's also important to be able to support multi-file output which occurs when using modules.

For example:

test.scala:

//> using scala "3.1.1"
//> using platform "scala-js"
//> using jsVersion "1.9.0"
//> using jsModuleKind "es"
//> using jsModuleSplitStyleStr "smallestmodules"

case class Foo(bar: String)

@main def main = println(Foo("baz"))

Run scala-cli package test.scala

output test.js:

'use strict';
import * as $j_java$002elang$002eObject from "./java.lang.Object.js";
import * as $j_main$002e from "./main..js";
$j_main$002e.$s_Lmain__main__AT__V(new ($j_java$002elang$002eObject.$d_T.getArrayOf().constr)([]));

Notice that test.js references ./java.lang.Object.js and ./main..js; however these are not produced by scala-cli.

Multi-module support is important for integrating with modern JS tooling such as snowpack which enables a fast-reload development cycle.

Thanks again for all your work on improving support for Scala.js. I think solving this one will nail it.

@lwronski
Copy link
Contributor Author

lwronski commented Mar 29, 2022

Hi @armanbilge, thanks again for reporting.

It seems, that java.lang.Object.js is generated by Scala.js linker but scala-cli doesn't copy these files to the output directory.

I see, that Scala.js Linker generates a lot files js files, should they all be copied to the output directory?

lwronski@VL-D-0317 scala-cli-js-linking266039794926029209 % ls
Foo.js								scala.Console$.js						scala.math.Integral$.js
Hello$package$.js						scala.MatchError.js						scala.math.Numeric$.js
java.io.FilterOutputStream.js					scala.Product$$anon$1.js					scala.math.Ordered$.js
java.io.OutputStream.js						scala.Product2.js						scala.math.Ordering$.js
java.io.PrintStream.js						scala.collection.IndexedSeq.js					scala.math.ScalaNumber.js
java.lang.Character$.js						scala.collection.IterableFactory$Delegate.js			scala.package$$anon$1.js
java.lang.IllegalArgumentException.js				scala.collection.IterableOnce.js				scala.runtime.AbstractFunction0.js
java.lang.Integer$.js						scala.collection.LinearSeq.js					scala.runtime.AbstractFunction1.js
java.lang.JSConsoleBasedPrintStream$DummyOutputStream.js	scala.collection.Seq.js						scala.runtime.BoxesRunTime$.js
java.lang.JSConsoleBasedPrintStream.js				scala.collection.SeqFactory$Delegate.js				scala.runtime.IntRef.js
java.lang.NullPointerException.js				scala.collection.StrictOptimizedLinearSeqOps.js			scala.runtime.ObjectRef.js
java.lang.NumberFormatException.js				scala.collection.View.js					scala.runtime.ScalaRunTime$.js
java.lang.Object.js						scala.collection.immutable.$colon$colon$.js			scala.runtime.Statics$.js
java.lang.SecurityException.js					scala.collection.immutable.LazyList$State$Empty$.js		scala.runtime.Statics$PFMarker$.js
java.lang.StringBuilder.js					scala.collection.immutable.LazyList$State.js			scala.scalajs.runtime.AnonFunction0.js
java.lang.System$Streams$.js					scala.collection.immutable.List$$anon$1.js			scala.scalajs.runtime.AnonFunction1.js
java.lang.System$SystemProperties$.js				scala.collection.immutable.Range$.js				scala.util.CommandLineParser$.js
java.lang.UnsupportedOperationException.js			scala.collection.immutable.Stream$.js				scala.util.CommandLineParser$ParseError.js
java.lang.Utils$.js						scala.collection.immutable.VectorStatics$.js			scala.util.DynamicVariable.js
java.lang.Utils$Cache$.js					scala.collection.mutable.StringBuilder$.js			scala.util.Either$.js
java.util.Arrays$.js						scala.collection.package$$colon$plus$.js			scala.util.Left$.js
java.util.NoSuchElementException.js				scala.collection.package$$plus$colon$.js			scala.util.Right$.js
main..js							scala.math.Equiv$.js						scala.util.hashing.MurmurHash3.js
main.js								scala.math.Fractional$.js

I think we can do it this way. Scala-cli will require the output parameter to point to an existing directory, and then merge-cli will copy all files generated by the Scala.js linker into that directory.

@lwronski lwronski linked a pull request Mar 29, 2022 that will close this issue
@armanbilge
Copy link
Contributor

I see, that Scala.js Linker generates a lot files js files, should they all be copied to the output directory?

Yes, that's right. But I see you've already fixed this in #816, amazing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Scala.js
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants