From 66beac99c64b5e5fe7bec0bda437ba5858d49a36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Thu, 18 Feb 2021 09:32:34 +0100 Subject: [PATCH] deps: Update github.com/tdewolff/minify/v2 v2.6.2 => v2.9.13 Fixes #8258 --- go.mod | 3 ++- go.sum | 6 ++++++ hugolib/resource_chain_test.go | 2 +- minifiers/config.go | 26 ++++++++++++++++++++------ minifiers/minifiers_test.go | 25 ++++++++++++++++++++++++- 5 files changed, 53 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index c925192a10b..6ad5ea450d9 100644 --- a/go.mod +++ b/go.mod @@ -44,6 +44,7 @@ require ( github.com/olekukonko/tablewriter v0.0.5 github.com/pelletier/go-toml v1.8.1 github.com/pkg/errors v0.9.1 + github.com/pkg/profile v1.5.0 // indirect github.com/rogpeppe/go-internal v1.6.2 github.com/russross/blackfriday v1.5.3-0.20200218234912-41c5fccfd6f6 github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd @@ -55,7 +56,7 @@ require ( github.com/spf13/jwalterweatherman v1.1.0 github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.7.1 - github.com/tdewolff/minify/v2 v2.6.2 + github.com/tdewolff/minify/v2 v2.9.13 github.com/yuin/goldmark v1.3.2 github.com/yuin/goldmark-highlighting v0.0.0-20200307114337-60d527fdb691 gocloud.dev v0.20.0 diff --git a/go.sum b/go.sum index 695b143fa89..01afef1cbc1 100644 --- a/go.sum +++ b/go.sum @@ -432,6 +432,7 @@ github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/profile v1.5.0/go.mod h1:qBsxPvzyUincmltOk6iyRVxHYg4adc0OFOv72ZdLa18= github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI= github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -506,8 +507,12 @@ github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/tdewolff/minify/v2 v2.6.2 h1:Jaod6aSABWmhftvnxvXogxcEoQt6yogfFeZgIQEMPOw= github.com/tdewolff/minify/v2 v2.6.2/go.mod h1:BkDSm8aMMT0ALGmpt7j3Ra7nLUgZL0qhyrAHXwxcy5w= +github.com/tdewolff/minify/v2 v2.9.13 h1:RrwQhgGoYBhKN/ezStGB+crU64wPK1ZE5Jmkl63lif0= +github.com/tdewolff/minify/v2 v2.9.13/go.mod h1:faNOp+awAoo+fhFHD+NAkBOaXBAvJI2X2SDERGKnARo= github.com/tdewolff/parse/v2 v2.4.2 h1:Bu2Qv6wepkc+Ou7iB/qHjAhEImlAP5vedzlQRUdj3BI= github.com/tdewolff/parse/v2 v2.4.2/go.mod h1:WzaJpRSbwq++EIQHYIRTpbYKNA3gn9it1Ik++q4zyho= +github.com/tdewolff/parse/v2 v2.5.10 h1:vj35n+ljq8LuYUx436s4qB18wuwP7thrLv+t1syE39M= +github.com/tdewolff/parse/v2 v2.5.10/go.mod h1:WzaJpRSbwq++EIQHYIRTpbYKNA3gn9it1Ik++q4zyho= github.com/tdewolff/test v1.0.6 h1:76mzYJQ83Op284kMT+63iCNCI7NEERsIN8dLM+RiKr4= github.com/tdewolff/test v1.0.6/go.mod h1:6DAvZliBAAnD7rhVgwaM7DE5/d9NMOAJ09SqYqeK4QE= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= @@ -692,6 +697,7 @@ golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980 h1:OjiUf46hAmXblsZdnoSXsEUSKU8r1UEzcL5RVZ4gO9Y= golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200724161237-0e2f3a69832c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/hugolib/resource_chain_test.go b/hugolib/resource_chain_test.go index d9b09e2a904..9ea1d85298c 100644 --- a/hugolib/resource_chain_test.go +++ b/hugolib/resource_chain_test.go @@ -575,7 +575,7 @@ Min HTML: {{ ( resources.Get "mydata/html1.html" | resources.Minify ).Content | `) }, func(b *sitesBuilder) { b.AssertFileContent("public/index.html", `Min CSS: h1{font-style:bold}`) - b.AssertFileContent("public/index.html", `Min JS: var x;x=5;document.getElementById("demo").innerHTML=x*10;`) + b.AssertFileContent("public/index.html", `Min JS: var x;x=5,document.getElementById("demo").innerHTML=x*10`) b.AssertFileContent("public/index.html", `Min JSON: {"employees":[{"firstName":"John","lastName":"Doe"},{"firstName":"Anna","lastName":"Smith"},{"firstName":"Peter","lastName":"Jones"}]}`) b.AssertFileContent("public/index.html", `Min XML: Hugo Rocks!`) b.AssertFileContent("public/index.html", `Min SVG: `) diff --git a/minifiers/config.go b/minifiers/config.go index 5ee3aa2f9cb..fc707ce3778 100644 --- a/minifiers/config.go +++ b/minifiers/config.go @@ -18,6 +18,7 @@ import ( "github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/docshelper" "github.com/gohugoio/hugo/parser" + "github.com/spf13/cast" "github.com/mitchellh/mapstructure" "github.com/tdewolff/minify/v2/css" @@ -35,18 +36,15 @@ var defaultTdewolffConfig = tdewolffConfig{ KeepEndTags: true, KeepDefaultAttrVals: true, KeepWhitespace: false, - // KeepQuotes: false, >= v2.6.2 }, CSS: css.Minifier{ - Decimals: -1, // will be deprecated - // Precision: 0, // use Precision with >= v2.7.0 - KeepCSS2: true, + Precision: 0, + KeepCSS2: true, }, JS: js.Minifier{}, JSON: json.Minifier{}, SVG: svg.Minifier{ - Decimals: -1, // will be deprecated - // Precision: 0, // use Precision with >= v2.7.0 + Precision: 0, }, XML: xml.Minifier{ KeepWhitespace: false, @@ -99,6 +97,22 @@ func decodeConfig(cfg config.Provider) (conf minifyConfig, err error) { m := maps.ToStringMap(v) + // Handle upstream renames. + if td, found := m["tdewolff"]; found { + tdm := cast.ToStringMap(td) + for _, key := range []string{"css", "svg"} { + if v, found := tdm[key]; found { + vm := cast.ToStringMap(v) + if vv, found := vm["decimal"]; found { + vvi := cast.ToInt(vv) + if vvi > 0 { + vm["precision"] = vvi + } + } + } + } + } + err = mapstructure.WeakDecode(m, &conf) if err != nil { diff --git a/minifiers/minifiers_test.go b/minifiers/minifiers_test.go index 9e62c5d507e..1a2d56e3049 100644 --- a/minifiers/minifiers_test.go +++ b/minifiers/minifiers_test.go @@ -34,7 +34,7 @@ func TestNew(t *testing.T) { var rawJS string var minJS string rawJS = " var foo =1 ; foo ++ ; " - minJS = "var foo=1;foo++;" + minJS = "var foo=1;foo++" var rawJSON string var minJSON string @@ -165,3 +165,26 @@ func TestBugs(t *testing.T) { c.Assert(b.String(), qt.Equals, test.expectedMinString) } } + +// Renamed to Precision in v2.7.0. Check that we support both. +func TestDecodeConfigDecimalIsNowPrecision(t *testing.T) { + c := qt.New(t) + v := viper.New() + v.Set("minify", map[string]interface{}{ + "disablexml": true, + "tdewolff": map[string]interface{}{ + "css": map[string]interface{}{ + "decimal": 3, + }, + "svg": map[string]interface{}{ + "decimal": 3, + }, + }, + }) + + conf, err := decodeConfig(v) + + c.Assert(err, qt.IsNil) + c.Assert(conf.Tdewolff.CSS.Precision, qt.Equals, 3) + +}