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

What do importPath and importBase in SassImport really mean? #12

Closed
saurabhnanda opened this issue Jul 18, 2018 · 2 comments
Closed

What do importPath and importBase in SassImport really mean? #12

saurabhnanda opened this issue Jul 18, 2018 · 2 comments

Comments

@saurabhnanda
Copy link

saurabhnanda commented Jul 18, 2018

I've spent a lot of time fiddling with compileFile and makePathImport and still don't understand what paths need to be passed where.

Sass.compileFile (stylesheetRoot </> "app.scss") sassOpts
  where
    sassOpts = Default.def
      { sassHeaders = Just
                      [ SassImporter
                        { importerPriority = 1.0
                        , importerFunction = (\_ -> pure $
                                                    [ makeSourceImport settingOverrides
                                                    , makePathImport (stylesheetRoot </> "settings") "."
                                                    , makePathImport (stylesheetRoot </> "zurb-foundation/foundation-emails")  "."
                                                    ])

                        }
                      ]
      }

The only way I have gotten this to work is if stylesheetRoot is set to the absolute path of the directory that contains all the stylesheets. However, I cannot explain the following behaviours:

  • if I set stylesheetRoot to the relative path containing all stylesheets (relative to current-working-directory of the Haskell process), Sass.compileFile is able to locate the file, BUT makePathImport is no longer able to locate the imports.
  • Further, if instead of passing "." as importBase to makePathPort, I pass absolute path of the folder containing stylesheets, it has no impact. makePathImport is still unable to locate the file.

How is this supposed to work and how are all these paths related to each other:

  • current working directory
  • paths relative to the file passed to compileFile
  • importPath
  • importBase
@jakubfijalkowski
Copy link
Owner

jakubfijalkowski commented Jul 18, 2018

You have found a bug in the bindings, thanks! :)

When I started making the bindings, I used sass/libsass@3672661 and there, sass_make_import (SassImport maps to a call to this function) required path and base, but current version relies on 3.5.2 (they changed the behavior around 3.3) and there the parameters are imp_path and abs_path which, as far as I can see, mean totally different things (imp_path is resolved based on basePath that you cannot specify using the C API as far as I can see, or paths that you can specify with sassIncludePaths). I must have missed the change during upgrade.

So, more or less, importPath and importBase are not what they pretend to be. This needs to be fixed. I will not be able to do this in near future (too many tasks...) so I would really appreciate a pull request with the fix (both to hlibsass and to hsass). :)

Plus, there is memory leak when creating importer AFAICS - the sass_make_import frees only source and source_map, imp_bath and abs_path are copied (but we don't free the CString on Haskell side).

@jakubfijalkowski
Copy link
Owner

I've finally had a time to work on this lib and I've fixed this bug - the SassImport reflects now how the sass_make_import (an imports overall) work, i.e. you can now specify either absolute path to file (that will be loaded by Libsass) or loaded source. It's still missing tests, but that needs to wait (at least on my side).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants