-
Notifications
You must be signed in to change notification settings - Fork 22
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
Fix #115: Add ESModule support #116
Conversation
Thank you for your contribution. Please sign the Scala CLA: https://www.lightbend.com/contribute/cla/scala in order for us to be able to accept your contribution. |
I'm aware this isn't (unfortunately) explicitly written in the readme here, but most (if not all) of the Scala.js main repo contribution guidelines apply. |
@gzm0 I just signed the CLA. I will go over the guidelines. Will appreciate if you could points a few missing things in the PR to get me started. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test. At least a superficial one examining the code paths, ideally one that actually loads another module. Note that this needs a webserver, so it should probably go in seleniumJSHttpEnvTest
.
Please put the commit message in the following form:
Fix #115: Add ESModule support
seleniumJSEnv/src/main/scala/org/scalajs/jsenv/selenium/SeleniumRun.scala
Outdated
Show resolved
Hide resolved
Thanks for the inputs @gzm0. |
60d10b2
to
0c455f6
Compare
@gzm0 I attempted writing a module import test by mapping JSImport to a CDN entry. Will that be ok? |
seleniumJSHttpESModuleEnvTest/src/main/scala/org/scalajs/jsenv/selenium/CamelcaseEsModule.scala
Outdated
Show resolved
Hide resolved
seleniumJSHttpESModuleEnvTest/src/test/scala/org/scalajs/jsenv/selenium/LocationTest.scala
Outdated
Show resolved
Hide resolved
Done with the version upgrade and ESModule setting on by default. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only minor nits. LG otherwise.
Once done, please put the changes in two commits: one with the version changes, one with the fix for module support.
In the one with the version changes, please put a short explanation into the commit body, why you are not re-using scalaJSVersions
. (feel free to reference http://www.scala-js.org/news/2020/07/02/announcing-scalajs-1.1.1/).
seleniumJSHttpEnvTest/src/test/scala/org/scalajs/jsenv/selenium/CamelCaseTest.scala
Outdated
Show resolved
Hide resolved
seleniumJSEnv/src/main/scala/org/scalajs/jsenv/selenium/SeleniumRun.scala
Outdated
Show resolved
Hide resolved
As mentioned in the [ScalaJS 1.1.1 release](http://www.scala-js.org/news/2020/07/02/announcing-scalajs-1.1.1), ScalaJS version in `scalajs-js-envs` should be harcoded instead of deriving it from `scalaJSVersion`. `scalajs-js-envs` is extracted out of the ScalaJS repository and will follow its own publishing cadence.
I have incorporated all the suggestions so far. Thank you. |
seleniumJSEnv/src/main/scala/org/scalajs/jsenv/selenium/SeleniumRun.scala
Outdated
Show resolved
Hide resolved
seleniumJSEnv/src/main/scala/org/scalajs/jsenv/selenium/SeleniumRun.scala
Outdated
Show resolved
Hide resolved
@sjrd further comments on this? |
I have nothing else to add :) |
val scriptTags = | ||
scripts.map(path => s"<script src='${path.toString}'></script>") | ||
private def htmlPage(setupJsPath: Path, input: Seq[Input], materializer: FileMaterializer): String = { | ||
val setupJs = makeTag(setupJsPath, "text/javascript", materializer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum, am I misunderstanding this now, or would this copy the setup script twice?
If you are looking for ways to consolidate code and the fact that the setup script is not a Path
is problematic, I think it would be OK to add Jimfs as a dependency and make in-memory Path
s. There is precedent for this in the Node.js env: https://github.com/scala-js/scala-js-js-envs/blob/v1.1.1/nodejs-env/src/main/scala/org/scalajs/jsenv/nodejs/ComSupport.scala#L247
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Let me know if I got it right.
val page = m.materialize("scalajsRun.html", htmlPage(allScriptURLs)) | ||
|
||
val setupJsPath = JSSetup.setupFile(enableCom) | ||
val page = m.materialize("scalajsRun.html", htmlPage(setupJsPath, input, m)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point, you can just pass this as additional input:
val fullInput = Input.Script(JSSetup.setupFile(enableCom)) :: input
/* snip */ htmlPage(fullInput, m) /* snip */
That'll also simplify htmlPage
.
""".stripMargin | ||
def setupFile(enableCom: Boolean): Path = { | ||
Files.write( | ||
Jimfs.newFileSystem().getPath("setup.js"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scala.js style guide demands that this be indented by 4 spaces (continuation line).
Consider:
val code = {
s"""
/* snip */
""".stripMargin
}
Files.write(
Jimfs.newFileSystem().getPath("/setup.js"),
code.getBytes(StandardCharset.UTF_8))
To avoid having to indent the huge string literal too much.
| </body> | ||
|</html> | ||
""".stripMargin | ||
} | ||
|
||
private def makeTag(path: Path, tpe: String, materializer: FileMaterializer): String = { | ||
val url = materializer.materialize(path) | ||
s"<script defer type='$tpe' src='${url.toString}'></script>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also just noticed this: You can drop the toString
(and hence the braces). It's implied by the s
interpolator.
Thank you! |
@gzm0 Any chance of getting a new release soon? |
No description provided.