Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dartsass: Fix nilpointer on Close when Dart Sass isn't installed #13077

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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