summaryrefslogtreecommitdiff
path: root/cli/isolate.rs
diff options
context:
space:
mode:
authorKevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com>2019-04-01 18:46:40 -0700
committerRyan Dahl <ry@tinyclouds.org>2019-04-01 21:46:40 -0400
commit534b8d30219a605c82bac706bc5429d44ae53c32 (patch)
tree2e653b1590fc237030d56f8535fa40d2dd923262 /cli/isolate.rs
parente44084c90dec8cafbc66d4e485ff24479c56ec2e (diff)
Follow redirect location as new referrers for nested module imports (#2031)
Fixes #1742 Fixes #2021
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());