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

Docs: Precise Resolution of Ambiguous Imports #445

Closed
bdkjones opened this issue Apr 15, 2020 · 3 comments
Closed

Docs: Precise Resolution of Ambiguous Imports #445

bdkjones opened this issue Apr 15, 2020 · 3 comments

Comments

@bdkjones
Copy link

bdkjones commented Apr 15, 2020

I'm trying to find out how, exactly, Dart Sass resolves ambiguous imports. I've looked through the source, but I can't really extract the exact search order.

I've seen this from Libsass: https://github.com/sass/libsass/blob/951500818a7820783a991313cdbe5862a57e2d51/src/file.cpp#L329

But that does not indicate where CSS files fit into the process. The Dart Sass docs for @use say that the compiler will import CSS files as a last resort.

Given a base file that has this:

// Base File named "something.scss" in /someFolder
@use 'foo';

What is the precise order Dart Sass uses to resolve this? My best guess is:

  1. /someFolder/foo
  2. /someFolder/_foo
  3. /someFolder/foo.scss Extension matching base file's ext.
  4. /someFolder/_foo.scss
  5. /someFolder/foo.sass
  6. /someFolder/_foo.sass
  7. /someFolder/foo/_index.scss Extension matching base file's ext.
  8. /someFolder/foo/_index.sass
  9. /someFolder/foo.css
  10. /someFolder/_foo.css
  11. Repeat the process for every load-path until something matches.

Is this correct? The entries in (3) and (7) use the base file's extension first and the alternate syntax extension as the next attempt.

The reason the exact order matters to me is that I need to build a dependency graph between files so I know which ones to re-compile when imported files change.

@bdkjones
Copy link
Author

I've been able to determine that Dart Sass does not resolve (1) or (2). A file must have an extension for Dart Sass or the compiler won't resolve to it.

Libsass, however, does.

I think this might be because there is not, as far as I know, a spec that definitively outlines the exact resolution process to follow. Would it be possible to get that? Once it's available, we could probably get Libsass and Dart Sass standardized on the same set of rules.

@stof
Copy link
Contributor

stof commented Mar 17, 2021

the official resolution algorithm is specified in the language spec. See https://github.com/sass/sass/blob/master/spec/modules.md#resolving-a-file-url

Dart Sass implements that algorithm.

@nex3
Copy link
Contributor

nex3 commented Mar 17, 2021

@stof is right; the spec is the place for highly specific technical descriptions of the language's behavior.

@nex3 nex3 closed this as completed Mar 17, 2021
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

3 participants