CompilerResults

Swift
public struct CompilerResults: Sendable

The output from a successful compilation.


Topics

var css: String

The CSS produced by the Sass compiler.

Declaration
Swift
public let css: String

var sourceMap: String?

The JSON sourcemap for css, style according to the SourceMapStyle provided at compile time.

Declaration
Swift
public let sourceMap: String?

var messages: [CompilerMessage]

Any compiler warnings and debug statements.

Declaration
Swift
public let messages: [CompilerMessage]

var loadedURLs: [URL]

The canonical URLs of all source files used to produce css.

This includes the URL of the initial Sass file if it is known.

Declaration
Swift
public let loadedURLs: [URL]

Source Map URL Control

enum URLStyle

How to reference source map resources from CSS.

There are two references here: the CSS pointing at the source map, and the source map pointing at the original sources. The Sass compiler uses absolute (typically file:) URLs for original sources. This can be modified and the CSS -> source map reference added using CompilerResults.withFileLocations(...).

If you plan to ship the source map (so it is accessed through http: URLs by a browser) then you need to use one of the .relative options to avoid file: URLs that won’t make sense to clients.

Declaration
Swift
public enum URLStyle

func withFileLocations(cssFileURL: URL, sourceMapFileURL: URL, style: URLStyle) -> CompilerResults

Add filenames to the CSS and its source map.

The CSS and source map come out of the Sass compiler without references to each other. Sources are referenced from the source map using absolute URLs. This routine updates various metadata to make the source map load correctly in a browser.

This routine does not write any files.

Declaration
Swift
public func withFileLocations(
    cssFileURL: URL, sourceMapFileURL: URL, style: URLStyle = .relative
) throws -> CompilerResults
Parameters
cssFileURL

The file URL for the CSS. This is used to update the source map with the name of the file it’s describing and, if style requires it, calculation of relative paths.

sourceMapFileURL

The file URL for the source map. This is used to generate the sourceMappingURL comment in the CSS.

style

How to reference the source map from the CSS and the sources from the source map. See URLStyle; the default is .relative.

Throws

If the CompilerResults does not have a source map, or if JSON encoding/ decoding goes wrong.

Return Value

A new CompilerResults with updated css and sourceMap fields. The messages and loadedURLs fields are copied over unchanged.