Update to LibSass v3.6.3

Fixes #6862
This commit is contained in:
Bjørn Erik Pedersen
2020-02-08 19:57:23 +01:00
parent 4f43c9022a
commit 40ba7e6d63
7 changed files with 111 additions and 117 deletions

View File

@@ -14,17 +14,16 @@
package scss
import (
"github.com/bep/go-tocss/scss"
"github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/hugolib/filesystems"
"github.com/gohugoio/hugo/resources"
"github.com/gohugoio/hugo/resources/internal"
"github.com/gohugoio/hugo/resources/resource"
"github.com/spf13/afero"
"github.com/mitchellh/mapstructure"
)
const transformationName = "tocss"
type Client struct {
rs *resources.Spec
sfs *filesystems.SourceFilesystem
@@ -61,41 +60,6 @@ type Options struct {
EnableSourceMap bool
}
type options struct {
// The options we receive from the end user.
from Options
// The options we send to the SCSS library.
to scss.Options
}
func (c *Client) ToCSS(res resources.ResourceTransformer, opts Options) (resource.Resource, error) {
internalOptions := options{
from: opts,
}
// Transfer values from client.
internalOptions.to.Precision = opts.Precision
internalOptions.to.OutputStyle = scss.OutputStyleFromString(opts.OutputStyle)
if internalOptions.to.Precision == 0 {
// bootstrap-sass requires 8 digits precision. The libsass default is 5.
// https://github.com/twbs/bootstrap-sass/blob/master/README.md#sass-number-precision
internalOptions.to.Precision = 8
}
return res.Transform(&toCSSTransformation{c: c, options: internalOptions})
}
type toCSSTransformation struct {
c *Client
options options
}
func (t *toCSSTransformation) Key() internal.ResourceTransformationKey {
return internal.NewResourceTransformationKey("tocss", t.options.from)
}
func DecodeOptions(m map[string]interface{}) (opts Options, err error) {
if m == nil {
return

View File

@@ -0,0 +1,58 @@
// Copyright 2018 The Hugo Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// +build extended
package scss
import (
"github.com/bep/golibsass/libsass"
"github.com/gohugoio/hugo/resources"
"github.com/gohugoio/hugo/resources/internal"
"github.com/gohugoio/hugo/resources/resource"
)
type options struct {
// The options we receive from the end user.
from Options
// The options we send to the SCSS library.
to libsass.Options
}
func (c *Client) ToCSS(res resources.ResourceTransformer, opts Options) (resource.Resource, error) {
internalOptions := options{
from: opts,
}
// Transfer values from client.
internalOptions.to.Precision = opts.Precision
internalOptions.to.OutputStyle = libsass.ParseOutputStyle(opts.OutputStyle)
if internalOptions.to.Precision == 0 {
// bootstrap-sass requires 8 digits precision. The libsass default is 5.
// https://github.com/twbs/bootstrap-sass/blob/master/README.md#sass-number-precision
internalOptions.to.Precision = 8
}
return res.Transform(&toCSSTransformation{c: c, options: internalOptions})
}
type toCSSTransformation struct {
c *Client
options options
}
func (t *toCSSTransformation) Key() internal.ResourceTransformationKey {
return internal.NewResourceTransformationKey(transformationName, t.options.from)
}

View File

@@ -1,4 +1,4 @@
// Copyright 2018 The Hugo Authors. All rights reserved.
// Copyright 2020 The Hugo Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -16,15 +16,15 @@
package scss
import (
"github.com/gohugoio/hugo/common/herrors"
"github.com/gohugoio/hugo/resources"
"github.com/gohugoio/hugo/resources/resource"
)
func (c *Client) ToCSS(res resources.ResourceTransformer, opts Options) (resource.Resource, error) {
return res.Transform(resources.NewFeatureNotAvailableTransformer(transformationName, opts))
}
// Used in tests.
func Supports() bool {
return false
}
func (t *toCSSTransformation) Transform(ctx *resources.ResourceTransformationCtx) error {
return herrors.ErrFeatureNotAvailable
}

View File

@@ -22,9 +22,7 @@ import (
"path/filepath"
"strings"
"github.com/bep/go-tocss/scss"
"github.com/bep/go-tocss/scss/libsass"
"github.com/bep/go-tocss/tocss"
"github.com/bep/golibsass/libsass"
"github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/hugofs"
"github.com/gohugoio/hugo/media"
@@ -67,6 +65,7 @@ func (t *toCSSTransformation) Transform(ctx *resources.ResourceTransformationCtx
// We add the entry directories for both project and themes to the include paths list, but
// that only work for overrides on the top level.
options.to.ImportResolver = func(url string, prev string) (newUrl string, body string, resolved bool) {
// We get URL paths from LibSASS, but we need file paths.
url = filepath.FromSlash(url)
prev = filepath.FromSlash(prev)
@@ -74,6 +73,7 @@ func (t *toCSSTransformation) Transform(ctx *resources.ResourceTransformationCtx
var basePath string
urlDir := filepath.Dir(url)
var prevDir string
if prev == "stdin" {
prevDir = baseDir
} else {
@@ -121,18 +121,18 @@ func (t *toCSSTransformation) Transform(ctx *resources.ResourceTransformationCtx
if options.from.EnableSourceMap {
options.to.SourceMapFilename = outName + ".map"
options.to.SourceMapRoot = t.c.rs.WorkingDir
options.to.SourceMapOptions.Filename = outName + ".map"
options.to.SourceMapOptions.Root = t.c.rs.WorkingDir
// Setting this to the relative input filename will get the source map
// more correct for the main entry path (main.scss typically), but
// it will mess up the import mappings. As a workaround, we do a replacement
// in the source map itself (see below).
//options.InputPath = inputPath
options.to.OutputPath = outName
options.to.SourceMapContents = true
options.to.OmitSourceMapURL = false
options.to.EnableEmbeddedSourceMap = false
options.to.SourceMapOptions.OutputPath = outName
options.to.SourceMapOptions.Contents = true
options.to.SourceMapOptions.OmitURL = false
options.to.SourceMapOptions.EnableEmbedded = false
}
res, err := t.c.toCSS(options.to, ctx.To, ctx.From)
@@ -161,18 +161,21 @@ func (t *toCSSTransformation) Transform(ctx *resources.ResourceTransformationCtx
return nil
}
func (c *Client) toCSS(options scss.Options, dst io.Writer, src io.Reader) (tocss.Result, error) {
var res tocss.Result
func (c *Client) toCSS(options libsass.Options, dst io.Writer, src io.Reader) (libsass.Result, error) {
var res libsass.Result
transpiler, err := libsass.New(options)
if err != nil {
return res, err
}
res, err = transpiler.Execute(dst, src)
in := helpers.ReaderToString(src)
res, err = transpiler.Execute(in)
if err != nil {
return res, errors.Wrap(err, "SCSS processing failed")
}
return res, nil
_, err = io.WriteString(dst, res.CSS)
return res, err
}