]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
resources: Add option to silence dependency deprecation warnings
authorJoe Mooring <joe.mooring@veriphor.com>
Thu, 27 Mar 2025 22:52:46 +0000 (15:52 -0700)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sat, 29 Mar 2025 18:04:53 +0000 (19:04 +0100)
Closes #13530

go.mod
go.sum
resources/resource_transformers/tocss/dartsass/client.go
resources/resource_transformers/tocss/dartsass/dartsass_integration_test.go
resources/resource_transformers/tocss/dartsass/transform.go

diff --git a/go.mod b/go.mod
index 2a76b3bea25f713c16d06c86fcd846f287b8cb44..f00429b7884889ebe8dc74b6f642453400b4641c 100644 (file)
--- a/go.mod
+++ b/go.mod
@@ -10,7 +10,7 @@ require (
        github.com/bep/debounce v1.2.0
        github.com/bep/gitmap v1.6.0
        github.com/bep/goat v0.5.0
-       github.com/bep/godartsass/v2 v2.4.1
+       github.com/bep/godartsass/v2 v2.5.0
        github.com/bep/golibsass v1.2.0
        github.com/bep/goportabletext v0.1.0
        github.com/bep/gowebp v0.3.0
diff --git a/go.sum b/go.sum
index fc3eae36b4977fa397aad74a28c892cfa2f56302..b5e5fd3be4e07a08a614028e0e908c87f4676b03 100644 (file)
--- a/go.sum
+++ b/go.sum
@@ -129,8 +129,8 @@ github.com/bep/gitmap v1.6.0 h1:sDuQMm9HoTL0LtlrfxjbjgAg2wHQd4nkMup2FInYzhA=
 github.com/bep/gitmap v1.6.0/go.mod h1:n+3W1f/rot2hynsqEGxGMErPRgT41n9CkGuzPvz9cIw=
 github.com/bep/goat v0.5.0 h1:S8jLXHCVy/EHIoCY+btKkmcxcXFd34a0Q63/0D4TKeA=
 github.com/bep/goat v0.5.0/go.mod h1:Md9x7gRxiWKs85yHlVTvHQw9rg86Bm+Y4SuYE8CTH7c=
-github.com/bep/godartsass/v2 v2.4.1 h1:ktbimHvS+FUZ2FQsSEqm5DDfKnr56DVf7GNWuIbA1M8=
-github.com/bep/godartsass/v2 v2.4.1/go.mod h1:rjsi1YSXAl/UbsGL85RLDEjRKdIKUlMQHr6ChUNYOFU=
+github.com/bep/godartsass/v2 v2.5.0 h1:tKRvwVdyjCIr48qgtLa4gHEdtRkPF8H1OeEhJAEv7xg=
+github.com/bep/godartsass/v2 v2.5.0/go.mod h1:rjsi1YSXAl/UbsGL85RLDEjRKdIKUlMQHr6ChUNYOFU=
 github.com/bep/golibsass v1.2.0 h1:nyZUkKP/0psr8nT6GR2cnmt99xS93Ji82ZD9AgOK6VI=
 github.com/bep/golibsass v1.2.0/go.mod h1:DL87K8Un/+pWUS75ggYv41bliGiolxzDKWJAq3eJ1MA=
 github.com/bep/goportabletext v0.1.0 h1:8dqym2So1cEqVZiBa4ZnMM1R9l/DnC1h4ONg4J5kujw=
index 4ab958c01c2a50da52c59ac1d25554e73d864594..965232ad4de6093b4a84e18bc945f0f86d3da81d 100644 (file)
@@ -161,6 +161,11 @@ type Options struct {
        // The IDs can be found in the Dart Sass log output, e.g. "import" in
        //    WARN  Dart Sass: DEPRECATED [import].
        SilenceDeprecations []string
+
+       // Whether to silence deprecation warnings from dependencies, where a
+       // dependency is considered any file transitively imported through a load
+       // path. This does not apply to @warn or @debug rules.
+       SilenceDependencyDeprecations bool
 }
 
 func decodeOptions(m map[string]any) (opts Options, err error) {
index 293fdfbcf86e056df80c69b16943a695706edeb3..89d503d36e7a34cd2aa8431b73ba0b0b411f8156 100644 (file)
@@ -642,3 +642,65 @@ T1: {{ $r.Content }}
        b.AssertLogContains("! Dart Sass: DEPRECATED [import]")
        b.AssertFileContent("public/index.html", `moo{color:#fff}`)
 }
+
+func TestSilenceDependencyDeprecations(t *testing.T) {
+       t.Parallel()
+
+       files := `
+-- hugo.toml --
+disableKinds = ['page','rss','section','sitemap','taxonomy','term']
+-- layouts/index.html --
+{{ $opts := dict
+  "transpiler" "dartsass"
+  "outputStyle" "compressed"
+  "includePaths" (slice "node_modules")
+  KVPAIR
+}}
+{{ (resources.Get "sass/main.scss" | css.Sass $opts).Content }}
+-- assets/sass/main.scss --
+@use "sass:color";
+@use "foo/deprecated.scss";
+h3 { color: rgb(color.channel(#ccc, "red", $space: rgb), 0, 0); }
+// COMMENT
+-- node_modules/foo/deprecated.scss --
+@use "sass:color";
+h1 { color: rgb(color.channel(#eee, "red", $space: rgb), 0, 0); }
+h2 { color: rgb(color.red(#ddd), 0, 0); } // deprecated
+`
+
+       expectedCSS := "h1{color:#e00}h2{color:#d00}h3{color:#c00}"
+
+       // Do not silence dependency deprecation warnings (default).
+       f := strings.ReplaceAll(files, "KVPAIR", "")
+       b := hugolib.Test(t, f, hugolib.TestOptWarn(), hugolib.TestOptOsFs())
+       b.AssertFileContent("public/index.html", expectedCSS)
+       b.AssertLogContains(
+               "WARN  Dart Sass: DEPRECATED [color-functions]",
+               "color.red() is deprecated",
+       )
+
+       // Do not silence dependency deprecation warnings (explicit).
+       f = strings.ReplaceAll(files, "KVPAIR", `"silenceDependencyDeprecations" false`)
+       b = hugolib.Test(t, f, hugolib.TestOptWarn(), hugolib.TestOptOsFs())
+       b.AssertFileContent("public/index.html", expectedCSS)
+       b.AssertLogContains(
+               "WARN  Dart Sass: DEPRECATED [color-functions]",
+               "color.red() is deprecated",
+       )
+
+       // Silence dependency deprecation warnings.
+       f = strings.ReplaceAll(files, "KVPAIR", `"silenceDependencyDeprecations" true`)
+       b = hugolib.Test(t, f, hugolib.TestOptWarn(), hugolib.TestOptOsFs())
+       b.AssertFileContent("public/index.html", expectedCSS)
+       b.AssertLogContains("! WARN")
+
+       // Make sure that we are not silencing non-dependency deprecation warnings.
+       f = strings.ReplaceAll(files, "KVPAIR", `"silenceDependencyDeprecations" true`)
+       f = strings.ReplaceAll(f, "// COMMENT", "h4 { color: rgb(0, color.green(#bbb), 0); }")
+       b = hugolib.Test(t, f, hugolib.TestOptWarn(), hugolib.TestOptOsFs())
+       b.AssertFileContent("public/index.html", expectedCSS+"h4{color:#0b0}")
+       b.AssertLogContains(
+               "WARN  Dart Sass: DEPRECATED [color-functions]",
+               "color.green() is deprecated",
+       )
+}
index 77bacc1155147f7fcfdfef577841bf565cfd780b..e1e9b0be0c6d2e325187670f96034b6bfe630c8c 100644 (file)
@@ -86,10 +86,11 @@ func (t *transform) Transform(ctx *resources.ResourceTransformationCtx) error {
 
                        varsStylesheet: godartsass.Import{Content: sass.CreateVarsStyleSheet(sass.TranspilerDart, opts.Vars)},
                },
-               OutputStyle:             godartsass.ParseOutputStyle(opts.OutputStyle),
-               EnableSourceMap:         opts.EnableSourceMap,
-               SourceMapIncludeSources: opts.SourceMapIncludeSources,
-               SilenceDeprecations:     opts.SilenceDeprecations,
+               OutputStyle:                   godartsass.ParseOutputStyle(opts.OutputStyle),
+               EnableSourceMap:               opts.EnableSourceMap,
+               SourceMapIncludeSources:       opts.SourceMapIncludeSources,
+               SilenceDeprecations:           opts.SilenceDeprecations,
+               SilenceDependencyDeprecations: opts.SilenceDependencyDeprecations,
        }
 
        // Append any workDir relative include paths