Skip to content

Commit

Permalink
Merge pull request #115 from ScalablyTyped/beta5
Browse files Browse the repository at this point in the history
Beta5 - Finalize Scala.js 1 support
  • Loading branch information
oyvindberg authored Feb 27, 2020
2 parents 5bead00 + 30ba4a9 commit 88836f7
Show file tree
Hide file tree
Showing 60 changed files with 1,087 additions and 972 deletions.
10 changes: 5 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ lazy val docs = project

lazy val scalajs = project
.dependsOn(utils, logging)
.configure(baseSettings, publicationSettings)
.configure(baseSettings, publicationSettings).settings(
libraryDependencies ++= Seq(Deps.scalaXml),
)

lazy val phases = project
.dependsOn(utils, logging)
Expand All @@ -35,7 +37,6 @@ lazy val `importer-portable` = project
.dependsOn(ts, scalajs, phases)
.enablePlugins(BuildInfoPlugin)
.settings(
libraryDependencies ++= Seq(Deps.scalaXml),
buildInfoPackage := "org.scalablytyped.converter.internal",
buildInfoKeys := Seq[BuildInfoKey](
"gitSha" -> "git rev-parse -1 HEAD".!!.split("\n").last.trim,
Expand Down Expand Up @@ -67,16 +68,15 @@ lazy val `sbt-converter06` = project
.configure(pluginSettings, baseSettings, publicationSettings)
.settings(
name := "sbt-converter06",
addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler-sjs06" % "0.16.0"),
addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler-sjs06" % "0.17.0"),
)

lazy val `sbt-converter` = project
.configure(pluginSettings, baseSettings, publicationSettings)
.settings(
name := "sbt-converter",
Compile / unmanagedSourceDirectories += (`sbt-converter06` / Compile / sourceDirectory).value,
//addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.16.0"),
addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.16.0+4-65a0c190"), //FIXME wait for https://github.com/scalacenter/scalajs-bundler/pull/324#event-3044771159
addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.17.0"),
)

lazy val root = project
Expand Down
4 changes: 2 additions & 2 deletions docs/devel/running.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ For development you'll always use "debug mode".
| `-publish` | Publish to bintray. You'll need credentials in `~/.bintray/.credentials`
| `-softWrites` | Will only write changed/deleted files. This is essential if you want to keep ScalablyTyped products open in an IDE to avoid reindexing the world.
| `-flavourNormal` | default
| `-flavourSlinky` | Use slinky flavour, integrate with scalajs-dom, and generate slinky components
| `-flavourJapgolly` | Use scalajs-react flavour, integrate with scalajs-dom, and generate scalajs-react components
| `-flavourSlinky` | Use slinky flavour, integrate with scala-js-dom, and generate slinky components
| `-flavourJapgolly` | Use scalajs-react flavour, integrate with scala-js-dom, and generate scalajs-react components
| `-useScalaJsDomTypes` | Rewrite types to use scala-js-dom types when using `-flavourNormal`

### Directories
Expand Down
6 changes: 3 additions & 3 deletions docs/flavour.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ You specify which one you want like this:
```scala
project.settings(
// for Slinky web projects
Compile / stFlavour := Flavour.Slinky,
stFlavour := Flavour.Slinky,
// for Slinky native projects
Compile / stFlavour := Flavour.SlinkyNative,
stFlavour := Flavour.SlinkyNative,
// for scalajs-react projects
Compile / stFlavour := Flavour.Japgolly
stFlavour := Flavour.Japgolly
)
```

Expand Down
28 changes: 15 additions & 13 deletions docs/plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ Then check out the demo projects:
Due to conflicting scala library dependencies **this plugin needs sbt 1.3.0 or newer**.

Since we generate source code, it should work with any combination of
Scala 2.12 / 2.13 and Scala.js 1 / 0.6.
Certain [flavours](flavour.md) might not yet work on Scala.js 1 if the libraries have not been published.
Scala 2.12 / 2.13 and Scala.js 1.x / 0.6.x

Note that the scalajs-react [flavour](flavour.md) won't work with Scala.js 1.x until the library has been updated.

## Add to your `project/plugins.sbt`

```scala
resolvers += Resolver.bintrayRepo("oyvindberg", "converter")

// for Scala.js 1.0.0 milestones
// for Scala.js 1.x.x
addSbtPlugin("org.scalablytyped.converter" % "sbt-converter" % "@VERSION@")

// for Scala.js 0.6.x
Expand Down Expand Up @@ -70,17 +71,17 @@ Scala.js react wrapper libraries. If you want to use either make sure to choose
```scala
project.settings(
// for Slinky web projects
Compile / stFlavour := Flavour.Slinky,
stFlavour := Flavour.Slinky,
// for Slinky native projects
Compile / stFlavour := Flavour.SlinkyNative,
stFlavour := Flavour.SlinkyNative,
)
```

### Scalajs-react

```scala
project.settings(
Compile / stFlavour := Flavour.Japgolly
stFlavour := Flavour.Japgolly
)
```

Expand All @@ -101,10 +102,11 @@ Yarn will need to be present on your system for this to work. You should also ch
Hopefully everything will work automatically. Change an npm dependency, reimport project, wait, voila.


The plugin taps into the `unmanagedJars` task in sbt, and this has some consequences for how it works.
The plugin taps into the `allDependencies` task in sbt, and this has some consequences for how it works.

Whenever the task is evaluated, typically through a `compile` or an import into an IDE, the plugin

- Runs a customized version of `installNpmDependencies` from scalajs-bundler, changed to avoid touching `unmanagedJars`.
- Runs a customized version of `installNpmDependencies` from scalajs-bundler, changed to avoid touching the classpath.

- Computes a digest from the resulting `package.json` file and of the configuration of the plugin

Expand Down Expand Up @@ -136,7 +138,7 @@ Some usage examples:

```scala
project.settings(
Compile / stIgnore += "csstype"
stIgnore += "csstype"
)
```

Expand All @@ -145,7 +147,7 @@ You also don't need the icons. If that's the case, you can also exclude prefixes

```scala
project.settings(
Compile / stIgnore ++= List("material-ui/svg-icons")
stIgnore ++= List("material-ui/svg-icons")
)
```

Expand All @@ -161,7 +163,7 @@ However, there an imperfection somewhere in Scala.js and/or scalac with handling
This setting also uses `Selection`, so an example usage is:
```scala
project.settings(
Compile / stEnableScalaJsDefined := Selection.All()
stEnableScalaJsDefined := Selection.All()
)
```

Expand All @@ -177,7 +179,7 @@ For instance, a node application should not access the DOM at all,

```scala
project.settings(
Compile / stStdlib := List("es6", "es2018.asyncgenerator")
stStdlib := List("es6", "es2018.asyncgenerator")
)
```

Expand All @@ -191,7 +193,7 @@ You can adjust the top-level package into which we put the generated code.

```scala
project.settings(
Compile / stOutputPackage := "mypackage",
stOutputPackage := "mypackage",
)
```

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.scalablytyped.converter.internal
package importer

import org.scalablytyped.converter.internal.scalajs.Dep
import io.circe.Decoder
import io.circe.generic.semiauto.deriveDecoder
import org.scalablytyped.converter.internal.scalajs.Dep

final case class FacadeJson(typings: Set[String], dependencies: Set[Dep])
final case class FacadeJson(typings: Set[String], dependencies: Set[Dep.ScalaJs])

object FacadeJson {
implicit val DecoderDep: Decoder[Dep] = deriveDecoder[Dep]
implicit val Decoder: Decoder[FacadeJson] = deriveDecoder[FacadeJson]
implicit val DecoderDep: Decoder[Dep.ScalaJs] = deriveDecoder[Dep.ScalaJs]
implicit val Decoder: Decoder[FacadeJson] = deriveDecoder[FacadeJson]
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,21 @@ object FileLocking {
tryWrite[V](path, onExists = onExists, onNotExists = onNotExists)
}

def tryWrite[T](path: Path, onExists: (FileChannel, () => ByteBuffer) => T, onNotExists: FileChannel => T): T = {
def tryWrite[T](path: Path, onExists: (FileChannel, () => ByteBuffer) => T, onNotExists: FileChannel => T): T =
withLock(path) { channel =>
val size = channel.size
if (size > 0) {
onExists(channel, () => {
val contents = ByteBuffer.allocate(size.toInt)
channel.read(contents)
contents
})
} else {
onNotExists(channel)
}
}

def withLock[T](path: Path)(f: FileChannel => T): T = {
var continue = true
var ret = null.asInstanceOf[T]
Files.createDirectories(path.getParent)
Expand All @@ -73,16 +86,7 @@ object FileLocking {

val channel = FileChannel.open(path, flags: _*)
val lock = channel.lock()
val size = channel.size
if (size > 0) {
ret = onExists(channel, () => {
val contents = ByteBuffer.allocate(size.toInt)
channel.read(contents)
contents
})
} else {
ret = onNotExists(channel)
}
ret = f(channel)

lock.release()
channel.close()
Expand Down
Loading

0 comments on commit 88836f7

Please sign in to comment.