-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
feat: import.meta.resolve() #15074
feat: import.meta.resolve() #15074
Conversation
This should be sync. HTML spec is sync. |
That's fine for me, I'll rework the PR after fixing |
@lucacasonato I've reworked it to be sync, PTAL |
@bartlomieju the reason for the Node.js behaviour is because Node.js will still apply the realpath algorithm to resolutions, which in turn throws. I agree it's not ideal - one thing we could do is catch any not found errors and rethrow them at load time rather. Perhaps realpathing should be handled more like redirects as well in being the response URL not the request URL, to get even more alignment with the web, despite the pains of that in double instancing. I can possibly try to push those two changes through Node.js process. |
That makes it clear now, thanks for a thorough explanation. Since it already diverges from the spec by returning a promise I think it's okay for the behavior to stay as is, but would be great to have it documented. |
We are actively working on aligning on a sync resolver, it just will take some time. |
core/bindings.rs
Outdated
}; | ||
match loader.resolve( | ||
&specifier.to_rust_string_lossy(tc_scope), | ||
&referrer, |
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.
What happens when the referrer is an invalid URL? That might not be tested for the core resolver?
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.
loader.resolve()
raises an error that is forwarded to JS
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.
Can you add a test? For example trying to resolve an invalid URL.
To be transparent there is still some uncertainty about the second argument - whatwg/html#8074 (comment). |
I think it would be safer for us, to only support the first argument for now since it's a living standard right now. |
I've reverted addition of the second argument since it is not yet specced. @lucacasonato please review. |
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.
LGTM
Opening for a discussion purposes.
@guybedford I'm a bit surprised in Node's behavior:
I would have thought that this function is for pure resolution and it won't touch file system to check for the existence of a specifier we're trying to resolve.
Closes #7296