From 6063bef0c13f14185a32bde77d5dbb17aa4c3a7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 4 May 2023 02:48:23 +0200 Subject: [PATCH] fix(npm): canonicalize search directory when looking for package.json (#18981) Co-authored-by: David Sherret --- ext/node/resolution.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ext/node/resolution.rs b/ext/node/resolution.rs index 0c90fffb6e..046c774fa2 100644 --- a/ext/node/resolution.rs +++ b/ext/node/resolution.rs @@ -1078,14 +1078,17 @@ impl NodeResolver { url: &ModuleSpecifier, ) -> Result { let file_path = url.to_file_path().unwrap(); - let mut current_dir = file_path.parent().unwrap(); + let current_dir = deno_core::strip_unc_prefix( + self.fs.canonicalize(file_path.parent().unwrap())?, + ); + let mut current_dir = current_dir.as_path(); let package_json_path = current_dir.join("package.json"); if self.fs.exists(&package_json_path) { return Ok(package_json_path); } let root_pkg_folder = self .npm_resolver - .resolve_package_folder_from_path(&url.to_file_path().unwrap())?; + .resolve_package_folder_from_path(current_dir)?; while current_dir.starts_with(&root_pkg_folder) { current_dir = current_dir.parent().unwrap(); let package_json_path = current_dir.join("package.json");