-
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
Fix error with deprecation warnings and legacy importers #339
Conversation
lib/src/legacy/utils.ts
Outdated
const url = removeLegacyImporter(span.url.toString()); | ||
return { | ||
...span, | ||
url: URL.canParse(url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
URL.canParse
requires node >= 19.9.0
, so better do a try
- catch
instead.
https://developer.mozilla.org/en-US/docs/Web/API/URL/canParse_static#browser_compatibility
lib/src/legacy/utils.ts
Outdated
return {...span, url: new URL(url)}; | ||
} catch (_) { | ||
// Relative URL | ||
return {...span, url: new URL(url, `file://${process.cwd()}`)}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just shoving a pathname into a URL string isn't safe in general. Use Node's pathToFileUrl()
.
lib/src/legacy/utils.ts
Outdated
const url = removeLegacyImporter(span.url.toString()); | ||
try { | ||
return {...span, url: new URL(url)}; | ||
} catch (_) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the URL is absolute, it won't use the basename anyway, so you can just pass it in eagerly rather than catching this error.
See sass/sass#3898.
See sass/sass-spec#2004.
See sass/dart-sass#2282.