summaryrefslogtreecommitdiff
path: root/cli/npm
diff options
context:
space:
mode:
authorYusuke Tanaka <yusuktan@maguro.dev>2023-08-08 10:07:29 -0700
committerGitHub <noreply@github.com>2023-08-08 10:07:29 -0700
commitf2e30a6f7999fa6ce4ab789266927e3abbb48e3f (patch)
tree9d941906a651fedf62818e3e9e8a782cf50d91ce /cli/npm
parent05f838a57cc5b5e7b262e1640baa4d93dfb0df28 (diff)
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).
Diffstat (limited to 'cli/npm')
-rw-r--r--cli/npm/registry.rs40
-rw-r--r--cli/npm/resolution.rs1
2 files changed, 19 insertions, 22 deletions
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<CliNpmRegistryApiInner> {
// 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;