diff options
Diffstat (limited to 'cli/npm/registry.rs')
-rw-r--r-- | cli/npm/registry.rs | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/cli/npm/registry.rs b/cli/npm/registry.rs index ed0911697..0b35079de 100644 --- a/cli/npm/registry.rs +++ b/cli/npm/registry.rs @@ -1,5 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +use std::borrow::Cow; use std::cmp::Ordering; use std::collections::HashMap; use std::collections::HashSet; @@ -178,8 +179,31 @@ impl NpmPackageVersionInfo { pub struct NpmPackageVersionDistInfo { /// URL to the tarball. pub tarball: String, - pub shasum: String, - pub integrity: Option<String>, + shasum: String, + integrity: Option<String>, +} + +impl NpmPackageVersionDistInfo { + #[cfg(test)] + pub fn new( + tarball: String, + shasum: String, + integrity: Option<String>, + ) -> Self { + Self { + tarball, + shasum, + integrity, + } + } + + pub fn integrity(&self) -> Cow<String> { + self + .integrity + .as_ref() + .map(Cow::Borrowed) + .unwrap_or_else(|| Cow::Owned(format!("sha1-{}", self.shasum))) + } } pub trait NpmRegistryApi: Clone + Sync + Send + 'static { |