- Notifications
You must be signed in to change notification settings - Fork2.9k
Add import.meta.resolve()#5572
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
This looks like a good start. A useful feature can be to permit a second argument to I can provide some spec along these lines if you'd be open to it? |
I'd like to get the basic version out there first. Adding more features is a sure way to prevent this one from landing. |
These have proven over time to be much less interesting than other future extensions we might spend time on. In particular:* Give up on fallback support.Closes#76,closes#79,closes#83,closes#84. Alsocloses#79 by removing all the potential complexity there; we can instead discuss onwhatwg/html#3871 andwhatwg/html#5572.* Give up on import: URLs.Closes#71,closes#149.* Give up on built-in module remapping.
In principle this sounds reasonable to me. Would also like to hear from@jasnell,@lucacasonato, and@codehag. Do we have some kind of place where we document extensions to |
jasnell commentedFeb 10, 2022
Yeah, I'm +1 on this. It'll be quite useful, I think. |
lucacasonato commentedFeb 10, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I have no strong opinion (maybe +0.1?). Not opposed, but I know some Node folks want this to be async. We are fine with it being sync (and would want it to be sync). |
codehag commentedFeb 11, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I don't see an issue with introducing this. I think this would be useful to test import maps, and i imagine it will be useful in such a world were import maps are the norm? |
Uh oh!
There was an error while loading.Please reload this page.
fa07fc6
tof91ff0e
Comparef91ff0e
to6cc21d3
CompareAwesome, thanks all for the review. I'll plan to merge this after I'm a bit more confident in the tests; I have some up initially athttps://chromium-review.googlesource.com/c/chromium/src/+/3456729 but that CL is messy enough that I don't trust them yet. |
GeoffreyBooth commentedFeb 11, 2022
Hey, can we slow this down just a bit? I’m a bit concerned with this being sync, since in Node the resolution step is async (and needs to remain so, or it would break various loaders use cases). Taking a step back, for the non-bare case isn’t And the bare case, |
domenic commentedFeb 11, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I think a 7-month incubation period is slow enough? It's ok for Node to use a different API than the web here. This is different than the URL constructor because import maps, indeed. There is no plan to make that async; we never want to introduce network calls into module resolution on the web. |
GeoffreyBooth commentedFeb 11, 2022
Put another way, is there some advantage in making this sync? If it’s async then we can maintain compatibility with Node or any platform that wants to allow customization in module resolution (and for that custom resolution to potentially be async). |
Aside: was whatwg/js-hosts dissolved due to the creation of the Winter CG? I was trying to make sense of the status of this in light ofmozilla/standards-positions#647 and it seems like it's roughly at where we left it in February. Node.js can make this shape work, but isn't thrilled about it. Deno doesn't necessarily have a need, but if it's added it should be this shape. And browser folks being somewhat positive given that it matches how we resolve JS module specifiers. Is that accurate? |
jasnell commentedJun 7, 2022
I believe that is the case, yes.
That's accurate. |
GeoffreyBooth commentedJun 7, 2022
To add to this, please readthis detailed comment about the downsides of Node making |
From my perspective, that comment displays some fundamental confusion between the resolve phases (a string operation) and the fetch phases (which includes things like checking for existence, permissions, network requests, etc.) |
GeoffreyBooth commentedJun 7, 2022
In Node, the resolve “phase” includes disk operations. Going back to CommonJS, |
Seewhatwg/html#5572Bug: 1296665Change-Id: I63938700518941d0f65a2a1c7fd13910bd095261
davidje13 commentedJun 20, 2022
Hi@domenic — sorry for this being quite a delayed reply (I wasn't aware of this thread which linked to my other comment) I'd like to clarify the use-case which led me to my other comment, which should help explain the bits which you think of as confusion on my part: In NodeJS's current system, these imports could all resolve to the same file: import'bar';import'bar/index';// or something else depending on bar's package.jsonimport'./node_modules/bar/index.js'; And It's important to know all thatbefore loading the module, because if they resolve to the same thing, we need to use the same instance of that module (e.g. so that any user-land global state is truly global). Once we get to the point of actually loading the module, it's too late. So we need Now you may say that's a problem with NodeJS's Import maps have of course been created to fill this need in the browser (with the intent being that all this information which was previously gathered by polling the filesystem is now available declaratively in-advance), but they are at an early stage (and only implemented in one runtime), so I for one cannot yet rely on them for this use-case (even in an experimental capacity). I could also imagine a future need to lazy-load or even dynamically-generate import maps, especially in local environments like Node where the number of entries could bevast. Even in-browser I could imagine the need to fetch (sub) import maps on-demand once nesting / combining of maps gets more specced out, which would make the My preference (as a userspace developer with a vested interest in keeping parity between browsers and NodeJS) is that |
FYI, the compartments proposal at TC39 (https://github.com/tc39/proposal-compartments) also defines specifier resolving as being a synchronous operation. (grep for |
Seewhatwg/html#5572.Intent to Ship:https://groups.google.com/a/chromium.org/g/blink-dev/c/ZVODFsnIf74Bug: 1296665Change-Id: I63938700518941d0f65a2a1c7fd13910bd095261
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Seewhatwg/html#5572.Intent to Ship:https://groups.google.com/a/chromium.org/g/blink-dev/c/ZVODFsnIf74Fixed: 1296665Change-Id: I63938700518941d0f65a2a1c7fd13910bd095261
Seewhatwg/html#5572.Intent to Ship:https://groups.google.com/a/chromium.org/g/blink-dev/c/ZVODFsnIf74Fixed: 1296665Change-Id: I63938700518941d0f65a2a1c7fd13910bd095261
Seewhatwg/html#5572.Intent to Ship:https://groups.google.com/a/chromium.org/g/blink-dev/c/ZVODFsnIf74Fixed: 1296665Change-Id: I63938700518941d0f65a2a1c7fd13910bd095261Reviewed-on:https://chromium-review.googlesource.com/c/chromium/src/+/3456729Reviewed-by: Kouhei Ueno <kouhei@chromium.org>Reviewed-by: Hiroshige Hayashizaki <hiroshige@chromium.org>Reviewed-by: Yuki Shiino <yukishiino@chromium.org>Commit-Queue: Domenic Denicola <domenic@chromium.org>Cr-Commit-Position: refs/heads/main@{#1021529}
Seewhatwg/html#5572.Intent to Ship:https://groups.google.com/a/chromium.org/g/blink-dev/c/ZVODFsnIf74Fixed: 1296665Change-Id: I63938700518941d0f65a2a1c7fd13910bd095261Reviewed-on:https://chromium-review.googlesource.com/c/chromium/src/+/3456729Reviewed-by: Kouhei Ueno <kouhei@chromium.org>Reviewed-by: Hiroshige Hayashizaki <hiroshige@chromium.org>Reviewed-by: Yuki Shiino <yukishiino@chromium.org>Commit-Queue: Domenic Denicola <domenic@chromium.org>Cr-Commit-Position: refs/heads/main@{#1021529}
Seewhatwg/html#5572.Intent to Ship:https://groups.google.com/a/chromium.org/g/blink-dev/c/ZVODFsnIf74Fixed: 1296665Change-Id: I63938700518941d0f65a2a1c7fd13910bd095261Reviewed-on:https://chromium-review.googlesource.com/c/chromium/src/+/3456729Reviewed-by: Kouhei Ueno <kouhei@chromium.org>Reviewed-by: Hiroshige Hayashizaki <hiroshige@chromium.org>Reviewed-by: Yuki Shiino <yukishiino@chromium.org>Commit-Queue: Domenic Denicola <domenic@chromium.org>Cr-Commit-Position: refs/heads/main@{#1021529}
Automatic update from web-platform-testsImplement import.meta.resolve()Seewhatwg/html#5572.Intent to Ship:https://groups.google.com/a/chromium.org/g/blink-dev/c/ZVODFsnIf74Fixed:1296665Change-Id: I63938700518941d0f65a2a1c7fd13910bd095261Reviewed-on:https://chromium-review.googlesource.com/c/chromium/src/+/3456729Reviewed-by: Kouhei Ueno <kouhei@chromium.org>Reviewed-by: Hiroshige Hayashizaki <hiroshige@chromium.org>Reviewed-by: Yuki Shiino <yukishiino@chromium.org>Commit-Queue: Domenic Denicola <domenic@chromium.org>Cr-Commit-Position: refs/heads/main@{#1021529}--wpt-commits: edcc51d740e71ace04d1fe1a4ae107ea3e640c2awpt-pr: 34188
Automatic update from web-platform-testsImplement import.meta.resolve()Seewhatwg/html#5572.Intent to Ship:https://groups.google.com/a/chromium.org/g/blink-dev/c/ZVODFsnIf74Fixed: 1296665Change-Id: I63938700518941d0f65a2a1c7fd13910bd095261Reviewed-on:https://chromium-review.googlesource.com/c/chromium/src/+/3456729Reviewed-by: Kouhei Ueno <kouhei@chromium.org>Reviewed-by: Hiroshige Hayashizaki <hiroshige@chromium.org>Reviewed-by: Yuki Shiino <yukishiino@chromium.org>Commit-Queue: Domenic Denicola <domenic@chromium.org>Cr-Commit-Position: refs/heads/main@{#1021529}--wpt-commits: edcc51d740e71ace04d1fe1a4ae107ea3e640c2awpt-pr: 34188
Uh oh!
There was an error while loading.Please reload this page.
Closes#3871.
This introduces a new function,
import.meta.resolve(moduleSpecifier)
, which returns the URL to which a given module specifier would resolve in the context of the current script. That is, it returns the URL that would be imported if you didimport(moduleSpecifier)
.It will throw an exception if an invalid specifier is given (including one not mapped to anywhere by an import map).
The main use case for this is to get URLs relative to the current script, or relative to a current page. For example:
or
(SeeWHATWG Working Mode: Changes for more details.)
/infrastructure.html (diff )
/webappapis.html (diff )