Skip to content

Commit e9cea1b

Browse files
authored
Cross-build for Scala.js (#515)
* Cross-build for Scala.js * Fixup remaining linking issues * Poke ci * Set eviction rule for Scala.js * Disable scoverage for Scala.js * JS hashing bug fix * Enable Scala.js bundler for tests * Fix cast exception * Implement ByteVector <-> ArrayBuffer conversion * Use Uint8Array * Use yarn for test npm modules * Move #231 to jvm-only * Add US locale * Add scala-java-time to eviction rules * Disable parallel execution, for a moment * Run tests alphabetically * Move parallel test setting * Revert "Run tests alphabetically" This reverts commit b99cf2a. * Disable several test suites * Disable several test suites * Bump munit * Remove framework declaration * Add junit-interface to deps * Undo all the damage * Dependency adjustments * Disable failing test * Tryint to isolate * Isolating... * Isolating... * Isolating... * Isolating... * Isolating... * Isolating... * Undo all the damage * One more isolation * And now it shouldn't crash * Try fixing scram * Re-enable SslTest * Bump fs2 * Bump Scalajs version * Try out new locale dependency * Bump fs2 * Bump fs2 * Bump fs2, fix failing test * Fix 2.12 and 3.0 compile * Add scala-java-time dep * Fix eviction warning * Correctly enable/disable logging * Restore sourcepos * Address review comments
1 parent 548b162 commit e9cea1b

File tree

218 files changed

+8325
-206
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

218 files changed

+8325
-206
lines changed

build.sbt

Lines changed: 69 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ lazy val `scala-2.13` = "2.13.6"
66
lazy val `scala-3.0` = "3.0.1"
77

88
// This is used in a couple places
9-
lazy val fs2Version = "3.0.5"
9+
lazy val fs2Version = "3.1.0"
1010
lazy val natchezVersion = "0.1.5"
1111

1212
// We do `evictionCheck` in CI
1313
inThisBuild(Seq(
1414
evictionRules ++= Seq(
1515
"org.typelevel" % "cats-*" % "semver-spec",
16+
"org.scala-js" % "scalajs-*" % "semver-spec",
17+
"org.portable-scala" % "portable-scala-reflect_*" % "semver-spec",
18+
"io.github.cquiroz" % "scala-java-time_*" % "semver-spec",
1619
)
1720
))
1821

@@ -65,9 +68,9 @@ lazy val commonSettings = Seq(
6568
Compile / unmanagedSourceDirectories ++= {
6669
val sourceDir = (Compile / sourceDirectory).value
6770
CrossVersion.partialVersion(scalaVersion.value) match {
68-
case Some((3, _)) => Seq(sourceDir / "scala-2.13+")
71+
case Some((3, _)) => Seq(sourceDir / "scala-2.13+", file(sourceDir.getPath.replaceFirst("jvm", "shared").replaceFirst("js", "shared")) / "scala-2.13+")
6972
case Some((2, 12)) => Seq()
70-
case Some((2, _)) => Seq(sourceDir / "scala-2.13+")
73+
case Some((2, _)) => Seq(sourceDir / "scala-2.13+", file(sourceDir.getPath.replaceFirst("jvm", "shared").replaceFirst("js", "shared")) / "scala-2.13+")
7174
case _ => Seq()
7275
}
7376
},
@@ -89,99 +92,124 @@ lazy val skunk = project
8992
.enablePlugins(AutomateHeaderPlugin)
9093
.settings(commonSettings)
9194
.settings(publish / skip := true)
92-
.dependsOn(core, tests, circe, refined, example)
93-
.aggregate(core, tests, circe, refined, example)
95+
.dependsOn(core.jvm, core.js, tests.jvm, tests.js, circe.jvm, circe.js, refined.jvm, refined.js, example)
96+
.aggregate(core.jvm, core.js, tests.jvm, tests.js, circe.jvm, circe.js, refined.jvm, refined.js, example)
9497

95-
lazy val core = project
98+
lazy val core = crossProject(JVMPlatform, JSPlatform)
99+
.crossType(CrossType.Full)
96100
.in(file("modules/core"))
97101
.enablePlugins(AutomateHeaderPlugin)
102+
.jsEnablePlugins(ScalaJSBundlerPlugin)
103+
.jsConfigure(_.disablePlugins(ScoverageSbtPlugin))
98104
.settings(commonSettings)
99105
.settings(
100106
name := "skunk-core",
101107
description := "Tagless, non-blocking data access library for Postgres.",
102108
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
103109
libraryDependencies ++= Seq(
104-
"org.typelevel" %% "cats-core" % "2.6.1",
105-
"org.typelevel" %% "cats-effect" % "3.1.1",
106-
"co.fs2" %% "fs2-core" % fs2Version,
107-
"co.fs2" %% "fs2-io" % fs2Version,
108-
"org.scodec" %% "scodec-core" % (if (scalaVersion.value.startsWith("3.")) "2.0.0" else "1.11.8"),
109-
"org.scodec" %% "scodec-cats" % "1.1.0",
110-
"org.tpolecat" %% "natchez-core" % natchezVersion,
111-
"org.tpolecat" %% "sourcepos" % "1.0.0",
112-
"com.ongres.scram" % "client" % "2.1",
113-
"org.scala-lang.modules" %% "scala-collection-compat" % "2.4.4",
110+
"org.typelevel" %%% "cats-core" % "2.6.1",
111+
"org.typelevel" %%% "cats-effect" % "3.1.1",
112+
"co.fs2" %%% "fs2-core" % fs2Version,
113+
"co.fs2" %%% "fs2-io" % fs2Version,
114+
"org.scodec" %%% "scodec-core" % (if (scalaVersion.value.startsWith("3.")) "2.0.0" else "1.11.8"),
115+
"org.scodec" %%% "scodec-cats" % "1.1.0",
116+
"org.tpolecat" %%% "natchez-core" % natchezVersion,
117+
"org.tpolecat" %%% "sourcepos" % "1.0.1",
118+
"org.scala-lang.modules" %%% "scala-collection-compat" % "2.4.4",
114119
) ++ Seq(
115-
"com.beachape" %% "enumeratum" % "1.6.1",
120+
"com.beachape" %%% "enumeratum" % "1.6.1",
116121
).filterNot(_ => scalaVersion.value.startsWith("3."))
122+
).jvmSettings(
123+
libraryDependencies += "com.ongres.scram" % "client" % "2.1",
124+
).jsSettings(
125+
libraryDependencies ++= Seq(
126+
"io.github.cquiroz" %%% "scala-java-time" % "2.3.0",
127+
"io.github.cquiroz" %%% "locales-minimal-en_us-db" % "1.2.1"
128+
),
129+
Compile / npmDependencies += "saslprep" -> "1.0.3",
130+
useYarn := true,
131+
yarnExtraArgs += "--frozen-lockfile",
117132
)
118133

119-
lazy val refined = project
134+
lazy val refined = crossProject(JVMPlatform, JSPlatform)
135+
.crossType(CrossType.Pure)
120136
.in(file("modules/refined"))
121137
.dependsOn(core)
122138
.enablePlugins(AutomateHeaderPlugin)
139+
.jsConfigure(_.disablePlugins(ScoverageSbtPlugin))
123140
.settings(commonSettings)
124141
.settings(
125142
libraryDependencies ++= Seq(
126-
"eu.timepit" %% "refined" % "0.9.27",
143+
"eu.timepit" %%% "refined" % "0.9.27",
127144
)
128145
)
129146

130-
lazy val circe = project
147+
lazy val circe = crossProject(JVMPlatform, JSPlatform)
148+
.crossType(CrossType.Pure)
131149
.in(file("modules/circe"))
132150
.dependsOn(core)
133151
.enablePlugins(AutomateHeaderPlugin)
152+
.jsConfigure(_.disablePlugins(ScoverageSbtPlugin))
134153
.settings(commonSettings)
135154
.settings(
136155
name := "skunk-circe",
137156
libraryDependencies ++= Seq(
138-
"io.circe" %% "circe-core" % "0.14.1",
139-
"io.circe" %% "circe-parser" % "0.14.1"
157+
"io.circe" %%% "circe-core" % "0.14.1",
158+
"io.circe" %%% "circe-parser" % "0.14.1"
140159
)
141160
)
142161

143-
lazy val tests = project
162+
lazy val tests = crossProject(JVMPlatform, JSPlatform)
163+
.crossType(CrossType.Full)
144164
.in(file("modules/tests"))
145165
.dependsOn(core, circe)
146166
.enablePlugins(AutomateHeaderPlugin)
167+
.jsEnablePlugins(ScalaJSBundlerPlugin)
168+
.jsConfigure(_.disablePlugins(ScoverageSbtPlugin))
147169
.settings(commonSettings)
148170
.settings(
149171
publish / skip := true,
150172
scalacOptions -= "-Xfatal-warnings",
151173
libraryDependencies ++= Seq(
152-
"org.typelevel" %% "scalacheck-effect-munit" % "1.0.2",
153-
"org.typelevel" %% "munit-cats-effect-3" % "1.0.5",
154-
"org.typelevel" %% "cats-free" % "2.6.1",
155-
"org.typelevel" %% "cats-laws" % "2.6.1",
156-
"org.typelevel" %% "discipline-munit" % "1.0.9",
174+
"org.scalameta" %%% "munit" % "0.7.27",
175+
"org.scalameta" % "junit-interface" % "0.7.27",
176+
"org.typelevel" %%% "scalacheck-effect-munit" % "1.0.2",
177+
"org.typelevel" %%% "munit-cats-effect-3" % "1.0.5",
178+
"org.typelevel" %%% "cats-free" % "2.6.1",
179+
"org.typelevel" %%% "cats-laws" % "2.6.1",
180+
"org.typelevel" %%% "discipline-munit" % "1.0.9",
157181
) ++ Seq(
158-
"io.chrisdavenport" %% "cats-time" % "0.3.4",
182+
"io.chrisdavenport" %%% "cats-time" % "0.3.4",
159183
).filterNot(_ => scalaVersion.value.startsWith("3.")),
160184
testFrameworks += new TestFramework("munit.Framework")
161185
)
186+
.jsSettings(
187+
Test / scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.CommonJSModule)),
188+
useYarn := true
189+
)
162190

