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>,
|
pub repository: Option<Repository>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default, Clone)]
|
||||||
pub struct NpmClient {
|
pub struct NpmClient {
|
||||||
reqwest: Client,
|
reqwest: Client,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,13 @@ use std::{
|
||||||
sync::{Arc, RwLock},
|
sync::{Arc, RwLock},
|
||||||
};
|
};
|
||||||
|
|
||||||
use color_eyre::{eyre::bail, Result};
|
use color_eyre::{eyre::eyre, Result};
|
||||||
use node_semver::Range;
|
use node_semver::Range;
|
||||||
use tracing::{debug, info};
|
use tracing::{debug, info};
|
||||||
|
|
||||||
use crate::{download::PackageMeta, NpmClient, WrapErr};
|
use crate::{download::PackageMeta, NpmClient, WrapErr};
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct ResolveContext {
|
pub struct ResolveContext {
|
||||||
meta_cache: Arc<RwLock<HashMap<String, Arc<PackageMeta>>>>,
|
meta_cache: Arc<RwLock<HashMap<String, Arc<PackageMeta>>>>,
|
||||||
client: NpmClient,
|
client: NpmClient,
|
||||||
|
|
@ -63,16 +64,16 @@ impl ResolveContext {
|
||||||
.filter(|version| version.satisfies(requested_version))
|
.filter(|version| version.satisfies(requested_version))
|
||||||
.max();
|
.max();
|
||||||
|
|
||||||
match chosen {
|
let version = chosen
|
||||||
Some(version) => {
|
.ok_or_else(|| eyre!("could not find matching version for '{requested_version}'"))?;
|
||||||
info!(%version, "Found version");
|
|
||||||
self.client
|
let package = &meta.versions[version];
|
||||||
.download_package(name, &meta.versions[version].dist.tarball)
|
|
||||||
.await
|
info!(%version, "Found version");
|
||||||
.wrap_err("downloading package")?;
|
self.client
|
||||||
}
|
.download_package(name, &package.dist.tarball)
|
||||||
None => bail!("could not find matching version for '{requested_version}'"),
|
.await
|
||||||
}
|
.wrap_err("downloading package")?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue