Skip to content

Commit

Permalink
Scripted test to hande multiple extracted versions of same webjar
Browse files Browse the repository at this point in the history
  • Loading branch information
mkurz committed Jan 28, 2024
1 parent 3667496 commit e174263
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
lazy val root = (project in file(".")).enablePlugins(SbtWeb)

val checkMapFileContents = taskKey[Unit]("check that map contents are correct")

checkMapFileContents := {
val contents = IO.read((Assets / WebKeys.public).value / "css" / "main.min.css.map")
val expectedContents = """{"version":3,"sources":["main.less"],"names":[],"mappings":"AAAA,GACE","file":"main.min.css"}"""

if (contents != expectedContents) {
sys.error(s"Unexpected contents: $contents, \nexpected: $expectedContents")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
addSbtPlugin("com.github.sbt" % "sbt-less" % sys.props("project.version"))

// When the same webjar (= same name) from different groupIds (org.webjars[.npm|bower]?)
// are are on the classpath, those webjars get extracted into subfolders which are named by the version of the webjar.
// However, if there is just one type (npm, bower, classic) of a webjar on the classpath, NO subfolders gets created.
// Now, because in a project we don't know which other webjars get pulled in from other dependencies, it can happen
// that subfolders get created, or may not. However, require(...) can't know that and therefore has to look in both places.
// To test that the lookup is correct, we force this scripted test to create subfolders by pulling in the same webjar
// but from different groupIds (the other scripted test does not do that and therefore no subfolders get created there)
// btw: dependency eviction within the same type of webjar still works correctly, so e.g. 0.2 wins over 0.1 within the same type of webjar
// and no subfolder will be forced for that case but the newest version will be choosen. Like normal dependency resolution.
libraryDependencies ++= Seq(
// Pulling in the classic and the npm webjar to subfolders for this webjar will be created
"org.webjars" % "mkdirp" % "0.3.5",
"org.webjars.npm" % "mkdirp" % "0.5.1",

// Same here, we pull in the bower and the npm one so subfolders will be created
// ("3.8.1/ and 3.8.1 etc.)
"org.webjars" % "less" % "3.8.1",
"org.webjars.npm" % "less" % "3.8.1",


// and so on...
"org.webjars.npm" % "es6-promise" % "4.1.0",
"org.webjars" % "es6-promise" % "2.1.1",

"org.webjars.npm" % "less-plugin-clean-css" % "1.5.1" intransitive(),
// TODO: there was no other webjars type for less-plugin-clean-css currently
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
h1 {
color: blue
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Compile a less file

> assets
$ exists target/web/public/main/css/main.css
$ exists target/web/public/main/css/main.css.map

# Compile with compression

> set Assets / LessKeys.compress := true
> assets
-$ exists target/web/public/main/css/main.css
-$ exists target/web/public/main/css/main.css.map
$ exists target/web/public/main/css/main.min.css
$ exists target/web/public/main/css/main.min.css.map
> checkMapFileContents

# Compile without sourceMaps
> set Assets / LessKeys.sourceMap := false
> assets
$ exists target/web/public/main/css/main.min.css
-$ exists target/web/public/main/css/main.min.css.map

0 comments on commit e174263

Please sign in to comment.