wellington/go-libsass

Issue with IncludePaths

paroxp opened this issue · 4 comments

Hey!

I'm rewriting my Webpack/Gulp compiler in Go and I've run into an issue, when using the IncludePaths functionality of go-libsass.

What

My tree looks like this:

.
├── css
│   └── style.css
├── node_modules
│   └── bourbon
│   │   └── *
│   └── susy
│   │   └── sass
│   │   │   └── *.scss
├── scss
│   └── style.scss
│   └── _variables.scss
└── main.go

The main.go file, has the following code implemented:

		fi, err := os.Open("scss/style.scss")
		if err != nil {
			return err
		}
		defer fi.Close()

		fo, err := os.Create("css/style.css")
		if err != nil {
			return err
		}
		defer fo.Close()

		p := libsass.IncludePaths([]string{"scss", "node_modules/bourbon/app/assets/stylesheets", "node_modules/susy/sass"})
		s := libsass.OutputStyle(libsass.COMPRESSED_STYLE)

		comp, err := libsass.New(fo, fi, p, s)
		if err != nil {
			return err
		}

		if err := comp.Run(); err != nil { # This line fails on me.
			return err
		}

The style.scss file, is simple.

@import "variables";
@import "bourbon";
@import "susy";

And then, when I execute go run main.go, I get the following:

panic: Error > stdin:5
File to import not found or unreadable: variables
Parent style sheet: stdin
@import "variables";
@import "bourbon";
@import "susy";


goroutine 1 [running]:
main.main()
        main.go:85 +0xdb
exit status 2

Possibility

I suspect, that the go-libsass may have a problem, when (for example), susy will contain it's own variables file.

I'm probably configuring something wrong, in which case it would be nice to see some documentation on this :)

Any feedback on this would be great.

Thanks!

You need to tell libsass the absolute path to resolve include paths. You can check out these lines in the wellington project to see how I handle this: https://github.com/wellington/wellington/blob/master/wt/main.go#L217-L222

My guess is that go-libsass passes the relative paths onto libsass, but it has no code to expand these to absolute paths. os.Open works because go is expanding the relative lookup, but libsass doesn't know where to resolve these paths.

I setup a project like so:

main.go
scss/style.scss
scss/_variable.scss

go run main.go worked as expected in this case so I couldn't reproduce your problem. Like you said, it might be a good idea to remove the other imports to make sure this is the issue.

If this doesn't solve the problem, isolating this into a full repo case would be helpful.

Thanks for the response.

It doesn't appear to solve the problem though :(

So, I've included the code responsible for converting paths into the absolutes here and then using it in my main file.

If you were going to run these, be sure to run npm install as well :(

go run main.go config.go page.go utils.go

Thanks for including the code, it should be fixed in 70e55d4

Thanks!