mirror of
https://github.com/denoland/deno.git
synced 2025-01-21 04:52:26 -05:00
perf: remove now needless canonicalization getting closest package.json (#27437)
This is no longer required because we now store everything in the file system for deno compile instead of in an eszip.
This commit is contained in:
parent
ece718eb3e
commit
77e1af79bd
2 changed files with 1 additions and 49 deletions
|
@ -320,7 +320,6 @@ impl NodeJsErrorCoded for PackageJsonLoadError {
|
||||||
impl NodeJsErrorCoded for ClosestPkgJsonError {
|
impl NodeJsErrorCoded for ClosestPkgJsonError {
|
||||||
fn code(&self) -> NodeJsErrorCode {
|
fn code(&self) -> NodeJsErrorCode {
|
||||||
match self.as_kind() {
|
match self.as_kind() {
|
||||||
ClosestPkgJsonErrorKind::CanonicalizingDir(e) => e.code(),
|
|
||||||
ClosestPkgJsonErrorKind::Load(e) => e.code(),
|
ClosestPkgJsonErrorKind::Load(e) => e.code(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -331,26 +330,10 @@ pub struct ClosestPkgJsonError(pub Box<ClosestPkgJsonErrorKind>);
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum ClosestPkgJsonErrorKind {
|
pub enum ClosestPkgJsonErrorKind {
|
||||||
#[error(transparent)]
|
|
||||||
CanonicalizingDir(#[from] CanonicalizingPkgJsonDirError),
|
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Load(#[from] PackageJsonLoadError),
|
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
|
// todo(https://github.com/denoland/deno_core/issues/810): make this a TypeError
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
#[error(
|
#[error(
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
use deno_package_json::PackageJson;
|
use deno_package_json::PackageJson;
|
||||||
use deno_package_json::PackageJsonRc;
|
use deno_package_json::PackageJsonRc;
|
||||||
use deno_path_util::strip_unc_prefix;
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::io::ErrorKind;
|
use std::io::ErrorKind;
|
||||||
|
@ -11,7 +10,6 @@ use std::path::PathBuf;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use crate::env::NodeResolverEnv;
|
use crate::env::NodeResolverEnv;
|
||||||
use crate::errors::CanonicalizingPkgJsonDirError;
|
|
||||||
use crate::errors::ClosestPkgJsonError;
|
use crate::errors::ClosestPkgJsonError;
|
||||||
use crate::errors::PackageJsonLoadError;
|
use crate::errors::PackageJsonLoadError;
|
||||||
|
|
||||||
|
@ -67,37 +65,8 @@ impl<TEnv: NodeResolverEnv> PackageJsonResolver<TEnv> {
|
||||||
&self,
|
&self,
|
||||||
file_path: &Path,
|
file_path: &Path,
|
||||||
) -> Result<Option<PackageJsonRc>, ClosestPkgJsonError> {
|
) -> 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 parent_dir = file_path.parent().unwrap();
|
||||||
let Some(start_dir) = canonicalize_first_ancestor_exists(
|
for current_dir in parent_dir.ancestors() {
|
||||||
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() {
|
|
||||||
let package_json_path = current_dir.join("package.json");
|
let package_json_path = current_dir.join("package.json");
|
||||||
if let Some(pkg_json) = self.load_package_json(&package_json_path)? {
|
if let Some(pkg_json) = self.load_package_json(&package_json_path)? {
|
||||||
return Ok(Some(pkg_json));
|
return Ok(Some(pkg_json));
|
||||||
|
|
Loading…
Add table
Reference in a new issue