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, context: ImporterContext) async -> URL?

Resolve an imported URL to a filesystem location.

Declaration
Swift
func resolve(ruleURL: String, context: ImporterContext) async throws -> URL?
Parameters
ruleURL

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

context

Some details about the import to help resolve it. You are free to ignore the fromImport field here: 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.

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.