For pure projects, provide way to use only single publish artifact
matthughes opened this issue · 3 comments
I'm currently using ScalaJS plugin / latest sbt-crossproject plugin. I have a typical common
cross-project that publishes both a commonJVM
jar and a commonJS
SJS jar. For my project, it takes about 60 seconds to compile each project. I don't have any platform specific files in this project.
If I look at the JVM jar and the SJS jar, they are identical except:
SJS jar has JS_DEPENDENCIES file
SJS jar has NPM_DEPENDENCIES file
SJS jar has the sjsir
artifacts in addition to the class
files.
Since ScalaJS is generating class files anyway, why do I need to the commonJVM
project at all? Couldn't we have some stricter CrossType.Pure
mode where we don't actually create two different projects? Or maybe they're two different projects but we're smarter and only do compilation once and only produce one JAR? For my case, I do not care that my commonJVM
jar is going to have useless SJS artifacts. I will gladly put up with that to shave over a minute off my build.
Sorry, this has been debated long ago in Scala.js core. There's no guarantee that the class files produced through Scala.js are workable on the JVM. Plus, even if the sources are the same, the metadata aren't. Scala.js doesn't guarantee anything here.
Given the lack of guarantee, sbt-crossproject is not going to allow this easily. It will be too easy for users to shoot themselves in the foot.
If your particular build and sources happen to produce the same class files, and you're willing to bet that this will remain true in the future, you can figure out how to hack your build to do it (not using sbt-crossproject, then, but your own mechanism). I am not going to give hints on how to do that, because I don't want to be blamed if and when things go wrong with that approach.
Are there any links to that discussion? I thought surely this must have been discussed or I completely misunderstood the issue but I couldn't find the discussions.
So why does ScalaJS generate class files in the first place if it doesn't use them? Is it just a side-effect of generating the sjsir files? What part of the process generates the class files and how could/would that be different than regular JVM project?
Those discussions are really old. They date back from the first year of Scala.js. I'm on vacation with only a mobile phone, so I can't really look them up at the moment. You can try in the oldest closed issues of the core Scala.js repo.