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

Ability to register custom mixins? #698

Open
kodie opened this issue Dec 29, 2023 · 3 comments
Open

Ability to register custom mixins? #698

kodie opened this issue Dec 29, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@kodie
Copy link

kodie commented Dec 29, 2023

The scssphp-glob function throws the following error:

The "scssphp-glob" function is deprecated an will be removed in ScssPhp 2.0. Register your own alternative through "Compiler::registerFunction

however this doesn't seem to be possible with registerFunction as that function is expected to return a value for a property.

I think what we actually need is a registerMixin function so that we could do something like this:

@include glob-import('../component/*/*.scss');

Unless I'm missing something?

@stof
Copy link
Member

stof commented Jan 13, 2024

scssphp-glob was not a mixin either. It's not usable with @include but with @import (however, thinking about that, returning a list of files to import for an expression instead of reporting a single one is probably also a non-standard feature).

Regarding the ability to register custom mixins, this is unlikely to happen. By definition, a mixin produces a side effect in the compilation. And I don't see how this could be done without access to the internal state of the compiler.
Looking at dart-sass, the only built-in module that contains some mixins (rather than only functions or immutable variables) is sass:meta which is (by design) a privileged module having access to the internals. dart-sass does not allow either registering custom mixins provided by the host. Their compiler API only allows custom functions (our own API allows registering custom variables, for which I will need to make sure we define a well-behaving semantic once we implement modules)

@stof stof added the enhancement New feature or request label Jan 15, 2024
@stof
Copy link
Member

stof commented Apr 5, 2024

I think the case of globs could be solved in 2.0 (not yet available, but you could try to prototype an equivalent logic in JS using dart-sass) thanks to a custom importer:

  • declare a custom importer supporting glob as a non-canonical scheme and absolute-glob as a canonical scheme
  • when canonicalizing a glob://../component/*/*.scss, turn it into an absolute-glob:// URL by resolving to an absolute path based on the containing URL
  • when loading absolute-glob:// URL, use the glob to find files (maybe throw an error if it does not find anything) and generate a content with @import '<file-uri>' for each file, where <file-uri> is the file://<absolute-path> URL (taking care of the actual full conversion of the absolute path, especially to support Windows paths)

@stof
Copy link
Member

stof commented Apr 5, 2024

To clarify my previous comment: such glob importer will definitely not be part of scssphp itself. But if this approach work (I haven't tested if my idea actually works), it will be something that can be shipped as a separate package.

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

No branches or pull requests

2 participants