Skip to content

Commit c15ebce

Browse files
jmooringbep
authored andcommitted
resources: Add option to silence dependency deprecation warnings
Closes #13530
1 parent 6f14dbe commit c15ebce

File tree

5 files changed

+75
-7
lines changed

5 files changed

+75
-7
lines changed

Diff for: go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/bep/debounce v1.2.0
1111
github.com/bep/gitmap v1.6.0
1212
github.com/bep/goat v0.5.0
13-
github.com/bep/godartsass/v2 v2.4.1
13+
github.com/bep/godartsass/v2 v2.5.0
1414
github.com/bep/golibsass v1.2.0
1515
github.com/bep/goportabletext v0.1.0
1616
github.com/bep/gowebp v0.3.0

Diff for: go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ github.com/bep/gitmap v1.6.0 h1:sDuQMm9HoTL0LtlrfxjbjgAg2wHQd4nkMup2FInYzhA=
129129
github.com/bep/gitmap v1.6.0/go.mod h1:n+3W1f/rot2hynsqEGxGMErPRgT41n9CkGuzPvz9cIw=
130130
github.com/bep/goat v0.5.0 h1:S8jLXHCVy/EHIoCY+btKkmcxcXFd34a0Q63/0D4TKeA=
131131
github.com/bep/goat v0.5.0/go.mod h1:Md9x7gRxiWKs85yHlVTvHQw9rg86Bm+Y4SuYE8CTH7c=
132-
github.com/bep/godartsass/v2 v2.4.1 h1:ktbimHvS+FUZ2FQsSEqm5DDfKnr56DVf7GNWuIbA1M8=
133-
github.com/bep/godartsass/v2 v2.4.1/go.mod h1:rjsi1YSXAl/UbsGL85RLDEjRKdIKUlMQHr6ChUNYOFU=
132+
github.com/bep/godartsass/v2 v2.5.0 h1:tKRvwVdyjCIr48qgtLa4gHEdtRkPF8H1OeEhJAEv7xg=
133+
github.com/bep/godartsass/v2 v2.5.0/go.mod h1:rjsi1YSXAl/UbsGL85RLDEjRKdIKUlMQHr6ChUNYOFU=
134134
github.com/bep/golibsass v1.2.0 h1:nyZUkKP/0psr8nT6GR2cnmt99xS93Ji82ZD9AgOK6VI=
135135
github.com/bep/golibsass v1.2.0/go.mod h1:DL87K8Un/+pWUS75ggYv41bliGiolxzDKWJAq3eJ1MA=
136136
github.com/bep/goportabletext v0.1.0 h1:8dqym2So1cEqVZiBa4ZnMM1R9l/DnC1h4ONg4J5kujw=

Diff for: resources/resource_transformers/tocss/dartsass/client.go

+5
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ type Options struct {
161161
// The IDs can be found in the Dart Sass log output, e.g. "import" in
162162
// WARN Dart Sass: DEPRECATED [import].
163163
SilenceDeprecations []string
164+
165+
// Whether to silence deprecation warnings from dependencies, where a
166+
// dependency is considered any file transitively imported through a load
167+
// path. This does not apply to @warn or @debug rules.
168+
SilenceDependencyDeprecations bool
164169
}
165170

