|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: Announcing Scala.js 0.6.20 |
| 4 | +category: news |
| 5 | +tags: [releases] |
| 6 | +permalink: /news/2017/09/01/announcing-scalajs-0.6.20/ |
| 7 | +--- |
| 8 | + |
| 9 | + |
| 10 | +We are pleased to announce the release of Scala.js 0.6.20! |
| 11 | + |
| 12 | +This release is mostly intended to bridge the gap between the 0.6.x and 1.x branches, to make it easier to cross-compile and/or migrate. |
| 13 | + |
| 14 | +Read on for more details. |
| 15 | + |
| 16 | +<!--more--> |
| 17 | + |
| 18 | +## Getting started |
| 19 | + |
| 20 | +If you are new to Scala.js, head over to |
| 21 | +[the tutorial]({{ BASE_PATH }}/tutorial/). |
| 22 | + |
| 23 | +## Release notes |
| 24 | + |
| 25 | +If upgrading from Scala.js 0.6.14 or earlier, make sure to read [the release notes of 0.6.15]({{ BASE_PATH }}/news/2017/03/21/announcing-scalajs-0.6.15/), which contain important migration information. |
| 26 | + |
| 27 | +As a minor release, 0.6.20 is backward source and binary compatible with previous releases in the 0.6.x series. |
| 28 | +Libraries compiled with earlier versions can be used with 0.6.20 without change. |
| 29 | +0.6.20 is also forward binary compatible with 0.6.{17-19}, but not with earlier releases: libraries compiled with 0.6.20 cannot be used by projects using 0.6.{0-16}. |
| 30 | + |
| 31 | +Please report any issues [on GitHub](https://github.com/scala-js/scala-js/issues). |
| 32 | + |
| 33 | +## Breaking changes |
| 34 | + |
| 35 | +### sbt 0.13.16 or above is required (or sbt 1.x) |
| 36 | + |
| 37 | +The sbt plugin of Scala.js 0.6.20 starts using features of sbt 0.13.16. |
| 38 | +If you are using an older version of sbt 0.13.x, you will have to upgrade to 0.13.16 or later. |
| 39 | + |
| 40 | +Since 0.6.19, Scala.js also supports sbt 1.0.0+. |
| 41 | + |
| 42 | +### `scalajs-env-selenium` has to be upgraded to 0.2.0 |
| 43 | + |
| 44 | +Scala.js 0.6.20 contains internal changes to improve the so-called test adapter, which is the mechanism used by sbt to communicate with testing frameworks. |
| 45 | +These changes are invisible to you, but they broke [`scalajs-env-selenium`](https://github.com/scala-js/scala-js-env-selenium) 0.1.x. |
| 46 | +If you use it, you will have to upgrade it to 0.2.0. |
| 47 | + |
| 48 | +## Deprecations |
| 49 | + |
| 50 | +Scala.js 0.6.20 introduces more aggressive deprecations for features that will disappear in 1.x. |
| 51 | +Note that those features have already had better replacements since Scala.js 0.6.18; we are just making it more obvious that these new features should be used to be compatible with 1.x. |
| 52 | + |
| 53 | +### `@ScalaJSDefined` |
| 54 | + |
| 55 | +This annotation is now deprecated. |
| 56 | +Instead of using it, you should add the following to your project settings: |
| 57 | + |
| 58 | +{% highlight scala %} |
| 59 | +scalacOptions += "-P:scalajs:sjsDefinedByDefault" |
| 60 | +{% endhighlight %} |
| 61 | + |
| 62 | +and remove the `@ScalaJSDefined` annotations everywhere in your codebase. |
| 63 | +The semantics of your codebase will be unchanged. |
| 64 | + |
| 65 | +### `js.JSApp` |
| 66 | + |
| 67 | +`js.JSApp` has traditionally provided two services to an `object Foo` that extends it. |
| 68 | +These two services are replaced by two different features. |
| 69 | + |
| 70 | +#### Discoverability by sbt as main object |
| 71 | + |
| 72 | +Since Scala.js 0.6.18, the sbt plugin can recognize "standard" `main` methods of the form |
| 73 | + |
| 74 | +{% highlight scala %} |
| 75 | +def main(args: Array[String]): Unit = ... |
| 76 | +{% endhighlight %} |
| 77 | + |
| 78 | +in objects, even if they do not extend `js.JSApp`. |
| 79 | +Use such a main method to replace `js.JSApp` in the context of discoverability by sbt. |
| 80 | + |
| 81 | +To enable it as main method, make sure you also set |
| 82 | + |
| 83 | +{% highlight scala %} |
| 84 | +scalaJSUseMainModuleInitializer := true |
| 85 | +{% endhighlight %} |
| 86 | + |
| 87 | +in your project settings. |
| 88 | + |
| 89 | +#### Automatic export to JavaScript |
| 90 | + |
| 91 | +Given |
| 92 | + |
| 93 | +{% highlight scala %} |
| 94 | +package bar |
| 95 | + |
| 96 | +object Foo extends js.JSApp { |
| 97 | + def main(): Unit = println("Hello world!") |
| 98 | +} |
| 99 | +{% endhighlight %} |
| 100 | + |
| 101 | +the object `Foo` and its `main` method are automatically exported such that JavaScript code can call |
| 102 | + |
| 103 | +{% highlight javascript %} |
| 104 | +bar.Foo().main(); |
| 105 | +{% endhighlight %} |
| 106 | + |
| 107 | +To achieve exactly the same behavior without `js.JSApp`, define `Foo` as |
| 108 | + |
| 109 | +{% highlight scala %} |
| 110 | +package bar |
| 111 | + |
| 112 | +object Foo { |
| 113 | + @JSExportTopLevel("bar.Foo") |
| 114 | + protected def getInstance(): this.type = this |
| 115 | + |
| 116 | + @JSExport |
| 117 | + def main(): Unit = println("Hello world!") |
| 118 | +} |
| 119 | +{% endhighlight %} |
| 120 | + |
| 121 | +Alternatively, you can define it as |
| 122 | + |
| 123 | +{% highlight scala %} |
| 124 | +package bar |
| 125 | + |
| 126 | +object Foo { |
| 127 | + @JSExportTopLevel("bar.Foo.main") |
| 128 | + def main(): Unit = println("Hello world!") |
| 129 | +} |
| 130 | +{% endhighlight %} |
| 131 | + |
| 132 | +but in that case, the JavaScript code will have to be changed to |
| 133 | + |
| 134 | +{% highlight javascript %} |
| 135 | +bar.Foo.main(); |
| 136 | +{% endhighlight %} |
| 137 | + |
| 138 | +### `jsDependencies += RuntimeDOM` and `requiresDOM := true` |
| 139 | + |
| 140 | +These settings will not be supported by [`sbt-jsdependencies`](https://github.com/scala-js/jsdependencies) 1.x, the new home of `jsDependencies` and related features. |
| 141 | + |
| 142 | +Instead of relying on them to configure a JS environment equipped with the DOM, you should explicitly do so. |
| 143 | +For example, to use Node.js with jsdom, use: |
| 144 | + |
| 145 | +{% highlight scala %} |
| 146 | +jsEnv := new org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv() |
| 147 | +{% endhighlight %} |
| 148 | + |
| 149 | +## New features |
| 150 | + |
| 151 | +### Improved support for cross-compilation with 1.x and `jsDependencies` |
| 152 | + |
| 153 | +[The release notes of Scala.js 1.0.0-M1]({{ BASE_PATH }}/news/2017/07/03/announcing-scalajs-1.0.0-M1/) detail how to cross-compile between 0.6.x and 1.x. |
| 154 | +One aspect of it was particularly painful: handling the new `JSDependenciesPlugin`. |
| 155 | +Scala.js 0.6.20 makes this easier by introducing a shim of `JSDependenciesPlugin` inside sbt-scalajs. |
| 156 | +It is now sufficient to add the following to your `project/plugins.sbt`: |
| 157 | + |
| 158 | +{% highlight scala %} |
| 159 | +// For jsDependencies |
| 160 | +{ |
| 161 | + if (scalaJSVersion.startsWith("0.6.")) Nil |
| 162 | + else Seq(addSbtPlugin("org.scala-js" % "sbt-jsdependencies" % "1.0.0-M1")) |
| 163 | +} |
| 164 | +{% endhighlight %} |
| 165 | + |
| 166 | +and add `enablePlugins(JSDependenciesPlugin)` to the projects that require it. |
| 167 | +There is no need for the hacky `project/JSDependenciesCompat.scala` anymore. |
| 168 | + |
| 169 | +### JDK APIs |
| 170 | + |
| 171 | +The following JDK API class has been added: |
| 172 | + |
| 173 | +* `java.util.SplittableRandom` |
| 174 | + |
| 175 | +## Bug fixes |
| 176 | + |
| 177 | +The following bugs have been fixed in 0.6.20: |
| 178 | + |
| 179 | +* [#3107](https://github.com/scala-js/scala-js/issues/3107) `ByteArrayOutputStream` (and in general all `Closeable`s) should be an `AutoCloseable` |
| 180 | +* [#3082](https://github.com/scala-js/scala-js/issues/3082) Incorrect handling of main generates broken code |
| 181 | + |
| 182 | +You can find the full list [on GitHub](https://github.com/scala-js/scala-js/issues?q=is%3Aissue+milestone%3Av0.6.20+is%3Aclosed). |
0 commit comments