2023-01-02 16:00:42 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
2022-08-10 15:23:58 -04:00
|
|
|
|
|
|
|
use std::collections::HashMap;
|
2022-11-27 13:25:08 -05:00
|
|
|
use std::collections::HashSet;
|
2022-08-10 15:23:58 -04:00
|
|
|
use std::fs;
|
2022-08-22 11:35:04 -04:00
|
|
|
use std::io::ErrorKind;
|
2022-08-10 15:23:58 -04:00
|
|
|
use std::path::PathBuf;
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
2023-02-21 12:03:48 -05:00
|
|
|
use async_trait::async_trait;
|
2023-04-06 18:46:44 -04:00
|
|
|
use deno_core::anyhow::anyhow;
|
2022-08-10 15:23:58 -04:00
|
|
|
use deno_core::anyhow::Context;
|
2022-08-22 11:35:04 -04:00
|
|
|
use deno_core::error::custom_error;
|
2022-08-10 15:23:58 -04:00
|
|
|
use deno_core::error::AnyError;
|
2023-04-06 18:46:44 -04:00
|
|
|
use deno_core::futures::future::BoxFuture;
|
|
|
|
use deno_core::futures::future::Shared;
|
|
|
|
use deno_core::futures::FutureExt;
|
2022-08-10 15:23:58 -04:00
|
|
|
use deno_core::parking_lot::Mutex;
|
|
|
|
use deno_core::serde_json;
|
|
|
|
use deno_core::url::Url;
|
2023-04-06 18:46:44 -04:00
|
|
|
use deno_core::TaskQueue;
|
|
|
|
use deno_npm::registry::NpmPackageInfo;
|
|
|
|
use deno_npm::registry::NpmRegistryApi;
|
2023-04-06 21:41:19 -04:00
|
|
|
use deno_npm::registry::NpmRegistryPackageInfoLoadError;
|
2023-02-21 12:03:48 -05:00
|
|
|
use once_cell::sync::Lazy;
|
2022-08-10 15:23:58 -04:00
|
|
|
|
2022-11-28 17:28:54 -05:00
|
|
|
use crate::args::CacheSetting;
|
|
|
|
use crate::cache::CACHE_PERM;
|
2022-11-18 17:28:14 -05:00
|
|
|
use crate::http_util::HttpClient;
|
2022-11-28 17:28:54 -05:00
|
|
|
use crate::util::fs::atomic_write_file;
|
|
|
|
use crate::util::progress_bar::ProgressBar;
|
2023-04-11 18:10:51 -04:00
|
|
|
use crate::util::sync::AtomicFlag;
|
2022-08-10 15:23:58 -04:00
|
|
|
|
2023-02-21 12:03:48 -05:00
|
|
|
use super::cache::should_sync_download;
|
2022-08-10 15:23:58 -04:00
|
|
|
use super::cache::NpmCache;
|
|
|
|
|
2023-02-21 12:03:48 -05:00
|
|
|
static NPM_REGISTRY_DEFAULT_URL: Lazy<Url> = Lazy::new(|| {
|
|
|
|
let env_var_name = "NPM_CONFIG_REGISTRY";
|
|
|
|
if let Ok(registry_url) = std::env::var(env_var_name) {
|
|
|
|
// ensure there is a trailing slash for the directory
|
|
|
|
let registry_url = format!("{}/", registry_url.trim_end_matches('/'));
|
|
|
|
match Url::parse(®istry_url) {
|
|
|
|
Ok(url) => {
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
Err(err) => {
|
|
|
|
log::debug!("Invalid {} environment variable: {:#}", env_var_name, err,);
|
2022-11-08 14:17:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-11-11 11:33:57 -05:00
|
|
|
|
2023-02-21 12:03:48 -05:00
|
|
|
Url::parse("https://registry.npmjs.org").unwrap()
|
|
|
|
});
|
2022-08-10 15:23:58 -04:00
|
|
|
|
2023-04-14 16:22:33 -04:00
|
|
|
#[derive(Debug)]
|
2023-04-12 08:36:11 -04:00
|
|
|
pub struct CliNpmRegistryApi(Option<Arc<CliNpmRegistryApiInner>>);
|
2022-12-07 16:10:50 -05:00
|
|
|
|
2023-04-12 08:36:11 -04:00
|
|
|
impl CliNpmRegistryApi {
|
2023-02-21 12:03:48 -05:00
|
|
|
pub fn default_url() -> &'static Url {
|
|
|
|
&NPM_REGISTRY_DEFAULT_URL
|
2022-08-10 15:23:58 -04:00
|
|
|
}
|
|
|
|
|
2022-08-22 11:35:04 -04:00
|
|
|
pub fn new(
|
|
|
|
base_url: Url,
|
2023-04-14 16:22:33 -04:00
|
|
|
cache: Arc<NpmCache>,
|
2023-05-01 16:42:05 -04:00
|
|
|
http_client: Arc<HttpClient>,
|
2022-09-09 15:57:39 -04:00
|
|
|
progress_bar: ProgressBar,
|
2022-08-22 11:35:04 -04:00
|
|
|
) -> Self {
|
2023-04-12 08:36:11 -04:00
|
|
|
Self(Some(Arc::new(CliNpmRegistryApiInner {
|
2022-08-10 15:23:58 -04:00
|
|
|
base_url,
|
|
|
|
cache,
|
2023-04-11 18:10:51 -04:00
|
|
|
force_reload_flag: Default::default(),
|
2022-08-10 15:23:58 -04:00
|
|
|
mem_cache: Default::default(),
|
2022-11-27 13:25:08 -05:00
|
|
|
previously_reloaded_packages: Default::default(),
|
2022-11-18 17:28:14 -05:00
|
|
|
http_client,
|
2022-09-09 15:57:39 -04:00
|
|
|
progress_bar,
|
2023-04-06 18:46:44 -04:00
|
|
|
})))
|
2022-08-10 15:23:58 -04:00
|
|
|
}
|
|
|
|
|
2023-04-06 18:46:44 -04:00
|
|
|
/// Creates an npm registry API that will be uninitialized. This is
|
|
|
|
/// useful for tests or for initializing the LSP.
|
2023-02-22 14:15:25 -05:00
|
|
|
pub fn new_uninitialized() -> Self {
|
2023-04-06 18:46:44 -04:00
|
|
|
Self(None)
|
2023-02-21 12:03:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Clears the internal memory cache.
|
|
|
|
pub fn clear_memory_cache(&self) {
|
2023-04-06 18:46:44 -04:00
|
|
|
self.inner().clear_memory_cache();
|
2023-02-21 12:03:48 -05:00
|
|
|
}
|
|
|
|
|
2023-02-22 14:15:25 -05:00
|
|
|
pub fn get_cached_package_info(
|
|
|
|
&self,
|
|
|
|
name: &str,
|
|
|
|
) -> Option<Arc<NpmPackageInfo>> {
|
2023-04-06 18:46:44 -04:00
|
|
|
self.inner().get_cached_package_info(name)
|
2023-02-22 14:15:25 -05:00
|
|
|
}
|
|
|
|
|
2022-08-10 15:23:58 -04:00
|
|
|
pub fn base_url(&self) -> &Url {
|
2023-04-06 18:46:44 -04:00
|
|
|
&self.inner().base_url
|
2022-08-10 15:23:58 -04:00
|
|
|
}
|
2023-02-21 12:03:48 -05:00
|
|
|
|
2023-04-06 21:41:19 -04:00
|
|
|
/// Marks that new requests for package information should retrieve it
|
|
|
|
/// from the npm registry
|
|
|
|
///
|
|
|
|
/// Returns true if it was successfully set for the first time.
|
|
|
|
pub fn mark_force_reload(&self) -> bool {
|
2023-04-12 08:36:11 -04:00
|
|
|
// never force reload the registry information if reloading
|
|
|
|
// is disabled or if we're already reloading
|
|
|
|
if matches!(
|
|
|
|
self.inner().cache.cache_setting(),
|
|
|
|
CacheSetting::Only | CacheSetting::ReloadAll
|
|
|
|
) {
|
2023-04-06 21:41:19 -04:00
|
|
|
return false;
|
|
|
|
}
|
2023-04-12 18:04:45 -04:00
|
|
|
if self.inner().force_reload_flag.raise() {
|
|
|
|
self.clear_memory_cache(); // clear the memory cache to force reloading
|
|
|
|
true
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
2023-04-06 21:41:19 -04:00
|
|
|
}
|
|
|
|
|
2023-04-12 08:36:11 -04:00
|
|
|
fn inner(&self) -> &Arc<CliNpmRegistryApiInner> {
|
2023-04-06 18:46:44 -04:00
|
|
|
// this panicking indicates a bug in the code where this
|
|
|
|
// wasn't initialized
|
|
|
|
self.0.as_ref().unwrap()
|
|
|
|
}
|
2023-02-21 12:03:48 -05:00
|
|
|
}
|
|
|
|
|
2023-04-06 18:46:44 -04:00
|
|
|
static SYNC_DOWNLOAD_TASK_QUEUE: Lazy<TaskQueue> =
|
|
|
|
Lazy::new(TaskQueue::default);
|
2023-02-21 12:03:48 -05:00
|
|
|
|
2023-04-06 18:46:44 -04:00
|
|
|
#[async_trait]
|
2023-04-12 08:36:11 -04:00
|
|
|
impl NpmRegistryApi for CliNpmRegistryApi {
|
2023-04-06 21:41:19 -04:00
|
|
|
async fn package_info(
|
2023-02-21 12:03:48 -05:00
|
|
|
&self,
|
|
|
|
name: &str,
|
2023-04-06 21:41:19 -04:00
|
|
|
) -> Result<Arc<NpmPackageInfo>, NpmRegistryPackageInfoLoadError> {
|
|
|
|
let result = if should_sync_download() {
|
2023-04-06 18:46:44 -04:00
|
|
|
let inner = self.inner().clone();
|
|
|
|
SYNC_DOWNLOAD_TASK_QUEUE
|
|
|
|
.queue(async move { inner.maybe_package_info(name).await })
|
|
|
|
.await
|
|
|
|
} else {
|
|
|
|
self.inner().maybe_package_info(name).await
|
2023-04-06 21:41:19 -04:00
|
|
|
};
|
|
|
|
match result {
|
|
|
|
Ok(Some(info)) => Ok(info),
|
|
|
|
Ok(None) => Err(NpmRegistryPackageInfoLoadError::PackageNotExists {
|
|
|
|
package_name: name.to_string(),
|
|
|
|
}),
|
|
|
|
Err(err) => {
|
|
|
|
Err(NpmRegistryPackageInfoLoadError::LoadError(Arc::new(err)))
|
|
|
|
}
|
2023-04-06 18:46:44 -04:00
|
|
|
}
|
2023-02-21 12:03:48 -05:00
|
|
|
}
|
2023-04-06 18:46:44 -04:00
|
|
|
}
|
2023-02-21 12:03:48 -05:00
|
|
|
|
2023-04-12 08:36:11 -04:00
|
|
|
type CacheItemPendingResult =
|
|
|
|
Result<Option<Arc<NpmPackageInfo>>, Arc<AnyError>>;
|
|
|
|
|
2023-04-06 18:46:44 -04:00
|
|
|
#[derive(Debug)]
|
|
|
|
enum CacheItem {
|
2023-04-12 08:36:11 -04:00
|
|
|
Pending(Shared<BoxFuture<'static, CacheItemPendingResult>>),
|
2023-04-06 18:46:44 -04:00
|
|
|
Resolved(Option<Arc<NpmPackageInfo>>),
|
2022-11-08 14:17:24 -05:00
|
|
|
}
|
2022-08-10 15:23:58 -04:00
|
|
|
|
2023-02-21 12:03:48 -05:00
|
|
|
#[derive(Debug)]
|
2023-04-12 08:36:11 -04:00
|
|
|
struct CliNpmRegistryApiInner {
|
2022-11-08 14:17:24 -05:00
|
|
|
base_url: Url,
|
2023-04-14 16:22:33 -04:00
|
|
|
cache: Arc<NpmCache>,
|
2023-04-11 18:10:51 -04:00
|
|
|
force_reload_flag: AtomicFlag,
|
2023-04-06 18:46:44 -04:00
|
|
|
mem_cache: Mutex<HashMap<String, CacheItem>>,
|
2022-11-27 13:25:08 -05:00
|
|
|
previously_reloaded_packages: Mutex<HashSet<String>>,
|
2023-05-01 16:42:05 -04:00
|
|
|
http_client: Arc<HttpClient>,
|
2022-11-08 14:17:24 -05:00
|
|
|
progress_bar: ProgressBar,
|
|
|
|
}
|
|
|
|
|
2023-04-12 08:36:11 -04:00
|
|
|
impl CliNpmRegistryApiInner {
|
2022-08-10 15:23:58 -04:00
|
|
|
pub async fn maybe_package_info(
|
2023-04-06 18:46:44 -04:00
|
|
|
self: &Arc<Self>,
|
2022-08-10 15:23:58 -04:00
|
|
|
name: &str,
|
2022-11-11 11:33:57 -05:00
|
|
|
) -> Result<Option<Arc<NpmPackageInfo>>, AnyError> {
|
2023-04-06 18:46:44 -04:00
|
|
|
let (created, future) = {
|
|
|
|
let mut mem_cache = self.mem_cache.lock();
|
|
|
|
match mem_cache.get(name) {
|
|
|
|
Some(CacheItem::Resolved(maybe_info)) => {
|
|
|
|
return Ok(maybe_info.clone());
|
|
|
|
}
|
|
|
|
Some(CacheItem::Pending(future)) => (false, future.clone()),
|
|
|
|
None => {
|
2023-04-06 21:41:19 -04:00
|
|
|
if (self.cache.cache_setting().should_use_for_npm_package(name) && !self.force_reload())
|
|
|
|
// if this has been previously reloaded, then try loading from the
|
|
|
|
// file system cache
|
|
|
|
|| !self.previously_reloaded_packages.lock().insert(name.to_string())
|
2023-04-06 18:46:44 -04:00
|
|
|
{
|
|
|
|
// attempt to load from the file cache
|
|
|
|
if let Some(info) = self.load_file_cached_package_info(name) {
|
|
|
|
let result = Some(Arc::new(info));
|
|
|
|
mem_cache
|
|
|
|
.insert(name.to_string(), CacheItem::Resolved(result.clone()));
|
|
|
|
return Ok(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let future = {
|
|
|
|
let api = self.clone();
|
|
|
|
let name = name.to_string();
|
2023-04-12 08:36:11 -04:00
|
|
|
async move {
|
|
|
|
api
|
|
|
|
.load_package_info_from_registry(&name)
|
|
|
|
.await
|
|
|
|
.map(|info| info.map(Arc::new))
|
|
|
|
.map_err(Arc::new)
|
|
|
|
}
|
|
|
|
.boxed()
|
|
|
|
.shared()
|
2023-04-06 18:46:44 -04:00
|
|
|
};
|
|
|
|
mem_cache
|
|
|
|
.insert(name.to_string(), CacheItem::Pending(future.clone()));
|
|
|
|
(true, future)
|
|
|
|
}
|
2022-08-10 15:23:58 -04:00
|
|
|
}
|
2023-04-06 18:46:44 -04:00
|
|
|
};
|
2022-08-10 15:23:58 -04:00
|
|
|
|
2023-04-06 18:46:44 -04:00
|
|
|
if created {
|
|
|
|
match future.await {
|
|
|
|
Ok(maybe_info) => {
|
|
|
|
// replace the cache item to say it's resolved now
|
|
|
|
self
|
|
|
|
.mem_cache
|
|
|
|
.lock()
|
|
|
|
.insert(name.to_string(), CacheItem::Resolved(maybe_info.clone()));
|
|
|
|
Ok(maybe_info)
|
2022-08-10 15:23:58 -04:00
|
|
|
}
|
2023-04-06 18:46:44 -04:00
|
|
|
Err(err) => {
|
|
|
|
// purge the item from the cache so it loads next time
|
|
|
|
self.mem_cache.lock().remove(name);
|
2023-04-12 08:36:11 -04:00
|
|
|
Err(anyhow!("{:#}", err))
|
2023-04-06 18:46:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2023-04-12 08:36:11 -04:00
|
|
|
Ok(future.await.map_err(|err| anyhow!("{:#}", err))?)
|
2022-08-10 15:23:58 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-06 21:41:19 -04:00
|
|
|
fn force_reload(&self) -> bool {
|
2023-04-11 18:10:51 -04:00
|
|
|
self.force_reload_flag.is_raised()
|
2023-04-06 21:41:19 -04:00
|
|
|
}
|
|
|
|
|
2022-08-10 15:23:58 -04:00
|
|
|
fn load_file_cached_package_info(
|
|
|
|
&self,
|
|
|
|
name: &str,
|
|
|
|
) -> Option<NpmPackageInfo> {
|
2022-08-22 11:35:04 -04:00
|
|
|
match self.load_file_cached_package_info_result(name) {
|
|
|
|
Ok(value) => value,
|
2022-08-10 15:23:58 -04:00
|
|
|
Err(err) => {
|
|
|
|
if cfg!(debug_assertions) {
|
2023-01-27 10:43:16 -05:00
|
|
|
panic!("error loading cached npm package info for {name}: {err:#}");
|
2022-08-10 15:23:58 -04:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-22 11:35:04 -04:00
|
|
|
fn load_file_cached_package_info_result(
|
|
|
|
&self,
|
|
|
|
name: &str,
|
|
|
|
) -> Result<Option<NpmPackageInfo>, AnyError> {
|
|
|
|
let file_cache_path = self.get_package_file_cache_path(name);
|
|
|
|
let file_text = match fs::read_to_string(file_cache_path) {
|
|
|
|
Ok(file_text) => file_text,
|
|
|
|
Err(err) if err.kind() == ErrorKind::NotFound => return Ok(None),
|
|
|
|
Err(err) => return Err(err.into()),
|
|
|
|
};
|
2022-09-02 13:06:42 -04:00
|
|
|
match serde_json::from_str(&file_text) {
|
|
|
|
Ok(package_info) => Ok(Some(package_info)),
|
|
|
|
Err(err) => {
|
|
|
|
// This scenario might mean we need to load more data from the
|
|
|
|
// npm registry than before. So, just debug log while in debug
|
|
|
|
// rather than panic.
|
|
|
|
log::debug!(
|
|
|
|
"error deserializing registry.json for '{}'. Reloading. {:?}",
|
|
|
|
name,
|
|
|
|
err
|
|
|
|
);
|
|
|
|
Ok(None)
|
|
|
|
}
|
|
|
|
}
|
2022-08-22 11:35:04 -04:00
|
|
|
}
|
|
|
|
|
2022-08-10 15:23:58 -04:00
|
|
|
fn save_package_info_to_file_cache(
|
|
|
|
&self,
|
|
|
|
name: &str,
|
|
|
|
package_info: &NpmPackageInfo,
|
|
|
|
) {
|
2022-08-22 11:35:04 -04:00
|
|
|
if let Err(err) =
|
|
|
|
self.save_package_info_to_file_cache_result(name, package_info)
|
|
|
|
{
|
|
|
|
if cfg!(debug_assertions) {
|
2023-01-27 10:43:16 -05:00
|
|
|
panic!("error saving cached npm package info for {name}: {err:#}");
|
2022-08-22 11:35:04 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn save_package_info_to_file_cache_result(
|
|
|
|
&self,
|
|
|
|
name: &str,
|
|
|
|
package_info: &NpmPackageInfo,
|
|
|
|
) -> Result<(), AnyError> {
|
2022-08-10 15:23:58 -04:00
|
|
|
let file_cache_path = self.get_package_file_cache_path(name);
|
2022-08-22 11:35:04 -04:00
|
|
|
let file_text = serde_json::to_string(&package_info)?;
|
2022-11-28 17:28:54 -05:00
|
|
|
atomic_write_file(&file_cache_path, file_text, CACHE_PERM)?;
|
2022-08-22 11:35:04 -04:00
|
|
|
Ok(())
|
2022-08-10 15:23:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
async fn load_package_info_from_registry(
|
|
|
|
&self,
|
|
|
|
name: &str,
|
2023-04-12 08:36:11 -04:00
|
|
|
) -> Result<Option<NpmPackageInfo>, AnyError> {
|
2023-04-06 18:46:44 -04:00
|
|
|
self
|
|
|
|
.load_package_info_from_registry_inner(name)
|
|
|
|
.await
|
|
|
|
.with_context(|| {
|
|
|
|
format!(
|
|
|
|
"Error getting response at {} for package \"{}\"",
|
|
|
|
self.get_package_url(name),
|
|
|
|
name
|
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn load_package_info_from_registry_inner(
|
|
|
|
&self,
|
|
|
|
name: &str,
|
2022-08-10 15:23:58 -04:00
|
|
|
) -> Result<Option<NpmPackageInfo>, AnyError> {
|
2022-11-27 13:25:08 -05:00
|
|
|
if *self.cache.cache_setting() == CacheSetting::Only {
|
2022-08-22 11:35:04 -04:00
|
|
|
return Err(custom_error(
|
|
|
|
"NotCached",
|
|
|
|
format!(
|
2023-01-27 10:43:16 -05:00
|
|
|
"An npm specifier not found in cache: \"{name}\", --cached-only is specified."
|
2022-08-22 11:35:04 -04:00
|
|
|
)
|
2022-11-27 13:25:08 -05:00
|
|
|
));
|
2022-08-22 11:35:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
let package_url = self.get_package_url(name);
|
2022-12-12 20:52:10 -05:00
|
|
|
let guard = self.progress_bar.update(package_url.as_str());
|
|
|
|
|
|
|
|
let maybe_bytes = self
|
|
|
|
.http_client
|
|
|
|
.download_with_progress(package_url, &guard)
|
|
|
|
.await?;
|
|
|
|
match maybe_bytes {
|
|
|
|
Some(bytes) => {
|
|
|
|
let package_info = serde_json::from_slice(&bytes)?;
|
|
|
|
self.save_package_info_to_file_cache(name, &package_info);
|
|
|
|
Ok(Some(package_info))
|
2022-08-10 15:23:58 -04:00
|
|
|
}
|
2022-12-12 20:52:10 -05:00
|
|
|
None => Ok(None),
|
2022-08-10 15:23:58 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_package_url(&self, name: &str) -> Url {
|
2023-06-15 14:36:33 -04:00
|
|
|
// list of all characters used in npm packages:
|
|
|
|
// !, ', (, ), *, -, ., /, [0-9], @, [A-Za-z], _, ~
|
|
|
|
const ASCII_SET: percent_encoding::AsciiSet =
|
|
|
|
percent_encoding::NON_ALPHANUMERIC
|
|
|
|
.remove(b'!')
|
|
|
|
.remove(b'\'')
|
|
|
|
.remove(b'(')
|
|
|
|
.remove(b')')
|
|
|
|
.remove(b'*')
|
|
|
|
.remove(b'-')
|
|
|
|
.remove(b'.')
|
|
|
|
.remove(b'/')
|
|
|
|
.remove(b'@')
|
|
|
|
.remove(b'_')
|
|
|
|
.remove(b'~');
|
|
|
|
let name = percent_encoding::utf8_percent_encode(name, &ASCII_SET);
|
|
|
|
self.base_url.join(&name.to_string()).unwrap()
|
2022-08-10 15:23:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
fn get_package_file_cache_path(&self, name: &str) -> PathBuf {
|
|
|
|
let name_folder_path = self.cache.package_name_folder(name, &self.base_url);
|
|
|
|
name_folder_path.join("registry.json")
|
|
|
|
}
|
2022-11-08 14:17:24 -05:00
|
|
|
|
2023-04-06 18:46:44 -04:00
|
|
|
pub fn clear_memory_cache(&self) {
|
|
|
|
self.mem_cache.lock().clear();
|
2022-11-08 14:17:24 -05:00
|
|
|
}
|
|
|
|
|
2023-04-06 18:46:44 -04:00
|
|
|
pub fn get_cached_package_info(
|
2022-11-08 14:17:24 -05:00
|
|
|
&self,
|
|
|
|
name: &str,
|
2023-02-21 12:03:48 -05:00
|
|
|
) -> Option<Arc<NpmPackageInfo>> {
|
2023-04-06 18:46:44 -04:00
|
|
|
let mem_cache = self.mem_cache.lock();
|
|
|
|
if let Some(CacheItem::Resolved(maybe_info)) = mem_cache.get(name) {
|
|
|
|
maybe_info.clone()
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
2023-02-22 13:16:40 -05:00
|
|
|
}
|
|
|
|
}
|