resources: Add option to silence dependency deprecation warnings

Closes #13530
This commit is contained in:
Joe Mooring
2025-03-27 15:52:46 -07:00
committed by Bjørn Erik Pedersen
parent 6f14dbe24c
commit c15ebce2fd
5 changed files with 75 additions and 7 deletions

View 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) {

View 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",
)
}

View 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