-
Notifications
You must be signed in to change notification settings - Fork 464
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
[API proposal] Expose add_source() interface #1368
Comments
I'm a little confused. How is this different than custom importers? The biggest performance bottleneck I have experienced is having libsass do file I/O. I had started by reading the Sass files in the implementation, tokenizing/parsing the Sass for imports then sending the concatenated Sass to the data compiler. Switching to the file compiler increased compile time by nearly 50%. It would be nice to have some APIs that made doing file I/O in the implementation easier. I'm not sure how this adds benefits over what the custom importer already makes available though. |
Thank you for this question @drewwells ! I think this actually touches the gist of this issue. Custom importers work in a Custom importers work this way: libsass processes the file and when it encounters In the new way (which does not remove the possibility to have custom importers as we have now, of course)
After
and then it is possible to do, hopefully without re-parsing everything:
Actually I think the custom importers we have now have been shaped after the Ruby implementation, where the Sass engine does not have a knowledge of files really but it invokes supplied importer (see documentation for Sass::Importers). File system import is just the default importer which can be replaced by another backend, for example database. Because of the nature of C, it seemed easier to provide a built-in file interface, that complicated the API a bit. (I have renamed |
I don't really see a benefit to have a prefilled "virtual filesystem". First thing is that I think that mostly anyone doesn't know beforehand which files are needed, so a on demand loading seems natural after all. Caching of compiled files could also be implemented easily with the existing interface (if wanted at some point, but I think could be something once we have a much more stable and clean code-base). Any objections to close this one? |
I'm not quite sure I see the benefit of this push method. Like @mgreter said, it's difficult to know which files will be necessary. However, what caching mechanism are you referring to? Is this referring to a custom importer that matches all strings? For instance, A.scss --depends on--> a.scss libSass is called twice here, so it opens a.scss twice rather than using a caching mechanism. I used to parse |
The point would be to not call a custom importer for the same file twice, even between different compiles and effectively re-use the already parsed AST tree. This would probably need some kind of check mechanism to see if the source can be served from cache or not. And as I said, this is IMO currently too far away to even consider it. But who knows where this all will lead ... |
Well that does sound far off, since variables could be different depending on what global variables a file needs. Unless those are resolved after AST tree is parsed. For my use case, it would have been sufficient to allow source notations to control which file/line number is resolved by libSass. The same thing that Chrome does with CSS/JS source which sounds less complex than reusing AST tree between compiles. ie.
Output
Then source could be added however you want while preserving sourcemaps and error file/line numbers. |
The parsed AST tree has a |
This is exactly what @mgreter means, thank you. I proposed to expose this for two reasons: to let libsass avoid any I/O operations (which breaks node-sass in some cases) and because this function was already there available (it is removed now as far as I can see). |
I created a collective ticket to keep track this and other "non-urgent" feature requests, in order to keep the issue tracker a bit more clean for the more 1st aid issues. I would like to encourage everybody interested in this particular feature to add their comments into this closed issue anyway. Thanks for your understanding and your contribution! |
I think it would be pretty good to expose some form of
add_source()
interface via C-API.How it would work:
In general libsass core could stop dealing with input files at all (only for compatibility and/or convenience) and just use import identifiers namespace.
It should be possible to replace imported sources on demand. Real custom importer functions could be called on demand.
I could also imagine
add_source
to be called in asynchronous callbacks after the file is loaded.add_source()
could trigger parsing of the supplied text as well.The text was updated successfully, but these errors were encountered: