-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| // MIT-style license that can be found in the LICENSE file or at | ||
| // https://opensource.org/licenses/MIT. | ||
|
|
||
| import * as p from 'path'; | ||
| import {Observable} from 'rxjs'; | ||
| import * as supportsColor from 'supports-color'; | ||
|
|
||
|
|
@@ -17,6 +18,7 @@ import {MessageTransformer} from './message-transformer'; | |
| import {PacketTransformer} from './packet-transformer'; | ||
| import {SyncEmbeddedCompiler} from './sync-compiler'; | ||
| import {deprotofySourceSpan} from './deprotofy-span'; | ||
| import {legacyImporterProtocol} from './legacy/importer'; | ||
|
|
||
| export function compile( | ||
| path: string, | ||
|
|
@@ -87,10 +89,17 @@ function newCompileStringRequest( | |
| input.setSource(source); | ||
| input.setSyntax(utils.protofySyntax(options?.syntax ?? 'scss')); | ||
|
|
||
| if (options?.url) input.setUrl(options.url.toString()); | ||
| const url = options?.url?.toString(); | ||
| if (url && url !== legacyImporterProtocol) { | ||
| input.setUrl(url); | ||
| } | ||
|
|
||
| if (options && 'importer' in options && options.importer) { | ||
| input.setImporter(importers.register(options.importer)); | ||
| } else if (url === legacyImporterProtocol) { | ||
| const importer = new proto.InboundMessage.CompileRequest.Importer(); | ||
| importer.setPath(p.resolve('.')); | ||
| input.setImporter(importer); | ||
|
Comment on lines
+100
to
+102
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nex3 With new spec, null URL will end up with |
||
| } | ||
ntkme marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const request = newCompileRequest(importers, options); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -172,7 +172,9 @@ function convertStringOptions<sync extends 'sync' | 'async'>( | |
|
|
||
| return { | ||
| ...modernOptions, | ||
| url: options.file ? pathToFileURL(options.file) : undefined, | ||
| url: options.file | ||
| ? pathToFileURL(options.file) | ||
| : new URL(legacyImporterProtocol), | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Legacy API needs to have a |
||
| importer: modernOptions.importers ? modernOptions.importers[0] : undefined, | ||
| syntax: options.indentedSyntax ? 'indented' : 'scss', | ||
| }; | ||
|
|
||
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
legacyImporterProtocolmeans this is from Legacy API that even if it does not set aurlit should behave as if it has one down below when setting the importer.