-
Notifications
You must be signed in to change notification settings - Fork 8
Support Scala.js 1.5.0 #33
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
Conversation
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.
Thank you for opening this PR!
.gitignore
Outdated
| target/ | ||
| /pack/ | ||
| /cli-test/ | ||
| .idea/ |
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.
We usually don't put IDE specific things into the checked-in .gitignore. Put it in your global .gitignore?
| val arity: Int = 1 | ||
| val reads = { (s: String) => | ||
| val file = implicitly[scopt.Read[File]].reads(s) | ||
| if(file.isDirectory){ |
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.
I'm not sure this is very user friendly. Essentially, if the output directory doesn't exist, instead of failing or creating it, it falls back to the old behavior (potentially creating a file where a directory is expected).
I think another flag that is mutually exclusive with this one is needed. Unfortunately, the obvious candidate -d (same option as in scalac / javac) is already taken. Not sure what a good flag would be.
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.
Ok, so I'll restore exact previous behavior, and introduce new option. IMHO sustaining backward compatibility is more important than one-letter option. I'll introduce output-dir option for directory output, and forbid simultaneous use of -o, and - output-dir . WDYT?
build.sbt
Outdated
| crossScalaVersions := Seq("2.12.13", "2.11.12", "2.13.5"), | ||
| scalaVersion := crossScalaVersions.value.head, | ||
| scalacOptions ++= Seq("-deprecation", "-feature", "-Xfatal-warnings"), | ||
| scalacOptions ++= Seq("-deprecation", "-feature"/*, "-Xfatal-warnings" FIMXE: commented because using legacy API */), |
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.
We need a better solution for this :) Have a look here (not pretty, but the best way we could find):
scripts/test-cli.sh
Outdated
| diff got-legacy.run want-legacy.run | ||
|
|
||
| mkdir test-output | ||
| scalajsld -s -o test-output -mm Foo.main bin |
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.
It might be nice to use SplitStyle.SmallestModules here to make sure the wiring is actually correct.
scripts/test-cli.sh
Outdated
| EOF | ||
|
|
||
| diff got.run want.run | ||
| diff got.run want.run |
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 put a newline at the end of the file.
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.
Mostly minor stuff, only larger point: is --outputDirectory good enough without short version. @sjrd might also have an opinion on this.
| opt[ModuleSplitStyle]("moduleSplitStyle") | ||
| .action { (x, c) => c.copy(moduleSplitStyle = x) } | ||
| .text("Module splitting strategy " + ModuleSplitStyleRead.All.mkString("(", ", ", ")")) | ||
| opt[String]("outputPatterns") |
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.
call this jsFilePattern? I think for now it is OK to only support this specific type of pattern, but we should reserve the outputPatterns name for that option, if we ever want to introduce it.
| .text("Don't optimize code") | ||
| opt[ModuleSplitStyle]("moduleSplitStyle") | ||
| .action { (x, c) => c.copy(moduleSplitStyle = x) } | ||
| .text("Module splitting strategy " + ModuleSplitStyleRead.All.mkString("(", ", ", ")")) |
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.
Module splitting style (style and strategy really both don't add any semantic value here IMO, but then we should stick with the terminology that already exists).
| esFeatures: ESFeatures = ESFeatures.Defaults, | ||
| moduleKind: ModuleKind = ModuleKind.NoModule, | ||
| moduleSplitStyle: ModuleSplitStyle = ModuleSplitStyle.FewestModules, | ||
| outputPatterns:OutputPatterns = OutputPatterns.Defaults, |
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.
Space after :.
| .text("Output file of linker (required)") | ||
| .action { (x, c) => c.copy(output = Some(x)) } | ||
| .text("Output file of linker (deprecated)") | ||
| opt[File]("outputDir") |
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.
I'm not a fan of not having a short option for a de-facto required flag (it's only not required for deprecated usage).
| } | ||
|
|
||
| @deprecated("Deprecate to silence warnings", "never/always") | ||
| private def deprecatedOutput(file: File) = { |
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.
It might be OK to inline this in the method above.
| } | ||
| } | ||
|
|
||
| private def createOutputFile(options: Options): Option[OutputFile] = { |
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.
Remove?
|
|
||
| for (options <- parser.parse(args, Options())) { | ||
| val outputFile = createOutputFile(options) | ||
| .getOrElse(throw new IllegalStateException("output either outputDir have to be defined")) |
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.
Remove?
scripts/test-cli.sh
Outdated
| mkdir test-output | ||
| scalajsld -s --outputDir test-output --moduleSplitStyle SmallestModules --moduleKind CommonJSModule -mm Foo.main bin | ||
| test -s test-output/Foo.js || fail "scalajsld: empty output" | ||
| test -s test-output/Foo.js.map || fail "scalajsld: empty output" |
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.
These file names are not specified (or more precisely: the module ID is an implementation detail subject to change). Maybe just assert that there is more than one .js file?
scripts/test-cli.sh
Outdated
| test -s test-output/Foo.js || fail "scalajsld: empty output" | ||
| test -s test-output/Foo.js.map || fail "scalajsld: empty output" | ||
| test -s test-output/main.js || fail "scalajsld: empty output" | ||
| test -s test-output/main.js.map || fail "scalajsld: empty source map" |
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.
It's maybe a good idea to have more specific error messages here. Otherwise it's hard to understand which part of the output is empty. (n.b. fail will not report the line it failed on, so calling it twice with the same string should be avoided if possible).
Indeed, this option should have a short name. If you can't find anything meaningful, use something meaningless like |
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.
Sorry this took so long. I'm struggling to find time for Scala.js.
I suggested a help text for jsFilePattern. Otherwise only codingstyle nits.
If all of this is addressed, feel free to squash everything into a single commit right away.
| DeprecatedLinkerAPI().link(linker, irFiles.toList, moduleInitializers, jsFile, logger) | ||
| case (None, Some(outputDir)) => | ||
| linker.link(irFiles, moduleInitializers, PathOutputDirectory(outputDir.toPath), logger) | ||
| case _ => throw new Exception("Either output or outputDir have to be defined.") |
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.
Throw an AssertionError? If we get here: The previous code has failed. So it's not a user error anymore, but a bug in the code.
| irFiles: Seq[IRFile], | ||
| moduleInitializers: Seq[ModuleInitializer], | ||
| linkerOutputFile: File, | ||
| logger: Logger): Future[Unit] |
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.
The indentation here is not following SJS style: https://github.com/scala-js/scala-js/blob/master/CODINGSTYLE.md#indentation
Either binpack it (as many args per line as possible, 4 spaces indent), or one per line, 2 spaces indented.
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.
I'm not sure, if it's this case. It'd be right for function invocation, but no declaration. I applied rule In general, indentation is 2 spaces, except continuation lines, which are indented 4 spaces. following example org.scalajs.linker.interface.Linker#link
| .text("Module splitting strategy " + ModuleSplitStyleRead.All.mkString("(", ", ", ")")) | ||
| opt[String]("outputPatterns") | ||
| .action { (x, c) => c.copy(outputPatterns = OutputPatterns.fromJSFile(x)) } | ||
| .text("Creates output patterns from a JS file pattern.") |
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.
How about: "Pattern for JS file names (default: %s.js). Expects a printf-style pattern with a single placeholder for the module ID. A typical use case is changing the file extension, e.g. %.mjs for Node.js modules."?
|
@gzm0 could we proceed? |
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.
Sorry, this slipped through the cracks. Thank you for reminding me. Only minor things, really.
| .action { (x, c) => c.copy(outputPatterns = OutputPatterns.fromJSFile(x)) } | ||
| .text("Pattern for JS file names (default: %s.js). " + | ||
| "Expects a printf-style pattern with a single placeholder for the module ID. " + | ||
| "A typical use case is changing the file extension, e.g. %.mjs for Node.js modules.") |
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.
Use backticks for the examples? (like in my comment, but the markdown version of it)?
| checkConfig { c => | ||
| if (c.output.isDefined) { | ||
| reportWarning("using a single file as output (--output) is deprecated since Scala.js 1.3.0." + | ||
| " Use --outputDirectory instead.") |
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.
--outputDir.
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.
LGTM. Please squash all the commits and then we can merge this (unless @sjrd has comments / objections).
|
No objection. ;) Looks good to me. |
I added scalajs 1.5.0 support. A allowed using deprecated "file as output" with warring, and ported to new API. WDYT?