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

Support import.meta.resolve baseURL argument #8074

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

guybedford
Copy link
Contributor

@guybedford guybedford commented Jul 4, 2022

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.

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


/webappapis.html ( diff )

@domenic
Copy link
Member

domenic commented Jul 5, 2022

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.

@guybedford
Copy link
Contributor Author

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 #8077 for further discussion on the topic.

@domenic domenic added addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: script labels Jul 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: script
Development

Successfully merging this pull request may close these issues.

2 participants