Skip to content

Commit c12aaef

Browse files
BillyAutreymkurz
authored andcommittedOct 24, 2024
Add compatibility shim to strip directories from mappings
1 parent 9455eaa commit c12aaef

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed
 

‎src/main/scala-2.12/com/typesafe/sbt/PluginCompat.scala

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.typesafe.sbt
22

33
import sbt.*
44
import sbt.Keys.Classpath
5+
import com.typesafe.sbt.web.PathMapping
56
import xsbti.FileConverter
67

78
import java.nio.file.{ Path => NioPath }
@@ -28,4 +29,5 @@ private[sbt] object PluginCompat {
2829
def toFileRef(f: File)(implicit conv: FileConverter): FileRef = f
2930
def selectFirstPredicate: Seq[FileRef] => Boolean = files =>
3031
files.forall(_.isFile) && files.map(_.hashString).distinct.size == 1
32+
def fileRefCompatible(path: PathMapping)(implicit conv: FileConverter): Boolean = true
3133
}

‎src/main/scala-3/com/typesafe/sbt/PluginCompat.scala

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import java.io.{ File => IoFile }
55
import sbt.*
66
import sbt.Keys.Classpath
77
import xsbti.{ FileConverter, HashedVirtualFileRef, VirtualFileRef }
8+
import com.typesafe.sbt.web.PathMapping
89

910
private[sbt] object PluginCompat:
1011
type FileRef = HashedVirtualFileRef
@@ -30,4 +31,6 @@ private[sbt] object PluginCompat:
3031
conv.toVirtualFile(file.toPath)
3132
inline def selectFirstPredicate(using conv: FileConverter): Seq[FileRef] => Boolean = files =>
3233
files.forall(toFile(_).isFile) && files.map(_.contentHashStr).distinct.size == 1
34+
inline def fileRefCompatible(path: PathMapping)(using conv: FileConverter): Boolean =
35+
!toFile(path._1).isDirectory
3336
end PluginCompat

‎src/main/scala/com/typesafe/sbt/web/SbtWeb.scala

+7-4
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,11 @@ object SbtWeb extends AutoPlugin {
402402
* Create package mappings for assets in the webjar format. Use the webjars path prefix and exclude all web module
403403
* assets.
404404
*/
405-
def createWebJarMappings: Def.Initialize[Task[Seq[(FileRef, String)]]] = Def.task {
405+
def createWebJarMappings: Def.Initialize[Task[Seq[PathMapping]]] = Def.task {
406406
def webModule(file: File) = webModuleDirectories.value.exists(dir => IO.relativize(dir, file).isDefined)
407407
implicit val fc: FileConverter = fileConverter.value
408408
mappings.value flatMap {
409+
case mapping if !fileRefCompatible(mapping) => None
409410
case (file, path) if webModule(toFile(file)) => None
410411
case (file, path) => Some(file -> (webJarsPathPrefix.value + path))
411412
}
@@ -450,10 +451,12 @@ object SbtWeb extends AutoPlugin {
450451
/**
451452
* Create package mappings for all assets, adding the optional prefix.
452453
*/
453-
def packageAssetsMappings: Def.Initialize[Task[Seq[(FileRef, String)]]] = Def.task {
454+
def packageAssetsMappings: Def.Initialize[Task[Seq[PathMapping]]] = Def.task {
455+
implicit val fc: FileConverter = fileConverter.value
454456
val prefix = packagePrefix.value
455-
(Defaults.ConfigGlobal / pipeline).value map { case (file, path) =>
456-
file -> (prefix + path)
457+
(Defaults.ConfigGlobal / pipeline).value collect {
458+
case (file, path) if fileRefCompatible((file, path)) =>
459+
file -> (prefix + path)
457460
}
458461
}
459462

0 commit comments

Comments
 (0)