FilesystemImporter

Swift
public protocol FilesystemImporter: Sendable

Methods required to implement a filesystem-redirecting stylesheet importer.

Use this to map imports to a filesystem location, letting the Sass compiler deal with index directories, file extensions, and actually loading the stylesheet.


Topics

func resolve(ruleURL: String, fromImport: Bool, containingURL: URL?) async -> URL?

Resolve an imported URL to a filesystem location.

Declaration
Swift
func resolve(ruleURL: String, fromImport: Bool, containingURL: URL?)
    async throws -> URL?
Parameters
ruleURL

The text following @import or @use in a stylesheet.

fromImport

Whether this request comes from an @import rule. See import-only files. You are free to ignore this flag: the Sass compiler understands it and will choose an import-only file when appropriate. For example, if your custom directory contains test.scss and test.import.scss then you can return file://your/custom/path/test and the compiler will pull in the right file.

containingURL

The canonical URL of the source file that contains the load being resolved. Can be nil if the source file does not have a canonical URL.

Throws

Only when ruleURL cannot be resolved: it is definitely this importer’s responsibility to do so, but it can’t.

Compilation will stop, quoting the description of the error thrown as the reason.

Return Value

A file: URL for the compiler to access, or nil if the importer doesn’t recognize the import request: the compiler will try the next importer.