Skip to content
Closed
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
11 changes: 10 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,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) {
Copy link
Contributor Author

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.

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
Copy link
Contributor Author

@ntkme ntkme Apr 3, 2022

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.

}

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),
Copy link
Contributor Author

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.

importer: modernOptions.importers ? modernOptions.importers[0] : undefined,
syntax: options.indentedSyntax ? 'indented' : 'scss',
};
Expand Down