Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to latest sbt-js-engine, use GHA/sbt-ci-release #41

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -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
44 changes: 44 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ project/plugins/project/
.idea/
.idea_modules/

.bsp/
3 changes: 0 additions & 3 deletions .travis.yml

This file was deleted.

14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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.

Expand Down Expand Up @@ -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.
29 changes: 26 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -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",
"[email protected]",
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
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.0.1
sbt.version=1.9.7
4 changes: 3 additions & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -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")

This file was deleted.

This file was deleted.

44 changes: 22 additions & 22 deletions src/main/scala/com/typesafe/sbt/uglify/SbtUglify.scala
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down Expand Up @@ -93,57 +93,56 @@ 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
val compressValue = uglifyCompress.value
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,
Expand All @@ -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
)
Expand Down Expand Up @@ -221,7 +220,6 @@ object SbtUglify extends AutoPlugin {
nodeModulePaths,
uglifyjsShell,
args: Seq[String],
timeout
)
}

Expand Down Expand Up @@ -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, ())
Expand Down
4 changes: 1 addition & 3 deletions src/sbt-test/sbt-uglify/uglify-concat/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -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/"
)
4 changes: 1 addition & 3 deletions src/sbt-test/sbt-uglify/uglify/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -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/"
)
1 change: 0 additions & 1 deletion version.sbt

This file was deleted.