Skip to content

Commit

Permalink
Rewrite legacy API using containingUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
ntkme committed Jul 27, 2024
1 parent 6121ef4 commit 7d66b8a
Show file tree
Hide file tree
Showing 9 changed files with 230 additions and 315 deletions.
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 @@ -44,7 +44,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

0 comments on commit 7d66b8a

Please sign in to comment.