diff options
author | Bjørn Erik Pedersen <[email protected]> | 2024-11-18 10:04:37 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2024-11-18 13:41:12 +0100 |
commit | 3b6eaf9b1f128b36fe25478b2e7c4d8463e5ab58 (patch) | |
tree | 6b22933db13ee7564c04f5daa8497754eccd6005 /resources/resource_transformers | |
parent | 1fd845eee4d2d0dc264c0f45471815d00160f7dc (diff) | |
download | hugo-3b6eaf9b1f128b36fe25478b2e7c4d8463e5ab58.tar.gz hugo-3b6eaf9b1f128b36fe25478b2e7c4d8463e5ab58.zip |
dartsass: Add silenceDeprecations option
Fixes #13045
Diffstat (limited to 'resources/resource_transformers')
3 files changed, 44 insertions, 1 deletions
diff --git a/resources/resource_transformers/tocss/dartsass/client.go b/resources/resource_transformers/tocss/dartsass/client.go index b42327621..762828b70 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/dartsass_integration_test.go b/resources/resource_transformers/tocss/dartsass/dartsass_integration_test.go index 2aac2c5fb..5d1b89eaf 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}`) +} diff --git a/resources/resource_transformers/tocss/dartsass/transform.go b/resources/resource_transformers/tocss/dartsass/transform.go index e23ef0986..c5f97abff 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 |