163191
lazy val example = project
164192
.in(file("modules/example"))
165-
.dependsOn(core)
193+
.dependsOn(core.jvm)
166194
.enablePlugins(AutomateHeaderPlugin)
167195
.settings(commonSettings)
168196
.settings(
169197
publish / skip := true,
170198
libraryDependencies ++= Seq(
171-
"org.tpolecat" %% "natchez-honeycomb" % natchezVersion,
172-
"org.tpolecat" %% "natchez-jaeger" % natchezVersion,
199+
"org.tpolecat" %%% "natchez-honeycomb" % natchezVersion,
200+
"org.tpolecat" %%% "natchez-jaeger" % natchezVersion,
173201
)
174202
// ) ++ Seq(
175-
// "org.http4s" %% "http4s-dsl" % "0.21.22",
176-
// "org.http4s" %% "http4s-blaze-server" % "0.21.22",
177-
// "org.http4s" %% "http4s-circe" % "0.21.22",
178-
// "io.circe" %% "circe-generic" % "0.13.0",
203+
// "org.http4s" %%% "http4s-dsl" % "0.21.22",
204+
// "org.http4s" %%% "http4s-blaze-server" % "0.21.22",
205+
// "org.http4s" %%% "http4s-circe" % "0.21.22",
206+
// "io.circe" %%% "circe-generic" % "0.13.0",
179207
// ).filterNot(_ => scalaVersion.value.startsWith("3."))
180208
)
181209

