-
Notifications
You must be signed in to change notification settings - Fork 465
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
Add importer registry to have multiple custom importers #962
Comments
@xzyfer also mentioned this for node-sass on Gitter chat. In JavaScript, the end-user can either use promises (such as async#waterfall: https://www.npmjs.com/package/async#waterfall, example usage: Bartinger/grunt-github-release-asset/github_release_asset.js#L42) or just a if/else, switch/case state machine to call appropriate function (to read data from database, web-service, file-systems etc.). For this, IMO, there is no need for API support and offloading the implementation design choice to final implementer would make sense: one generic entry point would suffice. I may be missing the point. Please correct me if there is a use-case which cannot be handled without multiple importers. |
The benefit if we provide our own implementation is mostly toward c++/c plugins (which can also be used by node-sass or any other libsass consumer btw). IMO it makes sense to have one API for this, since otherwise plugins may not be interoperable. But from an implementation standpoint, this functionality could be offloaded to a plugin, which in turn would handle the loading and calling of other plugins (they would only interact with the first plugin and not with libsass directly). IMO it makes more sense to bake this directly into libsass, since this layer of abstraction would not give much benefit. The current implementation would basically work the same, just adding one function that would signal it wants to handle every import it is given (and having the highest priority). The idea is that you could create a |
Does this mean libsass will define the types of custom importer? For instance:
Q2: Would we be able to pipe the output of one importer to the input of another, with some kind of a precedence order? Calling multiple importers for same |
Each importer will first be asked if it is able to handle a certain url we encounter in imports (like |
@mgreter, thank you for the explanation! 👍 |
The |
Merged #1000, which contains a first experimental implementation! |
👍 ⚡ 🎉 I will start implementing it later this week (in the middle of moving), unless, of course someone else wants to give it a go! 😃 //cc @matryo 😸 |
Currently we only support one custom importer, that has the job to "convert" import urls to import-data (basically loading the content). To support multiple importers, each importer should have a function to determine if it wants and can handle a given import url. This way we could have multiple importers loaded, one for http traffic, another for ftp etc.
Idea
canHandle
function (plus optional priority)canHandle
the import urlcanHandle
the url and repeat until first "valid" resultSome open questions
Expose more stuff for importers (#984)
ctx
and use option API?)This is open for discussion and more ideas!
The text was updated successfully, but these errors were encountered: