Repository: denoland/deno
Pull request: perf: remove now needless canonicalization getting closest package.json

This is no longer required because we now store everything in the file system for deno compile instead of in an eszip.

Before:

```
Timer precision: 41 ns
bench          fastest       │ slowest       │ median        │ mean          │ samples │ iters
╰─ resolution  217.7 µs      │ 715.5 µs      │ 227.2 µs      │ 233.4 µs      │ 1000    │ 1000
```

After:

```
Timer precision: 41 ns
bench          fastest       │ slowest       │ median        │ mean          │ samples │ iters
╰─ resolution  191.1 µs      │ 768.7 µs      │ 198.2 µs      │ 205.4 µs      │ 1000    │ 1000
```

(My system is noisy, not doing a proper bench, but it removes some fs operations so going to be faster)

Changed files:
filename: resolvers/node/errors.rs
patch: @@ -320,7 +320,6 @@ impl NodeJsErrorCoded for PackageJsonLoadError {
 impl NodeJsErrorCoded for ClosestPkgJsonError {
   fn code(&self) -> NodeJsErrorCode {
     match self.as_kind() {
-      ClosestPkgJsonErrorKind::CanonicalizingDir(e) => e.code(),
       ClosestPkgJsonErrorKind::Load(e) => e.code(),
     }
   }
@@ -331,26 +330,10 @@ pub struct ClosestPkgJsonError(pub Box<ClosestPkgJsonErrorKind>);
 
 #[derive(Debug, Error)]
 pub enum ClosestPkgJsonErrorKind {
-  #[error(transparent)]
-  CanonicalizingDir(#[from] CanonicalizingPkgJsonDirError),
   #[error(transparent)]
   Load(#[from] PackageJsonLoadError),
 }
 
-#[derive(Debug, Error)]
-#[error("[{}] Failed canonicalizing package.json directory '{}'.", self.code(), dir_path.display())]
-pub struct CanonicalizingPkgJsonDirError {
-  pub dir_path: PathBuf,
-  #[source]
-  pub source: std::io::Error,
-}
-
-impl NodeJsErrorCoded for CanonicalizingPkgJsonDirError {
-  fn code(&self) -> NodeJsErrorCode {
-    NodeJsErrorCode::ERR_MODULE_NOT_FOUND
-  }
-}
-
 // todo(https://github.com/denoland/deno_core/issues/810): make this a TypeError
 #[derive(Debug, Error)]
 #[error(

filename: resolvers/node/package_json.rs
patch: @@ -2,7 +2,6 @@
 
 use deno_package_json::PackageJson;
 use deno_package_json::PackageJsonRc;
-use deno_path_util::strip_unc_prefix;
 use std::cell::RefCell;
 use std::collections::HashMap;
 use std::io::ErrorKind;
@@ -11,7 +10,6 @@ use std::path::PathBuf;
 use url::Url;
 
 use crate::env::NodeResolverEnv;
-use crate::errors::CanonicalizingPkgJsonDirError;
 use crate::errors::ClosestPkgJsonError;
 use crate::errors::PackageJsonLoadError;
 
@@ -67,37 +65,8 @@ impl<TEnv: NodeResolverEnv> PackageJsonResolver<TEnv> {
     &self,
     file_path: &Path,
   ) -> Result<Option<PackageJsonRc>, ClosestPkgJsonError> {
-    // we use this for deno compile using byonm because the script paths
-    // won't be in virtual file system, but the package.json paths will be
-    fn canonicalize_first_ancestor_exists<TEnv: NodeResolverEnv>(
-      dir_path: &Path,
-      env: &TEnv,
-    ) -> Result<Option<PathBuf>, std::io::Error> {
-      for ancestor in dir_path.ancestors() {
-        match env.realpath_sync(ancestor) {
-          Ok(dir_path) => return Ok(Some(dir_path)),
-          Err(err) if err.kind() == std::io::ErrorKind::NotFound => {
-            // keep searching
-          }
-          Err(err) => return Err(err),
-        }
-      }
-      Ok(None)
-    }
-
     let parent_dir = file_path.parent().unwrap();
-    let Some(start_dir) = canonicalize_first_ancestor_exists(
-      parent_dir, &self.env,
-    )
-    .map_err(|source| CanonicalizingPkgJsonDirError {
-      dir_path: parent_dir.to_path_buf(),
-      source,
-    })?
-    else {
-      return Ok(None);
-    };
-    let start_dir = strip_unc_prefix(start_dir);
-    for current_dir in start_dir.ancestors() {
+    for current_dir in parent_dir.ancestors() {
       let package_json_path = current_dir.join("package.json");
       if let Some(pkg_json) = self.load_package_json(&package_json_path)? {
         return Ok(Some(pkg_json));