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

Fix error with deprecation warnings and legacy importers #339

Merged
merged 4 commits into from
Oct 17, 2024
Merged
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion lib/src/legacy/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ export function removeLegacyImporter(string: string): string {
// syntax.
export function removeLegacyImporterFromSpan(span: SourceSpan): SourceSpan {
if (!span.url) return span;
return {...span, url: new URL(removeLegacyImporter(span.url.toString()))};
const url = removeLegacyImporter(span.url.toString());
return {
...span,
url: URL.canParse(url)
Copy link
Contributor

@ntkme ntkme Oct 15, 2024

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

? new URL(url)
: new URL(url, `file://${process.cwd()}/`),
};
}

// Converts [path] to a `file:` URL and adds the [legacyImporterProtocolPrefix]
Expand Down
Loading