From f2e30a6f7999fa6ce4ab789266927e3abbb48e3f Mon Sep 17 00:00:00 2001 From: Yusuke Tanaka Date: Tue, 8 Aug 2023 10:07:29 -0700 Subject: refactor(cli): move `snapshot_from_lockfile` function to `deno_npm` (#20024) This commit moves `snapshot_from_lockfile` function to [deno_npm crate](https://github.com/denoland/deno_npm). This allows this function to be called outside Deno CLI (in particular, Deno Deploy). --- cli/npm/registry.rs | 40 ++++++++++++++++++---------------------- cli/npm/resolution.rs | 1 + 2 files changed, 19 insertions(+), 22 deletions(-) (limited to 'cli/npm') diff --git a/cli/npm/registry.rs b/cli/npm/registry.rs index 585cbe163..907258d3b 100644 --- a/cli/npm/registry.rs +++ b/cli/npm/registry.rs @@ -99,27 +99,6 @@ impl CliNpmRegistryApi { &self.inner().base_url } - /// 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 { - // 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 - ) { - return false; - } - if self.inner().force_reload_flag.raise() { - self.clear_memory_cache(); // clear the memory cache to force reloading - true - } else { - false - } - } - fn inner(&self) -> &Arc { // this panicking indicates a bug in the code where this // wasn't initialized @@ -154,6 +133,23 @@ impl NpmRegistryApi for CliNpmRegistryApi { } } } + + fn mark_force_reload(&self) -> bool { + // 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 + ) { + return false; + } + if self.inner().force_reload_flag.raise() { + self.clear_memory_cache(); // clear the cache to force reloading + true + } else { + false + } + } } type CacheItemPendingResult = @@ -386,7 +382,7 @@ impl CliNpmRegistryApiInner { name_folder_path.join("registry.json") } - pub fn clear_memory_cache(&self) { + fn clear_memory_cache(&self) { self.mem_cache.lock().clear(); } diff --git a/cli/npm/resolution.rs b/cli/npm/resolution.rs index 6992d875e..6beb52090 100644 --- a/cli/npm/resolution.rs +++ b/cli/npm/resolution.rs @@ -11,6 +11,7 @@ use deno_core::TaskQueue; use deno_lockfile::NpmPackageDependencyLockfileInfo; use deno_lockfile::NpmPackageLockfileInfo; use deno_npm::registry::NpmPackageInfo; +use deno_npm::registry::NpmRegistryApi; use deno_npm::resolution::NpmPackageVersionResolutionError; use deno_npm::resolution::NpmPackagesPartitioned; use deno_npm::resolution::NpmResolutionError; -- cgit v1.2.3