182210
lazy val docs = project
183211
.in(file("modules/docs"))
184-
.dependsOn(core)
212+
.dependsOn(core.jvm)
185213
.enablePlugins(AutomateHeaderPlugin)
186214
.enablePlugins(ParadoxPlugin)
187215
.enablePlugins(ParadoxSitePlugin)
@@ -196,11 +224,11 @@ lazy val docs = project
196224
paradoxTheme := Some(builtinParadoxTheme("generic")),
197225
version := version.value.takeWhile(_ != '+'), // strip off the +3-f22dca22+20191110-1520-SNAPSHOT business
198226
paradoxProperties ++= Map(
199-
"scala-versions" -> (core / crossScalaVersions).value.map(CrossVersion.partialVersion).flatten.map(_._2).mkString("2.", "/", ""),
227+
"scala-versions" -> (core.jvm / crossScalaVersions).value.map(CrossVersion.partialVersion).flatten.map(_._2).mkString("2.", "/", ""),
200228
"org" -> organization.value,
201229
"scala.binary.version" -> s"2.${CrossVersion.partialVersion(scalaVersion.value).get._2}",
202-
"core-dep" -> s"${(core / name).value}_2.${CrossVersion.partialVersion(scalaVersion.value).get._2}",
203-
"circe-dep" -> s"${(circe / name).value}_2.${CrossVersion.partialVersion(scalaVersion.value).get._2}",
230+
"core-dep" -> s"${(core.jvm / name).value}_2.${CrossVersion.partialVersion(scalaVersion.value).get._2}",
231+
"circe-dep" -> s"${(circe.jvm / name).value}_2.${CrossVersion.partialVersion(scalaVersion.value).get._2}",
204232
"version" -> version.value,
205233
"scaladoc.skunk.base_url" -> s"https://static.javadoc.io/org.tpolecat/skunk-core_2.12/${version.value}",
206234
"scaladoc.fs2.io.base_url"-> s"https://static.javadoc.io/co.fs2/fs2-io_2.12/${fs2Version}",
@@ -210,6 +238,6 @@ lazy val docs = project
210238
makeSite := makeSite.dependsOn(mdoc.toTask("")).value,
211239
mdocExtraArguments := Seq("--no-link-hygiene"), // paradox handles this
212240
libraryDependencies ++= Seq(
213-
"org.tpolecat" %% "natchez-jaeger" % natchezVersion,
241+
"org.tpolecat" %%% "natchez-jaeger" % natchezVersion,
214242
)
215243
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright (c) 2018-2021 by Rob Norris
2+
// This software is licensed under the MIT License (MIT).
3+
// For more information see LICENSE or https://opensource.org/licenses/MIT
4+
5+
package skunk
6+
7+
private[skunk] trait SSLCompanionPlatform
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) 2018-2021 by Rob Norris
2+
// This software is licensed under the MIT License (MIT).
3+
// For more information see LICENSE or https://opensource.org/licenses/MIT
4+
5+
package skunk.net.message
6+
7+
import scala.scalajs.js
8+
import scala.scalajs.js.typedarray._
9+
10+
private[message] trait PasswordMessagePlatform {
11+
12+
private val crypto = js.Dynamic.global.require("crypto")
13+
14+
// See https://www.postgresql.org/docs/9.6/protocol-flow.html#AEN113418
15+
// and https://github.com/pgjdbc/pgjdbc/blob/master/pgjdbc/src/main/java/org/postgresql/util/MD5Digest.java
16+
def md5(user: String, password: String, salt: Array[Byte]): PasswordMessage = {
17+
18+
// Hash with this thing
19+
var md = crypto.createHash("md5")
20+
21+
// First round
22+
md.update(password)
23+
md.update(user)
24+
var hex = BigInt(1, new Int8Array(md.digest().asInstanceOf[ArrayBuffer]).toArray).toString(16)
25+
while (hex.length < 32)
26+
hex = "0" + hex
27+
28+
// Second round
29+
md = crypto.createHash("md5")
30+
md.update(hex)
31+
md.update(salt.toTypedArray)
32+
hex = BigInt(1, new Int8Array(md.digest().asInstanceOf[ArrayBuffer]).toArray).toString(16)
33+
while (hex.length < 32)
34+
hex = "0" + hex
35+
36+
// Done
37+
new PasswordMessage("md5" + hex) {}
38+
39+
}
40+
41+
}

0 commit comments

Comments
 (0)