1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-05 13:59:01 -05:00

fix(npm): canonicalize search directory when looking for package.json (#18981)

Co-authored-by: David Sherret <dsherret@gmail.com>
This commit is contained in:
Bartek Iwańczuk 2023-05-04 02:48:23 +02:00 committed by Levente Kurusa
parent 979742dee5
commit 6063bef0c1
No known key found for this signature in database
GPG key ID: 9F72F3C05BA137C4

View file

@ -1078,14 +1078,17 @@ impl NodeResolver {
url: &ModuleSpecifier,
) -> Result<PathBuf, AnyError> {
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");