166171
func decodeOptions(m map[string]any) (opts Options, err error) {

Diff for: resources/resource_transformers/tocss/dartsass/dartsass_integration_test.go

+62
Original file line numberDiff line numberDiff line change
@@ -642,3 +642,65 @@ T1: {{ $r.Content }}
642642
b.AssertLogContains("! Dart Sass: DEPRECATED [import]")
643643
b.AssertFileContent("public/index.html", `moo{color:#fff}`)
644644
}
645+
646+
func TestSilenceDependencyDeprecations(t *testing.T) {
647+
t.Parallel()
648+
649+
files := `
650+
-- hugo.toml --
651+
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
652+
-- layouts/index.html --
653+
{{ $opts := dict
654+
"transpiler" "dartsass"
655+
"outputStyle" "compressed"
656+
"includePaths" (slice "node_modules")
657+
KVPAIR
658+
}}
659+
{{ (resources.Get "sass/main.scss" | css.Sass $opts).Content }}
660+
-- assets/sass/main.scss --
661+
@use "sass:color";
662+
@use "foo/deprecated.scss";
663+
h3 { color: rgb(color.channel(#ccc, "red", $space: rgb), 0, 0); }
664+
// COMMENT
665+
-- node_modules/foo/deprecated.scss --
666+
@use "sass:color";
667+
h1 { color: rgb(color.channel(#eee, "red", $space: rgb), 0, 0); }
668+
h2 { color: rgb(color.red(#ddd), 0, 0); } // deprecated
669+
`
670+
671+
expectedCSS := "h1{color:#e00}h2{color:#d00}h3{color:#c00}"
672+
673+
// Do not silence dependency deprecation warnings (default).
674+
f := strings.ReplaceAll(files, "KVPAIR", "")
675+
b := hugolib.Test(t, f, hugolib.TestOptWarn(), hugolib.TestOptOsFs())
676+
b.AssertFileContent("public/index.html", expectedCSS)
677+
b.AssertLogContains(
678+
"WARN Dart Sass: DEPRECATED [color-functions]",
679+
"color.red() is deprecated",
680+
)
681+
682+
// Do not silence dependency deprecation warnings (explicit).
683+
f = strings.ReplaceAll(files, "KVPAIR", `"silenceDependencyDeprecations" false`)
684+
b = hugolib.Test(t, f, hugolib.TestOptWarn(), hugolib.TestOptOsFs())
685+
b.AssertFileContent("public/index.html", expectedCSS)
686+
b.AssertLogContains(
687+
"WARN Dart Sass: DEPRECATED [color-functions]",
688+
"color.red() is deprecated",
689+
)
690+
691+
// Silence dependency deprecation warnings.
692+
f = strings.ReplaceAll(files, "KVPAIR", `"silenceDependencyDeprecations" true`)
693+
b = hugolib.Test(t, f, hugolib.TestOptWarn(), hugolib.TestOptOsFs())
694+
b.AssertFileContent("public/index.html", expectedCSS)
695+
b.AssertLogContains("! WARN")
696+
697+
// Make sure that we are not silencing non-dependency deprecation warnings.
698+
f = strings.ReplaceAll(files, "KVPAIR", `"silenceDependencyDeprecations" true`)
699+
f = strings.ReplaceAll(f, "// COMMENT", "h4 { color: rgb(0, color.green(#bbb), 0); }")
700+
b = hugolib.Test(t, f, hugolib.TestOptWarn(), hugolib.TestOptOsFs())
701+
b.AssertFileContent("public/index.html", expectedCSS+"h4{color:#0b0}")
702+
b.AssertLogContains(
703+
"WARN Dart Sass: DEPRECATED [color-functions]",
704+
"color.green() is deprecated",
705+
)
706+
}

Diff for: resources/resource_transformers/tocss/dartsass/transform.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,11 @@ func (t *transform) Transform(ctx *resources.ResourceTransformationCtx) error {
8686

8787
varsStylesheet: godartsass.Import{Content: sass.CreateVarsStyleSheet(sass.TranspilerDart, opts.Vars)},
8888
},
89-
OutputStyle: godartsass.ParseOutputStyle(opts.OutputStyle),
90-
EnableSourceMap: opts.EnableSourceMap,
91-
SourceMapIncludeSources: opts.SourceMapIncludeSources,
92-
SilenceDeprecations: opts.SilenceDeprecations,
89+
OutputStyle: godartsass.ParseOutputStyle(opts.OutputStyle),
90+
EnableSourceMap: opts.EnableSourceMap,
91+
SourceMapIncludeSources: opts.SourceMapIncludeSources,
92+
SilenceDeprecations: opts.SilenceDeprecations,
93+
SilenceDependencyDeprecations: opts.SilenceDependencyDeprecations,
9394
}
9495

9596
// Append any workDir relative include paths

0 commit comments

Comments
 (0)