Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Aug 23 09:24
    @sjrd banned @yensaoxuan_twitter
  • Apr 18 19:06
    @sjrd banned @Amitgup48798297_twitter
  • Mar 29 07:47
    @sjrd banned @quangs
  • Jan 23 06:34
    @sjrd banned @Rebeka58_gitlab
  • Jun 08 2020 20:43
    @sjrd banned @sw7240614
  • Sep 29 2019 08:35
    @sjrd banned @8bitpitRBX_twitter
  • May 23 2019 13:44
    @sjrd banned @BIGCRYPTO001_gitlab
  • May 01 2019 14:31
    @sjrd banned @Certificates1_gitlab
  • Apr 22 2019 15:31
    @sjrd banned @lerbatax
  • Jan 31 2019 23:04
    sjrd commented #3555
  • Jan 31 2019 22:56
    sjrd review_requested #3555
  • Jan 31 2019 22:56
    sjrd opened #3555
  • Jan 31 2019 21:06

    sjrd on 0.6.x

    Remove dead code: specific coll… Adapt the signature of `js.Arra… Merge pull request #3554 from s… (compare)

  • Jan 31 2019 21:06
    sjrd closed #3554
  • Jan 31 2019 20:54
    erikvanoosten commented #2665
  • Jan 31 2019 16:33
    sjrd commented #3538
  • Jan 31 2019 15:54

    sjrd on master

    Fix analyzer cycle detection to… Add toString methods to analyze… Do not provide linked ClassInfo… and 1 more (compare)

  • Jan 31 2019 15:54
    sjrd closed #3552
  • Jan 31 2019 15:54

    sjrd on master

    Remove Logger.success It is un… Make level helpers final Clean-up ScalaConsoleLogger cod… and 1 more (compare)

  • Jan 31 2019 15:54
    sjrd closed #3553
Sébastien Doeraene
@sjrd
Yes.
Mathieu
@mathieuleclaire
Now I have Uncaught ReferenceError: require is not defined
with:
def merge(first: File, second: File) = {
  val f1 = java.nio.file.Files.lines(first.toPath)
  val f2 = java.nio.file.Files.lines(second.toPath)
  val in = java.io.File.createTempFile("merge", "JS")
  val bw = new BufferedWriter(new FileWriter(in, true))
  f1.forEach { p => bw.append(p + "\n") }
  f2.forEach { p => bw.append(p + "\n") }
  bw.close
  in
}
Sébastien Doeraene
@sjrd
Well that makes sense to me, given what I said earlier:
Also Webpack is supposed to rewrite the calls to require in the JS code produced by Scala.js. With your setup, that won't happen.
It's possible that ScalaJSBundler's LibraryAndApplication mode could save you.
Mathieu
@mathieuleclaire
Mmh, this does not sound good
Uncaught SyntaxError: redeclaration of class $c_jl_Throwable
note: Previously declared at line 70829, column 6
with :
lazy val emptyProject = project.in(file("packJS")) enablePlugins (ScalaJSBundlerPlugin) settings(
  scalaJSUseMainModuleInitializer := true,
  webpackBundlingMode := LibraryAndApplication()
)dependsOn(ace, bootstrapnative, tools, highlightjs)
Mathieu
@mathieuleclaire
Is it because two mains are merged in the same js ?
Tobias Schlatter
@gzm0
@mathieuleclaire if by that you mean you simply concatenated to Scala.js generated JS, files, then yes.
Ah, but if that build statement you sent is all you did, sounds more like a bug somewhere...
Mathieu
@mathieuleclaire
Yes, it is all I do. In my empyProject, I only invoke libs I need, so that webpack wraps all required js libs:
object PackJS {

  def main(argvs: Array[String]): Unit = {
    def pack = {
      val editorDiv = div(idAttr := "editor")
      ace.edit(editorDiv.ref)
      Tabs.tabs()
      HighlightJS.initHighlightingOnLoad()
    }
  }
}
Tobias Schlatter
@gzm0
How do you include it in your wepage?
(or when do you see the error, when you type run?)
Mathieu
@mathieuleclaire
I don't include it. It is just a trick to webpack all the js I need for my main application, which is built at runtime (plugin system). I tried to explain it before. So, to try to take advantage of the webpack js resolution (which cannot be used in my manual link). To test the feasability, I work in a simpler pattern where I made two projects: my main one with a simple fastOpJS (and no webpacking) and an empty one (depending on the same js dependencies as the main one) to wrap the js required at runtime with webpack. And I try to merge both in a single js.
Tobias Schlatter
@gzm0
Sorry, just saw, there is much more context. Do you still use this merge thing? That will not work except with ModuleKind.NoModule because when you define modules, Scala.js uses the module-level scope for internal definitions.
And then, the second file will define some stuff twice.
You'll need to import the modules individually.

Is it because two mains are merged in the same js ?

So to answer that: It's not that two mains are merged, it's that two linked JS files are merged in the same JS. If you are working with modules, you need to import the two JS files.

Mathieu
@mathieuleclaire
I am still trying this stategy yes. So I should add NoModule in the empty project ?
Sébastien Doeraene
@sjrd
scalajs-bundler forces CommonJSModule and requires it.
TBH I'm not sure scalajs-bundler is fit for what you're trying to do.
Have you considered invoking Webpack yourself?
11 replies
Mathieu
@mathieuleclaire
nope, I am not familiar with js in general and with webpack. It's much more comfortable to use it through scala libs !
I had hacked a sbt plugin to gather js from node_modules but I had times to times dependency conflicts, so that I wanted to switch to webpack once and for all
Mathieu
@mathieuleclaire
Or you mean, work directly with Wepack run ?
Ulugbek Abdullaev
@ulugbekna

Hi! I am fastLinkJS a class that uses scala.util.parsing.input.Position and get the following errors:

[info] Fast optimizing /Users/ulugbekna/code/minicoq/minicoq/target/scala-3.0.0-RC3/minicoq-fastopt
[info] Fast optimizing /Users/ulugbekna/code/minicoq/minicoq-js/target/scala-3.0.0-RC3/minicoq-js-fastopt
[error] Referring to non-existent class scala.util.parsing.input.Position
[error]   called from private static minicoq.core.Interpreter.op$proxy1$2$$anonfun$1(minicoq.core.Term,minicoq.core.Term,minicoq.core.Term)java.lang.String
[error]   called from private minicoq.core.Interpreter.op$proxy1$1(minicoq.core.Stat)minicoq.core.Interpreter$Result
[error]   called from minicoq.core.Interpreter.interpret(minicoq.core.Stat)minicoq.core.Interpreter$Result
[error]   called from minicoq.core.Repl.interpret(java.lang.String)java.lang.String
[error]   called from minicoq.core.Repl.interpretRepl(java.lang.String)scala.util.Either
[error]   called from private minicoq.js.Webapp$.main$$anonfun$1(org.scalajs.dom.raw.HTMLDivElement,org.scalajs.dom.raw.HTMLInputElement,org.scalajs.dom.raw.KeyboardEvent)java.lang.Object
[error]   called from minicoq.js.Webapp$.main([java.lang.String)void
[error]   called from static minicoq.js.Webapp.main([java.lang.String)void
[error]   called from core module module initializers
[error] involving instantiated classes:
[error]   minicoq.core.Repl
[error]   minicoq.js.Webapp$
[error] Referring to non-existent method scala.util.parsing.input.Position.longString()java.lang.String

Do I understand it correctly that this class can't be compiled to javascript?

(full error here)

Sébastien Doeraene
@sjrd
Do you depend on the JS version of scala.util.parsing, i.e., with a %%% instead of a %% in the libraryDependencies?
Ulugbek Abdullaev
@ulugbekna
Hi, thanks for the reply. No, I don't.
Let me give more context if that's helpful. I have a library (a package) minicoq.core that is used by jvm REPL implementation and my js webapp. I want minicoq.core to be compatible with both jvm and js. Do you know how this could be achieved?
My sbt file looks like this now
val dottyVersion = "3.0.0-RC3"

lazy val minicoq = project
  .in(file("minicoq"))
  .enablePlugins(ScalaJSPlugin)
  .settings(
    name := "minicoq",
    version := "0.1.0",
    scalaVersion := dottyVersion,
    libraryDependencies += ("org.scala-lang.modules" %% "scala-parser-combinators" % "1.1.2")
      .withDottyCompat(scalaVersion.value),
    libraryDependencies += "org.scalameta" %% "munit" % "0.7.25" % Test,
    testFrameworks += new TestFramework("munit.Framework")
  )

lazy val minicoq_repl = project
  .in(file("."))
  .aggregate(minicoq)
  .dependsOn(minicoq)
  .settings(
    name := "minicoq-repl",
    version := "0.1.0",
    scalaVersion := dottyVersion
  )

lazy val minicoq_js = project
  .in(file("minicoq-js"))
  .enablePlugins(ScalaJSPlugin)
  .aggregate(minicoq)
  .dependsOn(minicoq)
  .settings(
    name := "minicoq-js",
    version := "0.1.0",
    scalaVersion := dottyVersion,
    scalaJSUseMainModuleInitializer := true,
    libraryDependencies += ("org.scala-js" %%% "scalajs-dom_sjs1" % "1.1.0")
      .withCrossVersion(CrossVersion.for3Use2_13)
  )
Anton Sviridov
@velvetbaldmime:matrix.org
[m]
libraryDependencies += ("org.scala-lang.modules" %% "scala-parser-combinators" % "1.1.2")
that's where the issue is - you need to use %%% here for SJS to use this dependency (transitively)
does parser combinators even publish for js?
(just checked, it does)
Ulugbek Abdullaev
@ulugbekna
If I use %%%, would I lose compat with JVM?
Anton Sviridov
@velvetbaldmime:matrix.org
[m]
Nope
it will work for both
https://github.com/portable-scala/sbt-platform-deps#sbt-platform-deps this is where it's coming from (scala.js plugin depends on it)
Ulugbek Abdullaev
@ulugbekna
Thanks, this is so helpful!
Anton Sviridov
@velvetbaldmime:matrix.org
[m]

no worries :)

Anton puts another notch next to the list of people tripped by %%%

I think in the context of cross platform projects you can just use %%% everywhere in the build to avoid this confusion

Ulugbek Abdullaev
@ulugbekna
You may also notice libraryDependencies += ("org.scala-js" %%% "scalajs-dom_sjs1" % "1.1.0") .withCrossVersion(CrossVersion.for3Use2_13) at the end of my sbt file and _sjs1 suffix in the dep name. Somehow, sbt can't find this dependency without this suffix. Is this the expected behavior?
Anton Sviridov
@velvetbaldmime:matrix.org
[m]
hm.. I wonder if it's some weird interplay with for3Use2_13? I have this library as a dependency in another project and it works without the suffix
Sébastien Doeraene
@sjrd
Doesn't ("org.scala-js" %%% "scalajs-dom" % "1.1.0").withCrossVersion(CrossVersion.for3Use2_13) work?
2 replies
Ulugbek Abdullaev
@ulugbekna
I discovered sbt-crossproject and see that it's updated some time ago. I wonder whether it is still used/maintained and what its primary purpose is since it seems just sbt itself can compile to both jvm and js?
Anton Sviridov
@velvetbaldmime:matrix.org
[m]

sbt itself can compile to both jvm and js

crossproject helps generating those project - one can do it manually like you did, or with crossproject/projectmatrix plugins.

If you have a ton of cross-built projects, manual creation can become tedious quickly :)

1 reply
Rich
@Rich2
What does io.Source.fromResource do when running Scala.js in a browser?
Anton Sviridov
@velvetbaldmime:matrix.org
[m]
I think it breaks during linking
[error] Referring to non-existent class java.io.FileNotFoundException 
[error]   called from scala.io.Source$.fromResource(java.lang.String,j
ava.lang.ClassLoader,scala.io.Codec)scala.io.BufferedSource
Rich
@Rich2
Ah OK I tried compiling under Scala.js. Thanks.
I'll make sure any methods that call it are in a Java only source folder.