diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-01-06 11:36:12 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-06 11:36:12 -0500 |
commit | 7db729a42dca760e1024f296ba4b9e5982f25325 (patch) | |
tree | e08ab4a6fc322bb88f936c7a6b9f38d374c65151 /cli/npm/registry.rs | |
parent | f26700862a2b35fb18a7cfec8dea8f81f665a75c (diff) |
fix(npm): support old packages and registries with no integrity, but with a sha1sum (#17289)
Closes #17281
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 { |