mirror of
https://github.com/Noratrieb/node-package-manager.git
synced 2026-01-14 15:45:03 +01:00
things
This commit is contained in:
parent
89168e9a1a
commit
13b2c9f56d
2 changed files with 13 additions and 12 deletions
|
|
@ -74,7 +74,7 @@ pub struct PackageMeta {
|
|||
pub repository: Option<Repository>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
#[derive(Default, Clone)]
|
||||
pub struct NpmClient {
|
||||
reqwest: Client,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,12 +3,13 @@ use std::{
|
|||
sync::{Arc, RwLock},
|
||||
};
|
||||
|
||||
use color_eyre::{eyre::bail, Result};
|
||||
use color_eyre::{eyre::eyre, Result};
|
||||
use node_semver::Range;
|
||||
use tracing::{debug, info};
|
||||
|
||||
use crate::{download::PackageMeta, NpmClient, WrapErr};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ResolveContext {
|
||||
meta_cache: Arc<RwLock<HashMap<String, Arc<PackageMeta>>>>,
|
||||
client: NpmClient,
|
||||
|
|
@ -63,16 +64,16 @@ impl ResolveContext {
|
|||
.filter(|version| version.satisfies(requested_version))
|
||||
.max();
|
||||
|
||||
match chosen {
|
||||
Some(version) => {
|
||||
let version = chosen
|
||||
.ok_or_else(|| eyre!("could not find matching version for '{requested_version}'"))?;
|
||||
|
||||
let package = &meta.versions[version];
|
||||
|
||||
info!(%version, "Found version");
|
||||
self.client
|
||||
.download_package(name, &meta.versions[version].dist.tarball)
|
||||
.download_package(name, &package.dist.tarball)
|
||||
.await
|
||||
.wrap_err("downloading package")?;
|
||||
}
|
||||
None => bail!("could not find matching version for '{requested_version}'"),
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue