Skip to content

Commit 554a3e2

Browse files
committed
update scala cli directives for dependencies
1 parent 72c442c commit 554a3e2

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ Thanks goes to these wonderful people for contributing to Scala Steward:
111111
* [Ikenna Darlington Ogbajie](https://github.com/idarlington)
112112
* [Ingar Abrahamsen](https://github.com/ingarabr)
113113
* [Jakub Kozłowski](https://github.com/kubukoz)
114+
* [Jamie Thompson](https://github.com/bishabosha)
114115
* [Javier Arrieta](https://github.com/javierarrieta)
115116
* [JCollier](https://github.com/Slakah)
116117
* [Jeff Martin](https://github.com/custommonkey)
@@ -125,7 +126,7 @@ Thanks goes to these wonderful people for contributing to Scala Steward:
125126
* [Leonhard Riedißer](https://github.com/L7R7)
126127
* [Maksym Ochenashko](https://github.com/iRevive)
127128
* [Manuel Cueto](https://github.com/manuelcueto)
128-
* [Marco Zühlke](https://github.com/mzuehlke)
129+
* [Marco Zühlke](https://github.com/mzuehlke)
129130
* [Mark Canlas](https://github.com/mcanlas)
130131
* [Mark van der Tol](https://github.com/markvandertol)
131132
* [MaT1g3R](https://github.com/MaT1g3R)

modules/core/src/main/scala/org/scalasteward/core/buildtool/scalacli/ScalaCliAlg.scala

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,27 @@ import org.scalasteward.core.io.{FileAlg, ProcessAlg, WorkspaceAlg}
2828
import org.scalasteward.core.util.Nel
2929
import org.typelevel.log4cats.Logger
3030

31+
object ScalaCliAlg {
32+
val directives =
33+
// sourced from https://github.com/VirtusLab/scala-cli/blob/9e22d4a91ba8699ac2727d2ac3042d64abe951e1/modules/directives/src/main/scala/scala/build/preprocessing/directives/Dependency.scala#L33-L48
34+
List(
35+
"lib",
36+
"libs",
37+
"dep",
38+
"deps",
39+
"dependencies",
40+
"test.dependency",
41+
"test.dep",
42+
"test.deps",
43+
"test.dependencies",
44+
"compileOnly.lib",
45+
"compileOnly.libs",
46+
"compileOnly.dep",
47+
"compileOnly.deps",
48+
"compileOnly.dependencies"
49+
).map(alias => s"//> $alias ")
50+
}
51+
3152
final class ScalaCliAlg[F[_]](implicit
3253
fileAlg: FileAlg[F],
3354
gitAlg: GitAlg[F],
@@ -42,8 +63,8 @@ final class ScalaCliAlg[F[_]](implicit
4263
override def containsBuild(buildRoot: BuildRoot): F[Boolean] = {
4364
val buildRootPath = buildRoot.relativePath.dropWhile(Set('.', '/'))
4465
val extensions = Set(".sc", ".scala")
45-
gitAlg
46-
.findFilesContaining(buildRoot.repo, "//> using lib ")
66+
ScalaCliAlg.directives
67+
.flatTraverse(gitAlg.findFilesContaining(buildRoot.repo, _))
4768
.map(_.exists(path => path.startsWith(buildRootPath) && extensions.exists(path.endsWith)))
4869
}
4970

modules/core/src/test/scala/org/scalasteward/core/buildtool/scalacli/ScalaCliAlgTest.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import org.scalasteward.core.mock.MockState
1010
import org.scalasteward.core.mock.MockState.TraceEntry.{Cmd, Log}
1111
import org.scalasteward.core.util.Nel
1212

13+
import cats.syntax.parallel._
14+
1315
class ScalaCliAlgTest extends CatsEffectSuite {
1416
test("containsBuild: directive in non-source file") {
1517
val repo = Repo("user", "repo")
@@ -24,6 +26,25 @@ class ScalaCliAlgTest extends CatsEffectSuite {
2426
assertIO(obtained, false)
2527
}
2628

29+
test("containsBuild: directive with test.dep, dep, and lib") {
30+
val repo = Repo("user", "repo")
31+
val buildRoot = BuildRoot(repo, ".")
32+
val repoDir = workspaceAlg.repoDir(repo).unsafeRunSync()
33+
val fileWithUsingDirective = "project.scala"
34+
35+
ScalaCliAlg.directives
36+
.map { search =>
37+
val grepCmd =
38+
Cmd.git(repoDir, "grep", "-I", "--fixed-strings", "--files-with-matches", search)
39+
val initial =
40+
MockState.empty.copy(commandOutputs = Map(grepCmd -> Right(List(fileWithUsingDirective))))
41+
val obtained = scalaCliAlg.containsBuild(buildRoot).runA(initial)
42+
assertIO(obtained, true)
43+
}
44+
.parSequence
45+
.void
46+
}
47+
2748
test("getDependencies") {
2849
val repo = Repo("user", "repo")
2950
val buildRoot = BuildRoot(repo, ".")

0 commit comments

Comments
 (0)