Skip to content

Commit

Permalink
dartsass: Fix nilpointer on Close when Dart Sass isn't installed
Browse files Browse the repository at this point in the history
Fixes #13076
  • Loading branch information
bep committed Nov 21, 2024
1 parent 8fcd3c1 commit 8d017a6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ hello:
other: "Bonjour"
-- layouts/index.html --
{{ $options := dict "inlineImports" true }}
{{ $styles := resources.Get "css/styles.css" | resources.PostCSS $options }}
{{ $styles := resources.Get "css/styles.css" | css.PostCSS $options }}
Styles RelPermalink: {{ $styles.RelPermalink }}
{{ $cssContent := $styles.Content }}
Styles Content: Len: {{ len $styles.Content }}|
Expand Down
15 changes: 9 additions & 6 deletions resources/resource_transformers/tocss/dartsass/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const dartSassStdinPrefix = "hugostdin:"

func New(fs *filesystems.SourceFilesystem, rs *resources.Spec) (*Client, error) {
if !Supports() {
return &Client{dartSassNotAvailable: true}, nil
return &Client{}, nil
}

if hugo.DartSassBinaryName == "" {
Expand Down Expand Up @@ -89,22 +89,25 @@ func New(fs *filesystems.SourceFilesystem, rs *resources.Spec) (*Client, error)
}

type Client struct {
dartSassNotAvailable bool
rs *resources.Spec
sfs *filesystems.SourceFilesystem
workFs afero.Fs
rs *resources.Spec
sfs *filesystems.SourceFilesystem
workFs afero.Fs

// This may be nil if Dart Sass is not available.
transpiler *godartsass.Transpiler
}

func (c *Client) ToCSS(res resources.ResourceTransformer, args map[string]any) (resource.Resource, error) {
if c.dartSassNotAvailable {
if c.transpiler == nil {
return res.Transform(resources.NewFeatureNotAvailableTransformer(transformationName, args))
}
return res.Transform(&transform{c: c, optsm: args})
}

func (c *Client) Close() error {
if c.transpiler == nil {
return nil
}
return c.transpiler.Close()
}

Expand Down

0 comments on commit 8d017a6

Please sign in to comment.