Skip to content

Conversation

@clutroth
Copy link
Contributor

I added scalajs 1.5.0 support. A allowed using deprecated "file as output" with warring, and ported to new API. WDYT?

Copy link
Contributor

@gzm0 gzm0 left a 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/
Copy link
Contributor

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){
Copy link
Contributor

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.

Copy link
Contributor Author

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 */),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff got-legacy.run want-legacy.run

mkdir test-output
scalajsld -s -o test-output -mm Foo.main bin
Copy link
Contributor

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.

EOF

diff got.run want.run
diff got.run want.run
Copy link
Contributor

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.

@clutroth clutroth requested a review from gzm0 March 25, 2021 13:01
Copy link
Contributor

@gzm0 gzm0 left a 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")
Copy link
Contributor

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("(", ", ", ")"))
Copy link
Contributor

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,
Copy link
Contributor

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")
Copy link
Contributor

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) = {
Copy link
Contributor

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] = {
Copy link
Contributor

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"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove?

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"
Copy link
Contributor

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?

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"
Copy link
Contributor

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).

@sjrd
Copy link
Member

sjrd commented Apr 3, 2021

Mostly minor stuff, only larger point: is --outputDirectory good enough without short version. @sjrd might also have an opinion on this.

Indeed, this option should have a short name. If you can't find anything meaningful, use something meaningless like -z. ;)

@clutroth clutroth requested a review from gzm0 April 16, 2021 06:31
Copy link
Contributor

@gzm0 gzm0 left a 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.")
Copy link
Contributor

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]
Copy link
Contributor

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.

Copy link
Contributor Author

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.")
Copy link
Contributor

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."?

@clutroth clutroth requested a review from gzm0 May 6, 2021 14:57
@clutroth
Copy link
Contributor Author

@gzm0 could we proceed?

Copy link
Contributor

@gzm0 gzm0 left a 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.")
Copy link
Contributor

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.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--outputDir.

@clutroth clutroth requested a review from gzm0 June 12, 2021 10:57
@gzm0 gzm0 changed the title support scalajs 1.5.0 Support Scala.js 1.5.0 Jun 12, 2021
Copy link
Contributor

@gzm0 gzm0 left a 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).

@sjrd
Copy link
Member

sjrd commented Jun 12, 2021

No objection. ;) Looks good to me.

@clutroth clutroth requested a review from gzm0 June 16, 2021 14:31
@gzm0 gzm0 merged commit 86278ac into scala-js:master Jun 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants