wellington / go-libsass

Go wrapper for libsass, the only Sass 3.5 compiler for Go
http://godoc.org/github.com/wellington/go-libsass
Apache License 2.0
206 stars 28 forks source link

Add option to pass abs path of the previous module to a resolver #82

Closed Adjective-Object closed 2 years ago

Adjective-Object commented 2 years ago

Hey, I implemented this for a project I'm working on and figured I'd PR it back in in case others could find it useful.

Context

I'm reimplementing a node-sass style resolution algorithm, where a sass file may specify the file it wants to import with a ~-prefixed node specifier. This resolves against the node_modules folders in the file tree.

However, if there are multiple versions of a library within a project, different imports of the same URL should resolve to different files on disc with different contents, so the resolver needs to know the path of the importer, not just the URL.

For example:

node_modules/
├─ common-lib/
│  └─ util.scss
├─ component/
│  ├─ node_modules/
│  │  └─ common-lib/
│  │     └─ util.scss
│  └─ component.scss      @import '~common-lib/util.scss' should resolve to
│                           node_modules/component/node_modules/common-lib/util.scss
│
└─file.scss               @import '~common-lib/util.scss' should resolve to
                             node_modules/common-lib/util.scss

Changes

numonedad commented 2 years ago

I dig it, go uses the same longest path to find matches