-
Notifications
You must be signed in to change notification settings - Fork 29
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
Using legacy APIs with importers triggers @import
deprecation warning
#340
Comments
This is somewhat expected, due to the way the legacy API in the embedded-host-node is emulated with modern API. #309 might fix this but we’ve decided that it’s not worth to do such a major rewrite given that the legacy API will be removed soon in 2.0.0. |
Is it possible to filter out the deprecation warning containing |
It's possible. However, filtering out the warning internally is only a partial workaround for the default config. When a user choose to opt-in with Here is a patch: diff --git a/lib/src/compiler/utils.ts b/lib/src/compiler/utils.ts
index f04f03f..ee94263 100644
--- a/lib/src/compiler/utils.ts
+++ b/lib/src/compiler/utils.ts
@@ -168,6 +168,13 @@ export function handleLogEvent(
? deprecations[event.deprecationType]
: null;
+ if (
+ deprecationType === deprecations.import &&
+ span?.text.startsWith('"sass-embedded-legacy-load-done:')
+ ) {
+ return;
+ }
+
if (event.type === proto.LogEventType.DEBUG) {
if (options?.logger?.debug) {
options.logger.debug(message, { Although this patch silences the deprecation for internal sass.renderSync({ data: '@use "test"', fatalDeprecations: ['import'], importer: [
function(url, _) {
if (url != 'test') return null;
return {
contents: 'a {b: c}'
};
}]
}); |
I guess that can be workaround by converting it to a normal deprecation and throwing on the host side. const wasImportIncludedInFatalDeprecations = fatalDeprecations.includes('import')
// also remove `import` from options.fatalDeprecations
// ---
if (deprecationType === deprecations.import) {
if (span?.text.startsWith('"sass-embedded-legacy-load-done:')) {
return;
}
if (wasImportIncludedInFatalDeprecations) {
throw new Error('@import fatal deprecation')
}
} |
That is certainly possible, but unfortunately not as straightforward as you would think. The main problem is that the event dispatcher in a synchronous compiler currently dispatches log event asynchronously, meaning anything thrown in logger will just become unhandled exception that is not catchable. See original discussion here: #261 (comment) |
Ah, I see. |
This unfortunately may make error reports look a little odd for errors on the first line of SCSS files loaded via the legacy importer and it'll give indented-syntax errors an off-by-one error, but there's an easy fix: stop using the legacy API. Closes #340
This unfortunately may make error reports look a little odd for errors on the first line of SCSS files loaded via the legacy importer and it'll give indented-syntax errors an off-by-one error, but there's an easy fix: stop using the legacy API. Closes #340 Co-authored-by: Jennifer Thakar <jathak@google.com>
Even if the code doesn't contain
@import
, the@import
deprecation warning appears.While I can set
silenceDeprecations
, it's a bit confusing.Reproduction:
npm i
node index.js
The text was updated successfully, but these errors were encountered: