aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2024-11-18 10:26:35 +0100
committerBjørn Erik Pedersen <[email protected]>2024-11-18 12:32:39 +0100
commit1fd845eee4d2d0dc264c0f45471815d00160f7dc (patch)
tree84af6881b99193da262574a80117687963cbe310
parent61e2ce2a49ad49fccdd1dc5f8aeb42616ac313f3 (diff)
downloadhugo-1fd845eee4d2d0dc264c0f45471815d00160f7dc.tar.gz
hugo-1fd845eee4d2d0dc264c0f45471815d00160f7dc.zip
dartsass: Remove support for v1 of the protocol/binary (note)
People who stil use a very old binary named `dart-sass-embedded` need to upgrade. See https://gohugo.io/functions/css/sass/#dart-sass
-rw-r--r--common/herrors/file_error.go11
-rw-r--r--common/hugo/hugo.go24
-rw-r--r--go.mod1
-rw-r--r--go.sum7
-rw-r--r--resources/resource_transformers/tocss/dartsass/client.go95
-rw-r--r--resources/resource_transformers/tocss/dartsass/transform.go10
6 files changed, 35 insertions, 113 deletions
diff --git a/common/herrors/file_error.go b/common/herrors/file_error.go
index 32a6f0081..007a06b48 100644
--- a/common/herrors/file_error.go
+++ b/common/herrors/file_error.go
@@ -20,8 +20,6 @@ import (
"io"
"path/filepath"
- godartsassv1 "github.com/bep/godartsass"
-
"github.com/bep/godartsass/v2"
"github.com/bep/golibsass/libsass/libsasserrors"
"github.com/gohugoio/hugo/common/paths"
@@ -153,8 +151,6 @@ func (e *fileError) causeString() string {
// Avoid repeating the file info in the error message.
case godartsass.SassError:
return v.Message
- case godartsassv1.SassError:
- return v.Message
case libsasserrors.Error:
return v.Message
default:
@@ -392,13 +388,6 @@ func extractPosition(e error) (pos text.Position) {
pos.Filename = filename
pos.Offset = start.Offset
pos.ColumnNumber = start.Column
- case godartsassv1.SassError:
- span := v.Span
- start := span.Start
- filename, _ := paths.UrlToFilename(span.Url)
- pos.Filename = filename
- pos.Offset = start.Offset
- pos.ColumnNumber = start.Column
case libsasserrors.Error:
pos.Filename = v.File
pos.LineNumber = v.Line
diff --git a/common/hugo/hugo.go b/common/hugo/hugo.go
index dd43cf7b6..11ec40e0b 100644
--- a/common/hugo/hugo.go
+++ b/common/hugo/hugo.go
@@ -25,9 +25,7 @@ import (
"sync"
"time"
- godartsassv1 "github.com/bep/godartsass"
"github.com/bep/logg"
- "github.com/mitchellh/mapstructure"
"github.com/bep/godartsass/v2"
"github.com/gohugoio/hugo/common/hcontext"
@@ -318,7 +316,7 @@ func GetDependencyListNonGo() []string {
if dartSass := dartSassVersion(); dartSass.ProtocolVersion != "" {
dartSassPath := "github.com/sass/dart-sass-embedded"
- if IsDartSassV2() {
+ if IsDartSassGeV2() {
dartSassPath = "github.com/sass/dart-sass"
}
deps = append(deps,
@@ -365,22 +363,15 @@ type Dependency struct {
}
func dartSassVersion() godartsass.DartSassVersion {
- if DartSassBinaryName == "" {
+ if DartSassBinaryName == "" || !IsDartSassGeV2() {
return godartsass.DartSassVersion{}
}
- if IsDartSassV2() {
- v, _ := godartsass.Version(DartSassBinaryName)
- return v
- }
-
- v, _ := godartsassv1.Version(DartSassBinaryName)
- var vv godartsass.DartSassVersion
- mapstructure.WeakDecode(v, &vv)
- return vv
+ v, _ := godartsass.Version(DartSassBinaryName)
+ return v
}
// DartSassBinaryName is the name of the Dart Sass binary to use.
-// TODO(beop) find a better place for this.
+// TODO(bep) find a better place for this.
var DartSassBinaryName string
func init() {
@@ -405,7 +396,10 @@ var (
dartSassBinaryNamesV2 = []string{"dart-sass", "sass"}
)
-func IsDartSassV2() bool {
+// TODO(bep) we eventually want to remove this, but keep it for a while to throw an informative error.
+// We stopped supporting the old binary in Hugo 0.139.0.
+func IsDartSassGeV2() bool {
+ // dart-sass-embedded was the first version of the embedded Dart Sass before it was moved into the main project.
return !strings.Contains(DartSassBinaryName, "embedded")
}
diff --git a/go.mod b/go.mod
index dcf1926f6..c19e8da34 100644
--- a/go.mod
+++ b/go.mod
@@ -10,7 +10,6 @@ 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 v1.2.0
github.com/bep/godartsass/v2 v2.2.0
github.com/bep/golibsass v1.2.0
github.com/bep/gowebp v0.3.0
diff --git a/go.sum b/go.sum
index 4a61c396a..0ba28ce4d 100644
--- a/go.sum
+++ b/go.sum
@@ -129,8 +129,6 @@ github.com/bep/gitmap v1.6.0 h1:sDuQMm9HoTL0LtlrfxjbjgAg2wHQd4nkMup2FInYzhA=
github.com/bep/gitmap v1.6.0/go.mod h1:n+3W1f/rot2hynsqEGxGMErPRgT41n9CkGuzPvz9cIw=
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 v1.2.0 h1:E2VvQrxAHAFwbjyOIExAMmogTItSKodoKuijNrGm5yU=
-github.com/bep/godartsass v1.2.0/go.mod h1:6LvK9RftsXMxGfsA0LDV12AGc4Jylnu6NgHL+Q5/pE8=
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/golibsass v1.2.0 h1:nyZUkKP/0psr8nT6GR2cnmt99xS93Ji82ZD9AgOK6VI=
@@ -163,7 +161,6 @@ github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5P
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/clbanning/mxj/v2 v2.7.0 h1:WA/La7UGCanFe5NpHF0Q3DNtnCsVoxbPKuyBNHWRyME=
github.com/clbanning/mxj/v2 v2.7.0/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s=
-github.com/cli/safeexec v1.0.0/go.mod h1:Z/D4tTN8Vs5gXYHDCbaM1S/anmEDnJb1iW0+EJ5zx3Q=
github.com/cli/safeexec v1.0.1 h1:e/C79PbXF4yYTN/wauC4tviMxEV13BwljGj0N9j+N00=
github.com/cli/safeexec v1.0.1/go.mod h1:Z/D4tTN8Vs5gXYHDCbaM1S/anmEDnJb1iW0+EJ5zx3Q=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
@@ -200,7 +197,6 @@ github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHqu
github.com/frankban/quicktest v1.4.1/go.mod h1:36zfPVQyHxymz4cH7wlDmVwDrJuljRB60qkgn7rorfQ=
github.com/frankban/quicktest v1.7.2/go.mod h1:jaStnuzAqU1AJdCO0l53JDCJrVDKcS03DbaAcR7Ks/o=
github.com/frankban/quicktest v1.13.0/go.mod h1:qLE0fzW0VuyUAJgPU19zByoIr0HtCHN/r/VLSOOIySU=
-github.com/frankban/quicktest v1.14.2/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M=
@@ -287,7 +283,6 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
-github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
@@ -358,7 +353,6 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
-github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
@@ -417,7 +411,6 @@ github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4
github.com/prashantv/gostub v1.1.0/go.mod h1:A5zLQHz7ieHGG7is6LLXLz7I8+3LZzsrV0P1IAHhP5U=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
-github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
diff --git a/resources/resource_transformers/tocss/dartsass/client.go b/resources/resource_transformers/tocss/dartsass/client.go
index e6f5567e4..b42327621 100644
--- a/resources/resource_transformers/tocss/dartsass/client.go
+++ b/resources/resource_transformers/tocss/dartsass/client.go
@@ -20,7 +20,6 @@ import (
"io"
"strings"
- godartsassv1 "github.com/bep/godartsass"
"github.com/bep/godartsass/v2"
"github.com/bep/logg"
"github.com/gohugoio/hugo/common/herrors"
@@ -52,54 +51,39 @@ func New(fs *filesystems.SourceFilesystem, rs *resources.Spec) (*Client, error)
return nil, fmt.Errorf("no Dart Sass binary found in $PATH")
}
+ if !hugo.IsDartSassGeV2() {
+ return nil, fmt.Errorf("unsupported Dart Sass version detected, please upgrade to Dart Sass 2.0 or later, see https://gohugo.io/functions/css/sass/#dart-sass")
+ }
+
if err := rs.ExecHelper.Sec().CheckAllowedExec(hugo.DartSassBinaryName); err != nil {
return nil, err
}
var (
- transpiler *godartsass.Transpiler
- transpilerv1 *godartsassv1.Transpiler
- err error
- infol = rs.Logger.InfoCommand("Dart Sass")
- warnl = rs.Logger.WarnCommand("Dart Sass")
+ transpiler *godartsass.Transpiler
+ err error
+ infol = rs.Logger.InfoCommand("Dart Sass")
+ warnl = rs.Logger.WarnCommand("Dart Sass")
)
- if hugo.IsDartSassV2() {
- transpiler, err = godartsass.Start(godartsass.Options{
- DartSassEmbeddedFilename: hugo.DartSassBinaryName,
- LogEventHandler: func(event godartsass.LogEvent) {
- message := strings.ReplaceAll(event.Message, dartSassStdinPrefix, "")
- switch event.Type {
- case godartsass.LogEventTypeDebug:
- // Log as Info for now, we may adjust this if it gets too chatty.
- infol.Log(logg.String(message))
- default:
- // The rest are either deprecations or @warn statements.
- warnl.Log(logg.String(message))
- }
- },
- })
- } else {
- transpilerv1, err = godartsassv1.Start(godartsassv1.Options{
- DartSassEmbeddedFilename: hugo.DartSassBinaryName,
- LogEventHandler: func(event godartsassv1.LogEvent) {
- message := strings.ReplaceAll(event.Message, dartSassStdinPrefix, "")
- switch event.Type {
- case godartsassv1.LogEventTypeDebug:
- // Log as Info for now, we may adjust this if it gets too chatty.
- infol.Log(logg.String(message))
- default:
- // The rest are either deprecations or @warn statements.
- warnl.Log(logg.String(message))
- }
- },
- })
- }
-
+ transpiler, err = godartsass.Start(godartsass.Options{
+ DartSassEmbeddedFilename: hugo.DartSassBinaryName,
+ LogEventHandler: func(event godartsass.LogEvent) {
+ message := strings.ReplaceAll(event.Message, dartSassStdinPrefix, "")
+ switch event.Type {
+ case godartsass.LogEventTypeDebug:
+ // Log as Info for now, we may adjust this if it gets too chatty.
+ infol.Log(logg.String(message))
+ default:
+ // The rest are either deprecations or @warn statements.
+ warnl.Log(logg.String(message))
+ }
+ },
+ })
if err != nil {
return nil, err
}
- return &Client{sfs: fs, workFs: rs.BaseFs.Work, rs: rs, transpiler: transpiler, transpilerV1: transpilerv1}, nil
+ return &Client{sfs: fs, workFs: rs.BaseFs.Work, rs: rs, transpiler: transpiler}, nil
}
type Client struct {
@@ -108,9 +92,7 @@ type Client struct {
sfs *filesystems.SourceFilesystem
workFs afero.Fs
- // One of these are non-nil.
- transpiler *godartsass.Transpiler
- transpilerV1 *godartsassv1.Transpiler
+ transpiler *godartsass.Transpiler
}
func (c *Client) ToCSS(res resources.ResourceTransformer, args map[string]any) (resource.Resource, error) {
@@ -121,13 +103,7 @@ func (c *Client) ToCSS(res resources.ResourceTransformer, args map[string]any) (
}
func (c *Client) Close() error {
- if c.transpilerV1 != nil {
- return c.transpilerV1.Close()
- }
- if c.transpiler != nil {
- return c.transpiler.Close()
- }
- return nil
+ return c.transpiler.Close()
}
func (c *Client) toCSS(args godartsass.Args, src io.Reader) (godartsass.Result, error) {
@@ -135,26 +111,7 @@ func (c *Client) toCSS(args godartsass.Args, src io.Reader) (godartsass.Result,
args.Source = in
- var (
- err error
- res godartsass.Result
- )
-
- if c.transpilerV1 != nil {
- var resv1 godartsassv1.Result
- var argsv1 godartsassv1.Args
- mapstructure.Decode(args, &argsv1)
- if args.ImportResolver != nil {
- argsv1.ImportResolver = importResolverV1{args.ImportResolver}
- }
- resv1, err = c.transpilerV1.Execute(argsv1)
- if err == nil {
- mapstructure.Decode(resv1, &res)
- }
- } else {
- res, err = c.transpiler.Execute(args)
- }
-
+ res, err := c.transpiler.Execute(args)
if err != nil {
if err.Error() == "unexpected EOF" {
//lint:ignore ST1005 end user message.
diff --git a/resources/resource_transformers/tocss/dartsass/transform.go b/resources/resource_transformers/tocss/dartsass/transform.go
index d8b6ae5b4..e23ef0986 100644
--- a/resources/resource_transformers/tocss/dartsass/transform.go
+++ b/resources/resource_transformers/tocss/dartsass/transform.go
@@ -35,7 +35,6 @@ import (
"github.com/gohugoio/hugo/hugofs"
- godartsassv1 "github.com/bep/godartsass"
"github.com/bep/godartsass/v2"
)
@@ -206,12 +205,3 @@ func (t importResolver) Load(url string) (godartsass.Import, error) {
return godartsass.Import{Content: string(b), SourceSyntax: sourceSyntax}, err
}
-
-type importResolverV1 struct {
- godartsass.ImportResolver
-}
-
-func (t importResolverV1) Load(url string) (godartsassv1.Import, error) {
- res, err := t.ImportResolver.Load(url)
- return godartsassv1.Import{Content: res.Content, SourceSyntax: godartsassv1.SourceSyntax(res.SourceSyntax)}, err
-}