deps: Update github.com/tdewolff/minify/v2 v2.20.9 => v2.20.13

KeepConditionalComments was deprecated in the upstream library and replaced with KeepSpecialComments. This new option reflects that both conditional comments and Server Side Include comments can be optionally stripped by the minifier. As with KeepConditionalComments, the minifier is configured not to strip them by default.
This commit is contained in:
James Tatum
2024-01-11 13:30:42 -08:00
committed by Bjørn Erik Pedersen
parent a541e3b4d4
commit 8915343075
6 changed files with 90 additions and 20 deletions

View File

@@ -28,11 +28,11 @@ import (
var defaultTdewolffConfig = TdewolffConfig{
HTML: html.Minifier{
KeepDocumentTags: true,
KeepConditionalComments: true,
KeepEndTags: true,
KeepDefaultAttrVals: true,
KeepWhitespace: false,
KeepDocumentTags: true,
KeepSpecialComments: true,
KeepEndTags: true,
KeepDefaultAttrVals: true,
KeepWhitespace: false,
},
CSS: css.Minifier{
Precision: 0,
@@ -90,17 +90,39 @@ func DecodeConfig(v any) (conf MinifyConfig, err error) {
// Handle upstream renames.
if td, found := m["tdewolff"]; found {
tdm := maps.ToStringMap(td)
for _, key := range []string{"css", "svg"} {
if v, found := tdm[key]; found {
vm := maps.ToStringMap(v)
if vv, found := vm["decimal"]; found {
vvi := cast.ToInt(vv)
if vvi > 0 {
vm["precision"] = vvi
ko := "decimal"
kn := "precision"
if vv, found := vm[ko]; found {
if _, found = vm[kn]; !found {
vvi := cast.ToInt(vv)
if vvi > 0 {
vm[kn] = vvi
}
}
delete(vm, ko)
}
}
}
// keepConditionalComments was renamed to keepSpecialComments
if v, found := tdm["html"]; found {
vm := maps.ToStringMap(v)
ko := "keepconditionalcomments"
kn := "keepspecialcomments"
if vv, found := vm[ko]; found {
// Set keepspecialcomments, if not already set
if _, found := vm[kn]; !found {
vm[kn] = cast.ToBool(vv)
}
// Remove the old key to prevent deprecation warnings
delete(vm, ko)
}
}
}
err = mapstructure.WeakDecode(m, &conf)

View File

@@ -59,3 +59,45 @@ func TestConfigLegacy(t *testing.T) {
conf := testconfig.GetTestConfigs(nil, v).Base.Minify
c.Assert(conf.MinifyOutput, qt.Equals, true)
}
func TestConfigNewCommentOptions(t *testing.T) {
c := qt.New(t)
v := config.New()
// setting the old options should automatically set the new options
v.Set("minify", map[string]any{
"tdewolff": map[string]any{
"html": map[string]any{
"keepConditionalComments": false,
},
"svg": map[string]any{
"decimal": "5",
},
},
})
conf := testconfig.GetTestConfigs(nil, v).Base.Minify
c.Assert(conf.Tdewolff.HTML.KeepSpecialComments, qt.Equals, false)
c.Assert(conf.Tdewolff.SVG.Precision, qt.Equals, 5)
// the new values should win, regardless of the contents of the old values
v = config.New()
v.Set("minify", map[string]any{
"tdewolff": map[string]any{
"html": map[string]any{
"keepConditionalComments": false,
"keepSpecialComments": true,
},
"svg": map[string]any{
"decimal": "5",
"precision": "10",
},
},
})
conf = testconfig.GetTestConfigs(nil, v).Base.Minify
c.Assert(conf.Tdewolff.HTML.KeepSpecialComments, qt.Equals, true)
c.Assert(conf.Tdewolff.SVG.Precision, qt.Equals, 10)
}

View File

@@ -203,13 +203,13 @@ func TestDecodeConfigKeepWhitespace(t *testing.T) {
c.Assert(conf.Tdewolff.HTML, qt.DeepEquals,
html.Minifier{
KeepComments: false,
KeepConditionalComments: true,
KeepDefaultAttrVals: true,
KeepDocumentTags: true,
KeepEndTags: false,
KeepQuotes: false,
KeepWhitespace: false},
KeepComments: false,
KeepSpecialComments: true,
KeepDefaultAttrVals: true,
KeepDocumentTags: true,
KeepEndTags: false,
KeepQuotes: false,
KeepWhitespace: false},
)
}