summaryrefslogtreecommitdiff
path: root/cli/isolate.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/isolate.rs')
-rw-r--r--cli/isolate.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/cli/isolate.rs b/cli/isolate.rs
index ced1cb792..9dcf6e8f0 100644
--- a/cli/isolate.rs
+++ b/cli/isolate.rs
@@ -84,6 +84,15 @@ impl<B: DenoBehavior> Isolate<B> {
&out.js_source(),
)?;
+ // The resolved module is an alias to another module (due to redirects).
+ // Save such alias to the module map.
+ if out.module_redirect_source_name.is_some() {
+ self.mod_alias(
+ &out.module_redirect_source_name.clone().unwrap(),
+ &out.module_name,
+ );
+ }
+
self.mod_load_deps(child_id)?;
}
}
@@ -117,10 +126,23 @@ impl<B: DenoBehavior> Isolate<B> {
let out = fetch_module_meta_data_and_maybe_compile(&self.state, url, ".")
.map_err(RustOrJsError::from)?;
+ // Be careful.
+ // url might not match the actual out.module_name
+ // due to the mechanism of redirection.
+
let id = self
.mod_new_and_register(true, &out.module_name.clone(), &out.js_source())
.map_err(RustOrJsError::from)?;
+ // The resolved module is an alias to another module (due to redirects).
+ // Save such alias to the module map.
+ if out.module_redirect_source_name.is_some() {
+ self.mod_alias(
+ &out.module_redirect_source_name.clone().unwrap(),
+ &out.module_name,
+ );
+ }
+
self.mod_load_deps(id)?;
let state = self.state.clone();
@@ -153,6 +175,13 @@ impl<B: DenoBehavior> Isolate<B> {
Ok(id)
}
+ /// Create an alias for another module.
+ /// The alias could later be used to grab the module
+ /// which `target` points to.
+ fn mod_alias(&self, name: &str, target: &str) {
+ self.state.modules.lock().unwrap().alias(name, target);
+ }
+
pub fn print_file_info(&self, module: &str) {
let m = self.state.modules.lock().unwrap();
m.print_file_info(&self.state.dir, module.to_string());