Skip to content

Commit 9937a5d

Browse files
authored
tpl/css: Deprecate libsass in favor of dartsass (note)
The upstream library is now EOL and the repo is archived. Also, it's time for us to move away from the extended CGO build and for Hugo users not already done that, move to https://gohugo.io/functions/css/sass/#dart-sass https://github.com/sass/libsass Closes #14261
1 parent 1b4514e commit 9937a5d

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

‎resources/resource_transformers/tocss/scss/scss_integration_test.go‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,3 +462,26 @@ target = "assets/sass"
462462

463463
b.AssertFileContent("public/index.html", ".foo1{color:red}.bar1{color:blue}.foo2{color:red}.bar2{color:blue}")
464464
}
465+
466+
func TestLibsassDeprecatedIssue14261(t *testing.T) {
467+
// This cannot be run in parallel because of global state in log deprecation handling.
468+
if !scss.Supports() {
469+
t.Skip()
470+
}
471+
472+
files := `
473+
-- assets/scss/main.scss --
474+
body {
475+
background-color: #fff;
476+
}
477+
-- hugo.toml --
478+
-- layouts/home.html --
479+
{{ $cssOpts := (dict "transpiler" "libsass") }}
480+
{{ $r := resources.Get "scss/main.scss" | toCSS $cssOpts }}
481+
{{ $r.RelPermalink }}
482+
`
483+
484+
b := hugolib.Test(t, files, hugolib.TestOptOsFs(), hugolib.TestOptInfo())
485+
486+
b.AssertLogContains("deprecated: css.Sass: libsass was deprecated in Hugo v0.153.0")
487+
}

‎tpl/css/css.go‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"sync"
88

9+
"github.com/gohugoio/hugo/common/hugo"
910
"github.com/gohugoio/hugo/common/maps"
1011
"github.com/gohugoio/hugo/common/paths"
1112
"github.com/gohugoio/hugo/common/types/css"
@@ -91,7 +92,7 @@ func (ns *Namespace) Sass(args ...any) (resource.Resource, error) {
9192
targetPath string
9293
err error
9394
ok bool
94-
transpiler = sass.TranspilerLibSass
95+
transpiler = sass.TranspilerLibSass // Deprecated default. Will be dartsass in future versions. See below.
9596
)
9697

9798
r, targetPath, ok = resourcehelpers.ResolveIfFirstArgIsString(args)
@@ -106,7 +107,10 @@ func (ns *Namespace) Sass(args ...any) (resource.Resource, error) {
106107
if m != nil {
107108
if t, _, found := maps.LookupEqualFold(m, "transpiler"); found {
108109
switch t {
109-
case sass.TranspilerDart, sass.TranspilerLibSass:
110+
case sass.TranspilerDart:
111+
transpiler = cast.ToString(t)
112+
case sass.TranspilerLibSass:
113+
hugo.Deprecate("css.Sass: libsass", "Use dartsass instead. See https://gohugo.io/functions/css/sass/#dart-sass", "v0.153.0")
110114
transpiler = cast.ToString(t)
111115
default:
112116
return nil, fmt.Errorf("unsupported transpiler %q; valid values are %q or %q", t, sass.TranspilerLibSass, sass.TranspilerDart)

0 commit comments

Comments
 (0)