-
Notifications
You must be signed in to change notification settings - Fork 357
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
Dart API: Support custom importers #172
Comments
I'd like to support this by providing an importer interface similar to the one supported by Ruby Sass and node-sass. An importer is effectively just a function that maps URLs to Sass strings, although in practice the existing importer APIs are more complex than that, so we'd need to do some design to figure out what's right for our use-case. |
One thing that's important to consider for this API is the issue of canonicalization. Right now, Dart Sass uses a map with resolved Ideally, any imports which point to some intuitive notion of "the same place" will share a module. Cases to consider include:
One option I considered was to add a method to We also want to require that a given canonical URL always loads the same stylesheet, even across importers. This is a difficult guarantee to enforce with heterogeneous importers that may be written without knowledge of one another. It's possible we should rethink the structure entirely: rather than following Ruby Sass's example of having a single That might most directly represent the underlying semantics, but it also adds a lot of complexity. What's worse, the complexity won't be contained to the importer implementations; it'll bubble up to the configuration layer as well. I suspect it's not worth the pain. I would like to find a way to enforce the canonicalization requirement, but if possible I'd like to do it within a given importer. |
After thinking about this more, I think I've come up with a decent API:
|
@nex3 thanks, waiting for this new api! |
@nex3 I’ve encountered a problem. BuildStep api is asynchronous only, but Importer api is synchronious. It’s seems impossible to implement this interface with build api. Any ideas and workarounds? https://www.dartdocs.org/documentation/build/0.10.2+1/build/AssetReader/readAsString.html |
That's a really tough issue. Dart Sass is written synchronously, and Dart doesn't provide any means of calling async callbacks in a synchronous context, or of writing code that's polymorphic over asynchrony. I think this is ultimately something that will need to be solved as the language or VM level. |
I've filed dart-lang/sdk#31102 to track Dart support for some sort of synchronization primitive, if you want to 👍 it. |
@nex3 Thanks, I will track this issue |
In Dart ecosystem there are 2 primary build systems:
As in the docs,
It should be noted that you should never touch the file system directly. Go through the buildStep#readAsString and buildStep#writeAsString methods in order to read and write assets.
. The main thing here is that build system creates graph of assets dependencies for incremental compilation and that's why directly using of file system is prohibited.What I suggest is to add file system abstraction layer so there will be different implementation for direct file system access and access of assets in build system steps. This can be interface in sass package itself, or, better, you can use https://pub.dartlang.org/packages/file and accept
FileSystem
instance incompile
method and useLocalFileSystem
as default. This also eliminates need forcompileString
function because if someone needs to compile sass from source in memoryMemoryFileSystem
can be used for this.If you don't have time for implementing this yourself just guide me in right direction and I will do this. This is very important for me because lack of this abstraction do not allow me to use this package in any of dart projects in my company. If abstraction will be introduced, I will publish packages like
sass_build
andsass_backback
that can be used to directly embed sass in dart build systems.The text was updated successfully, but these errors were encountered: