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
Adds a ResolverMode enum that changes the bridge function used when calling back into go to libs
Adds a new api NewImportsWithAbsResolver that uses the abspath ResolverMode
Adds go.mod and go.sum files:
go build and go test wouldn't work for me without a go.mod file
I couldn't reference the module locally with a replace directive without a go.mod file
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:
Changes
ResolverMode
enum that changes the bridge function used when calling back into go to libsNewImportsWithAbsResolver
that uses the abspath ResolverModego build
andgo test
wouldn't work for me without a go.mod filereplace
directive without a go.mod file