Repository: gohugoio/hugo (language: go)

Issue:
Add support for `quietDeps` for Sass compiler
Right now the `quietDeps`/`--quiet-deps` option is not available in the [sass](https://gohugo.io/functions/css/sass/) function. It would allow us to not have to silence warnings for all the codebase.

See references:
https://sass-lang.com/documentation/cli/dart-sass/#quiet-deps
https://sass-lang.com/documentation/js-api/interfaces/stringoptions/#quietDeps

Use case:
I'm customizing Bootstrap and getting a lot of deprecation warnings after I started to import it.


Discussion / hints:
We can use dart cli with javascript api

For reference, there is a `silenceDeprecations`, option, but you would have to list each ID. But sure, we can add one more option.

For the person who want to implement this, you can take this commit as an inspiration: https://github.com/bep/godartsass/commit/8eb162a8cafc099e7fc6c18231b12150b1c16775
> For reference, there is a `silenceDeprecations`, option, but you would have to list each ID. But sure, we can add one more option.
> 
> For the person who want to implement this, you can take this commit as an inspiration: https://github.com/bep/godartsass/commit/8eb162a8cafc099e7fc6c18231b12150b1c16775

I'd love to do it, if I was fluent in Go I'd send a PR... Thank you for accepting the suggestion. I'm manually silencing the deprecations, but only because of Bootstrap and it bothers me as I might end up using deprecated items myself.

Fix patch:
diff --git a/go.mod b/go.mod
index 2a76b3bea25..f00429b7884 100644
--- 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 fc3eae36b49..b5e5fd3be4e 100644
--- 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=
diff --git a/resources/resource_transformers/tocss/dartsass/client.go b/resources/resource_transformers/tocss/dartsass/client.go
index 4ab958c01c2..965232ad4de 100644
--- 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) {
diff --git a/resources/resource_transformers/tocss/dartsass/transform.go b/resources/resource_transformers/tocss/dartsass/transform.go
index 77bacc11551..e1e9b0be0c6 100644
--- 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


Test patch:
diff --git a/resources/resource_transformers/tocss/dartsass/dartsass_integration_test.go b/resources/resource_transformers/tocss/dartsass/dartsass_integration_test.go
index 293fdfbcf86..89d503d36e7 100644
--- 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",
+	)
+}