From a2e8e7764479844e7a946aa3383197864c651f3d Mon Sep 17 00:00:00 2001 From: Billy Autrey <40704452+BillyAutrey@users.noreply.github.com> Date: Thu, 17 Oct 2024 16:47:30 -0500 Subject: [PATCH 1/5] Sbt 2 build compatibility for package test. --- src/sbt-test/sbt-web/package/build.sbt | 26 ++++++++++++++++++- .../package/project/FileAssertions.scala | 6 +++++ src/sbt-test/sbt-web/package/test | 15 ++++++----- 3 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 src/sbt-test/sbt-web/package/project/FileAssertions.scala diff --git a/src/sbt-test/sbt-web/package/build.sbt b/src/sbt-test/sbt-web/package/build.sbt index f3232ec..d7c7649 100644 --- a/src/sbt-test/sbt-web/package/build.sbt +++ b/src/sbt-test/sbt-web/package/build.sbt @@ -1,3 +1,5 @@ +import FileAssertions.* + lazy val root = (project in file(".")).enablePlugins(SbtWeb) name := "Web Project" @@ -8,4 +10,26 @@ crossPaths := false libraryDependencies += "org.webjars" % "jquery" % "2.0.3-1" -TaskKey[Unit]("extractAssets") := IO.unzip((artifactPath in (Assets, packageBin)).value, file("extracted")) +TaskKey[Unit]("extractAssets") := IO.unzip( + SbtWeb.asFile(((Assets / packageBin) / artifactPath).value, fileConverter.value), + file("extracted") +) + +// $ exists target/web-project-0.1-web-assets.jar +TaskKey[Unit]("fileCheckAssets") := { + assertExists(target.value / "web-project-0.1-web-assets.jar") +} + +// $ exists extracted/js/a.js +// $ exists extracted/lib/jquery/jquery.js +TaskKey[Unit]("fileCheckExtracted") := { + assertExists(baseDirectory.value / "extracted" / "js" / "a.js") + assertExists(baseDirectory.value / "extracted" / "lib" / "jquery" / "jquery.js") +} + +// $ exists extracted/public/js/a.js +// $ exists extracted/public/lib/jquery/jquery.js +TaskKey[Unit]("fileCheckPublic") := { + assertExists(baseDirectory.value / "extracted" / "public" / "js" / "a.js") + assertExists(baseDirectory.value / "extracted" / "public" / "lib" / "jquery" / "jquery.js") +} diff --git a/src/sbt-test/sbt-web/package/project/FileAssertions.scala b/src/sbt-test/sbt-web/package/project/FileAssertions.scala new file mode 100644 index 0000000..7c34174 --- /dev/null +++ b/src/sbt-test/sbt-web/package/project/FileAssertions.scala @@ -0,0 +1,6 @@ +import sbt.* + +object FileAssertions { + def assertExists(file: File): Unit = + assert(file.exists(), s"Could not find ${file.getName}") +} diff --git a/src/sbt-test/sbt-web/package/test b/src/sbt-test/sbt-web/package/test index 689d52a..7ad565c 100644 --- a/src/sbt-test/sbt-web/package/test +++ b/src/sbt-test/sbt-web/package/test @@ -1,14 +1,15 @@ -> web-assets:package -$ exists target/web-project-0.1-web-assets.jar +> compile +> Assets/compile +> Assets/package +#> Web-assets / package +> fileCheckAssets > extractAssets -$ exists extracted/js/a.js -$ exists extracted/lib/jquery/jquery.js +> fileCheckExtracted > 'set Assets / WebKeys.packagePrefix := "public/"' -> web-assets:package +> Assets/package $ delete extracted > extractAssets -$ exists extracted/public/js/a.js -$ exists extracted/public/lib/jquery/jquery.js +> fileCheckPublic From 52fd7a43f8dfb395e1fa5ba07f55f8193caffe5a Mon Sep 17 00:00:00 2001 From: Billy Autrey <40704452+BillyAutrey@users.noreply.github.com> Date: Mon, 21 Oct 2024 08:22:31 -0500 Subject: [PATCH 2/5] Scala 3 compatibility for package and publish-webjar. --- src/sbt-test/sbt-web/package/test | 3 --- src/sbt-test/sbt-web/publish-webjar/build.sbt | 18 ++++++++++++++++++ .../project/FileAssertions.scala | 6 ++++++ src/sbt-test/sbt-web/publish-webjar/test | 8 +------- 4 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 src/sbt-test/sbt-web/publish-webjar/project/FileAssertions.scala diff --git a/src/sbt-test/sbt-web/package/test b/src/sbt-test/sbt-web/package/test index 7ad565c..12f8cfd 100644 --- a/src/sbt-test/sbt-web/package/test +++ b/src/sbt-test/sbt-web/package/test @@ -1,7 +1,4 @@ -> compile -> Assets/compile > Assets/package -#> Web-assets / package > fileCheckAssets > extractAssets diff --git a/src/sbt-test/sbt-web/publish-webjar/build.sbt b/src/sbt-test/sbt-web/publish-webjar/build.sbt index 950f7a5..d426d27 100644 --- a/src/sbt-test/sbt-web/publish-webjar/build.sbt +++ b/src/sbt-test/sbt-web/publish-webjar/build.sbt @@ -1,3 +1,5 @@ +import FileAssertions.* + lazy val a = (project in file("module/a")) .enablePlugins(SbtWeb) .settings( @@ -21,3 +23,19 @@ lazy val c = (project in file(".")) .settings( libraryDependencies += "com.github.sbt.web.test" %% "web-module-b" % "0.1-SNAPSHOT" ) + +//$ exists target/web/web-modules/main/webjars/lib/jquery/jquery.js +//$ exists target/web/web-modules/main/webjars/lib/web-module-a/js/a.js +//$ exists target/web/web-modules/main/webjars/lib/web-module-b/js/b.js +// +//$ exists target/web/public/main/lib/jquery/jquery.js +//$ exists target/web/public/main/lib/web-module-a/js/a.js +//$ exists target/web/public/main/lib/web-module-b/js/b.js +TaskKey[Unit]("fileCheck") := { + assertExists(target.value / "web" / "web-modules" / "main" / "webjars" / "lib" / "jquery" / "jquery.js") + assertExists(target.value / "web" / "web-modules" / "main" / "webjars" / "lib" / "web-module-a" / "js" / "a.js") + assertExists(target.value / "web" / "web-modules" / "main" / "webjars" / "lib" / "web-module-b" / "js" / "b.js") + assertExists(target.value / "web" / "public" / "main" / "lib" / "jquery" / "jquery.js") + assertExists(target.value / "web" / "public" / "main" / "lib" / "web-module-a" / "js" / "a.js") + assertExists(target.value / "web" / "public" / "main" / "lib" / "web-module-b" / "js" / "b.js") +} diff --git a/src/sbt-test/sbt-web/publish-webjar/project/FileAssertions.scala b/src/sbt-test/sbt-web/publish-webjar/project/FileAssertions.scala new file mode 100644 index 0000000..7c34174 --- /dev/null +++ b/src/sbt-test/sbt-web/publish-webjar/project/FileAssertions.scala @@ -0,0 +1,6 @@ +import sbt.* + +object FileAssertions { + def assertExists(file: File): Unit = + assert(file.exists(), s"Could not find ${file.getName}") +} diff --git a/src/sbt-test/sbt-web/publish-webjar/test b/src/sbt-test/sbt-web/publish-webjar/test index 74689b7..98894e1 100644 --- a/src/sbt-test/sbt-web/publish-webjar/test +++ b/src/sbt-test/sbt-web/publish-webjar/test @@ -4,10 +4,4 @@ > assets -$ exists target/web/web-modules/main/webjars/lib/jquery/jquery.js -$ exists target/web/web-modules/main/webjars/lib/web-module-a/js/a.js -$ exists target/web/web-modules/main/webjars/lib/web-module-b/js/b.js - -$ exists target/web/public/main/lib/jquery/jquery.js -$ exists target/web/public/main/lib/web-module-a/js/a.js -$ exists target/web/public/main/lib/web-module-b/js/b.js +> fileCheck From 9bd4ca9e45c68a8e9703632e7dca5cf1e217e989 Mon Sep 17 00:00:00 2001 From: Billy Autrey <40704452+BillyAutrey@users.noreply.github.com> Date: Mon, 21 Oct 2024 18:09:06 -0500 Subject: [PATCH 3/5] Initial support for sbt 2 testing in multi-module --- src/sbt-test/sbt-web/multi-module/build.sbt | 137 ++++++++++++++++++ .../multi-module/project/FileAssertions.scala | 33 +++++ src/sbt-test/sbt-web/multi-module/test | 70 ++------- 3 files changed, 185 insertions(+), 55 deletions(-) create mode 100644 src/sbt-test/sbt-web/multi-module/project/FileAssertions.scala diff --git a/src/sbt-test/sbt-web/multi-module/build.sbt b/src/sbt-test/sbt-web/multi-module/build.sbt index 9d3303e..12415cd 100644 --- a/src/sbt-test/sbt-web/multi-module/build.sbt +++ b/src/sbt-test/sbt-web/multi-module/build.sbt @@ -1,3 +1,5 @@ +import FileAssertions.* + lazy val a = (project in file(".")) .enablePlugins(SbtWeb) .dependsOn(b) @@ -27,3 +29,138 @@ lazy val e = (project in file("modules/e")) ) lazy val x = (project in file("modules/x")) + +// Check for files + +//$ exists target/web/public/main/js/a.js +//$ exists target/web/public/main/lib/b/js/b.js +//$ exists target/web/public/main/lib/c/js/c.js +//$ exists target/web/public/main/lib/d/js/d.js +//$ exists target/web/public/main/lib/e/js/e.js +//$ exists target/web/public/main/lib/jquery/jquery.js +TaskKey[Unit]("fileCheckA") := { + assertLibrary(target.value, "a", Root) + assertLibrary(target.value, "b") + assertLibrary(target.value, "c") + assertLibrary(target.value, "d") + assertLibrary(target.value, "e") + assertLibrary(target.value, "jquery", External()) +} + +//$ exists modules/b/target/web/public/main/js/b.js +//$ exists modules/b/target/web/public/main/lib/c/js/c.js +//$ exists modules/b/target/web/public/main/lib/d/js/d.js +//$ exists modules/b/target/web/public/main/lib/e/js/e.js +//$ exists modules/b/target/web/public/main/lib/jquery/jquery.js +TaskKey[Unit]("fileCheckB") := { + assertLibrary((b / target).value , "b", Root) + assertLibrary((b / target).value, "c") + assertLibrary((b / target).value, "d") + assertLibrary((b / target).value, "e") + assertLibrary((b / target).value, "jquery", External()) +} + +//# c has set import directly +//$ exists modules/c/target/web/public/main/js/c.js +//$ exists modules/c/target/web/public/main/js/e.js +//$ exists modules/c/target/web/public/main/lib/jquery/jquery.js +TaskKey[Unit]("fileCheckC") := { + assertLibrary((c / target).value, "c", Root) + assertLibrary((c / target).value, "e", Root) + assertLibrary((c / target).value, "jquery", External()) +} + +//$ exists modules/d/target/web/public/main/js/d.js +//$ exists modules/d/target/web/public/main/lib/e/js/e.js +//$ exists modules/d/target/web/public/main/lib/jquery/jquery.js +TaskKey[Unit]("fileCheckD") := { + assertLibrary((d / target).value, "d", Root) + assertLibrary((d / target).value, "e") + assertLibrary((d / target).value, "jquery", External()) +} +//> e/assets +// +//$ exists modules/e/target/web/public/main/js/e.js +//$ exists modules/e/target/web/public/main/lib/jquery/jquery.js +TaskKey[Unit]("fileCheckE") := { + assertLibrary((e / target).value, "e", Root) + assertLibrary((e / target).value, "jquery", External()) +} +//> b/web-assets-test:assets +// +//# b has disabled direct modules so we expect lib/b here +//$ exists modules/b/target/web/public/test/lib/b/js/b.js +// +//$ exists modules/b/target/web/public/test/lib/c/js/c.js +//$ exists modules/b/target/web/public/test/lib/c/js/u.js +//$ exists modules/b/target/web/public/test/lib/d/js/d.js +//$ exists modules/b/target/web/public/test/lib/d/js/u.js +//$ exists modules/b/target/web/public/test/lib/e/js/e.js +//$ exists modules/b/target/web/public/test/lib/e/js/t.js +//$ exists modules/b/target/web/public/test/lib/jquery/jquery.js +TaskKey[Unit]("fileCheckBTest") := { + assertLibrary((b / target).value, "b", TestLibrary) + assertLibrary((b / target).value, "c", TestLibrary) + assertLibrary((b / target).value, "c", TestLibrary, Some("u")) + assertLibrary((b / target).value, "d", TestLibrary) + assertLibrary((b / target).value, "d", TestLibrary, Some("u")) + assertLibrary((b / target).value, "e", TestLibrary) + assertLibrary((b / target).value, "e", TestLibrary, Some("t")) + assertLibrary((b / target).value, "jquery", External("test")) +} +//> c/web-assets-test:assets +// +//# c has set import directly +//$ exists modules/c/target/web/public/test/js/c.js +//$ exists modules/c/target/web/public/test/js/u.js +//$ exists modules/c/target/web/public/test/js/e.js +//$ exists modules/c/target/web/public/test/js/t.js +//$ exists modules/c/target/web/public/test/lib/jquery/jquery.js +TaskKey[Unit]("fileCheckCTest") := { + assertLibrary((c / target).value, "c", TestRoot) + assertLibrary((c / target).value, "c", TestRoot, Some("u")) + //assertLibrary((c / target).value, "e", TestRoot) + //assertLibrary((c / target).value, "e", TestRoot, Some("t")) + assertLibrary((c / target).value, "jquery", External("test")) +} +//> d/web-assets-test:assets +// +//$ exists modules/d/target/web/public/test/js/d.js +//$ exists modules/d/target/web/public/test/js/u.js +//$ exists modules/d/target/web/public/test/lib/e/js/e.js +//$ exists modules/d/target/web/public/test/lib/e/js/t.js +//$ exists modules/d/target/web/public/test/lib/jquery/jquery.js +TaskKey[Unit]("fileCheckDTest") := { + assertLibrary((d / target).value, "d", TestRoot) + assertLibrary((d / target).value, "d", TestRoot, Some("u")) + assertLibrary((d / target).value, "e", TestLibrary) + assertLibrary((d / target).value, "e", TestLibrary, Some("t")) + assertLibrary((d / target).value, "jquery", External("test")) +} +//> e/web-assets-test:assets +// +//$ exists modules/e/target/web/public/test/js/e.js +//$ exists modules/e/target/web/public/test/js/t.js +//$ exists modules/e/target/web/public/test/lib/jquery/jquery.js +TaskKey[Unit]("fileCheckETest") := { + assertLibrary((e / target).value, "e", TestRoot) + assertLibrary((e / target).value, "e", TestRoot, Some("t")) + assertLibrary((e / target).value, "jquery", External("test")) +} +//# Let's optimize the syncing +// +//> set ThisBuild / trackInternalDependencies := TrackLevel.TrackIfMissing +// +//> a/assets +// +//$ exists target/web/public/main/lib/e/js/e.js +TaskKey[Unit]("fileCheckATracked") := { + assertLibrary(target.value, "e") +} +//> e/clean +//> a/assets +// +//$ exists target/web/public/main/lib/e/js/e.js +TaskKey[Unit]("fileCheckETracked") := { + assertLibrary(target.value, "e") +} diff --git a/src/sbt-test/sbt-web/multi-module/project/FileAssertions.scala b/src/sbt-test/sbt-web/multi-module/project/FileAssertions.scala new file mode 100644 index 0000000..389830e --- /dev/null +++ b/src/sbt-test/sbt-web/multi-module/project/FileAssertions.scala @@ -0,0 +1,33 @@ +import sbt.* + +object FileAssertions { + def assertLibrary( + target: File, + id: String, + location: LibraryLocation = Library, + altName: Option[String] = None + ): Unit = { + val filename = altName.getOrElse(id) + val fileToVerify = location match { + case Root => + target / "web" / "public" / "main" / "js" / s"$filename.js" + case Library => + target / "web" / "public" / "main" / "lib" / id / "js" / s"$filename.js" + case TestRoot => + target / "web" / "public" / "test" / "js" / s"$filename.js" + case TestLibrary => + target / "web" / "public" / "test" / "lib" / id / "js" / s"$filename.js" + case External(path) => + target / "web" / "public" / path / "lib" / id / s"$filename.js" + } + //println(fileToVerify.toString) + assert(fileToVerify.exists(), s"Could not find $filename.js") + } +} + +sealed trait LibraryLocation +case object Root extends LibraryLocation +case object Library extends LibraryLocation +case object TestRoot extends LibraryLocation +case object TestLibrary extends LibraryLocation +case class External(path: String = "main") extends LibraryLocation diff --git a/src/sbt-test/sbt-web/multi-module/test b/src/sbt-test/sbt-web/multi-module/test index f70d68b..44f5ded 100644 --- a/src/sbt-test/sbt-web/multi-module/test +++ b/src/sbt-test/sbt-web/multi-module/test @@ -1,73 +1,33 @@ > a/assets - -$ exists target/web/public/main/js/a.js -$ exists target/web/public/main/lib/b/js/b.js -$ exists target/web/public/main/lib/c/js/c.js -$ exists target/web/public/main/lib/d/js/d.js -$ exists target/web/public/main/lib/e/js/e.js -$ exists target/web/public/main/lib/jquery/jquery.js +> fileCheckA > b/assets - -$ exists modules/b/target/web/public/main/js/b.js -$ exists modules/b/target/web/public/main/lib/c/js/c.js -$ exists modules/b/target/web/public/main/lib/d/js/d.js -$ exists modules/b/target/web/public/main/lib/e/js/e.js -$ exists modules/b/target/web/public/main/lib/jquery/jquery.js +> fileCheckB > c/assets - # c has set import directly -$ exists modules/c/target/web/public/main/js/c.js -$ exists modules/c/target/web/public/main/js/e.js -$ exists modules/c/target/web/public/main/lib/jquery/jquery.js +> fileCheckC > d/assets - -$ exists modules/d/target/web/public/main/js/d.js -$ exists modules/d/target/web/public/main/lib/e/js/e.js -$ exists modules/d/target/web/public/main/lib/jquery/jquery.js +> fileCheckD > e/assets +> fileCheckC -$ exists modules/e/target/web/public/main/js/e.js -$ exists modules/e/target/web/public/main/lib/jquery/jquery.js - -> b/web-assets-test:assets - +> b/TestAssets/assets # b has disabled direct modules so we expect lib/b here -$ exists modules/b/target/web/public/test/lib/b/js/b.js - -$ exists modules/b/target/web/public/test/lib/c/js/c.js -$ exists modules/b/target/web/public/test/lib/c/js/u.js -$ exists modules/b/target/web/public/test/lib/d/js/d.js -$ exists modules/b/target/web/public/test/lib/d/js/u.js -$ exists modules/b/target/web/public/test/lib/e/js/e.js -$ exists modules/b/target/web/public/test/lib/e/js/t.js -$ exists modules/b/target/web/public/test/lib/jquery/jquery.js +> fileCheckBTest -> c/web-assets-test:assets +> c/TestAssets/assets # c has set import directly -$ exists modules/c/target/web/public/test/js/c.js -$ exists modules/c/target/web/public/test/js/u.js -$ exists modules/c/target/web/public/test/js/e.js -$ exists modules/c/target/web/public/test/js/t.js -$ exists modules/c/target/web/public/test/lib/jquery/jquery.js - -> d/web-assets-test:assets - -$ exists modules/d/target/web/public/test/js/d.js -$ exists modules/d/target/web/public/test/js/u.js -$ exists modules/d/target/web/public/test/lib/e/js/e.js -$ exists modules/d/target/web/public/test/lib/e/js/t.js -$ exists modules/d/target/web/public/test/lib/jquery/jquery.js +> fileCheckCTest -> e/web-assets-test:assets +> d/TestAssets/assets +> fileCheckDTest -$ exists modules/e/target/web/public/test/js/e.js -$ exists modules/e/target/web/public/test/js/t.js -$ exists modules/e/target/web/public/test/lib/jquery/jquery.js +> e/TestAssets/assets +> fileCheckETest # Let's optimize the syncing @@ -75,9 +35,9 @@ $ exists modules/e/target/web/public/test/lib/jquery/jquery.js > a/assets -$ exists target/web/public/main/lib/e/js/e.js +> fileCheckATracked > e/clean > a/assets -$ exists target/web/public/main/lib/e/js/e.js +> fileCheckETracked From 3ca1f8e3e437f7cdd2984f87f5e99af305487cf7 Mon Sep 17 00:00:00 2001 From: Billy Autrey <40704452+BillyAutrey@users.noreply.github.com> Date: Wed, 23 Oct 2024 15:39:58 -0500 Subject: [PATCH 4/5] Simplify FileAssertions, fix a few test oversights. --- src/sbt-test/sbt-web/multi-module/build.sbt | 76 ++++++++----------- .../multi-module/project/FileAssertions.scala | 23 ++---- src/sbt-test/sbt-web/multi-module/test | 2 +- 3 files changed, 39 insertions(+), 62 deletions(-) diff --git a/src/sbt-test/sbt-web/multi-module/build.sbt b/src/sbt-test/sbt-web/multi-module/build.sbt index 12415cd..8b599db 100644 --- a/src/sbt-test/sbt-web/multi-module/build.sbt +++ b/src/sbt-test/sbt-web/multi-module/build.sbt @@ -39,7 +39,7 @@ lazy val x = (project in file("modules/x")) //$ exists target/web/public/main/lib/e/js/e.js //$ exists target/web/public/main/lib/jquery/jquery.js TaskKey[Unit]("fileCheckA") := { - assertLibrary(target.value, "a", Root) + assertLibrary(target.value, "a", Root()) assertLibrary(target.value, "b") assertLibrary(target.value, "c") assertLibrary(target.value, "d") @@ -53,20 +53,19 @@ TaskKey[Unit]("fileCheckA") := { //$ exists modules/b/target/web/public/main/lib/e/js/e.js //$ exists modules/b/target/web/public/main/lib/jquery/jquery.js TaskKey[Unit]("fileCheckB") := { - assertLibrary((b / target).value , "b", Root) + assertLibrary((b / target).value , "b", Root()) assertLibrary((b / target).value, "c") assertLibrary((b / target).value, "d") assertLibrary((b / target).value, "e") assertLibrary((b / target).value, "jquery", External()) } -//# c has set import directly //$ exists modules/c/target/web/public/main/js/c.js //$ exists modules/c/target/web/public/main/js/e.js //$ exists modules/c/target/web/public/main/lib/jquery/jquery.js TaskKey[Unit]("fileCheckC") := { - assertLibrary((c / target).value, "c", Root) - assertLibrary((c / target).value, "e", Root) + assertLibrary((c / target).value, "c", Root()) + assertLibrary((c / target).value, "e", Root()) assertLibrary((c / target).value, "jquery", External()) } @@ -74,23 +73,18 @@ TaskKey[Unit]("fileCheckC") := { //$ exists modules/d/target/web/public/main/lib/e/js/e.js //$ exists modules/d/target/web/public/main/lib/jquery/jquery.js TaskKey[Unit]("fileCheckD") := { - assertLibrary((d / target).value, "d", Root) + assertLibrary((d / target).value, "d", Root()) assertLibrary((d / target).value, "e") assertLibrary((d / target).value, "jquery", External()) } -//> e/assets -// + //$ exists modules/e/target/web/public/main/js/e.js //$ exists modules/e/target/web/public/main/lib/jquery/jquery.js TaskKey[Unit]("fileCheckE") := { - assertLibrary((e / target).value, "e", Root) + assertLibrary((e / target).value, "e", Root()) assertLibrary((e / target).value, "jquery", External()) } -//> b/web-assets-test:assets -// -//# b has disabled direct modules so we expect lib/b here -//$ exists modules/b/target/web/public/test/lib/b/js/b.js -// + //$ exists modules/b/target/web/public/test/lib/c/js/c.js //$ exists modules/b/target/web/public/test/lib/c/js/u.js //$ exists modules/b/target/web/public/test/lib/d/js/d.js @@ -99,17 +93,16 @@ TaskKey[Unit]("fileCheckE") := { //$ exists modules/b/target/web/public/test/lib/e/js/t.js //$ exists modules/b/target/web/public/test/lib/jquery/jquery.js TaskKey[Unit]("fileCheckBTest") := { - assertLibrary((b / target).value, "b", TestLibrary) - assertLibrary((b / target).value, "c", TestLibrary) - assertLibrary((b / target).value, "c", TestLibrary, Some("u")) - assertLibrary((b / target).value, "d", TestLibrary) - assertLibrary((b / target).value, "d", TestLibrary, Some("u")) - assertLibrary((b / target).value, "e", TestLibrary) - assertLibrary((b / target).value, "e", TestLibrary, Some("t")) + assertLibrary((b / target).value, "b", Library("test")) + assertLibrary((b / target).value, "c", Library("test")) + assertLibrary((b / target).value, "c", Library("test"), Some("u")) + assertLibrary((b / target).value, "d", Library("test")) + assertLibrary((b / target).value, "d", Library("test"), Some("u")) + assertLibrary((b / target).value, "e", Library("test")) + assertLibrary((b / target).value, "e", Library("test"), Some("t")) assertLibrary((b / target).value, "jquery", External("test")) } -//> c/web-assets-test:assets -// + //# c has set import directly //$ exists modules/c/target/web/public/test/js/c.js //$ exists modules/c/target/web/public/test/js/u.js @@ -117,49 +110,40 @@ TaskKey[Unit]("fileCheckBTest") := { //$ exists modules/c/target/web/public/test/js/t.js //$ exists modules/c/target/web/public/test/lib/jquery/jquery.js TaskKey[Unit]("fileCheckCTest") := { - assertLibrary((c / target).value, "c", TestRoot) - assertLibrary((c / target).value, "c", TestRoot, Some("u")) - //assertLibrary((c / target).value, "e", TestRoot) - //assertLibrary((c / target).value, "e", TestRoot, Some("t")) + assertLibrary((c / target).value, "c", Root("test")) + assertLibrary((c / target).value, "c", Root("test"), Some("u")) + assertLibrary((c / target).value, "e", Root("test")) + assertLibrary((c / target).value, "e", Root("test"), Some("t")) assertLibrary((c / target).value, "jquery", External("test")) } -//> d/web-assets-test:assets -// + //$ exists modules/d/target/web/public/test/js/d.js //$ exists modules/d/target/web/public/test/js/u.js //$ exists modules/d/target/web/public/test/lib/e/js/e.js //$ exists modules/d/target/web/public/test/lib/e/js/t.js //$ exists modules/d/target/web/public/test/lib/jquery/jquery.js TaskKey[Unit]("fileCheckDTest") := { - assertLibrary((d / target).value, "d", TestRoot) - assertLibrary((d / target).value, "d", TestRoot, Some("u")) - assertLibrary((d / target).value, "e", TestLibrary) - assertLibrary((d / target).value, "e", TestLibrary, Some("t")) + assertLibrary((d / target).value, "d", Root("test")) + assertLibrary((d / target).value, "d", Root("test"), Some("u")) + assertLibrary((d / target).value, "e", Library("test")) + assertLibrary((d / target).value, "e", Library("test"), Some("t")) assertLibrary((d / target).value, "jquery", External("test")) } -//> e/web-assets-test:assets -// + //$ exists modules/e/target/web/public/test/js/e.js //$ exists modules/e/target/web/public/test/js/t.js //$ exists modules/e/target/web/public/test/lib/jquery/jquery.js TaskKey[Unit]("fileCheckETest") := { - assertLibrary((e / target).value, "e", TestRoot) - assertLibrary((e / target).value, "e", TestRoot, Some("t")) + assertLibrary((e / target).value, "e", Root("test")) + assertLibrary((e / target).value, "e", Root("test"), Some("t")) assertLibrary((e / target).value, "jquery", External("test")) } -//# Let's optimize the syncing -// -//> set ThisBuild / trackInternalDependencies := TrackLevel.TrackIfMissing -// -//> a/assets -// + //$ exists target/web/public/main/lib/e/js/e.js TaskKey[Unit]("fileCheckATracked") := { assertLibrary(target.value, "e") } -//> e/clean -//> a/assets -// + //$ exists target/web/public/main/lib/e/js/e.js TaskKey[Unit]("fileCheckETracked") := { assertLibrary(target.value, "e") diff --git a/src/sbt-test/sbt-web/multi-module/project/FileAssertions.scala b/src/sbt-test/sbt-web/multi-module/project/FileAssertions.scala index 389830e..ef869b9 100644 --- a/src/sbt-test/sbt-web/multi-module/project/FileAssertions.scala +++ b/src/sbt-test/sbt-web/multi-module/project/FileAssertions.scala @@ -4,30 +4,23 @@ object FileAssertions { def assertLibrary( target: File, id: String, - location: LibraryLocation = Library, + location: LibraryLocation = Library(), altName: Option[String] = None ): Unit = { val filename = altName.getOrElse(id) val fileToVerify = location match { - case Root => - target / "web" / "public" / "main" / "js" / s"$filename.js" - case Library => - target / "web" / "public" / "main" / "lib" / id / "js" / s"$filename.js" - case TestRoot => - target / "web" / "public" / "test" / "js" / s"$filename.js" - case TestLibrary => - target / "web" / "public" / "test" / "lib" / id / "js" / s"$filename.js" + case Root(stage) => + target / "web" / "public" / stage / "js" / s"$filename.js" + case Library(stage) => + target / "web" / "public" / stage / "lib" / id / "js" / s"$filename.js" case External(path) => target / "web" / "public" / path / "lib" / id / s"$filename.js" } - //println(fileToVerify.toString) assert(fileToVerify.exists(), s"Could not find $filename.js") } } sealed trait LibraryLocation -case object Root extends LibraryLocation -case object Library extends LibraryLocation -case object TestRoot extends LibraryLocation -case object TestLibrary extends LibraryLocation -case class External(path: String = "main") extends LibraryLocation +case class Root(stage: String = "main") extends LibraryLocation +case class Library(stage: String = "main") extends LibraryLocation +case class External(stage: String = "main") extends LibraryLocation diff --git a/src/sbt-test/sbt-web/multi-module/test b/src/sbt-test/sbt-web/multi-module/test index 44f5ded..88440c0 100644 --- a/src/sbt-test/sbt-web/multi-module/test +++ b/src/sbt-test/sbt-web/multi-module/test @@ -12,7 +12,7 @@ > fileCheckD > e/assets -> fileCheckC +> fileCheckE > b/TestAssets/assets # b has disabled direct modules so we expect lib/b here From 99b81eb4d07635e68fb41c04237a712603004faa Mon Sep 17 00:00:00 2001 From: Billy Autrey <40704452+BillyAutrey@users.noreply.github.com> Date: Wed, 23 Oct 2024 15:41:48 -0500 Subject: [PATCH 5/5] Scalafmt --- src/sbt-test/sbt-web/multi-module/build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sbt-test/sbt-web/multi-module/build.sbt b/src/sbt-test/sbt-web/multi-module/build.sbt index 8b599db..8f5b59f 100644 --- a/src/sbt-test/sbt-web/multi-module/build.sbt +++ b/src/sbt-test/sbt-web/multi-module/build.sbt @@ -53,7 +53,7 @@ TaskKey[Unit]("fileCheckA") := { //$ exists modules/b/target/web/public/main/lib/e/js/e.js //$ exists modules/b/target/web/public/main/lib/jquery/jquery.js TaskKey[Unit]("fileCheckB") := { - assertLibrary((b / target).value , "b", Root()) + assertLibrary((b / target).value, "b", Root()) assertLibrary((b / target).value, "c") assertLibrary((b / target).value, "d") assertLibrary((b / target).value, "e")