From f22b90978a0bd30db03f18bc247720e4458048d7 Mon Sep 17 00:00:00 2001 From: Matthias Kurz Date: Thu, 11 Jan 2024 11:44:26 +0100 Subject: [PATCH] Upgrade to latest sbt-js-engine, use GHA/sbt-ci-release --- .github/workflows/build-test.yml | 30 +++++++++++++ .github/workflows/publish.yml | 44 +++++++++++++++++++ .gitignore | 1 + .travis.yml | 3 -- README.md | 14 +++--- build.sbt | 29 ++++++++++-- project/build.properties | 2 +- project/plugins.sbt | 4 +- .../typesafe/sbt/proguard/Sbt10Compat.scala | 10 ----- .../typesafe/sbt/proguard/Sbt10Compat.scala | 8 ---- .../com/typesafe/sbt/uglify/SbtUglify.scala | 44 +++++++++---------- .../uglify-concat/project/plugins.sbt | 4 +- .../sbt-uglify/uglify/project/plugins.sbt | 4 +- version.sbt | 1 - 14 files changed, 135 insertions(+), 63 deletions(-) create mode 100644 .github/workflows/build-test.yml create mode 100644 .github/workflows/publish.yml delete mode 100644 .travis.yml delete mode 100644 src/main/scala-sbt-0.13/com/typesafe/sbt/proguard/Sbt10Compat.scala delete mode 100644 src/main/scala-sbt-1.0/com/typesafe/sbt/proguard/Sbt10Compat.scala delete mode 100644 version.sbt diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml new file mode 100644 index 0000000..6ab438e --- /dev/null +++ b/.github/workflows/build-test.yml @@ -0,0 +1,30 @@ +name: Check + +on: + pull_request: + + push: + branches: + - main # Check branch after merge + +concurrency: + # Only run once for latest commit per ref and cancel other (previous) runs. + group: ci-${{ github.ref }} + cancel-in-progress: true + +jobs: + tests: + name: Tests + uses: playframework/.github/.github/workflows/cmd.yml@v3 + with: + java: 17, 11, 8 + scala: 2.12.18 + cmd: | + sbt ++$MATRIX_SCALA test ^scripted + + finish: + name: Finish + if: github.event_name == 'pull_request' + needs: # Should be last + - "tests" + uses: playframework/.github/.github/workflows/rtm.yml@v3 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..6a6c3ae --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,44 @@ +name: Publish + +on: + push: + branches: # Snapshots + - main + tags: ["**"] # Releases + +jobs: + publish-artifacts: + name: JDK 8 + runs-on: ubuntu-20.04 + if: ${{ github.repository_owner == 'sbt' }} + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + # we don't know what commit the last tag was it's safer to get entire repo so previousStableVersion resolves + fetch-depth: 0 + + - name: Coursier Cache + id: coursier-cache + uses: coursier/cache-action@v6 + + - name: Install Adoptium Temurin OpenJDK + uses: coursier/setup-action@v1 + with: + jvm: adoptium:8 + + - name: Publish artifacts + run: sbt ci-release + env: + SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} + SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }} + PGP_SECRET: ${{ secrets.PGP_SECRET }} + + - name: Cleanup before cache + shell: bash + run: | + find $HOME/Library/Caches/Coursier/v1 -name "ivydata-*.properties" -delete || true + find $HOME/.ivy2/cache -name "ivydata-*.properties" -delete || true + find $HOME/.cache/coursier/v1 -name "ivydata-*.properties" -delete || true + find $HOME/.sbt -name "*.lock" -delete || true diff --git a/.gitignore b/.gitignore index 86f0e5f..56d525f 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ project/plugins/project/ .idea/ .idea_modules/ +.bsp/ diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b61b7c9..0000000 --- a/.travis.yml +++ /dev/null @@ -1,3 +0,0 @@ -jdk: oraclejdk8 -language: scala -script: sbt "^ scripted" diff --git a/README.md b/README.md index 01a91db..371390d 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,19 @@ sbt-uglify ========== -[![Build Status](https://api.travis-ci.org/sbt/sbt-uglify.png?branch=master)](https://travis-ci.org/sbt/sbt-uglify) [![Download](https://api.bintray.com/packages/sbt-web/sbt-plugin-releases/sbt-uglify/images/download.svg)](https://bintray.com/sbt-web/sbt-plugin-releases/sbt-uglify/_latestVersion) +[![Build Status](https://github.com/sbt/sbt-uglify/actions/workflows/build-test.yml/badge.svg)](https://github.com/sbt/sbt-uglify/actions/workflows/build-test.yml) An sbt-web plugin to perform [UglifyJS optimization](https://github.com/mishoo/UglifyJS2) on the asset pipeline. Usage ----- -To use this plugin, use the addSbtPlugin command within your project's `plugins.sbt` file: +To use this plugin, use the `addSbtPlugin` command within your project's `project/plugins.sbt` file: ```scala -addSbtPlugin("com.typesafe.sbt" % "sbt-uglify" % "2.0.0") +addSbtPlugin("com.github.sbt" % "sbt-uglify" % "3.0.0") ``` -Your project's build file also needs to enable sbt-web plugins. For example, with build.sbt: +Your project's build file also needs to enable sbt-web plugins. For example, with `build.sbt`: ```scala lazy val root = (project in file(".")).enablePlugins(SbtWeb) @@ -32,7 +32,7 @@ compression. Each input `.js` file found in your assets folders will have a corr If you wish to limit or extend what is uglified then you can use filters: ```scala -includeFilter in uglify := GlobFilter("myjs/*.js"), +uglify / includeFilter := GlobFilter("myjs/*.js"), ``` ...where the above will include only those files under the `myjs` folder. @@ -76,6 +76,4 @@ uglifyPreamble | Any preamble to include at the start of the output. uglifyReserved | Reserved names to exclude from mangling. | `Nil` uglifyOps | A function defining how to combine input files into output files. | `UglifyOps.singleFileWithSourceMapOut` -The plugin is built on top of [JavaScript Engine](https://github.com/typesafehub/js-engine) which supports different JavaScript runtimes. - -© Typesafe Inc., 2014 +The plugin is built on top of [JavaScript Engine](https://github.com/sbt/sbt-js-engine) which supports different JavaScript runtimes. diff --git a/build.sbt b/build.sbt index 59cfa8b..03d5538 100644 --- a/build.sbt +++ b/build.sbt @@ -1,10 +1,33 @@ -organization := "com.typesafe.sbt" -name := "sbt-uglify" +lazy val `sbt-uglify` = project in file(".") + +enablePlugins(SbtWebBase) + +sonatypeProfileName := "com.github.sbt.sbt-uglify" // See https://issues.sonatype.org/browse/OSSRH-77819#comment-1203625 + description := "sbt-web plugin for minifying JavaScript files" -addSbtJsEngine("1.2.2") + +developers += Developer( + "playframework", + "The Play Framework Team", + "contact@playframework.com", + url("https://github.com/playframework") +) + +addSbtJsEngine("1.3.5") + libraryDependencies ++= Seq( "org.webjars.npm" % "uglify-js" % "3.16.3", "io.monix" %% "monix" % "2.3.3" ) +// Customise sbt-dynver's behaviour to make it work with tags which aren't v-prefixed +ThisBuild / dynverVTagPrefix := false + +// Sanity-check: assert that version comes from a tag (e.g. not a too-shallow clone) +// https://github.com/dwijnand/sbt-dynver/#sanity-checking-the-version +Global / onLoad := (Global / onLoad).value.andThen { s => + dynverAssertTagVersion.value + s +} + //scriptedBufferLog := false diff --git a/project/build.properties b/project/build.properties index 7b6213b..e8a1e24 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.0.1 +sbt.version=1.9.7 diff --git a/project/plugins.sbt b/project/plugins.sbt index 7a1196f..6e4254c 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1 +1,3 @@ -addSbtPlugin("com.typesafe.sbt" % "sbt-web-build-base" % "1.2.0") +addSbtPlugin("com.github.sbt" % "sbt-web-build-base" % "2.0.2") + +addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.12") diff --git a/src/main/scala-sbt-0.13/com/typesafe/sbt/proguard/Sbt10Compat.scala b/src/main/scala-sbt-0.13/com/typesafe/sbt/proguard/Sbt10Compat.scala deleted file mode 100644 index 6ad073e..0000000 --- a/src/main/scala-sbt-0.13/com/typesafe/sbt/proguard/Sbt10Compat.scala +++ /dev/null @@ -1,10 +0,0 @@ -package com.typesafe.sbt.proguard - -import sbt.Def -import sbt.Keys.streams - -object Sbt10Compat { - object DummyPath - - val SbtIoPath = DummyPath -} diff --git a/src/main/scala-sbt-1.0/com/typesafe/sbt/proguard/Sbt10Compat.scala b/src/main/scala-sbt-1.0/com/typesafe/sbt/proguard/Sbt10Compat.scala deleted file mode 100644 index e7a53d4..0000000 --- a/src/main/scala-sbt-1.0/com/typesafe/sbt/proguard/Sbt10Compat.scala +++ /dev/null @@ -1,8 +0,0 @@ -package com.typesafe.sbt.proguard - -import sbt.Def -import sbt.Keys.streams - -object Sbt10Compat { - val SbtIoPath = sbt.io.Path -} diff --git a/src/main/scala/com/typesafe/sbt/uglify/SbtUglify.scala b/src/main/scala/com/typesafe/sbt/uglify/SbtUglify.scala index 1f4035e..b1ae705 100644 --- a/src/main/scala/com/typesafe/sbt/uglify/SbtUglify.scala +++ b/src/main/scala/com/typesafe/sbt/uglify/SbtUglify.scala @@ -1,16 +1,16 @@ package com.typesafe.sbt.uglify import com.typesafe.sbt.jse.{SbtJsEngine, SbtJsTask} -import com.typesafe.sbt.proguard.Sbt10Compat import com.typesafe.sbt.web.incremental._ import com.typesafe.sbt.web.pipeline.Pipeline -import com.typesafe.sbt.web.{Compat, PathMapping, SbtWeb, incremental} +import com.typesafe.sbt.web.{PathMapping, SbtWeb, incremental} import monix.reactive.Observable import sbt.Keys._ import sbt.{Task, _} -import Sbt10Compat.SbtIoPath._ +import sbt.io.Path._ import scala.concurrent.Await +import scala.concurrent.duration.Duration object Import { @@ -93,37 +93,37 @@ object SbtUglify extends AutoPlugin { } override def projectSettings = Seq( - uglifyBuildDir := (resourceManaged in uglify).value / "build", + uglifyBuildDir := (uglify / resourceManaged).value / "build", uglifyComments := None, uglifyCompress := true, uglifyCompressOptions := Nil, uglifyDefine := None, uglifyEnclose := false, - excludeFilter in uglify := + uglify / excludeFilter := HiddenFileFilter || GlobFilter("*.min.js") || new SimpleFileFilter({ file => - file.startsWith((WebKeys.webModuleDirectory in Assets).value) + file.startsWith((Assets / WebKeys.webModuleDirectory).value) }), - includeFilter in uglify := GlobFilter("*.js"), + uglify / includeFilter := GlobFilter("*.js"), uglifyIncludeSource := false, - resourceManaged in uglify := webTarget.value / uglify.key.label, + uglify / resourceManaged := webTarget.value / uglify.key.label, uglifyMangle := true, uglifyMangleOptions := Nil, uglifyPreamble := None, uglifyReserved := Nil, - uglify := runOptimizer.dependsOn(webJarsNodeModules in Plugin).value, + uglify := runOptimizer.dependsOn(Plugin / webJarsNodeModules).value, uglifyOps := singleFileWithSourceMapOut ) private def runOptimizer: Def.Initialize[Task[Pipeline.Stage]] = Def.task { - val include = (includeFilter in uglify).value - val exclude = (excludeFilter in uglify).value + val include = (uglify / includeFilter).value + val exclude = (uglify / excludeFilter).value val buildDirValue = uglifyBuildDir.value val uglifyOpsValue = uglifyOps.value val streamsValue = streams.value - val nodeModuleDirectoriesInPluginValue = (nodeModuleDirectories in Plugin).value - val webJarsNodeModulesDirectoryInPluginValue = (webJarsNodeModulesDirectory in Plugin).value + val nodeModuleDirectoriesInPluginValue = (Plugin / nodeModuleDirectories).value + val webJarsNodeModulesDirectoryInPluginValue = (Plugin / webJarsNodeModulesDirectory).value val mangleValue = uglifyMangle.value val mangleOptionsValue = uglifyMangleOptions.value val reservedValue = uglifyReserved.value @@ -131,19 +131,18 @@ object SbtUglify extends AutoPlugin { val compressOptionsValue = uglifyCompressOptions.value val encloseValue = uglifyEnclose.value val includeSourceValue = uglifyIncludeSource.value - val timeout = (timeoutPerSource in uglify).value val stateValue = state.value - val engineTypeInUglifyValue = (engineType in uglify).value - val commandInUglifyValue = (command in uglify).value + val engineTypeInUglifyValue = (uglify / engineType).value + val commandInUglifyValue = (uglify / command).value val options = Seq( uglifyComments.value, compressValue, compressOptionsValue, uglifyDefine.value, encloseValue, - (excludeFilter in uglify).value, - (includeFilter in uglify).value, - (resourceManaged in uglify).value, + (uglify / excludeFilter).value, + (uglify / includeFilter).value, + (uglify / resourceManaged).value, mangleValue, mangleOptionsValue, uglifyPreamble.value, @@ -155,7 +154,7 @@ object SbtUglify extends AutoPlugin { val optimizerMappings = mappings.filter(f => !f._1.isDirectory && include.accept(f._1) && !exclude.accept(f._1)) SbtWeb.syncMappings( - Compat.cacheStore(streamsValue, "uglify-cache"), + streamsValue.cacheStoreFactory.make("uglify-cache"), optimizerMappings, buildDirValue ) @@ -221,7 +220,6 @@ object SbtUglify extends AutoPlugin { nodeModulePaths, uglifyjsShell, args: Seq[String], - timeout ) } @@ -278,7 +276,9 @@ object SbtUglify extends AutoPlugin { ) val result = Await.result( resultObservable.toListL.runAsync(uglifyPool), - timeout * modifiedGroupings.size + Duration.Inf // TODO: really? Do we need to run this whole thing async actually since sbt-web 1.5? + // sbt-web 1.5 removed usage of akka internally and is not async anymore, so we might + // can get rid of it here too (meaning removing this monix stuff) ) (result.toMap, ()) diff --git a/src/sbt-test/sbt-uglify/uglify-concat/project/plugins.sbt b/src/sbt-test/sbt-uglify/uglify-concat/project/plugins.sbt index 3fd8f05..085a88d 100644 --- a/src/sbt-test/sbt-uglify/uglify-concat/project/plugins.sbt +++ b/src/sbt-test/sbt-uglify/uglify-concat/project/plugins.sbt @@ -1,8 +1,6 @@ -addSbtPlugin("com.typesafe.sbt" % "sbt-uglify" % sys.props("project.version")) +addSbtPlugin("com.github.sbt" % "sbt-uglify" % sys.props("project.version")) resolvers ++= Seq( Resolver.mavenLocal, - Resolver.url("sbt snapshot plugins", url("http://repo.scala-sbt.org/scalasbt/sbt-plugin-snapshots"))(Resolver.ivyStylePatterns), Resolver.sonatypeRepo("snapshots"), - "Typesafe Snapshots Repository" at "http://repo.typesafe.com/typesafe/snapshots/" ) diff --git a/src/sbt-test/sbt-uglify/uglify/project/plugins.sbt b/src/sbt-test/sbt-uglify/uglify/project/plugins.sbt index 3fd8f05..085a88d 100644 --- a/src/sbt-test/sbt-uglify/uglify/project/plugins.sbt +++ b/src/sbt-test/sbt-uglify/uglify/project/plugins.sbt @@ -1,8 +1,6 @@ -addSbtPlugin("com.typesafe.sbt" % "sbt-uglify" % sys.props("project.version")) +addSbtPlugin("com.github.sbt" % "sbt-uglify" % sys.props("project.version")) resolvers ++= Seq( Resolver.mavenLocal, - Resolver.url("sbt snapshot plugins", url("http://repo.scala-sbt.org/scalasbt/sbt-plugin-snapshots"))(Resolver.ivyStylePatterns), Resolver.sonatypeRepo("snapshots"), - "Typesafe Snapshots Repository" at "http://repo.typesafe.com/typesafe/snapshots/" ) diff --git a/version.sbt b/version.sbt deleted file mode 100644 index c670469..0000000 --- a/version.sbt +++ /dev/null @@ -1 +0,0 @@ -version in ThisBuild := "2.0.1-SNAPSHOT"