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 e7622c4
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 328 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
25 changes: 5 additions & 20 deletions lib/src/compiler/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ import {deprotofySourceSpan} from '../deprotofy-span';
import {Dispatcher, DispatcherHandlers} from '../dispatcher';
import {Exception} from '../exception';
import {ImporterRegistry} from '../importer-registry';
import {
legacyImporterProtocol,
removeLegacyImporter,
removeLegacyImporterFromSpan,
} from '../legacy/utils';
import {Logger} from '../logger';
import {MessageTransformer} from '../message-transformer';
import * as utils from '../utils';
Expand Down Expand Up @@ -121,19 +116,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 All @@ -153,12 +141,9 @@ export function handleLogEvent(
options: OptionsWithLegacy<'sync' | 'async'> | undefined,
event: proto.OutboundMessage_LogEvent
): void {
let span = event.span ? deprotofySourceSpan(event.span) : null;
if (span && options?.legacy) span = removeLegacyImporterFromSpan(span);
let message = event.message;
if (options?.legacy) message = removeLegacyImporter(message);
let formatted = event.formatted;
if (options?.legacy) formatted = removeLegacyImporter(formatted);
const span = event.span ? deprotofySourceSpan(event.span) : null;
const message = event.message;
const formatted = event.formatted;
const deprecationType = validDeprecationId(event.deprecationType)
? deprecations[event.deprecationType]
: null;
Expand Down Expand Up @@ -189,7 +174,7 @@ export function handleLogEvent(

const stack = event.stackTrace;
if (stack) {
params.stack = options?.legacy ? removeLegacyImporter(stack) : stack;
params.stack = stack;
}

options.logger.warn(message, params);
Expand Down
Loading

0 comments on commit e7622c4

Please sign in to comment.