summaryrefslogtreecommitdiff
path: root/cli/cache/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/cache/mod.rs')
-rw-r--r--cli/cache/mod.rs29
1 files changed, 14 insertions, 15 deletions
diff --git a/cli/cache/mod.rs b/cli/cache/mod.rs
index 1d6a79963..5cc91f50f 100644
--- a/cli/cache/mod.rs
+++ b/cli/cache/mod.rs
@@ -4,6 +4,7 @@ use crate::args::CacheSetting;
use crate::errors::get_error_class_name;
use crate::file_fetcher::FetchOptions;
use crate::file_fetcher::FileFetcher;
+use crate::npm::CliNpmResolver;
use crate::util::fs::atomic_write_file;
use deno_ast::MediaType;
@@ -101,10 +102,10 @@ pub struct FetchCacher {
file_fetcher: Arc<FileFetcher>,
file_header_overrides: HashMap<ModuleSpecifier, HashMap<String, String>>,
global_http_cache: Arc<GlobalHttpCache>,
+ npm_resolver: Arc<dyn CliNpmResolver>,
parsed_source_cache: Arc<ParsedSourceCache>,
permissions: PermissionsContainer,
cache_info_enabled: bool,
- maybe_local_node_modules_url: Option<ModuleSpecifier>,
}
impl FetchCacher {
@@ -113,19 +114,19 @@ impl FetchCacher {
file_fetcher: Arc<FileFetcher>,
file_header_overrides: HashMap<ModuleSpecifier, HashMap<String, String>>,
global_http_cache: Arc<GlobalHttpCache>,
+ npm_resolver: Arc<dyn CliNpmResolver>,
parsed_source_cache: Arc<ParsedSourceCache>,
permissions: PermissionsContainer,
- maybe_local_node_modules_url: Option<ModuleSpecifier>,
) -> Self {
Self {
emit_cache,
file_fetcher,
file_header_overrides,
global_http_cache,
+ npm_resolver,
parsed_source_cache,
permissions,
cache_info_enabled: false,
- maybe_local_node_modules_url,
}
}
@@ -214,20 +215,18 @@ impl Loader for FetchCacher {
) -> LoadFuture {
use deno_graph::source::CacheSetting as LoaderCacheSetting;
- if let Some(node_modules_url) = self.maybe_local_node_modules_url.as_ref() {
+ if specifier.path().contains("/node_modules/") {
// The specifier might be in a completely different symlinked tree than
- // what the resolved node_modules_url is in (ex. `/my-project-1/node_modules`
- // symlinked to `/my-project-2/node_modules`), so first check if the path
- // is in a node_modules dir to avoid needlessly canonicalizing, then compare
+ // 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.
- if specifier.path().contains("/node_modules/") {
- let specifier =
- crate::node::resolve_specifier_into_node_modules(specifier);
- if specifier.as_str().starts_with(node_modules_url.as_str()) {
- return Box::pin(futures::future::ready(Ok(Some(
- LoadResponse::External { 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 },
+ ))));
}
}