Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/src/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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,
Expand Down Expand Up @@ -87,10 +89,20 @@ 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);
} else {
// When importer is not set on the host, the compiler will set a
// FileSystemImporter if `url` is set to a file: url or a NoOpImporter.
}

const request = newCompileRequest(importers, options);
Expand Down
4 changes: 3 additions & 1 deletion lib/src/legacy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
importer: modernOptions.importers ? modernOptions.importers[0] : undefined,
syntax: options.indentedSyntax ? 'indented' : 'scss',
};
Expand Down