diff --git a/Cargo.lock b/Cargo.lock index d16aafe6f0..71979d448a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7762,9 +7762,9 @@ dependencies = [ [[package]] name = "sys_traits" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1c12873696bde6de3aea3cd27de8e52897177c5b368a6a30987fd4926e30f85" +checksum = "5b46ac05dfbe9fd3a9703eff20e17f5b31e7b6a54daf27a421dcd56c7a27ecdd" dependencies = [ "filetime", "getrandom", diff --git a/Cargo.toml b/Cargo.toml index b7c7219fba..48abe48305 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -193,7 +193,7 @@ slab = "0.4" smallvec = "1.8" socket2 = { version = "0.5.3", features = ["all"] } spki = "0.7.2" -sys_traits = "=0.1.6" +sys_traits = "=0.1.7" tar = "=0.4.40" tempfile = "3.4.0" termcolor = "1.1.3" diff --git a/cli/npm/mod.rs b/cli/npm/mod.rs index 9ac478732d..837fe26cf9 100644 --- a/cli/npm/mod.rs +++ b/cli/npm/mod.rs @@ -136,7 +136,7 @@ pub enum InnerCliNpmResolverRef<'a> { Byonm(&'a CliByonmNpmResolver), } -pub trait CliNpmResolver: NpmPackageFolderResolver + CliNpmReqResolver { +pub trait CliNpmResolver: CliNpmReqResolver { fn into_npm_pkg_folder_resolver( self: Arc, ) -> Arc; diff --git a/resolvers/deno/npm/byonm.rs b/resolvers/deno/npm/byonm.rs index e9aad66e3f..710608490a 100644 --- a/resolvers/deno/npm/byonm.rs +++ b/resolvers/deno/npm/byonm.rs @@ -400,14 +400,14 @@ impl< } impl< - Sys: FsCanonicalize + TSys: FsCanonicalize + FsMetadata + FsRead + FsReadDir + Send + Sync + std::fmt::Debug, - > NpmPackageFolderResolver for ByonmNpmResolver + > NpmPackageFolderResolver for ByonmNpmResolver { fn resolve_package_folder_from_package( &self, diff --git a/resolvers/deno/npm/managed/common.rs b/resolvers/deno/npm/managed/common.rs index 5a4a517bf0..8a523f3ea4 100644 --- a/resolvers/deno/npm/managed/common.rs +++ b/resolvers/deno/npm/managed/common.rs @@ -3,10 +3,9 @@ use std::path::Path; use std::path::PathBuf; -use async_trait::async_trait; use deno_npm::NpmPackageCacheFolderId; use deno_npm::NpmPackageId; -use node_resolver::errors::PackageFolderResolveError; +use node_resolver::NpmPackageFolderResolver; use url::Url; use crate::sync::MaybeSend; @@ -22,8 +21,9 @@ pub(super) type NpmPackageFsResolverRc = pub struct NpmPackageFsResolverPackageFolderError(deno_semver::StackString); /// Part of the resolution that interacts with the file system. -#[async_trait(?Send)] -pub trait NpmPackageFsResolver: MaybeSend + MaybeSync { +pub trait NpmPackageFsResolver: + NpmPackageFolderResolver + MaybeSend + MaybeSync +{ /// The local node_modules folder if it is applicable to the implementation. fn node_modules_path(&self) -> Option<&Path>; @@ -38,12 +38,6 @@ pub trait NpmPackageFsResolver: MaybeSend + MaybeSync { }) } - fn resolve_package_folder_from_package( - &self, - name: &str, - referrer: &Url, - ) -> Result; - fn resolve_package_cache_folder_id_from_specifier( &self, specifier: &Url, diff --git a/resolvers/deno/npm/managed/global.rs b/resolvers/deno/npm/managed/global.rs index 16a2bc7a70..cffe68a30e 100644 --- a/resolvers/deno/npm/managed/global.rs +++ b/resolvers/deno/npm/managed/global.rs @@ -5,7 +5,6 @@ use std::path::Path; use std::path::PathBuf; -use async_trait::async_trait; use deno_npm::NpmPackageCacheFolderId; use deno_npm::NpmPackageId; use deno_semver::package::PackageNv; @@ -14,6 +13,7 @@ use deno_semver::Version; use node_resolver::errors::PackageFolderResolveError; use node_resolver::errors::PackageNotFoundError; use node_resolver::errors::ReferrerNotFoundError; +use node_resolver::NpmPackageFolderResolver; use url::Url; use super::resolution::NpmResolutionRc; @@ -61,25 +61,7 @@ impl GlobalNpmPackageResolver { } } -#[async_trait(?Send)] -impl NpmPackageFsResolver for GlobalNpmPackageResolver { - fn node_modules_path(&self) -> Option<&Path> { - None - } - - fn maybe_package_folder(&self, id: &NpmPackageId) -> Option { - let folder_copy_index = self - .resolution - .resolve_pkg_cache_folder_copy_index_from_pkg_id(id)?; - let registry_url = self.npm_rc.get_registry_url(&id.nv.name); - Some(self.cache.package_folder_for_id( - &id.nv.name, - &id.nv.version.to_string(), - folder_copy_index, - registry_url, - )) - } - +impl NpmPackageFolderResolver for GlobalNpmPackageResolver { fn resolve_package_folder_from_package( &self, name: &str, @@ -138,6 +120,25 @@ impl NpmPackageFsResolver for GlobalNpmPackageResolver { }, } } +} + +impl NpmPackageFsResolver for GlobalNpmPackageResolver { + fn node_modules_path(&self) -> Option<&Path> { + None + } + + fn maybe_package_folder(&self, id: &NpmPackageId) -> Option { + let folder_copy_index = self + .resolution + .resolve_pkg_cache_folder_copy_index_from_pkg_id(id)?; + let registry_url = self.npm_rc.get_registry_url(&id.nv.name); + Some(self.cache.package_folder_for_id( + &id.nv.name, + &id.nv.version.to_string(), + folder_copy_index, + registry_url, + )) + } fn resolve_package_cache_folder_id_from_specifier( &self, diff --git a/resolvers/deno/npm/managed/local.rs b/resolvers/deno/npm/managed/local.rs index e84de964ad..f23f7bd591 100644 --- a/resolvers/deno/npm/managed/local.rs +++ b/resolvers/deno/npm/managed/local.rs @@ -6,7 +6,6 @@ use std::borrow::Cow; use std::path::Path; use std::path::PathBuf; -use async_trait::async_trait; use deno_npm::NpmPackageCacheFolderId; use deno_npm::NpmPackageId; use deno_path_util::fs::canonicalize_path_maybe_not_exists; @@ -15,6 +14,7 @@ use node_resolver::errors::PackageFolderResolveError; use node_resolver::errors::PackageFolderResolveIoError; use node_resolver::errors::PackageNotFoundError; use node_resolver::errors::ReferrerNotFoundError; +use node_resolver::NpmPackageFolderResolver; use sys_traits::FsCanonicalize; use sys_traits::FsMetadata; use url::Url; @@ -99,33 +99,9 @@ impl } } -#[async_trait(?Send)] -impl NpmPackageFsResolver - for LocalNpmPackageResolver +impl + NpmPackageFolderResolver for LocalNpmPackageResolver { - fn node_modules_path(&self) -> Option<&Path> { - Some(self.root_node_modules_path.as_ref()) - } - - fn maybe_package_folder(&self, id: &NpmPackageId) -> Option { - let folder_copy_index = self - .resolution - .resolve_pkg_cache_folder_copy_index_from_pkg_id(id)?; - // package is stored at: - // node_modules/.deno//node_modules/ - Some( - self - .root_node_modules_path - .join(".deno") - .join(get_package_folder_id_folder_name_from_parts( - &id.nv, - folder_copy_index, - )) - .join("node_modules") - .join(&id.nv.name), - ) - } - fn resolve_package_folder_from_package( &self, name: &str, @@ -159,7 +135,13 @@ impl NpmPackageFsResolver let sub_dir = join_package_name(&node_modules_folder, name); if self.sys.fs_is_dir_no_err(&sub_dir) { - return Ok(sub_dir); + return Ok(self.sys.fs_canonicalize(&sub_dir).map_err(|err| { + PackageFolderResolveIoError { + package_name: name.to_string(), + referrer: referrer.clone(), + source: err, + } + })?); } if current_folder == self.root_node_modules_path { @@ -176,6 +158,33 @@ impl NpmPackageFsResolver .into(), ) } +} + +impl + NpmPackageFsResolver for LocalNpmPackageResolver +{ + fn node_modules_path(&self) -> Option<&Path> { + Some(self.root_node_modules_path.as_ref()) + } + + fn maybe_package_folder(&self, id: &NpmPackageId) -> Option { + let folder_copy_index = self + .resolution + .resolve_pkg_cache_folder_copy_index_from_pkg_id(id)?; + // package is stored at: + // node_modules/.deno//node_modules/ + Some( + self + .root_node_modules_path + .join(".deno") + .join(get_package_folder_id_folder_name_from_parts( + &id.nv, + folder_copy_index, + )) + .join("node_modules") + .join(&id.nv.name), + ) + } fn resolve_package_cache_folder_id_from_specifier( &self, diff --git a/resolvers/deno/npm/managed/mod.rs b/resolvers/deno/npm/managed/mod.rs index 53b07f7d90..d08ee07d6a 100644 --- a/resolvers/deno/npm/managed/mod.rs +++ b/resolvers/deno/npm/managed/mod.rs @@ -25,7 +25,7 @@ use crate::NpmCacheDirRc; use crate::ResolvedNpmRcRc; pub fn create_npm_fs_resolver< - TSys: FsCanonicalize + FsMetadata + Send + Sync + 'static, + TSys: FsCanonicalize + FsMetadata + std::fmt::Debug + Send + Sync + 'static, >( npm_cache_dir: &NpmCacheDirRc, npm_rc: &ResolvedNpmRcRc,