Skip to content

Commit

Permalink
Add compatibility shim to strip directories from mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
BillyAutrey authored and mkurz committed Oct 24, 2024
1 parent 9455eaa commit c12aaef
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/main/scala-2.12/com/typesafe/sbt/PluginCompat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.typesafe.sbt

import sbt.*
import sbt.Keys.Classpath
import com.typesafe.sbt.web.PathMapping
import xsbti.FileConverter

import java.nio.file.{ Path => NioPath }
Expand All @@ -28,4 +29,5 @@ private[sbt] object PluginCompat {
def toFileRef(f: File)(implicit conv: FileConverter): FileRef = f
def selectFirstPredicate: Seq[FileRef] => Boolean = files =>
files.forall(_.isFile) && files.map(_.hashString).distinct.size == 1
def fileRefCompatible(path: PathMapping)(implicit conv: FileConverter): Boolean = true
}
3 changes: 3 additions & 0 deletions src/main/scala-3/com/typesafe/sbt/PluginCompat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import java.io.{ File => IoFile }
import sbt.*
import sbt.Keys.Classpath
import xsbti.{ FileConverter, HashedVirtualFileRef, VirtualFileRef }
import com.typesafe.sbt.web.PathMapping

private[sbt] object PluginCompat:
type FileRef = HashedVirtualFileRef
Expand All @@ -30,4 +31,6 @@ private[sbt] object PluginCompat:
conv.toVirtualFile(file.toPath)
inline def selectFirstPredicate(using conv: FileConverter): Seq[FileRef] => Boolean = files =>
files.forall(toFile(_).isFile) && files.map(_.contentHashStr).distinct.size == 1
inline def fileRefCompatible(path: PathMapping)(using conv: FileConverter): Boolean =
!toFile(path._1).isDirectory
end PluginCompat
11 changes: 7 additions & 4 deletions src/main/scala/com/typesafe/sbt/web/SbtWeb.scala
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,11 @@ object SbtWeb extends AutoPlugin {
* Create package mappings for assets in the webjar format. Use the webjars path prefix and exclude all web module
* assets.
*/
def createWebJarMappings: Def.Initialize[Task[Seq[(FileRef, String)]]] = Def.task {
def createWebJarMappings: Def.Initialize[Task[Seq[PathMapping]]] = Def.task {
def webModule(file: File) = webModuleDirectories.value.exists(dir => IO.relativize(dir, file).isDefined)
implicit val fc: FileConverter = fileConverter.value
mappings.value flatMap {
case mapping if !fileRefCompatible(mapping) => None
case (file, path) if webModule(toFile(file)) => None
case (file, path) => Some(file -> (webJarsPathPrefix.value + path))
}
Expand Down Expand Up @@ -450,10 +451,12 @@ object SbtWeb extends AutoPlugin {
/**
* Create package mappings for all assets, adding the optional prefix.
*/
def packageAssetsMappings: Def.Initialize[Task[Seq[(FileRef, String)]]] = Def.task {
def packageAssetsMappings: Def.Initialize[Task[Seq[PathMapping]]] = Def.task {
implicit val fc: FileConverter = fileConverter.value
val prefix = packagePrefix.value
(Defaults.ConfigGlobal / pipeline).value map { case (file, path) =>
file -> (prefix + path)
(Defaults.ConfigGlobal / pipeline).value collect {
case (file, path) if fileRefCompatible((file, path)) =>
file -> (prefix + path)
}
}

Expand Down

0 comments on commit c12aaef

Please sign in to comment.