refactor(npm): extract out some npm fs resolution code from the cli (#27607)

Moves the npm fs resolvers into the deno_resolution crate.

This does not entirely move things out, but is a step in that direction.
This commit is contained in:
David Sherret 2025-01-09 12:10:07 -05:00 committed by GitHub
parent ce0968ef3a
commit 093f3ba565
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 312 additions and 213 deletions

View file

@ -6,7 +6,6 @@ use std::path::Path;
use std::path::PathBuf;
use std::sync::Arc;
use anyhow::Error as AnyError;
use deno_cache_dir::file_fetcher::CacheSetting;
use deno_cache_dir::npm::NpmCacheDir;
use deno_error::JsErrorBox;
@ -51,7 +50,7 @@ pub use tarball::TarballCache;
#[class(generic)]
pub struct DownloadError {
pub status_code: Option<StatusCode>,
pub error: AnyError,
pub error: JsErrorBox,
}
impl std::error::Error for DownloadError {
@ -312,15 +311,17 @@ impl<
&self,
name: &str,
package_info: &NpmPackageInfo,
) -> Result<(), AnyError> {
) -> Result<(), JsErrorBox> {
let file_cache_path = self.get_registry_package_info_file_cache_path(name);
let file_text = serde_json::to_string(&package_info)?;
let file_text =
serde_json::to_string(&package_info).map_err(JsErrorBox::from_err)?;
atomic_write_file_with_retries(
&self.sys,
&file_cache_path,
file_text.as_bytes(),
0o644,
)?;
)
.map_err(JsErrorBox::from_err)?;
Ok(())
}