diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2022-11-28 17:28:54 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-28 17:28:54 -0500 |
commit | 2d4c46c975eb916dc622cc729a1a8d397582a76f (patch) | |
tree | 445e819117acd2f94ffc9d7da7ed8e3e604435d0 /cli/npm | |
parent | f526513d74d34ac254aa40ef9b73238cb21c395b (diff) |
refactor: create util folder, move nap_sym to napi/sym, move http_cache to cache folder (#16857)
Diffstat (limited to 'cli/npm')
-rw-r--r-- | cli/npm/cache.rs | 21 | ||||
-rw-r--r-- | cli/npm/registry.rs | 10 | ||||
-rw-r--r-- | cli/npm/resolvers/global.rs | 3 | ||||
-rw-r--r-- | cli/npm/resolvers/local.rs | 15 | ||||
-rw-r--r-- | cli/npm/resolvers/mod.rs | 4 |
5 files changed, 26 insertions, 27 deletions
diff --git a/cli/npm/cache.rs b/cli/npm/cache.rs index 5e2f06ef7..ad6ab9db2 100644 --- a/cli/npm/cache.rs +++ b/cli/npm/cache.rs @@ -14,11 +14,13 @@ use deno_core::error::AnyError; use deno_core::parking_lot::Mutex; use deno_core::url::Url; +use crate::args::CacheSetting; use crate::cache::DenoDir; -use crate::file_fetcher::CacheSetting; -use crate::fs_util; use crate::http_util::HttpClient; -use crate::progress_bar::ProgressBar; +use crate::util::fs::canonicalize_path; +use crate::util::fs::hard_link_dir_recursive; +use crate::util::path::root_url_to_safe_local_dirname; +use crate::util::progress_bar::ProgressBar; use super::registry::NpmPackageVersionDistInfo; use super::semver::NpmVersion; @@ -162,7 +164,7 @@ impl ReadonlyNpmCache { std::fs::create_dir_all(root_dir) .with_context(|| format!("Error creating {}", root_dir.display()))?; } - Ok(crate::fs_util::canonicalize_path(root_dir)?) + Ok(canonicalize_path(root_dir)?) } // this may fail on readonly file systems, so just ignore if so @@ -227,7 +229,7 @@ impl ReadonlyNpmCache { pub fn registry_folder(&self, registry_url: &Url) -> PathBuf { self .root_dir - .join(fs_util::root_url_to_safe_local_dirname(registry_url)) + .join(root_url_to_safe_local_dirname(registry_url)) } pub fn resolve_package_folder_id_from_specifier( @@ -252,7 +254,7 @@ impl ReadonlyNpmCache { .root_dir_url .join(&format!( "{}/", - fs_util::root_url_to_safe_local_dirname(registry_url) + root_url_to_safe_local_dirname(registry_url) .to_string_lossy() .replace('\\', "/") )) @@ -457,12 +459,7 @@ impl NpmCache { with_folder_sync_lock( (id.name.as_str(), &id.version), &package_folder, - || { - fs_util::hard_link_dir_recursive( - &original_package_folder, - &package_folder, - ) - }, + || hard_link_dir_recursive(&original_package_folder, &package_folder), )?; Ok(()) } diff --git a/cli/npm/registry.rs b/cli/npm/registry.rs index c62e6e1e7..9ba565366 100644 --- a/cli/npm/registry.rs +++ b/cli/npm/registry.rs @@ -21,11 +21,11 @@ use deno_core::url::Url; use deno_runtime::colors; use serde::Serialize; -use crate::file_fetcher::CacheSetting; -use crate::fs_util; -use crate::http_cache::CACHE_PERM; +use crate::args::CacheSetting; +use crate::cache::CACHE_PERM; use crate::http_util::HttpClient; -use crate::progress_bar::ProgressBar; +use crate::util::fs::atomic_write_file; +use crate::util::progress_bar::ProgressBar; use super::cache::NpmCache; use super::resolution::NpmVersionMatcher; @@ -405,7 +405,7 @@ impl RealNpmRegistryApiInner { let file_cache_path = self.get_package_file_cache_path(name); let file_text = serde_json::to_string(&package_info)?; std::fs::create_dir_all(file_cache_path.parent().unwrap())?; - fs_util::atomic_write_file(&file_cache_path, file_text, CACHE_PERM)?; + atomic_write_file(&file_cache_path, file_text, CACHE_PERM)?; Ok(()) } diff --git a/cli/npm/resolvers/global.rs b/cli/npm/resolvers/global.rs index 044c889d8..46cfec48f 100644 --- a/cli/npm/resolvers/global.rs +++ b/cli/npm/resolvers/global.rs @@ -16,7 +16,6 @@ use deno_runtime::deno_node::PackageJson; use deno_runtime::deno_node::TYPES_CONDITIONS; use crate::args::Lockfile; -use crate::fs_util; use crate::npm::resolution::NpmResolution; use crate::npm::resolution::NpmResolutionSnapshot; use crate::npm::resolvers::common::cache_packages; @@ -125,7 +124,7 @@ impl InnerNpmPackageResolver for GlobalNpmPackageResolver { fn package_size(&self, package_id: &NpmPackageId) -> Result<u64, AnyError> { let package_folder = self.package_folder(package_id); - Ok(fs_util::dir_size(&package_folder)?) + Ok(crate::util::fs::dir_size(&package_folder)?) } fn has_packages(&self) -> bool { diff --git a/cli/npm/resolvers/local.rs b/cli/npm/resolvers/local.rs index ff699f26f..3a9e97433 100644 --- a/cli/npm/resolvers/local.rs +++ b/cli/npm/resolvers/local.rs @@ -10,6 +10,7 @@ use std::path::Path; use std::path::PathBuf; use std::sync::Arc; +use crate::util::fs::symlink_dir; use deno_ast::ModuleSpecifier; use deno_core::anyhow::bail; use deno_core::anyhow::Context; @@ -23,7 +24,6 @@ use deno_runtime::deno_node::TYPES_CONDITIONS; use tokio::task::JoinHandle; use crate::args::Lockfile; -use crate::fs_util; use crate::npm::cache::mixed_case_package_name_encode; use crate::npm::cache::should_sync_download; use crate::npm::cache::NpmPackageCacheFolderId; @@ -34,6 +34,8 @@ use crate::npm::NpmPackageId; use crate::npm::NpmPackageReq; use crate::npm::NpmResolutionPackage; use crate::npm::RealNpmRegistryApi; +use crate::util::fs::copy_dir_recursive; +use crate::util::fs::hard_link_dir_recursive; use super::common::ensure_registry_read_permission; use super::common::types_package_name; @@ -203,7 +205,7 @@ impl InnerNpmPackageResolver for LocalNpmPackageResolver { fn package_size(&self, package_id: &NpmPackageId) -> Result<u64, AnyError> { let package_folder_path = self.get_package_id_folder(package_id)?; - Ok(fs_util::dir_size(&package_folder_path)?) + Ok(crate::util::fs::dir_size(&package_folder_path)?) } fn has_packages(&self) -> bool { @@ -318,7 +320,7 @@ async fn sync_resolution_with_fs( ®istry_url, ); // for now copy, but in the future consider hard linking - fs_util::copy_dir_recursive(&cache_folder, &package_path)?; + copy_dir_recursive(&cache_folder, &package_path)?; // write out a file that indicates this folder has been initialized fs::write(initialized_file, "")?; Ok(()) @@ -356,7 +358,7 @@ async fn sync_resolution_with_fs( .join("node_modules"), &package.id.name, ); - fs_util::hard_link_dir_recursive(&source_path, &package_path)?; + hard_link_dir_recursive(&source_path, &package_path)?; // write out a file that indicates this folder has been initialized fs::write(initialized_file, "")?; } @@ -467,7 +469,7 @@ fn symlink_package_dir( #[cfg(windows)] return junction_or_symlink_dir(old_path, new_path); #[cfg(not(windows))] - fs_util::symlink_dir(old_path, new_path) + symlink_dir(old_path, new_path) } #[cfg(windows)] @@ -477,6 +479,7 @@ fn junction_or_symlink_dir( ) -> Result<(), AnyError> { // Use junctions because they're supported on ntfs file systems without // needing to elevate privileges on Windows + match junction::create(old_path, new_path) { Ok(()) => Ok(()), Err(junction_err) => { @@ -486,7 +489,7 @@ fn junction_or_symlink_dir( log::warn!("Error creating junction. {:#}", junction_err); } - match fs_util::symlink_dir(old_path, new_path) { + match symlink_dir(old_path, new_path) { Ok(()) => Ok(()), Err(symlink_err) => bail!( concat!( diff --git a/cli/npm/resolvers/mod.rs b/cli/npm/resolvers/mod.rs index 869874c8b..3cc695523 100644 --- a/cli/npm/resolvers/mod.rs +++ b/cli/npm/resolvers/mod.rs @@ -23,7 +23,7 @@ use std::path::PathBuf; use std::sync::Arc; use crate::args::Lockfile; -use crate::fs_util; +use crate::util::fs::canonicalize_path_maybe_not_exists; use self::common::InnerNpmPackageResolver; use self::local::LocalNpmPackageResolver; @@ -187,7 +187,7 @@ impl NpmPackageResolver { let path = self .inner .resolve_package_folder_from_deno_module(pkg_req)?; - let path = fs_util::canonicalize_path_maybe_not_exists(&path)?; + let path = canonicalize_path_maybe_not_exists(&path)?; log::debug!("Resolved {} to {}", pkg_req, path.display()); Ok(path) } |