summaryrefslogtreecommitdiff
path: root/cli/cache/mod.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-02-23 10:58:10 -0500
committerGitHub <noreply@github.com>2023-02-23 10:58:10 -0500
commit344317ec501fa124f0c74b44035fa4516999dce6 (patch)
tree3a0e4ca3d83b1a47a0903f08648ef1b896b32195 /cli/cache/mod.rs
parent214bdbbc2b09ab3f56f0ffe1ad5930d48ec0c76f (diff)
feat(npm): support bare specifiers from package.json in more subcommands and language server (#17891)
Diffstat (limited to 'cli/cache/mod.rs')
-rw-r--r--cli/cache/mod.rs24
1 files changed, 18 insertions, 6 deletions
diff --git a/cli/cache/mod.rs b/cli/cache/mod.rs
index 6c50c4c8b..90f88530f 100644
--- a/cli/cache/mod.rs
+++ b/cli/cache/mod.rs
@@ -2,6 +2,7 @@
use crate::errors::get_error_class_name;
use crate::file_fetcher::FileFetcher;
+use crate::util::fs::canonicalize_path;
use deno_core::futures;
use deno_core::futures::FutureExt;
@@ -101,12 +102,23 @@ impl Loader for FetchCacher {
is_dynamic: bool,
) -> LoadFuture {
if let Some(node_modules_url) = self.maybe_local_node_modules_url.as_ref() {
- if specifier.as_str().starts_with(node_modules_url.as_str()) {
- return Box::pin(futures::future::ready(Ok(Some(
- LoadResponse::External {
- specifier: specifier.clone(),
- },
- ))));
+ // 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
+ // against the canonicalized specifier.
+ if specifier.path().contains("/node_modules/") {
+ let specifier = specifier
+ .to_file_path()
+ .ok()
+ .and_then(|path| canonicalize_path(&path).ok())
+ .and_then(|path| ModuleSpecifier::from_file_path(path).ok())
+ .unwrap_or_else(|| specifier.clone());
+ if specifier.as_str().starts_with(node_modules_url.as_str()) {
+ return Box::pin(futures::future::ready(Ok(Some(
+ LoadResponse::External { specifier },
+ ))));
+ }
}
}