1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-26 16:09:27 -05:00

fix(cli): use global_state file_fetcher when using SpecifierHandler (#7748)

Fixes: #7709
This commit is contained in:
Kitson Kelly 2020-09-30 17:22:58 +10:00 committed by GitHub
parent 27ee4b2551
commit 7c62b7b043
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 17 deletions

View file

@ -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)?;

View file

@ -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<V> = result::Result<V, AnyError>;
@ -204,27 +204,19 @@ pub struct FetchHandler {
}
impl FetchHandler {
pub fn new(flags: &Flags, permissions: &Permissions) -> Result<Self> {
pub fn new(
global_state: &Arc<GlobalState>,
permissions: Permissions,
) -> Result<Self> {
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;

View file

@ -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