Repository: gohugoio/hugo (language: go)

Issue:
Add --silence-deprecation Dart Sass options (slice?)
I would like to request a feature to silence deprecation warnings from Dart Sass.

```html
{{ $css := resources.Get "index.scss" | toCSS (dict
  "transpiler" "dartsass"
  "silenceDeprecation" "import"
) }}
```

Reference: https://sass-lang.com/blog/import-is-deprecated/#controlling-deprecation-warnings


Discussion / hints:
Note that these options must be passed via the protobuf API (https://github.com/bep/godartsass); I assume they are also available there and not just as CLI flags.

Fix patch:
diff --git a/docs/content/en/functions/css/Sass.md b/docs/content/en/functions/css/Sass.md
index 328037bb96b..793c0c1ac2f 100644
--- a/docs/content/en/functions/css/Sass.md
+++ b/docs/content/en/functions/css/Sass.md
@@ -86,6 +86,9 @@ includePaths
 {{ end }}
 ```
 
+silenceDeprecations
+: (`slice`) {{< new-in 0.139.0 >}} A slice of deprecation IDs to silence. The deprecation IDs are printed to in the warning message, e.g "import" in `WARN  Dart Sass: DEPRECATED [import] ...`. This is for Dart Sass only.
+
 ## Dart Sass
 
 The extended version of Hugo includes [LibSass] to transpile Sass to CSS. In 2020, the Sass team deprecated LibSass in favor of [Dart Sass].
diff --git a/go.mod b/go.mod
index c19e8da34c6..82a59ac91ca 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.2.0
+	github.com/bep/godartsass/v2 v2.3.0
 	github.com/bep/golibsass v1.2.0
 	github.com/bep/gowebp v0.3.0
 	github.com/bep/helpers v0.5.0
diff --git a/go.sum b/go.sum
index 0ba28ce4dfe..a3af71aee04 100644
--- a/go.sum
+++ b/go.sum
@@ -131,6 +131,8 @@ 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.2.0 h1:3hO9Dt4BOnxkKmRxc+OpoKVFrDvBycpSCXEdElVAMVI=
 github.com/bep/godartsass/v2 v2.2.0/go.mod h1:AcP8QgC+OwOXEq6im0WgDRYK7scDsmZCEW62o1prQLo=
+github.com/bep/godartsass/v2 v2.3.0 h1:gEMyq/bNn4hxpUSwy/NKyOTqPqVh3AedhMHvQR+x0kU=
+github.com/bep/godartsass/v2 v2.3.0/go.mod h1:AcP8QgC+OwOXEq6im0WgDRYK7scDsmZCEW62o1prQLo=
 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/gowebp v0.3.0 h1:MhmMrcf88pUY7/PsEhMgEP0T6fDUnRTMpN8OclDrbrY=
diff --git a/resources/resource_transformers/tocss/dartsass/client.go b/resources/resource_transformers/tocss/dartsass/client.go
index b4232762154..762828b70a5 100644
--- a/resources/resource_transformers/tocss/dartsass/client.go
+++ b/resources/resource_transformers/tocss/dartsass/client.go
@@ -74,8 +74,10 @@ func New(fs *filesystems.SourceFilesystem, rs *resources.Spec) (*Client, error)
 			case godartsass.LogEventTypeDebug:
 				// Log as Info for now, we may adjust this if it gets too chatty.
 				infol.Log(logg.String(message))
+			case godartsass.LogEventTypeDeprecated:
+				warnl.Logf("DEPRECATED [%s]: %s", event.DeprecationType, message)
 			default:
-				// The rest are either deprecations or @warn statements.
+				// The rest are @warn statements.
 				warnl.Log(logg.String(message))
 			}
 		},
@@ -151,6 +153,11 @@ type Options struct {
 	//     @use "hugo:vars";
 	//     $color: vars.$color;
 	Vars map[string]any
+
+	// Deprecations IDs in this slice will be silenced.
+	// The IDs can be found in the Dart Sass log output, e.g. "import" in
+	//    WARN  Dart Sass: DEPRECATED [import].
+	SilenceDeprecations []string
 }
 
 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 e23ef0986b0..c5f97abff3e 100644
--- a/resources/resource_transformers/tocss/dartsass/transform.go
+++ b/resources/resource_transformers/tocss/dartsass/transform.go
@@ -89,6 +89,7 @@ func (t *transform) Transform(ctx *resources.ResourceTransformationCtx) error {
 		OutputStyle:             godartsass.ParseOutputStyle(opts.OutputStyle),
 		EnableSourceMap:         opts.EnableSourceMap,
 		SourceMapIncludeSources: opts.SourceMapIncludeSources,
+		SilenceDeprecations:     opts.SilenceDeprecations,
 	}
 
 	// Append any workDir relative include paths


Test patch:
diff --git a/hugolib/integrationtest_builder.go b/hugolib/integrationtest_builder.go
index 5dc13592ff2..637e5dee0cc 100644
--- a/hugolib/integrationtest_builder.go
+++ b/hugolib/integrationtest_builder.go
@@ -76,6 +76,13 @@ func TestOptWarn() TestOpt {
 	}
 }
 
+// TestOptOsFs will enable the real file system in integration tests.
+func TestOptOsFs() TestOpt {
+	return func(c *IntegrationTestConfig) {
+		c.NeedsOsFS = true
+	}
+}
+
 // TestOptWithNFDOnDarwin will normalize the Unicode filenames to NFD on Darwin.
 func TestOptWithNFDOnDarwin() TestOpt {
 	return func(c *IntegrationTestConfig) {
diff --git a/resources/resource_transformers/tocss/dartsass/dartsass_integration_test.go b/resources/resource_transformers/tocss/dartsass/dartsass_integration_test.go
index 2aac2c5fb54..5d1b89eaf08 100644
--- a/resources/resource_transformers/tocss/dartsass/dartsass_integration_test.go
+++ b/resources/resource_transformers/tocss/dartsass/dartsass_integration_test.go
@@ -605,3 +605,38 @@ module hugo-github-issue-12849
 
 	b.AssertFileContent("public/index.html", ".foo{color:red}.bar{color:green}")
 }
+
+func TestIgnoreDeprecationWarnings(t *testing.T) {
+	t.Parallel()
+	if !dartsass.Supports() {
+		t.Skip()
+	}
+
+	files := `
+-- hugo.toml --
+disableKinds = ['page','section','rss','sitemap','taxonomy','term']
+-- assets/scss/main.scss --
+@import "moo";
+-- node_modules/foo/_moo.scss --
+$moolor: #fff;
+
+moo {
+  color: $moolor;
+}
+-- config.toml --
+-- layouts/index.html --
+{{ $cssOpts := (dict "includePaths" (slice "node_modules/foo") "transpiler" "dartsass" ) }}
+{{ $r := resources.Get "scss/main.scss" |  toCSS $cssOpts  | minify  }}
+T1: {{ $r.Content }}
+	`
+
+	b := hugolib.Test(t, files, hugolib.TestOptOsFs(), hugolib.TestOptWarn())
+	b.AssertLogContains("Dart Sass: DEPRECATED [import]")
+	b.AssertFileContent("public/index.html", `moo{color:#fff}`)
+
+	files = strings.ReplaceAll(files, `"transpiler" "dartsass"`, `"transpiler" "dartsass" "silenceDeprecations" (slice "import")`)
+
+	b = hugolib.Test(t, files, hugolib.TestOptOsFs(), hugolib.TestOptWarn())
+	b.AssertLogContains("! Dart Sass: DEPRECATED [import]")
+	b.AssertFileContent("public/index.html", `moo{color:#fff}`)
+}