resources: Add option to silence dependency deprecation warnings - hugo - [fork] hugo port for 9front
HTML git clone git@git.drkhsh.at/hugo.git
DIR Log
DIR Files
DIR Refs
DIR Submodules
DIR README
DIR LICENSE
---
DIR commit c15ebce2fd9cf0427e89578389f298a83be95728
DIR parent 6f14dbe24c2c951ff5cf70986170d87aa56cb03e
HTML Author: Joe Mooring <joe.mooring@veriphor.com>
Date: Thu, 27 Mar 2025 15:52:46 -0700
resources: Add option to silence dependency deprecation warnings
Closes #13530
Diffstat:
M go.mod | 2 +-
M go.sum | 4 ++--
M resources/resource_transformers/to… | 5 +++++
M resources/resource_transformers/to… | 62 +++++++++++++++++++++++++++++++
M resources/resource_transformers/to… | 9 +++++----
5 files changed, 75 insertions(+), 7 deletions(-)
---
DIR diff --git 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
DIR diff --git 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=
DIR diff --git a/resources/resource_transformers/tocss/dartsass/client.go b/resources/resource_transformers/tocss/dartsass/client.go
@@ -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) {
DIR diff --git a/resources/resource_transformers/tocss/dartsass/dartsass_integration_test.go b/resources/resource_transformers/tocss/dartsass/dartsass_integration_test.go
@@ -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",
+ )
+}
DIR diff --git a/resources/resource_transformers/tocss/dartsass/transform.go b/resources/resource_transformers/tocss/dartsass/transform.go
@@ -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