From 7c62b7b0434314fee1355ccfa2a95aea2a9cc01e Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Wed, 30 Sep 2020 17:22:58 +1000 Subject: [PATCH] fix(cli): use global_state file_fetcher when using SpecifierHandler (#7748) Fixes: #7709 --- cli/global_state.rs | 4 +++- cli/specifier_handler.rs | 26 ++++++++++---------------- cli/tests/integration_tests.rs | 6 ++++++ 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/cli/global_state.rs b/cli/global_state.rs index ec2d781309..336dcae003 100644 --- a/cli/global_state.rs +++ b/cli/global_state.rs @@ -126,8 +126,10 @@ impl GlobalState { if self.flags.no_check { debug!("Transpiling root: {}", module_specifier); + // TODO(kitsonk) note that self.permissions != permissions, which is + // something that should be handled better in the future. let handler = - Rc::new(RefCell::new(FetchHandler::new(&self.flags, &permissions)?)); + Rc::new(RefCell::new(FetchHandler::new(self, permissions.clone())?)); let mut builder = GraphBuilder::new(handler, maybe_import_map); builder.insert(&module_specifier).await?; let mut graph = builder.get_graph(&self.lockfile)?; diff --git a/cli/specifier_handler.rs b/cli/specifier_handler.rs index f2b4221413..bc5b29e4e7 100644 --- a/cli/specifier_handler.rs +++ b/cli/specifier_handler.rs @@ -4,8 +4,7 @@ use crate::deno_dir::DenoDir; use crate::disk_cache::DiskCache; use crate::file_fetcher::SourceFileFetcher; use crate::file_fetcher::TextDocument; -use crate::flags::Flags; -use crate::http_cache::HttpCache; +use crate::global_state::GlobalState; use crate::media_type::MediaType; use crate::permissions::Permissions; @@ -22,6 +21,7 @@ use std::error::Error; use std::fmt; use std::pin::Pin; use std::result; +use std::sync::Arc; type Result = result::Result; @@ -204,27 +204,19 @@ pub struct FetchHandler { } impl FetchHandler { - pub fn new(flags: &Flags, permissions: &Permissions) -> Result { + pub fn new( + global_state: &Arc, + permissions: Permissions, + ) -> Result { let custom_root = env::var("DENO_DIR").map(String::into).ok(); let deno_dir = DenoDir::new(custom_root)?; - let deps_cache_location = deno_dir.root.join("deps"); - let http_cache = HttpCache::new(&deps_cache_location); - let ca_file = flags.ca_file.clone().or_else(|| env::var("DENO_CERT").ok()); - - let file_fetcher = SourceFileFetcher::new( - http_cache, - !flags.reload, - flags.cache_blocklist.clone(), - flags.no_remote, - flags.cached_only, - ca_file.as_deref(), - )?; let disk_cache = deno_dir.gen_cache; + let file_fetcher = global_state.file_fetcher.clone(); Ok(FetchHandler { disk_cache, file_fetcher, - permissions: permissions.clone(), + permissions, }) } } @@ -387,6 +379,8 @@ impl SpecifierHandler for FetchHandler { pub mod tests { use super::*; + use crate::http_cache::HttpCache; + use deno_core::futures::future; use std::fs; use std::path::PathBuf; diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index c062d3371c..d836bc71a5 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -1506,6 +1506,12 @@ itest!(deno_test_only { output: "deno_test_only.ts.out", }); +itest!(deno_test_no_check { + args: "test --no-check test_runner_test.ts", + exit_code: 1, + output: "deno_test.out", +}); + #[test] fn timeout_clear() { // https://github.com/denoland/deno/issues/7599