{"id":16682278,"url":"https://github.com/johnfairh/swift-sass","last_synced_at":"2026-03-11T06:31:11.016Z","repository":{"id":41972918,"uuid":"311617890","full_name":"johnfairh/swift-sass","owner":"johnfairh","description":"Embed the Dart Sass compiler in Swift with custom importers and functions","archived":false,"fork":false,"pushed_at":"2026-01-15T11:13:18.000Z","size":228539,"stargazers_count":20,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2026-01-15T15:50:37.424Z","etag":null,"topics":["dart","embedded","linux","macos","nio","sass","scss","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/johnfairh.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-11-10T10:06:36.000Z","updated_at":"2026-01-15T11:12:45.000Z","dependencies_parsed_at":"2025-04-09T23:22:20.260Z","dependency_job_id":null,"html_url":"https://github.com/johnfairh/swift-sass","commit_stats":{"total_commits":172,"total_committers":1,"mean_commits":172.0,"dds":0.0,"last_synced_commit":"dafa8d193cee6bafb24a87815667f8ba2ac90ef3"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"purl":"pkg:github/johnfairh/swift-sass","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnfairh%2Fswift-sass","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnfairh%2Fswift-sass/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnfairh%2Fswift-sass/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnfairh%2Fswift-sass/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/johnfairh","download_url":"https://codeload.github.com/johnfairh/swift-sass/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnfairh%2Fswift-sass/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30373440,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-11T06:09:32.197Z","status":"ssl_error","status_checked_at":"2026-03-11T06:09:17.086Z","response_time":84,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dart","embedded","linux","macos","nio","sass","scss","swift"],"created_at":"2024-10-12T14:06:54.667Z","updated_at":"2026-03-11T06:31:10.933Z","avatar_url":"https://github.com/johnfairh.png","language":"Swift","funding_links":[],"categories":["Swift"],"sub_categories":[],"readme":"\u003c!--\nswift-sass\nREADME.md\nDistributed under the MIT license, see LICENSE.\n--\u003e\n\n![Platforms](https://img.shields.io/badge/platform-macOS%20%7C%20linux-lightgrey.svg)\n[![codecov](https://codecov.io/gh/johnfairh/swift-sass/branch/main/graph/badge.svg?token=0NAP6IA9EB)](https://codecov.io/gh/johnfairh/swift-sass)\n![Tests](https://github.com/johnfairh/swift-sass/workflows/Tests/badge.svg)\n![Sass](https://img.shields.io/badge/sass-1.83.4-purple)\n\n# Swift Sass\n\nEmbed the Dart [Sass](https://sass-lang.com) compiler in your Swift program.  Write\nstylesheet importers and SassScript functions in Swift.\n\nThis package provides a Swift language interface to a separate Sass\nimplementation.  The `DartSass` module lets you access\n[Dart Sass](https://sass-lang.com/dart-sass),\nthe most up to date implementation of the Sass language.  It runs the\n[Dart Sass compiler](https://github.com/sass/dart-sass) as a separate process\nand communicates with it using the\n[Sass embedded protocol](https://github.com/sass/sass/blob/main/spec/embedded-protocol.md).  If you\ncome across another implementation of the 'compiler' side of the protocol then\nthat should work fine too.\n\nThis package doesn't support LibSass right now.  [More info](#on-libsass).\n\n## Examples\n\nMinimally:\n```swift\nimport DartSass\n\nlet compiler = try Compiler()\n\nlet results = try await compiler.compile(fileURL: scssFileURL)\n\nprint(results.css)\n```\nAlthough the compiler output is more structured, if this is all you want to do\nthen you're probably better off running the binary directly.  The reason to use\nthis package is to provide custom implementations of `@use` rules to load\ncontent, and custom functions to provide application-specific behavior:\n```swift\n\nstruct ExtrasImporter: Importer {\n    func canonicalize(ruleURL: String, context: ImporterContext) async throws -\u003e URL? {\n      guard ruleURL == \"extras\" else {\n      return nil\n    }\n    return URL(string: \"custom://extras\")\n  }\n\n  func load(canonicalURL: URL) async throws -\u003e ImporterResults? {\n    ImporterResults(my_extras_stylesheet)\n  }\n}\n\nlet customFunctions: SassFunctionMap = [\n  \"userColorForScore($score)\" : { args in\n    let score = try args[0].asInt()\n    return SassColor(...)\n  }\n]\n\nlet results = try await compiler.compile(\n    fileURL: scssFileURL,\n    importers: [\n      .loadPath(sassIncludeDirectoryFileURL),\n      .importer(ExtrasImporter())\n    ],\n    functions: customFunctions\n)\n```\n\n```scss\n// stylesheet\n\n@use \"extras\";\n\n.score-mid {\n  color: userColorForScore(50);\n}\n```\n\n`DartSass` is built on [NIO](https://github.com/apple/swift-nio) but the user\ninterface is entirely Swift 5.5 async-await.\n\n## Documentation\n\n* [API documentation](https://johnfairh.github.io/swift-sass/)\n* Dash docset [feed](dash-feed://https%3A%2F%2Fjohnfairh%2Egithub%2Eio%2Fswift%2Dsass%2Fdocsets%2Fswift%2Dsass%2Exml) or [direct download](https://johnfairh.github.io/swift-sass/docsets/swift-sass.tgz)\n\n## Requirements\n\n* Swift 6.0\n* macOS 14+ (tested on macOS 14.x x64)\n* Linux (tested on Ubuntu latest x64)\n* Embedded Sass Protocol version 3.1.0\n\n## Installation\n\nOnly with Swift Package Manager, via Xcode or directly:\n\nPackage dependency:\n```swift\n.package(name: \"swift-sass\",\n         url: \"https://github.com/johnfairh/swift-sass.git\",\n         from: \"3.1.0\")\n```\n\nTarget dependency:\n```swift\n.product(name: \"DartSass\", package: \"swift-sass\"),\n```\n\nThe Swift package bundles the Dart Sass compiler for macOS and Linux\n(specifically Ubuntu Focal/20.04 64-bit) both x86_64 and arm64.  The correct\nbinary is selected at build time.  The selection is made based on the host\narchitecture though, so if you want to cross-compile you'll need to assemble\nthe results manually.\n\nFor other platforms you will need to either download the correct version from\n[the release page](https://github.com/sass/dart-sass/release) or build\nit manually, ship it as part of your program's distribution, and use\n[this initializer](https://johnfairh.github.io/swift-sass/sassembedded/types/compiler.html?swift#initeventloopgroupprovidertimeoutimportersfunctions).\n\nThere is no need to install a Dart runtime or SDK as part of this, the\n`dart-sass-embedded` program is standalone.  The version required is shown in\nthe [VERSION_DART_SASS](VERSION_DART_SASS) file.\n\n## On LibSass\n\n[LibSass](https://sass-lang.com/libsass) is the C++ implementation of Sass.\nIn recent years it has fallen behind the specification and reference\nimplementations, and was\n[deprecated in 2020](https://sass-lang.com/blog/libsass-is-deprecated).\nHowever, work is underway to revive the project and it may be that LibSass 4\nor [libsass-ng](https://github.com/mgreter/libsass-ng/) emerges as an\nalternative Sass implementation with the same level of language support as\nDart Sass.  As of summer 2024 this revival effort is showing signs of life but\nI'm still not holding my breath.\n\nSee the experimental [libsass4 branch](https://github.com/johnfairh/swift-sass/tree/libsass4)\nfor the current state of development: if LibSass itself manages to get to a\nrelease then this package will support it as an alternative integration.\n\n## Contributions\n\nWelcome: open an issue / johnfairh@gmail.com / @johnfairh@mastodon.social\n\n## License\n\nDistributed under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnfairh%2Fswift-sass","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohnfairh%2Fswift-sass","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnfairh%2Fswift-sass/lists"}