Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: Allow resolving "ext:" modules from "ext:" or "node:" modules #369

Merged
merged 5 commits into from
Dec 6, 2023

Conversation

bartlomieju
Copy link
Member

@bartlomieju bartlomieju commented Dec 6, 2023

A new "ModuleMap::resolve" function was added that is now used in
favor of directly calling "loader.resolve". This method performs additional
checks that prohibit resolution of "ext:" modules from modules that are not
"ext:" or "node:" modules.

This will allow us to sunset "RuntimeOptions::preserve_snapshotted_modules"
and will greatly help with #263 and denoland/deno#21422.

A bit different approach than suggested in the issue, but closes #363.

@bartlomieju bartlomieju requested a review from mmastrac December 6, 2023 21:51
if specifier.starts_with("ext:")
&& !referrer.starts_with("ext:")
&& !referrer.starts_with("node:")
&& referrer != "."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When would referrer be .?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Referrer is "." when we are resolving top level specifier - in such case the specifier needs to be already resolved. It's a bit of code smell, but that code hasn't been touched in a couple years.

@@ -541,11 +569,14 @@ impl ModuleMap {
referrer: &str,
import_assertions: HashMap<String, String>,
) -> Option<v8::Local<'s, v8::Module>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up for the future. Not for this PR, but it would be nice if this function was more rust-y and returned Result<Module, Error> and we had an extra small shim function that would throw the error and return None.

Copy link
Contributor

@mmastrac mmastrac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, one question. Should be easy enough to slot in a custom callback.

@bartlomieju bartlomieju enabled auto-merge (squash) December 6, 2023 22:27
@bartlomieju bartlomieju merged commit 298b9ea into denoland:main Dec 6, 2023
@bartlomieju bartlomieju deleted the allow_resolving_ext_from_ext branch December 6, 2023 22:34
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ModuleMap::clear_module_map should be rearchitectured
2 participants