html icon indicating copy to clipboard operation
html copied to clipboard

Support import.meta.resolve baseURL argument

Open guybedford opened this issue 2 years ago • 2 comments

This specifies a new optional second argument for import.meta.resolve which supports a custom baseURL to be provided.

This effectively generalizes import.meta.resolve to act as a global resolver which can be useful for performing arbitrary module resolutions.

Node.js already implements this feature, and Deno has expressed implementation interest.

  • [ ] At least two implementers are interested (and none opposed):
    • Node.js
    • Deno
  • [x] Tests are written and can be reviewed and commented upon at:
    • https://github.com/web-platform-tests/wpt/pull/34692
  • [ ] Implementation bugs are filed:
    • Node.js (only for timers, structured clone, base64 utils, channel messaging, and module resolution): Already implemented
    • Deno (only for timers, structured clone, base64 utils, channel messaging, module resolution, web workers, and web storage): https://github.com/denoland/deno/issues/15073
    • Chrome: Will file pending review
    • Firefox: Will file pending review
    • Safari: Will file pending review

(See WHATWG Working Mode: Changes for more details.)


/webappapis.html ( diff )

guybedford avatar Jul 04 '22 18:07 guybedford

So two issues with this:

  • I don't think a global resolver belongs on import.meta, because it's no longer specific to the current module like all existing import.meta properties are. Instead you just seem to be using it as a sort of weird global namespace. Something like self.resolveModuleSpecifier() or HTMLScriptElement.resolve() would make more sense to me.

  • Even if we put that aside, it seems unlikely that we want to lock in all future uses of the second argument this way. I suspect there may be other (perhaps more appropriate) modifiers we apply to resolution in the future, so an options bag seems more reasonable here, e.g. import.meta.resolve(x, { baseURL }).

Apart from these specific issues, I'd encourage you to open an issue with a proposal, instead of jumping to a spec and tests PR and asking for review time from people. Such a proposal could include things like justifications why this is important, use cases, examples, etc.

domenic avatar Jul 05 '22 07:07 domenic

Thanks for the feedback, very good point with regards to the options bag second argument possibly being a more future-extensible design. I've posted https://github.com/whatwg/html/issues/8077 for further discussion on the topic.

guybedford avatar Jul 05 '22 20:07 guybedford