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

import.meta.resolve() #746

Closed
1 task done
domenic opened this issue Jun 6, 2022 · 3 comments
Closed
1 task done

import.meta.resolve() #746

domenic opened this issue Jun 6, 2022 · 3 comments
Assignees
Labels

Comments

@domenic
Copy link
Member

domenic commented Jun 6, 2022

Wotcher TAG!

I'm requesting a TAG review of import.meta.resolve().

import.meta.resolve(specifier) returns the URL to which specifier would resolve in the context of the current script. That is, it returns the URL that would be imported if you did import(specifier).

This is a quite small feature (a single function, with only a few lines of spec text which exposes an already-existing spec algorithm).

Further details:

  • I have reviewed the TAG's Web Platform Design Principles
  • Relevant time constraints or deadlines: Chrome would like to ship this within a few weeks.
  • The group where the work on this specification is currently being done: WHATWG
  • Major unresolved issues with or opposition to this specification: There was some opposition from Node.js about how synchronous semantics would conflict with their existing experimental async semantics; see the discussion in the explainer. I believe these have been largely resolved.
  • This work is being funded by: Google

We'd prefer the TAG provide feedback as (please delete all but the desired option):

💬 leave review feedback as a comment in this issue and @-notify @domenic

@plinss
Copy link
Member

plinss commented Jul 18, 2022

We took a look at this today and are generally favorable. Some questions though regarding the sync/async decision, what happens if the author calls this while there's a pending load for an import map? Does it throw or return the wrong value? If the author needs to wait until the import map(s) are fully loaded, how do they do that?

@plinss plinss added the Progress: pending external feedback The TAG is waiting on response to comments/questions asked by the TAG during the review label Jul 20, 2022
@domenic
Copy link
Member Author

domenic commented Jul 21, 2022

Right now import maps are always inline and cannot be loaded. It's unclear whether that will change in the future; implementer interest is low, although I personally think it'd be nice.

In such a future, it would return the current value. It would not throw. It's not clear whether the current value would be considered "wrong"; if you do import.meta.resolve(x); import(x); while an import map is being loaded, the import() statement will import the same URL returned by import.meta.resolve(x) (i.e., the current value).

If an author needs to wait for import maps in such a future, it depends on how we expose external import map loading, but probably the simplest way would be to wait for that import map <script> element's load event.

@LeaVerou
Copy link
Member

We looked at this again today during a breakout. Even without import map loading, authors can always dynamically add import maps by creating new <script> elements and appending them to the document. So even if the API were async, it could not possibly account for all future import maps. Therefore we're fine with a sync API, that is easier to reason about as resolving the specifier based on whatever the current state of import maps is, and we're going to close this. Thank you for flying TAG!

@LeaVerou LeaVerou added Resolution: satisfied The TAG is satisfied with this design and removed Progress: pending external feedback The TAG is waiting on response to comments/questions asked by the TAG during the review labels Oct 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants