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

Conversation

jathak
Copy link
Member

@jathak jathak commented Oct 15, 2024

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

@jathak jathak requested a review from nex3 October 15, 2024 20:54
return {...span, url: new URL(url)};
} catch (_) {
// Relative URL
return {...span, url: new URL(url, `file://${process.cwd()}`)};
Copy link
Contributor

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().

const url = removeLegacyImporter(span.url.toString());
try {
return {...span, url: new URL(url)};
} catch (_) {
Copy link
Contributor

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.

@jathak jathak requested a review from nex3 October 15, 2024 23:25
@jathak jathak merged commit ecb7c20 into main Oct 17, 2024
16 checks passed
@jathak jathak deleted the import-deprecation branch October 17, 2024 00:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants