diff options
Diffstat (limited to 'cli/cache')
-rw-r--r-- | cli/cache/emit.rs | 13 | ||||
-rw-r--r-- | cli/cache/mod.rs | 60 |
2 files changed, 26 insertions, 47 deletions
diff --git a/cli/cache/emit.rs b/cli/cache/emit.rs index 5e89f9a90..6807f06c1 100644 --- a/cli/cache/emit.rs +++ b/cli/cache/emit.rs @@ -82,19 +82,6 @@ impl EmitCache { Ok(()) } - /// Gets the filepath which stores the emit. - pub fn get_emit_filepath( - &self, - specifier: &ModuleSpecifier, - ) -> Option<PathBuf> { - Some( - self - .disk_cache - .location - .join(self.get_emit_filename(specifier)?), - ) - } - fn get_emit_filename(&self, specifier: &ModuleSpecifier) -> Option<PathBuf> { self .disk_cache diff --git a/cli/cache/mod.rs b/cli/cache/mod.rs index 4500e3a4a..3b4e27760 100644 --- a/cli/cache/mod.rs +++ b/cli/cache/mod.rs @@ -8,6 +8,7 @@ use crate::file_fetcher::FileFetcher; use crate::file_fetcher::FileOrRedirect; use crate::npm::CliNpmResolver; use crate::util::fs::atomic_write_file_with_retries; +use crate::util::path::specifier_has_extension; use deno_ast::MediaType; use deno_core::futures; @@ -106,7 +107,6 @@ pub use deno_cache_dir::HttpCache; /// A "wrapper" for the FileFetcher and DiskCache for the Deno CLI that provides /// a concise interface to the DENO_DIR when building module graphs. pub struct FetchCacher { - emit_cache: Arc<EmitCache>, file_fetcher: Arc<FileFetcher>, file_header_overrides: HashMap<ModuleSpecifier, HashMap<String, String>>, global_http_cache: Arc<GlobalHttpCache>, @@ -118,7 +118,6 @@ pub struct FetchCacher { impl FetchCacher { pub fn new( - emit_cache: Arc<EmitCache>, file_fetcher: Arc<FileFetcher>, file_header_overrides: HashMap<ModuleSpecifier, HashMap<String, String>>, global_http_cache: Arc<GlobalHttpCache>, @@ -127,7 +126,6 @@ impl FetchCacher { permissions: PermissionsContainer, ) -> Self { Self { - emit_cache, file_fetcher, file_header_overrides, global_http_cache, @@ -144,15 +142,7 @@ impl FetchCacher { self.cache_info_enabled = true; } - // DEPRECATED: Where the file is stored and how it's stored should be an implementation - // detail of the cache. - // - // todo(dsheret): remove once implementing - // * https://github.com/denoland/deno/issues/17707 - // * https://github.com/denoland/deno/issues/17703 - #[deprecated( - note = "There should not be a way to do this because the file may not be cached at a local path in the future." - )] + /// Only use this for `deno info`. fn get_local_path(&self, specifier: &ModuleSpecifier) -> Option<PathBuf> { // TODO(@kitsonk) fix when deno_graph does not query cache for synthetic // modules @@ -179,15 +169,7 @@ impl Loader for FetchCacher { #[allow(deprecated)] let local = self.get_local_path(specifier)?; if local.is_file() { - let emit = self - .emit_cache - .get_emit_filepath(specifier) - .filter(|p| p.is_file()); - Some(CacheInfo { - local: Some(local), - emit, - map: None, - }) + Some(CacheInfo { local: Some(local) }) } else { None } @@ -200,19 +182,28 @@ impl Loader for FetchCacher { ) -> LoadFuture { use deno_graph::source::CacheSetting as LoaderCacheSetting; - if specifier.scheme() == "file" - && specifier.path().contains("/node_modules/") - { - // The specifier might be in a completely different symlinked tree than - // what the node_modules url is in (ex. `/my-project-1/node_modules` - // symlinked to `/my-project-2/node_modules`), so first we checked if the path - // is in a node_modules dir to avoid needlessly canonicalizing, then now compare - // against the canonicalized specifier. - let specifier = - crate::node::resolve_specifier_into_node_modules(specifier); - if self.npm_resolver.in_npm_package(&specifier) { + if specifier.scheme() == "file" { + if specifier.path().contains("/node_modules/") { + // The specifier might be in a completely different symlinked tree than + // what the node_modules url is in (ex. `/my-project-1/node_modules` + // symlinked to `/my-project-2/node_modules`), so first we checked if the path + // is in a node_modules dir to avoid needlessly canonicalizing, then now compare + // against the canonicalized specifier. + let specifier = + crate::node::resolve_specifier_into_node_modules(specifier); + if self.npm_resolver.in_npm_package(&specifier) { + return Box::pin(futures::future::ready(Ok(Some( + LoadResponse::External { specifier }, + )))); + } + } + + // make local CJS modules external to the graph + if specifier_has_extension(specifier, "cjs") { return Box::pin(futures::future::ready(Ok(Some( - LoadResponse::External { specifier }, + LoadResponse::External { + specifier: specifier.clone(), + }, )))); } } @@ -293,6 +284,7 @@ impl Loader for FetchCacher { fn cache_module_info( &self, specifier: &ModuleSpecifier, + media_type: MediaType, source: &Arc<[u8]>, module_info: &deno_graph::ModuleInfo, ) { @@ -300,7 +292,7 @@ impl Loader for FetchCacher { let source_hash = CacheDBHash::from_source(source); let result = self.module_info_cache.set_module_info( specifier, - MediaType::from_specifier(specifier), + media_type, source_hash, module_info, ); |