-
Notifications
You must be signed in to change notification settings - Fork 29
Avoid resolving imports relative to working directory for compileString #124
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
Conversation
| const importer = new proto.InboundMessage.CompileRequest.Importer(); | ||
| importer.setPath(p.resolve('.')); | ||
| input.setImporter(importer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nex3 With new spec, null URL will end up with noOpImporter on embedded compiler, but legacy API wants a FilesystemImporter even without filename/url, so explicitly set it should give the compiler the correct importer.
| url: options.file ? pathToFileURL(options.file) : undefined, | ||
| url: options.file | ||
| ? pathToFileURL(options.file) | ||
| : new URL(legacyImporterProtocol), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Legacy API needs to have a FilesystemImporter('.') as if it has an url even if it does not. Set a special value here to let the new API know that.
|
|
||
| if (options?.url) input.setUrl(options.url.toString()); | ||
| const url = options?.url?.toString(); | ||
| if (url && url !== legacyImporterProtocol) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The special value legacyImporterProtocol means this is from Legacy API that even if it does not set a url it should behave as if it has one down below when setting the importer.
|
Unless I'm mistaken, updating sass/dart-sass-embedded#83 so that the compiler uses a filesystem importer in the right circumstances should mitigate the need for this PR. However, it would be good to also add a JS API spec to sass-spec that verifies that CWD-relative imports don't work with |
|
Looks like this can be simplified a bit by constructing proto importer inside the legacy compile. |
|
Let me close this and open an new PR. |
This PR fixes sass/dart-sass-embedded#82.