Skip to content
This repository was archived by the owner on Jul 30, 2024. It is now read-only.

Commit ba73036

Browse files
author
TATSUNO Yasuhiro
authored
Merge pull request #13 from exoego/conditional-compile
Introduce conditional compile
2 parents d87864e + a38ca13 commit ba73036

File tree

169 files changed

+91
-25
lines changed

Some content is hidden

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

169 files changed

+91
-25
lines changed

app/nodejs_v8/src/test/scala/io/scalajs/nodejs/fs/FsTest.scala renamed to app/current/src/test/scala/nodejs/fs/FsTest.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ import org.scalatest.FunSpec
1212
*/
1313
class FsTest extends FunSpec {
1414

15-
val TEST_RESOURCES = "./app/nodejs_v8/src/test/resources/"
15+
final val testResources = "./app/current/src/test/resources/"
1616

1717
describe("Fs") {
1818

1919
it("supports watching files") {
20-
val watcher = Fs.watch(s"${TEST_RESOURCES}", (eventType, file) => {
20+
val watcher = Fs.watch(s"${testResources}", (eventType, file) => {
2121
info(s"watcher: eventType = '$eventType' file = '$file'")
2222
})
2323
info(s"watcher: ${Util.inspect(watcher)}")
2424

2525
setImmediate(
2626
() =>
27-
Fs.writeFile(s"${TEST_RESOURCES}1.txt", "Hello", error => {
27+
Fs.writeFile(s"${testResources}1.txt", "Hello", error => {
2828
if (isDefined(error)) {
2929
alert(s"error: ${JSON.stringify(error)}")
3030
}
@@ -33,9 +33,9 @@ class FsTest extends FunSpec {
3333
}
3434

3535
it("should stream data") {
36-
val file1 = s"${TEST_RESOURCES}fileA1.txt"
37-
val file2 = s"${TEST_RESOURCES}fileA2.txt"
38-
val file3 = s"${TEST_RESOURCES}fileC2.txt"
36+
val file1 = s"${testResources}fileA1.txt"
37+
val file2 = s"${testResources}fileA2.txt"
38+
val file3 = s"${testResources}fileC2.txt"
3939

4040
val readable = Fs.createReadStream(file1)
4141
val writable = Fs.createWriteStream(file2)
@@ -60,8 +60,8 @@ class FsTest extends FunSpec {
6060
}
6161

6262
it("should pipe data from a Readable to a Writable") {
63-
val file1 = s"${TEST_RESOURCES}fileB1.txt"
64-
val file2 = s"${TEST_RESOURCES}fileB2.txt"
63+
val file1 = s"${testResources}fileB1.txt"
64+
val file2 = s"${testResources}fileB2.txt"
6565

6666
val readable = Fs.createReadStream(file1)
6767
val writable = Fs.createWriteStream(file2)

build.sbt

Lines changed: 61 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ val supportedScalaVersion = Seq(scala212Version, scala213Version)
77

88
val scalatestVersion = "3.0.8"
99
val scalacticVersion = "3.0.8"
10+
val enableIfVersion = "1.1.7"
1011

1112
organization in ThisBuild := "net.exoego"
1213

@@ -18,10 +19,12 @@ lazy val commonSettings = Seq(
1819
"-unchecked",
1920
"-feature",
2021
"-language:implicitConversions",
21-
"-Xlint",
22-
"-Xfatal-warnings"
22+
"-Xlint"
2323
),
24-
scalacOptions in (Compile, doc) ++= Seq("-no-link-warnings")
24+
scalacOptions in (Compile, doc) ++= Seq(
25+
"-Xfatal-warnings",
26+
"-no-link-warnings"
27+
)
2528
)
2629
lazy val commonScalaJsSettings = Seq(
2730
scalacOptions += "-P:scalajs:sjsDefinedByDefault",
@@ -43,13 +46,14 @@ lazy val commonMacroParadiseSetting = Seq(
4346
}
4447
)
4548
val nonPublishingSetting = Seq(
49+
skip in publish := true,
4650
publishArtifact := false,
4751
publish := {},
4852
publishLocal := {}
4953
)
5054

5155
lazy val root = (project in file("."))
52-
.aggregate(core, common, nodejs_v8)
56+
.aggregate(core, current, nodejs_v8)
5357
.settings(commonSettings)
5458
.settings(publishingSettings)
5559
.settings(nonPublishingSetting)
@@ -70,40 +74,80 @@ lazy val core = (project in file("./core"))
7074
)
7175
)
7276

73-
lazy val common = (project in file("./app/common"))
77+
lazy val compilerSwitches = (project in file("./compiler-switches"))
78+
.settings(commonSettings)
79+
.settings(nonPublishingSetting)
80+
.settings(
81+
libraryDependencies ++= Seq(
82+
"org.scala-lang" % "scala-reflect" % scalaVersion.value
83+
)
84+
)
85+
86+
lazy val current = (project in file("./app/current"))
7487
.enablePlugins(ScalaJSPlugin)
7588
.settings(commonSettings)
7689
.settings(commonScalaJsSettings)
7790
.settings(commonMacroParadiseSetting)
7891
.settings(publishingSettings)
7992
.settings(
80-
name := "scala-js-nodejs-common",
93+
scalacOptions ++= Seq(
94+
"-Xmacro-settings:nodeJs12.5.0"
95+
),
96+
name := "scala-js-nodejs-v12",
8197
libraryDependencies ++= Seq(
82-
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
83-
"org.scalactic" %% "scalactic" % scalacticVersion,
84-
"org.scalatest" %%% "scalatest" % scalatestVersion % "test"
98+
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
99+
"org.scalactic" %% "scalactic" % scalacticVersion,
100+
"org.scalatest" %%% "scalatest" % scalatestVersion % "test",
101+
"com.thoughtworks.enableIf" %% "enableif" % enableIfVersion
85102
)
86103
)
87-
.dependsOn(core)
104+
.dependsOn(core, compilerSwitches)
88105

89-
lazy val nodejs_v8 = (project in file("./app/nodejs_v8"))
90-
.dependsOn(common)
106+
lazy val nodejs_v10 = (project in file("./app/nodejs-v10"))
91107
.enablePlugins(ScalaJSPlugin)
92108
.settings(commonSettings)
93109
.settings(commonScalaJsSettings)
94110
.settings(commonMacroParadiseSetting)
95111
.settings(publishingSettings)
96112
.settings(
113+
unmanagedSourceDirectories in Compile += (baseDirectory in current).value / "src" / "main" / "scala",
114+
scalacOptions ++= Seq(
115+
"-Xmacro-settings:nodeJs10.16.0"
116+
),
117+
name := "scala-js-nodejs-v10",
118+
description := "NodeJS v10.16.0 API for Scala.js",
119+
homepage := Some(url("https://github.com/exoego/scala-js-nodejs")),
120+
libraryDependencies ++= Seq(
121+
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
122+
"org.scalactic" %% "scalactic" % scalacticVersion,
123+
"org.scalatest" %%% "scalatest" % scalatestVersion % "test",
124+
"com.thoughtworks.enableIf" %% "enableif" % enableIfVersion
125+
)
126+
)
127+
.dependsOn(core, compilerSwitches)
128+
129+
lazy val nodejs_v8 = (project in file("./app/nodejs-v8"))
130+
.enablePlugins(ScalaJSPlugin)
131+
.settings(commonSettings)
132+
.settings(commonScalaJsSettings)
133+
.settings(commonMacroParadiseSetting)
134+
.settings(publishingSettings)
135+
.settings(
136+
unmanagedSourceDirectories in Compile += (baseDirectory in current).value / "src" / "main" / "scala",
137+
scalacOptions ++= Seq(
138+
"-Xmacro-settings:nodeJs8.16.0"
139+
),
97140
name := "scala-js-nodejs-v8",
98-
description := "NodeJS v8.7.0 API for Scala.js",
141+
description := "NodeJS v8.16.0 API for Scala.js",
99142
homepage := Some(url("https://github.com/exoego/scala-js-nodejs")),
100143
libraryDependencies ++= Seq(
101-
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
102-
"org.scalactic" %% "scalactic" % scalacticVersion,
103-
"org.scalatest" %%% "scalatest" % scalatestVersion % "test"
144+
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
145+
"org.scalactic" %% "scalactic" % scalacticVersion,
146+
"org.scalatest" %%% "scalatest" % scalatestVersion % "test",
147+
"com.thoughtworks.enableIf" %% "enableif" % enableIfVersion
104148
)
105149
)
106-
.dependsOn(core)
150+
.dependsOn(core, compilerSwitches)
107151

108152
lazy val publishingSettings = Seq(
109153
licenses := Seq("APL2" -> url("http://www.apache.org/licenses/LICENSE-2.0.txt")),
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package io.scalajs.nodejs
2+
3+
import scala.reflect.macros.whitebox
4+
5+
object CompilerSwitches {
6+
7+
private val nodejsVersionPattern = "^nodeJs([0-9]{1,2})\\.([0-9]{1,2})\\.([0-9]{1,2})$".r
8+
9+
private def compare(predicate: (Int, Int, Int) => Boolean): String => Boolean = { version: String =>
10+
val nodejsVersionPattern(major, minor, patch) = version
11+
predicate(major.toInt, minor.toInt, patch.toInt)
12+
}
13+
14+
final val isNodeJs8 = (c: whitebox.Context) => c.settings.exists(compare((major, _, _) => major == 8))
15+
final val gteNodeJs8 = (c: whitebox.Context) => c.settings.exists(compare((major, _, _) => major >= 8))
16+
17+
final val isNodeJs10 = (c: whitebox.Context) => c.settings.exists(compare((major, _, _) => major == 10))
18+
final val gteNodeJs10 = (c: whitebox.Context) => c.settings.exists(compare((major, _, _) => major >= 10))
19+
20+
final val isNodeJs12 = (c: whitebox.Context) => c.settings.exists(compare((major, _, _) => major == 12))
21+
final val gteNodeJs12 = (c: whitebox.Context) => c.settings.exists(compare((major, _, _) => major >= 12))
22+
}

0 commit comments

Comments
 (0)