Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Importers may need access to the original, unaltered URL, as well as the URL of the importer, like the legacy API supported #1673

Closed
wessberg opened this issue Apr 14, 2022 · 1 comment

Comments

@wessberg
Copy link

wessberg commented Apr 14, 2022

Hi there.
I'm the author of a Custom Importer for sass which enables Node Module Resolution as well as path mapping.
I've been looking into migrating to the new Custom Importer API, but it seems this won't actually be possible.

Previously, a Custom Importer would be invoked with the raw, unaltered module specifier ("URL", as you call it inside your documentation) as the first argument, followed by the URL of the importing file ("prev", as you call it).

For example, when parsing @import "my-alias" from the file /foo/bar/baz.scss, a Custom Importer would be invoked with "my alias" as the first argument, and "/foo/bar/baz.scss", as the second argument.

Having access to the exact value provided to the import statement here is essential to the path mapping feature I'm currently supporting via the legacy API. For example, as documented here, consider a scenario in which "my-alias" is actually path mapped to another location on the filesystem, configured like so:

import {createImporter} from "sass-extended-importer";
import sass from "sass";

sass({
	// ...
	importer: createImporter({
		paths: {
			"my-alias": ["../other-folder/src/index.scss"],
			"my-alias/*": ["../other-folder/src/*"]
		}
	})
});

With the new Custom Importer API, the canonicalize method is invoked with a full URL (prefixed by a protocol like file://), and no way of knowing exactly what was actually written. In the original example from above, that URL would like like this: file://foo/bar/my-alias, making it impossible to understand how to map that to the path mapped values.

To work around this, and to allow me to migrate to the new API, I request having access to the raw, unaltered URL/module specifier as part of the options object that canonicalize is invoked with as the second argument, and ideally also the URL of the file importing it, if any ("prev").

I'm also open to suggestions as to how I might be able to achieve this with the current API, as I currently don't see a way forward.
Thanks for your time.

@stof
Copy link
Contributor

stof commented Apr 15, 2022

The discussion about that is happening at sass/sass#3247

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants