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

Rewrite legacy API using containingUrl #309

Closed
wants to merge 1 commit into from
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
14 changes: 14 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,19 @@
// It would be nice to sort import declaration order as well, but that's not
// autofixable and it's not worth the effort of handling manually.
"sort-imports": ["error", {"ignoreDeclarationSort": true}],
// Match TypeScript style of exempting names starting with `_`.
// See: https://typescript-eslint.io/rules/no-unused-vars/
"@typescript-eslint/no-unused-vars": [
"error",
{
"args": "all",
"argsIgnorePattern": "^_",
"caughtErrors": "all",
"caughtErrorsIgnorePattern": "^_",
"destructuredArrayIgnorePattern": "^_",
"varsIgnorePattern": "^_",
"ignoreRestSiblings": true
}
]
}
}
2 changes: 1 addition & 1 deletion lib/src/compiler-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const compilerCommand = (() => {
`sass-embedded-${platform}-${arch}/dart-sass/src/sass.snapshot`
),
];
} catch (ignored) {
} catch (_ignored) {
// ignored
}

Expand Down
10 changes: 1 addition & 9 deletions lib/src/compiler/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {Dispatcher, DispatcherHandlers} from '../dispatcher';
import {Exception} from '../exception';
import {ImporterRegistry} from '../importer-registry';
import {
legacyImporterProtocol,
removeLegacyImporter,
removeLegacyImporterFromSpan,
} from '../legacy/utils';
Expand Down Expand Up @@ -121,19 +120,12 @@ export function newCompileStringRequest(
});

const url = options?.url?.toString();
if (url && url !== legacyImporterProtocol) {
if (url) {
input.url = url;
}

if (options && 'importer' in options && options.importer) {
input.importer = importers.register(options.importer);
} else if (url === legacyImporterProtocol) {
input.importer = new proto.InboundMessage_CompileRequest_Importer({
importer: {case: 'path', value: p.resolve('.')},
});
} 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
15 changes: 11 additions & 4 deletions lib/src/importer-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import * as utils from './utils';
import {FileImporter, Importer, Options} from './vendor/sass';
import * as proto from './vendor/embedded_sass_pb';
import {PromiseOr, catchOr, thenOr} from './utils';
import {LegacyImporterWrapper} from './legacy/importer';
import {legacyImporterScheme} from './legacy/utils';

const entryPointDirectoryKey = Symbol();

Expand Down Expand Up @@ -94,10 +96,15 @@ export class ImporterRegistry<sync extends 'sync' | 'async'> {
}

message.importer = {case: 'importerId', value: this.id};
message.nonCanonicalScheme =
typeof importer.nonCanonicalScheme === 'string'
? [importer.nonCanonicalScheme]
: importer.nonCanonicalScheme ?? [];
if (importer instanceof LegacyImporterWrapper) {
message.nonCanonicalScheme = [legacyImporterScheme];
message.invertNonCanonicalScheme = true;
} else {
message.nonCanonicalScheme =
typeof importer.nonCanonicalScheme === 'string'
? [importer.nonCanonicalScheme]
: importer.nonCanonicalScheme ?? [];
}
this.importersById.set(this.id, importer);
} else {
message.importer = {case: 'fileImporterId', value: this.id};
Expand Down
Loading
Loading